Bug 1478875 - add different default layout for autoplay prompt. draft
authoralwu <alwu@mozilla.com>
Thu, 26 Jul 2018 18:13:36 -0700
changeset 823578 ca05ef7375cc89724a11d4e47bdaaccc466ce734
parent 822792 9b59ea6c2845ba5501ddc45064bd965ab2afe38d
push id117733
push userbmo:alwu@mozilla.com
push dateFri, 27 Jul 2018 16:58:09 +0000
bugs1478875
milestone63.0a1
Bug 1478875 - add different default layout for autoplay prompt. In our shield-study, we want to provide different layout of prompt to different user groups. We need 4 different layouts for the default prompt. 0) [Allow], [Remember this decision] unchecked 1) [Don’t Allow], [Remember this decision] unchecked 2) [Allow], [Remember this decision] checked 3) [Don’t Allow], [Remember this decision] checked MozReview-Commit-ID: 6xnoH93viTY
browser/modules/PermissionUI.jsm
modules/libpref/init/all.js
--- a/browser/modules/PermissionUI.jsm
+++ b/browser/modules/PermissionUI.jsm
@@ -789,17 +789,20 @@ AutoplayPermissionPrompt.prototype = {
   },
 
   get popupOptions() {
     let checkbox = {
       show: !PrivateBrowsingUtils.isWindowPrivate(this.browser.ownerGlobal) &&
         !this.principal.URI.schemeIs("file")
     };
     if (checkbox.show) {
-      checkbox.checked = true;
+      let layout = Services.prefs.getIntPref("media.autoplay.prompt-layout");
+      if (layout >= 2) {
+        checkbox.checked = true;
+      }
       checkbox.label = gBrowserBundle.GetStringFromName("autoplay.remember");
     }
     return {
       checkbox,
       displayURI: false,
       name: this.principal.URI.hostPort,
     };
   },
@@ -815,26 +818,31 @@ AutoplayPermissionPrompt.prototype = {
   get message() {
     if (this.principal.URI.schemeIs("file")) {
       return gBrowserBundle.GetStringFromName("autoplay.messageWithFile");
     }
     return gBrowserBundle.formatStringFromName("autoplay.message", ["<>"], 1);
   },
 
   get promptActions() {
-    return [{
-        label: gBrowserBundle.GetStringFromName("autoplay.Allow2.label"),
-        accessKey: gBrowserBundle.GetStringFromName("autoplay.Allow2.accesskey"),
-        action: Ci.nsIPermissionManager.ALLOW_ACTION,
-      },
-      {
-        label: gBrowserBundle.GetStringFromName("autoplay.DontAllow.label"),
-        accessKey: gBrowserBundle.GetStringFromName("autoplay.DontAllow.accesskey"),
-        action: Ci.nsIPermissionManager.DENY_ACTION,
-    }];
+    let allowAction = {
+      label: gBrowserBundle.GetStringFromName("autoplay.Allow2.label"),
+      accessKey: gBrowserBundle.GetStringFromName("autoplay.Allow2.accesskey"),
+      action: Ci.nsIPermissionManager.ALLOW_ACTION,
+    };
+    let denyAction = {
+      label: gBrowserBundle.GetStringFromName("autoplay.DontAllow.label"),
+      accessKey: gBrowserBundle.GetStringFromName("autoplay.DontAllow.accesskey"),
+      action: Ci.nsIPermissionManager.DENY_ACTION,
+    };
+    let layout = Services.prefs.getIntPref("media.autoplay.prompt-layout");
+    if (layout == 0 || layout == 2) {
+      return [allowAction, denyAction];
+    }
+    return [denyAction, allowAction];
   },
 
   onAfterShow() {
     // Remove the event listener to prevent any leaks.
     this.browser.removeEventListener(
       "DOMAudioPlaybackStarted", this.handlePlaybackStart);
   },
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -562,16 +562,23 @@ pref("media.recorder.audio_node.enabled"
 // Whether MediaRecorder's video encoder should allow dropping frames in order
 // to keep up under load. Useful for tests but beware of memory consumption!
 pref("media.recorder.video.frame_drops", true);
 
 // Whether to autostart a media element with an |autoplay| attribute.
 // ALLOWED=0, BLOCKED=1, PROMPT=2, defined in dom/media/Autoplay.idl
 pref("media.autoplay.default", 0);
 
+// Use to control the default setting layout of doorhanger.
+// 0 = [Allow], [Remember this decision] unchecked
+// 1 = [Don’t Allow], [Remember this decision] unchecked
+// 2 = [Allow], [Remember this decision] checked
+// 3 = [Don’t Allow], [Remember this decision] checked
+pref("media.autoplay.prompt-layout", 2);
+
 // By default, don't block WebAudio from playing automatically.
 pref("media.autoplay.block-webaudio", false);
 
 // By default, don't block muted media from playing automatically.
 pref("media.autoplay.allow-muted", true);
 
 // If "media.autoplay.default" is not ALLOWED, and this pref is true,
 // then audible media would only be allowed to autoplay after website has