2018-08-31 08:59:17 +03:00
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = [
|
2016-08-28 06:11:07 +03:00
|
|
|
"PermissionUI",
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PermissionUI is responsible for exposing both a prototype
|
|
|
|
* PermissionPrompt that can be used by arbitrary browser
|
|
|
|
* components and add-ons, but also hosts the implementations of
|
|
|
|
* built-in permission prompts.
|
|
|
|
*
|
|
|
|
* If you're developing a feature that requires web content to ask
|
|
|
|
* for special permissions from the user, this module is for you.
|
|
|
|
*
|
|
|
|
* Suppose a system add-on wants to add a new prompt for a new request
|
|
|
|
* for getting more low-level access to the user's sound card, and the
|
|
|
|
* permission request is coming up from content by way of the
|
|
|
|
* nsContentPermissionHelper. The system add-on could then do the following:
|
|
|
|
*
|
|
|
|
* Cu.import("resource://gre/modules/Integration.jsm");
|
|
|
|
* Cu.import("resource:///modules/PermissionUI.jsm");
|
|
|
|
*
|
|
|
|
* const SoundCardIntegration = (base) => ({
|
|
|
|
* __proto__: base,
|
|
|
|
* createPermissionPrompt(type, request) {
|
|
|
|
* if (type != "sound-api") {
|
|
|
|
* return super.createPermissionPrompt(...arguments);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* return {
|
|
|
|
* __proto__: PermissionUI.PermissionPromptForRequestPrototype,
|
|
|
|
* get permissionKey() {
|
|
|
|
* return "sound-permission";
|
|
|
|
* }
|
|
|
|
* // etc - see the documentation for PermissionPrompt for
|
|
|
|
* // a better idea of what things one can and should override.
|
|
|
|
* }
|
|
|
|
* },
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
* // Add-on startup:
|
|
|
|
* Integration.contentPermission.register(SoundCardIntegration);
|
|
|
|
* // ...
|
|
|
|
* // Add-on shutdown:
|
|
|
|
* Integration.contentPermission.unregister(SoundCardIntegration);
|
|
|
|
*
|
|
|
|
* Note that PermissionPromptForRequestPrototype must be used as the
|
|
|
|
* prototype, since the prompt is wrapping an nsIContentPermissionRequest,
|
|
|
|
* and going through nsIContentPermissionPrompt.
|
|
|
|
*
|
|
|
|
* It is, however, possible to take advantage of PermissionPrompt without
|
|
|
|
* having to go through nsIContentPermissionPrompt or with a
|
|
|
|
* nsIContentPermissionRequest. The PermissionPromptPrototype can be
|
|
|
|
* imported, subclassed, and have prompt() called directly, without
|
|
|
|
* the caller having called into createPermissionPrompt.
|
|
|
|
*/
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2016-08-28 06:11:07 +03:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "Services",
|
2016-08-28 06:11:07 +03:00
|
|
|
"resource://gre/modules/Services.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "SitePermissions",
|
2016-09-23 00:09:30 +03:00
|
|
|
"resource:///modules/SitePermissions.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
|
2016-08-28 06:11:07 +03:00
|
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gBrowserBundle", function() {
|
|
|
|
return Services.strings
|
2017-01-17 18:48:17 +03:00
|
|
|
.createBundle("chrome://browser/locale/browser.properties");
|
2016-08-28 06:11:07 +03:00
|
|
|
});
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var PermissionUI = {};
|
2016-08-28 06:11:07 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* PermissionPromptPrototype should be subclassed by callers that
|
|
|
|
* want to display prompts to the user. See each method and property
|
|
|
|
* below for guidance on what to override.
|
|
|
|
*
|
|
|
|
* Note that if you're creating a prompt for an
|
|
|
|
* nsIContentPermissionRequest, you'll want to subclass
|
|
|
|
* PermissionPromptForRequestPrototype instead.
|
|
|
|
*/
|
2018-02-23 22:50:01 +03:00
|
|
|
var PermissionPromptPrototype = {
|
2016-08-28 06:11:07 +03:00
|
|
|
/**
|
|
|
|
* Returns the associated <xul:browser> for the request. This should
|
|
|
|
* work for the e10s and non-e10s case.
|
|
|
|
*
|
|
|
|
* Subclasses must override this.
|
|
|
|
*
|
|
|
|
* @return {<xul:browser>}
|
|
|
|
*/
|
|
|
|
get browser() {
|
|
|
|
throw new Error("Not implemented.");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the nsIPrincipal associated with the request.
|
|
|
|
*
|
|
|
|
* Subclasses must override this.
|
|
|
|
*
|
|
|
|
* @return {nsIPrincipal}
|
|
|
|
*/
|
|
|
|
get principal() {
|
|
|
|
throw new Error("Not implemented.");
|
|
|
|
},
|
|
|
|
|
2018-05-16 20:32:42 +03:00
|
|
|
/**
|
|
|
|
* Provides the preferred name to use in the permission popups,
|
|
|
|
* based on the principal URI (the URI.hostPort for any URI scheme
|
|
|
|
* besides the moz-extension one which should default to the
|
|
|
|
* extension name).
|
|
|
|
*/
|
|
|
|
get principalName() {
|
|
|
|
if (this.principal.addonPolicy) {
|
|
|
|
return this.principal.addonPolicy.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.principal.URI.hostPort;
|
|
|
|
},
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
/**
|
|
|
|
* If the nsIPermissionManager is being queried and written
|
|
|
|
* to for this permission request, set this to the key to be
|
2018-11-26 13:32:19 +03:00
|
|
|
* used. If this is undefined, no integration with temporary
|
|
|
|
* permissions infrastructure will be provided.
|
2016-08-28 06:11:07 +03:00
|
|
|
*
|
|
|
|
* Note that if a permission is set, in any follow-up
|
|
|
|
* prompting within the expiry window of that permission,
|
|
|
|
* the prompt will be skipped and the allow or deny choice
|
|
|
|
* will be selected automatically.
|
|
|
|
*/
|
|
|
|
get permissionKey() {
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
2018-11-26 13:32:19 +03:00
|
|
|
/**
|
|
|
|
* If true, user permissions will be read from and written to.
|
|
|
|
* When this is false, we still provide integration with
|
|
|
|
* infrastructure such as temporary permissions. permissionKey should
|
|
|
|
* still return a valid name in those cases for that integration to work.
|
|
|
|
*/
|
|
|
|
get usePermissionManager() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
/**
|
|
|
|
* These are the options that will be passed to the
|
|
|
|
* PopupNotification when it is shown. See the documentation
|
|
|
|
* for PopupNotification for more details.
|
|
|
|
*
|
2016-10-04 08:27:32 +03:00
|
|
|
* Note that prompt() will automatically set displayURI to
|
|
|
|
* be the URI of the requesting pricipal, unless the displayURI is exactly
|
|
|
|
* set to false.
|
2016-08-28 06:11:07 +03:00
|
|
|
*/
|
|
|
|
get popupOptions() {
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PopupNotification requires a unique ID to open the notification.
|
|
|
|
* You must return a unique ID string here, for which PopupNotification
|
|
|
|
* will then create a <xul:popupnotification> node with the ID
|
|
|
|
* "<notificationID>-notification".
|
|
|
|
*
|
|
|
|
* If there's a custom <xul:popupnotification> you're hoping to show,
|
|
|
|
* then you need to make sure its ID has the "-notification" suffix,
|
|
|
|
* and then return the prefix here.
|
|
|
|
*
|
|
|
|
* See PopupNotification.jsm for more details.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* The unique ID that will be used to as the
|
|
|
|
* "<unique ID>-notification" ID for the <xul:popupnotification>
|
|
|
|
* to use or create.
|
|
|
|
*/
|
|
|
|
get notificationID() {
|
|
|
|
throw new Error("Not implemented.");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The ID of the element to anchor the PopupNotification to.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
get anchorID() {
|
|
|
|
return "default-notification-icon";
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-02-27 23:31:55 +03:00
|
|
|
* The message to show to the user in the PopupNotification. A string
|
|
|
|
* with "<>" as a placeholder that is usually replaced by an addon name
|
|
|
|
* or a host name, formatted in bold, to describe the permission that is being requested.
|
2016-08-28 06:11:07 +03:00
|
|
|
*
|
|
|
|
* Subclasses must override this.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
get message() {
|
|
|
|
throw new Error("Not implemented.");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This will be called if the request is to be cancelled.
|
|
|
|
*
|
|
|
|
* Subclasses only need to override this if they provide a
|
|
|
|
* permissionKey.
|
|
|
|
*/
|
|
|
|
cancel() {
|
2017-10-15 21:50:30 +03:00
|
|
|
throw new Error("Not implemented.");
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This will be called if the request is to be allowed.
|
|
|
|
*
|
|
|
|
* Subclasses only need to override this if they provide a
|
|
|
|
* permissionKey.
|
|
|
|
*/
|
|
|
|
allow() {
|
|
|
|
throw new Error("Not implemented.");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The actions that will be displayed in the PopupNotification
|
|
|
|
* via a dropdown menu. The first item in this array will be
|
|
|
|
* the default selection. Each action is an Object with the
|
|
|
|
* following properties:
|
|
|
|
*
|
|
|
|
* label (string):
|
|
|
|
* The label that will be displayed for this choice.
|
|
|
|
* accessKey (string):
|
|
|
|
* The access key character that will be used for this choice.
|
2016-09-23 00:09:30 +03:00
|
|
|
* action (SitePermissions state)
|
|
|
|
* The action that will be associated with this choice.
|
|
|
|
* This should be either SitePermissions.ALLOW or SitePermissions.BLOCK.
|
2016-08-28 06:11:07 +03:00
|
|
|
*
|
|
|
|
* callback (function, optional)
|
2016-11-20 20:40:26 +03:00
|
|
|
* A callback function that will fire if the user makes this choice, with
|
|
|
|
* a single parameter, state. State is an Object that contains the property
|
|
|
|
* checkboxChecked, which identifies whether the checkbox to remember this
|
|
|
|
* decision was checked.
|
2016-08-28 06:11:07 +03:00
|
|
|
*/
|
|
|
|
get promptActions() {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the prompt will be shown to the user, this callback will
|
|
|
|
* be called just before. Subclasses may want to override this
|
|
|
|
* in order to, for example, bump a counter Telemetry probe for
|
|
|
|
* how often a particular permission request is seen.
|
|
|
|
*/
|
|
|
|
onBeforeShow() {},
|
|
|
|
|
2018-07-03 02:17:16 +03:00
|
|
|
/**
|
2018-11-27 00:23:16 +03:00
|
|
|
* If the prompt was shown to the user, this callback will be called just
|
|
|
|
* after it's been shown.
|
|
|
|
*/
|
|
|
|
onShown() {},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the prompt was shown to the user, this callback will be called just
|
|
|
|
* after it's been hidden.
|
2018-07-03 02:17:16 +03:00
|
|
|
*/
|
|
|
|
onAfterShow() {},
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
/**
|
|
|
|
* Will determine if a prompt should be shown to the user, and if so,
|
|
|
|
* will show it.
|
|
|
|
*
|
|
|
|
* If a permissionKey is defined prompt() might automatically
|
|
|
|
* allow or cancel itself based on the user's current
|
|
|
|
* permission settings without displaying the prompt.
|
|
|
|
*
|
2017-02-05 03:10:50 +03:00
|
|
|
* If the permission is not already set and the <xul:browser> that the request
|
|
|
|
* is associated with does not belong to a browser window with the
|
|
|
|
* PopupNotifications global set, the prompt request is ignored.
|
2016-08-28 06:11:07 +03:00
|
|
|
*/
|
|
|
|
prompt() {
|
|
|
|
// We ignore requests from non-nsIStandardURLs
|
|
|
|
let requestingURI = this.principal.URI;
|
|
|
|
if (!(requestingURI instanceof Ci.nsIStandardURL)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-26 13:32:19 +03:00
|
|
|
if (this.usePermissionManager &&
|
|
|
|
this.permissionKey) {
|
2016-08-28 06:11:07 +03:00
|
|
|
// If we're reading and setting permissions, then we need
|
|
|
|
// to check to see if we already have a permission setting
|
|
|
|
// for this particular principal.
|
2016-09-23 00:09:30 +03:00
|
|
|
let {state} = SitePermissions.get(requestingURI,
|
|
|
|
this.permissionKey,
|
|
|
|
this.browser);
|
2016-08-28 06:11:07 +03:00
|
|
|
|
2016-09-23 00:09:30 +03:00
|
|
|
if (state == SitePermissions.BLOCK) {
|
2018-07-23 18:43:08 +03:00
|
|
|
// If the request is blocked by a global setting then we record
|
|
|
|
// a flag that lasts for the duration of the current page load
|
|
|
|
// to notify the user that the permission has been blocked.
|
|
|
|
// Currently only applies to autoplay-media
|
|
|
|
if (state == SitePermissions.getDefault(this.permissionKey) &&
|
|
|
|
SitePermissions.showGloballyBlocked(this.permissionKey)) {
|
|
|
|
SitePermissions.set(this.principal.URI,
|
|
|
|
this.permissionKey,
|
|
|
|
state,
|
|
|
|
SitePermissions.SCOPE_GLOBAL,
|
|
|
|
this.browser);
|
|
|
|
}
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
this.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-23 00:09:30 +03:00
|
|
|
if (state == SitePermissions.ALLOW) {
|
2016-08-28 06:11:07 +03:00
|
|
|
this.allow();
|
|
|
|
return;
|
|
|
|
}
|
2017-01-23 13:44:03 +03:00
|
|
|
|
|
|
|
// Tell the browser to refresh the identity block display in case there
|
|
|
|
// are expired permission states.
|
|
|
|
this.browser.dispatchEvent(new this.browser.ownerGlobal
|
|
|
|
.CustomEvent("PermissionStateChange"));
|
2018-11-26 13:32:19 +03:00
|
|
|
} else if (this.permissionKey) {
|
|
|
|
// If we're reading a permission which already has a temporary value,
|
|
|
|
// see if we can use the temporary value.
|
|
|
|
let {state} = SitePermissions.get(null,
|
|
|
|
this.permissionKey,
|
|
|
|
this.browser);
|
|
|
|
|
|
|
|
if (state == SitePermissions.BLOCK) {
|
|
|
|
// TODO: Add support for showGloballyBlocked
|
|
|
|
|
|
|
|
this.cancel();
|
|
|
|
return;
|
|
|
|
}
|
2016-08-28 06:11:07 +03:00
|
|
|
}
|
|
|
|
|
2017-02-05 03:10:50 +03:00
|
|
|
let chromeWin = this.browser.ownerGlobal;
|
|
|
|
if (!chromeWin.PopupNotifications) {
|
|
|
|
this.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
// Transform the PermissionPrompt actions into PopupNotification actions.
|
|
|
|
let popupNotificationActions = [];
|
|
|
|
for (let promptAction of this.promptActions) {
|
|
|
|
let action = {
|
|
|
|
label: promptAction.label,
|
|
|
|
accessKey: promptAction.accessKey,
|
2016-11-20 20:40:26 +03:00
|
|
|
callback: state => {
|
2016-08-28 06:11:07 +03:00
|
|
|
if (promptAction.callback) {
|
|
|
|
promptAction.callback();
|
|
|
|
}
|
|
|
|
|
2018-11-26 13:32:19 +03:00
|
|
|
if (this.usePermissionManager &&
|
|
|
|
this.permissionKey) {
|
2018-07-17 05:45:17 +03:00
|
|
|
if ((state && state.checkboxChecked && state.source != "esc-press") ||
|
2017-02-25 05:42:36 +03:00
|
|
|
promptAction.scope == SitePermissions.SCOPE_PERSISTENT) {
|
2018-07-17 05:45:17 +03:00
|
|
|
// Permanently store permission.
|
2016-09-23 00:09:30 +03:00
|
|
|
let scope = SitePermissions.SCOPE_PERSISTENT;
|
|
|
|
// Only remember permission for session if in PB mode.
|
|
|
|
if (PrivateBrowsingUtils.isBrowserPrivate(this.browser)) {
|
|
|
|
scope = SitePermissions.SCOPE_SESSION;
|
|
|
|
}
|
|
|
|
SitePermissions.set(this.principal.URI,
|
|
|
|
this.permissionKey,
|
|
|
|
promptAction.action,
|
|
|
|
scope);
|
2018-08-03 18:00:55 +03:00
|
|
|
} else if (promptAction.action == SitePermissions.BLOCK ||
|
|
|
|
SitePermissions.permitTemporaryAllow(this.permissionKey)) {
|
|
|
|
// Temporarily store BLOCK permissions only unless permission object
|
|
|
|
// sets permitTemporaryAllow: true
|
2016-09-23 00:09:30 +03:00
|
|
|
// SitePermissions does not consider subframes when storing temporary
|
|
|
|
// permissions on a tab, thus storing ALLOW could be exploited.
|
|
|
|
SitePermissions.set(this.principal.URI,
|
|
|
|
this.permissionKey,
|
|
|
|
promptAction.action,
|
|
|
|
SitePermissions.SCOPE_TEMPORARY,
|
|
|
|
this.browser);
|
2016-08-28 06:11:07 +03:00
|
|
|
}
|
|
|
|
|
2016-09-23 00:09:30 +03:00
|
|
|
// Grant permission if action is ALLOW.
|
|
|
|
if (promptAction.action == SitePermissions.ALLOW) {
|
2016-08-28 06:11:07 +03:00
|
|
|
this.allow();
|
|
|
|
} else {
|
|
|
|
this.cancel();
|
|
|
|
}
|
2018-11-26 13:32:19 +03:00
|
|
|
} else if (this.permissionKey) {
|
|
|
|
// TODO: Add support for permitTemporaryAllow
|
|
|
|
if (promptAction.action == SitePermissions.BLOCK) {
|
|
|
|
// Temporarily store BLOCK permissions.
|
|
|
|
// We don't consider subframes when storing temporary
|
|
|
|
// permissions on a tab, thus storing ALLOW could be exploited.
|
|
|
|
SitePermissions.set(null,
|
|
|
|
this.permissionKey,
|
|
|
|
promptAction.action,
|
|
|
|
SitePermissions.SCOPE_TEMPORARY,
|
|
|
|
this.browser);
|
|
|
|
}
|
2016-08-28 06:11:07 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
2016-11-01 08:56:32 +03:00
|
|
|
if (promptAction.dismiss) {
|
2017-10-15 21:50:30 +03:00
|
|
|
action.dismiss = promptAction.dismiss;
|
2016-11-01 08:56:32 +03:00
|
|
|
}
|
2016-08-28 06:11:07 +03:00
|
|
|
|
|
|
|
popupNotificationActions.push(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mainAction = popupNotificationActions.length ?
|
|
|
|
popupNotificationActions[0] : null;
|
|
|
|
let secondaryActions = popupNotificationActions.splice(1);
|
|
|
|
|
|
|
|
let options = this.popupOptions;
|
2016-10-04 08:27:32 +03:00
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
if (!options.hasOwnProperty("displayURI") || options.displayURI) {
|
2016-10-04 08:27:32 +03:00
|
|
|
options.displayURI = this.principal.URI;
|
|
|
|
}
|
2017-01-16 15:38:07 +03:00
|
|
|
// Permission prompts are always persistent; the close button is controlled by a pref.
|
2016-11-20 20:40:04 +03:00
|
|
|
options.persistent = true;
|
2017-01-16 15:38:07 +03:00
|
|
|
options.hideClose = !Services.prefs.getBoolPref("privacy.permissionPrompts.showCloseButton");
|
2018-07-03 02:17:16 +03:00
|
|
|
options.eventCallback = (topic) => {
|
|
|
|
// When the docshell of the browser is aboout to be swapped to another one,
|
|
|
|
// the "swapping" event is called. Returning true causes the notification
|
|
|
|
// to be moved to the new browser.
|
|
|
|
if (topic == "swapping") {
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-27 00:23:16 +03:00
|
|
|
// The prompt has been shown, notify the PermissionUI.
|
|
|
|
if (topic == "shown") {
|
|
|
|
this.onShown();
|
|
|
|
}
|
2018-07-03 02:17:16 +03:00
|
|
|
// The prompt has been removed, notify the PermissionUI.
|
|
|
|
if (topic == "removed") {
|
|
|
|
this.onAfterShow();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2016-08-28 06:11:07 +03:00
|
|
|
|
|
|
|
this.onBeforeShow();
|
|
|
|
chromeWin.PopupNotifications.show(this.browser,
|
|
|
|
this.notificationID,
|
|
|
|
this.message,
|
|
|
|
this.anchorID,
|
|
|
|
mainAction,
|
|
|
|
secondaryActions,
|
|
|
|
options);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.PermissionPromptPrototype = PermissionPromptPrototype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A subclass of PermissionPromptPrototype that assumes
|
|
|
|
* that this.request is an nsIContentPermissionRequest
|
|
|
|
* and fills in some of the required properties on the
|
|
|
|
* PermissionPrompt. For callers that are wrapping an
|
|
|
|
* nsIContentPermissionRequest, this should be subclassed
|
|
|
|
* rather than PermissionPromptPrototype.
|
|
|
|
*/
|
2018-02-23 22:50:01 +03:00
|
|
|
var PermissionPromptForRequestPrototype = {
|
2016-08-28 06:11:07 +03:00
|
|
|
__proto__: PermissionPromptPrototype,
|
|
|
|
|
|
|
|
get browser() {
|
|
|
|
// In the e10s-case, the <xul:browser> will be at request.element.
|
|
|
|
// In the single-process case, we have to use some XPCOM incantations
|
|
|
|
// to resolve to the <xul:browser>.
|
|
|
|
if (this.request.element) {
|
|
|
|
return this.request.element;
|
|
|
|
}
|
2018-08-01 20:07:10 +03:00
|
|
|
return this.request.window.docShell.chromeEventHandler;
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get principal() {
|
|
|
|
return this.request.principal;
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
this.request.cancel();
|
|
|
|
},
|
|
|
|
|
2018-11-27 00:23:16 +03:00
|
|
|
allow(choices) {
|
|
|
|
this.request.allow(choices);
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.PermissionPromptForRequestPrototype =
|
|
|
|
PermissionPromptForRequestPrototype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a PermissionPrompt for a nsIContentPermissionRequest for
|
|
|
|
* the GeoLocation API.
|
|
|
|
*
|
|
|
|
* @param request (nsIContentPermissionRequest)
|
|
|
|
* The request for a permission from content.
|
|
|
|
*/
|
|
|
|
function GeolocationPermissionPrompt(request) {
|
|
|
|
this.request = request;
|
|
|
|
}
|
|
|
|
|
|
|
|
GeolocationPermissionPrompt.prototype = {
|
|
|
|
__proto__: PermissionPromptForRequestPrototype,
|
|
|
|
|
|
|
|
get permissionKey() {
|
|
|
|
return "geo";
|
|
|
|
},
|
|
|
|
|
|
|
|
get popupOptions() {
|
|
|
|
let pref = "browser.geolocation.warning.infoURL";
|
2016-11-20 20:40:26 +03:00
|
|
|
let options = {
|
2016-08-28 06:11:07 +03:00
|
|
|
learnMoreURL: Services.urlFormatter.formatURLPref(pref),
|
2018-02-27 23:31:55 +03:00
|
|
|
displayURI: false,
|
2018-05-16 20:32:42 +03:00
|
|
|
name: this.principalName,
|
2016-08-28 06:11:07 +03:00
|
|
|
};
|
2016-11-20 20:40:26 +03:00
|
|
|
|
|
|
|
if (this.principal.URI.schemeIs("file")) {
|
|
|
|
options.checkbox = { show: false };
|
|
|
|
} else {
|
|
|
|
// Don't offer "always remember" action in PB mode
|
|
|
|
options.checkbox = {
|
2018-08-31 08:59:17 +03:00
|
|
|
show: !PrivateBrowsingUtils.isWindowPrivate(this.browser.ownerGlobal),
|
2016-11-20 20:40:26 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.checkbox.show) {
|
|
|
|
options.checkbox.label = gBrowserBundle.GetStringFromName("geolocation.remember");
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get notificationID() {
|
|
|
|
return "geolocation";
|
|
|
|
},
|
|
|
|
|
|
|
|
get anchorID() {
|
|
|
|
return "geo-notification-icon";
|
|
|
|
},
|
|
|
|
|
|
|
|
get message() {
|
|
|
|
if (this.principal.URI.schemeIs("file")) {
|
2018-02-27 23:31:55 +03:00
|
|
|
return gBrowserBundle.GetStringFromName("geolocation.shareWithFile3");
|
2016-08-28 06:11:07 +03:00
|
|
|
}
|
2018-02-27 23:31:55 +03:00
|
|
|
|
|
|
|
return gBrowserBundle.formatStringFromName("geolocation.shareWithSite3",
|
2018-05-16 20:32:42 +03:00
|
|
|
["<>"], 1);
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get promptActions() {
|
|
|
|
// We collect Telemetry data on Geolocation prompts and how users
|
|
|
|
// respond to them. The probe keys are a bit verbose, so let's alias them.
|
|
|
|
const SHARE_LOCATION =
|
|
|
|
Ci.nsISecurityUITelemetry.WARNING_GEOLOCATION_REQUEST_SHARE_LOCATION;
|
|
|
|
const ALWAYS_SHARE =
|
|
|
|
Ci.nsISecurityUITelemetry.WARNING_GEOLOCATION_REQUEST_ALWAYS_SHARE;
|
|
|
|
const NEVER_SHARE =
|
|
|
|
Ci.nsISecurityUITelemetry.WARNING_GEOLOCATION_REQUEST_NEVER_SHARE;
|
|
|
|
|
|
|
|
let secHistogram = Services.telemetry.getHistogramById("SECURITY_UI");
|
|
|
|
|
2016-11-20 20:40:26 +03:00
|
|
|
return [{
|
|
|
|
label: gBrowserBundle.GetStringFromName("geolocation.allowLocation"),
|
2016-08-28 06:11:07 +03:00
|
|
|
accessKey:
|
2016-11-20 20:40:26 +03:00
|
|
|
gBrowserBundle.GetStringFromName("geolocation.allowLocation.accesskey"),
|
2016-09-23 00:09:30 +03:00
|
|
|
action: SitePermissions.ALLOW,
|
2016-12-30 02:34:54 +03:00
|
|
|
callback(state) {
|
2016-11-20 20:40:26 +03:00
|
|
|
if (state && state.checkboxChecked) {
|
2016-08-28 06:11:07 +03:00
|
|
|
secHistogram.add(ALWAYS_SHARE);
|
2016-11-20 20:40:26 +03:00
|
|
|
} else {
|
|
|
|
secHistogram.add(SHARE_LOCATION);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
label: gBrowserBundle.GetStringFromName("geolocation.dontAllowLocation"),
|
|
|
|
accessKey:
|
|
|
|
gBrowserBundle.GetStringFromName("geolocation.dontAllowLocation.accesskey"),
|
2016-09-23 00:09:30 +03:00
|
|
|
action: SitePermissions.BLOCK,
|
2016-12-30 02:34:54 +03:00
|
|
|
callback(state) {
|
2016-11-20 20:40:26 +03:00
|
|
|
if (state && state.checkboxChecked) {
|
2016-08-28 06:11:07 +03:00
|
|
|
secHistogram.add(NEVER_SHARE);
|
2016-11-20 20:40:26 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}];
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onBeforeShow() {
|
|
|
|
let secHistogram = Services.telemetry.getHistogramById("SECURITY_UI");
|
|
|
|
const SHOW_REQUEST = Ci.nsISecurityUITelemetry.WARNING_GEOLOCATION_REQUEST;
|
|
|
|
secHistogram.add(SHOW_REQUEST);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.GeolocationPermissionPrompt = GeolocationPermissionPrompt;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a PermissionPrompt for a nsIContentPermissionRequest for
|
|
|
|
* the Desktop Notification API.
|
|
|
|
*
|
|
|
|
* @param request (nsIContentPermissionRequest)
|
|
|
|
* The request for a permission from content.
|
|
|
|
* @return {PermissionPrompt} (see documentation in header)
|
|
|
|
*/
|
|
|
|
function DesktopNotificationPermissionPrompt(request) {
|
|
|
|
this.request = request;
|
|
|
|
}
|
|
|
|
|
|
|
|
DesktopNotificationPermissionPrompt.prototype = {
|
|
|
|
__proto__: PermissionPromptForRequestPrototype,
|
|
|
|
|
|
|
|
get permissionKey() {
|
|
|
|
return "desktop-notification";
|
|
|
|
},
|
|
|
|
|
|
|
|
get popupOptions() {
|
|
|
|
let learnMoreURL =
|
|
|
|
Services.urlFormatter.formatURLPref("app.support.baseURL") + "push";
|
|
|
|
|
|
|
|
return {
|
|
|
|
learnMoreURL,
|
2018-02-27 23:31:55 +03:00
|
|
|
displayURI: false,
|
2018-05-16 20:32:42 +03:00
|
|
|
name: this.principalName,
|
2016-08-28 06:11:07 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
get notificationID() {
|
|
|
|
return "web-notifications";
|
|
|
|
},
|
|
|
|
|
|
|
|
get anchorID() {
|
|
|
|
return "web-notifications-notification-icon";
|
|
|
|
},
|
|
|
|
|
|
|
|
get message() {
|
2018-02-27 23:31:55 +03:00
|
|
|
return gBrowserBundle.formatStringFromName("webNotifications.receiveFromSite2",
|
2017-12-14 18:30:28 +03:00
|
|
|
["<>"], 1);
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get promptActions() {
|
2017-03-23 09:07:30 +03:00
|
|
|
let actions = [
|
2016-11-20 20:40:26 +03:00
|
|
|
{
|
|
|
|
label: gBrowserBundle.GetStringFromName("webNotifications.allow"),
|
|
|
|
accessKey:
|
|
|
|
gBrowserBundle.GetStringFromName("webNotifications.allow.accesskey"),
|
2016-09-23 00:09:30 +03:00
|
|
|
action: SitePermissions.ALLOW,
|
2017-02-25 05:42:36 +03:00
|
|
|
scope: SitePermissions.SCOPE_PERSISTENT,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: gBrowserBundle.GetStringFromName("webNotifications.notNow"),
|
|
|
|
accessKey:
|
|
|
|
gBrowserBundle.GetStringFromName("webNotifications.notNow.accesskey"),
|
|
|
|
action: SitePermissions.BLOCK,
|
2016-11-20 20:40:26 +03:00
|
|
|
},
|
2017-03-23 09:07:30 +03:00
|
|
|
];
|
|
|
|
if (!PrivateBrowsingUtils.isBrowserPrivate(this.browser)) {
|
|
|
|
actions.push({
|
|
|
|
label: gBrowserBundle.GetStringFromName("webNotifications.never"),
|
2016-11-20 20:40:26 +03:00
|
|
|
accessKey:
|
2017-02-25 05:42:36 +03:00
|
|
|
gBrowserBundle.GetStringFromName("webNotifications.never.accesskey"),
|
2016-09-23 00:09:30 +03:00
|
|
|
action: SitePermissions.BLOCK,
|
2017-02-25 05:42:36 +03:00
|
|
|
scope: SitePermissions.SCOPE_PERSISTENT,
|
2017-03-23 09:07:30 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return actions;
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.DesktopNotificationPermissionPrompt =
|
|
|
|
DesktopNotificationPermissionPrompt;
|
2017-04-11 07:07:29 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a PermissionPrompt for a nsIContentPermissionRequest for
|
|
|
|
* the persistent-storage API.
|
|
|
|
*
|
|
|
|
* @param request (nsIContentPermissionRequest)
|
|
|
|
* The request for a permission from content.
|
|
|
|
*/
|
|
|
|
function PersistentStoragePermissionPrompt(request) {
|
|
|
|
this.request = request;
|
|
|
|
}
|
|
|
|
|
|
|
|
PersistentStoragePermissionPrompt.prototype = {
|
|
|
|
__proto__: PermissionPromptForRequestPrototype,
|
|
|
|
|
|
|
|
get permissionKey() {
|
|
|
|
return "persistent-storage";
|
|
|
|
},
|
|
|
|
|
|
|
|
get popupOptions() {
|
|
|
|
let learnMoreURL =
|
|
|
|
Services.urlFormatter.formatURLPref("app.support.baseURL") + "storage-permissions";
|
|
|
|
return {
|
2017-12-14 18:30:28 +03:00
|
|
|
learnMoreURL,
|
2018-02-27 23:31:55 +03:00
|
|
|
displayURI: false,
|
2018-05-16 20:32:42 +03:00
|
|
|
name: this.principalName,
|
2017-04-11 07:07:29 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
get notificationID() {
|
|
|
|
return "persistent-storage";
|
|
|
|
},
|
|
|
|
|
|
|
|
get anchorID() {
|
|
|
|
return "persistent-storage-notification-icon";
|
|
|
|
},
|
|
|
|
|
|
|
|
get message() {
|
2018-02-27 23:31:55 +03:00
|
|
|
return gBrowserBundle.formatStringFromName("persistentStorage.allowWithSite",
|
2017-12-14 18:30:28 +03:00
|
|
|
["<>"], 1);
|
2017-04-11 07:07:29 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get promptActions() {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: gBrowserBundle.GetStringFromName("persistentStorage.allow"),
|
|
|
|
accessKey:
|
|
|
|
gBrowserBundle.GetStringFromName("persistentStorage.allow.accesskey"),
|
2018-08-31 08:59:17 +03:00
|
|
|
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
2018-11-02 11:15:05 +03:00
|
|
|
scope: SitePermissions.SCOPE_PERSISTENT,
|
2017-04-11 07:07:29 +03:00
|
|
|
},
|
|
|
|
{
|
2018-11-02 11:15:05 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("persistentStorage.notNow.label"),
|
2017-04-11 07:07:29 +03:00
|
|
|
accessKey:
|
2018-11-02 11:15:05 +03:00
|
|
|
gBrowserBundle.GetStringFromName("persistentStorage.notNow.accesskey"),
|
2018-08-31 08:59:17 +03:00
|
|
|
action: Ci.nsIPermissionManager.DENY_ACTION,
|
|
|
|
},
|
2018-11-02 11:15:05 +03:00
|
|
|
{
|
|
|
|
label: gBrowserBundle.GetStringFromName("persistentStorage.neverAllow.label"),
|
|
|
|
accessKey:
|
|
|
|
gBrowserBundle.GetStringFromName("persistentStorage.neverAllow.accesskey"),
|
|
|
|
action: SitePermissions.BLOCK,
|
|
|
|
scope: SitePermissions.SCOPE_PERSISTENT,
|
|
|
|
},
|
2017-04-11 07:07:29 +03:00
|
|
|
];
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2017-04-11 07:07:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.PersistentStoragePermissionPrompt = PersistentStoragePermissionPrompt;
|
2017-11-15 22:13:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a PermissionPrompt for a nsIContentPermissionRequest for
|
|
|
|
* the WebMIDI API.
|
|
|
|
*
|
|
|
|
* @param request (nsIContentPermissionRequest)
|
|
|
|
* The request for a permission from content.
|
|
|
|
*/
|
|
|
|
function MIDIPermissionPrompt(request) {
|
|
|
|
this.request = request;
|
|
|
|
let types = request.types.QueryInterface(Ci.nsIArray);
|
|
|
|
let perm = types.queryElementAt(0, Ci.nsIContentPermissionType);
|
|
|
|
this.isSysexPerm = (perm.options.length > 0 &&
|
|
|
|
perm.options.queryElementAt(0, Ci.nsISupportsString) == "sysex");
|
|
|
|
this.permName = "midi";
|
|
|
|
if (this.isSysexPerm) {
|
|
|
|
this.permName = "midi-sysex";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MIDIPermissionPrompt.prototype = {
|
|
|
|
__proto__: PermissionPromptForRequestPrototype,
|
|
|
|
|
|
|
|
get permissionKey() {
|
|
|
|
return this.permName;
|
|
|
|
},
|
|
|
|
|
|
|
|
get popupOptions() {
|
|
|
|
// TODO (bug 1433235) We need a security/permissions explanation URL for this
|
|
|
|
let options = {
|
2018-02-27 23:31:55 +03:00
|
|
|
displayURI: false,
|
2018-05-16 20:32:42 +03:00
|
|
|
name: this.principalName,
|
2017-11-15 22:13:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if (this.principal.URI.schemeIs("file")) {
|
|
|
|
options.checkbox = { show: false };
|
|
|
|
} else {
|
|
|
|
// Don't offer "always remember" action in PB mode
|
|
|
|
options.checkbox = {
|
2018-08-31 08:59:17 +03:00
|
|
|
show: !PrivateBrowsingUtils.isWindowPrivate(this.browser.ownerGlobal),
|
2017-11-15 22:13:12 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.checkbox.show) {
|
|
|
|
options.checkbox.label = gBrowserBundle.GetStringFromName("midi.remember");
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
},
|
|
|
|
|
|
|
|
get notificationID() {
|
|
|
|
return "midi";
|
|
|
|
},
|
|
|
|
|
|
|
|
get anchorID() {
|
2018-02-06 05:10:30 +03:00
|
|
|
return "midi-notification-icon";
|
2017-11-15 22:13:12 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get message() {
|
2018-02-27 23:31:55 +03:00
|
|
|
let message;
|
2017-11-15 22:13:12 +03:00
|
|
|
if (this.principal.URI.schemeIs("file")) {
|
|
|
|
if (this.isSysexPerm) {
|
2018-02-27 23:31:55 +03:00
|
|
|
message = gBrowserBundle.formatStringFromName("midi.shareSysexWithFile.message");
|
2017-11-15 22:13:12 +03:00
|
|
|
} else {
|
2018-02-27 23:31:55 +03:00
|
|
|
message = gBrowserBundle.formatStringFromName("midi.shareWithFile.message");
|
2017-11-15 22:13:12 +03:00
|
|
|
}
|
2018-02-27 23:31:55 +03:00
|
|
|
} else if (this.isSysexPerm) {
|
|
|
|
message = gBrowserBundle.formatStringFromName("midi.shareSysexWithSite.message",
|
|
|
|
["<>"], 1);
|
2017-11-15 22:13:12 +03:00
|
|
|
} else {
|
2018-02-27 23:31:55 +03:00
|
|
|
message = gBrowserBundle.formatStringFromName("midi.shareWithSite.message",
|
|
|
|
["<>"], 1);
|
2017-11-15 22:13:12 +03:00
|
|
|
}
|
|
|
|
return message;
|
|
|
|
},
|
|
|
|
|
|
|
|
get promptActions() {
|
|
|
|
return [{
|
|
|
|
label: gBrowserBundle.GetStringFromName("midi.Allow.label"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName("midi.Allow.accesskey"),
|
2018-08-31 08:59:17 +03:00
|
|
|
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
2017-11-15 22:13:12 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: gBrowserBundle.GetStringFromName("midi.DontAllow.label"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName("midi.DontAllow.accesskey"),
|
2018-08-31 08:59:17 +03:00
|
|
|
action: Ci.nsIPermissionManager.DENY_ACTION,
|
2017-11-15 22:13:12 +03:00
|
|
|
}];
|
|
|
|
},
|
|
|
|
|
|
|
|
onBeforeShow() {
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.MIDIPermissionPrompt = MIDIPermissionPrompt;
|
2018-05-18 14:54:33 +03:00
|
|
|
|
|
|
|
function AutoplayPermissionPrompt(request) {
|
|
|
|
this.request = request;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoplayPermissionPrompt.prototype = {
|
|
|
|
__proto__: PermissionPromptForRequestPrototype,
|
|
|
|
|
|
|
|
get permissionKey() {
|
|
|
|
return "autoplay-media";
|
|
|
|
},
|
|
|
|
|
|
|
|
get popupOptions() {
|
2018-08-17 13:22:29 +03:00
|
|
|
let learnMoreURL =
|
|
|
|
Services.urlFormatter.formatURLPref("app.support.baseURL") + "block-autoplay";
|
2018-08-17 13:42:04 +03:00
|
|
|
let checkbox = {show: !this.principal.URI.schemeIs("file")};
|
2018-05-18 14:54:33 +03:00
|
|
|
if (checkbox.show) {
|
|
|
|
checkbox.checked = true;
|
2018-08-17 13:42:04 +03:00
|
|
|
checkbox.label = PrivateBrowsingUtils.isWindowPrivate(this.browser.ownerGlobal) ?
|
|
|
|
gBrowserBundle.GetStringFromName("autoplay.remember-private") :
|
|
|
|
gBrowserBundle.GetStringFromName("autoplay.remember");
|
2018-05-18 14:54:33 +03:00
|
|
|
}
|
|
|
|
return {
|
|
|
|
checkbox,
|
2018-08-17 13:22:29 +03:00
|
|
|
learnMoreURL,
|
2018-05-18 14:54:33 +03:00
|
|
|
displayURI: false,
|
|
|
|
name: this.principal.URI.hostPort,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
get notificationID() {
|
|
|
|
return "autoplay-media";
|
|
|
|
},
|
|
|
|
|
|
|
|
get anchorID() {
|
2018-07-19 23:17:44 +03:00
|
|
|
return "autoplay-media-notification-icon";
|
2018-05-18 14:54:33 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get message() {
|
|
|
|
if (this.principal.URI.schemeIs("file")) {
|
|
|
|
return gBrowserBundle.GetStringFromName("autoplay.messageWithFile");
|
|
|
|
}
|
|
|
|
return gBrowserBundle.formatStringFromName("autoplay.message", ["<>"], 1);
|
|
|
|
},
|
|
|
|
|
|
|
|
get promptActions() {
|
|
|
|
return [{
|
2018-07-23 14:20:30 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("autoplay.Allow2.label"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName("autoplay.Allow2.accesskey"),
|
2018-05-18 14:54:33 +03:00
|
|
|
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: gBrowserBundle.GetStringFromName("autoplay.DontAllow.label"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName("autoplay.DontAllow.accesskey"),
|
|
|
|
action: Ci.nsIPermissionManager.DENY_ACTION,
|
|
|
|
}];
|
|
|
|
},
|
|
|
|
|
2018-07-03 02:17:16 +03:00
|
|
|
onAfterShow() {
|
|
|
|
// Remove the event listener to prevent any leaks.
|
|
|
|
this.browser.removeEventListener(
|
|
|
|
"DOMAudioPlaybackStarted", this.handlePlaybackStart);
|
|
|
|
},
|
|
|
|
|
2018-05-18 14:54:33 +03:00
|
|
|
onBeforeShow() {
|
2018-07-03 02:17:16 +03:00
|
|
|
// Hide the prompt if the tab starts playing media.
|
|
|
|
this.handlePlaybackStart = () => {
|
|
|
|
let chromeWin = this.browser.ownerGlobal;
|
|
|
|
if (!chromeWin.PopupNotifications) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let notification = chromeWin.PopupNotifications.getNotification(
|
|
|
|
this.notificationID, this.browser);
|
|
|
|
if (notification) {
|
|
|
|
chromeWin.PopupNotifications.remove(notification);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.browser.addEventListener(
|
|
|
|
"DOMAudioPlaybackStarted", this.handlePlaybackStart);
|
2018-05-18 14:54:33 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.AutoplayPermissionPrompt = AutoplayPermissionPrompt;
|
2018-11-27 00:23:16 +03:00
|
|
|
|
|
|
|
function StorageAccessPermissionPrompt(request) {
|
|
|
|
this.request = request;
|
|
|
|
}
|
|
|
|
|
|
|
|
StorageAccessPermissionPrompt.prototype = {
|
|
|
|
__proto__: PermissionPromptForRequestPrototype,
|
|
|
|
|
|
|
|
get usePermissionManager() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
get permissionKey() {
|
|
|
|
// Make sure this name is unique per each third-party tracker
|
|
|
|
return "storage-access-" + this.principal.origin;
|
|
|
|
},
|
|
|
|
|
|
|
|
get popupOptions() {
|
|
|
|
return {
|
|
|
|
displayURI: false,
|
|
|
|
name: this.principal.URI.hostPort,
|
|
|
|
secondName: this.topLevelPrincipal.URI.hostPort,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
onShown() {
|
|
|
|
let document = this.browser.ownerDocument;
|
|
|
|
let label =
|
|
|
|
gBrowserBundle.formatStringFromName("storageAccess.description.label",
|
|
|
|
[this.request.principal.URI.hostPort, "<>"], 2);
|
|
|
|
let parts = label.split("<>");
|
|
|
|
if (parts.length == 1) {
|
|
|
|
parts.push("");
|
|
|
|
}
|
|
|
|
let map = {
|
|
|
|
"storage-access-perm-label": parts[0],
|
|
|
|
"storage-access-perm-learnmore":
|
|
|
|
gBrowserBundle.GetStringFromName("storageAccess.description.learnmore"),
|
|
|
|
"storage-access-perm-endlabel": parts[1],
|
|
|
|
};
|
|
|
|
for (let id in map) {
|
|
|
|
let str = map[id];
|
|
|
|
document.getElementById(id).textContent = str;
|
|
|
|
}
|
|
|
|
let learnMoreURL =
|
|
|
|
Services.urlFormatter.formatURLPref("app.support.baseURL") + "third-party-cookies";
|
|
|
|
document.getElementById("storage-access-perm-learnmore")
|
|
|
|
.href = learnMoreURL;
|
|
|
|
},
|
|
|
|
|
|
|
|
get notificationID() {
|
|
|
|
return "storage-access";
|
|
|
|
},
|
|
|
|
|
|
|
|
get anchorID() {
|
|
|
|
return "storage-access-notification-icon";
|
|
|
|
},
|
|
|
|
|
|
|
|
get message() {
|
|
|
|
return gBrowserBundle.formatStringFromName("storageAccess.message", ["<>", "<>"], 2);
|
|
|
|
},
|
|
|
|
|
|
|
|
get promptActions() {
|
|
|
|
let self = this;
|
|
|
|
return [{
|
|
|
|
label: gBrowserBundle.GetStringFromName("storageAccess.DontAllow.label"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName("storageAccess.DontAllow.accesskey"),
|
|
|
|
action: Ci.nsIPermissionManager.DENY_ACTION,
|
|
|
|
callback(state) {
|
|
|
|
self.cancel();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: gBrowserBundle.GetStringFromName("storageAccess.Allow.label"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName("storageAccess.Allow.accesskey"),
|
|
|
|
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
|
|
|
callback(state) {
|
|
|
|
self.allow({"storage-access": "allow"});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: gBrowserBundle.GetStringFromName("storageAccess.AllowOnAnySite.label"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName("storageAccess.AllowOnAnySite.accesskey"),
|
|
|
|
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
|
|
|
callback(state) {
|
|
|
|
self.allow({"storage-access": "allow-on-any-site"});
|
|
|
|
},
|
|
|
|
}];
|
|
|
|
},
|
|
|
|
|
|
|
|
get topLevelPrincipal() {
|
|
|
|
return this.request.topLevelPrincipal;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.StorageAccessPermissionPrompt = StorageAccessPermissionPrompt;
|