Closed Bug 1722659 Opened 2 years ago Closed 1 year ago

Stop using singleton for MessageHandlerRegistry


(Remote Protocol :: WebDriver BiDi, task, P2)



(firefox94 fixed)

94 Branch
Tracking Status
firefox94 --- fixed


(Reporter: jdescottes, Assigned: jdescottes)


(Blocks 1 open bug)


(Whiteboard: [bidi-m2-mvp])


(1 file)

In the initial implementation for MessageHandler, we have a single MessageHandlerRegistry per process, and consumers can use it in order to retrieve a MessageHandler instance.

In a given process, you can have MessageHandlers for various context types (Root, WindowGlobal, Worker...), for various contexts (browsing context 1, browsing context 2, ...) and finally for various sessions.

The platform APIs we are using to cross process/thread boundaries should remain tied by nature to a given context & context id. For instance, a MessageHandlerFrame JSWindowActor pair is tied to a specific BrowsingContext and is only dealing with WindowGlobalMessageHandlers. Also all MessageHandlers related to this JSWindowActor pair cannot outlive the JSWindowActor. For this reason, it doesn't really help to have a single registry which knows about all MessageHandler for all the contexts.

Instead, the proposal is to instantiate MessageHandlerRegistry for each context and make the Registry only care about sessions. For instance for WindowGlobalMessageHandlers, a MessageHandlerFrameChild will own a MessageHandlerRegistry and will use it to resolve the MessageHandler corresponding to a specific session. In the parent process, Root MessageHandlers should still be owned by a "singleton". This could either be a new dedicated singleton, or we could reuse RemoteAgent.

This will avoid having to craft complex MessageHandler keys combining the type + contextId + sessionId information, and should also simplify the ownership model for MessageHandlers. For instance when the MessageHandlerFrameChild is destroyed, it can simply destroy its Registry, which will in turn destroy all the MessageHandlers.

Thanks for filing this bug Julian. Maybe you could have an updated drawing of how this would look like when we discuss this topic in the next triage meeting?

Priority: -- → P3
Whiteboard: [webdriver:triage] → [bidi-m1-mvp]
Assignee: nobody → jdescottes
Whiteboard: [bidi-m1-mvp] → [bidi-m2-mvp]
Priority: P3 → --
Points: --- → 2
Priority: -- → P2
Pushed by
[remote] Stop using singleton for MessageHandlerRegistry r=webdriver-reviewers,whimboo
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 94 Branch
You need to log in before you can comment on or make changes to this bug.