Commit d501b02a authored by Dan Beam's avatar Dan Beam Committed by Commit Bot

WebUI Dark Mode: fix hole w/ "force light mode" code

WebContents::GetURL() wasn't the right place to query a URL
from when checking whether to override the webkit pref sent
to the RenderViewHost when creating a renderer.

Instead, use rvh->GetSiteInstance()->GetSiteUrl(), which is
correct at the time we need to query.

The reason for this code is to ensure that:

  @media (prefers-color-scheme: dark) {
    /* bunch of dark mode styles go here */
  }

Does not apply as we have code shared across different
platforms (i.e. Linux, Windows, Mac, ChromeOS, etc.).
Only Mac & Windows currently support dark mode (and hence,
are the only platforms in which all the web UI has been
audited and/or updated). So in order to change shared code
that also runs on Linux/CrOS, we put both light/dark style
into the CSS, but disallow the dark styles from running
on non-dark-mode-enabled-platforms (Linux, CrOS).

Bug: 1007892
Fixed: 1007892
Change-Id: I1076e48eaa160a23213e6873f1d857cf54935f42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1825936Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Dan Beam <dbeam@chromium.org>
Auto-Submit: Dan Beam <dbeam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702693}
parent 74a9c58d
...@@ -3337,13 +3337,13 @@ void ChromeContentBrowserClient::OverrideWebkitPrefs( ...@@ -3337,13 +3337,13 @@ void ChromeContentBrowserClient::OverrideWebkitPrefs(
// disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS
// explicitly uses light (instead of not dark), which is why we don't reset // explicitly uses light (instead of not dark), which is why we don't reset
// back to no-preference. https://crbug.com/965811 // back to no-preference. https://crbug.com/965811
if (contents && !base::FeatureList::IsEnabled(features::kWebUIDarkMode)) { if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
bool force_light = contents->GetURL().SchemeIs(content::kChromeUIScheme); const GURL url = rvh->GetSiteInstance()->GetSiteURL();
bool force_light = url.SchemeIs(content::kChromeUIScheme);
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
if (!force_light) { if (!force_light) {
force_light = force_light = url.SchemeIs(extensions::kExtensionScheme) &&
contents->GetURL().SchemeIs(extensions::kExtensionScheme) && url.host_piece() == extension_misc::kPdfExtensionId;
contents->GetURL().host_piece() == extension_misc::kPdfExtensionId;
} }
#endif #endif
if (force_light) if (force_light)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment