webview: allow setting background color
authorRobo <hop2deep@gmail.com>
Sun, 13 Mar 2016 04:16:33 +0000 (09:46 +0530)
committerRobo <hop2deep@gmail.com>
Mon, 14 Mar 2016 09:31:36 +0000 (15:01 +0530)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/web_view_guest_delegate.cc
atom/browser/web_view_guest_delegate.h
atom/common/api/api_messages.h
atom/renderer/atom_render_view_observer.cc
atom/renderer/atom_render_view_observer.h
lib/browser/guest-view-manager.js
lib/renderer/web-view/guest-view-internal.js
lib/renderer/web-view/web-view-attributes.js
lib/renderer/web-view/web-view-constants.js

index c8b597704cd0e21c0a95c07b6cec8974401a8ba3..e5ea7e32a292fad4bd920d8d644f694262bc1a5b 100644 (file)
@@ -1100,11 +1100,6 @@ void WebContents::SetSize(const SetSizeParams& params) {
     guest_delegate_->SetSize(params);
 }
 
-void WebContents::SetAllowTransparency(bool allow) {
-  if (guest_delegate_)
-    guest_delegate_->SetAllowTransparency(allow);
-}
-
 bool WebContents::IsGuest() const {
   return type_ == WEB_VIEW;
 }
@@ -1202,7 +1197,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
                  &WebContents::BeginFrameSubscription)
       .SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
       .SetMethod("setSize", &WebContents::SetSize)
-      .SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
       .SetMethod("isGuest", &WebContents::IsGuest)
       .SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
       .SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)
index d98b838fb464967e48f9b40dc7a27e3ed9a0f3b0..b734dc304dffc731456fcdf519ad0448eca6695a 100644 (file)
@@ -131,7 +131,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
 
   // Methods for creating <webview>.
   void SetSize(const SetSizeParams& params);
-  void SetAllowTransparency(bool allow);
   bool IsGuest() const;
 
   // Callback triggered on permission response.
index 38f0fb1783fa2058dee8847719d909d9d3f7d247..47fcc204a4da9b4f9840db20e0fea46d0557b182 100644 (file)
@@ -5,6 +5,7 @@
 #include "atom/browser/web_view_guest_delegate.h"
 
 #include "atom/browser/api/atom_api_web_contents.h"
+#include "atom/common/api/api_messages.h"
 #include "atom/common/native_mate_converters/gurl_converter.h"
 #include "content/public/browser/guest_host.h"
 #include "content/public/browser/render_frame_host.h"
@@ -22,8 +23,7 @@ const int kDefaultHeight = 300;
 }  // namespace
 
 WebViewGuestDelegate::WebViewGuestDelegate()
-    : guest_opaque_(true),
-      guest_host_(nullptr),
+    : guest_host_(nullptr),
       auto_size_enabled_(false),
       is_full_page_plugin_(false),
       api_web_contents_(nullptr) {
@@ -96,23 +96,6 @@ void WebViewGuestDelegate::SetSize(const SetSizeParams& params) {
   auto_size_enabled_ = enable_auto_size;
 }
 
-void WebViewGuestDelegate::SetAllowTransparency(bool allow) {
-  if (guest_opaque_ != allow)
-    return;
-
-  auto render_view_host = web_contents()->GetRenderViewHost();
-  guest_opaque_ = !allow;
-  if (!render_view_host->GetWidget()->GetView())
-    return;
-
-  if (guest_opaque_) {
-    render_view_host->GetWidget()->GetView()->SetBackgroundColorToDefault();
-  } else {
-    render_view_host->GetWidget()->GetView()->SetBackgroundColor(
-        SK_ColorTRANSPARENT);
-  }
-}
-
 void WebViewGuestDelegate::HandleKeyboardEvent(
     content::WebContents* source,
     const content::NativeWebKeyboardEvent& event) {
@@ -121,16 +104,9 @@ void WebViewGuestDelegate::HandleKeyboardEvent(
 }
 
 void WebViewGuestDelegate::RenderViewReady() {
-  // 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.
-  auto render_view_host_view =
-      web_contents()->GetRenderViewHost()->GetWidget()->GetView();
-  if (guest_opaque_)
-    render_view_host_view->SetBackgroundColorToDefault();
-  else
-    render_view_host_view->SetBackgroundColor(SK_ColorTRANSPARENT);
+  // Set default UA-dependent background as transparent.
+  api_web_contents_->Send(new AtomViewMsg_SetTransparentBackground(
+      api_web_contents_->routing_id()));
 }
 
 void WebViewGuestDelegate::DidCommitProvisionalLoadForFrame(
index 65e0bcde19160fcd60e42264b2ddee1f6751aea5..d4549e8dba4a85d7ddaae160bba3fb7f1aa4d6ef 100644 (file)
@@ -49,9 +49,6 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
   // and normal sizes.
   void SetSize(const SetSizeParams& params);
 
-  // Sets the transparency of the guest.
-  void SetAllowTransparency(bool allow);
-
   // Transfer the keyboard event to embedder.
   void HandleKeyboardEvent(content::WebContents* source,
                            const content::NativeWebKeyboardEvent& event);
@@ -85,9 +82,6 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
   // Returns the default size of the guestview.
   gfx::Size GetDefaultSize() const;
 
-  // Stores whether the contents of the guest can be transparent.
-  bool guest_opaque_;
-
   // The WebContents that attaches this guest view.
   content::WebContents* embedder_web_contents_;
 
index eeb26614847b0bbe33b006909103f6e23ceb1bac..e98f1bdfba0ffb409faf0e48f59cacd051a4c80c 100644 (file)
@@ -37,3 +37,5 @@ IPC_MESSAGE_ROUTED2(AtomViewMsg_Message,
 // Sent by the renderer when the draggable regions are updated.
 IPC_MESSAGE_ROUTED1(AtomViewHostMsg_UpdateDraggableRegions,
                     std::vector<atom::DraggableRegion> /* regions */)
+
+IPC_MESSAGE_ROUTED0(AtomViewMsg_SetTransparentBackground)
index cdbdb3d7c3ce76081decf2085428a91dc38e4901..19eaec9e07bf0cb55e18c2af36e7af5dcb88292b 100644 (file)
@@ -22,6 +22,7 @@
 #include "ipc/ipc_message_macros.h"
 #include "net/base/net_module.h"
 #include "net/grit/net_resources.h"
+#include "third_party/skia/include/core/SkColor.h"
 #include "third_party/WebKit/public/web/WebDraggableRegion.h"
 #include "third_party/WebKit/public/web/WebDocument.h"
 #include "third_party/WebKit/public/web/WebFrame.h"
@@ -113,6 +114,8 @@ bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
   bool handled = true;
   IPC_BEGIN_MESSAGE_MAP(AtomRenderViewObserver, message)
     IPC_MESSAGE_HANDLER(AtomViewMsg_Message, OnBrowserMessage)
+    IPC_MESSAGE_HANDLER(AtomViewMsg_SetTransparentBackground,
+                        OnSetTransparentBackground)
     IPC_MESSAGE_UNHANDLED(handled = false)
   IPC_END_MESSAGE_MAP()
 
@@ -148,4 +151,10 @@ void AtomRenderViewObserver::OnBrowserMessage(const base::string16& channel,
   }
 }
 
+void AtomRenderViewObserver::OnSetTransparentBackground() {
+  if (!render_view()->GetWebView())
+    return;
+  render_view()->GetWebView()->setBaseBackgroundColor(SK_ColorTRANSPARENT);
+}
+
 }  // namespace atom
index 4b9d59f3fa08720ab25170a4c0cc785ba1c170de..3fcaeaa331fb5511449cc93d8244f6a4619cb6e3 100644 (file)
@@ -32,6 +32,7 @@ class AtomRenderViewObserver : public content::RenderViewObserver {
 
   void OnBrowserMessage(const base::string16& channel,
                         const base::ListValue& args);
+  void OnSetTransparentBackground();
 
   // Weak reference to renderer client.
   AtomRendererClient* renderer_client_;
index b41b9b3a0f5ce823adaebba1b85dbe8e6c056c75..574207dd5b15a933e4e3fae8c9ca661921289f44 100644 (file)
@@ -131,9 +131,6 @@ var createGuest = function(embedder, params) {
       }
       this.loadURL(params.src, opts);
     }
-    if (params.allowtransparency != null) {
-      this.setAllowTransparency(params.allowtransparency);
-    }
     return guest.allowPopups = params.allowpopups;
   });
 
