Bug 1560229 - [Fission] Make Autoplay work with JSWindowActor. r=NeilDeakin
authorAbdoulaye O. Ly <ablayelyfondou@gmail.com>
Tue, 25 Jun 2019 20:29:19 +0000
changeset 480096 e927a7bfb85e6ef07fc84c34b5e967fa1924e426
parent 480095 c396b50af035b2205a3bc32190e105c97705c497
child 480097 28854bf543da35394680922280e267eb65eb7a41
push id88501
push userneil@mozilla.com
push dateTue, 25 Jun 2019 20:29:45 +0000
treeherderautoland@e927a7bfb85e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeilDeakin
bugs1560229
milestone69.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 1560229 - [Fission] Make Autoplay work with JSWindowActor. r=NeilDeakin Differential Revision: https://phabricator.services.mozilla.com/D35395
toolkit/actors/AutoplayChild.jsm
toolkit/actors/AutoplayParent.jsm
toolkit/actors/moz.build
toolkit/content/widgets/browser-custom-element.js
toolkit/modules/ActorManagerParent.jsm
--- a/toolkit/actors/AutoplayChild.jsm
+++ b/toolkit/actors/AutoplayChild.jsm
@@ -1,15 +1,13 @@
 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
 var EXPORTED_SYMBOLS = ["AutoplayChild"];
 
-const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
-
-class AutoplayChild extends ActorChild {
+class AutoplayChild extends JSWindowActorChild {
   handleEvent(event) {
-    this.mm.sendAsyncMessage("GloballyAutoplayBlocked");
+    this.sendAsyncMessage("GloballyAutoplayBlocked", {});
   }
 }
new file mode 100644
--- /dev/null
+++ b/toolkit/actors/AutoplayParent.jsm
@@ -0,0 +1,20 @@
+/* vim: set ts=2 sw=2 sts=2 et tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this
+* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+var EXPORTED_SYMBOLS = ["AutoplayParent"];
+
+class AutoplayParent extends JSWindowActorParent {
+  receiveMessage(aMessage) {
+    let topBrowsingContext = this.manager.browsingContext.top;
+    let browser = topBrowsingContext.embedderElement;
+    let document = browser.ownerDocument;
+    let event = document.createEvent("CustomEvent");
+    event.initCustomEvent("GloballyAutoplayBlocked", true, false, {
+      url: this.documentURI,
+    });
+    browser.dispatchEvent(event);
+  }
+}
--- a/toolkit/actors/moz.build
+++ b/toolkit/actors/moz.build
@@ -16,16 +16,17 @@ with Files('KeyPressEventModelCheckerChi
 TESTING_JS_MODULES += [
     'TestChild.jsm',
     'TestParent.jsm',
 ]
 
 FINAL_TARGET_FILES.actors += [
     'AudioPlaybackChild.jsm',
     'AutoplayChild.jsm',
+    'AutoplayParent.jsm',
     'BrowserElementChild.jsm',
     'BrowserElementParent.jsm',
     'ControllersChild.jsm',
     'DateTimePickerChild.jsm',
     'ExtFindChild.jsm',
     'FindBarChild.jsm',
     'FinderChild.jsm',
     'InlineSpellCheckerChild.jsm',
--- a/toolkit/content/widgets/browser-custom-element.js
+++ b/toolkit/content/widgets/browser-custom-element.js
@@ -977,24 +977,16 @@ class MozBrowser extends MozElements.Moz
   }
 
   audioPlaybackStopped() {
     let event = document.createEvent("Events");
     event.initEvent("DOMAudioPlaybackStopped", true, false);
     this.dispatchEvent(event);
   }
 
-  notifyGloballyAutoplayBlocked() {
-    let event = document.createEvent("CustomEvent");
-    event.initCustomEvent("GloballyAutoplayBlocked", true, false, {
-      url: this.documentURI,
-    });
-    this.dispatchEvent(event);
-  }
-
   /**
    * 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
@@ -1176,17 +1168,16 @@ class MozBrowser extends MozElements.Moz
       this.messageManager.addMessageListener("PopupBlocking:UpdateBlockedPopups", this);
       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("GloballyAutoplayBlocked", this);
     }
   }
 
   /**
    * This is necessary because the destructor doesn't always get called when
    * we are removed from a tabbrowser. This will be explicitly called by tabbrowser.
    */
   destroy() {
@@ -1290,19 +1281,16 @@ class MozBrowser extends MozElements.Moz
       case "AudioPlayback:ActiveMediaBlockStop":
         this.activeMediaBlockStopped();
         break;
       case "UnselectedTabHover:Toggle":
         this._shouldSendUnselectedTabHover = data.enable ?
           ++this._unselectedTabHoverMessageListenerCount > 0 :
           --this._unselectedTabHoverMessageListenerCount == 0;
         break;
-      case "GloballyAutoplayBlocked":
-        this.notifyGloballyAutoplayBlocked();
-        break;
     }
     return undefined;
   }
 
   receiveMessage(aMessage) {
     if (!this.isRemoteBrowser) {
       return this._receiveMessage(aMessage);
     }
--- a/toolkit/modules/ActorManagerParent.jsm
+++ b/toolkit/modules/ActorManagerParent.jsm
@@ -96,16 +96,31 @@
 var EXPORTED_SYMBOLS = ["ActorManagerParent"];
 
 const {ExtensionUtils} = ChromeUtils.import("resource://gre/modules/ExtensionUtils.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const {DefaultMap} = ExtensionUtils;
 
 let ACTORS = {
+  Autoplay: {
+    parent: {
+      moduleURI: "resource://gre/actors/AutoplayParent.jsm",
+    },
+
+    child: {
+      moduleURI: "resource://gre/actors/AutoplayChild.jsm",
+      events: {
+        "GloballyAutoplayBlocked": {},
+      },
+    },
+
+    allFrames: true,
+  },
+
   BrowserElement: {
     parent: {
       moduleURI: "resource://gre/actors/BrowserElementParent.jsm",
     },
 
     child: {
       moduleURI: "resource://gre/actors/BrowserElementChild.jsm",
       events: {
@@ -154,25 +169,16 @@ let LEGACY_ACTORS = {
         "AudioPlayback",
       ],
       observers: [
         "audio-playback",
       ],
     },
   },
 
-  Autoplay: {
-    child: {
-      module: "resource://gre/actors/AutoplayChild.jsm",
-      events: {
-        "GloballyAutoplayBlocked": {},
-      },
-    },
-  },
-
   Controllers: {
     child: {
       module: "resource://gre/actors/ControllersChild.jsm",
       messages: [
         "ControllerCommands:Do",
         "ControllerCommands:DoWithParams",
       ],
     },