Understanding how DevTools multiprocess architecture works.
________________________________________________________________________________________
| Parent process |
|----------------------------------------------------------------------------------------|
| |
| DevTools Toolbox (there can be multiple instances) |
| |
| - DevTools client code and panels (devtools/client) |
| Even though client code is typically running in the privileged parent process, |
| ideally it shouldn't actually run any privileged code. These should be factored |
| out into actors, or shimmed so that the panels can run independently in |
| content processes. |
| |
| - Actor Fronts |
| The fronts (clients) communicate via various transport adaptors to server code |
| (see devtools/shared/transport/transport.js for specific mechanisms.) The |
| transport mechanism varies but includes message managers, freezing packets and |
| passing by reference, or other internal communication methods. |
| |
| ^ |
| | |
| LocalDebuggerTransport handles messages by passing |
| deeply frozen objects by reference if communicating |
| . . . . . . . . . to actors in the same process. If connecting to a . . . . . . . . |
| remote debuggee, another Transport will be swapped |
| in to do the message handling. |
| | |
| v |
| |
| DebuggerServer (devtools/server/main.js) Only one instance is loaded in the process |
| .connectToChild() -> loads devtools/server/child.js in child process |
| .connectToContent() -> loads content-process-debugger-server.js |
| .connectToWorker() -> loads devtools/server/worker.js in worker |
| |
| Here is an example layout of the actors and their connections: |
| |
| DebuggerServer |
| Connection: server1.conn0. |
| RootActor |
| Connection: server1.conn1. |
| RootActor |
| ----------------------------------------------------------------------------------------
^
|
ChildDebuggerTransport handles message manager communication
|
v
________________________________________________________________________________________
| Content process |
|----------------------------------------------------------------------------------------|
| Multiple tabs can live in a single content process, and multiple content |
| processes can be created. This is left up to the browser. |
| Privileged frame script: |
| |
| The parent process runs DebuggerServer.connectToContent() which uses a message |
| manager to inject devtools/server/child.js as a frame script. It requires |
| devtools/server/main.js and initializes DebuggerServer only on the first require. |
| The DebuggerServer is shared across multiple tabs in the same content process. |
| |
| DebuggerServer performs the following on each new tab connection to DevTools: |
| |
| - Runs DebuggerServer.connectToParent() to complete and create a new connection. |
| Both the parent and child process create a new DebuggerServerConnection |
| to represent this connection. |
| |
| - Creates a `new TabActor()` for the tab. Tab scoped actors (like the |
| InspectorActor or WebConsoleActor) are loaded into that TabActor's pool and are |
| scoped to the lifetime of the single tab. each instance of a TabActor has a 1:1 |
| relationship with a RootActor in the parent process. This relationship is |
| maintained through a DebuggerServerConnection in both the parent and child |
| DebuggerServer. |
| |
| Here is an example layout of the actors and their connections: |
| |
| DebuggerServer |
| Connection: server1.conn0.child1/ |
| TabActor: server1.conn0.child1/tab1 |
| Actor: server1.conn0.child1/consoleActor2 |
| Actor: server1.conn0.child1/inspectorActor3 |
| Actor: server1.conn0.child1/callWatcherActor4 |
| Actor: server1.conn0.child1/canvasActor5 |
| Actor: server1.conn0.child1/webglActor6 |
| ... |
| Connection: server1.conn1.child1/ |
| TabActor: server1.conn1.child1/tab1 |
| Actor: server1.conn1.child1/consoleActor2 |
| Actor: server1.conn1.child1/inspectorActor3 |
| Actor: server1.conn1.child1/callWatcherActor4 |
| Actor: server1.conn1.child1/canvasActor5 |
| Actor: server1.conn1.child1/webglActor6 |
| ... |
| |
| __________________________________________________________________________________ |
| | Tab | |
| |----------------------------------------------------------------------------------| |
| | Non-privileged content, e.g. http://wikipedia.org/ | |
| | | |
| | Actors synchronously access content here, but with Xray vision in order to | |
| | do so safely. The actors can then send messages back to the parent process | |
| | asynchronously through the actor-front relationship. | |
| | | |
| | See: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Xray_vision | |
| ------------------------------------------------------------------------------------ |
| |
| __________________________________________________________________________________ |
| | Tab | |
| |----------------------------------------------------------------------------------| |
| | Non-privileged content, e.g. http://wikipedia.org/ | |
| ------------------------------------------------------------------------------------ |
| |
-----------------------------------------------------------------------------------------
________________________________________________________________________________________
| Content process |
|----------------------------------------------------------------------------------------|
| Additional content processes can be created. They will have their own DebuggerServer |
-----------------------------------------------------------------------------------------