Bug 1513681 - part2 : handle 'GloballyAutoplayBlocked' event r=jaws,daleharvey
☠☠ backed out by 0c02d1f0db78 ☠ ☠
authoralwu <alwu@mozilla.com>
Fri, 28 Dec 2018 09:12:44 +0000
changeset 452105 d0a9422928aec6530c4def97000ef14cbdc5ca91
parent 452104 23b5a58e3bcce5a76f36f8f681b69d88d859a559
child 452106 79a78732c3ac2b91eee4378ba630da3090cccd2e
push id75321
push useralwu@mozilla.com
push dateSat, 29 Dec 2018 00:24:14 +0000
treeherderautoland@d24ddb803761 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, daleharvey
bugs1513681
milestone66.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 1513681 - part2 : handle 'GloballyAutoplayBlocked' event r=jaws,daleharvey Handle the process from receiving event to showing the block icon. Differential Revision: https://phabricator.services.mozilla.com/D14795
browser/base/content/tabbrowser.js
toolkit/actors/AudibleAutoplayChild.jsm
toolkit/content/widgets/browser.xml
toolkit/modules/ActorManagerParent.jsm
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -4767,16 +4767,29 @@ window._gBrowser = {
       let browser = event.originalTarget;
       let tab = this.getTabForBrowser(browser);
       if (!tab) {
         return;
       }
 
       Services.obs.notifyObservers(tab, "AudibleAutoplayMediaOccurred");
     });
+
+    this.addEventListener("GloballyAutoplayBlocked", (event) => {
+      let browser = event.originalTarget;
+      let tab = this.getTabForBrowser(browser);
+      if (!tab) {
+        return;
+      }
+
+      SitePermissions.set(event.detail.url, "autoplay-media",
+                          SitePermissions.BLOCK,
+                          SitePermissions.SCOPE_GLOBAL,
+                          browser);
+    });
   },
 
   setSuccessor(aTab, successorTab) {
     if (aTab.ownerGlobal != window) {
       throw new Error("Cannot set the successor of another window's tab");
     }
     if (successorTab == aTab) {
       successorTab = null;
--- a/toolkit/actors/AudibleAutoplayChild.jsm
+++ b/toolkit/actors/AudibleAutoplayChild.jsm
@@ -5,11 +5,18 @@
 "use strict";
 
 var EXPORTED_SYMBOLS = ["AudibleAutoplayChild"];
 
 ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
 
 class AudibleAutoplayChild extends ActorChild {
   handleEvent(event) {
-    this.mm.sendAsyncMessage("AudibleAutoplayMediaOccurred");
+    if (event.type == "AudibleAutoplayMediaOccurred") {
+      this.mm.sendAsyncMessage("AudibleAutoplayMediaOccurred");
+      return;
+    }
+    if (event.type == "GloballyAutoplayBlocked") {
+      this.mm.sendAsyncMessage("GloballyAutoplayBlocked");
+      return;
+    }
   }
 }
--- a/toolkit/content/widgets/browser.xml
+++ b/toolkit/content/widgets/browser.xml
@@ -767,16 +767,29 @@
           <![CDATA[
             let event = document.createEvent("Events");
             event.initEvent("AudibleAutoplayMediaOccurred", true, false);
             this.dispatchEvent(event);
           ]]>
         </body>
       </method>
 
+      <method name="notifyGloballyAutoplayBlocked">
+        <body>
+          <![CDATA[
+            let event = document.createEvent("CustomEvent");
+            event.initCustomEvent("GloballyAutoplayBlocked", true, false,
+              {
+                url: this.documentURI,
+              });
+            this.dispatchEvent(event);
+          ]]>
+        </body>
+      </method>
+
       <!--
         When the pref "media.block-autoplay-until-in-foreground" is on,
         Gecko delays starting playback of media resources in tabs until the
         tab has been in the foreground or resumed by tab's play tab icon.
         - When Gecko delays starting playback of a media resource in a window,
         it sends a message to call activeMediaBlockStarted(). This causes the
         tab audio indicator to show.
         - When a tab is foregrounded, Gecko starts playing all delayed media
@@ -1104,16 +1117,17 @@
             this.messageManager.addMessageListener("Autoscroll:Start", this);
             this.messageManager.addMessageListener("Autoscroll:Cancel", this);
             this.messageManager.addMessageListener("AudioPlayback:Start", this);
             this.messageManager.addMessageListener("AudioPlayback:Stop", this);
             this.messageManager.addMessageListener("AudioPlayback:ActiveMediaBlockStart", this);
             this.messageManager.addMessageListener("AudioPlayback:ActiveMediaBlockStop", this);
             this.messageManager.addMessageListener("UnselectedTabHover:Toggle", this);
             this.messageManager.addMessageListener("AudibleAutoplayMediaOccurred", this);
+            this.messageManager.addMessageListener("GloballyAutoplayBlocked", this);
 
             if (this.hasAttribute("selectmenulist")) {
               this.messageManager.addMessageListener("Forms:ShowDropDown", this);
               this.messageManager.addMessageListener("Forms:HideDropDown", this);
             }
 
           }
         ]]></body>
@@ -1248,16 +1262,19 @@
             case "UnselectedTabHover:Toggle":
               this._shouldSendUnselectedTabHover = data.enable ?
                 ++this._unselectedTabHoverMessageListenerCount > 0 :
                 --this._unselectedTabHoverMessageListenerCount == 0;
               break;
             case "AudibleAutoplayMediaOccurred":
               this.notifyAudibleAutoplayMediaOccurred();
               break;
+            case "GloballyAutoplayBlocked":
+              this.notifyGloballyAutoplayBlocked();
+              break;
             case "Forms:ShowDropDown": {
               if (!this._selectParentHelper) {
                 this._selectParentHelper =
                   ChromeUtils.import("resource://gre/modules/SelectParentHelper.jsm", {}).SelectParentHelper;
               }
 
               let menulist = document.getElementById(this.getAttribute("selectmenulist"));
               menulist.menupopup.style.direction = data.direction;
--- a/toolkit/modules/ActorManagerParent.jsm
+++ b/toolkit/modules/ActorManagerParent.jsm
@@ -101,16 +101,17 @@ ChromeUtils.import("resource://gre/modul
 const {DefaultMap} = ExtensionUtils;
 
 let ACTORS = {
   AudibleAutoplay: {
     child: {
       module: "resource://gre/actors/AudibleAutoplayChild.jsm",
       events: {
         "AudibleAutoplayMediaOccurred": {},
+        "GloballyAutoplayBlocked": {},
       },
     },
   },
 
   AudioPlayback: {
     child: {
       module: "resource://gre/actors/AudioPlaybackChild.jsm",
       messages: [