Bug 1513681 - part2 : handle 'GloballyAutoplayBlocked' event r=jaws,daleharvey
authorAlastor Wu <alwu@mozilla.com>
Fri, 04 Jan 2019 18:33:53 +0000
changeset 452605 d99f4d17ea923a3465e71b556b126ad8db30e6e0
parent 452604 9cb5b5f77ed8210c871b5377a9a6739841fb1e0e
child 452606 239ede916b0dc40a234c097fef5fecb8beb25c30
push id75510
push useralwu@mozilla.com
push dateSat, 05 Jan 2019 02:07:23 +0000
treeherderautoland@fedf648d3785 [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: [