Bug 1570674 - Default to "Never Allow" for notification permission prompt denials. r=Ehsan
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 22 Aug 2019 16:24:56 +0000
changeset 553211 15d0f55c9720876fd43194c1b79a9362f1e8a8ce
parent 553210 a74f854d44b261b793a810b5014f10dc691c85b1
child 553212 01ed7f4e9a8f62f1761b6048539cd220cdc74827
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1570674
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1570674 - Default to "Never Allow" for notification permission prompt denials. r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D43081
browser/app/profile/firefox.js
browser/base/content/test/permissions/browser_permissions_event_telemetry.js
browser/modules/PermissionUI.jsm
browser/modules/test/browser/browser_PermissionUI_prompts.js
dom/notification/test/browser/browser_permission_dismiss.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -395,16 +395,18 @@ pref("permissions.default.desktop-notifi
 pref("permissions.default.shortcuts", 0);
 
 #ifdef EARLY_BETA_OR_EARLIER
   pref("permissions.desktop-notification.postPrompt.enabled", true);
 #else
   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);
 
 // This is primarily meant to be enabled for studies.
 #ifdef NIGHTLY_BUILD
   pref("permissions.eventTelemetry.enabled", true);
 #else
--- a/browser/base/content/test/permissions/browser_permissions_event_telemetry.js
+++ b/browser/base/content/test/permissions/browser_permissions_event_telemetry.js
@@ -95,16 +95,20 @@ function checkEventTelemetry(method) {
   );
 }
 
 add_task(async function setup() {
   let oldCanRecord = Services.telemetry.canRecordExtended;
   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);
   let uri2 = Services.io.newURI("https://example.org");
   let uri3 = Services.io.newURI("http://sub.example.org");
   PermissionTestUtils.add(uri, "geo", Services.perms.ALLOW_ACTION);
   PermissionTestUtils.add(
     uri3,
@@ -113,16 +117,19 @@ add_task(async function setup() {
   );
   PermissionTestUtils.add(uri2, "microphone", Services.perms.DENY_ACTION);
   PermissionTestUtils.add(uri, "camera", Services.perms.DENY_ACTION);
   PermissionTestUtils.add(uri2, "geo", Services.perms.DENY_ACTION);
 
   registerCleanupFunction(() => {
     Services.perms.removeAll();
     Services.prefs.clearUserPref("permissions.eventTelemetry.enabled");
+    Services.prefs.clearUserPref(
+      "permissions.desktop-notification.notNow.enabled"
+    );
     Services.telemetry.canRecordExtended = oldCanRecord;
   });
 
   Services.telemetry.clearEvents();
 });
 
 add_task(async function testAccept() {
   await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function(browser) {
--- a/browser/modules/PermissionUI.jsm
+++ b/browser/modules/PermissionUI.jsm
@@ -867,16 +867,21 @@ function DesktopNotificationPermissionPr
     "requiresUserInput",
     "dom.webnotifications.requireuserinteraction"
   );
   XPCOMUtils.defineLazyPreferenceGetter(
     this,
     "postPromptEnabled",
     "permissions.desktop-notification.postPrompt.enabled"
   );
+  XPCOMUtils.defineLazyPreferenceGetter(
+    this,
+    "notNowEnabled",
+    "permissions.desktop-notification.notNow.enabled"
+  );
 }
 
 DesktopNotificationPermissionPrompt.prototype = {
   __proto__: PermissionPromptForRequestPrototype,
 
   get permissionKey() {
     return "desktop-notification";
   },
@@ -916,34 +921,36 @@ DesktopNotificationPermissionPrompt.prot
       {
         label: gBrowserBundle.GetStringFromName("webNotifications.allow"),
         accessKey: gBrowserBundle.GetStringFromName(
           "webNotifications.allow.accesskey"
         ),
         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;
   },
 
   get postPromptActions() {
     return [
       {
         label: gBrowserBundle.GetStringFromName("webNotifications.allow"),
         accessKey: gBrowserBundle.GetStringFromName(
--- a/browser/modules/test/browser/browser_PermissionUI_prompts.js
+++ b/browser/modules/test/browser/browser_PermissionUI_prompts.js
@@ -19,18 +19,25 @@ add_task(async function test_geo_permiss
 });
 
 // Tests that DesktopNotificationPermissionPrompt works as expected
 add_task(async function test_desktop_notification_permission_prompt() {
   Services.prefs.setBoolPref(
     "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
 add_task(async function test_persistent_storage_permission_prompt() {
   await testPrompt(PermissionUI.PersistentStoragePermissionPrompt);
 });
 
 // Tests that MidiPrompt works as expected
--- a/dom/notification/test/browser/browser_permission_dismiss.js
+++ b/dom/notification/test/browser/browser_permission_dismiss.js
@@ -91,18 +91,25 @@ function tabWithRequest(task, permission
   );
 }
 
 add_task(async function setup() {
   Services.prefs.setBoolPref(
     "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);
   });
 });
 
 add_task(async function test_requestPermission_granted() {
   await tabWithRequest(function() {
     clickDoorhangerButton(PROMPT_ALLOW_BUTTON);
   }, "granted");