Bug 1433513 - Correctly handle new expire type (EXPIRE_POLICY) in the Site Identity panel and Page Info window. r?johannh
MozReview-Commit-ID: 7mfxnqI1C65
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -8000,17 +8000,19 @@ var gIdentityHandler = {
classes += " in-use";
img.setAttribute("class", classes);
let nameLabel = document.createElement("label");
nameLabel.setAttribute("flex", "1");
nameLabel.setAttribute("class", "identity-popup-permission-label");
nameLabel.textContent = SitePermissions.getPermissionLabel(aPermission.id);
- if (aPermission.id == "popup") {
+ let isPolicyPermission = aPermission.scope == SitePermissions.SCOPE_POLICY;
+
+ if (aPermission.id == "popup" && !isPolicyPermission) {
let menulist = document.createElement("menulist");
let menupopup = document.createElement("menupopup");
let block = document.createElement("vbox");
block.setAttribute("id", "identity-popup-popup-container");
menulist.setAttribute("sizetopopup", "none");
menulist.setAttribute("class", "identity-popup-popup-menulist");
menulist.setAttribute("id", "identity-popup-popup-menulist");
@@ -8055,16 +8057,27 @@ var gIdentityHandler = {
// If the user did not permanently allow this device but it is currently
// used, set the variables to display a "temporarily allowed" info.
if (state != SitePermissions.ALLOW && aPermission.inUse) {
state = SitePermissions.ALLOW;
scope = SitePermissions.SCOPE_REQUEST;
}
stateLabel.textContent = SitePermissions.getCurrentStateLabel(state, scope);
+ container.appendChild(img);
+ container.appendChild(nameLabel);
+ container.appendChild(stateLabel);
+
+ /* We return the permission item here without a remove button if the permission is a
+ SCOPE_POLICY permission. Policy permissions cannot be removed/changed for the duration
+ of the browser session. */
+ if (isPolicyPermission) {
+ return container;
+ }
+
let button = document.createElement("button");
button.setAttribute("class", "identity-popup-permission-remove-button");
let tooltiptext = gNavigatorBundle.getString("permissions.remove.tooltip");
button.setAttribute("tooltiptext", tooltiptext);
button.addEventListener("command", () => {
let browser = gBrowser.selectedBrowser;
this._permissionList.removeChild(container);
if (aPermission.inUse &&
@@ -8119,19 +8132,16 @@ var gIdentityHandler = {
// 4 : clear temporary blocked permission
permissionType = 4;
}
histogram.add("(all)", permissionType);
histogram.add(aPermission.id, permissionType);
});
- container.appendChild(img);
- container.appendChild(nameLabel);
- container.appendChild(stateLabel);
container.appendChild(button);
return container;
},
_createBlockedPopupIndicator() {
let indicator = document.createElement("hbox");
indicator.setAttribute("class", "identity-popup-permission-item");
--- a/browser/base/content/pageinfo/permissions.js
+++ b/browser/base/content/pageinfo/permissions.js
@@ -64,26 +64,32 @@ function initRow(aPartId) {
initPluginsRow();
return;
}
createRow(aPartId);
var checkbox = document.getElementById(aPartId + "Def");
var command = document.getElementById("cmd_" + aPartId + "Toggle");
- var {state} = SitePermissions.get(gPermURI, aPartId);
+ var {state, scope} = SitePermissions.get(gPermURI, aPartId);
let defaultState = SitePermissions.getDefault(aPartId);
if (state != defaultState) {
checkbox.checked = false;
command.removeAttribute("disabled");
} else {
checkbox.checked = true;
command.setAttribute("disabled", "true");
}
+
+ if (scope == SitePermissions.SCOPE_POLICY) {
+ checkbox.setAttribute("disabled", "true");
+ command.setAttribute("disabled", "true");
+ }
+
setRadioState(aPartId, state);
}
function createRow(aPartId) {
let rowId = "perm-" + aPartId + "-row";
if (document.getElementById(rowId))
return;
--- a/browser/base/content/test/permissions/browser_permissions.js
+++ b/browser/base/content/test/permissions/browser_permissions.js
@@ -219,8 +219,50 @@ add_task(async function testPermissionSh
await tryKey("pressed when globally blocked but site allowed", 3);
SitePermissions.set(gBrowser.currentURI, "shortcuts", SitePermissions.BLOCK);
await tryKey("pressed when globally blocked and site blocked", 3);
SitePermissions.remove(gBrowser.currentURI, "shortcuts");
});
});
+
+// Test the control center UI when policy permissions are set.
+add_task(async function testPolicyPermission() {
+ await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function() {
+ await SpecialPowers.pushPrefEnv({set: [
+ ["dom.disable_open_during_load", true],
+ ]});
+
+ let permissionsList = document.getElementById("identity-popup-permission-list");
+ SitePermissions.set(gBrowser.currentURI, "popup", SitePermissions.ALLOW, SitePermissions.SCOPE_POLICY);
+
+ await openIdentityPopup();
+
+ // Check if the icon, nameLabel and stateLabel are visible.
+ let img, labelText, labels;
+
+ img = permissionsList.querySelector("image.identity-popup-permission-icon");
+ ok(img, "There is an image for the popup permission");
+ ok(img.classList.contains("popup-icon"), "proper class is in image class");
+
+ labelText = SitePermissions.getPermissionLabel("popup");
+ labels = permissionsList.querySelectorAll(".identity-popup-permission-label");
+ is(labels.length, 1, "One permission visible in main view");
+ is(labels[0].textContent, labelText, "Correct name label value");
+
+ labelText = SitePermissions.getCurrentStateLabel(SitePermissions.ALLOW, SitePermissions.SCOPE_POLICY);
+ labels = permissionsList.querySelectorAll(".identity-popup-permission-state-label");
+ is(labels[0].textContent, labelText, "Correct state label value");
+
+ // Check if the menulist and the remove button are hidden.
+ // The menulist is specific to the "popup" permission.
+ let menulist = document.getElementById("identity-popup-popup-menulist");
+ ok(menulist == null, "The popup permission menulist is not visible");
+
+ let removeButton = permissionsList.querySelector(".identity-popup-permission-remove-button");
+ ok(removeButton == null, "The permission remove button is not visible");
+
+ Services.perms.removeAll();
+ await closeIdentityPopup();
+ });
+});
+
--- a/browser/modules/SitePermissions.jsm
+++ b/browser/modules/SitePermissions.jsm
@@ -144,16 +144,17 @@ this.SitePermissions = {
PROMPT: Services.perms.PROMPT_ACTION,
ALLOW_COOKIES_FOR_SESSION: Components.interfaces.nsICookiePermission.ACCESS_SESSION,
// Permission scopes.
SCOPE_REQUEST: "{SitePermissions.SCOPE_REQUEST}",
SCOPE_TEMPORARY: "{SitePermissions.SCOPE_TEMPORARY}",
SCOPE_SESSION: "{SitePermissions.SCOPE_SESSION}",
SCOPE_PERSISTENT: "{SitePermissions.SCOPE_PERSISTENT}",
+ SCOPE_POLICY: "{SitePermissions.SCOPE_POLICY}",
_defaultPrefBranch: Services.prefs.getBranch("permissions.default."),
/**
* Gets all custom permissions for a given URI.
* Install addon permission is excluded, check bug 1303108.
*
* @return {Array} a list of objects with the keys:
@@ -183,17 +184,20 @@ this.SitePermissions = {
if ((permission.type == "canvas") &&
!Services.prefs.getBoolPref("privacy.resistFingerprinting")) {
continue;
}
let scope = this.SCOPE_PERSISTENT;
if (permission.expireType == Services.perms.EXPIRE_SESSION) {
scope = this.SCOPE_SESSION;
+ } else if (permission.expireType == Services.perms.EXPIRE_POLICY) {
+ scope = this.SCOPE_POLICY;
}
+
result.push({
id: permission.type,
scope,
state: permission.capability,
});
}
}
@@ -353,16 +357,18 @@ this.SitePermissions = {
} else {
permission = Services.perms.getPermissionObjectForURI(uri, permissionID, false);
}
if (permission) {
result.state = permission.capability;
if (permission.expireType == Services.perms.EXPIRE_SESSION) {
result.scope = this.SCOPE_SESSION;
+ } else if (permission.expireType == Services.perms.EXPIRE_POLICY) {
+ result.scope = this.SCOPE_POLICY;
}
}
}
if (result.state == defaultState) {
// If there's no persistent permission saved, check if we have something
// set temporarily.
let value = TemporaryBlockedPermissions.get(browser, permissionID);
@@ -425,16 +431,18 @@ this.SitePermissions = {
TemporaryBlockedPermissions.set(browser, permissionID);
browser.dispatchEvent(new browser.ownerGlobal
.CustomEvent("PermissionStateChange"));
} else if (this.isSupportedURI(uri)) {
let perms_scope = Services.perms.EXPIRE_NEVER;
if (scope == this.SCOPE_SESSION) {
perms_scope = Services.perms.EXPIRE_SESSION;
+ } else if (scope == this.SCOPE_POLICY) {
+ perms_scope = Services.perms.EXPIRE_POLICY;
}
Services.perms.add(uri, permissionID, state, perms_scope);
}
},
/**
* Removes the saved state of a particular permission for a given URI and/or browser.
@@ -536,23 +544,23 @@ this.SitePermissions = {
* @return {String|null} the localized label or null if an
* unknown state was passed.
*/
getCurrentStateLabel(state, scope = null) {
switch (state) {
case this.PROMPT:
return gStringBundle.GetStringFromName("state.current.prompt");
case this.ALLOW:
- if (scope && scope != this.SCOPE_PERSISTENT)
+ if (scope && scope != this.SCOPE_PERSISTENT && scope != this.SCOPE_POLICY)
return gStringBundle.GetStringFromName("state.current.allowedTemporarily");
return gStringBundle.GetStringFromName("state.current.allowed");
case this.ALLOW_COOKIES_FOR_SESSION:
return gStringBundle.GetStringFromName("state.current.allowedForSession");
case this.BLOCK:
- if (scope && scope != this.SCOPE_PERSISTENT)
+ if (scope && scope != this.SCOPE_PERSISTENT && scope != this.SCOPE_POLICY)
return gStringBundle.GetStringFromName("state.current.blockedTemporarily");
return gStringBundle.GetStringFromName("state.current.blocked");
default:
return null;
}
},
};