Commit 261746fe authored by fsamuel@chromium.org's avatar fsamuel@chromium.org

<webview>: Expose transparency API

BUG=157628

Review URL: https://codereview.chromium.org/95693002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238428 0039d316-1c4b-4281-b951-d872f2087c98
parent 03d9afc0
......@@ -34,9 +34,10 @@ var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth';
/** @type {Array.<string>} */
var WEB_VIEW_ATTRIBUTES = [
'allowtransparency',
'autosize',
'name',
'partition',
'autosize',
WEB_VIEW_ATTRIBUTE_MINHEIGHT,
WEB_VIEW_ATTRIBUTE_MINWIDTH,
WEB_VIEW_ATTRIBUTE_MAXHEIGHT,
......
......@@ -31,6 +31,7 @@ const char kEventInternalInstanceIDAllocated[] = "instanceid-allocated";
const char kEventInternalTrackedObjectGone[] = "trackedobjectgone";
// Attributes.
const char kAttributeAllowTransparency[] = "allowtransparency";
const char kAttributeApi[] = "api";
const char kAttributeAutoSize[] = "autosize";
const char kAttributeContentWindow[] = "contentWindow";
......
......@@ -31,6 +31,7 @@ extern const char kEventInternalInstanceIDAllocated[];
extern const char kEventInternalTrackedObjectGone[];
// Attributes.
extern const char kAttributeAllowTransparency[];
extern const char kAttributeApi[];
extern const char kAttributeAutoSize[];
extern const char kAttributeContentWindow[];
......
......@@ -86,7 +86,6 @@ BrowserPlugin::BrowserPlugin(
content_window_routing_id_(MSG_ROUTING_NONE),
plugin_focused_(false),
visible_(true),
opaque_(true),
before_first_navigation_(true),
mouse_locked_(false),
browser_plugin_manager_(render_view->GetBrowserPluginManager()),
......@@ -182,6 +181,10 @@ std::string BrowserPlugin::GetNameAttribute() const {
return GetDOMAttributeValue(browser_plugin::kAttributeName);
}
bool BrowserPlugin::GetAllowTransparencyAttribute() const {
return HasDOMAttribute(browser_plugin::kAttributeAllowTransparency);
}
std::string BrowserPlugin::GetSrcAttribute() const {
return GetDOMAttributeValue(browser_plugin::kAttributeSrc);
}
......@@ -259,6 +262,21 @@ void BrowserPlugin::ParseNameAttribute() {
GetNameAttribute()));
}
void BrowserPlugin::ParseAllowTransparencyAttribute() {
if (!HasGuestInstanceID())
return;
bool opaque = !GetAllowTransparencyAttribute();
if (compositing_helper_)
compositing_helper_->SetContentsOpaque(opaque);
browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque(
render_view_routing_id_,
guest_instance_id_,
opaque));
}
bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) {
if (!valid_partition_id_) {
*error_message = browser_plugin::kErrorInvalidPartition;
......@@ -372,7 +390,7 @@ void BrowserPlugin::Attach(scoped_ptr<base::DictionaryValue> extra_params) {
BrowserPluginHostMsg_Attach_Params attach_params;
attach_params.focused = ShouldGuestBeFocused();
attach_params.visible = visible_;
attach_params.opaque = opaque_;
attach_params.opaque = !GetAllowTransparencyAttribute();
attach_params.name = GetNameAttribute();
attach_params.storage_partition_id = storage_partition_id_;
attach_params.persist_storage = persist_storage_;
......@@ -393,23 +411,6 @@ void BrowserPlugin::DidCommitCompositorFrame() {
compositing_helper_->DidCommitCompositorFrame();
}
void BrowserPlugin::SetContentsOpaque(bool opaque) {
if (opaque_ == opaque)
return;
opaque_ = opaque;
if (!HasGuestInstanceID())
return;
if (compositing_helper_)
compositing_helper_->SetContentsOpaque(opaque_);
browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque(
render_view_routing_id_,
guest_instance_id_,
opaque_));
}
void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) {
DCHECK(render_view_.get());
render_view_->GetWebView()->advanceFocus(reverse);
......@@ -922,7 +923,7 @@ void BrowserPlugin::EnableCompositing(bool enable) {
}
}
compositing_helper_->EnableCompositing(enable);
compositing_helper_->SetContentsOpaque(opaque_);
compositing_helper_->SetContentsOpaque(!GetAllowTransparencyAttribute());
}
void BrowserPlugin::destroy() {
......
......@@ -60,6 +60,11 @@ class CONTENT_EXPORT BrowserPlugin :
std::string GetNameAttribute() const;
// Parse the name attribute value.
void ParseNameAttribute();
// Get the allowtransparency attribute value.
bool GetAllowTransparencyAttribute() const;
// Parse the allowtransparency attribute and adjust transparency of
// BrowserPlugin accordingly.
void ParseAllowTransparencyAttribute();
// Get the src attribute value of the BrowserPlugin instance.
std::string GetSrcAttribute() const;
// Parse the src attribute value of the BrowserPlugin instance.
......@@ -135,10 +140,6 @@ class CONTENT_EXPORT BrowserPlugin :
// sent, if needed.
void DidCommitCompositorFrame();
// Apply opacity settings on the composited layers in embedder and send a
// message to the guest renderer to enable or disable transparent background.
void SetContentsOpaque(bool opaque);
// Returns whether a message should be forwarded to BrowserPlugin.
static bool ShouldForwardToBrowserPlugin(const IPC::Message& message);
......@@ -335,9 +336,6 @@ class CONTENT_EXPORT BrowserPlugin :
// Tracks the visibility of the browser plugin regardless of the whole
// embedder RenderView's visibility.
bool visible_;
// Tracks the opacity of the compositing helper's layers and the guest
// renderer process.
bool opaque_;
WebCursor cursor_;
......
......@@ -312,6 +312,41 @@ class BrowserPluginPropertyBinding {
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBinding);
};
class BrowserPluginPropertyBindingAllowTransparency
: public BrowserPluginPropertyBinding {
public:
BrowserPluginPropertyBindingAllowTransparency()
: BrowserPluginPropertyBinding(
browser_plugin::kAttributeAllowTransparency) {
}
virtual bool GetProperty(BrowserPluginBindings* bindings,
NPVariant* result) OVERRIDE {
bool allow_transparency =
bindings->instance()->GetAllowTransparencyAttribute();
BOOLEAN_TO_NPVARIANT(allow_transparency, *result);
return true;
}
virtual bool SetProperty(BrowserPluginBindings* bindings,
NPObject* np_obj,
const NPVariant* variant) OVERRIDE {
std::string value = StringFromNPVariant(*variant);
if (!bindings->instance()->HasDOMAttribute(name())) {
UpdateDOMAttribute(bindings, value);
bindings->instance()->ParseAllowTransparencyAttribute();
} else {
UpdateDOMAttribute(bindings, value);
}
return true;
}
virtual void RemoveProperty(BrowserPluginBindings* bindings,
NPObject* np_obj) OVERRIDE {
bindings->instance()->RemoveDOMAttribute(name());
bindings->instance()->ParseAllowTransparencyAttribute();
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAllowTransparency);
};
class BrowserPluginPropertyBindingAutoSize
: public BrowserPluginPropertyBinding {
public:
......@@ -638,6 +673,8 @@ BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance)
method_bindings_.push_back(new BrowserPluginBindingAttach);
method_bindings_.push_back(new BrowserPluginBindingAttachWindowTo);
property_bindings_.push_back(
new BrowserPluginPropertyBindingAllowTransparency);
property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize);
property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow);
property_bindings_.push_back(new BrowserPluginPropertyBindingMaxHeight);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment