Bug 1566810 - Part 2: Add the permission granted indicator to the identity panel. r=johannh
authorTim Huang <tihuang@mozilla.com>
Fri, 16 Aug 2019 07:42:39 +0000
changeset 488461 0a7463d82e5f5f3cbca589baab9abc07881f5142
parent 488460 93ae831e2fb9a6ceac0f0495a280d6538fc62f21
child 488462 a550b308d88ae8e6bbdd1bab0123028ca98512d8
push id92759
push usertihuang@mozilla.com
push dateFri, 16 Aug 2019 07:46:54 +0000
treeherderautoland@0a7463d82e5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1566810
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 1566810 - Part 2: Add the permission granted indicator to the identity panel. r=johannh This patch adds the permission granted indicator to the identity panel. The granted indicator will be shown if there is any granted permission. And it will got update if permission changes. We also update a test for this change. Differential Revision: https://phabricator.services.mozilla.com/D42121
browser/base/content/browser-siteIdentity.js
browser/base/content/test/permissions/browser_permissions.js
browser/components/controlcenter/content/identityPanel.inc.xul
browser/themes/shared/controlcenter/panel.inc.css
--- a/browser/base/content/browser-siteIdentity.js
+++ b/browser/base/content/browser-siteIdentity.js
@@ -263,16 +263,22 @@ var gIdentityHandler = {
     delete this._permissionAnchors;
     let permissionAnchors = {};
     for (let anchor of document.getElementById("blocked-permissions-container")
       .children) {
       permissionAnchors[anchor.getAttribute("data-permission-id")] = anchor;
     }
     return (this._permissionAnchors = permissionAnchors);
   },
