Closed Bug 1352522 Opened 7 years ago Closed 7 years ago

Lazily load ContentWebRTC.jsm

Categories

(Firefox :: Site Permissions, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 55
Tracking Status
firefox55 --- fixed

People

(Reporter: mccr8, Assigned: mccr8)

References

Details

(Whiteboard: [MemShrink:P2])

Attachments

(3 files)

ContentWebRTC.jsm is imported for two reasons:

1. Add a bunch of observers, once per process.
2. Add a bunch of message listeners.

We shouldn't have to pay the price of a .jsm unless we're actually using WebRTC.

We can avoid the import for 1 by moving the addObserver calls into ContentObservers.jsm, and thunkifying them. Maybe avoiding the compartment for ContentObservers.jsm would be nice, but it is an easy way to have code only run once per process.

The import for 2 can be done just by thunkifying the message listeners. It is ugly but it works.
Depends on: 1353174
Whiteboard: [MemShrink] → [MemShrink:P2]
The webrtc:StartBrowserSharing code at https://hg.mozilla.org/try/rev/222fb449535fb8149197c3df8cefa23ff78a6f07#l1.30 seems to be deadcode. It was part of Firefox Hello and landed in bug 1133493.
Comment on attachment 8855534 [details]
Bug 1352522, part 3 - Remove the unused listener for webrtc:StartBrowserSharing.

https://reviewboard.mozilla.org/r/127362/#review130342
Attachment #8855534 - Flags: review?(florian) → review+
Comment on attachment 8855360 [details]
Bug 1352522, part 1 - Add ContentWebRTC observers in ContentObservers.js.

https://reviewboard.mozilla.org/r/127208/#review130344

r+ because I think this works and doesn't introduce bugs, but I wonder if it wouldn't be cleaner to have a single shim function used by all 5 observers, and to add an observe method in the ContentWebRTC object, with a switch/case in it, like receiveMessage does.
If all the observers use the same shim function, you can even define a constant array of the notification topics we care about, and loop over it both when adding and when removing observers.

Also, style wise, mixing methods directly inside the ContentWebRTC objects with method added using
ContentWebRTC.methodName = () => {
isn't exactly beautiful either.
Attachment #8855360 - Flags: review?(florian) → review+
Comment on attachment 8855361 [details]
Bug 1352522, part 2 - Use a shim for ContentWebRTC message listeners.

https://reviewboard.mozilla.org/r/127210/#review130346

::: browser/base/content/content.js:712
(Diff revision 1)
> -addMessageListener("rtcpeer:Deny", ContentWebRTC);
> -addMessageListener("webrtc:Allow", ContentWebRTC);
> -addMessageListener("webrtc:Deny", ContentWebRTC);
> -addMessageListener("webrtc:StopSharing", ContentWebRTC);
> +// it is actually needed.
> +var ContentWebRTCShim = {
> +  receiveMessage(aMessage) {
> +    ContentWebRTC.receiveMessage(aMessage);
> +  }
> +};

The nsIMessagerListener interface is defined with the 'function' keyword (http://searchfox.org/mozilla-central/rev/fcd9f1480d65f1a5df2acda97eb07a7e133f6ed4/dom/base/nsIMessageManager.idl#173), so you can use a function instead of an object as the second addMessageListener parameter, ie. simplify to:

var ContentWebRTCShim = message => ContentWebRTC.receiveMessage(message);
Attachment #8855361 - Flags: review?(florian) → review+
I r+'ed, but don't hesitate to re-request review if you decide to make significant changes to follow my suggestions.
Thanks for the feedback. I reworked part 1 a bit, so that should probably get re-reviewed.

(In reply to Florian Quèze [:florian] [:flo] from comment #8)
> The nsIMessagerListener interface is defined with the 'function' keyword

Ah, neat, I didn't know about that.
Can you re-review part 1, please? I'm not sure how to request that in MozReview.
Flags: needinfo?(florian)
(In reply to Andrew McCreight [:mccr8] from comment #14)
> Can you re-review part 1, please? I'm not sure how to request that in
> MozReview.

Looks good to me, I prefer this new version, thanks!

Please re-run at least the webrtc bc tests before landing. Eg. locally:
  mach mochitest browser/base/content/test/webrtc/
Flags: needinfo?(florian)
Thanks! Yeah, I did do a full Linux 64 debug try run because I didn't try myself to be able to find all the important tests for this code: https://treeherder.mozilla.org/#/jobs?repo=try&revision=0b3038140466797cf9ffe087b293966a6ba625d9
Pushed by amccreight@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/c2fbf1f0dc9d
part 1 - Add ContentWebRTC observers in ContentObservers.js. r=florian
https://hg.mozilla.org/integration/autoland/rev/e62cc0fa0007
part 2 - Use a shim for ContentWebRTC message listeners. r=florian
https://hg.mozilla.org/integration/autoland/rev/2510319470b0
part 3 - Remove the unused listener for webrtc:StartBrowserSharing. r=florian
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: