Bug 1574111 - Improve the definition of ThirdPartyCookies.isDetected. r=johannh
authorNihanth Subramanya <nhnt11@gmail.com>
Fri, 30 Aug 2019 14:19:43 +0000
changeset 551379 6e6f9cf6ea5861630bf0570ae6667660b583bc70
parent 551378 9e00286ac2a6b8953e216dbf904fa2aa5914853f
child 551380 a07e1432deaab8acf7a4a090f2365cfcd86c5d22
push id11865
push userbtara@mozilla.com
push dateMon, 02 Sep 2019 08:54:37 +0000
treeherdermozilla-beta@37f59c4671b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1574111
milestone70.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 1574111 - Improve the definition of ThirdPartyCookies.isDetected. r=johannh Differential Revision: https://phabricator.services.mozilla.com/D43464
browser/base/content/browser-siteProtections.js
browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js
--- a/browser/base/content/browser-siteProtections.js
+++ b/browser/base/content/browser-siteProtections.js
@@ -660,30 +660,46 @@ var ThirdPartyCookies = {
       (state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_ALL) != 0 ||
       (state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_BY_PERMISSION) !=
         0 ||
       (state & Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_FOREIGN) != 0
     );
   },
 
   isDetected(state) {
-    return (state & Ci.nsIWebProgressListener.STATE_COOKIES_LOADED) != 0;
+    if (this.behaviorPref == Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER) {
+      // We don't have a state that specifically represents loaded tracker cookies,
+      // so use loaded tracking content as a proxy - it's not perfect but it
+      // yields fewer false-positives than the generic loaded cookies state.
+      return (
+        (state & Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT) != 0
+      );
+    }
+
+    // We don't have any proxies for the other cookie behaviors unfortunately.
+    return (
+      this.isBlocking(state) ||
+      (state & Ci.nsIWebProgressListener.STATE_COOKIES_LOADED) != 0
+    );
   },
 
   async updateSubView() {
     let contentBlockingLog = await gBrowser.selectedBrowser.getContentBlockingLog();
     contentBlockingLog = JSON.parse(contentBlockingLog);
 
     let categories = this._processContentBlockingLog(contentBlockingLog);
 
     this.subViewList.textContent = "";
 
     for (let category of ["firstParty", "trackers", "thirdParty"]) {
       let itemsToShow;
-      if (category == "trackers" && gProtectionsHandler.hasException) {
+      if (
+        category == "trackers" &&
+        (gProtectionsHandler.hasException || !this.enabled)
+      ) {
         itemsToShow = categories[category];
       } else {
         itemsToShow = categories[category].filter(
           info => !info.isAllowed || info.hasException
         );
       }
 
       if (!itemsToShow.length) {
--- a/browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js
@@ -33,17 +33,17 @@ add_task(async function setup() {
  * [7] - integer indicating number of expected cookie list items
  *       after loading a cookie-setting first party URL in an iframe
  */
 async function assertSitesListed(testCase) {
   let sitesListedTestCases = [
     [true, false, false, 4, 1, 1, 1, 1],
     [true, true, false, 5, 1, 1, 2, 2],
     [true, true, true, 6, 2, 2, 3, 3],
-    [false, false, false, 3, 0, 0, 0, 0],
+    [false, false, false, 3, 1, 1, 1, 1],
   ];
   let [
     trackersBlocked,
     thirdPartyBlocked,
     firstPartyBlocked,
     contentBlockingEventCount,
     listHeaderCount,
     cookieItemsCount1,