Bug 1493563 - Part 10: Implement the per-document blocked states in terms of the content blocking log; r=baku
☠☠ backed out by 1681bd622c63 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 23 Sep 2018 02:40:27 -0400
changeset 494521 344298c73ee77f8e003717fad204e1cbb6da13eb
parent 494520 02b8b073f7d7007ce41c2fb71aab5ceafe5d371b
child 494522 1ce58f0045933cfa698ffed60d9792b76614c47b
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1493563
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1493563 - Part 10: Implement the per-document blocked states in terms of the content blocking log; r=baku It is arguably more accurate to implement these boolean getters in terms of whether we remember blocking anything in the category being asked about. This will allow us to correctly account for hiding the sheild icon when all currently blocked trackers become unblocked, for example. Differential Revision: https://phabricator.services.mozilla.com/D6600
dom/base/ContentBlockingLog.h
dom/base/nsDocument.cpp
dom/base/nsIDocument.h
--- a/dom/base/ContentBlockingLog.h
+++ b/dom/base/ContentBlockingLog.h
@@ -108,16 +108,32 @@ public:
       w.EndArray();
     }
 
     w.End();
 
     return buffer;
   }
 
+  bool HasBlockedAnyOfType(uint32_t aType)
+  {
+    for (auto iter = mLog.Iter(); !iter.Done(); iter.Next()) {
+      if (!iter.UserData()) {
+        continue;
+      }
+
+      for (auto& item: *iter.UserData()) {
+        if ((item.mType & aType) != 0) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
   void AddSizeOfExcludingThis(nsWindowSizes& aSizes) const
   {
     aSizes.mDOMOtherSize += mLog.ShallowSizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
 
     // Now add the sizes of each origin log queue.
     // The const_cast is needed because the nsTHashtable::Iterator interface is
     // not const-safe.  :-(
     for (auto iter = const_cast<OriginLogHashTable&>(mLog).Iter();
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1398,22 +1398,16 @@ nsIDocument::nsIDocument()
     mHasMixedActiveContentLoaded(false),
     mHasMixedActiveContentBlocked(false),
     mHasMixedDisplayContentLoaded(false),
     mHasMixedDisplayContentBlocked(false),
     mHasMixedContentObjectSubrequest(false),
     mHasCSP(false),
     mHasUnsafeEvalCSP(false),
     mHasUnsafeInlineCSP(false),
-    mHasTrackingContentBlocked(false),
-    mHasSlowTrackingContentBlocked(false),
-    mHasAllCookiesBlocked(false),
-    mHasTrackingCookiesBlocked(false),
-    mHasForeignCookiesBlocked(false),
-    mHasCookiesBlockedByPermission(false),
     mHasTrackingContentLoaded(false),
     mBFCacheDisallowed(false),
     mHasHadDefaultView(false),
     mStyleSheetChangeEventsEnabled(false),
     mIsSrcdocDocument(false),
     mDidDocumentOpen(false),
     mHasDisplayDocument(false),
     mFontFaceSetDirty(true),
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -987,126 +987,126 @@ public:
     return &mContentBlockingLog;
   }
 
   /**
    * Get tracking content blocked flag for this document.
    */
   bool GetHasTrackingContentBlocked()
   {
-    return mHasTrackingContentBlocked;
+    return mContentBlockingLog.HasBlockedAnyOfType(
+        nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT);
   }
 
   /**
    * Get slow tracking content blocked flag for this document.
    */
   bool GetHasSlowTrackingContentBlocked()
   {
-    return mHasSlowTrackingContentBlocked;
+    return mContentBlockingLog.HasBlockedAnyOfType(
+        nsIWebProgressListener::STATE_BLOCKED_SLOW_TRACKING_CONTENT);
   }
 
   /**
    * Get all cookies blocked flag for this document.
    */
   bool GetHasAllCookiesBlocked()
   {
-    return mHasAllCookiesBlocked;
+    return mContentBlockingLog.HasBlockedAnyOfType(
+        nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL);
   }
 
   /**
    * Get tracking cookies blocked flag for this document.
    */
   bool GetHasTrackingCookiesBlocked()
   {
-    return mHasTrackingCookiesBlocked;
+    return mContentBlockingLog.HasBlockedAnyOfType(
+        nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER);
   }
 
   /**
    * Get third-party cookies blocked flag for this document.
    */
   bool GetHasForeignCookiesBlocked()
   {
-    return mHasForeignCookiesBlocked;
+    return mContentBlockingLog.HasBlockedAnyOfType(
+        nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN);
   }
 
   /**
    * Get cookies blocked by site permission flag for this document.
    */
   bool GetHasCookiesBlockedByPermission()
   {
-    return mHasCookiesBlockedByPermission;
+    return mContentBlockingLog.HasBlockedAnyOfType(
+        nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION);
   }
 
   /**
    * Set the tracking content blocked flag for this document.
    */
   void SetHasTrackingContentBlocked(bool aHasTrackingContentBlocked,
                                     const nsAString& aOriginBlocked)
   {
-    mHasTrackingContentBlocked = aHasTrackingContentBlocked;
     RecordContentBlockingLog(aOriginBlocked,
                              nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT,
                              aHasTrackingContentBlocked);
   }
 
   /**
    * Set the slow tracking content blocked flag for this document.
    */
   void SetHasSlowTrackingContentBlocked(bool aHasSlowTrackingContentBlocked,
                                         const nsAString& aOriginBlocked)
   {
-    mHasSlowTrackingContentBlocked = aHasSlowTrackingContentBlocked;
     RecordContentBlockingLog(aOriginBlocked,
                              nsIWebProgressListener::STATE_BLOCKED_SLOW_TRACKING_CONTENT,
                              aHasSlowTrackingContentBlocked);
   }
 
   /**
    * Set the all cookies blocked flag for this document.
    */
   void SetHasAllCookiesBlocked(bool aHasAllCookiesBlocked,
                                const nsAString& aOriginBlocked)
   {
-    mHasAllCookiesBlocked = aHasAllCookiesBlocked;
     RecordContentBlockingLog(aOriginBlocked,
                              nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL,
                              aHasAllCookiesBlocked);
   }
 
   /**
    * Set the tracking cookies blocked flag for this document.
    */
   void SetHasTrackingCookiesBlocked(bool aHasTrackingCookiesBlocked,
                                     const nsAString& aOriginBlocked)
   {
-    mHasTrackingCookiesBlocked = aHasTrackingCookiesBlocked;
     RecordContentBlockingLog(aOriginBlocked,
                              nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER,
                              aHasTrackingCookiesBlocked);
   }
 
   /**
    * Set the third-party cookies blocked flag for this document.
    */
   void SetHasForeignCookiesBlocked(bool aHasForeignCookiesBlocked,
                                    const nsAString& aOriginBlocked)
   {
-    mHasForeignCookiesBlocked = aHasForeignCookiesBlocked;
     RecordContentBlockingLog(aOriginBlocked,
                              nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN,
                              aHasForeignCookiesBlocked);
   }
 
   /**
    * Set the cookies blocked by site permission flag for this document.
    */
   void SetHasCookiesBlockedByPermission(bool aHasCookiesBlockedByPermission,
                                         const nsAString& aOriginBlocked)
   {
-    mHasCookiesBlockedByPermission = aHasCookiesBlockedByPermission;
     RecordContentBlockingLog(aOriginBlocked,
                              nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION,
                              aHasCookiesBlockedByPermission);
   }
 
   /**
    * Get tracking content loaded flag for this document.
    */
@@ -4185,34 +4185,16 @@ protected:
   bool mHasCSP : 1;
 
   // True if a document load has a CSP with unsafe-eval attached.
   bool mHasUnsafeEvalCSP : 1;
 
   // True if a document load has a CSP with unsafe-inline attached.
   bool mHasUnsafeInlineCSP : 1;
 
-  // True if a document has blocked Tracking Content
-  bool mHasTrackingContentBlocked : 1;
-
-  // True if a document has blocked Slow Tracking Content
-  bool mHasSlowTrackingContentBlocked : 1;
-
-  // True if a document has blocked All Cookies
-  bool mHasAllCookiesBlocked : 1;
-
-  // True if a document has blocked Tracking Cookies
-  bool mHasTrackingCookiesBlocked : 1;
-
-  // True if a document has blocked Foreign Cookies
-  bool mHasForeignCookiesBlocked : 1;
-
-  // True if a document has blocked Cookies By Site Permission
-  bool mHasCookiesBlockedByPermission : 1;
-
   // True if a document has loaded Tracking Content
   bool mHasTrackingContentLoaded : 1;
 
   // True if DisallowBFCaching has been called on this document.
   bool mBFCacheDisallowed : 1;
 
   bool mHasHadDefaultView : 1;