Bug 1601256 - Hide private browsing session permissions in preferences permission lists. r=johannh
authorpbz <pbz@mozilla.com>
Fri, 13 Dec 2019 12:27:12 +0000
changeset 506889 adec5f2eb156c86b243d04d29a6023ae6479130b
parent 506888 82a7408c8b3202774a3a01ef1b5f5646365f52ab
child 506890 c400f7480696ce9fce0234f857a94965536c0567
push id36913
push useropoprus@mozilla.com
push dateFri, 13 Dec 2019 16:53:24 +0000
treeherdermozilla-central@1ed684598bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1601256
milestone73.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 1601256 - Hide private browsing session permissions in preferences permission lists. r=johannh Differential Revision: https://phabricator.services.mozilla.com/D56184
browser/components/preferences/in-content/tests/browser_permissions_dialog.js
browser/components/preferences/sitePermissions.js
--- a/browser/components/preferences/in-content/tests/browser_permissions_dialog.js
+++ b/browser/components/preferences/in-content/tests/browser_permissions_dialog.js
@@ -64,16 +64,57 @@ add_task(async function addPermission() 
 
   // Observe the added permission changes in the dialog UI.
   Assert.equal(richlistbox.itemCount, 1);
   checkPermissionItem(URL, Services.perms.ALLOW_ACTION);
 
   PermissionTestUtils.remove(URI, "desktop-notification");
 });
 
+add_task(async function addPermissionPrivateBrowsing() {
+  let privateBrowsingPrincipal = Services.scriptSecurityManager.createContentPrincipal(
+    URI,
+    { privateBrowsingId: 1 }
+  );
+  let doc = sitePermissionsDialog.document;
+  let richlistbox = doc.getElementById("permissionsBox");
+
+  Assert.equal(
+    richlistbox.itemCount,
+    0,
+    "Number of permission items is 0 initially"
+  );
+
+  // Add a session permission for private browsing.
+  PermissionTestUtils.add(
+    privateBrowsingPrincipal,
+    "desktop-notification",
+    Services.perms.ALLOW_ACTION,
+    Services.perms.EXPIRE_SESSION
+  );
+
+  // The permission should not show in the dialog UI.
+  Assert.equal(richlistbox.itemCount, 0);
+
+  PermissionTestUtils.remove(privateBrowsingPrincipal, "desktop-notification");
+
+  // Add a permanent permission for private browsing
+  // The permission manager will store it as EXPIRE_SESSION
+  PermissionTestUtils.add(
+    privateBrowsingPrincipal,
+    "desktop-notification",
+    Services.perms.ALLOW_ACTION
+  );
+
+  // The permission should not show in the dialog UI.
+  Assert.equal(richlistbox.itemCount, 0);
+
+  PermissionTestUtils.remove(privateBrowsingPrincipal, "desktop-notification");
+});
+
 add_task(async function observePermissionChange() {
   PermissionTestUtils.add(
     URI,
     "desktop-notification",
     Services.perms.ALLOW_ACTION
   );
 
   // Change the permission.
--- a/browser/components/preferences/sitePermissions.js
+++ b/browser/components/preferences/sitePermissions.js
@@ -309,17 +309,21 @@ var gSitePermissionsManager = {
         throw new Error(`Unknown capability: ${capability}`);
     }
   },
 
   _addPermissionToList(perm) {
     // Ignore unrelated permission types and permissions with unknown states.
     if (
       perm.type !== this._type ||
-      !PERMISSION_STATES.includes(perm.capability)
+      !PERMISSION_STATES.includes(perm.capability) ||
+      // Skip private browsing session permissions
+      (perm.principal.privateBrowsingId !==
+        Services.scriptSecurityManager.DEFAULT_PRIVATE_BROWSING_ID &&
+        perm.expireType === Services.perms.EXPIRE_SESSION)
     ) {
       return;
     }
     let l10nId = this._getCapabilityString(perm.type, perm.capability);
     let p = new Permission(perm.principal, perm.type, perm.capability, l10nId);
     this._permissions.set(p.origin, p);
   },