Bug 2033191 made sure we only call ownerGlobal on nodes. As per the discussion in dev-platform, the front-end ~always wants .documentGlobal. This removes ownerGlobal from the bindings. Following patch will rename internal GetOwnerGlobal in gecko to GetRelevantGlobal as per the HTML spec terminology. Differential Revision: https://phabricator.services.mozilla.com/D297183
117 lines
3.3 KiB
JavaScript
117 lines
3.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 https://mozilla.org/MPL/2.0/. */
|
|
|
|
import { PrivateBrowsingUtils } from "resource://gre/modules/PrivateBrowsingUtils.sys.mjs";
|
|
|
|
export let CanvasPermissionPromptHelper = {
|
|
_permissionsPrompt: "canvas-permissions-prompt",
|
|
_permissionsPromptHideDoorHanger: "canvas-permissions-prompt-hide-doorhanger",
|
|
_notificationIcon: "canvas-notification-icon",
|
|
|
|
// aSubject is an nsIBrowser (e10s) or an nsIDOMWindow (non-e10s).
|
|
// aData is an Origin string.
|
|
observe(aSubject, aTopic, aData) {
|
|
if (
|
|
aTopic != this._permissionsPrompt &&
|
|
aTopic != this._permissionsPromptHideDoorHanger
|
|
) {
|
|
return;
|
|
}
|
|
|
|
let browser;
|
|
if (aSubject instanceof Ci.nsIDOMWindow) {
|
|
browser = aSubject.docShell.chromeEventHandler;
|
|
} else {
|
|
browser = aSubject;
|
|
}
|
|
|
|
let window = browser?.documentGlobal;
|
|
if (!window) {
|
|
// Without knowing where this came from, we can't show the prompt.
|
|
return;
|
|
}
|
|
|
|
let { gNavigatorBundle, gBrowserBundle } = window;
|
|
let message = gNavigatorBundle.getFormattedString(
|
|
"canvas.siteprompt2",
|
|
["<>"],
|
|
1
|
|
);
|
|
|
|
let principal =
|
|
Services.scriptSecurityManager.createContentPrincipalFromOrigin(aData);
|
|
|
|
function setCanvasPermission(aPerm, aPersistent) {
|
|
Services.perms.addFromPrincipal(
|
|
principal,
|
|
"canvas",
|
|
aPerm,
|
|
aPersistent
|
|
? Ci.nsIPermissionManager.EXPIRE_NEVER
|
|
: Ci.nsIPermissionManager.EXPIRE_SESSION
|
|
);
|
|
}
|
|
|
|
let mainAction = {
|
|
label: gNavigatorBundle.getString("canvas.allow2"),
|
|
accessKey: gNavigatorBundle.getString("canvas.allow2.accesskey"),
|
|
callback(state) {
|
|
setCanvasPermission(
|
|
Ci.nsIPermissionManager.ALLOW_ACTION,
|
|
state && state.checkboxChecked
|
|
);
|
|
},
|
|
};
|
|
|
|
let secondaryActions = [
|
|
{
|
|
label: gNavigatorBundle.getString("canvas.block"),
|
|
accessKey: gNavigatorBundle.getString("canvas.block.accesskey"),
|
|
callback(state) {
|
|
setCanvasPermission(
|
|
Ci.nsIPermissionManager.DENY_ACTION,
|
|
state && state.checkboxChecked
|
|
);
|
|
},
|
|
},
|
|
];
|
|
|
|
let checkbox = {
|
|
// In PB mode, we don't want the "always remember" checkbox
|
|
show: !PrivateBrowsingUtils.isWindowPrivate(window),
|
|
};
|
|
if (checkbox.show) {
|
|
checkbox.checked = true;
|
|
checkbox.label = gBrowserBundle.GetStringFromName("canvas.remember2");
|
|
}
|
|
|
|
let options = {
|
|
checkbox,
|
|
name: principal.host,
|
|
learnMoreURL:
|
|
Services.urlFormatter.formatURLPref("app.support.baseURL") +
|
|
"fingerprint-permission",
|
|
dismissed: aTopic == this._permissionsPromptHideDoorHanger,
|
|
eventCallback(e) {
|
|
if (e == "showing") {
|
|
this.browser.ownerDocument.getElementById(
|
|
"canvas-permissions-prompt-warning"
|
|
).textContent = gBrowserBundle.GetStringFromName(
|
|
"canvas.siteprompt2.warning"
|
|
);
|
|
}
|
|
},
|
|
};
|
|
window.PopupNotifications.show(
|
|
browser,
|
|
this._permissionsPrompt,
|
|
message,
|
|
this._notificationIcon,
|
|
mainAction,
|
|
secondaryActions,
|
|
options
|
|
);
|
|
},
|
|
};
|