Bug 1484876 - Part 2: Check the trackingprotection-pb permission in the channel classifier code instead of accessing nsIPrivateBrowsingTrackingProtectionWhitelist; r=francois
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 20 Aug 2018 19:46:58 -0400
changeset 487991 66519e95427ef0744b84e3dd292867ccb8c3a854
parent 487990 bddf9e4f6f3ab2c4ed2b9c4d64250319b957c5c0
child 487992 5ffff7652f8762a0fa411692b929316f8f36e756
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois
bugs1484876
milestone63.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 1484876 - Part 2: Check the trackingprotection-pb permission in the channel classifier code instead of accessing nsIPrivateBrowsingTrackingProtectionWhitelist; r=francois
netwerk/base/nsChannelClassifier.cpp
--- a/netwerk/base/nsChannelClassifier.cpp
+++ b/netwerk/base/nsChannelClassifier.cpp
@@ -17,17 +17,16 @@
 #include "nsIClassOfService.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
 #include "nsIHttpChannel.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsIIOService.h"
 #include "nsIParentChannel.h"
 #include "nsIPermissionManager.h"
-#include "nsIPrivateBrowsingTrackingProtectionWhitelist.h"
 #include "nsIProtocolHandler.h"
 #include "nsIScriptError.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsISecureBrowserUI.h"
 #include "nsISecurityEventSink.h"
 #include "nsISupportsPriority.h"
 #include "nsIURL.h"
 #include "nsIWebProgressListener.h"
@@ -482,54 +481,42 @@ nsChannelClassifier::ShouldEnableTrackin
     // Stuff the whole thing back into a URI for the permission manager.
     rv = ios->NewURI(escaped, nullptr, nullptr, getter_AddRefs(topWinURI));
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIPermissionManager> permMgr =
         do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    uint32_t permissions = nsIPermissionManager::UNKNOWN_ACTION;
-    rv = permMgr->TestPermission(topWinURI, "trackingprotection", &permissions);
-    NS_ENSURE_SUCCESS(rv, rv);
+    // Check both the normal mode and private browsing mode user override permissions.
+    const char* types[] = {
+      "trackingprotection",
+      "trackingprotection-pb"
+    };
 
-    if (permissions == nsIPermissionManager::ALLOW_ACTION) {
-      if (LOG_ENABLED()) {
-        nsCString chanSpec = chanURI->GetSpecOrDefault();
-        chanSpec.Truncate(std::min(chanSpec.Length(), sMaxSpecLength));
-        LOG(("nsChannelClassifier[%p]: User override on channel[%p] (%s) for %s",
-             this, aChannel, chanSpec.get(), escaped.get()));
-      }
-      mIsAllowListed = true;
-      *result = false;
-    } else {
-      *result = true;
-    }
-
-    // In Private Browsing Mode we also check against an in-memory list.
-    if (NS_UsePrivateBrowsing(aChannel)) {
-      nsCOMPtr<nsIPrivateBrowsingTrackingProtectionWhitelist> pbmtpWhitelist =
-          do_GetService(NS_PBTRACKINGPROTECTIONWHITELIST_CONTRACTID, &rv);
+    for (size_t i = 0; i < ArrayLength(types); ++i) {
+      uint32_t permissions = nsIPermissionManager::UNKNOWN_ACTION;
+      rv = permMgr->TestPermission(topWinURI, types[i], &permissions);
       NS_ENSURE_SUCCESS(rv, rv);
 
-      bool exists = false;
-      rv = pbmtpWhitelist->ExistsInAllowList(topWinURI, &exists);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      if (exists) {
-        mIsAllowListed = true;
+      if (permissions == nsIPermissionManager::ALLOW_ACTION) {
         if (LOG_ENABLED()) {
           nsCString chanSpec = chanURI->GetSpecOrDefault();
           chanSpec.Truncate(std::min(chanSpec.Length(), sMaxSpecLength));
-          LOG(("nsChannelClassifier[%p]: User override (PBM) on channel[%p] (%s) for %s",
-               this, aChannel, chanSpec.get(), escaped.get()));
+          LOG(("nsChannelClassifier[%p]: User override on channel[%p] (%s) for %s (%s)",
+               this, aChannel, chanSpec.get(), escaped.get(), types[i]));
         }
+        mIsAllowListed = true;
+        *result = false;
+        // Stop checking the next permisson type if we decided to override.
+        break;
+      } else if (i == ArrayLength(types) - 1) {
+        // Do this on the last iteration.
+        *result = true;
       }
-
-      *result = !exists;
     }
 
     // Tracking protection will be enabled so return without updating
     // the security state. If any channels are subsequently cancelled
     // (page elements blocked) the state will be then updated.
     if (*result) {
       if (LOG_ENABLED()) {
         nsCString chanSpec = chanURI->GetSpecOrDefault();