]> khamidou — GitHub mirrors - electron.git/commitdiff
Tell the render widget to use transparent background.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 23 Dec 2014 19:17:32 +0000 (11:17 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 23 Dec 2014 19:17:32 +0000 (11:17 -0800)
atom/browser/native_window.cc
atom/browser/native_window.h

index 5248f6bda816b7ac29c96b53f8d09c375a8b4642..f0261f274539e8c519a570e5c636e62931ce0836 100644 (file)
@@ -32,6 +32,7 @@
 #include "brightray/browser/inspectable_web_contents_view.h"
 #include "chrome/browser/printing/print_view_manager_basic.h"
 #include "chrome/browser/ui/browser_dialogs.h"
+#include "content/browser/renderer_host/render_widget_host_impl.h"
 #include "content/public/browser/devtools_agent_host.h"
 #include "content/public/browser/invalidate_type.h"
 #include "content/public/browser/navigation_entry.h"
@@ -60,6 +61,10 @@ using content::NavigationEntry;
 using content::RenderWidgetHostView;
 using content::RenderWidgetHost;
 
+namespace content {
+CONTENT_EXPORT extern bool g_use_transparent_window;
+}
+
 namespace atom {
 
 namespace {
@@ -88,6 +93,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
                            const mate::Dictionary& options)
     : content::WebContentsObserver(web_contents),
       has_frame_(true),
+      transparent_(false),
       enable_larger_than_screen_(false),
       is_closed_(false),
       node_integration_(true),
@@ -99,9 +105,14 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
   printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
 
   options.Get(switches::kFrame, &has_frame_);
+  options.Get(switches::kTransparent, &transparent_);
   options.Get(switches::kEnableLargerThanScreen, &enable_larger_than_screen_);
   options.Get(switches::kNodeIntegration, &node_integration_);
 
+  // Tell the content module to initialize renderer widget with transparent
+  // mode.
+  content::g_use_transparent_window = transparent_;
+
   // Read icon before window is created.
   options.Get(switches::kIcon, &icon_);
 
@@ -560,6 +571,18 @@ content::JavaScriptDialogManager* NativeWindow::GetJavaScriptDialogManager() {
   return dialog_manager_.get();
 }
 
+void NativeWindow::RenderViewCreated(
+    content::RenderViewHost* render_view_host) {
+  if (!transparent_)
+    return;
+
+  content::RenderWidgetHostImpl* impl = content::RenderWidgetHostImpl::FromID(
+      render_view_host->GetProcess()->GetID(),
+      render_view_host->GetRoutingID());
+  if (impl)
+    impl->SetBackgroundOpaque(false);
+}
+
 void NativeWindow::BeforeUnloadFired(content::WebContents* tab,
                                      bool proceed,
                                      bool* proceed_to_fire_unload) {
index 06f7163862b5668e7663747b09ed46430dfe70fd..0f3a8deb7be11e0e33c73398f69896160bf3f2eb 100644 (file)
@@ -269,6 +269,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   void RendererResponsive(content::WebContents* source) override;
 
   // Implementations of content::WebContentsObserver.
+  void RenderViewCreated(content::RenderViewHost* render_view_host) override;
   void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
   bool OnMessageReceived(const IPC::Message& message) override;
 
@@ -287,6 +288,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   // Whether window has standard frame.
   bool has_frame_;
 
+  // Whether window is transparent.
+  bool transparent_;
+
   // Whether window can be resized larger than screen.
   bool enable_larger_than_screen_;