1206251 - Add a permission change observer to refresh the identity block. r?paolo
draft
1206251 - Add a permission change observer to refresh the identity block. r?paolo
MozReview-Commit-ID: J7qwLud2oXo
--- 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");
});