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'; ...@@ -34,9 +34,10 @@ var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth';
/** @type {Array.<string>} */ /** @type {Array.<string>} */
var WEB_VIEW_ATTRIBUTES = [ var WEB_VIEW_ATTRIBUTES = [
'allowtransparency',
'autosize',
'name', 'name',
'partition', 'partition',
'autosize',
WEB_VIEW_ATTRIBUTE_MINHEIGHT, WEB_VIEW_ATTRIBUTE_MINHEIGHT,
WEB_VIEW_ATTRIBUTE_MINWIDTH, WEB_VIEW_ATTRIBUTE_MINWIDTH,
WEB_VIEW_ATTRIBUTE_MAXHEIGHT, WEB_VIEW_ATTRIBUTE_MAXHEIGHT,
......
...@@ -31,6 +31,7 @@ const char kEventInternalInstanceIDAllocated[] = "instanceid-allocated"; ...@@ -31,6 +31,7 @@ const char kEventInternalInstanceIDAllocated[] = "instanceid-allocated";
const char kEventInternalTrackedObjectGone[] = "trackedobjectgone"; const char kEventInternalTrackedObjectGone[] = "trackedobjectgone";
// Attributes. // Attributes.
const char kAttributeAllowTransparency[] = "allowtransparency";
const char kAttributeApi[] = "api"; const char kAttributeApi[] = "api";
const char kAttributeAutoSize[] = "autosize"; const char kAttributeAutoSize[] = "autosize";
const char kAttributeContentWindow[] = "contentWindow"; const char kAttributeContentWindow[] = "contentWindow";
......
...@@ -31,6 +31,7 @@ extern const char kEventInternalInstanceIDAllocated[]; ...@@ -31,6 +31,7 @@ extern const char kEventInternalInstanceIDAllocated[];
extern const char kEventInternalTrackedObjectGone[]; extern const char kEventInternalTrackedObjectGone[];
// Attributes. // Attributes.
extern const char kAttributeAllowTransparency[];
extern const char kAttributeApi[]; extern const char kAttributeApi[];
extern const char kAttributeAutoSize[]; extern const char kAttributeAutoSize[];
extern const char kAttributeContentWindow[]; extern const char kAttributeContentWindow[];
......
...@@ -86,7 +86,6 @@ BrowserPlugin::BrowserPlugin( ...@@ -86,7 +86,6 @@ BrowserPlugin::BrowserPlugin(
content_window_routing_id_(MSG_ROUTING_NONE), content_window_routing_id_(MSG_ROUTING_NONE),
plugin_focused_(false), plugin_focused_(false),
visible_(true), visible_(true),
opaque_(true),
before_first_navigation_(true), before_first_navigation_(true),
mouse_locked_(false), mouse_locked_(false),
browser_plugin_manager_(render_view->GetBrowserPluginManager()), browser_plugin_manager_(render_view->GetBrowserPluginManager()),
...@@ -182,6 +181,10 @@ std::string BrowserPlugin::GetNameAttribute() const { ...@@ -182,6 +181,10 @@ std::string BrowserPlugin::GetNameAttribute() const {
return GetDOMAttributeValue(browser_plugin::kAttributeName); return GetDOMAttributeValue(browser_plugin::kAttributeName);
} }
bool BrowserPlugin::GetAllowTransparencyAttribute() const {
return HasDOMAttribute(browser_plugin::kAttributeAllowTransparency);
}
std::string BrowserPlugin::GetSrcAttribute() const { std::string BrowserPlugin::GetSrcAttribute() const {
return GetDOMAttributeValue(browser_plugin::kAttributeSrc); return GetDOMAttributeValue(browser_plugin::kAttributeSrc);
} }
...@@ -259,6 +262,21 @@ void BrowserPlugin::ParseNameAttribute() { ...@@ -259,6 +262,21 @@ void BrowserPlugin::ParseNameAttribute() {
GetNameAttribute())); 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) { bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) {
if (!valid_partition_id_) { if (!valid_partition_id_) {
*error_message = browser_plugin::kErrorInvalidPartition; *error_message = browser_plugin::kErrorInvalidPartition;
...@@ -372,7 +390,7 @@ void BrowserPlugin::Attach(scoped_ptr<base::DictionaryValue> extra_params) { ...@@ -372,7 +390,7 @@ void BrowserPlugin::Attach(scoped_ptr<base::DictionaryValue> extra_params) {
BrowserPluginHostMsg_Attach_Params attach_params; BrowserPluginHostMsg_Attach_Params attach_params;
attach_params.focused = ShouldGuestBeFocused(); attach_params.focused = ShouldGuestBeFocused();
attach_params.visible = visible_; attach_params.visible = visible_;
attach_params.opaque = opaque_; attach_params.opaque = !GetAllowTransparencyAttribute();
attach_params.name = GetNameAttribute(); attach_params.name = GetNameAttribute();
attach_params.storage_partition_id = storage_partition_id_; attach_params.storage_partition_id = storage_partition_id_;
attach_params.persist_storage = persist_storage_; attach_params.persist_storage = persist_storage_;
...@@ -393,23 +411,6 @@ void BrowserPlugin::DidCommitCompositorFrame() { ...@@ -393,23 +411,6 @@ void BrowserPlugin::DidCommitCompositorFrame() {
compositing_helper_->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) { void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) {
DCHECK(render_view_.get()); DCHECK(render_view_.get());
render_view_->GetWebView()->advanceFocus(reverse); render_view_->GetWebView()->advanceFocus(reverse);
...@@ -922,7 +923,7 @@ void BrowserPlugin::EnableCompositing(bool enable) { ...@@ -922,7 +923,7 @@ void BrowserPlugin::EnableCompositing(bool enable) {
} }
} }
compositing_helper_->EnableCompositing(enable); compositing_helper_->EnableCompositing(enable);
compositing_helper_->SetContentsOpaque(opaque_); compositing_helper_->SetContentsOpaque(!GetAllowTransparencyAttribute());
} }
void BrowserPlugin::destroy() { void BrowserPlugin::destroy() {
......
...@@ -60,6 +60,11 @@ class CONTENT_EXPORT BrowserPlugin : ...@@ -60,6 +60,11 @@ class CONTENT_EXPORT BrowserPlugin :
std::string GetNameAttribute() const; std::string GetNameAttribute() const;
// Parse the name attribute value. // Parse the name attribute value.
void ParseNameAttribute(); 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. // Get the src attribute value of the BrowserPlugin instance.
std::string GetSrcAttribute() const; std::string GetSrcAttribute() const;
// Parse the src attribute value of the BrowserPlugin instance. // Parse the src attribute value of the BrowserPlugin instance.
...@@ -135,10 +140,6 @@ class CONTENT_EXPORT BrowserPlugin : ...@@ -135,10 +140,6 @@ class CONTENT_EXPORT BrowserPlugin :
// sent, if needed. // sent, if needed.
void DidCommitCompositorFrame(); 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. // Returns whether a message should be forwarded to BrowserPlugin.
static bool ShouldForwardToBrowserPlugin(const IPC::Message& message); static bool ShouldForwardToBrowserPlugin(const IPC::Message& message);
...@@ -335,9 +336,6 @@ class CONTENT_EXPORT BrowserPlugin : ...@@ -335,9 +336,6 @@ class CONTENT_EXPORT BrowserPlugin :
// Tracks the visibility of the browser plugin regardless of the whole // Tracks the visibility of the browser plugin regardless of the whole
// embedder RenderView's visibility. // embedder RenderView's visibility.
bool visible_; bool visible_;
// Tracks the opacity of the compositing helper's layers and the guest
// renderer process.
bool opaque_;
WebCursor cursor_; WebCursor cursor_;
......
...@@ -312,6 +312,41 @@ class BrowserPluginPropertyBinding { ...@@ -312,6 +312,41 @@ class BrowserPluginPropertyBinding {
DISALLOW_COPY_AND_ASSIGN(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 class BrowserPluginPropertyBindingAutoSize
: public BrowserPluginPropertyBinding { : public BrowserPluginPropertyBinding {
public: public:
...@@ -638,6 +673,8 @@ BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) ...@@ -638,6 +673,8 @@ BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance)
method_bindings_.push_back(new BrowserPluginBindingAttach); method_bindings_.push_back(new BrowserPluginBindingAttach);
method_bindings_.push_back(new BrowserPluginBindingAttachWindowTo); method_bindings_.push_back(new BrowserPluginBindingAttachWindowTo);
property_bindings_.push_back(
new BrowserPluginPropertyBindingAllowTransparency);
property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize); property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize);
property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow); property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow);
property_bindings_.push_back(new BrowserPluginPropertyBindingMaxHeight); 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