Bug 1271868 - opt-out permissions in the Permissions section of the Control Center; r?paolo
MozReview-Commit-ID: 7hWbTUsmuRD
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -7089,17 +7089,17 @@ var gIdentityHandler = {
},
updateSitePermissions: function () {
while (this._permissionList.hasChildNodes())
this._permissionList.removeChild(this._permissionList.lastChild);
let uri = gBrowser.currentURI;
- for (let permission of SitePermissions.listPermissions()) {
+ for (let permission of SitePermissions.listPermissions("hideInControlCenter")) {
let state = SitePermissions.get(uri, permission);
if (state == SitePermissions.UNKNOWN)
continue;
let item = this._createPermissionItem(permission, state);
this._permissionList.appendChild(item);
}
--- a/browser/modules/SitePermissions.jsm
+++ b/browser/modules/SitePermissions.jsm
@@ -20,23 +20,35 @@ this.SitePermissions = {
* URI. This excludes file URIs, for instance, as they don't have a host,
* even though nsIPermissionManager can still handle them.
*/
isSupportedURI: function (aURI) {
return aURI.schemeIs("http") || aURI.schemeIs("https");
},
/* Returns an array of all permission IDs.
+ *
+ * filterOut - filter out items from the list if the property value is true.
+ * return full list if the specified item is not matched
*/
- listPermissions: function () {
+ listPermissions: function (filterOut) {
let array = Object.keys(gPermissionObject);
- array.sort((a, b) => {
+ let filtered = [];
+ if (filterOut) {
+ filtered = array.filter(function(item) {
+ return !(filterOut in gPermissionObject[item] &&
+ gPermissionObject[item][filterOut]);
+ });
+ } else {
+ filtered = array;
+ }
+ filtered.sort((a, b) => {
return this.getPermissionLabel(a).localeCompare(this.getPermissionLabel(b));
});
- return array;
+ return filtered;
},
/* Returns an array of permission states to be exposed to the user for a
* permission with the given ID.
*/
getAvailableStates: function (aPermissionID) {
if (aPermissionID in gPermissionObject &&
gPermissionObject[aPermissionID].states)
@@ -139,58 +151,65 @@ var gPermissionObject = {
*
* - labelID
* Use the given ID instead of the permission name for looking up strings.
* e.g. "desktop-notification2" to use permission.desktop-notification2.label
*
* - states
* Array of permission states to be exposed to the user.
* Defaults to ALLOW, BLOCK and the default state (see getDefault).
+ *
+ * - hideInControlCenter
+ * Not shown this permission in Control Center
+ *
*/
"image": {
getDefault: function () {
return Services.prefs.getIntPref("permissions.default.image") == 2 ?
SitePermissions.BLOCK : SitePermissions.ALLOW;
- }
+ },
+ hideInControlCenter: true
},
"cookie": {
states: [ SitePermissions.ALLOW, SitePermissions.SESSION, SitePermissions.BLOCK ],
getDefault: function () {
if (Services.prefs.getIntPref("network.cookie.cookieBehavior") == 2)
return SitePermissions.BLOCK;
if (Services.prefs.getIntPref("network.cookie.lifetimePolicy") == 2)
return SitePermissions.SESSION;
return SitePermissions.ALLOW;
- }
+ },
+ hideInControlCenter: true
},
"desktop-notification": {
exactHostMatch: true,
- labelID: "desktop-notification2",
+ labelID: "desktop-notification2"
},
"camera": {},
"microphone": {},
"popup": {
getDefault: function () {
return Services.prefs.getBoolPref("dom.disable_open_during_load") ?
SitePermissions.BLOCK : SitePermissions.ALLOW;
}
},
"install": {
getDefault: function () {
return Services.prefs.getBoolPref("xpinstall.whitelist.required") ?
SitePermissions.BLOCK : SitePermissions.ALLOW;
- }
+ },
+ hideInControlCenter: true
},
"geo": {
exactHostMatch: true
},
"indexedDB": {},
--- a/browser/modules/test/xpcshell/test_SitePermissions.js
+++ b/browser/modules/test/xpcshell/test_SitePermissions.js
@@ -6,8 +6,22 @@
Components.utils.import("resource:///modules/SitePermissions.jsm");
add_task(function* testPermissionsListing() {
Assert.deepEqual(SitePermissions.listPermissions().sort(),
["camera","cookie","desktop-notification","geo","image",
"indexedDB","install","microphone","pointerLock","popup"],
"Correct list of all permissions");
});
+
+add_task(function* testPermissionsListingWithFilter() {
+ Assert.deepEqual(SitePermissions.listPermissions("hideInControlCenter").sort(),
+ ["camera","desktop-notification","geo",
+ "indexedDB","microphone","pointerLock","popup"],
+ "Correct list of filtered permissions");
+});
+
+add_task(function* testPermissionsListingWithFalseFilter() {
+ Assert.deepEqual(SitePermissions.listPermissions("hideXXX").sort(),
+ ["camera","cookie","desktop-notification","geo","image",
+ "indexedDB","install","microphone","pointerLock","popup"],
+ "Got full list of false filtered permissions");
+});