diff options
author | fsamuel <fsamuel@chromium.org> | 2014-09-20 09:57:58 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-20 16:58:11 +0000 |
commit | 516005f409bc6d2221c4be32fe1c0920975cf1ae (patch) | |
tree | 09f7f6e56f593e368eb1514ede7e53404131c622 | |
parent | 0394320b458343d2ce133403f479c344fffaeb06 (diff) | |
download | chromium_src-516005f409bc6d2221c4be32fe1c0920975cf1ae.zip chromium_src-516005f409bc6d2221c4be32fe1c0920975cf1ae.tar.gz chromium_src-516005f409bc6d2221c4be32fe1c0920975cf1ae.tar.bz2 |
Browser Plugin: Remove dependency on NPAPI
The CL moves the final attribute on BrowserPlugin 'allowtransparency' out to the extensions module! No new content APIs had to be introduced! Transparency can be enabled from RenderWidgetHostView::SetBackgroundOpaque in the content embedder.
This means that BrowserPlugin no longer depends on NPAPI and so this patch removes a lot of unnecessary code.
TBR=asvitkine@chromium.org for histograms.xml, extension_function_histogram_value.h
TBR=asvitkine@chromium.org for histograms.xml, extension
BUG=330264
Review URL: https://codereview.chromium.org/584713002
Cr-Commit-Position: refs/heads/master@{#295879}
23 files changed, 232 insertions, 585 deletions
diff --git a/chrome/browser/apps/web_view_browsertest.cc b/chrome/browser/apps/web_view_browsertest.cc index caaf3ed..8bb80fe 100644 --- a/chrome/browser/apps/web_view_browsertest.cc +++ b/chrome/browser/apps/web_view_browsertest.cc @@ -906,6 +906,10 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_Shim_TestAutosizeAfterNavigation) { TestHelper("testAutosizeAfterNavigation", "web_view/shim", NO_TEST_SERVER); } +IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAllowTransparencyAttribute) { + TestHelper("testAllowTransparencyAttribute", "web_view/shim", NO_TEST_SERVER); +} + IN_PROC_BROWSER_TEST_F(WebViewDPITest, Shim_TestAutosizeHeight) { TestHelper("testAutosizeHeight", "web_view/shim", NO_TEST_SERVER); } diff --git a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js index d6688bc..e0e0ca1 100644 --- a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js +++ b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js @@ -93,6 +93,26 @@ embedder.test.assertFalse = function(condition) { // Tests begin. +// This test verifies that the allowtransparency property cannot be changed +// once set. The attribute can only be deleted. +function testAllowTransparencyAttribute() { + var webview = document.createElement('webview'); + webview.src = 'data:text/html,webview test'; + webview.allowtransparency = true; + + webview.addEventListener('loadstop', function(e) { + embedder.test.assertTrue(webview.hasAttribute('allowtransparency')); + webview.allowtransparency = false; + embedder.test.assertTrue(webview.allowtransparency); + embedder.test.assertTrue(webview.hasAttribute('allowtransparency')); + webview.removeAttribute('allowtransparency'); + embedder.test.assertFalse(webview.allowtransparency); + embedder.test.succeed(); + }); + + document.body.appendChild(webview); +} + // This test verifies that a lengthy page with autosize enabled will report // the correct height in the sizechanged event. function testAutosizeHeight() { @@ -1808,6 +1828,7 @@ function testFindAPI_findupdate() { }; embedder.test.testList = { + 'testAllowTransparencyAttribute': testAllowTransparencyAttribute, 'testAutosizeHeight': testAutosizeHeight, 'testAutosizeAfterNavigation': testAutosizeAfterNavigation, 'testAutosizeBeforeNavigation': testAutosizeBeforeNavigation, diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc index 992bccc..1d23397 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.cc +++ b/content/browser/browser_plugin/browser_plugin_guest.cc @@ -80,7 +80,6 @@ BrowserPluginGuest::BrowserPluginGuest(bool has_render_view, mouse_locked_(false), pending_lock_request_(false), guest_visible_(false), - guest_opaque_(true), embedder_visible_(true), copy_request_id_(0), has_render_view_(has_render_view), @@ -183,8 +182,6 @@ bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent, OnSetEditCommandsForNextKeyEvent) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) - IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetContentsOpaque, - OnSetContentsOpaque) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) @@ -200,7 +197,6 @@ void BrowserPluginGuest::Initialize( browser_plugin_instance_id_ = browser_plugin_instance_id; focused_ = params.focused; guest_visible_ = params.visible; - guest_opaque_ = params.opaque; guest_window_rect_ = gfx::Rect(params.origin, params.resize_guest_params.view_size); @@ -371,6 +367,12 @@ void BrowserPluginGuest::SwapCompositorFrame( browser_plugin_instance_id(), guest_params)); } +void BrowserPluginGuest::SetContentsOpaque(bool opaque) { + SendMessageToEmbedder( + new BrowserPluginMsg_SetContentsOpaque( + browser_plugin_instance_id(), opaque)); +} + WebContentsImpl* BrowserPluginGuest::GetWebContents() const { return static_cast<WebContentsImpl*>(web_contents()); } @@ -441,8 +443,6 @@ void BrowserPluginGuest::RenderViewReady() { Send(new InputMsg_SetFocus(routing_id(), focused_)); UpdateVisibility(); - OnSetContentsOpaque(browser_plugin_instance_id(), guest_opaque_); - RenderWidgetHostImpl::From(rvh)->set_hung_renderer_delay_ms( base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)); } @@ -484,7 +484,6 @@ bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest( case BrowserPluginHostMsg_ResizeGuest::ID: case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: case BrowserPluginHostMsg_SetFocus::ID: - case BrowserPluginHostMsg_SetContentsOpaque::ID: case BrowserPluginHostMsg_SetVisibility::ID: case BrowserPluginHostMsg_UnlockMouse_ACK::ID: case BrowserPluginHostMsg_UpdateGeometry::ID: @@ -730,12 +729,6 @@ void BrowserPluginGuest::OnSetEditCommandsForNextKeyEvent( edit_commands)); } -void BrowserPluginGuest::OnSetContentsOpaque(int browser_plugin_instance_id, - bool opaque) { - guest_opaque_ = opaque; - Send(new ViewMsg_SetBackgroundOpaque(routing_id(), guest_opaque_)); -} - void BrowserPluginGuest::OnSetVisibility(int browser_plugin_instance_id, bool visible) { guest_visible_ = visible; diff --git a/content/browser/browser_plugin/browser_plugin_guest.h b/content/browser/browser_plugin/browser_plugin_guest.h index 13aed33..cecca6d 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.h +++ b/content/browser/browser_plugin/browser_plugin_guest.h @@ -203,6 +203,8 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { int host_routing_id, scoped_ptr<cc::CompositorFrame> frame); + void SetContentsOpaque(bool opaque); + private: class EmbedderWebContentsObserver; @@ -263,7 +265,6 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { void OnSetEditCommandsForNextKeyEvent( int instance_id, const std::vector<EditCommand>& edit_commands); - void OnSetContentsOpaque(int instance_id, bool opaque); // The guest WebContents is visible if both its embedder is visible and // the browser plugin element is visible. If either one is not then the // WebContents is marked as hidden. A hidden WebContents will consume @@ -336,7 +337,6 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { bool mouse_locked_; bool pending_lock_request_; bool guest_visible_; - bool guest_opaque_; bool embedder_visible_; // Each copy-request is identified by a unique number. The unique number is diff --git a/content/browser/frame_host/render_widget_host_view_guest.cc b/content/browser/frame_host/render_widget_host_view_guest.cc index fb68070..924d703 100644 --- a/content/browser/frame_host/render_widget_host_view_guest.cc +++ b/content/browser/frame_host/render_widget_host_view_guest.cc @@ -367,7 +367,15 @@ void RenderWidgetHostViewGuest::CopyFromCompositingSurface( } void RenderWidgetHostViewGuest::SetBackgroundOpaque(bool opaque) { - platform_view_->SetBackgroundOpaque(opaque); + // Content embedders can toggle opaque backgrounds through this API. + // We plumb the value here so that BrowserPlugin updates its compositing + // state in response to this change. We also want to preserve this flag + // after recovering from a crash so we let BrowserPluginGuest store it. + if (!guest_) + return; + RenderWidgetHostViewBase::SetBackgroundOpaque(opaque); + host_->SetBackgroundOpaque(opaque); + guest_->SetContentsOpaque(opaque); } bool RenderWidgetHostViewGuest::LockMouse() { diff --git a/content/common/browser_plugin/browser_plugin_constants.cc b/content/common/browser_plugin/browser_plugin_constants.cc index 9fd3b7e..93fa662 100644 --- a/content/common/browser_plugin/browser_plugin_constants.cc +++ b/content/common/browser_plugin/browser_plugin_constants.cc @@ -8,9 +8,6 @@ namespace content { namespace browser_plugin { -// Attributes. -const char kAttributeAllowTransparency[] = "allowtransparency"; - // Other. const int kInstanceIDNone = 0; diff --git a/content/common/browser_plugin/browser_plugin_constants.h b/content/common/browser_plugin/browser_plugin_constants.h index 5161f7b..812d07f 100644 --- a/content/common/browser_plugin/browser_plugin_constants.h +++ b/content/common/browser_plugin/browser_plugin_constants.h @@ -9,9 +9,6 @@ namespace content { namespace browser_plugin { -// Attributes. -extern const char kAttributeAllowTransparency[]; - // Other. extern const int kInstanceIDNone; diff --git a/content/common/browser_plugin/browser_plugin_messages.h b/content/common/browser_plugin/browser_plugin_messages.h index b1c7f43..80c8e23 100644 --- a/content/common/browser_plugin/browser_plugin_messages.h +++ b/content/common/browser_plugin/browser_plugin_messages.h @@ -50,7 +50,6 @@ IPC_STRUCT_END() IPC_STRUCT_BEGIN(BrowserPluginHostMsg_Attach_Params) IPC_STRUCT_MEMBER(bool, focused) IPC_STRUCT_MEMBER(bool, visible) - IPC_STRUCT_MEMBER(bool, opaque) IPC_STRUCT_MEMBER(BrowserPluginHostMsg_ResizeGuest_Params, resize_guest_params) IPC_STRUCT_MEMBER(gfx::Point, origin) @@ -136,11 +135,6 @@ IPC_MESSAGE_ROUTED2(BrowserPluginHostMsg_SetVisibility, int /* browser_plugin_instance_id */, bool /* visible */) -// Tells the guest to change its background opacity. -IPC_MESSAGE_ROUTED2(BrowserPluginHostMsg_SetContentsOpaque, - int /* browser_plugin_instance_id */, - bool /* opaque */) - // Tells the guest that a drag event happened on the plugin. IPC_MESSAGE_ROUTED5(BrowserPluginHostMsg_DragStatusUpdate, int /* browser_plugin_instance_id */, @@ -198,6 +192,11 @@ IPC_MESSAGE_CONTROL2(BrowserPluginMsg_ShouldAcceptTouchEvents, int /* browser_plugin_instance_id */, bool /* accept */) +// Tells the guest to change its background opacity. +IPC_MESSAGE_CONTROL2(BrowserPluginMsg_SetContentsOpaque, + int /* browser_plugin_instance_id */, + bool /* opaque */) + // Inform the embedder of the cursor the guest wishes to display. IPC_MESSAGE_CONTROL2(BrowserPluginMsg_SetCursor, int /* browser_plugin_instance_id */, diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index a2334d3..cdec14c 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -104,8 +104,6 @@ 'renderer/battery_status/battery_status_dispatcher.h', 'renderer/browser_plugin/browser_plugin.cc', 'renderer/browser_plugin/browser_plugin.h', - 'renderer/browser_plugin/browser_plugin_bindings.cc', - 'renderer/browser_plugin/browser_plugin_bindings.h', 'renderer/browser_plugin/browser_plugin_manager_factory.h', 'renderer/browser_plugin/browser_plugin_manager_impl.cc', 'renderer/browser_plugin/browser_plugin_manager_impl.h', diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc index 661816c..2fdd343 100644 --- a/content/renderer/browser_plugin/browser_plugin.cc +++ b/content/renderer/browser_plugin/browser_plugin.cc @@ -15,7 +15,6 @@ #include "content/public/common/content_switches.h" #include "content/public/renderer/browser_plugin_delegate.h" #include "content/public/renderer/content_renderer_client.h" -#include "content/renderer/browser_plugin/browser_plugin_bindings.h" #include "content/renderer/browser_plugin/browser_plugin_manager.h" #include "content/renderer/child_frame_compositing_helper.h" #include "content/renderer/cursor_utils.h" @@ -23,8 +22,6 @@ #include "content/renderer/render_thread_impl.h" #include "content/renderer/sad_plugin.h" #include "third_party/WebKit/public/platform/WebRect.h" -#include "third_party/WebKit/public/web/WebBindings.h" -#include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebElement.h" #include "third_party/WebKit/public/web/WebInputEvent.h" #include "third_party/WebKit/public/web/WebPluginContainer.h" @@ -72,12 +69,12 @@ BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, last_device_scale_factor_(GetDeviceScaleFactor()), sad_guest_(NULL), guest_crashed_(false), - content_window_routing_id_(MSG_ROUTING_NONE), plugin_focused_(false), visible_(true), mouse_locked_(false), browser_plugin_manager_(render_view->GetBrowserPluginManager()), browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), + contents_opaque_(true), delegate_(delegate.Pass()), weak_ptr_factory_(this) { browser_plugin_instance_id_ = browser_plugin_manager()->GetNextInstanceID(); @@ -107,6 +104,7 @@ bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(BrowserPluginMsg_CopyFromCompositingSurface, OnCopyFromCompositingSurface) IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) + IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetContentsOpaque, OnSetContentsOpaque) IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock) IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, @@ -124,56 +122,8 @@ void BrowserPlugin::UpdateDOMAttribute(const std::string& attribute_name, blink::WebElement element = container()->element(); blink::WebString web_attribute_name = blink::WebString::fromUTF8(attribute_name); - if (!HasDOMAttribute(attribute_name) || - (std::string(element.getAttribute(web_attribute_name).utf8()) != - attribute_value)) { - element.setAttribute(web_attribute_name, - blink::WebString::fromUTF8(attribute_value)); - } -} - -void BrowserPlugin::RemoveDOMAttribute(const std::string& attribute_name) { - if (!container()) - return; - - container()->element().removeAttribute( - blink::WebString::fromUTF8(attribute_name)); -} - -std::string BrowserPlugin::GetDOMAttributeValue( - const std::string& attribute_name) const { - if (!container()) - return std::string(); - - return container()->element().getAttribute( - blink::WebString::fromUTF8(attribute_name)).utf8(); -} - -bool BrowserPlugin::HasDOMAttribute(const std::string& attribute_name) const { - if (!container()) - return false; - - return container()->element().hasAttribute( - blink::WebString::fromUTF8(attribute_name)); -} - -bool BrowserPlugin::GetAllowTransparencyAttribute() const { - return HasDOMAttribute(browser_plugin::kAttributeAllowTransparency); -} - -void BrowserPlugin::ParseAllowTransparencyAttribute() { - if (!ready()) - return; - - bool opaque = !GetAllowTransparencyAttribute(); - - if (compositing_helper_.get()) - compositing_helper_->SetContentsOpaque(opaque); - - browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque( - render_view_routing_id_, - browser_plugin_instance_id_, - opaque)); + element.setAttribute(web_attribute_name, + blink::WebString::fromUTF8(attribute_value)); } void BrowserPlugin::Attach() { @@ -191,7 +141,6 @@ void BrowserPlugin::Attach() { BrowserPluginHostMsg_Attach_Params attach_params; attach_params.focused = ShouldGuestBeFocused(); attach_params.visible = visible_; - attach_params.opaque = !GetAllowTransparencyAttribute(); attach_params.origin = plugin_rect().origin(); gfx::Size view_size(width(), height()); if (!view_size.IsEmpty()) { @@ -277,6 +226,15 @@ void BrowserPlugin::OnGuestGone(int browser_plugin_instance_id) { weak_ptr_factory_.GetWeakPtr())); } +void BrowserPlugin::OnSetContentsOpaque(int browser_plugin_instance_id, + bool opaque) { + if (contents_opaque_ == opaque) + return; + contents_opaque_ = opaque; + if (compositing_helper_.get()) + compositing_helper_->SetContentsOpaque(opaque); +} + void BrowserPlugin::OnSetCursor(int browser_plugin_instance_id, const WebCursor& cursor) { cursor_ = cursor; @@ -356,11 +314,6 @@ bool BrowserPlugin::initialize(WebPluginContainer* container) { if (!container) return false; - // Tell |container| to allow this plugin to use script objects. - npp_.reset(new NPP_t); - container->allowScriptObjects(); - - bindings_.reset(new BrowserPluginBindings(this)); container_ = container; container_->setWantsWheelEvents(true); @@ -390,7 +343,7 @@ void BrowserPlugin::EnableCompositing(bool enable) { } } compositing_helper_->EnableCompositing(enable); - compositing_helper_->SetContentsOpaque(!GetAllowTransparencyAttribute()); + compositing_helper_->SetContentsOpaque(contents_opaque_); if (!enable) { DCHECK(compositing_helper_.get()); @@ -400,11 +353,8 @@ void BrowserPlugin::EnableCompositing(bool enable) { } void BrowserPlugin::destroy() { - // If the plugin was initialized then it has a valid |npp_| identifier, and - // the |container_| must clear references to the plugin's script objects. - DCHECK(!npp_ || container_); if (container_) { - container_->clearScriptObjects(); + //container_->clearScriptObjects(); // The BrowserPlugin's WebPluginContainer is deleted immediately after this // call returns, so let's not keep a reference to it around. @@ -420,20 +370,6 @@ void BrowserPlugin::destroy() { base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); } -NPObject* BrowserPlugin::scriptableObject() { - if (!bindings_) - return NULL; - - NPObject* browser_plugin_np_object(bindings_->np_object()); - // The object is expected to be retained before it is returned. - blink::WebBindings::retainObject(browser_plugin_np_object); - return browser_plugin_np_object; -} - -NPP BrowserPlugin::pluginNPP() { - return npp_.get(); -} - bool BrowserPlugin::supportsKeyboardFocus() const { return true; } @@ -487,6 +423,7 @@ bool BrowserPlugin::ShouldForwardToBrowserPlugin( case BrowserPluginMsg_CompositorFrameSwapped::ID: case BrowserPluginMsg_CopyFromCompositingSurface::ID: case BrowserPluginMsg_GuestGone::ID: + case BrowserPluginMsg_SetContentsOpaque::ID: case BrowserPluginMsg_SetCursor::ID: case BrowserPluginMsg_SetMouseLock::ID: case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: diff --git a/content/renderer/browser_plugin/browser_plugin.h b/content/renderer/browser_plugin/browser_plugin.h index 08ef04c..ee521c0 100644 --- a/content/renderer/browser_plugin/browser_plugin.h +++ b/content/renderer/browser_plugin/browser_plugin.h @@ -10,7 +10,6 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/sequenced_task_runner_helpers.h" -#include "content/renderer/browser_plugin/browser_plugin_bindings.h" #include "content/renderer/mouse_lock_dispatcher.h" #include "content/renderer/render_view_impl.h" #include "third_party/WebKit/public/web/WebCompositionUnderline.h" @@ -19,7 +18,6 @@ #include "third_party/WebKit/public/web/WebWidget.h" struct BrowserPluginHostMsg_ResizeGuest_Params; -struct BrowserPluginMsg_UpdateRect_Params; struct FrameMsg_BuffersSwapped_Params; namespace content { @@ -50,24 +48,13 @@ class CONTENT_EXPORT BrowserPlugin : // |attribute_value|. void UpdateDOMAttribute(const std::string& attribute_name, const std::string& attribute_value); - // Remove the DOM Node attribute with the name |attribute_name|. - void RemoveDOMAttribute(const std::string& attribute_name); - // Get Browser Plugin's DOM Node attribute |attribute_name|'s value. - std::string GetDOMAttributeValue(const std::string& attribute_name) const; - // Checks if the attribute |attribute_name| exists in the DOM. - bool HasDOMAttribute(const std::string& attribute_name) const; - - // Get the allowtransparency attribute value. - bool GetAllowTransparencyAttribute() const; - // Parse the allowtransparency attribute and adjust transparency of - // BrowserPlugin accordingly. - void ParseAllowTransparencyAttribute(); // Returns whether the guest process has crashed. bool guest_crashed() const { return guest_crashed_; } // Informs the guest of an updated focus state. void UpdateGuestFocusState(); + // Indicates whether the guest should be focused. bool ShouldGuestBeFocused() const; @@ -93,8 +80,6 @@ class CONTENT_EXPORT BrowserPlugin : virtual blink::WebPluginContainer* container() const OVERRIDE; virtual bool initialize(blink::WebPluginContainer* container) OVERRIDE; virtual void destroy() OVERRIDE; - virtual NPObject* scriptableObject() OVERRIDE; - virtual struct _NPP* pluginNPP() OVERRIDE; virtual bool supportsKeyboardFocus() const OVERRIDE; virtual bool supportsEditCommands() const OVERRIDE; virtual bool supportsInputMethod() const OVERRIDE; @@ -195,6 +180,7 @@ class CONTENT_EXPORT BrowserPlugin : gfx::Rect source_rect, gfx::Size dest_size); void OnGuestGone(int instance_id); + void OnSetContentsOpaque(int instance_id, bool opaque); void OnSetCursor(int instance_id, const WebCursor& cursor); void OnSetMouseLock(int instance_id, bool enable); void OnShouldAcceptTouchEvents(int instance_id, bool accept); @@ -209,13 +195,11 @@ class CONTENT_EXPORT BrowserPlugin : // then we will attempt to access a NULL pointer. const int render_view_routing_id_; blink::WebPluginContainer* container_; - scoped_ptr<BrowserPluginBindings> bindings_; gfx::Rect plugin_rect_; float last_device_scale_factor_; // Bitmap for crashed plugin. Lazily initialized, non-owning pointer. SkBitmap* sad_guest_; bool guest_crashed_; - int content_window_routing_id_; bool plugin_focused_; // Tracks the visibility of the browser plugin regardless of the whole // embedder RenderView's visibility. @@ -234,12 +218,12 @@ class CONTENT_EXPORT BrowserPlugin : // Used for HW compositing. scoped_refptr<ChildFrameCompositingHelper> compositing_helper_; - // Used to identify the plugin to WebBindings. - scoped_ptr<struct _NPP> npp_; - // URL for the embedder frame. int browser_plugin_instance_id_; + // Indicates whether the guest content is opaque. + bool contents_opaque_; + std::vector<EditCommand> edit_commands_; scoped_ptr<BrowserPluginDelegate> delegate_; diff --git a/content/renderer/browser_plugin/browser_plugin_bindings.cc b/content/renderer/browser_plugin/browser_plugin_bindings.cc deleted file mode 100644 index 46751d6..0000000 --- a/content/renderer/browser_plugin/browser_plugin_bindings.cc +++ /dev/null @@ -1,267 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/renderer/browser_plugin/browser_plugin_bindings.h" - -#include <string> - -#include "content/common/browser_plugin/browser_plugin_constants.h" -#include "content/renderer/browser_plugin/browser_plugin.h" -#include "third_party/WebKit/public/web/WebBindings.h" -#include "third_party/npapi/bindings/npapi.h" - -using blink::WebBindings; - -namespace content { - -namespace { - -BrowserPluginBindings* GetBindings(NPObject* object) { - return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> - message_channel.get(); -} - -std::string StringFromNPVariant(const NPVariant& variant) { - if (!NPVARIANT_IS_STRING(variant)) - return std::string(); - const NPString& np_string = NPVARIANT_TO_STRING(variant); - return std::string(np_string.UTF8Characters, np_string.UTF8Length); -} - -//------------------------------------------------------------------------------ -// Implementations of NPClass functions. These are here to: -// - Implement src attribute. -//------------------------------------------------------------------------------ -NPObject* BrowserPluginBindingsAllocate(NPP npp, NPClass* the_class) { - return new BrowserPluginBindings::BrowserPluginNPObject; -} - -void BrowserPluginBindingsDeallocate(NPObject* object) { - BrowserPluginBindings::BrowserPluginNPObject* instance = - static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object); - delete instance; -} - -bool BrowserPluginBindingsHasMethod(NPObject* np_obj, NPIdentifier name) { - return false; -} - -bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, - const NPVariant* args, - uint32 arg_count, - NPVariant* result) { - NOTIMPLEMENTED(); - return false; -} - -bool BrowserPluginBindingsHasProperty(NPObject* np_obj, NPIdentifier name) { - if (!np_obj) - return false; - - BrowserPluginBindings* bindings = GetBindings(np_obj); - if (!bindings) - return false; - - return bindings->HasProperty(name); -} - -bool BrowserPluginBindingsGetProperty(NPObject* np_obj, NPIdentifier name, - NPVariant* result) { - if (!np_obj) - return false; - - if (!result) - return false; - - // All attributes from here on rely on the bindings, so retrieve it once and - // return on failure. - BrowserPluginBindings* bindings = GetBindings(np_obj); - if (!bindings) - return false; - - return bindings->GetProperty(name, result); -} - -bool BrowserPluginBindingsSetProperty(NPObject* np_obj, NPIdentifier name, - const NPVariant* variant) { - if (!np_obj) - return false; - if (!variant) - return false; - - // All attributes from here on rely on the bindings, so retrieve it once and - // return on failure. - BrowserPluginBindings* bindings = GetBindings(np_obj); - if (!bindings) - return false; - - if (variant->type == NPVariantType_Null) - return bindings->RemoveProperty(np_obj, name); - - return bindings->SetProperty(np_obj, name, variant); -} - -bool BrowserPluginBindingsEnumerate(NPObject *np_obj, NPIdentifier **value, - uint32_t *count) { - NOTIMPLEMENTED(); - return true; -} - -NPClass browser_plugin_message_class = { - NP_CLASS_STRUCT_VERSION, - &BrowserPluginBindingsAllocate, - &BrowserPluginBindingsDeallocate, - NULL, - &BrowserPluginBindingsHasMethod, - NULL, - &BrowserPluginBindingsInvokeDefault, - &BrowserPluginBindingsHasProperty, - &BrowserPluginBindingsGetProperty, - &BrowserPluginBindingsSetProperty, - NULL, - &BrowserPluginBindingsEnumerate, -}; - -} // namespace - -// BrowserPluginPropertyBinding ------------------------------------------------ - -class BrowserPluginPropertyBinding { - public: - explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) {} - virtual ~BrowserPluginPropertyBinding() {} - const std::string& name() const { return name_; } - bool MatchesName(NPIdentifier name) const { - return WebBindings::getStringIdentifier(name_.c_str()) == name; - } - virtual bool GetProperty(BrowserPluginBindings* bindings, - NPVariant* result) = 0; - virtual bool SetProperty(BrowserPluginBindings* bindings, - NPObject* np_obj, - const NPVariant* variant) = 0; - virtual void RemoveProperty(BrowserPluginBindings* bindings, - NPObject* np_obj) = 0; - // Updates the DOM Attribute value with the current property value. - void UpdateDOMAttribute(BrowserPluginBindings* bindings, - std::string new_value) { - bindings->instance()->UpdateDOMAttribute(name(), new_value); - } - private: - std::string name_; - - 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); -}; - - -// BrowserPluginBindings ------------------------------------------------------ - -BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { -} - -BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { -} - -BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) - : instance_(instance), - np_object_(NULL), - weak_ptr_factory_(this) { - NPObject* obj = - WebBindings::createObject(instance->pluginNPP(), - &browser_plugin_message_class); - np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); - np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); - - property_bindings_.push_back( - new BrowserPluginPropertyBindingAllowTransparency); -} - -BrowserPluginBindings::~BrowserPluginBindings() { - WebBindings::releaseObject(np_object_); -} - -bool BrowserPluginBindings::HasProperty(NPIdentifier name) const { - for (PropertyBindingList::const_iterator iter = property_bindings_.begin(); - iter != property_bindings_.end(); - ++iter) { - if ((*iter)->MatchesName(name)) - return true; - } - return false; -} - -bool BrowserPluginBindings::SetProperty(NPObject* np_obj, - NPIdentifier name, - const NPVariant* variant) { - for (PropertyBindingList::iterator iter = property_bindings_.begin(); - iter != property_bindings_.end(); - ++iter) { - if ((*iter)->MatchesName(name)) { - if ((*iter)->SetProperty(this, np_obj, variant)) { - return true; - } - break; - } - } - return false; -} - -bool BrowserPluginBindings::RemoveProperty(NPObject* np_obj, - NPIdentifier name) { - for (PropertyBindingList::iterator iter = property_bindings_.begin(); - iter != property_bindings_.end(); - ++iter) { - if ((*iter)->MatchesName(name)) { - (*iter)->RemoveProperty(this, np_obj); - return true; - } - } - return false; -} - -bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { - for (PropertyBindingList::iterator iter = property_bindings_.begin(); - iter != property_bindings_.end(); - ++iter) { - if ((*iter)->MatchesName(name)) - return (*iter)->GetProperty(this, result); - } - return false; -} - -} // namespace content diff --git a/content/renderer/browser_plugin/browser_plugin_bindings.h b/content/renderer/browser_plugin/browser_plugin_bindings.h deleted file mode 100644 index b565f51..0000000 --- a/content/renderer/browser_plugin/browser_plugin_bindings.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__ -#define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__ - -#include "base/memory/scoped_vector.h" -#include "base/memory/weak_ptr.h" -#include "third_party/npapi/bindings/npruntime.h" - -namespace content { - -class BrowserPlugin; -class BrowserPluginPropertyBinding; - -class BrowserPluginBindings { - public: - // BrowserPluginNPObject is a simple struct that adds a pointer back to a - // BrowserPluginBindings instance. This way, we can use an NPObject to allow - // JavaScript interactions without forcing BrowserPluginBindings to inherit - // from NPObject. - struct BrowserPluginNPObject : public NPObject { - BrowserPluginNPObject(); - ~BrowserPluginNPObject(); - - base::WeakPtr<BrowserPluginBindings> message_channel; - }; - - explicit BrowserPluginBindings(BrowserPlugin* instance); - ~BrowserPluginBindings(); - - NPObject* np_object() const { return np_object_; } - - BrowserPlugin* instance() const { return instance_; } - - bool HasMethod(NPIdentifier name) const; - - bool HasProperty(NPIdentifier name) const; - bool SetProperty(NPObject* np_obj, - NPIdentifier name, - const NPVariant* variant); - bool GetProperty(NPIdentifier name, NPVariant* result); - bool RemoveProperty(NPObject *np_obj, NPIdentifier name); - private: - BrowserPlugin* instance_; - // The NPObject we use to expose postMessage to JavaScript. - BrowserPluginNPObject* np_object_; - - typedef ScopedVector<BrowserPluginPropertyBinding> PropertyBindingList; - PropertyBindingList property_bindings_; - - // This is used to ensure pending tasks will not fire after this object is - // destroyed. - base::WeakPtrFactory<BrowserPluginBindings> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindings); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__ diff --git a/extensions/browser/api/web_view/web_view_internal_api.cc b/extensions/browser/api/web_view/web_view_internal_api.cc index 0bffc5a7..cbacf7e 100644 --- a/extensions/browser/api/web_view/web_view_internal_api.cc +++ b/extensions/browser/api/web_view/web_view_internal_api.cc @@ -180,12 +180,6 @@ WebViewInternalSetNameFunction::WebViewInternalSetNameFunction() { WebViewInternalSetNameFunction::~WebViewInternalSetNameFunction() { } -WebViewInternalSetZoomFunction::WebViewInternalSetZoomFunction() { -} - -WebViewInternalSetZoomFunction::~WebViewInternalSetZoomFunction() { -} - bool WebViewInternalSetNameFunction::RunAsyncSafe(WebViewGuest* guest) { scoped_ptr<webview::SetName::Params> params( webview::SetName::Params::Create(*args_)); @@ -195,6 +189,30 @@ bool WebViewInternalSetNameFunction::RunAsyncSafe(WebViewGuest* guest) { return true; } +WebViewInternalSetAllowTransparencyFunction:: +WebViewInternalSetAllowTransparencyFunction() { +} + +WebViewInternalSetAllowTransparencyFunction:: +~WebViewInternalSetAllowTransparencyFunction() { +} + +bool WebViewInternalSetAllowTransparencyFunction::RunAsyncSafe( + WebViewGuest* guest) { + scoped_ptr<webview::SetAllowTransparency::Params> params( + webview::SetAllowTransparency::Params::Create(*args_)); + EXTENSION_FUNCTION_VALIDATE(params.get()); + guest->SetAllowTransparency(params->allow); + SendResponse(true); + return true; +} + +WebViewInternalSetZoomFunction::WebViewInternalSetZoomFunction() { +} + +WebViewInternalSetZoomFunction::~WebViewInternalSetZoomFunction() { +} + bool WebViewInternalSetZoomFunction::RunAsyncSafe(WebViewGuest* guest) { scoped_ptr<webview::SetZoom::Params> params( webview::SetZoom::Params::Create(*args_)); diff --git a/extensions/browser/api/web_view/web_view_internal_api.h b/extensions/browser/api/web_view/web_view_internal_api.h index 6eae99f..ecb54c1 100644 --- a/extensions/browser/api/web_view/web_view_internal_api.h +++ b/extensions/browser/api/web_view/web_view_internal_api.h @@ -150,6 +150,23 @@ class WebViewInternalSetNameFunction : public WebViewInternalExtensionFunction { DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetNameFunction); }; +class WebViewInternalSetAllowTransparencyFunction : + public WebViewInternalExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowTransparency", + WEBVIEWINTERNAL_SETALLOWTRANSPARENCY); + + WebViewInternalSetAllowTransparencyFunction(); + + protected: + virtual ~WebViewInternalSetAllowTransparencyFunction(); + + private: + virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowTransparencyFunction); +}; + class WebViewInternalSetZoomFunction : public WebViewInternalExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoom", diff --git a/extensions/browser/extension_function_histogram_value.h b/extensions/browser/extension_function_histogram_value.h index 3eaa577..67245e0 100644 --- a/extensions/browser/extension_function_histogram_value.h +++ b/extensions/browser/extension_function_histogram_value.h @@ -953,6 +953,7 @@ enum HistogramValue { EASYUNLOCKPRIVATE_TRYSIGNINSECRET, ACCESSIBILITY_PRIVATE_SETFOCUSRING, USB_GETCONFIGURATION, + WEBVIEWINTERNAL_SETALLOWTRANSPARENCY, // Last entry: Add new entries above and ensure to update // tools/metrics/histograms/histograms.xml. ENUM_BOUNDARY diff --git a/extensions/browser/guest_view/web_view/web_view_constants.cc b/extensions/browser/guest_view/web_view/web_view_constants.cc index 4e2ee90..9d61ec6 100644 --- a/extensions/browser/guest_view/web_view/web_view_constants.cc +++ b/extensions/browser/guest_view/web_view/web_view_constants.cc @@ -7,11 +7,14 @@ namespace webview { // Attributes. +const char kAttributeAllowTransparency[] = "allowtransparency"; const char kAttributeAutoSize[] = "autosize"; const char kAttributeMaxHeight[] = "maxheight"; const char kAttributeMaxWidth[] = "maxwidth"; const char kAttributeMinHeight[] = "minheight"; const char kAttributeMinWidth[] = "minwidth"; +const char kAttributeName[] = "name"; +const char kAttributeSrc[] = "src"; // API namespace. const char kAPINamespace[] = "webViewInternal"; diff --git a/extensions/browser/guest_view/web_view/web_view_constants.h b/extensions/browser/guest_view/web_view/web_view_constants.h index d0a24e2..b186edb 100644 --- a/extensions/browser/guest_view/web_view/web_view_constants.h +++ b/extensions/browser/guest_view/web_view/web_view_constants.h @@ -10,11 +10,14 @@ namespace webview { // Attributes. +extern const char kAttributeAllowTransparency[]; extern const char kAttributeAutoSize[]; extern const char kAttributeMaxHeight[]; extern const char kAttributeMaxWidth[]; extern const char kAttributeMinHeight[]; extern const char kAttributeMinWidth[]; +extern const char kAttributeName[]; +extern const char kAttributeSrc[]; // API namespace. // TODO(kalman): Consolidate this with the other API constants. diff --git a/extensions/browser/guest_view/web_view/web_view_guest.cc b/extensions/browser/guest_view/web_view/web_view_guest.cc index d7afe16..deb840e 100644 --- a/extensions/browser/guest_view/web_view/web_view_guest.cc +++ b/extensions/browser/guest_view/web_view/web_view_guest.cc @@ -18,6 +18,7 @@ #include "content/public/browser/notification_types.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" +#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/resource_request_details.h" #include "content/public/browser/site_instance.h" #include "content/public/browser/storage_partition.h" @@ -244,7 +245,7 @@ void WebViewGuest::DidAttachToEmbedder() { SetUpAutoSize(); std::string name; - if (attach_params()->GetString(webview::kName, &name)) { + if (attach_params()->GetString(webview::kAttributeName, &name)) { // If the guest window's name is empty, then the WebView tag's name is // assigned. Otherwise, the guest window's name takes precedence over the // WebView tag's name. @@ -262,7 +263,7 @@ void WebViewGuest::DidAttachToEmbedder() { } std::string src; - if (attach_params()->GetString("src", &src) && !src.empty()) + if (attach_params()->GetString(webview::kAttributeSrc, &src) && !src.empty()) NavigateGuest(src); if (GetOpener()) { @@ -284,6 +285,13 @@ void WebViewGuest::DidAttachToEmbedder() { // lifetime of the new guest is no longer managed by the opener guest. GetOpener()->pending_new_windows_.erase(this); } + + bool allow_transparency = false; + attach_params()->GetBoolean(webview::kAttributeAllowTransparency, + &allow_transparency); + // We need to set the background opaque flag after navigation to ensure that + // there is a RenderWidgetHostView available. + SetAllowTransparency(allow_transparency); } void WebViewGuest::DidInitialize() { @@ -331,6 +339,13 @@ void WebViewGuest::GuestReady() { // The guest RenderView should always live in an isolated guest process. CHECK(web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); Send(new ExtensionMsg_SetFrameName(web_contents()->GetRoutingID(), name_)); + + // We don't want to accidentally set the opacity of an interstitial page. + // WebContents::GetRenderWidgetHostView will return the RWHV of an + // interstitial page if one is showing at this time. We only want opacity + // to apply to web pages. + web_contents()->GetRenderViewHost()->GetView()-> + SetBackgroundOpaque(guest_opaque_); } void WebViewGuest::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size, @@ -618,6 +633,7 @@ WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, : GuestView<WebViewGuest>(browser_context, guest_instance_id), find_helper_(this), is_overriding_user_agent_(false), + guest_opaque_(true), javascript_dialog_helper_(this) { web_view_guest_delegate_.reset( ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); @@ -955,6 +971,17 @@ void WebViewGuest::SetZoom(double zoom_factor) { web_view_guest_delegate_->OnSetZoom(zoom_factor); } +void WebViewGuest::SetAllowTransparency(bool allow) { + if (guest_opaque_ != allow) + return; + + guest_opaque_ = !allow; + if (!web_contents()->GetRenderViewHost()->GetView()) + return; + + web_contents()->GetRenderViewHost()->GetView()->SetBackgroundOpaque(!allow); +} + void WebViewGuest::AddNewContents(content::WebContents* source, content::WebContents* new_contents, WindowOpenDisposition disposition, diff --git a/extensions/browser/guest_view/web_view/web_view_guest.h b/extensions/browser/guest_view/web_view/web_view_guest.h index e62629b..1d9ba9a 100644 --- a/extensions/browser/guest_view/web_view/web_view_guest.h +++ b/extensions/browser/guest_view/web_view/web_view_guest.h @@ -74,6 +74,9 @@ class WebViewGuest : public GuestView<WebViewGuest>, // Set the zoom factor. void SetZoom(double zoom_factor); + // Sets the transparency of the guest. + void SetAllowTransparency(bool allow); + // GuestViewBase implementation. virtual const char* GetAPINamespace() const OVERRIDE; virtual int GetTaskPrefix() const OVERRIDE; @@ -330,6 +333,9 @@ class WebViewGuest : public GuestView<WebViewGuest>, // Stores the window name of the main frame of the guest. std::string name_; + // Stores whether the contents of the guest can be transparent. + bool guest_opaque_; + // Handles the JavaScript dialog requests. JavaScriptDialogHelper javascript_dialog_helper_; diff --git a/extensions/common/api/web_view_internal.json b/extensions/common/api/web_view_internal.json index 28aac0e..0f58854 100644 --- a/extensions/common/api/web_view_internal.json +++ b/extensions/common/api/web_view_internal.json @@ -332,6 +332,20 @@ ] }, { + "name": "setAllowTransparency", + "type": "function", + "parameters": [ + { + "type": "integer", + "name": "instanceId" + }, + { + "type": "boolean", + "name": "allow" + } + ] + }, + { "name": "setName", "type": "function", "parameters": [ diff --git a/extensions/renderer/resources/web_view.js b/extensions/renderer/resources/web_view.js index d28b479..9829bd9 100644 --- a/extensions/renderer/resources/web_view.js +++ b/extensions/renderer/resources/web_view.js @@ -29,17 +29,13 @@ var AUTO_SIZE_ATTRIBUTES = [ WEB_VIEW_ATTRIBUTE_MINWIDTH ]; +var WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY = "allowtransparency"; var WEB_VIEW_ATTRIBUTE_PARTITION = 'partition'; var ERROR_MSG_ALREADY_NAVIGATED = 'The object has already navigated, so its partition cannot be changed.'; var ERROR_MSG_INVALID_PARTITION_ATTRIBUTE = 'Invalid partition attribute.'; -/** @type {Array.<string>} */ -var WEB_VIEW_ATTRIBUTES = [ - 'allowtransparency', -]; - /** @class representing state of storage partition. */ function Partition() { this.validPartitionId = true; @@ -128,23 +124,6 @@ WebViewInternal.prototype.createBrowserPluginNode = function() { // to attributes synchronously. var browserPluginNode = new WebViewInternal.BrowserPlugin(); privates(browserPluginNode).internal = this; - - $Array.forEach(WEB_VIEW_ATTRIBUTES, function(attributeName) { - // Only copy attributes that have been assigned values, rather than copying - // a series of undefined attributes to BrowserPlugin. - if (this.webviewNode.hasAttribute(attributeName)) { - browserPluginNode.setAttribute( - attributeName, this.webviewNode.getAttribute(attributeName)); - } else if (this.webviewNode[attributeName]){ - // Reading property using has/getAttribute does not work on - // document.DOMContentLoaded event (but works on - // window.DOMContentLoaded event). - // So copy from property if copying from attribute fails. - browserPluginNode.setAttribute( - attributeName, this.webviewNode[attributeName]); - } - }, this); - return browserPluginNode; }; @@ -195,12 +174,12 @@ WebViewInternal.prototype.setupFocusPropagation = function() { var self = this; this.webviewNode.addEventListener('focus', function(e) { // Focus the BrowserPlugin when the <webview> takes focus. - self.browserPluginNode.focus(); - }); + this.browserPluginNode.focus(); + }.bind(this)); this.webviewNode.addEventListener('blur', function(e) { // Blur the BrowserPlugin when the <webview> loses focus. - self.browserPluginNode.blur(); - }); + this.browserPluginNode.blur(); + }.bind(this)); }; /** @@ -329,19 +308,18 @@ WebViewInternal.prototype.insertCSS = function(var_args) { }; WebViewInternal.prototype.setupAutoSizeProperties = function() { - var self = this; $Array.forEach(AUTO_SIZE_ATTRIBUTES, function(attributeName) { this[attributeName] = this.webviewNode.getAttribute(attributeName); Object.defineProperty(this.webviewNode, attributeName, { get: function() { - return self[attributeName]; - }, + return this[attributeName]; + }.bind(this), set: function(value) { - self.webviewNode.setAttribute(attributeName, value); - }, + this.webviewNode.setAttribute(attributeName, value); + }.bind(this), enumerable: true }); - }, this); + }.bind(this), this); }; /** @@ -353,78 +331,63 @@ WebViewInternal.prototype.setupWebviewNodeProperties = function() { 'when the page has finished loading.'; this.setupAutoSizeProperties(); - var self = this; - var browserPluginNode = this.browserPluginNode; - // Expose getters and setters for the attributes. - $Array.forEach(WEB_VIEW_ATTRIBUTES, function(attributeName) { - Object.defineProperty(this.webviewNode, attributeName, { - get: function() { - if (browserPluginNode.hasOwnProperty(attributeName)) { - return browserPluginNode[attributeName]; - } else { - return browserPluginNode.getAttribute(attributeName); - } - }, - set: function(value) { - if (browserPluginNode.hasOwnProperty(attributeName)) { - // Give the BrowserPlugin first stab at the attribute so that it can - // throw an exception if there is a problem. This attribute will then - // be propagated back to the <webview>. - browserPluginNode[attributeName] = value; - } else { - browserPluginNode.setAttribute(attributeName, value); - } - }, - enumerable: true - }); - }, this); - // <webview> src does not quite behave the same as BrowserPlugin src, and so - // we don't simply keep the two in sync. - this.src = this.webviewNode.getAttribute('src'); - Object.defineProperty(this.webviewNode, 'src', { + Object.defineProperty(this.webviewNode, + WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY, { get: function() { - return self.src; - }, + return this.allowtransparency; + }.bind(this), set: function(value) { - self.webviewNode.setAttribute('src', value); - }, + this.webviewNode.setAttribute(WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY, + value); + }.bind(this), + enumerable: true + }); + + // We cannot use {writable: true} property descriptor because we want a + // dynamic getter value. + Object.defineProperty(this.webviewNode, 'contentWindow', { + get: function() { + if (this.contentWindow) { + return this.contentWindow; + } + window.console.error(ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); + }.bind(this), // No setter. enumerable: true }); Object.defineProperty(this.webviewNode, 'name', { get: function() { - return self.name; - }, + return this.name; + }.bind(this), set: function(value) { - self.webviewNode.setAttribute('name', value); - }, + this.webviewNode.setAttribute('name', value); + }.bind(this), enumerable: true }); Object.defineProperty(this.webviewNode, 'partition', { get: function() { - return self.partition.toAttribute(); - }, + return this.partition.toAttribute(); + }.bind(this), set: function(value) { - var result = self.partition.fromAttribute(value, self.hasNavigated()); + var result = this.partition.fromAttribute(value, this.hasNavigated()); if (result.error) { throw result.error; } - self.webviewNode.setAttribute('partition', value); - }, + this.webviewNode.setAttribute('partition', value); + }.bind(this), enumerable: true }); - // We cannot use {writable: true} property descriptor because we want a - // dynamic getter value. - Object.defineProperty(this.webviewNode, 'contentWindow', { + this.src = this.webviewNode.getAttribute('src'); + Object.defineProperty(this.webviewNode, 'src', { get: function() { - if (this.contentWindow) { - return this.contentWindow; - } - window.console.error(ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); + return this.src; + }.bind(this), + set: function(value) { + this.webviewNode.setAttribute('src', value); }.bind(this), // No setter. enumerable: true @@ -495,6 +458,23 @@ WebViewInternal.prototype.handleWebviewAttributeMutation = } }); return; + } else if (name == WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY) { + // We treat null attribute (attribute removed) and the empty string as + // one case. + oldValue = oldValue || ''; + newValue = newValue || ''; + + if (oldValue === newValue) { + return; + } + this.allowtransparency = newValue != ''; + + if (!this.guestInstanceId) { + return; + } + + WebView.setAllowTransparency(this.guestInstanceId, this.allowtransparency); + return; } else if (name == 'name') { // We treat null attribute (attribute removed) and the empty string as // one case. @@ -543,17 +523,6 @@ WebViewInternal.prototype.handleWebviewAttributeMutation = // Note that throwing error here won't synchronously propagate. this.partition.fromAttribute(newValue, this.hasNavigated()); } - - // No <webview> -> <object> mutation propagation for these attributes. - if (name == 'src' || name == 'partition') { - return; - } - - if (this.browserPluginNode.hasOwnProperty(name)) { - this.browserPluginNode[name] = newValue; - } else { - this.browserPluginNode.setAttribute(name, newValue); - } }; /** @@ -588,26 +557,6 @@ WebViewInternal.prototype.handleBrowserPluginAttributeMutation = return; } - - // This observer monitors mutations to attributes of the BrowserPlugin and - // updates the <webview> attributes accordingly. - // |newValue| is null if the attribute |name| has been removed. - if (newValue != null) { - // Update the <webview> attribute to match the BrowserPlugin attribute. - // Note: Calling setAttribute on <webview> will trigger its mutation - // observer which will then propagate that attribute to BrowserPlugin. In - // cases where we permit assigning a BrowserPlugin attribute the same value - // again (such as navigation when crashed), this could end up in an infinite - // loop. Thus, we avoid this loop by only updating the <webview> attribute - // if the BrowserPlugin attributes differs from it. - if (newValue != this.webviewNode.getAttribute(name)) { - this.webviewNode.setAttribute(name, newValue); - } - } else { - // If an attribute is removed from the BrowserPlugin, then remove it - // from the <webview> as well. - this.webviewNode.removeAttribute(name); - } }; WebViewInternal.prototype.onSizeChanged = function(webViewEvent) { @@ -728,15 +677,13 @@ WebViewInternal.prototype.allocateInstanceId = function() { var params = { 'storagePartitionId': storagePartitionId, }; - var self = this; GuestViewInternal.createGuest( 'webview', params, function(guestInstanceId) { - // TODO(lazyboy): Make sure this.autoNavigate_ stuff correctly updated - // |self.src| at this point. - self.attachWindow(guestInstanceId, false); - }); + this.attachWindow(guestInstanceId, false); + }.bind(this) + ); }; WebViewInternal.prototype.onFrameNameChanged = function(name) { @@ -768,7 +715,7 @@ WebViewInternal.prototype.setupEventProperty = function(eventName) { }.bind(this), set: function(value) { if (this.on[propertyName]) - this.webviewNode.removeEventListener(eventName, self.on[propertyName]); + this.webviewNode.removeEventListener(eventName, this.on[propertyName]); this.on[propertyName] = value; if (value) this.webviewNode.addEventListener(eventName, value); @@ -855,6 +802,7 @@ WebViewInternal.prototype.getZoom = function(callback) { WebViewInternal.prototype.buildAttachParams = function(isNewWindow) { var params = { + 'allowtransparency': this.allowtransparency || false, 'autosize': this.webviewNode.hasAttribute(WEB_VIEW_ATTRIBUTE_AUTOSIZE), 'instanceId': this.viewInstanceId, 'maxheight': parseInt(this.maxheight || 0), diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 27d1dd3..0a75768 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -41926,6 +41926,7 @@ Therefore, the affected-histogram name has to have at least one dot in it. <int value="892" label="EASYUNLOCKPRIVATE_TRYSIGNINSECRET"/> <int value="893" label="ACCESSIBILITY_PRIVATE_SETFOCUSRING"/> <int value="894" label="USB_GETCONFIGURATION"/> + <int value="895" label="WEBVIEWINTERNAL_SETALLOWTRANSPARENCY"/> </enum> <enum name="ExtensionInstallCause" type="int"> |