Bug 1521598 - Part 1: Create a lazy preference getter for privacy.resistFingerprinting in SitePermissions; r=johannh
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 23 Jan 2019 15:57:09 +0000
changeset 515117 b6167098e831d161bfa877537aa9f5e0c6bd83a2
parent 515116 9f90c6e59169405e873e76f9c72e9b6fa70877ee
child 515118 ce0aae2058f2a3a4321e562b29e3a5a340d92e10
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1521598
milestone66.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 1521598 - Part 1: Create a lazy preference getter for privacy.resistFingerprinting in SitePermissions; r=johannh Differential Revision: https://phabricator.services.mozilla.com/D17362
browser/modules/SitePermissions.jsm
--- a/browser/modules/SitePermissions.jsm
+++ b/browser/modules/SitePermissions.jsm
@@ -215,16 +215,17 @@ var SitePermissions = {
   // Permission scopes.
   SCOPE_REQUEST: "{SitePermissions.SCOPE_REQUEST}",
   SCOPE_TEMPORARY: "{SitePermissions.SCOPE_TEMPORARY}",
   SCOPE_SESSION: "{SitePermissions.SCOPE_SESSION}",
   SCOPE_PERSISTENT: "{SitePermissions.SCOPE_PERSISTENT}",
   SCOPE_POLICY: "{SitePermissions.SCOPE_POLICY}",
   SCOPE_GLOBAL: "{SitePermissions.SCOPE_GLOBAL}",
 
+  _permissionsArray: null,
   _defaultPrefBranch: Services.prefs.getBranch("permissions.default."),
 
   /**
    * Gets all custom permissions for a given URI.
    * Install addon permission is excluded, check bug 1303108.
    *
    * @return {Array} a list of objects with the keys:
    *          - id: the permissionId of the permission
@@ -245,18 +246,17 @@ var SitePermissions = {
       // filter out unknown permissions
       if (gPermissionObject[permission.type]) {
         // XXX Bug 1303108 - Control Center should only show non-default permissions
         if (permission.type == "install") {
           continue;
         }
 
         // Hide canvas permission when privacy.resistFingerprinting is false.
-        if ((permission.type == "canvas") &&
-            !Services.prefs.getBoolPref("privacy.resistFingerprinting")) {
+        if ((permission.type == "canvas") && !this.resistFingerprinting) {
           continue;
         }
 
         let scope = this.SCOPE_PERSISTENT;
         if (permission.expireType == Services.perms.EXPIRE_SESSION) {
           scope = this.SCOPE_SESSION;
         } else if (permission.expireType == Services.perms.EXPIRE_POLICY) {
           scope = this.SCOPE_POLICY;
@@ -343,24 +343,43 @@ var SitePermissions = {
   },
 
   /**
    * Gets an array of all permission IDs.
    *
    * @return {Array<String>} an array of all permission IDs.
    */
   listPermissions() {
-    let permissions = Object.keys(gPermissionObject);
+    if (this._permissionsArray === null) {
+      let permissions = Object.keys(gPermissionObject);
 
-    // Hide canvas permission when privacy.resistFingerprinting is false.
-    if (!Services.prefs.getBoolPref("privacy.resistFingerprinting")) {
-      permissions = permissions.filter(permission => permission !== "canvas");
+      // Hide canvas permission when privacy.resistFingerprinting is false.
+      if (!this.resistFingerprinting) {
+        permissions = permissions.filter(permission => permission !== "canvas");
+      }
+      this._permissionsArray = permissions;
     }
 
-    return permissions;
+    return this._permissionsArray;
+  },
+
+  /**
+   * Called when the privacy.resistFingerprinting preference changes its value.
+   *
+   * @param {string} data
+   *        The last argument passed to the preference change observer
+   * @param {string} previous
+   *        The previous value of the preference
+   * @param {string} latest
+   *        The latest value of the preference
+   */
+  onResistFingerprintingChanged(data, previous, latest) {
+    // Ensure that listPermissions() will reconstruct its return value the next
+    // time it's called.
+    this._permissionsArray = null;
   },
 
   /**
    * Returns an array of permission states to be exposed to the user for a
    * permission with the given ID.
    *
    * @param {string} permissionID
    *        The ID to get permission states for.
@@ -805,8 +824,11 @@ if (!Services.prefs.getBoolPref("dom.web
   // names use hyphens. Disabling rule for line to keep things consistent.
   // eslint-disable-next-line dot-notation
   delete gPermissionObject["midi"];
   delete gPermissionObject["midi-sysex"];
 }
 
 XPCOMUtils.defineLazyPreferenceGetter(SitePermissions, "temporaryPermissionExpireTime",
                                       "privacy.temporary_permission_expire_time_ms", 3600 * 1000);
+XPCOMUtils.defineLazyPreferenceGetter(SitePermissions, "resistFingerprinting",
+                                      "privacy.resistFingerprinting", false,
+                                      SitePermissions.onResistFingerprintingChanged.bind(SitePermissions));