From b84a178cebd3d193fa4cd9109855a9be7a2149f9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 14 Apr 2016 21:52:17 +0900 Subject: [PATCH] Set the backgroundColor of RenderWidgetHostView --- atom/browser/api/atom_api_web_contents.cc | 14 +++++++++++--- atom/browser/native_window_mac.mm | 11 ++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 81e2423a3519..6c9c1b58ea41 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -20,6 +20,7 @@ #include "atom/browser/web_view_guest_delegate.h" #include "atom/common/api/api_messages.h" #include "atom/common/api/event_emitter_caller.h" +#include "atom/common/color_util.h" #include "atom/common/mouse_util.h" #include "atom/common/native_mate_converters/blink_converter.h" #include "atom/common/native_mate_converters/callback.h" @@ -747,12 +748,19 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE; web_contents()->GetController().LoadURLWithParams(params); - // Set the background color of RenderViewHost to transparent so it doesn't - // override the background color set by the user. + // Set the background color of RenderWidgetHostView. // We have to call it right after LoadURL because the RenderViewHost is only // created after loading a page. const auto view = web_contents()->GetRenderWidgetHostView(); - view->SetBackgroundColor(SK_ColorTRANSPARENT); + WebContentsPreferences* web_preferences = + WebContentsPreferences::FromWebContents(web_contents()); + std::string color_name; + if (web_preferences->web_preferences()->GetString(options::kBackgroundColor, + &color_name)) { + view->SetBackgroundColor(ParseHexColor(color_name)); + } else { + view->SetBackgroundColor(SK_ColorTRANSPARENT); + } // For the same reason we can only disable hidden here. const auto host = static_cast( diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 3c76cbe25a57..b24e828e578d 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -807,9 +807,14 @@ bool NativeWindowMac::IsKiosk() { } void NativeWindowMac::SetBackgroundColor(const std::string& color_name) { - base::ScopedCFTypeRef color = - skia::CGColorCreateFromSkColor(ParseHexColor(color_name)); - [[[window_ contentView] layer] setBackgroundColor:color]; + SkColor color = ParseHexColor(color_name); + base::ScopedCFTypeRef cgcolor = + skia::CGColorCreateFromSkColor(color); + [[[window_ contentView] layer] setBackgroundColor:cgcolor]; + + const auto view = web_contents()->GetRenderWidgetHostView(); + if (view) + view->SetBackgroundColor(color); } void NativeWindowMac::SetHasShadow(bool has_shadow) {