Bug 1408235 part 1 - Move stylo checking logic into a separate function. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Fri, 20 Oct 2017 17:14:41 +1100
changeset 684294 024a940349c480c20d967e4e1e4ddd03fd4f05b3
parent 683738 a5e2ef4ba187a3eaf89b4c6af276a904b5ec1bbc
child 684295 67afcbb4d6f80a831c8629231427f9c6133c5433
push id85584
push userxquan@mozilla.com
push dateFri, 20 Oct 2017 23:57:36 +0000
reviewersheycam
bugs1408235
milestone58.0a1
Bug 1408235 part 1 - Move stylo checking logic into a separate function. r?heycam MozReview-Commit-ID: 9fOyC4QUSDA
dom/base/nsDocument.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -13610,59 +13610,29 @@ nsIDocument::ReportHasScrollLinkedEffect
   }
   mHasScrollLinkedEffect = true;
   nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
                                   NS_LITERAL_CSTRING("Async Pan/Zoom"),
                                   this, nsContentUtils::eLAYOUT_PROPERTIES,
                                   "ScrollLinkedEffectFound2");
 }
 
-#ifdef MOZ_STYLO
-// URL-based blacklist for stylo.
-static bool
-ShouldUseGeckoBackend(nsIURI* aDocumentURI)
-{
-  if (!aDocumentURI) {
-    return false;
-  }
-  bool isScheme = false;
-  if (NS_SUCCEEDED(aDocumentURI->SchemeIs("about", &isScheme))) {
-    nsAutoCString path;
-    aDocumentURI->GetFilePath(path);
-    // about:reader requires support of :scope pseudo-class so we have
-    // to use Gecko backend for now. See bug 1402094.
-    // This should be fixed by bug 1204818.
-    if (path.EqualsLiteral("reader")) {
-      return true;
-    }
-  }
-  return false;
-}
-#endif // MOZ_STYLO
-
 void
 nsIDocument::UpdateStyleBackendType()
 {
   MOZ_ASSERT(mStyleBackendType == StyleBackendType::None,
              "no need to call UpdateStyleBackendType now");
 
   // Assume Gecko by default.
   mStyleBackendType = StyleBackendType::Gecko;
 
 #ifdef MOZ_STYLO
-  if (nsLayoutUtils::StyloEnabled()) {
-    // Disable stylo only for system principal. Other principals 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(NodePrincipal()) &&
-        !ShouldUseGeckoBackend(mDocumentURI) &&
-        !nsLayoutUtils::IsInStyloBlocklist(NodePrincipal())) {
-      mStyleBackendType = StyleBackendType::Servo;
-    }
+  if (nsLayoutUtils::StyloEnabled() &&
+      nsLayoutUtils::ShouldUseStylo(mDocumentURI, NodePrincipal())) {
+    mStyleBackendType = StyleBackendType::Servo;
   }
 #endif
 }
 
 /**
  * Retrieves the classification of the Flash plugins in the document based on
  * the classification lists. We perform AsyncInitFlashClassification on
  * StartDocumentLoad() and the result may not be initialized when this function
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -8019,16 +8019,48 @@ nsLayoutUtils::Shutdown()
 
   // so the cached initial quotes array doesn't appear to be a leak
   nsStyleList::Shutdown();
 }
 
 #ifdef MOZ_STYLO
 /* 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)) {
+    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);
+      // about:reader requires support of scoped style, so we have to
+      // use Gecko backend for now. See bug 1402094.
+      // This should be fixed by bug 1204818.
+      if (path.EqualsLiteral("reader")) {
+        return false;
+      }
+    }
+  }
+  // Check the stylo block list.
+  if (IsInStyloBlocklist(aPrincipal)) {
+    return false;
+  }
+  return true;
+}
+
+/* static */
+bool
 nsLayoutUtils::IsInStyloBlocklist(nsIPrincipal* aPrincipal)
 {
   if (!sStyloBlocklist) {
     return false;
   }
 
   // Note that a non-codebase principal (eg the system principal) will return
   // a null URI.
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -2555,16 +2555,22 @@ public:
     return sInvalidationDebuggingIsEnabled || getenv("MOZ_DUMP_INVALIDATION") != 0;
   }
 
   static void Initialize();
   static void Shutdown();
 
 #ifdef MOZ_STYLO
   /**
+   * Return whether stylo should be used for a given document URI and
+   * principal.
+   */
+  static bool ShouldUseStylo(nsIURI* aDocumentURI, nsIPrincipal* aPrincipal);
+
+  /**
    * Principal-based blocklist for stylo.
    * Check if aPrincipal is blocked by stylo's blocklist and should fallback to
    * use Gecko's style backend. Note that using a document's principal rather
    * than the document URI will let us piggy-back off the existing principal
    * relationships and symmetries.
    */
   static bool IsInStyloBlocklist(nsIPrincipal* aPrincipal);
 
@@ -2576,16 +2582,20 @@ public:
   static void AddToStyloBlocklist(const nsACString& aBlockedDomain);
 
   /**
    * Remove aBlockedDomain from the existing stylo blocklist, i.e., sStyloBlocklist.
    * This function is exposed to nsDOMWindowUtils and only for testing purpose.
    * So, NEVER use this in any other cases.
    */
   static void RemoveFromStyloBlocklist(const nsACString& aBlockedDomain);
+#else
+  static bool ShouldUseStylo(nsIURI* aDocumentURI, nsIPrincipal* aPrincipal) {
+    return false;
+  }
 #endif
 
   /**
    * Register an imgIRequest object with a refresh driver.
    *
    * @param aPresContext The nsPresContext whose refresh driver we want to
    *        register with.
    * @param aRequest A pointer to the imgIRequest object which the client wants