diff --git a/toolkit/actors/AutoplayChild.jsm b/toolkit/actors/AutoplayChild.jsm index a4a9099bb2b6..54071266ce32 100644 --- a/toolkit/actors/AutoplayChild.jsm +++ b/toolkit/actors/AutoplayChild.jsm @@ -6,10 +6,8 @@ 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", {}); } } diff --git a/toolkit/actors/AutoplayParent.jsm b/toolkit/actors/AutoplayParent.jsm new file mode 100644 index 000000000000..b6e4dfc0586e --- /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); + } +} diff --git a/toolkit/actors/moz.build b/toolkit/actors/moz.build index c6446b46ef8f..d68696e07576 100644 --- a/toolkit/actors/moz.build +++ b/toolkit/actors/moz.build @@ -21,6 +21,7 @@ TESTING_JS_MODULES += [ FINAL_TARGET_FILES.actors += [ 'AudioPlaybackChild.jsm', 'AutoplayChild.jsm', + 'AutoplayParent.jsm', 'BrowserElementChild.jsm', 'BrowserElementParent.jsm', 'ControllersChild.jsm', diff --git a/toolkit/content/widgets/browser-custom-element.js b/toolkit/content/widgets/browser-custom-element.js index f612953a9136..b414db8b6a38 100644 --- a/toolkit/content/widgets/browser-custom-element.js +++ b/toolkit/content/widgets/browser-custom-element.js @@ -982,14 +982,6 @@ class MozBrowser extends MozElements.MozElementMixin(XULFrameElement) { 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 @@ -1181,7 +1173,6 @@ class MozBrowser extends MozElements.MozElementMixin(XULFrameElement) { this.messageManager.addMessageListener("AudioPlayback:ActiveMediaBlockStart", this); this.messageManager.addMessageListener("AudioPlayback:ActiveMediaBlockStop", this); this.messageManager.addMessageListener("UnselectedTabHover:Toggle", this); - this.messageManager.addMessageListener("GloballyAutoplayBlocked", this); } } @@ -1295,9 +1286,6 @@ class MozBrowser extends MozElements.MozElementMixin(XULFrameElement) { ++this._unselectedTabHoverMessageListenerCount > 0 : --this._unselectedTabHoverMessageListenerCount == 0; break; - case "GloballyAutoplayBlocked": - this.notifyGloballyAutoplayBlocked(); - break; } return undefined; } diff --git a/toolkit/modules/ActorManagerParent.jsm b/toolkit/modules/ActorManagerParent.jsm index 66f50bcad89f..769c3ea0ab37 100644 --- a/toolkit/modules/ActorManagerParent.jsm +++ b/toolkit/modules/ActorManagerParent.jsm @@ -101,6 +101,21 @@ 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", @@ -159,15 +174,6 @@ let LEGACY_ACTORS = { }, }, - Autoplay: { - child: { - module: "resource://gre/actors/AutoplayChild.jsm", - events: { - "GloballyAutoplayBlocked": {}, - }, - }, - }, - Controllers: { child: { module: "resource://gre/actors/ControllersChild.jsm",