Bug 1472491: Part 5θ - Add WebRTCChild actor. r?florian f=mconley
MozReview-Commit-ID: 8ucJr2Hp0F9
rename from browser/modules/ContentWebRTC.jsm
rename to browser/actors/WebRTCChild.jsm
--- a/browser/modules/ContentWebRTC.jsm
+++ b/browser/actors/WebRTCChild.jsm
@@ -1,41 +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 = [ "ContentWebRTC" ];
+var EXPORTED_SYMBOLS = ["WebRTCChild"];
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "MediaManagerService",
"@mozilla.org/mediaManagerService;1",
"nsIMediaManagerService");
const kBrowserURL = AppConstants.BROWSER_CHROME_URL;
-var ContentWebRTC = {
+class WebRTCChild extends ActorChild {
// Called only for 'unload' to remove pending gUM prompts in reloaded frames.
- handleEvent(aEvent) {
+ static handleEvent(aEvent) {
let contentWindow = aEvent.target.defaultView;
let mm = getMessageManagerForWindow(contentWindow);
for (let key of contentWindow.pendingGetUserMediaRequests.keys()) {
mm.sendAsyncMessage("webrtc:CancelRequest", key);
}
for (let key of contentWindow.pendingPeerConnectionRequests.keys()) {
mm.sendAsyncMessage("rtcpeer:CancelRequest", key);
}
- },
+ }
// This observer is registered in ContentObservers.js to avoid
// loading this .jsm when WebRTC is not in use.
- observe(aSubject, aTopic, aData) {
+ static observe(aSubject, aTopic, aData) {
switch (aTopic) {
case "getUserMedia:request":
handleGUMRequest(aSubject, aTopic, aData);
break;
case "recording-device-stopped":
handleGUMStop(aSubject, aTopic, aData);
break;
case "PeerConnection:request":
@@ -43,17 +44,17 @@ var ContentWebRTC = {
break;
case "recording-device-events":
updateIndicators(aSubject, aTopic, aData);
break;
case "recording-window-ended":
removeBrowserSpecificIndicator(aSubject, aTopic, aData);
break;
}
- },
+ }
receiveMessage(aMessage) {
switch (aMessage.name) {
case "rtcpeer:Allow":
case "rtcpeer:Deny": {
let callID = aMessage.data.callID;
let contentWindow = Services.wm.getOuterWindowWithId(aMessage.data.windowID);
forgetPCRequest(contentWindow, callID);
@@ -79,17 +80,17 @@ var ContentWebRTC = {
case "webrtc:Deny":
denyGUMRequest(aMessage.data);
break;
case "webrtc:StopSharing":
Services.obs.notifyObservers(null, "getUserMedia:revoke", aMessage.data);
break;
}
}
-};
+}
function handlePCRequest(aSubject, aTopic, aData) {
let { windowID, innerWindowID, callID, isSecure } = aSubject;
let contentWindow = Services.wm.getOuterWindowWithId(windowID);
let mm = getMessageManagerForWindow(contentWindow);
if (!mm) {
// Workaround for Bug 1207784. To use WebRTC, add-ons right now use
@@ -259,27 +260,27 @@ function forgetPCRequest(aContentWindow,
}
function setupPendingListsInitially(aContentWindow) {
if (aContentWindow.pendingGetUserMediaRequests) {
return;
}
aContentWindow.pendingGetUserMediaRequests = new Map();
aContentWindow.pendingPeerConnectionRequests = new Set();
- aContentWindow.addEventListener("unload", ContentWebRTC);
+ aContentWindow.addEventListener("unload", WebRTCChild.handleEvent);
}
function forgetPendingListsEventually(aContentWindow) {
if (aContentWindow.pendingGetUserMediaRequests.size ||
aContentWindow.pendingPeerConnectionRequests.size) {
return;
}
aContentWindow.pendingGetUserMediaRequests = null;
aContentWindow.pendingPeerConnectionRequests = null;
- aContentWindow.removeEventListener("unload", ContentWebRTC);
+ aContentWindow.removeEventListener("unload", WebRTCChild.handleEvent);
}
function updateIndicators(aSubject, aTopic, aData) {
if (aSubject instanceof Ci.nsIPropertyBag &&
aSubject.getProperty("requestURL") == kBrowserURL) {
// Ignore notifications caused by the browser UI showing previews.
return;
}
--- a/browser/actors/moz.build
+++ b/browser/actors/moz.build
@@ -11,25 +11,29 @@ with Files("PageInfoChild.jsm"):
BUG_COMPONENT = ("Firefox", "Page Info Window")
with Files("PageStyleChild.jsm"):
BUG_COMPONENT = ("Firefox", "Menus")
with Files("PluginChild.jsm"):
BUG_COMPONENT = ("Core", "Plug-ins")
+with Files("WebRTCChild.jsm"):
+ BUG_COMPONENT = ("Firefox", "Device Permissions")
+
FINAL_TARGET_FILES.actors += [
'AboutReaderChild.jsm',
'BlockedSiteChild.jsm',
'BrowserTabChild.jsm',
'ClickHandlerChild.jsm',
'ContentSearchChild.jsm',
'ContextMenuChild.jsm',
'DOMFullscreenChild.jsm',
'LightWeightThemeInstallChild.jsm',
'NetErrorChild.jsm',
'OfflineAppsChild.jsm',
'PageInfoChild.jsm',
'PageMetadataChild.jsm',
'PageStyleChild.jsm',
'PluginChild.jsm',
'URIFixupChild.jsm',
+ 'WebRTCChild.jsm',
]
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -13,17 +13,16 @@ ChromeUtils.import("resource://gre/modul
ChromeUtils.import("resource://gre/modules/Services.jsm");
// TabChildGlobal
var global = this;
XPCOMUtils.defineLazyModuleGetters(this, {
ContentLinkHandler: "resource:///modules/ContentLinkHandler.jsm",
ContentMetaHandler: "resource:///modules/ContentMetaHandler.jsm",
- ContentWebRTC: "resource:///modules/ContentWebRTC.jsm",
LoginFormFactory: "resource://gre/modules/LoginManagerContent.jsm",
InsecurePasswordUtils: "resource://gre/modules/InsecurePasswordUtils.jsm",
FormSubmitObserver: "resource:///modules/FormSubmitObserver.jsm",
ContextMenuChild: "resource:///modules/ContextMenuChild.jsm",
});
XPCOMUtils.defineLazyGetter(this, "LoginManagerContent", () => {
let tmp = {};
@@ -65,18 +64,8 @@ new ContentLinkHandler(this);
ContentMetaHandler.init(this);
// This is a temporary hack to prevent regressions (bug 1471327).
void content;
addEventListener("DOMWindowFocus", function(event) {
sendAsyncMessage("DOMWindowFocus", {});
}, false);
-
-// We use this shim so that ContentWebRTC.jsm will not be loaded until
-// it is actually needed.
-var ContentWebRTCShim = message => ContentWebRTC.receiveMessage(message);
-
-addMessageListener("rtcpeer:Allow", ContentWebRTCShim);
-addMessageListener("rtcpeer:Deny", ContentWebRTCShim);
-addMessageListener("webrtc:Allow", ContentWebRTCShim);
-addMessageListener("webrtc:Deny", ContentWebRTCShim);
-addMessageListener("webrtc:StopSharing", ContentWebRTCShim);
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -242,16 +242,29 @@ let ACTORS = {
URIFixup: {
child: {
module: "resource:///actors/URIFixupChild.jsm",
group: "browsers",
observers: ["keyword-uri-fixup"],
},
},
+
+ WebRTC: {
+ child: {
+ module: "resource:///actors/WebRTCChild.jsm",
+ messages: [
+ "rtcpeer:Allow",
+ "rtcpeer:Deny",
+ "webrtc:Allow",
+ "webrtc:Deny",
+ "webrtc:StopSharing",
+ ],
+ },
+ },
};
(function earlyBlankFirstPaint() {
if (!Services.prefs.getBoolPref("browser.startup.blankWindow", false))
return;
let store = Services.xulStore;
let getValue = attr =>
--- a/browser/modules/ContentObservers.js
+++ b/browser/modules/ContentObservers.js
@@ -12,18 +12,18 @@
* which is bad for perf.
*/
"use strict";
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-ChromeUtils.defineModuleGetter(this, "ContentWebRTC",
- "resource:///modules/ContentWebRTC.jsm");
+ChromeUtils.defineModuleGetter(this, "WebRTCChild",
+ "resource:///modules/WebRTCChild.jsm");
var gEMEUIObserver = function(subject, topic, data) {
let win = subject.top;
let mm = getMessageManagerForWindow(win);
if (mm) {
mm.sendAsyncMessage("EMEVideo:ContentMediaKeysRequest", data);
}
};
@@ -39,25 +39,25 @@ var gDecoderDoctorObserver = function(su
function getMessageManagerForWindow(aContentWindow) {
return aContentWindow.docShell.messageManager;
}
Services.obs.addObserver(gEMEUIObserver, "mediakeys-request");
Services.obs.addObserver(gDecoderDoctorObserver, "decoder-doctor-notification");
-// ContentWebRTC observer registration.
+// WebRTCChild observer registration.
const kWebRTCObserverTopics = ["getUserMedia:request",
"recording-device-stopped",
"PeerConnection:request",
"recording-device-events",
"recording-window-ended"];
function webRTCObserve(aSubject, aTopic, aData) {
- ContentWebRTC.observe(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");
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -50,19 +50,16 @@ with Files("*Telemetry.jsm"):
BUG_COMPONENT = ("Toolkit", "Telemetry")
with Files("ContentCrashHandlers.jsm"):
BUG_COMPONENT = ("Toolkit", "Crash Reporting")
with Files("ContentSearch.jsm"):
BUG_COMPONENT = ("Firefox", "Search")
-with Files("ContentWebRTC.jsm"):
- BUG_COMPONENT = ("Firefox", "Device Permissions")
-
with Files("ExtensionsUI.jsm"):
BUG_COMPONENT = ("WebExtensions", "General")
with Files("LaterRun.jsm"):
BUG_COMPONENT = ("Firefox", "Tours")
with Files("LightweightThemeChildHelper.jsm"):
BUG_COMPONENT = ("WebExtensions", "Themes")
@@ -126,20 +123,18 @@ EXTRA_JS_MODULES += [
'BrowserUsageTelemetry.jsm',
'BrowserWindowTracker.jsm',
'ContentClick.jsm',
'ContentCrashHandlers.jsm',
'ContentLinkHandler.jsm',
'ContentMetaHandler.jsm',
'ContentObservers.js',
'ContentSearch.jsm',
- 'ContentWebRTC.jsm',
'ExtensionsUI.jsm',
'Feeds.jsm',
- 'FormSubmitObserver.jsm',
'FormValidationHandler.jsm',
'HomePage.jsm',
'LaterRun.jsm',
'LightweightThemeChildHelper.jsm',
'OpenInTabsUtils.jsm',
'PageActions.jsm',
'PermissionUI.jsm',
'PingCentre.jsm',