Bug 1484876 - Part 1: Refactor the PrivateBrowsingTrackingProtectionWhitelist service on top of the permission manager; r=johannh
☠☠ backed out by 41ebcb085bb0 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 20 Aug 2018 19:32:32 -0400
changeset 432824 1c9895ab06c6a1fa7799005bda10bc21d35c8a9b
parent 432823 c0893e34dfcfaf1b7d7f131a35067346d0522927
child 432825 babf6abc7f4cc189f17f73c7ddff8987da69a43a
push id34488
push usernerli@mozilla.com
push dateWed, 22 Aug 2018 16:28:54 +0000
treeherdermozilla-central@d6e4d3e69d4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
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 1: Refactor the PrivateBrowsingTrackingProtectionWhitelist service on top of the permission manager; r=johannh Session permissions aren't persisted to disk, so we can easily add a new permission type and only store session permissions in the permission manager database, and drop the in-memory allow list that this service maintains. This has the advantage that the permission manager already has the IPC machinery to make this information available in the content processes, so we can also check this allow list in the content process.
toolkit/components/privatebrowsing/PrivateBrowsingTrackingProtectionWhitelist.js
--- a/toolkit/components/privatebrowsing/PrivateBrowsingTrackingProtectionWhitelist.js
+++ b/toolkit/components/privatebrowsing/PrivateBrowsingTrackingProtectionWhitelist.js
@@ -1,62 +1,56 @@
 /* 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/. */
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 function PrivateBrowsingTrackingProtectionWhitelist() {
-  // The list of URIs explicitly excluded from tracking protection.
-  this._allowlist = [];
-
   Services.obs.addObserver(this, "last-pb-context-exited", true);
 }
 
 PrivateBrowsingTrackingProtectionWhitelist.prototype = {
   classID: Components.ID("{a319b616-c45d-4037-8d86-01c592b5a9af}"),
   QueryInterface: ChromeUtils.generateQI([Ci.nsIPrivateBrowsingTrackingProtectionWhitelist, Ci.nsIObserver, Ci.nsISupportsWeakReference]),
   _xpcom_factory: XPCOMUtils.generateSingletonFactory(PrivateBrowsingTrackingProtectionWhitelist),
 
   /**
    * Add the provided URI to the list of allowed tracking sites.
    *
    * @param uri nsIURI
    *        The URI to add to the list.
    */
   addToAllowList(uri) {
-    if (!this._allowlist.includes(uri.spec)) {
-      this._allowlist.push(uri.spec);
-    }
+    Services.perms.add(uri, "trackingprotection-pb", Ci.nsIPermissionManager.ALLOW_ACTION,
+                       Ci.nsIPermissionManager.EXPIRE_SESSION);
   },
 
   /**
    * Remove the provided URI from the list of allowed tracking sites.
    *
    * @param uri nsIURI
    *        The URI to add to the list.
    */
   removeFromAllowList(uri) {
-    let index = this._allowlist.indexOf(uri.spec);
-    if (index !== -1) {
-      this._allowlist.splice(index, 1);
-    }
+    Services.perms.remove(uri, "trackingprotection-pb");
   },
 
   /**
    * Check if the provided URI exists in the list of allowed tracking sites.
    *
    * @param uri nsIURI
    *        The URI to add to the list.
    */
   existsInAllowList(uri) {
-    return this._allowlist.includes(uri.spec);
+    return Services.perms.testPermission(uri, "trackingprotection-pb") ==
+           Ci.nsIPermissionManager.ALLOW_ACTION;
   },
 
   observe(subject, topic, data) {
     if (topic == "last-pb-context-exited") {
-      this._allowlist = [];
+      Services.perms.removeByType("trackingprotection-pb");
     }
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PrivateBrowsingTrackingProtectionWhitelist]);