зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1524619 - Part 1 - Add support for requiring user gestures for push notifications. r=Ehsan,MattN
Differential Revision: https://phabricator.services.mozilla.com/D23647 --HG-- extra : rebase_source : ef6bb77983b135c0c352e8fe0a37ba72e4f69718
This commit is contained in:
Родитель
f5a09d85ce
Коммит
79332e3ef4
|
@ -166,6 +166,14 @@ var PermissionPromptPrototype = {
|
|||
return {};
|
||||
},
|
||||
|
||||
/**
|
||||
* If true, the prompt will be cancelled automatically unless
|
||||
* request.isHandlingUserInput is true.
|
||||
*/
|
||||
get requiresUserInput() {
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* PopupNotification requires a unique ID to open the notification.
|
||||
* You must return a unique ID string here, for which PopupNotification
|
||||
|
@ -332,6 +340,11 @@ var PermissionPromptPrototype = {
|
|||
}
|
||||
}
|
||||
|
||||
if (this.requiresUserInput && !this.request.isHandlingUserInput) {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
let chromeWin = this.browser.ownerGlobal;
|
||||
if (!chromeWin.PopupNotifications) {
|
||||
this.cancel();
|
||||
|
@ -570,6 +583,9 @@ PermissionUI.GeolocationPermissionPrompt = GeolocationPermissionPrompt;
|
|||
*/
|
||||
function DesktopNotificationPermissionPrompt(request) {
|
||||
this.request = request;
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(this, "requiresUserInput",
|
||||
"dom.webnotifications.requireuserinteraction");
|
||||
}
|
||||
|
||||
DesktopNotificationPermissionPrompt.prototype = {
|
||||
|
|
|
@ -317,6 +317,7 @@ LargeAllocationNotOnlyToplevelInTabGroup=A Large-Allocation header was ignored d
|
|||
LargeAllocationNonE10S=A Large-Allocation header was ignored due to the document not being loaded out of process.
|
||||
GeolocationInsecureRequestIsForbidden=A Geolocation request can only be fulfilled in a secure context.
|
||||
NotificationsInsecureRequestIsForbidden=The Notification permission may only be requested in a secure context.
|
||||
NotificationsRequireUserGesture=The Notification permission may only be requested from inside a short running user-generated event handler.
|
||||
# LOCALIZATION NOTE: Do not translate "Large-Allocation", as it is a literal header name.
|
||||
LargeAllocationNonWin32=This page would be loaded in a new process due to a Large-Allocation header, however Large-Allocation process creation is disabled on non-Win32 platforms.
|
||||
# LOCALIZATION NOTE: Do not translate "content", "Window", and "window.top"
|
||||
|
|
|
@ -554,9 +554,23 @@ inline nsresult NotificationPermissionRequest::DispatchResolvePromise() {
|
|||
|
||||
nsresult NotificationPermissionRequest::ResolvePromise() {
|
||||
nsresult rv = NS_OK;
|
||||
// This will still be "default" if the user dismissed the doorhanger,
|
||||
// or "denied" otherwise.
|
||||
if (mPermission == NotificationPermission::Default) {
|
||||
// This will still be "default" if the user dismissed the doorhanger,
|
||||
// or "denied" otherwise.
|
||||
// When the front-end has decided to deny the permission request
|
||||
// automatically and we are not handling user input, then log a
|
||||
// warning in the current document that this happened because
|
||||
// Notifications require a user gesture.
|
||||
if (!mIsHandlingUserInput &&
|
||||
StaticPrefs::dom_webnotifications_requireuserinteraction()) {
|
||||
nsCOMPtr<Document> doc = mWindow->GetExtantDoc();
|
||||
if (doc) {
|
||||
nsContentUtils::ReportToConsole(
|
||||
nsIScriptError::errorFlag, NS_LITERAL_CSTRING("DOM"), doc,
|
||||
nsContentUtils::eDOM_PROPERTIES, "NotificationsRequireUserGesture");
|
||||
}
|
||||
}
|
||||
|
||||
mPermission = Notification::TestPermission(mPrincipal);
|
||||
}
|
||||
if (mCallback) {
|
||||
|
@ -1539,7 +1553,7 @@ already_AddRefed<Promise> Notification::RequestPermission(
|
|||
do_QueryInterface(aGlobal.GetAsSupports());
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> sop =
|
||||
do_QueryInterface(aGlobal.GetAsSupports());
|
||||
if (!sop) {
|
||||
if (!sop || !window) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -324,6 +324,12 @@ VARCACHE_PREF(
|
|||
RelaxedAtomicBool, false
|
||||
)
|
||||
|
||||
VARCACHE_PREF(
|
||||
"dom.webnotifications.requireuserinteraction",
|
||||
dom_webnotifications_requireuserinteraction,
|
||||
RelaxedAtomicBool, false
|
||||
)
|
||||
|
||||
VARCACHE_PREF(
|
||||
"dom.webnotifications.serviceworker.enabled",
|
||||
dom_webnotifications_serviceworker_enabled,
|
||||
|
|
Загрузка…
Ссылка в новой задаче