diff --git a/dom/ipc/ContentPrefs.cpp b/dom/ipc/ContentPrefs.cpp index 9f67707af562c..2f2ae1b548242 100644 --- a/dom/ipc/ContentPrefs.cpp +++ b/dom/ipc/ContentPrefs.cpp @@ -122,6 +122,7 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "javascript.use_us_english_locale", "jsloader.shareGlobal", #ifdef MOZ_STYLO + "layout.css.servo.chrome.enabled", "layout.css.stylo-blocklist.blocked_domains", "layout.css.stylo-blocklist.enabled", #endif diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 38ae2d1e2c903..ff8807ff52fc5 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -8152,7 +8152,8 @@ nsLayoutUtils::ShouldUseStylo(nsIURI* aDocumentURI, nsIPrincipal* aPrincipal) // supported. Other principal aren't able to use XUL by default, and // the back door to enable XUL is mostly just for testing, which means // they don't matter, and we shouldn't respect them at the same time. - if (nsContentUtils::IsSystemPrincipal(aPrincipal)) { + if (!StyloChromeEnabled() && + nsContentUtils::IsSystemPrincipal(aPrincipal)) { return false; } // Check any internal page which we need to explicitly blacklist. @@ -8232,6 +8233,21 @@ nsLayoutUtils::RemoveFromStyloBlocklist(const nsACString& aBlockedDomain) sStyloBlocklist = nullptr; } } + +/* static */ +bool +nsLayoutUtils::StyloChromeEnabled() +{ + static bool sInitialized = false; + static bool sEnabled = false; + if (!sInitialized) { + // We intentionally don't allow dynamic toggling of this pref + // because it is rather risky to mix style backend in XUL. + sEnabled = Preferences::GetBool("layout.css.servo.chrome.enabled"); + sInitialized = true; + } + return sEnabled; +} #endif /* static */ diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index d471a96689917..50ad9b12a7f6b 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -2526,13 +2526,33 @@ class nsLayoutUtils #endif } - // Whether Stylo should be allowed to be enabled in this process. This - // returns true for content processes and the non-e10s parent process. + // Whether Stylo should be allowed to be enabled in this process. static bool StyloSupportedInCurrentProcess() { - return XRE_IsContentProcess() || - (XRE_IsParentProcess() && !XRE_IsE10sParentProcess()); +#ifdef MOZ_STYLO + if (XRE_IsContentProcess()) { + return true; + } + if (XRE_IsParentProcess()) { + // If Stylo is enabled for chrome document, we use it in all + // parent processes, regardless of whether it's e10s parent. + if (StyloChromeEnabled()) { + return true; + } + // Otherwise we only use stylo on non-e10s parent. + return !XRE_IsE10sParentProcess(); + } +#endif + // Stylo is not enabled for any other process. + MOZ_DIAGNOSTIC_ASSERT(false, "We should not be creating any document " + "in processes other than content and parent"); + return false; } +#ifdef MOZ_STYLO + // Whether Stylo should be used on chrome documents. + static bool StyloChromeEnabled(); +#endif + static uint32_t IdlePeriodDeadlineLimit() { return sIdlePeriodDeadlineLimit; } diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 995d65f3bfdaa..5a022d0d718f0 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -5818,6 +5818,11 @@ pref("layout.css.servo.enabled", true); #else pref("layout.css.servo.enabled", false); #endif +// Whether Stylo is enabled for chrome document? +// If Stylo is not enabled, this pref doesn't take any effect. +// Note that this pref is only read once when requested. Changing it +// at runtime may have no effect. +pref("layout.css.servo.chrome.enabled", false); #endif // HSTS Priming