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";
|
|
|
|
|
|
|
|
var EXPORTED_SYMBOLS = ["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.
|
|
|
|
*/
|
2019-01-17 21:18:31 +03:00
|
|
|
const { XPCOMUtils } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/XPCOMUtils.jsm"
|
|
|
|
);
|
2019-07-05 10:55:19 +03:00
|
|
|
|
2018-01-30 08:17:48 +03:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"Services",
|
2016-08-28 06:11:07 +03:00
|
|
|
"resource://gre/modules/Services.jsm"
|
|
|
|
);
|
2018-01-30 08:17:48 +03:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"SitePermissions",
|
2016-09-23 00:09:30 +03:00
|
|
|
"resource:///modules/SitePermissions.jsm"
|
|
|
|
);
|
2018-01-30 08:17:48 +03:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"PrivateBrowsingUtils",
|
2016-08-28 06:11:07 +03:00
|
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm"
|
|
|
|
);
|
2019-07-05 10:55:19 +03:00
|
|
|
|
2018-11-30 05:17:50 +03:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(
|
|
|
|
this,
|
|
|
|
"IDNService",
|
|
|
|
"@mozilla.org/network/idn-service;1",
|
|
|
|
"nsIIDNService"
|
|
|
|
);
|
|
|
|
|
2019-07-30 11:28:31 +03:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(
|
|
|
|
this,
|
|
|
|
"ContentPrefService2",
|
|
|
|
"@mozilla.org/content-pref/service;1",
|
|
|
|
"nsIContentPrefService2"
|
|
|
|
);
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gBrowserBundle", function() {
|
|
|
|
return Services.strings.createBundle(
|
|
|
|
"chrome://browser/locale/browser.properties"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
var PermissionUI = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
var PermissionPromptPrototype = {
|
|
|
|
/**
|
|
|
|
* 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.");
|
|
|
|
},
|
|
|
|
|
2019-12-04 18:39:03 +03:00
|
|
|
/**
|
|
|
|
* Indicates the type of the permission request from content. This type might
|
|
|
|
* be different from the permission key used in the permissions database.
|
|
|
|
*/
|
|
|
|
get type() {
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
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 {};
|
|
|
|
},
|
|
|
|
|
2019-04-05 13:22:19 +03:00
|
|
|
/**
|
|
|
|
* If true, automatically denied permission requests will
|
|
|
|
* spawn a "post-prompt" that allows the user to correct the
|
|
|
|
* automatic denial by giving permanent permission access to
|
|
|
|
* the site.
|
|
|
|
*
|
|
|
|
* Note that if this function returns true, the permissionKey
|
|
|
|
* and postPromptActions attributes must be implemented.
|
|
|
|
*/
|
|
|
|
get postPromptEnabled() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2019-03-15 13:43:17 +03:00
|
|
|
/**
|
|
|
|
* If true, the prompt will be cancelled automatically unless
|
|
|
|
* request.isHandlingUserInput is true.
|
|
|
|
*/
|
|
|
|
get requiresUserInput() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
/**
|
|
|
|
* 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.");
|
|
|
|
},
|
|
|
|
|
2019-12-04 18:39:26 +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).
|
|
|
|
*/
|
|
|
|
getPrincipalName(principal = this.principal) {
|
|
|
|
if (principal.addonPolicy) {
|
|
|
|
return principal.addonPolicy.name;
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:50:14 +03:00
|
|
|
return principal.hostPort;
|
2019-12-04 18:39:26 +03:00
|
|
|
},
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
2019-04-05 13:22:19 +03:00
|
|
|
* scope (SitePermissions scope)
|
|
|
|
* The scope of the associated action (e.g. SitePermissions.SCOPE_PERSISTENT)
|
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 [];
|
|
|
|
},
|
|
|
|
|
2019-04-05 13:22:19 +03:00
|
|
|
/**
|
|
|
|
* The actions that will be displayed in the PopupNotification
|
|
|
|
* for post-prompt notifications 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.
|
|
|
|
* action (SitePermissions state)
|
|
|
|
* The action that will be associated with this choice.
|
|
|
|
* This should be either SitePermissions.ALLOW or SitePermissions.BLOCK.
|
|
|
|
* Note that the scope of this action will always be persistent.
|
|
|
|
*
|
|
|
|
* callback (function, optional)
|
|
|
|
* A callback function that will fire if the user makes this choice.
|
|
|
|
*/
|
|
|
|
get postPromptActions() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
2018-11-25 22:03:30 +03:00
|
|
|
*
|
|
|
|
* If this returns false, it cancels the process of showing the prompt. In
|
|
|
|
* that case, it is the responsibility of the onBeforeShow() implementation
|
|
|
|
* to ensure that allow() or cancel() are called on the object appropriately.
|
2016-08-28 06:11:07 +03:00
|
|
|
*/
|
2018-11-25 22:03:30 +03:00
|
|
|
onBeforeShow() {
|
|
|
|
return true;
|
|
|
|
},
|
2016-08-28 06:11:07 +03:00
|
|
|
|
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.
|
2019-05-17 16:23:08 +03:00
|
|
|
let { state } = SitePermissions.getForPrincipal(
|
|
|
|
this.principal,
|
|
|
|
this.permissionKey,
|
|
|
|
this.browser
|
|
|
|
);
|
2016-08-28 06:11:07 +03:00
|
|
|
|
2016-09-23 00:09:30 +03:00
|
|
|
if (state == SitePermissions.BLOCK) {
|
2019-04-05 13:22:19 +03:00
|
|
|
// If this block was done based on a global user setting, we want to show
|
|
|
|
// a post prompt to give the user some more granular control without
|
|
|
|
// annoying them too much.
|
|
|
|
if (
|
|
|
|
this.postPromptEnabled &&
|
|
|
|
SitePermissions.getDefault(this.permissionKey) ==
|
|
|
|
SitePermissions.BLOCK
|
|
|
|
) {
|
|
|
|
this.postPrompt();
|
|
|
|
}
|
2016-08-28 06:11:07 +03:00
|
|
|
this.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-04 18:39:26 +03:00
|
|
|
if (
|
|
|
|
state == SitePermissions.ALLOW &&
|
|
|
|
!this.request.maybeUnsafePermissionDelegate
|
|
|
|
) {
|
2016-08-28 06:11:07 +03:00
|
|
|
this.allow();
|
|
|
|
return;
|
|
|
|
}
|
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.
|
2019-08-20 15:15:00 +03:00
|
|
|
let { state } = SitePermissions.getForPrincipal(
|
2018-11-26 13:32:19 +03:00
|
|
|
null,
|
|
|
|
this.permissionKey,
|
|
|
|
this.browser
|
|
|
|
);
|
|
|
|
|
|
|
|
if (state == SitePermissions.BLOCK) {
|
|
|
|
this.cancel();
|
|
|
|
return;
|
|
|
|
}
|
2016-08-28 06:11:07 +03:00
|
|
|
}
|
|
|
|
|
2019-03-15 13:43:17 +03:00
|
|
|
if (this.requiresUserInput && !this.request.isHandlingUserInput) {
|
2019-04-05 13:22:19 +03:00
|
|
|
if (this.postPromptEnabled) {
|
|
|
|
this.postPrompt();
|
|
|
|
}
|
2019-03-15 13:43:17 +03:00
|
|
|
this.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2019-05-17 16:23:08 +03:00
|
|
|
SitePermissions.setForPrincipal(
|
|
|
|
this.principal,
|
|
|
|
this.permissionKey,
|
|
|
|
promptAction.action,
|
|
|
|
scope
|
|
|
|
);
|
2019-01-07 21:42:55 +03:00
|
|
|
} else if (promptAction.action == SitePermissions.BLOCK) {
|
|
|
|
// Temporarily store BLOCK permissions only
|
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.
|
2019-05-17 16:23:08 +03:00
|
|
|
SitePermissions.setForPrincipal(
|
|
|
|
this.principal,
|
|
|
|
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.
|
2019-08-20 15:15:00 +03:00
|
|
|
SitePermissions.setForPrincipal(
|
2018-11-26 13:32:19 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-04-05 13:22:19 +03:00
|
|
|
this._showNotification(popupNotificationActions);
|
|
|
|
},
|
|
|
|
|
|
|
|
postPrompt() {
|
|
|
|
let browser = this.browser;
|
|
|
|
let principal = this.principal;
|
|
|
|
let chromeWin = browser.ownerGlobal;
|
|
|
|
if (!chromeWin.PopupNotifications) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.permissionKey) {
|
|
|
|
throw new Error("permissionKey is required to show a post-prompt");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.postPromptActions) {
|
|
|
|
throw new Error("postPromptActions are required to show a post-prompt");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transform the PermissionPrompt actions into PopupNotification actions.
|
|
|
|
let popupNotificationActions = [];
|
|
|
|
for (let promptAction of this.postPromptActions) {
|
|
|
|
let action = {
|
|
|
|
label: promptAction.label,
|
|
|
|
accessKey: promptAction.accessKey,
|
|
|
|
callback: state => {
|
|
|
|
if (promptAction.callback) {
|
|
|
|
promptAction.callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Post-prompt permissions are stored permanently by default.
|
|
|
|
// Since we can not reply to the original permission request anymore,
|
|
|
|
// the page will need to listen for permission changes which are triggered
|
|
|
|
// by permanent entries in the permission manager.
|
|
|
|
let scope = SitePermissions.SCOPE_PERSISTENT;
|
|
|
|
// Only remember permission for session if in PB mode.
|
|
|
|
if (PrivateBrowsingUtils.isBrowserPrivate(browser)) {
|
|
|
|
scope = SitePermissions.SCOPE_SESSION;
|
|
|
|
}
|
2019-06-14 18:49:25 +03:00
|
|
|
SitePermissions.setForPrincipal(
|
|
|
|
principal,
|
|
|
|
this.permissionKey,
|
|
|
|
promptAction.action,
|
|
|
|
scope
|
|
|
|
);
|
2019-04-05 13:22:19 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
popupNotificationActions.push(action);
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:06:50 +03:00
|
|
|
// Post-prompt animation
|
|
|
|
if (!chromeWin.gReduceMotion) {
|
2019-04-05 13:22:19 +03:00
|
|
|
let anchor = chromeWin.document.getElementById(this.anchorID);
|
|
|
|
// Only show the animation on the first request, not after e.g. tab switching.
|
|
|
|
anchor.addEventListener(
|
|
|
|
"animationend",
|
|
|
|
() => anchor.removeAttribute("animate"),
|
|
|
|
{ once: true }
|
|
|
|
);
|
|
|
|
anchor.setAttribute("animate", "true");
|
|
|
|
}
|
|
|
|
|
|
|
|
this._showNotification(popupNotificationActions, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
_showNotification(actions, postPrompt = false) {
|
2019-04-18 16:43:29 +03:00
|
|
|
let chromeWin = this.browser.ownerGlobal;
|
2019-04-05 13:22:19 +03:00
|
|
|
let mainAction = actions.length ? actions[0] : null;
|
|
|
|
let secondaryActions = actions.splice(1);
|
2016-08-28 06:11:07 +03:00
|
|
|
|
|
|
|
let options = this.popupOptions;
|
2016-10-04 08:27:32 +03:00
|
|
|
|
|
|
|
if (!options.hasOwnProperty("displayURI") || options.displayURI) {
|
|
|
|
options.displayURI = this.principal.URI;
|
|
|
|
}
|
2019-04-05 13:22:19 +03:00
|
|
|
|
|
|
|
if (!postPrompt) {
|
|
|
|
// Permission prompts are always persistent; the close button is controlled by a pref.
|
|
|
|
options.persistent = true;
|
|
|
|
options.hideClose = true;
|
|
|
|
}
|
|
|
|
|
2021-06-08 03:41:43 +03:00
|
|
|
if (!mainAction.hasOwnProperty("disableHighlight")) {
|
2021-03-08 20:45:21 +03:00
|
|
|
mainAction.disableHighlight = true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 19:17:54 +03:00
|
|
|
options.eventCallback = (topic, nextRemovalReason, isCancel) => {
|
2018-07-03 02:17:16 +03:00
|
|
|
// 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.
|
2019-04-05 13:22:19 +03:00
|
|
|
// onShown() is currently not called for post-prompts,
|
|
|
|
// because there is no prompt that would make use of this.
|
|
|
|
// You can remove this restriction if you need it, but be
|
|
|
|
// mindful of other consumers.
|
|
|
|
if (topic == "shown" && !postPrompt) {
|
2018-11-27 00:23:16 +03:00
|
|
|
this.onShown();
|
|
|
|
}
|
2018-07-03 02:17:16 +03:00
|
|
|
// The prompt has been removed, notify the PermissionUI.
|
2019-04-05 13:22:19 +03:00
|
|
|
// onAfterShow() is currently not called for post-prompts,
|
|
|
|
// because there is no prompt that would make use of this.
|
|
|
|
// You can remove this restriction if you need it, but be
|
|
|
|
// mindful of other consumers.
|
|
|
|
if (topic == "removed" && !postPrompt) {
|
2019-07-24 19:17:54 +03:00
|
|
|
if (isCancel) {
|
|
|
|
this.cancel();
|
|
|
|
}
|
2018-07-03 02:17:16 +03:00
|
|
|
this.onAfterShow();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2016-08-28 06:11:07 +03:00
|
|
|
|
2019-04-05 13:22:19 +03:00
|
|
|
// Post-prompts show up as dismissed.
|
|
|
|
options.dismissed = postPrompt;
|
|
|
|
|
|
|
|
// onBeforeShow() is currently not called for post-prompts,
|
|
|
|
// because there is no prompt that would make use of this.
|
|
|
|
// You can remove this restriction if you need it, but be
|
|
|
|
// mindful of other consumers.
|
|
|
|
if (postPrompt || this.onBeforeShow() !== false) {
|
2018-11-25 22:03:30 +03:00
|
|
|
chromeWin.PopupNotifications.show(
|
|
|
|
this.browser,
|
|
|
|
this.notificationID,
|
|
|
|
this.message,
|
|
|
|
this.anchorID,
|
|
|
|
mainAction,
|
|
|
|
secondaryActions,
|
|
|
|
options
|
|
|
|
);
|
|
|
|
}
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
var PermissionPromptForRequestPrototype = {
|
|
|
|
__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() {
|
2019-12-04 18:39:26 +03:00
|
|
|
let request = this.request.QueryInterface(Ci.nsIContentPermissionRequest);
|
|
|
|
return request.getDelegatePrincipal(this.type);
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
2019-12-04 18:39:03 +03:00
|
|
|
get type() {
|
|
|
|
return "geo";
|
|
|
|
},
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
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,
|
2019-12-04 18:39:26 +03:00
|
|
|
name: this.getPrincipalName(),
|
2016-08-28 06:11:07 +03:00
|
|
|
};
|
2016-11-20 20:40:26 +03:00
|
|
|
|
2019-09-26 13:47:33 +03:00
|
|
|
if (this.principal.schemeIs("file")) {
|
2016-11-20 20:40:26 +03:00
|
|
|
options.checkbox = { show: false };
|
|
|
|
} else {
|
|
|
|
// Don't offer "always remember" action in PB mode
|
|
|
|
options.checkbox = {
|
|
|
|
show: !PrivateBrowsingUtils.isWindowPrivate(this.browser.ownerGlobal),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-12-04 18:39:26 +03:00
|
|
|
if (this.request.maybeUnsafePermissionDelegate) {
|
|
|
|
// Second name should be the third party origin
|
|
|
|
options.secondName = this.getPrincipalName(this.request.principal);
|
|
|
|
options.checkbox = { show: false };
|
|
|
|
}
|
|
|
|
|
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() {
|
2019-09-26 13:47:33 +03:00
|
|
|
if (this.principal.schemeIs("file")) {
|
2021-03-03 23:19:31 +03:00
|
|
|
return gBrowserBundle.GetStringFromName("geolocation.shareWithFile4");
|
2016-08-28 06:11:07 +03:00
|
|
|
}
|
2018-02-27 23:31:55 +03:00
|
|
|
|
2019-12-04 18:39:26 +03:00
|
|
|
if (this.request.maybeUnsafePermissionDelegate) {
|
|
|
|
return gBrowserBundle.formatStringFromName(
|
2021-03-03 23:19:31 +03:00
|
|
|
"geolocation.shareWithSiteUnsafeDelegation2",
|
2019-12-04 18:39:26 +03:00
|
|
|
["<>", "{}"]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-03 23:19:31 +03:00
|
|
|
return gBrowserBundle.formatStringFromName("geolocation.shareWithSite4", [
|
2019-06-11 18:51:51 +03:00
|
|
|
"<>",
|
|
|
|
]);
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get promptActions() {
|
2016-11-20 20:40:26 +03:00
|
|
|
return [
|
|
|
|
{
|
2021-03-03 23:19:31 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("geolocation.allow"),
|
2016-11-20 20:40:26 +03:00
|
|
|
accessKey: gBrowserBundle.GetStringFromName(
|
2021-03-03 23:19:31 +03:00
|
|
|
"geolocation.allow.accesskey"
|
2016-11-20 20:40:26 +03:00
|
|
|
),
|
2016-09-23 00:09:30 +03:00
|
|
|
action: SitePermissions.ALLOW,
|
2016-11-20 20:40:26 +03:00
|
|
|
},
|
|
|
|
{
|
2021-03-03 23:19:31 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("geolocation.block"),
|
2016-11-20 20:40:26 +03:00
|
|
|
accessKey: gBrowserBundle.GetStringFromName(
|
2021-03-03 23:19:31 +03:00
|
|
|
"geolocation.block.accesskey"
|
2016-11-20 20:40:26 +03:00
|
|
|
),
|
2016-09-23 00:09:30 +03:00
|
|
|
action: SitePermissions.BLOCK,
|
2016-11-20 20:40:26 +03:00
|
|
|
},
|
|
|
|
];
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
2019-07-30 11:28:31 +03:00
|
|
|
|
|
|
|
_updateGeoSharing(state) {
|
|
|
|
let gBrowser = this.browser.ownerGlobal.gBrowser;
|
|
|
|
if (gBrowser == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gBrowser.updateBrowserSharing(this.browser, { geo: state });
|
2019-09-25 12:16:32 +03:00
|
|
|
|
|
|
|
// Update last access timestamp
|
2019-07-30 11:28:31 +03:00
|
|
|
let host;
|
|
|
|
try {
|
|
|
|
host = this.browser.currentURI.host;
|
|
|
|
} catch (e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (host == null || host == "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ContentPrefService2.set(
|
|
|
|
this.browser.currentURI.host,
|
|
|
|
"permissions.geoLocation.lastAccess",
|
|
|
|
new Date().toString(),
|
|
|
|
this.browser.loadContext
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
allow(...args) {
|
|
|
|
this._updateGeoSharing(true);
|
|
|
|
PermissionPromptForRequestPrototype.allow.apply(this, args);
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel(...args) {
|
|
|
|
this._updateGeoSharing(false);
|
|
|
|
PermissionPromptForRequestPrototype.cancel.apply(this, args);
|
|
|
|
},
|
2016-08-28 06:11:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.GeolocationPermissionPrompt = GeolocationPermissionPrompt;
|
|
|
|
|
2019-12-12 06:10:51 +03:00
|
|
|
/**
|
|
|
|
* Creates a PermissionPrompt for a nsIContentPermissionRequest for
|
|
|
|
* the WebXR API.
|
|
|
|
*
|
|
|
|
* @param request (nsIContentPermissionRequest)
|
|
|
|
* The request for a permission from content.
|
|
|
|
*/
|
|
|
|
function XRPermissionPrompt(request) {
|
|
|
|
this.request = request;
|
|
|
|
}
|
|
|
|
|
|
|
|
XRPermissionPrompt.prototype = {
|
|
|
|
__proto__: PermissionPromptForRequestPrototype,
|
|
|
|
|
|
|
|
get type() {
|
|
|
|
return "xr";
|
|
|
|
},
|
|
|
|
|
|
|
|
get permissionKey() {
|
|
|
|
return "xr";
|
|
|
|
},
|
|
|
|
|
|
|
|
get popupOptions() {
|
|
|
|
let pref = "browser.xr.warning.infoURL";
|
|
|
|
let options = {
|
|
|
|
learnMoreURL: Services.urlFormatter.formatURLPref(pref),
|
|
|
|
displayURI: false,
|
|
|
|
name: this.getPrincipalName(),
|
|
|
|
};
|
|
|
|
|
2020-05-18 16:52:21 +03:00
|
|
|
if (this.principal.schemeIs("file")) {
|
2019-12-12 06:10:51 +03:00
|
|
|
options.checkbox = { show: false };
|
|
|
|
} else {
|
|
|
|
// Don't offer "always remember" action in PB mode
|
|
|
|
options.checkbox = {
|
|
|
|
show: !PrivateBrowsingUtils.isWindowPrivate(this.browser.ownerGlobal),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.checkbox.show) {
|
|
|
|
options.checkbox.label = gBrowserBundle.GetStringFromName("xr.remember");
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
},
|
|
|
|
|
|
|
|
get notificationID() {
|
|
|
|
return "xr";
|
|
|
|
},
|
|
|
|
|
|
|
|
get anchorID() {
|
|
|
|
return "xr-notification-icon";
|
|
|
|
},
|
|
|
|
|
|
|
|
get message() {
|
2020-05-18 16:52:21 +03:00
|
|
|
if (this.principal.schemeIs("file")) {
|
2021-03-08 23:04:15 +03:00
|
|
|
return gBrowserBundle.GetStringFromName("xr.shareWithFile4");
|
2019-12-12 06:10:51 +03:00
|
|
|
}
|
|
|
|
|
2021-03-08 23:04:15 +03:00
|
|
|
return gBrowserBundle.formatStringFromName("xr.shareWithSite4", ["<>"]);
|
2019-12-12 06:10:51 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get promptActions() {
|
|
|
|
return [
|
|
|
|
{
|
2021-03-08 23:04:15 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("xr.allow2"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName("xr.allow2.accesskey"),
|
2019-12-12 06:10:51 +03:00
|
|
|
action: SitePermissions.ALLOW,
|
|
|
|
},
|
|
|
|
{
|
2021-03-08 23:04:15 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("xr.block"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName("xr.block.accesskey"),
|
2019-12-12 06:10:51 +03:00
|
|
|
action: SitePermissions.BLOCK,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateXRSharing(state) {
|
|
|
|
let gBrowser = this.browser.ownerGlobal.gBrowser;
|
|
|
|
if (gBrowser == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gBrowser.updateBrowserSharing(this.browser, { xr: state });
|
|
|
|
|
|
|
|
let devicePermOrigins = this.browser.getDevicePermissionOrigins("xr");
|
|
|
|
if (!state) {
|
|
|
|
devicePermOrigins.delete(this.principal.origin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
devicePermOrigins.add(this.principal.origin);
|
|
|
|
},
|
|
|
|
|
|
|
|
allow(...args) {
|
|
|
|
this._updateXRSharing(true);
|
|
|
|
PermissionPromptForRequestPrototype.allow.apply(this, args);
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel(...args) {
|
|
|
|
this._updateXRSharing(false);
|
|
|
|
PermissionPromptForRequestPrototype.cancel.apply(this, args);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.XRPermissionPrompt = XRPermissionPrompt;
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
/**
|
|
|
|
* 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;
|
2019-03-15 13:43:17 +03:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(
|
|
|
|
this,
|
|
|
|
"requiresUserInput",
|
|
|
|
"dom.webnotifications.requireuserinteraction"
|
|
|
|
);
|
2019-04-05 13:22:19 +03:00
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(
|
|
|
|
this,
|
|
|
|
"postPromptEnabled",
|
|
|
|
"permissions.desktop-notification.postPrompt.enabled"
|
|
|
|
);
|
2019-08-22 19:24:56 +03:00
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(
|
|
|
|
this,
|
|
|
|
"notNowEnabled",
|
|
|
|
"permissions.desktop-notification.notNow.enabled"
|
|
|
|
);
|
2016-08-28 06:11:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DesktopNotificationPermissionPrompt.prototype = {
|
|
|
|
__proto__: PermissionPromptForRequestPrototype,
|
|
|
|
|
2019-12-04 18:39:03 +03:00
|
|
|
get type() {
|
|
|
|
return "desktop-notification";
|
|
|
|
},
|
|
|
|
|
2016-08-28 06:11:07 +03:00
|
|
|
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,
|
2019-12-04 18:39:26 +03:00
|
|
|
name: this.getPrincipalName(),
|
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(
|
2021-03-10 00:26:17 +03:00
|
|
|
"webNotifications.receiveFromSite3",
|
2019-06-11 18:51:51 +03:00
|
|
|
["<>"]
|
|
|
|
);
|
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
|
|
|
{
|
2021-03-10 00:26:17 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("webNotifications.allow2"),
|
2016-11-20 20:40:26 +03:00
|
|
|
accessKey: gBrowserBundle.GetStringFromName(
|
2021-03-10 00:26:17 +03:00
|
|
|
"webNotifications.allow2.accesskey"
|
2016-11-20 20:40:26 +03:00
|
|
|
),
|
2016-09-23 00:09:30 +03:00
|
|
|
action: SitePermissions.ALLOW,
|
2017-02-25 05:42:36 +03:00
|
|
|
scope: SitePermissions.SCOPE_PERSISTENT,
|
|
|
|
},
|
2017-03-23 09:07:30 +03:00
|
|
|
];
|
2019-08-22 19:24:56 +03:00
|
|
|
if (this.notNowEnabled) {
|
2017-03-23 09:07:30 +03:00
|
|
|
actions.push({
|
2019-08-22 19:24:56 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("webNotifications.notNow"),
|
2017-02-25 05:42:36 +03:00
|
|
|
accessKey: gBrowserBundle.GetStringFromName(
|
2019-08-22 19:24:56 +03:00
|
|
|
"webNotifications.notNow.accesskey"
|
2017-02-25 05:42:36 +03:00
|
|
|
),
|
2016-09-23 00:09:30 +03:00
|
|
|
action: SitePermissions.BLOCK,
|
2017-03-23 09:07:30 +03:00
|
|
|
});
|
|
|
|
}
|
2021-03-10 00:26:17 +03:00
|
|
|
|
|
|
|
let isBrowserPrivate = PrivateBrowsingUtils.isBrowserPrivate(this.browser);
|
2019-08-22 19:24:56 +03:00
|
|
|
actions.push({
|
2021-03-10 00:26:17 +03:00
|
|
|
label: isBrowserPrivate
|
|
|
|
? gBrowserBundle.GetStringFromName("webNotifications.block")
|
|
|
|
: gBrowserBundle.GetStringFromName("webNotifications.alwaysBlock"),
|
|
|
|
accessKey: isBrowserPrivate
|
|
|
|
? gBrowserBundle.GetStringFromName("webNotifications.block.accesskey")
|
|
|
|
: gBrowserBundle.GetStringFromName(
|
|
|
|
"webNotifications.alwaysBlock.accesskey"
|
|
|
|
),
|
2019-08-22 19:24:56 +03:00
|
|
|
action: SitePermissions.BLOCK,
|
2021-03-10 00:26:17 +03:00
|
|
|
scope: isBrowserPrivate
|
2019-08-22 19:24:56 +03:00
|
|
|
? SitePermissions.SCOPE_SESSION
|
|
|
|
: SitePermissions.SCOPE_PERSISTENT,
|
|
|
|
});
|
2017-03-23 09:07:30 +03:00
|
|
|
return actions;
|
2016-08-28 06:11:07 +03:00
|
|
|
},
|
2019-04-05 13:22:19 +03:00
|
|
|
|
|
|
|
get postPromptActions() {
|
2021-03-10 00:26:17 +03:00
|
|
|
let actions = [
|
2019-04-05 13:22:19 +03:00
|
|
|
{
|
2021-03-10 00:26:17 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("webNotifications.allow2"),
|
2019-04-05 13:22:19 +03:00
|
|
|
accessKey: gBrowserBundle.GetStringFromName(
|
2021-03-10 00:26:17 +03:00
|
|
|
"webNotifications.allow2.accesskey"
|
2019-04-05 13:22:19 +03:00
|
|
|
),
|
|
|
|
action: SitePermissions.ALLOW,
|
|
|
|
},
|
|
|
|
];
|
2021-03-10 00:26:17 +03:00
|
|
|
|
|
|
|
let isBrowserPrivate = PrivateBrowsingUtils.isBrowserPrivate(this.browser);
|
|
|
|
actions.push({
|
|
|
|
label: isBrowserPrivate
|
|
|
|
? gBrowserBundle.GetStringFromName("webNotifications.block")
|
|
|
|
: gBrowserBundle.GetStringFromName("webNotifications.alwaysBlock"),
|
|
|
|
accessKey: isBrowserPrivate
|
|
|
|
? gBrowserBundle.GetStringFromName("webNotifications.block.accesskey")
|
|
|
|
: gBrowserBundle.GetStringFromName(
|
|
|
|
"webNotifications.alwaysBlock.accesskey"
|
|
|
|
),
|
|
|
|
action: SitePermissions.BLOCK,
|
|
|
|
});
|
|
|
|
return actions;
|
2019-04-05 13:22:19 +03:00
|
|
|
},
|
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,
|
|
|
|
|
2019-12-04 18:39:03 +03:00
|
|
|
get type() {
|
|
|
|
return "persistent-storage";
|
|
|
|
},
|
|
|
|
|
2017-04-11 07:07:29 +03:00
|
|
|
get permissionKey() {
|
|
|
|
return "persistent-storage";
|
|
|
|
},
|
|
|
|
|
|
|
|
get popupOptions() {
|
|
|
|
let learnMoreURL =
|
|
|
|
Services.urlFormatter.formatURLPref("app.support.baseURL") +
|
|
|
|
"storage-permissions";
|
2021-03-16 21:00:56 +03:00
|
|
|
return {
|
2017-12-14 18:30:28 +03:00
|
|
|
learnMoreURL,
|
2018-02-27 23:31:55 +03:00
|
|
|
displayURI: false,
|
2019-12-04 18:39:26 +03:00
|
|
|
name: this.getPrincipalName(),
|
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(
|
2021-03-05 00:59:23 +03:00
|
|
|
"persistentStorage.allowWithSite2",
|
2019-06-11 18:51:51 +03:00
|
|
|
["<>"]
|
|
|
|
);
|
2017-04-11 07:07:29 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get promptActions() {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: gBrowserBundle.GetStringFromName("persistentStorage.allow"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName(
|
|
|
|
"persistentStorage.allow.accesskey"
|
|
|
|
),
|
|
|
|
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(
|
2021-03-05 00:59:23 +03:00
|
|
|
"persistentStorage.block.label"
|
2018-11-02 11:15:05 +03:00
|
|
|
),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName(
|
2021-03-05 00:59:23 +03:00
|
|
|
"persistentStorage.block.accesskey"
|
2018-11-02 11:15:05 +03:00
|
|
|
),
|
|
|
|
action: SitePermissions.BLOCK,
|
|
|
|
},
|
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 =
|
2019-09-14 12:39:26 +03:00
|
|
|
!!perm.options.length &&
|
2017-11-15 22:13:12 +03:00
|
|
|
perm.options.queryElementAt(0, Ci.nsISupportsString) == "sysex";
|
|
|
|
this.permName = "midi";
|
|
|
|
if (this.isSysexPerm) {
|
|
|
|
this.permName = "midi-sysex";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MIDIPermissionPrompt.prototype = {
|
|
|
|
__proto__: PermissionPromptForRequestPrototype,
|
|
|
|
|
2019-12-04 18:39:03 +03:00
|
|
|
get type() {
|
|
|
|
return "midi";
|
|
|
|
},
|
|
|
|
|
2017-11-15 22:13:12 +03:00
|
|
|
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,
|
2019-12-04 18:39:26 +03:00
|
|
|
name: this.getPrincipalName(),
|
2017-11-15 22:13:12 +03:00
|
|
|
};
|
|
|
|
|
2019-09-26 13:47:33 +03:00
|
|
|
if (this.principal.schemeIs("file")) {
|
2017-11-15 22:13:12 +03:00
|
|
|
options.checkbox = { show: false };
|
|
|
|
} else {
|
|
|
|
// Don't offer "always remember" action in PB mode
|
|
|
|
options.checkbox = {
|
|
|
|
show: !PrivateBrowsingUtils.isWindowPrivate(this.browser.ownerGlobal),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2019-09-26 13:47:33 +03:00
|
|
|
if (this.principal.schemeIs("file")) {
|
2017-11-15 22:13:12 +03:00
|
|
|
if (this.isSysexPerm) {
|
2021-03-03 23:17:46 +03:00
|
|
|
message = gBrowserBundle.GetStringFromName("midi.shareSysexWithFile");
|
2017-11-15 22:13:12 +03:00
|
|
|
} else {
|
2021-03-03 23:17:46 +03:00
|
|
|
message = gBrowserBundle.GetStringFromName("midi.shareWithFile");
|
2017-11-15 22:13:12 +03:00
|
|
|
}
|
2018-02-27 23:31:55 +03:00
|
|
|
} else if (this.isSysexPerm) {
|
2021-03-03 23:17:46 +03:00
|
|
|
message = gBrowserBundle.formatStringFromName("midi.shareSysexWithSite", [
|
|
|
|
"<>",
|
|
|
|
]);
|
2017-11-15 22:13:12 +03:00
|
|
|
} else {
|
2021-03-03 23:17:46 +03:00
|
|
|
message = gBrowserBundle.formatStringFromName("midi.shareWithSite", [
|
|
|
|
"<>",
|
|
|
|
]);
|
2017-11-15 22:13:12 +03:00
|
|
|
}
|
|
|
|
return message;
|
|
|
|
},
|
|
|
|
|
|
|
|
get promptActions() {
|
|
|
|
return [
|
|
|
|
{
|
2021-03-03 23:17:46 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("midi.allow.label"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName("midi.allow.accesskey"),
|
2017-11-15 22:13:12 +03:00
|
|
|
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
|
|
|
},
|
|
|
|
{
|
2021-03-03 23:17:46 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("midi.block.label"),
|
|
|
|
accessKey: gBrowserBundle.GetStringFromName("midi.block.accesskey"),
|
2017-11-15 22:13:12 +03:00
|
|
|
action: Ci.nsIPermissionManager.DENY_ACTION,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.MIDIPermissionPrompt = MIDIPermissionPrompt;
|
2018-05-18 14:54:33 +03:00
|
|
|
|
2018-11-27 00:23:16 +03:00
|
|
|
function StorageAccessPermissionPrompt(request) {
|
|
|
|
this.request = request;
|
|
|
|
}
|
|
|
|
|
|
|
|
StorageAccessPermissionPrompt.prototype = {
|
|
|
|
__proto__: PermissionPromptForRequestPrototype,
|
|
|
|
|
|
|
|
get usePermissionManager() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2019-12-04 18:39:03 +03:00
|
|
|
get type() {
|
|
|
|
return "storage-access";
|
|
|
|
},
|
|
|
|
|
2018-11-27 00:23:16 +03:00
|
|
|
get permissionKey() {
|
|
|
|
// Make sure this name is unique per each third-party tracker
|
|
|
|
return "storage-access-" + this.principal.origin;
|
|
|
|
},
|
|
|
|
|
2020-05-18 16:50:14 +03:00
|
|
|
prettifyHostPort(hostport) {
|
|
|
|
let [host, port] = hostport.split(":");
|
|
|
|
host = IDNService.convertToDisplayIDN(host, {});
|
|
|
|
if (port) {
|
|
|
|
return `${host}:${port}`;
|
2018-11-30 05:17:50 +03:00
|
|
|
}
|
|
|
|
return host;
|
|
|
|
},
|
|
|
|
|
2018-11-27 00:23:16 +03:00
|
|
|
get popupOptions() {
|
2019-12-11 13:08:19 +03:00
|
|
|
let learnMoreURL =
|
|
|
|
Services.urlFormatter.formatURLPref("app.support.baseURL") +
|
|
|
|
"third-party-cookies";
|
2020-07-21 14:26:36 +03:00
|
|
|
let hostPort = this.prettifyHostPort(this.principal.hostPort);
|
|
|
|
let hintText = gBrowserBundle.formatStringFromName(
|
|
|
|
"storageAccess.hintText",
|
|
|
|
[hostPort]
|
|
|
|
);
|
2018-11-27 00:23:16 +03:00
|
|
|
return {
|
2019-12-11 13:08:19 +03:00
|
|
|
learnMoreURL,
|
2018-11-27 00:23:16 +03:00
|
|
|
displayURI: false,
|
2020-07-21 14:26:36 +03:00
|
|
|
name: hostPort,
|
|
|
|
hintText,
|
|
|
|
escAction: "secondarybuttoncommand",
|
2018-11-27 00:23:16 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
get notificationID() {
|
|
|
|
return "storage-access";
|
|
|
|
},
|
|
|
|
|
|
|
|
get anchorID() {
|
|
|
|
return "storage-access-notification-icon";
|
|
|
|
},
|
|
|
|
|
|
|
|
get message() {
|
2020-07-21 14:26:36 +03:00
|
|
|
return gBrowserBundle.formatStringFromName("storageAccess3.message", [
|
2019-06-11 18:51:51 +03:00
|
|
|
"<>",
|
2020-07-21 14:26:36 +03:00
|
|
|
this.prettifyHostPort(this.topLevelPrincipal.hostPort),
|
|
|
|
this.prettifyHostPort(this.principal.hostPort),
|
2019-06-11 18:51:51 +03:00
|
|
|
]);
|
2018-11-27 00:23:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get promptActions() {
|
|
|
|
let self = this;
|
2019-01-30 15:41:58 +03:00
|
|
|
|
2018-11-27 00:23:16 +03:00
|
|
|
return [
|
|
|
|
{
|
2020-07-21 14:26:36 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName("storageAccess.Allow.label"),
|
2018-11-27 00:23:16 +03:00
|
|
|
accessKey: gBrowserBundle.GetStringFromName(
|
2020-07-21 14:26:36 +03:00
|
|
|
"storageAccess.Allow.accesskey"
|
2018-11-27 00:23:16 +03:00
|
|
|
),
|
2020-07-21 14:26:36 +03:00
|
|
|
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
2018-11-27 00:23:16 +03:00
|
|
|
callback(state) {
|
2020-07-21 14:26:36 +03:00
|
|
|
self.allow({ "storage-access": "allow" });
|
2018-11-27 00:23:16 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-21 14:26:36 +03:00
|
|
|
label: gBrowserBundle.GetStringFromName(
|
|
|
|
"storageAccess.DontAllow.label"
|
|
|
|
),
|
2018-11-27 00:23:16 +03:00
|
|
|
accessKey: gBrowserBundle.GetStringFromName(
|
2020-07-21 14:26:36 +03:00
|
|
|
"storageAccess.DontAllow.accesskey"
|
2018-11-27 00:23:16 +03:00
|
|
|
),
|
2020-07-21 14:26:36 +03:00
|
|
|
action: Ci.nsIPermissionManager.DENY_ACTION,
|
2018-11-27 00:23:16 +03:00
|
|
|
callback(state) {
|
2020-07-21 14:26:36 +03:00
|
|
|
self.cancel();
|
2018-11-27 00:23:16 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
},
|
|
|
|
|
|
|
|
get topLevelPrincipal() {
|
|
|
|
return this.request.topLevelPrincipal;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
PermissionUI.StorageAccessPermissionPrompt = StorageAccessPermissionPrompt;
|