Bug 1560229 - [Fission] Make Autoplay work with JSWindowActor. r=NeilDeakin

Differential Revision: https://phabricator.services.mozilla.com/D35395

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Abdoulaye O. Ly 2019-06-25 20:29:19 +00:00
parent 632715284a
commit 90236200b9
5 changed files with 38 additions and 25 deletions

View File

@ -6,10 +6,8 @@
var EXPORTED_SYMBOLS = ["AutoplayChild"]; var EXPORTED_SYMBOLS = ["AutoplayChild"];
const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm"); class AutoplayChild extends JSWindowActorChild {
class AutoplayChild extends ActorChild {
handleEvent(event) { handleEvent(event) {
this.mm.sendAsyncMessage("GloballyAutoplayBlocked"); this.sendAsyncMessage("GloballyAutoplayBlocked", {});
} }
} }

View File

@ -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);
}
}

View File

@ -21,6 +21,7 @@ TESTING_JS_MODULES += [
FINAL_TARGET_FILES.actors += [ FINAL_TARGET_FILES.actors += [
'AudioPlaybackChild.jsm', 'AudioPlaybackChild.jsm',
'AutoplayChild.jsm', 'AutoplayChild.jsm',
'AutoplayParent.jsm',
'BrowserElementChild.jsm', 'BrowserElementChild.jsm',
'BrowserElementParent.jsm', 'BrowserElementParent.jsm',
'ControllersChild.jsm', 'ControllersChild.jsm',

View File

@ -982,14 +982,6 @@ class MozBrowser extends MozElements.MozElementMixin(XULFrameElement) {
this.dispatchEvent(event); 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, * When the pref "media.block-autoplay-until-in-foreground" is on,
* Gecko delays starting playback of media resources in tabs until the * 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:ActiveMediaBlockStart", this);
this.messageManager.addMessageListener("AudioPlayback:ActiveMediaBlockStop", this); this.messageManager.addMessageListener("AudioPlayback:ActiveMediaBlockStop", this);
this.messageManager.addMessageListener("UnselectedTabHover:Toggle", 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 :
--this._unselectedTabHoverMessageListenerCount == 0; --this._unselectedTabHoverMessageListenerCount == 0;
break; break;
case "GloballyAutoplayBlocked":
this.notifyGloballyAutoplayBlocked();
break;
} }
return undefined; return undefined;
} }

View File

@ -101,6 +101,21 @@ const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const {DefaultMap} = ExtensionUtils; const {DefaultMap} = ExtensionUtils;
let ACTORS = { let ACTORS = {
Autoplay: {
parent: {
moduleURI: "resource://gre/actors/AutoplayParent.jsm",
},
child: {
moduleURI: "resource://gre/actors/AutoplayChild.jsm",
events: {
"GloballyAutoplayBlocked": {},
},
},
allFrames: true,
},
BrowserElement: { BrowserElement: {
parent: { parent: {
moduleURI: "resource://gre/actors/BrowserElementParent.jsm", moduleURI: "resource://gre/actors/BrowserElementParent.jsm",
@ -159,15 +174,6 @@ let LEGACY_ACTORS = {
}, },
}, },
Autoplay: {
child: {
module: "resource://gre/actors/AutoplayChild.jsm",
events: {
"GloballyAutoplayBlocked": {},
},
},
},
Controllers: { Controllers: {
child: { child: {
module: "resource://gre/actors/ControllersChild.jsm", module: "resource://gre/actors/ControllersChild.jsm",