commit 99ae537386ee60bc0340afd90d1897c21f6ff094
parent 10c182547bc367bc83c30055471d43cb558fb723
Author: Sandor Molnar <smolnar@mozilla.com>
Date: Mon, 15 Dec 2025 23:52:17 +0200
Revert "Bug 2006091 - Only use preferred-color-scheme override explicitly on our browsing context. r=jwatt" for causing mochitest failures @ test_emulate_color_scheme.html
This reverts commit 2ade44471efb1e2d65ee81c5c112bee7547c823c.
Diffstat:
3 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp
@@ -917,10 +917,13 @@ void nsPresContext::RecomputeBrowsingContextDependentData() {
auto* top = browsingContext->Top();
SetColorSchemeOverride([&] {
auto overriden = top->PrefersColorSchemeOverride();
- if (browsingContext == top &&
- overriden != PrefersColorSchemeOverride::None) {
+ if (overriden != PrefersColorSchemeOverride::None) {
return overriden;
}
+ if (!StaticPrefs::
+ layout_css_iframe_embedder_prefers_color_scheme_content_enabled()) {
+ return top->GetEmbedderColorSchemes().mPreferred;
+ }
return browsingContext->GetEmbedderColorSchemes().mPreferred;
}());
diff --git a/layout/base/tests/test_emulate_color_scheme.html b/layout/base/tests/test_emulate_color_scheme.html
@@ -12,8 +12,6 @@
}
</style>
<div id="test"></div>
-<iframe id="light-iframe" style="color-scheme: light"></iframe>
-<iframe id="dark-iframe" style="color-scheme: dark"></iframe>
<script>
function colorId() {
// Gets the middle number of the rgb(0, x, 0) color.
@@ -23,32 +21,20 @@ function colorId() {
return id;
}
-function iframeIsDark(id) {
- return document.getElementById(id).contentWindow.matchMedia("(prefers-color-scheme: dark)").matches;
-}
-
-add_task(function() {
+{
let bc = SpecialPowers.wrap(window).browsingContext.top;
ok('prefersColorSchemeOverride' in bc, "API should exist");
is(bc.prefersColorSchemeOverride, "none", "Override shouldn't be active.");
- ok(iframeIsDark("dark-iframe"), "Dark iframe is dark");
- ok(!iframeIsDark("light-iframe"), "Light iframe is light");
let originalColor = colorId();
bc.prefersColorSchemeOverride = "light";
is(colorId(), 1, "Light emulation works");
- ok(iframeIsDark("dark-iframe"), "Dark iframe still dark");
- ok(!iframeIsDark("light-iframe"), "Light iframe still light");
-
bc.prefersColorSchemeOverride = "dark";
is(colorId(), 2, "Dark emulation works");
- ok(iframeIsDark("dark-iframe"), "Dark iframe still dark");
- ok(!iframeIsDark("light-iframe"), "Light iframe still light");
-
bc.prefersColorSchemeOverride = "none";
is(colorId(), originalColor, "Clearing the override works");
-});
+}
</script>
diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml
@@ -10015,6 +10015,13 @@
value: false
mirror: always
+# This pref controls whether the `prefers-color-scheme` value of iframes images
+# reacts to the embedder `color-scheme` in content.
+- name: layout.css.iframe-embedder-prefers-color-scheme.content.enabled
+ type: RelaxedAtomicBool
+ value: true
+ mirror: always
+
# Controls the transparency of the initial about:blank document. Generally you
# don't ever want a white flash in dark mode, but due to backwards compat we
# have some extra control over this, for now at least.