@@ -229,11 +226,6 @@ ipcMain.on('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', function(event, id, params)
   return (ref1 = guestInstances[id]) != null ? ref1.guest.setSize(params) : void 0;
 });
 
-ipcMain.on('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', function(event, id, allowtransparency) {
-  var ref1;
-  return (ref1 = guestInstances[id]) != null ? ref1.guest.setAllowTransparency(allowtransparency) : void 0;
-});
-
 // Returns WebContents from its guest id.
 exports.getGuest = function(id) {
   var ref1;
index a7427abd631c49a938ac305957920f2bf73f5114..c6e46fab9547e0e393fed76b53ee4596cfa42d54 100644 (file)
@@ -106,7 +106,4 @@ module.exports = {
   setSize: function(guestInstanceId, params) {
     return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params);
   },
-  setAllowTransparency: function(guestInstanceId, allowtransparency) {
-    return ipcRenderer.send('ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', guestInstanceId, allowtransparency);
-  }
 };
index bb7847fe16364c0a0e777a914675897381b6d9f4..e47b42c026142f4fd082369e2812efddc934f6bc 100644 (file)
@@ -81,20 +81,6 @@ class BooleanAttribute extends WebViewAttribute {
   }
 }
 
-// Attribute that specifies whether transparency is allowed in the webview.
-class AllowTransparencyAttribute extends BooleanAttribute {
-  constructor(webViewImpl) {
-    super(webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, webViewImpl);
-  }
-
-  handleMutation() {
-    if (!this.webViewImpl.guestInstanceId) {
-      return;
-    }
-    return guestViewInternal.setAllowTransparency(this.webViewImpl.guestInstanceId, this.getValue());
-  }
-}
-
 // Attribute used to define the demension limits of autosizing.
 class AutosizeDimensionAttribute extends WebViewAttribute {
   constructor(name, webViewImpl) {
@@ -298,7 +284,6 @@ class BlinkFeaturesAttribute extends WebViewAttribute {
 // Sets up all of the webview attributes.
 WebViewImpl.prototype.setupWebViewAttributes = function() {
   this.attributes = {};
-  this.attributes[webViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY] = new AllowTransparencyAttribute(this);
   this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE] = new AutosizeAttribute(this);
   this.attributes[webViewConstants.ATTRIBUTE_PARTITION] = new PartitionAttribute(this);
   this.attributes[webViewConstants.ATTRIBUTE_SRC] = new SrcAttribute(this);
index de2a571f5d5fc15df44c7d3acbf98bdf609f6a4d..297941aa801244f84d72fa88ad3cdcc31d30aaad 100644 (file)
@@ -1,6 +1,5 @@
 module.exports = {
   // Attributes.
-  ATTRIBUTE_ALLOWTRANSPARENCY: 'allowtransparency',
   ATTRIBUTE_AUTOSIZE: 'autosize',
   ATTRIBUTE_MAXHEIGHT: 'maxheight',
   ATTRIBUTE_MAXWIDTH: 'maxwidth',