Skip to content

Commit

Permalink
Fix the timing of SetBackgroundColor (fixes issue chromiumembedded#2482)
Browse files Browse the repository at this point in the history
If the background color is set too early it won't be sent to renderer process.
Also force refresh of the background color for newly created popups.
  • Loading branch information
andytzeng authored and magreenblatt committed Oct 4, 2021
1 parent 0fd0d6f commit 1d9e261
Showing 3 changed files with 18 additions and 13 deletions.
4 changes: 0 additions & 4 deletions libcef/browser/alloy/alloy_content_browser_client.cc
Original file line number Diff line number Diff line change
@@ -944,10 +944,6 @@ void AlloyContentBrowserClient::OverrideWebkitPrefs(
renderer_prefs::PopulateWebPreferences(rvh, *prefs, base_background_color);

web_contents->SetPageBaseBackgroundColor(base_background_color);

if (rvh->GetWidget()->GetView()) {
rvh->GetWidget()->GetView()->SetBackgroundColor(base_background_color);
}
}

bool AlloyContentBrowserClient::OverrideWebPreferencesAfterNavigation(
22 changes: 18 additions & 4 deletions libcef/browser/browser_contents_delegate.cc
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "third_party/blink/public/mojom/favicon/favicon_url.mojom.h"
#include "third_party/blink/public/mojom/input/focus_type.mojom-blink.h"

@@ -45,11 +47,11 @@ void CefBrowserContentsDelegate::ObserveWebContents(
content::Source<content::NavigationController>(
&new_contents->GetController()));

// Make sure RenderFrameCreated is called at least one time.
// Make sure MaybeCreateFrame is called at least one time.
// Create the frame representation before OnAfterCreated is called for a new
// browser. Additionally, RenderFrameCreated is otherwise not called at all
// for new popup browsers.
RenderFrameCreated(new_contents->GetMainFrame());
// browser.
browser_info_->MaybeCreateFrame(new_contents->GetMainFrame(),
false /* is_guest_view */);
} else {
registrar_.reset();
}
@@ -235,6 +237,18 @@ bool CefBrowserContentsDelegate::HandleKeyboardEvent(
void CefBrowserContentsDelegate::RenderFrameCreated(
content::RenderFrameHost* render_frame_host) {
browser_info_->MaybeCreateFrame(render_frame_host, false /* is_guest_view */);
if (render_frame_host->GetParent() == nullptr) {
auto render_view_host = render_frame_host->GetRenderViewHost();
auto base_background_color = platform_delegate()->GetBackgroundColor();
if (browser_info_ && browser_info_->is_popup()) {
// force reset page base background color because popup window won't get
// the page base background from web_contents at the creation time
web_contents()->SetPageBaseBackgroundColor(SkColor());
web_contents()->SetPageBaseBackgroundColor(base_background_color);
}
render_view_host->GetWidget()->GetView()->SetBackgroundColor(
base_background_color);
}
}

void CefBrowserContentsDelegate::RenderFrameHostChanged(
5 changes: 0 additions & 5 deletions libcef/browser/chrome/chrome_content_browser_client_cef.cc
Original file line number Diff line number Diff line change
@@ -188,11 +188,6 @@ void ChromeContentBrowserClientCef::OverrideWebkitPrefs(
}

web_contents->SetPageBaseBackgroundColor(base_background_color);

auto rvh = web_contents->GetRenderViewHost();
if (rvh->GetWidget()->GetView()) {
rvh->GetWidget()->GetView()->SetBackgroundColor(base_background_color);
}
}

bool ChromeContentBrowserClientCef::WillCreateURLLoaderFactory(

0 comments on commit 1d9e261

Please sign in to comment.