From 4fc73117c4188a2006bb48f0e1bd4b7d06477f7f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 23 Dec 2014 11:17:32 -0800 Subject: [PATCH] Tell the render widget to use transparent background. --- atom/browser/native_window.cc | 23 +++++++++++++++++++++++ atom/browser/native_window.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 5248f6bda816..f0261f274539 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -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) { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 06f7163862b5..0f3a8deb7be1 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -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_;