1206251 - Add a permission change observer to refresh the identity block. r?paolo draft
authorJohann Hofmann <jhofmann@mozilla.com>
Tue, 07 Jun 2016 11:36:54 +0200
changeset 378074 e709187cf6969c8c10da5ea1688a182c9fc16551
parent 377951 ddb6b30149221f00eb5dd180530e9033093d4c2b
child 523462 ccdd3db4a79f598e7101b4a85a78588565c545d8
push id20930
push usermail@johann-hofmann.com
push dateTue, 14 Jun 2016 15:21:43 +0000
reviewerspaolo
bugs1206251
milestone50.0a1
1206251 - Add a permission change observer to refresh the identity block. r?paolo MozReview-Commit-ID: J7qwLud2oXo
browser/base/content/browser.js
browser/base/content/test/general/browser_permissions.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -403,16 +403,24 @@ const gSessionHistoryObserver = {
     // Hide session restore button on about:home
     window.messageManager.broadcastAsyncMessage("Browser:HideSessionRestoreButton");
 
     // Clear undo history of the URL bar
     gURLBar.editor.transactionManager.clear()
   }
 };
 
+const gPermissionObserver = {
+  observe: function(subject, topic, data) {
+    if (topic === "perm-changed") {
+      gIdentityHandler.refreshIdentityBlock();
+    }
+  }
+};
+
 /**
  * Given a starting docshell and a URI to look up, find the docshell the URI
  * is loaded in.
  * @param   aDocument
  *          A document to find instead of using just a URI - this is more specific.
  * @param   aDocShell
  *          The doc shell to start at
  * @param   aSoughtURI
@@ -1166,16 +1174,17 @@ var gBrowserInit = {
       }
     }
 
     if (AppConstants.MOZ_SAFE_BROWSING) {
       // Bug 778855 - Perf regression if we do this here. To be addressed in bug 779008.
       setTimeout(function() { SafeBrowsing.init(); }, 2000);
     }
 
+    Services.obs.addObserver(gPermissionObserver, "perm-changed", false);
     Services.obs.addObserver(gSessionHistoryObserver, "browser:purge-session-history", false);
     Services.obs.addObserver(gXPInstallObserver, "addon-install-disabled", false);
     Services.obs.addObserver(gXPInstallObserver, "addon-install-started", false);
     Services.obs.addObserver(gXPInstallObserver, "addon-install-blocked", false);
     Services.obs.addObserver(gXPInstallObserver, "addon-install-origin-blocked", false);
     Services.obs.addObserver(gXPInstallObserver, "addon-install-failed", false);
     Services.obs.addObserver(gXPInstallObserver, "addon-install-confirmation", false);
     Services.obs.addObserver(gXPInstallObserver, "addon-install-complete", false);
@@ -1489,16 +1498,17 @@ var gBrowserInit = {
         Win7Features.onCloseWindow();
 
       gPrefService.removeObserver(ctrlTab.prefName, ctrlTab);
       ctrlTab.uninit();
       SocialUI.uninit();
       gBrowserThumbnails.uninit();
       FullZoom.destroy();
 
+      Services.obs.removeObserver(gPermissionObserver, "perm-changed");
       Services.obs.removeObserver(gSessionHistoryObserver, "browser:purge-session-history");
       Services.obs.removeObserver(gXPInstallObserver, "addon-install-disabled");
       Services.obs.removeObserver(gXPInstallObserver, "addon-install-started");
       Services.obs.removeObserver(gXPInstallObserver, "addon-install-blocked");
       Services.obs.removeObserver(gXPInstallObserver, "addon-install-origin-blocked");
       Services.obs.removeObserver(gXPInstallObserver, "addon-install-failed");
       Services.obs.removeObserver(gXPInstallObserver, "addon-install-confirmation");
       Services.obs.removeObserver(gXPInstallObserver, "addon-install-complete");
--- a/browser/base/content/test/general/browser_permissions.js
+++ b/browser/base/content/test/general/browser_permissions.js
@@ -53,31 +53,27 @@ add_task(function* testMainViewVisible()
 });
 
 add_task(function* testIdentityIcon() {
   let {gIdentityHandler} = gBrowser.ownerGlobal;
   let tab = gBrowser.selectedTab = gBrowser.addTab();
   yield promiseTabLoadEvent(tab, PERMISSIONS_PAGE);
 
   gIdentityHandler.setPermission("geo", SitePermissions.ALLOW);
-  gIdentityHandler.refreshIdentityBlock();
 
   ok(gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
     "identity-box signals granted permssions");
 
   gIdentityHandler.setPermission("geo", SitePermissions.getDefault("geo"));
-  gIdentityHandler.refreshIdentityBlock();
 
   ok(!gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
     "identity-box doesn't signal granted permssions");
 
   gIdentityHandler.setPermission("camera", SitePermissions.BLOCK);
-  gIdentityHandler.refreshIdentityBlock();
 
   ok(!gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
     "identity-box doesn't signal granted permssions");
 
   gIdentityHandler.setPermission("cookie", SitePermissions.SESSION);
-  gIdentityHandler.refreshIdentityBlock();
 
   ok(gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
     "identity-box signals granted permssions");
 });