8000 fix: set WebContents background color ubiquitously by codebytere · Pull Request #27945 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: set WebContents background color ubiquitously #27945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,19 @@ void WebContents::BeforeUnloadFired(bool proceed,
void WebContents::RenderViewCreated(content::RenderViewHost* render_view_host) {
if (!background_throttling_)
render_view_host->SetSchedulerThrottling(false);

// Set the background color of RenderWidgetHostView.
auto* const view = web_contents()->GetRenderWidgetHostView();
auto* web_preferences = WebContentsPreferences::From(web_contents());
if (view && web_preferences) {
std::string color_name;
if (web_preferences->GetPreference(options::kBackgroundColor,
&color_name)) {
view->SetBackgroundColor(ParseHexColor(color_name));
} else {
view->SetBackgroundColor(SK_ColorTRANSPARENT);
}
}
}

void WebContents::RenderFrameCreated(
Expand Down Expand Up @@ -1686,21 +1699,6 @@ void WebContents::LoadURL(const GURL& url,
// It's not safe to assume that |this| points to valid memory at this point.
if (!weak_this)
return;

// Set the background color of RenderWidgetHostView.
// We have to call it right after LoadURL because the RenderViewHost is only
// created after loading a page.
auto* const view = weak_this->web_contents()->GetRenderWidgetHostView();
if (view) {
auto* web_preferences = WebContentsPreferences::From(web_contents());
std::string color_name;
if (web_preferences->GetPreference(options::kBackgroundColor,
&color_name)) {
view->SetBackgroundColor(ParseHexColor(color_name));
} else {
view->SetBackgroundColor(SK_ColorTRANSPARENT);
}
}
}

void WebContents::DownloadURL(const GURL& url) {
Expand Down
0