From e91d880e084f8fdc3a113dee486440c76e4e4231 Mon Sep 17 00:00:00 2001 From: Johann Hofmann Date: Thu, 22 Aug 2019 16:24:56 +0000 Subject: [PATCH] Bug 1570674 - Default to "Never Allow" for notification permission prompt denials. r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D43081 --HG-- extra : moz-landing-system : lando --- browser/app/profile/firefox.js | 2 ++ .../browser_permissions_event_telemetry.js | 7 +++++ browser/modules/PermissionUI.jsm | 29 ++++++++++++------- .../browser/browser_PermissionUI_prompts.js | 7 +++++ .../browser/browser_permission_dismiss.js | 7 +++++ 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 718afa668cd1..369c23ffb8f9 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -400,6 +400,8 @@ pref("permissions.default.shortcuts", 0); pref("permissions.desktop-notification.postPrompt.enabled", false); #endif +pref("permissions.desktop-notification.notNow.enabled", false); + pref("permissions.fullscreen.allowed", false); pref("permissions.postPrompt.animate", true); diff --git a/browser/base/content/test/permissions/browser_permissions_event_telemetry.js b/browser/base/content/test/permissions/browser_permissions_event_telemetry.js index 44be1ff80423..aef570cf3285 100644 --- a/browser/base/content/test/permissions/browser_permissions_event_telemetry.js +++ b/browser/base/content/test/permissions/browser_permissions_event_telemetry.js @@ -100,6 +100,10 @@ add_task(async function setup() { Services.telemetry.canRecordExtended = true; Services.prefs.setBoolPref("permissions.eventTelemetry.enabled", true); + Services.prefs.setBoolPref( + "permissions.desktop-notification.notNow.enabled", + true + ); // Add some example permissions. let uri = Services.io.newURI(PERMISSIONS_PAGE); @@ -118,6 +122,9 @@ add_task(async function setup() { registerCleanupFunction(() => { Services.perms.removeAll(); Services.prefs.clearUserPref("permissions.eventTelemetry.enabled"); + Services.prefs.clearUserPref( + "permissions.desktop-notification.notNow.enabled" + ); Services.telemetry.canRecordExtended = oldCanRecord; }); diff --git a/browser/modules/PermissionUI.jsm b/browser/modules/PermissionUI.jsm index 66a3e946ba5c..cbae0fb6e47f 100644 --- a/browser/modules/PermissionUI.jsm +++ b/browser/modules/PermissionUI.jsm @@ -872,6 +872,11 @@ function DesktopNotificationPermissionPrompt(request) { "postPromptEnabled", "permissions.desktop-notification.postPrompt.enabled" ); + XPCOMUtils.defineLazyPreferenceGetter( + this, + "notNowEnabled", + "permissions.desktop-notification.notNow.enabled" + ); } DesktopNotificationPermissionPrompt.prototype = { @@ -921,24 +926,26 @@ DesktopNotificationPermissionPrompt.prototype = { action: SitePermissions.ALLOW, scope: SitePermissions.SCOPE_PERSISTENT, }, - { + ]; + if (this.notNowEnabled) { + actions.push({ label: gBrowserBundle.GetStringFromName("webNotifications.notNow"), accessKey: gBrowserBundle.GetStringFromName( "webNotifications.notNow.accesskey" ), action: SitePermissions.BLOCK, - }, - ]; - if (!PrivateBrowsingUtils.isBrowserPrivate(this.browser)) { - actions.push({ - label: gBrowserBundle.GetStringFromName("webNotifications.never"), - accessKey: gBrowserBundle.GetStringFromName( - "webNotifications.never.accesskey" - ), - action: SitePermissions.BLOCK, - scope: SitePermissions.SCOPE_PERSISTENT, }); } + actions.push({ + label: gBrowserBundle.GetStringFromName("webNotifications.never"), + accessKey: gBrowserBundle.GetStringFromName( + "webNotifications.never.accesskey" + ), + action: SitePermissions.BLOCK, + scope: PrivateBrowsingUtils.isBrowserPrivate(this.browser) + ? SitePermissions.SCOPE_SESSION + : SitePermissions.SCOPE_PERSISTENT, + }); return actions; }, diff --git a/browser/modules/test/browser/browser_PermissionUI_prompts.js b/browser/modules/test/browser/browser_PermissionUI_prompts.js index 5b791796021d..35d5e5c6f8bb 100644 --- a/browser/modules/test/browser/browser_PermissionUI_prompts.js +++ b/browser/modules/test/browser/browser_PermissionUI_prompts.js @@ -24,8 +24,15 @@ add_task(async function test_desktop_notification_permission_prompt() { "dom.webnotifications.requireuserinteraction", false ); + Services.prefs.setBoolPref( + "permissions.desktop-notification.notNow.enabled", + true + ); await testPrompt(PermissionUI.DesktopNotificationPermissionPrompt); Services.prefs.clearUserPref("dom.webnotifications.requireuserinteraction"); + Services.prefs.clearUserPref( + "permissions.desktop-notification.notNow.enabled" + ); }); // Tests that PersistentStoragePermissionPrompt works as expected diff --git a/dom/notification/test/browser/browser_permission_dismiss.js b/dom/notification/test/browser/browser_permission_dismiss.js index c0572b2c11fa..c25ddb4ff689 100644 --- a/dom/notification/test/browser/browser_permission_dismiss.js +++ b/dom/notification/test/browser/browser_permission_dismiss.js @@ -96,8 +96,15 @@ add_task(async function setup() { "dom.webnotifications.requireuserinteraction", false ); + Services.prefs.setBoolPref( + "permissions.desktop-notification.notNow.enabled", + true + ); SimpleTest.registerCleanupFunction(() => { Services.prefs.clearUserPref("dom.webnotifications.requireuserinteraction"); + Services.prefs.clearUserPref( + "permissions.desktop-notification.notNow.enabled" + ); PermissionTestUtils.remove(ORIGIN_URI, PERMISSION_NAME); }); });