Bug 1411532 part 1 - Add a pref for enabling stylo on chrome documents. r=bz
authorXidorn Quan <me@upsuper.org>
Fri, 27 Oct 2017 15:07:51 +1100
changeset 688131 49750002c7a67b6e8765dda8d75cbfa2c1fc00dc
parent 688130 4fb672bad577126973c1192a94b510449e701123
child 688132 af22292a7122cb6ca9aa3e43a93dd82f6b55917c
push id86669
push userhikezoe@mozilla.com
push dateSat, 28 Oct 2017 10:13:18 +0000
reviewersbz
bugs1411532
milestone58.0a1
Bug 1411532 part 1 - Add a pref for enabling stylo on chrome documents. r=bz MozReview-Commit-ID: 7Zbh4Mf43xC
dom/ipc/ContentPrefs.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
modules/libpref/init/all.js
--- a/dom/ipc/ContentPrefs.cpp
+++ b/dom/ipc/ContentPrefs.cpp
@@ -117,16 +117,17 @@ const char* mozilla::dom::ContentPrefs::
   "javascript.options.throw_on_debuggee_would_run",
   "javascript.options.wasm",
   "javascript.options.wasm_baselinejit",
   "javascript.options.wasm_ionjit",
   "javascript.options.werror",
   "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
   "layout.idle_period.required_quiescent_frames",
   "layout.idle_period.time_limit",
   "layout.interruptible-reflow.enabled",
   "mathml.disabled",
   "media.apple.forcevda",
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -8147,17 +8147,18 @@ nsLayoutUtils::Shutdown()
 /* static */
 bool
 nsLayoutUtils::ShouldUseStylo(nsIURI* aDocumentURI, nsIPrincipal* aPrincipal)
 {
   // Disable stylo for system principal because XUL hasn't been fully
   // 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.
   if (aDocumentURI) {
     bool isAbout = false;
     if (NS_SUCCEEDED(aDocumentURI->SchemeIs("about", &isAbout)) && isAbout) {
       nsAutoCString path;
       aDocumentURI->GetFilePath(path);
@@ -8227,16 +8228,31 @@ nsLayoutUtils::RemoveFromStyloBlocklist(
 
   sStyloBlocklist->RemoveElement(aBlockedDomain);
 
   if (sStyloBlocklist->IsEmpty()) {
     delete sStyloBlocklist;
     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 */
 void
 nsLayoutUtils::RegisterImageRequest(nsPresContext* aPresContext,
                                     imgIRequest* aRequest,
                                     bool* aRequestRegistered)
 {
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -2521,23 +2521,43 @@ public:
   static bool StyloEnabled() {
 #ifdef MOZ_STYLO
     return sStyloEnabled && StyloSupportedInCurrentProcess();
 #else
     return false;
 #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;
   }
 
   static uint32_t QuiescentFramesBeforeIdlePeriod() {
     return sQuiescentFramesBeforeIdlePeriod;
   }
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5813,16 +5813,21 @@ pref("media.block-autoplay-until-in-fore
 // XXX: We should flip this pref to true once the blocked_domains is non-empty.
 pref("layout.css.stylo-blocklist.enabled", false);
 pref("layout.css.stylo-blocklist.blocked_domains", "");
 #ifdef MOZ_STYLO_ENABLE
 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
 // If a request is mixed-content, send an HSTS priming request to attempt to
 // see if it is available over HTTPS.
 // Don't change the order of evaluation of mixed-content and HSTS upgrades in
 // order to be most compatible with current standards in Release
 pref("security.mixed_content.send_hsts_priming", false);