Bug 1403077 - Part 2: Add two test-only helper functions to access the stylo blocklist. r=heycam, a=ritu
authorJeremy Chen <jeremychen@mozilla.com>
Wed, 11 Oct 2017 20:57:00 -0400
changeset 432432 1059f19c81364d89cbdfedcacf50e06998d87e7d
parent 432431 c2c10508ec8d9e50eba1db0137d4509fe7d9af19
child 432433 f4ba99b411837e4b16b134cbab5bcc355ddd6b22
push id7953
push userryanvm@gmail.com
push dateThu, 12 Oct 2017 14:05:58 +0000
treeherdermozilla-beta@f4ba99b41183 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam, ritu
bugs1403077
milestone57.0
Bug 1403077 - Part 2: Add two test-only helper functions to access the stylo blocklist. r=heycam, a=ritu In the current blocklist implementation, we read the stylo blocklist from the user preferences very early and only once, even earlier than the test preferences updating happens. So, to be able to test the functionality of the stylo blocklist, we add these two nsIDOMWindowUtils APIs to be able to add/remove a mock domain to the existing blocklist. MozReview-Commit-ID: 1iRnGmyTJgC
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/base/nsIDOMWindowUtils.idl
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -4528,16 +4528,34 @@ nsDOMWindowUtils::EnsureDirtyRootFrame()
 NS_IMETHODIMP
 nsDOMWindowUtils::GetIsStyledByServo(bool* aStyledByServo)
 {
   nsIDocument* doc = GetDocument();
   *aStyledByServo = doc && doc->IsStyledByServo();
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsDOMWindowUtils::AddToStyloBlocklist(const nsACString& aBlockedDomain)
+{
+#ifdef MOZ_STYLO
+  nsLayoutUtils::AddToStyloBlocklist(aBlockedDomain);
+#endif
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsDOMWindowUtils::RemoveFromStyloBlocklist(const nsACString& aBlockedDomain)
+{
+#ifdef MOZ_STYLO
+  nsLayoutUtils::RemoveFromStyloBlocklist(aBlockedDomain);
+#endif
+  return NS_OK;
+}
+
 NS_INTERFACE_MAP_BEGIN(nsTranslationNodeList)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
   NS_INTERFACE_MAP_ENTRY(nsITranslationNodeList)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_ADDREF(nsTranslationNodeList)
 NS_IMPL_RELEASE(nsTranslationNodeList)
 
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -2048,16 +2048,30 @@ interface nsIDOMWindowUtils : nsISupport
 
   /**
    * Whether the current document is styled by Servo's style engine.
    *
    * This calls nsIDocument::IsStyledByServo().
    */
   readonly attribute boolean isStyledByServo;
 
+  /**
+   * Add a domain to the existing stylo blocklist.
+   *
+   * This calls nsLayoutUtils::AddToStyloBlocklist().
+   */
+  void addToStyloBlocklist(in ACString aBlockedDomain);
+
+  /**
+   * Remove a domain from the existing stylo blocklist.
+   *
+   * This calls nsLayoutUtils::RemoveFromStyloBlocklist().
+   */
+  void removeFromStyloBlocklist(in ACString aBlockedDomain);
+
   // These consts are only for testing purposes.
   const long DEFAULT_MOUSE_POINTER_ID = 0;
   const long DEFAULT_PEN_POINTER_ID   = 1;
   const long DEFAULT_TOUCH_POINTER_ID = 2;
 
   // Match WidgetMouseEventBase::buttonType.
   const long MOUSE_BUTTON_LEFT_BUTTON   = 0;
   const long MOUSE_BUTTON_MIDDLE_BUTTON = 1;
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -7929,16 +7929,42 @@ nsLayoutUtils::IsInStyloBlocklist(nsIPri
   NS_SUCCEEDED(tldService->GetBaseDomain(codebaseURI, 0, baseDomain));
   for (const nsCString& domains : *sStyloBlocklist) {
     if (baseDomain.Equals(domains)) {
       return true;
     }
   }
   return false;
 }
+
+/* static */
+void
+nsLayoutUtils::AddToStyloBlocklist(const nsACString& aBlockedDomain)
+{
+  if (!sStyloBlocklist) {
+    sStyloBlocklist = new nsTArray<nsCString>;
+  }
+  sStyloBlocklist->AppendElement(aBlockedDomain);
+}
+
+/* static */
+void
+nsLayoutUtils::RemoveFromStyloBlocklist(const nsACString& aBlockedDomain)
+{
+  if (!sStyloBlocklist) {
+    return;
+  }
+
+  sStyloBlocklist->RemoveElement(aBlockedDomain);
+
+  if (sStyloBlocklist->IsEmpty()) {
+    delete sStyloBlocklist;
+    sStyloBlocklist = nullptr;
+  }
+}
 #endif
 
 /* static */
 void
 nsLayoutUtils::RegisterImageRequest(nsPresContext* aPresContext,
                                     imgIRequest* aRequest,
                                     bool* aRequestRegistered)
 {
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -2533,16 +2533,30 @@ public:
   /**
    * 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);
+
+  /**
+   * Add aBlockedDomain to 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 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);
 #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