Bug 1505198 - Make sure the STATE_COOKIES_LOADED state is stored outside of the content blocking log r=baku
☠☠ backed out by bb4931442276 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 09 Nov 2018 13:45:12 +0000
changeset 501871 dbf610ddefe12d639e3d39881729a38bce871164
parent 501870 23849b2015ce4cd60c7123c742bc0a0ce8512f07
child 501872 4f04e189f2bbce09691a4877e45e3bf025402e4d
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1505198
milestone65.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 1505198 - Make sure the STATE_COOKIES_LOADED state is stored outside of the content blocking log r=baku Differential Revision: https://phabricator.services.mozilla.com/D11143
dom/base/ContentBlockingLog.h
toolkit/components/antitracking/test/browser/browser_subResources.js
--- a/dom/base/ContentBlockingLog.h
+++ b/dom/base/ContentBlockingLog.h
@@ -3,17 +3,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_ContentBlockingLog_h
 #define mozilla_dom_ContentBlockingLog_h
 
 #include "mozilla/JSONWriter.h"
+#include "mozilla/Maybe.h"
 #include "mozilla/StaticPrefs.h"
+#include "mozilla/Tuple.h"
 #include "mozilla/UniquePtr.h"
 #include "nsClassHashtable.h"
 #include "nsHashKeys.h"
 #include "nsReadableUtils.h"
 #include "nsTArray.h"
 #include "nsWindowSizes.h"
 
 namespace mozilla {
@@ -25,17 +27,17 @@ class ContentBlockingLog final
     uint32_t mType;
     uint32_t mRepeatCount;
     bool mBlocked;
   };
 
   // Each element is a tuple of (type, blocked, repeatCount). The type values
   // come from the blocking types defined in nsIWebProgressListener.
   typedef nsTArray<LogEntry> OriginLog;
