forked from mirrors/gecko-dev
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8
This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:
ChromeUtils.import("resource://gre/modules/Services.jsm");
is approximately the same as the following, in the new model:
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs
This was done using the followng script:
https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16750
--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
189 lines
6.3 KiB
JavaScript
189 lines
6.3 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
/* import-globals-from pageInfo.js */
|
|
|
|
const {SitePermissions} = ChromeUtils.import("resource:///modules/SitePermissions.jsm");
|
|
|
|
var gPermURI;
|
|
var gPermPrincipal;
|
|
var gUsageRequest;
|
|
|
|
// Array of permissionIDs sorted alphabetically by label.
|
|
var gPermissions = SitePermissions.listPermissions()
|
|
.filter(p => SitePermissions.getPermissionLabel(p) != null)
|
|
.sort((a, b) => {
|
|
let firstLabel = SitePermissions.getPermissionLabel(a);
|
|
let secondLabel = SitePermissions.getPermissionLabel(b);
|
|
return firstLabel.localeCompare(secondLabel);
|
|
});
|
|
|
|
var permissionObserver = {
|
|
observe(aSubject, aTopic, aData) {
|
|
if (aTopic == "perm-changed") {
|
|
var permission = aSubject.QueryInterface(Ci.nsIPermission);
|
|
if (permission.matchesURI(gPermURI, true) && gPermissions.includes(permission.type)) {
|
|
initRow(permission.type);
|
|
}
|
|
}
|
|
},
|
|
};
|
|
|
|
function onLoadPermission(uri, principal) {
|
|
var permTab = document.getElementById("permTab");
|
|
if (SitePermissions.isSupportedURI(uri)) {
|
|
gPermURI = uri;
|
|
gPermPrincipal = principal;
|
|
var hostText = document.getElementById("hostText");
|
|
hostText.value = gPermURI.displayPrePath;
|
|
|
|
for (var i of gPermissions)
|
|
initRow(i);
|
|
Services.obs.addObserver(permissionObserver, "perm-changed");
|
|
onUnloadRegistry.push(onUnloadPermission);
|
|
permTab.hidden = false;
|
|
} else
|
|
permTab.hidden = true;
|
|
}
|
|
|
|
function onUnloadPermission() {
|
|
Services.obs.removeObserver(permissionObserver, "perm-changed");
|
|
|
|
if (gUsageRequest) {
|
|
gUsageRequest.cancel();
|
|
gUsageRequest = null;
|
|
}
|
|
}
|
|
|
|
function initRow(aPartId) {
|
|
createRow(aPartId);
|
|
|
|
var checkbox = document.getElementById(aPartId + "Def");
|
|
var command = document.getElementById("cmd_" + aPartId + "Toggle");
|
|
var {state, scope} = SitePermissions.get(gPermURI, aPartId);
|
|
let defaultState = SitePermissions.getDefault(aPartId);
|
|
|
|
// Since cookies preferences have many different possible configuration states
|
|
// we don't consider any permission except "no permission" to be default.
|
|
if (aPartId == "cookie") {
|
|
state = Services.perms.testPermissionFromPrincipal(gPermPrincipal, "cookie");
|
|
|
|
if (state == SitePermissions.UNKNOWN) {
|
|
checkbox.checked = true;
|
|
command.setAttribute("disabled", "true");
|
|
// Don't select any item in the radio group, as we can't
|
|
// confidently say that all cookies on the site will be allowed.
|
|
let radioGroup = document.getElementById("cookieRadioGroup");
|
|
radioGroup.selectedItem = null;
|
|
} else {
|
|
checkbox.checked = false;
|
|
command.removeAttribute("disabled");
|
|
}
|
|
|
|
setRadioState(aPartId, state);
|
|
return;
|
|
}
|
|
|
|
// When flash permission state is "Hide", we show it as "Always Ask" in page info.
|
|
if (aPartId.startsWith("plugin") && state == SitePermissions.PROMPT_HIDE) {
|
|
defaultState == SitePermissions.UNKNOWN ? state = defaultState : state = SitePermissions.PROMPT;
|
|
}
|
|
|
|
if (state != defaultState) {
|
|
checkbox.checked = false;
|
|
command.removeAttribute("disabled");
|
|
} else {
|
|
checkbox.checked = true;
|
|
command.setAttribute("disabled", "true");
|
|
}
|
|
|
|
if ([SitePermissions.SCOPE_POLICY, SitePermissions.SCOPE_GLOBAL].includes(scope)) {
|
|
checkbox.setAttribute("disabled", "true");
|
|
command.setAttribute("disabled", "true");
|
|
}
|
|
|
|
setRadioState(aPartId, state);
|
|
}
|
|
|
|
function createRow(aPartId) {
|
|
let rowId = "perm-" + aPartId + "-row";
|
|
if (document.getElementById(rowId))
|
|
return;
|
|
|
|
let commandId = "cmd_" + aPartId + "Toggle";
|
|
let labelId = "perm-" + aPartId + "-label";
|
|
let radiogroupId = aPartId + "RadioGroup";
|
|
|
|
let command = document.createXULElement("command");
|
|
command.setAttribute("id", commandId);
|
|
command.setAttribute("oncommand", "onRadioClick('" + aPartId + "');");
|
|
document.getElementById("pageInfoCommandSet").appendChild(command);
|
|
|
|
let row = document.createXULElement("vbox");
|
|
row.setAttribute("id", rowId);
|
|
row.setAttribute("class", "permission");
|
|
|
|
let label = document.createXULElement("label");
|
|
label.setAttribute("id", labelId);
|
|
label.setAttribute("control", radiogroupId);
|
|
label.setAttribute("value", SitePermissions.getPermissionLabel(aPartId));
|
|
label.setAttribute("class", "permissionLabel");
|
|
row.appendChild(label);
|
|
|
|
let controls = document.createXULElement("hbox");
|
|
controls.setAttribute("role", "group");
|
|
controls.setAttribute("aria-labelledby", labelId);
|
|
|
|
let checkbox = document.createXULElement("checkbox");
|
|
checkbox.setAttribute("id", aPartId + "Def");
|
|
checkbox.setAttribute("oncommand", "onCheckboxClick('" + aPartId + "');");
|
|
checkbox.setAttribute("label", gBundle.getString("permissions.useDefault"));
|
|
controls.appendChild(checkbox);
|
|
|
|
let spacer = document.createXULElement("spacer");
|
|
spacer.setAttribute("flex", "1");
|
|
controls.appendChild(spacer);
|
|
|
|
let radiogroup = document.createXULElement("radiogroup");
|
|
radiogroup.setAttribute("id", radiogroupId);
|
|
radiogroup.setAttribute("orient", "horizontal");
|
|
for (let state of SitePermissions.getAvailableStates(aPartId)) {
|
|
let radio = document.createXULElement("radio");
|
|
radio.setAttribute("id", aPartId + "#" + state);
|
|
radio.setAttribute("label", SitePermissions.getMultichoiceStateLabel(state));
|
|
radio.setAttribute("command", commandId);
|
|
radiogroup.appendChild(radio);
|
|
}
|
|
controls.appendChild(radiogroup);
|
|
|
|
row.appendChild(controls);
|
|
|
|
document.getElementById("permList").appendChild(row);
|
|
}
|
|
|
|
function onCheckboxClick(aPartId) {
|
|
var command = document.getElementById("cmd_" + aPartId + "Toggle");
|
|
var checkbox = document.getElementById(aPartId + "Def");
|
|
if (checkbox.checked) {
|
|
SitePermissions.remove(gPermURI, aPartId);
|
|
command.setAttribute("disabled", "true");
|
|
} else {
|
|
onRadioClick(aPartId);
|
|
command.removeAttribute("disabled");
|
|
}
|
|
}
|
|
|
|
function onRadioClick(aPartId) {
|
|
var radioGroup = document.getElementById(aPartId + "RadioGroup");
|
|
var id = radioGroup.selectedItem ? radioGroup.selectedItem.id : "#1";
|
|
var permission = parseInt(id.split("#")[1]);
|
|
SitePermissions.set(gPermURI, aPartId, permission);
|
|
}
|
|
|
|
function setRadioState(aPartId, aValue) {
|
|
var radio = document.getElementById(aPartId + "#" + aValue);
|
|
if (radio) {
|
|
radio.radioGroup.selectedItem = radio;
|
|
}
|
|
}
|