From cee6ec947ff30bdaf2710db33a03cdf201f839a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A3o=20Gottwald?= Date: Tue, 2 Jul 2013 02:42:48 +0200 Subject: [PATCH] Bug 885366 - Show granted and refused site permissions in site identity panel. r=jaws --- browser/base/content/browser.css | 2 +- browser/base/content/browser.js | 93 +++++++++++- browser/base/content/browser.xul | 24 ++-- .../locales/en-US/chrome/browser/browser.dtd | 2 + .../chrome/browser/sitePermissions.properties | 18 +++ browser/locales/jar.mn | 1 + browser/modules/Makefile.in | 1 + browser/modules/SitePermissions.jsm | 136 ++++++++++++++++++ browser/themes/linux/browser.css | 12 +- browser/themes/osx/browser.css | 14 ++ browser/themes/windows/browser.css | 19 ++- 11 files changed, 304 insertions(+), 18 deletions(-) create mode 100644 browser/locales/en-US/chrome/browser/sitePermissions.properties create mode 100644 browser/modules/SitePermissions.jsm diff --git a/browser/base/content/browser.css b/browser/base/content/browser.css index 0b0bda7509b..d0003675f3f 100644 --- a/browser/base/content/browser.css +++ b/browser/base/content/browser.css @@ -390,7 +390,7 @@ window[chromehidden~="toolbar"] toolbar:not(.toolbar-primary):not(.chromeclass-m #identity-popup-content-box:not(.chromeUI) > #identity-popup-chromeLabel, #identity-popup-content-box.chromeUI > .identity-popup-label:not(#identity-popup-brandName):not(#identity-popup-chromeLabel), #identity-popup-content-box.chromeUI > .identity-popup-description, -#identity-popup-content-box.chromeUI > #identity-popup-button-container, +#identity-popup.chromeUI > #identity-popup-button-container, #identity-popup-content-box.unknownIdentity > #identity-popup-connectedToLabel , #identity-popup-content-box.unknownIdentity > #identity-popup-runByLabel , #identity-popup-content-box.unknownIdentity > #identity-popup-content-host , diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 186cc849bb9..266bd8d31c5 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -141,6 +141,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "gBrowserNewTabPreloader", XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "SitePermissions", + "resource:///modules/SitePermissions.jsm"); + let gInitialPages = [ "about:blank", "about:newtab", @@ -6483,6 +6486,14 @@ var gIdentityHandler = { delete this._identityIcon; return this._identityIcon = document.getElementById("page-proxy-favicon"); }, + get _permissionsContainer () { + delete this._permissionsContainer; + return this._permissionsContainer = document.getElementById("identity-popup-permissions"); + }, + get _permissionList () { + delete this._permissionList; + return this._permissionList = document.getElementById("identity-popup-permission-list"); + }, /** * Rebuild cache of the elements that may or may not exist depending @@ -6493,10 +6504,14 @@ var gIdentityHandler = { delete this._identityIconLabel; delete this._identityIconCountryLabel; delete this._identityIcon; + delete this._permissionsContainer; + delete this._permissionList; this._identityBox = document.getElementById("identity-box"); this._identityIconLabel = document.getElementById("identity-icon-label"); this._identityIconCountryLabel = document.getElementById("identity-icon-country-label"); this._identityIcon = document.getElementById("page-proxy-favicon"); + this._permissionsContainer = document.getElementById("identity-popup-permissions"); + this._permissionList = document.getElementById("identity-popup-permission-list"); }, /** @@ -6506,6 +6521,7 @@ var gIdentityHandler = { handleMoreInfoClick : function(event) { displaySecurityInfo(); event.stopPropagation(); + this._identityPopup.hidePopup(); }, /** @@ -6647,6 +6663,7 @@ var gIdentityHandler = { return; } + this._identityPopup.className = newMode; this._identityBox.className = newMode; this.setIdentityMessages(newMode); @@ -6789,10 +6806,6 @@ var gIdentityHandler = { this._identityPopupContentVerif.textContent = verifier; }, - hideIdentityPopup : function() { - this._identityPopup.hidePopup(); - }, - /** * Click handler for the identity-box element in primary chrome. */ @@ -6820,6 +6833,8 @@ var gIdentityHandler = { // Update the popup strings this.setPopupMessages(this._identityBox.className); + this.updateSitePermissions(); + // Add the "open" attribute to the identity box for styling this._identityBox.setAttribute("open", "true"); var self = this; @@ -6834,7 +6849,11 @@ var gIdentityHandler = { onPopupShown : function(event) { TelemetryStopwatch.finish("FX_IDENTITY_POPUP_OPEN_MS"); + document.getElementById('identity-popup-more-info-button').focus(); + + this._identityPopup.addEventListener("blur", this, true); + this._identityPopup.addEventListener("popuphidden", this); }, onDragStart: function (event) { @@ -6851,6 +6870,72 @@ var gIdentityHandler = { dt.setData("text/plain", value); dt.setData("text/html", htmlString); dt.setDragImage(gProxyFavIcon, 16, 16); + }, + + handleEvent: function (event) { + switch (event.type) { + case "blur": + // Focus hasn't moved yet, need to wait until after the blur event. + setTimeout(() => { + if (document.activeElement && + document.activeElement.compareDocumentPosition(this._identityPopup) & + Node.DOCUMENT_POSITION_CONTAINS) + return; + + this._identityPopup.hidePopup(); + }, 0); + break; + case "popuphidden": + this._identityPopup.removeEventListener("blur", this, true); + this._identityPopup.removeEventListener("popuphidden", this); + break; + } + }, + + updateSitePermissions: function () { + while (this._permissionList.hasChildNodes()) + this._permissionList.removeChild(this._permissionList.lastChild); + + let uri = gBrowser.currentURI; + + for (let permission of SitePermissions.listPermissions()) { + let state = SitePermissions.get(uri, permission); + + if (state == SitePermissions.UNKNOWN) + continue; + + let item = this._createPermissionItem(permission, state); + this._permissionList.appendChild(item); + } + + this._permissionsContainer.hidden = !this._permissionList.hasChildNodes(); + }, + + _createPermissionItem: function (aPermission, aState) { + let menulist = document.createElement("menulist"); + let menupopup = document.createElement("menupopup"); + for (let state of SitePermissions.getAvailableStates(aPermission)) { + let menuitem = document.createElement("menuitem"); + menuitem.setAttribute("value", state); + menuitem.setAttribute("label", SitePermissions.getStateLabel(state)); + menupopup.appendChild(menuitem); + } + menulist.appendChild(menupopup); + menulist.setAttribute("value", aState); + menulist.setAttribute("oncommand", "SitePermissions.set(gBrowser.currentURI, '" + + aPermission + "', this.value)"); + menulist.setAttribute("id", "identity-popup-permission:" + aPermission); + + let label = document.createElement("label"); + label.setAttribute("flex", "1"); + label.setAttribute("control", menulist.getAttribute("id")); + label.setAttribute("value", SitePermissions.getPermissionLabel(aPermission)); + + let container = document.createElement("hbox"); + container.setAttribute("align", "center"); + container.appendChild(label); + container.appendChild(menulist); + return container; } }; diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 49eecf5946f..f91409c1dc9 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -293,7 +293,9 @@ hidden="true" noautofocus="true" consumeoutsideclicks="true" - onpopupshown="gIdentityHandler.onPopupShown(event);" + onpopupshown="if (event.target == this) + gIdentityHandler.onPopupShown(event);" + orient="vertical" level="top"> @@ -327,15 +329,21 @@ - - -