-  typedef Pair<bool, OriginLog> OriginData;
+  typedef Tuple<bool, Maybe<bool>, OriginLog> OriginData;
   typedef nsClassHashtable<nsStringHashKey, OriginData> OriginDataHashTable;
 
   struct StringWriteFunc : public JSONWriteFunc
   {
     nsAString& mBuffer; // The lifetime of the struct must be bound to the buffer
     explicit StringWriteFunc(nsAString& aBuffer)
       : mBuffer(aBuffer)
     {}
@@ -54,20 +56,28 @@ public:
   {
     if (aOrigin.IsVoid()) {
       return;
     }
     auto entry = mLog.LookupForAdd(aOrigin);
     if (entry) {
       auto& data = entry.Data();
       if (aType == nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
-        data->first() = aBlocked;
+        Get<0>(*data) = aBlocked;
         return;
       }
-      auto& log = data->second();
+      if (aType == nsIWebProgressListener::STATE_COOKIES_LOADED) {
+        if (Get<1>(*data).isSome()) {
+          Get<1>(*data).ref() = aBlocked;
+        } else {
+          Get<1>(*data).emplace(aBlocked);
+        }
+        return;
+      }
+      auto& log = Get<2>(*data);
       if (!log.IsEmpty()) {
         auto& last = log.LastElement();
         if (last.mType == aType &&
             last.mBlocked == aBlocked) {
           ++last.mRepeatCount;
           // Don't record recorded events.  This helps compress our log.
           return;
         }
@@ -75,21 +85,27 @@ public:
       if (log.Length() ==
             std::max(1u, StaticPrefs::browser_contentblocking_originlog_length())) {
         // Cap the size at the maximum length adjustable by the pref
         log.RemoveElementAt(0);
       }
       log.AppendElement(LogEntry{aType, 1u, aBlocked});
     } else {
       entry.OrInsert([=] {
-        nsAutoPtr<OriginData> data(new OriginData(false, OriginLog()));
+        nsAutoPtr<OriginData> data(new OriginData(false, Maybe<bool>(), OriginLog()));
         if (aType == nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
-          data->first() = true;
+          Get<0>(*data) = aBlocked;
+        } else if (aType == nsIWebProgressListener::STATE_COOKIES_LOADED) {
+          if (Get<1>(*data).isSome()) {
+            Get<1>(*data).ref() = aBlocked;
+          } else {
+            Get<1>(*data).emplace(aBlocked);
+          }
         } else {
-          data->second().AppendElement(LogEntry{aType, 1u, aBlocked});
+          Get<2>(*data).AppendElement(LogEntry{aType, 1u, aBlocked});
         }
         return data.forget();
       });
     }
   }
 
   nsAutoString Stringify()
   {
@@ -102,26 +118,35 @@ public:
       if (!iter.UserData()) {
         w.StartArrayProperty(NS_ConvertUTF16toUTF8(iter.Key()).get(), w.SingleLineStyle);
         w.EndArray();
         continue;
       }
 
       w.StartArrayProperty(NS_ConvertUTF16toUTF8(iter.Key()).get(), w.SingleLineStyle);
       auto& data = *iter.UserData();
-      if (data.first()) {
+      if (Get<0>(data)) {
         w.StartArrayElement(w.SingleLineStyle);
         {
           w.IntElement(nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT);
           w.BoolElement(true); // blocked
           w.IntElement(1);     // repeat count
         }
         w.EndArray();
       }
-      for (auto& item: data.second()) {
+      if (Get<1>(data).isSome()) {
+        w.StartArrayElement(w.SingleLineStyle);
+        {
+          w.IntElement(nsIWebProgressListener::STATE_COOKIES_LOADED);
+          w.BoolElement(Get<1>(data).value()); // blocked
+          w.IntElement(1);                     // repeat count
+        }
+        w.EndArray();
+      }
+      for (auto& item: Get<2>(data)) {
         w.StartArrayElement(w.SingleLineStyle);
         {
           w.IntElement(item.mType);
           w.BoolElement(item.mBlocked);
           w.IntElement(item.mRepeatCount);
         }
         w.EndArray();
       }
@@ -136,21 +161,26 @@ public:
   bool HasBlockedAnyOfType(uint32_t aType)
   {
     for (auto iter = mLog.Iter(); !iter.Done(); iter.Next()) {
       if (!iter.UserData()) {
         continue;
       }
 
       if (aType == nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
-        if (iter.UserData()->first()) {
+        if (Get<0>(*iter.UserData())) {
           return true;
         }
+      } else if (aType == nsIWebProgressListener::STATE_COOKIES_LOADED) {
+        if (Get<1>(*iter.UserData()).isSome()) {
+          return Get<1>(*iter.UserData()).value();
+        }
+        return true; // true means blocked, aka not loaded any cookies
       } else {
-        for (auto& item: iter.UserData()->second()) {
+        for (auto& item: Get<2>(*iter.UserData())) {
           if ((item.mType & aType) != 0) {
             return true;
           }
         }
       }
     }
     return false;
   }
@@ -161,17 +191,17 @@ public:
 
     // 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<OriginDataHashTable&>(mLog).Iter();
          !iter.Done(); iter.Next()) {
       if (iter.UserData()) {
         aSizes.mDOMOtherSize +=
-          iter.UserData()->second().ShallowSizeOfIncludingThis(aSizes.mState.mMallocSizeOf);
+          Get<2>(*iter.UserData()).ShallowSizeOfIncludingThis(aSizes.mState.mMallocSizeOf);
       }
     }
   }
 
 private:
   OriginDataHashTable mLog;
 };
 
--- a/toolkit/components/antitracking/test/browser/browser_subResources.js
+++ b/toolkit/components/antitracking/test/browser/browser_subResources.js
@@ -182,33 +182,21 @@ add_task(async function() {
     ok(item[2] >= 1,
        "Correct repeat count reported");
   };
 
   let log = JSON.parse(await browser.getContentBlockingLog());
   for (let trackerOrigin in log) {
     is(trackerOrigin, TEST_3RD_PARTY_DOMAIN, "Correct tracker origin must be reported");
     let originLog = log[trackerOrigin];
-    is(originLog.length, 16, "We should have 16 entries in the compressed log");
+    is(originLog.length, 4, "We should have 4 entries in the compressed log");
     expectTrackerFound(originLog[0]);
     expectCookiesLoaded(originLog[1]);
     expectTrackerBlocked(originLog[2], true);
-    expectCookiesLoaded(originLog[3]);
-    expectTrackerBlocked(originLog[4], true);
-    expectCookiesLoaded(originLog[5]);
-    expectTrackerBlocked(originLog[6], true);
-    expectCookiesLoaded(originLog[7]);
-    expectTrackerBlocked(originLog[8], true);
-    expectCookiesLoaded(originLog[9]);
-    expectTrackerBlocked(originLog[10], true);
-    expectCookiesLoaded(originLog[11]);
-    expectTrackerBlocked(originLog[12], true);
-    expectCookiesLoaded(originLog[13]);
-    expectTrackerBlocked(originLog[14], false);
-    expectCookiesLoaded(originLog[15]);
+    expectTrackerBlocked(originLog[3], false);
   }
 
   info("Removing the tab");
   BrowserTestUtils.removeTab(tab);
 });
 
 add_task(async function() {
   info("Cleaning up.");