Bug 1654127, move webrtc and about home cache handling out of ContentObservers.js framescript, r=mconley

Differential Revision: https://phabricator.services.mozilla.com/D84277
This commit is contained in:
Neil Deakin
2020-07-22 10:14:26 +00:00
parent 4cb04c556d
commit ed663afb66
6 changed files with 74 additions and 57 deletions

View File

@@ -0,0 +1,42 @@
/* 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 = ["BrowserProcessChild"];
ChromeUtils.defineModuleGetter(
this,
"WebRTCChild",
"resource:///actors/WebRTCChild.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"AboutHomeStartupCacheChild",
"resource:///modules/AboutNewTabService.jsm"
);
class BrowserProcessChild extends JSProcessActorChild {
receiveMessage(message) {
switch (message.name) {
case "AboutHomeStartupCache:InputStreams":
let { pageInputStream, scriptInputStream } = message.data;
AboutHomeStartupCacheChild.init(pageInputStream, scriptInputStream);
break;
}
}
observe(subject, topic, data) {
switch (topic) {
case "getUserMedia:request":
case "recording-device-stopped":
case "PeerConnection:request":
case "recording-device-events":
case "recording-window-ended":
WebRTCChild.observe(subject, topic, data);
break;
}
}
}

View File

@@ -49,7 +49,7 @@ class WebRTCChild extends JSWindowActorChild {
}
}
// This observer is registered in ContentObservers.js to avoid
// This observer is called from BrowserProcessChild to avoid
// loading this .jsm when WebRTC is not in use.
static observe(aSubject, aTopic, aData) {
switch (aTopic) {

View File

@@ -44,6 +44,7 @@ FINAL_TARGET_FILES.actors += [
'AboutTabCrashedParent.jsm',
'BlockedSiteChild.jsm',
'BlockedSiteParent.jsm',
'BrowserProcessChild.jsm',
'BrowserTabChild.jsm',
'BrowserTabParent.jsm',
'ClickHandlerChild.jsm',

View File

@@ -76,7 +76,23 @@ const PREF_PDFJS_ISDEFAULT_CACHE_STATE = "pdfjs.enabledCache.state";
* Detailed documentation of these options is in dom/docs/Fission.rst,
* available at https://firefox-source-docs.mozilla.org/dom/Fission.html#jsprocessactor
*/
let JSPROCESSACTORS = {};
let JSPROCESSACTORS = {
// Miscellaneous stuff that needs to be initialized per process.
BrowserProcess: {
child: {
moduleURI: "resource:///actors/BrowserProcessChild.jsm",
observers: [
// WebRTC related notifications. They are here to avoid loading WebRTC
// components when not needed.
"getUserMedia:request",
"recording-device-stopped",
"PeerConnection:request",
"recording-device-events",
"recording-window-ended",
],
},
},
};
/**
* Fission-compatible JSWindowActor implementations.
@@ -5428,8 +5444,10 @@ var AboutHomeStartupCache = {
* @param aProcManager (ContentProcessMessageManager)
* The message manager for the newly created "privileged about
* content process".
* @param aProcessParent
* The nsIDOMProcessParent for the tab.
*/
sendCacheInputStreams(aProcManager) {
sendCacheInputStreams(aProcManager, aProcessParent) {
if (aProcManager.remoteType != E10SUtils.PRIVILEGEDABOUT_REMOTE_TYPE) {
throw new Error(
"Cannot send about:home cache to a non-privileged content process."
@@ -5439,7 +5457,8 @@ var AboutHomeStartupCache = {
// can occur if the nsICacheEntry hasn't been retrieved yet.
this.makePipes();
this.log.info("Sending input streams down to content process.");
aProcManager.sendAsyncMessage(this.SEND_STREAMS_MESSAGE, {
let actor = aProcessParent.getActor("BrowserProcess");
actor.sendAsyncMessage(this.SEND_STREAMS_MESSAGE, {
pageInputStream: this.pagePipe.inputStream,
scriptInputStream: this.scriptPipe.inputStream,
});
@@ -5592,14 +5611,16 @@ var AboutHomeStartupCache = {
* ipc:content-created.
* @param procManager (ProcessMessageManager)
* The ProcessMessageManager for the created content process.
* @param processParent
* The nsIDOMProcessParent for the tab.
*/
onContentProcessCreated(childID, procManager) {
onContentProcessCreated(childID, procManager, processParent) {
if (procManager.remoteType == E10SUtils.PRIVILEGEDABOUT_REMOTE_TYPE) {
this.log.trace(
`A privileged about content process is launching with ID ${childID}.` +
"Sending it the cache input streams."
);
this.sendCacheInputStreams(procManager);
this.sendCacheInputStreams(procManager, processParent);
procManager.addMessageListener(this.CACHE_RESPONSE_MESSAGE, this);
procManager.addMessageListener(this.CACHE_USAGE_RESULT_MESSAGE, this);
this._procManager = procManager;
@@ -5783,7 +5804,8 @@ var AboutHomeStartupCache = {
let procManager = aSubject
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIMessageSender);
this.onContentProcessCreated(childID, procManager);
let pp = aSubject.QueryInterface(Ci.nsIDOMProcessParent);
this.onContentProcessCreated(childID, procManager, pp);
break;
}

View File

@@ -109,7 +109,8 @@ async function simulateRestart(
if (AboutHomeStartupCache.initted) {
let processManager = browser.messageManager.processMessageManager;
AboutHomeStartupCache.sendCacheInputStreams(processManager);
let pp = browser.browsingContext.currentWindowGlobal.domProcess;
AboutHomeStartupCache.sendCacheInputStreams(processManager, pp);
info("Waiting for AboutHomeStartupCache cache entry");
await AboutHomeStartupCache.ensureCacheEntry();

View File

@@ -16,18 +16,6 @@
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(
this,
"WebRTCChild",
"resource:///actors/WebRTCChild.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"AboutHomeStartupCacheChild",
"resource:///modules/AboutNewTabService.jsm"
);
var gDecoderDoctorObserver = function(subject, topic, data) {
let win = subject.top;
let mm = getMessageManagerForWindow(win);
@@ -41,40 +29,3 @@ function getMessageManagerForWindow(aContentWindow) {
}
Services.obs.addObserver(gDecoderDoctorObserver, "decoder-doctor-notification");
// WebRTCChild observer registration. Actor observers require the subject
// to be a window, so they are registered here instead.
const kWebRTCObserverTopics = [
"getUserMedia:request",
"recording-device-stopped",
"PeerConnection:request",
"recording-device-events",
"recording-window-ended",
];
function webRTCObserve(aSubject, aTopic, aData) {
WebRTCChild.observe(aSubject, aTopic, aData);
}
for (let topic of kWebRTCObserverTopics) {
Services.obs.addObserver(webRTCObserve, topic);
}
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
Services.obs.addObserver(processShutdown, "content-child-shutdown");
}
function processShutdown() {
for (let topic of kWebRTCObserverTopics) {
Services.obs.removeObserver(webRTCObserve, topic);
}
Services.obs.removeObserver(processShutdown, "content-child-shutdown");
}
Services.cpmm.addMessageListener(
"AboutHomeStartupCache:InputStreams",
message => {
let { pageInputStream, scriptInputStream } = message.data;
AboutHomeStartupCacheChild.init(pageInputStream, scriptInputStream);
}
);