Bug 1352522, part 2 - Use a shim for ContentWebRTC message listeners. r=florian draft
authorAndrew McCreight <continuation@gmail.com>
Fri, 31 Mar 2017 11:19:27 -0700
changeset 558679 364b1e25000ebc7590f776966d56ea02ea9301a2
parent 558678 c048c9d8ce0cc123b5ead2a6deae27ba154e4992
child 558680 440d8b958ef866376a52fbc6ed2cd859c5cb45a3
push id52931
push userbmo:continuation@gmail.com
push dateFri, 07 Apr 2017 22:06:59 +0000
reviewersflorian
bugs1352522
milestone55.0a1
Bug 1352522, part 2 - Use a shim for ContentWebRTC message listeners. r=florian This avoids importing ContentWebRTC.jsm unless webrtc is actually being used, which reduces memory usage. MozReview-Commit-ID: GlMo1WIZEFD
browser/base/content/content.js
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -698,21 +698,25 @@ ContentLinkHandler.init(this);
 
 // TODO: Load this lazily so the JSM is run only if a relevant event/message fires.
 var pluginContent = new PluginContent(global);
 
 addEventListener("DOMWindowFocus", function(event) {
   sendAsyncMessage("DOMWindowFocus", {});
 }, false);
 
-addMessageListener("rtcpeer:Allow", ContentWebRTC);
-addMessageListener("rtcpeer:Deny", ContentWebRTC);
-addMessageListener("webrtc:Allow", ContentWebRTC);
-addMessageListener("webrtc:Deny", ContentWebRTC);
-addMessageListener("webrtc:StopSharing", ContentWebRTC);
+// 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);
 addMessageListener("webrtc:StartBrowserSharing", () => {
   let windowID = content.QueryInterface(Ci.nsIInterfaceRequestor)
                         .getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
   sendAsyncMessage("webrtc:response:StartBrowserSharing", {
     windowID
   });
 });