+  get _permissionGrantedIndicator() {
+    delete this._permissionGrantedIndicator;
+    return (this._permissionGrantedIndicator = document.getElementById(
+      "identity-popup-permissions-granted-indicator"
+    ));
+  },
   get _trackingProtectionIconContainer() {
     delete this._trackingProtectionIconContainer;
     return (this._trackingProtectionIconContainer = document.getElementById(
       "tracking-protection-icon-container"
     ));
   },
 
   get _geoSharingIcon() {
@@ -1244,16 +1250,17 @@ var gIdentityHandler = {
     if (
       topic == "perm-changed" &&
       subject &&
       SitePermissions.listPermissions().includes(
         subject.QueryInterface(Ci.nsIPermission).type
       )
     ) {
       this.refreshIdentityBlock();
+      this.updateSitePermissionsGrantedIndicator();
     }
   },
 
   onDragStart(event) {
     if (gURLBar.getAttribute("pageproxystate") != "valid") {
       return;
     }
 
@@ -1400,16 +1407,41 @@ var gIdentityHandler = {
     if (
       !this._permissionList.hasChildNodes() &&
       this._permissionReloadHint.hasAttribute("hidden")
     ) {
       this._permissionEmptyHint.removeAttribute("hidden");
     } else {
       this._permissionEmptyHint.setAttribute("hidden", "true");
     }
+
+    this.updateSitePermissionsGrantedIndicator();
+  },
+
+  updateSitePermissionsGrantedIndicator() {
+    let hasGrantedPermissions = false;
+
+    let permissions = SitePermissions.getAllPermissionDetailsForBrowser(
+      gBrowser.selectedBrowser
+    );
+
+    for (let permission of permissions) {
+      if (
+        permission.state === SitePermissions.ALLOW ||
+        permission.state === SitePermissions.ALLOW_COOKIES_FOR_SESSION
+      ) {
+        hasGrantedPermissions = true;
+      }
+    }
+
+    // Display the permission granted indicator if necessary.
+    this._permissionGrantedIndicator.toggleAttribute(
+      "show",
+      hasGrantedPermissions
+    );
   },
 
   _createPermissionItem(aPermission) {
     let container = document.createXULElement("hbox");
     container.setAttribute("class", "identity-popup-permission-item");
     container.setAttribute("align", "center");
     container.setAttribute("role", "group");
 
--- a/browser/base/content/test/permissions/browser_permissions.js
+++ b/browser/base/content/test/permissions/browser_permissions.js
@@ -76,57 +76,87 @@ add_task(async function testMainViewVisi
 
     ok(!BrowserTestUtils.is_hidden(emptyLabel), "List of permissions is empty");
 
     await closeIdentityPopup();
   });
 });
 
 add_task(async function testIdentityIcon() {
-  await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, function() {
+  await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function() {
     PermissionTestUtils.add(
       gBrowser.currentURI,
       "geo",
       Services.perms.ALLOW_ACTION
     );
 
     ok(
       gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
       "identity-box signals granted permissions"
     );
 
+    await openIdentityPopup();
+    ok(
+      BrowserTestUtils.is_visible(gIdentityHandler._permissionGrantedIndicator),
+      "The permissions granted indicator is visible if a permission is granted"
+    );
+
+    // We don't close the panel here since we want to check whether the
+    // permission granted indicator gets update on the fly if there is a
+    // permission change.
+
     PermissionTestUtils.remove(gBrowser.currentURI, "geo");
 
     ok(
       !gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
       "identity-box doesn't signal granted permissions"
     );
 
+    ok(
+      BrowserTestUtils.is_hidden(gIdentityHandler._permissionGrantedIndicator),
+      "The permissions granted indicator is hidden if no permission is granted"
+    );
+    await closeIdentityPopup();
+
     PermissionTestUtils.add(
       gBrowser.currentURI,
       "camera",
       Services.perms.DENY_ACTION
     );
 
     ok(
       !gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
       "identity-box doesn't signal granted permissions"
     );
 
+    await openIdentityPopup();
+    ok(
+      BrowserTestUtils.is_hidden(gIdentityHandler._permissionGrantedIndicator),
+      "The permissions granted indicator is hidden if no permission is granted"
+    );
+    await closeIdentityPopup();
+
     PermissionTestUtils.add(
       gBrowser.currentURI,
       "cookie",
       Ci.nsICookiePermission.ACCESS_SESSION
     );
 
     ok(
       gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
       "identity-box signals granted permissions"
     );
 
+    await openIdentityPopup();
+    ok(
+      BrowserTestUtils.is_visible(gIdentityHandler._permissionGrantedIndicator),
+      "The permissions granted indicator is visible if a permission is granted"
+    );
+    await closeIdentityPopup();
+
     PermissionTestUtils.remove(gBrowser.currentURI, "geo");
     PermissionTestUtils.remove(gBrowser.currentURI, "camera");
     PermissionTestUtils.remove(gBrowser.currentURI, "cookie");
   });
 });
 
 add_task(async function testCancelPermission() {
   await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function() {
--- a/browser/components/controlcenter/content/identityPanel.inc.xul
+++ b/browser/components/controlcenter/content/identityPanel.inc.xul
@@ -62,18 +62,18 @@
 
       <!-- Permissions Section -->
       <hbox class="identity-popup-section"
             when-connection="not-secure secure secure-ev secure-cert-user-overridden file extension">
         <vbox id="identity-popup-permissions-content" flex="1" role="group"
               aria-labelledby="identity-popup-permissions-headline">
           <hbox>
             <label id="identity-popup-permissions-headline"
-                   flex="1"
                    value="&identity.permissions2;"/>
+            <image id="identity-popup-permissions-granted-indicator"/>
           </hbox>
           <vbox id="identity-popup-permission-list"/>
           <description id="identity-popup-permission-reload-hint">&identity.permissionsReloadHint;</description>
           <description id="identity-popup-permission-empty-hint">&identity.permissionsEmpty;</description>
         </vbox>
       </hbox>
 
       <!-- Clear Site Data Button -->
--- a/browser/themes/shared/controlcenter/panel.inc.css
+++ b/browser/themes/shared/controlcenter/panel.inc.css
@@ -803,16 +803,27 @@ description#identity-popup-content-verif
 }
 
 #identity-popup-permissions-headline {
   color: #737373;
   font-weight: 500;
   margin-inline-start: 0;
 }
 
+#identity-popup-permissions-granted-indicator {
+  display: none;
+  list-style-image: url(chrome://browser/skin/badge-blue.svg);
+  width: 16px;
+  height: 16px;
+}
+
+#identity-popup-permissions-granted-indicator[show] {
+  display: block;
+}
+
 :root[lwt-popup-brighttext] #identity-popup-permissions-headline {
   color: #f9f9fa;
 }
 
 .protections-popup-category,
 .identity-popup-permission-item {
   min-height: 24px;
 }