diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/mozilla/firefox/multiprocess_firefox/message_manager | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/ja/mozilla/firefox/multiprocess_firefox/message_manager')
-rw-r--r-- | files/ja/mozilla/firefox/multiprocess_firefox/message_manager/index.html | 71 | ||||
-rw-r--r-- | files/ja/mozilla/firefox/multiprocess_firefox/message_manager/message_manager_overview/index.html | 444 |
2 files changed, 515 insertions, 0 deletions
diff --git a/files/ja/mozilla/firefox/multiprocess_firefox/message_manager/index.html b/files/ja/mozilla/firefox/multiprocess_firefox/message_manager/index.html new file mode 100644 index 0000000000..869474d44f --- /dev/null +++ b/files/ja/mozilla/firefox/multiprocess_firefox/message_manager/index.html @@ -0,0 +1,71 @@ +--- +title: Message manager +slug: Mozilla/Firefox/Multiprocess_Firefox/Message_Manager +tags: + - NeedsTranslation + - TopicStub +translation_of: Mozilla/Firefox/Multiprocess_Firefox/Message_Manager +--- +<p>Message managers provide a way for chrome-privileged JavaScript code to communicate across process boundaries. They are particularly useful for allowing chrome code, including the browser's own code and extension code, to access web content when the browser is running web content in a separate process.</p> + +<p>These guides explain how to use message managers in multiprocess Firefox.</p> + +<p>Note that none of this requires multiprocess Firefox: everything described here will work with single-process Firefox, so the same code will work in both variants.</p> + +<hr> +<h2 id="Guides">Guides</h2> + +<div class="column-container"> +<div class="column-half"> +<dl> + <dt><a href="/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Message_manager_overview">Message manager overview</a></dt> + <dd> </dd> + <dt><a href="/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Frame_script_loading_and_lifetime">Frame script loading and lifetime</a></dt> + <dd> </dd> + <dt><a href="/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Communicating_with_frame_scripts">Communicating with frame scripts</a></dt> + <dd> </dd> + <dt><a href="/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Performance">Performance Best Practices</a></dt> + <dd> </dd> +</dl> +</div> + +<div class="column-half"> +<dl> + <dt><a href="/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Frame_script_environment">Frame script environment</a></dt> + <dd> </dd> + <dt><a href="/en-US/Firefox/Multiprocess_Firefox/Message_Manager/_Limitations_of_frame_scripts">Limitations of frame scripts</a></dt> + <dd> </dd> + <dt><a href="/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Process_scripts">Process scripts</a></dt> + <dd> </dd> +</dl> +</div> +</div> + +<hr> +<h2 id="API_reference">API reference</h2> + +<div class="column-container"> +<div class="column-half"> +<dl> + <dt><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFrameScriptLoader">nsIFrameScriptLoader</a></dt> + <dd> </dd> + <dt><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager">nsIMessageListenerManager</a></dt> + <dd> </dd> + <dt><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster">nsIMessageBroadcaster</a></dt> + <dd> </dd> + <dt><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageSender">nsIMessageSender</a></dt> + <dd> </dd> +</dl> +</div> + +<div class="column-half"> +<dl> + <dt><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsISyncMessageSender">nsISyncMessageSender</a></dt> + <dd> </dd> + <dt><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentFrameMessageManager">nsIContentFrameMessageManager</a></dt> + <dd> </dd> + <dt><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcessScriptLoader">nsIProcessScriptLoader</a></dt> + <dd> </dd> +</dl> +</div> +</div> diff --git a/files/ja/mozilla/firefox/multiprocess_firefox/message_manager/message_manager_overview/index.html b/files/ja/mozilla/firefox/multiprocess_firefox/message_manager/message_manager_overview/index.html new file mode 100644 index 0000000000..5e00266603 --- /dev/null +++ b/files/ja/mozilla/firefox/multiprocess_firefox/message_manager/message_manager_overview/index.html @@ -0,0 +1,444 @@ +--- +title: Message manager overview +slug: Mozilla/Firefox/Multiprocess_Firefox/Message_Manager/Message_manager_overview +translation_of: Mozilla/Firefox/Multiprocess_Firefox/Message_Manager/Message_manager_overview +--- +<div class="summary"> +<p>マルチプロセスの Firefo では 2 つのプロセスが存在します。</p> + +<ul> + <li>Chrome プロセスまたは親プロセスと呼ばれるもので、ブラウザ UI(chrome) コードと拡張によって挿入されたコードが動いています。</li> + <li>コンテンツプロセスまたは子プロセスと呼ばれます。Web コンテンツのすべてが動いています。近い将来のマルチプロセス Firefo のバージョンでは、それぞれのタブが個別のプロセスで動作するようになりますが、現在はすべてのコンテンツタブが 1 つのコンテンツプロセスを共有している状況です。</li> +</ul> + +<p>Message manager はあるプロセス上の chrome 権限 JavaScript がほかのプロセス上の Chrome 権限 JavaScript と通信することを可能にします。</p> + +<p>この記事では種類の違う message manager の説明、アクセス方法、使いどころの説明をします。</p> +</div> + +<p>トップレベルにおいて、2つの違う種類の message manager が存在します。</p> + +<ul> + <li><em>Frame message managers:</em>コンテンツタブにロードされた iframe にロードされた chrome プロセスコードを有効にします。(現在は 1 つのブラウザタブ) それは<em> frame scripts</em> と呼ばれ、 その名の通り、ブラウザ内の特定のフレームにスコープされます。もし chrome コードを子プロセスで動作して、Web コンテンツにアクセスしたい場合は、一般的にこの種の message manager を使います。</li> + <li><em>Process message managers: </em>プロセスの境界を越え、親(chrome) プロセスで動作しているコードが子(コンテンツ)プロセスで動作するコードと通信することを可能にします。これが子プロセスにおいてはグローバルである事を除いては、frame scripts に似ています。Process scripts は <a href="/en/docs/Observer_Notifications">observer</a> や <a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentPolicy">content policy</a> のグローバルサービスにアクセスするように、エクステンションがコンテンツプロセスで限られたコードを実行する場合と使い方が似ています。</li> +</ul> + +<h2 id="Frame_message_managers">Frame message managers</h2> + +<p>マルチプロセスの Firefo では、chrome コードが Web コンテンツにアクセスする必要が出た時に、以下のように使います。</p> + +<ul> + <li>factor the code that needs direct access to content into separate scripts, which are called "frame scripts"</li> + <li>use a frame message manager to load these frame scripts into the content process</li> + <li>use the frame message manager API to communicate with the frame script</li> +</ul> + +<div class="note"> +<p>Some older articles on multiprocess Firefox and the message manager might refer to "content scripts" instead of "frame scripts", but this usage is deprecated because the Add-on SDK uses "content script" to refer to a <a href="https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts">similar but different kind of script</a>.</p> +</div> + +<p>So fundamentally, frame message managers enable chrome code to:</p> + +<ul> + <li>load a script into a frame (essentially, a single browser tab) in the content process. These scripts are called "frame scripts".</li> + <li>communicate with frame scripts using message-passing APIs</li> +</ul> + +<p>There are various types of frame message managers, as depicted in this diagram:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/10795/frame-message-managers.png" style="display: block; height: 596px; margin-left: auto; margin-right: auto; width: 737px;"></p> + +<p>This diagram shows the setup when there are 2 browser windows open, one with 2 tabs open and one with 1 tab open.</p> + +<h3 id="Chrome_process">Chrome process</h3> + +<p>In the chrome process, there's a hierarchy of frame message managers: the global frame message manager, window message managers, and browser message managers.</p> + +<h4 id="Global_frame_message_manager">Global frame message manager</h4> + +<table class="fullwidth-table standard-table"> + <tbody> + <tr> + <td style="width: 20%;">Description</td> + <td> + <p>There's a single <em>global frame message manager</em> in the chrome process.</p> + + <p>This operates on all frames, in all content tabs. If you load a frame script using the global frame message manager, the script gets loaded separately into every open tab: three times, in the diagram above. Similarly, if you send a message using the global frame message manager, it's received by all content tabs, and is then delivered to any frame scripts that are listening for it.</p> + + <p>Its most important functions and attributes are:</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster#childCount">childCount</a></code> : contains the number of children (typically, browser windows)</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster#getChildAt()">getChildAt()</a></code> : get the child at the given index</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFrameScriptLoader#loadFrameScript()">loadFrameScript()</a></code> : load a frame script into every tab in the browser</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster#broadcastAsyncMessage()">broadcastAsyncMessage()</a></code> : send a message to frame scripts</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#addMessageListener()">addMessageListener()</a></code> : start listening to a specific message from all frame scripts</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#removeMessageListener()">removeMessageListener()</a></code> : stop listening to a specific message</p> + </td> + </tr> + <tr> + <td>Interfaces</td> + <td> + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFrameScriptLoader" title="">nsIFrameScriptLoader</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager" title="">nsIMessageListenerManager</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster" title="">nsIMessageBroadcaster</a></code></p> + </td> + </tr> + <tr> + <td>How to access</td> + <td> + <p>Access it using <code><a href="/en-US/docs/Components.classes">Components.classes</a></code>:</p> + + <pre class="brush: js language-js"> +// chrome script +let globalMM = Cc["@mozilla.org/globalmessagemanager;1"] + .getService(Ci.nsIMessageListenerManager);</pre> + + <p>You can also access it as the <code>mm</code> property of <a href="/en-US/docs/Mozilla/JavaScript_code_modules/Services.jsm">Services.jsm</a>, if you are in the parent process.</p> + </td> + </tr> + </tbody> +</table> + +<h4 id="Window_message_manager">Window message manager</h4> + +<table class="fullwidth-table standard-table"> + <tbody> + <tr> + <td style="width: 20%;">Description</td> + <td> + <p>There's a <em>window message manager</em> for every browser window: two, in the diagram above.</p> + + <p>It operates on all content tabs in a given window. If you load a frame script using the window message manager it gets loaded separately into each tab open in that particular window. If you send a message using the window message manager, it gets sent to all content tabs in that window.</p> + + <p>Its most important functions and attributes are:</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster#childCount">childCount</a></code> : contains the number of children (typically, browser tabs)</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster#getChildAt()">getChildAt()</a></code> : get the child at the given index</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFrameScriptLoader#loadFrameScript()">loadFrameScript()</a></code> : load a frame script into every tab in this window</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster#broadcastAsyncMessage()">broadcastAsyncMessage()</a></code> : send a message to all frame scripts in this window</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#addMessageListener()">addMessageListener()</a></code> : start listening to a specific message from frame scripts</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#removeMessageListener()">removeMessageListener()</a></code> : stop listening to a specific message</p> + </td> + </tr> + <tr> + <td>Interfaces</td> + <td> + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFrameScriptLoader" title="">nsIFrameScriptLoader</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager" title="">nsIMessageListenerManager</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster" title="">nsIMessageBroadcaster</a></code></p> + </td> + </tr> + <tr> + <td>How to access</td> + <td> + <p>You can access it as a property of the browser window:</p> + + <pre class="brush: js"> +// chrome script +let windowMM = window.messageManager;</pre> + </td> + </tr> + </tbody> +</table> + +<h4 id="Browser_message_manager">Browser message manager</h4> + +<div class="note"> +<p>Note that in this context, "browser" refers to the <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/browser">XUL <browser> object</a>, which is a frame that hosts a single Web document. It does not refer to the more general sense of a Web browser.</p> +</div> + +<table class="fullwidth-table standard-table"> + <tbody> + <tr> + <td style="width: 20%;">Description</td> + <td> + <p>Finally, there's a <em>browser message manager</em> for every open content tab: three, in the diagram above.</p> + + <p>This corresponds one-to-one with a content tab. Scripts you load using a browser message manager are loaded only into that content tab, and messages you send are delivered only to that content tab.</p> + + <p>You can mix and match: so for example, you could load a script into every tab using the global message manager, but then send a message to the script instance loaded into a specific tab by using the browser message manager.</p> + + <p>Its most important functions are:</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFrameScriptLoader#loadFrameScript()">loadFrameScript()</a></code> : load a frame script into this browser frame (tab)</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageSender#sendAsyncMessage()">sendAsyncMessage()</a></code> : send a message to all frame scripts in this browser frame</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#addMessageListener()">addMessageListener()</a></code> : start listening to a specific message from frame scripts</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#removeMessageListener()">removeMessageListener()</a></code> : stop listening to a specific message</p> + </td> + </tr> + <tr> + <td>Interfaces</td> + <td> + <p><code>nsIProcessChecker</code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFrameScriptLoader">nsIFrameScriptLoader</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager">nsIMessageListenerManager</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageSender">nsIMessageSender</a></code></p> + </td> + </tr> + <tr> + <td>How to access</td> + <td> + <p>The browser message manager can be accessed as a property of the XUL <code><browser></code> element:</p> + + <pre class="brush: js"> +// chrome script +let browserMM = gBrowser.selectedBrowser.messageManager;</pre> + </td> + </tr> + </tbody> +</table> + +<h3 id="Content_process">Content process</h3> + +<h4 id="Content_frame_message_manager">Content frame message manager</h4> + +<table class="fullwidth-table standard-table"> + <tbody> + <tr> + <td style="width: 20%;">Description</td> + <td> + <p>There's a <em>content frame message manager</em> for every open tab. It's the content-side end of frame message manager conversations.</p> + + <p>Frame scripts are loaded into the content frame message manager scope, and messages from chrome message managers end up here.</p> + + <p>The content frame message manager provides the <a href="/en-US/Firefox/Multiprocess_Firefox/Frame_script_environment">global object for frame scripts</a> (but note that there is trickery to ensure that top-level variables defined by frame scripts are not shared).</p> + + <p>Frame scripts can use this object to send messages to the chrome process, and to receive messages from the chrome process.</p> + + <p>Its most important attributes and functions are:</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentFrameMessageManager#content">content</a></code> : access the DOM window hosted by the tab</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentFrameMessageManager#docShell">docShell</a></code> : access the top-level docshell</p> + + <p><code><a href="/en-US/docs/Components_object">Components</a></code> : access privileged objects and APIs</p> + + <p><code><a href="/en-US/docs/Web/API/EventTarget/addEventListener">addEventListener()</a></code> : listen to DOM events</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#addMessageListener()">addMessageListener()</a></code> : receive messages from the chrome process</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageSender#sendAsyncMessage()">sendAsyncMessage()</a></code> : send asynchronous messages to the chrome process</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsISyncMessageSender#sendSyncMessage()">sendSyncMessage()</a></code> : send synchronous messages to the chrome process</p> + </td> + </tr> + <tr> + <td>Interfaces</td> + <td> + <p><code><a href="https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIDOMEventTarget">nsIDOMEventTarget</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager">nsIMessageListenerManager</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageSender">nsIMessageSender</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsISyncMessageSender">nsISyncMessageSender</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentFrameMessageManager">nsIContentFrameMessageManager</a></code></p> + </td> + </tr> + <tr> + <td>How to access</td> + <td>The content frame message manager is the global object in frame scripts.</td> + </tr> + </tbody> +</table> + +<h2 id="Process_message_managers">Process message managers</h2> + +<p>Process message managers はプロセス境界を越え、異なるプロセスと通信することを可能にします。マルチプロセスの Firefo のコンセプトは次の通り。</p> + +<ul> + <li>"親プロセス"</li> + <li>"子プロセス" は親プロセスによって生成されたプロセス</li> +</ul> + +<p>実用的な目的で、マルチプロセスの Firefo の親プロセスは chrome プロセスで、子プロセスは コンテンツプロセスです。</p> + +<p>各子プロセスは、single <em>child process message manager</em> (CPMM) を持ちます。それに加え、親プロエスでは <em>child-in-process message manager</em> (CIPMM) をもっています。</p> + +<p>各子プロセスの message manager は、親プロセスに対応する <em>parent process message manager</em> (PPMM) を持っています。</p> + +<p>親プロセスには 1つの <em>global parent process message manager</em> (GPPMM) をもっており、それがすべての親プロセスの message manager に対するアクセスを提供します。2 つの子プロセスを持つと以下の図のように構築されます。</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/10799/process-message-managers.png" style="display: block; height: 477px; margin-left: auto; margin-right: auto; width: 477px;"></p> + +<p>GPPMM を使って、CIPMM とすべての CPMM にブロードキャストすることができます。PPMM は対応する CPMM にだけメッセージを送信できます。CPMM では親プロセスにメッセージを送信できます。まず初めに対応する PPMM が受信でき、次に GPPMM が受信します。<br> + <br> + From Firefox 38 onwards, you can also use a parent process message manager to load a script into a child process. This is the recommended way to load a script that executes just once per child process, which is something you might want to do if you are interacting with some global service (for example, adding listeners to observer notifications or registering a content policy).</p> + +<h3 id="Parent_process">Parent process</h3> + +<h4 id="Global_parent_process_message_manager">Global parent process message manager</h4> + +<table class="fullwidth-table standard-table"> + <tbody> + <tr> + <td style="width: 20%;">Description</td> + <td> + <p>The global parent process message manager (GPPMM) is global to the parent process.</p> + + <ul> + <li>Messages sent using the GPPMM get sent to all CPMMs in all child processes.</li> + <li>Process scripts loaded using the GPPMM get loaded in all child processes.</li> + </ul> + + <p>Its most important functions and attributes are:</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster#childCount">childCount</a></code> : contains the number of children (child processes, plus the in-content child)</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster#getChildAt()">getChildAt()</a></code> : get the child at the given index</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcessScriptLoader#loadProcessScript()">loadProcessScript()</a></code> : load a process script into every content process</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster#broadcastAsyncMessage()">broadcastAsyncMessage()</a></code> : send a message to all process scripts</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#addMessageListener()">addMessageListener()</a></code> : start listening to a specific message from process scripts</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#removeMessageListener()">removeMessageListener()</a></code> : stop listening to a specific message</p> + </td> + </tr> + <tr> + <td>Interfaces</td> + <td> + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcessScriptLoader">nsIProcessScriptLoader</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager" title="">nsIMessageListenerManager</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster" title="">nsIMessageBroadcaster</a></code></p> + </td> + </tr> + <tr> + <td>How to access</td> + <td> + <p>You can access the GPPMM with code like this:</p> + + <pre class="brush: js"> +// parent process +let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"] + .getService(Ci.nsIMessageBroadcaster);</pre> + + <p>You can also access it as the <code>ppmm</code> property of <a href="/en-US/docs/Mozilla/JavaScript_code_modules/Services.jsm">Services.jsm</a>, if you are in the parent process.</p> + </td> + </tr> + </tbody> +</table> + +<h4 id="Parent_process_message_manager">Parent process message manager</h4> + +<table class="fullwidth-table standard-table"> + <tbody> + <tr> + <td style="width: 20%;">Description</td> + <td> + <p>There's one parent process message manager (PPMM) in the parent process for every child process, and its API is oriented to that one child process.</p> + + <ul> + <li>Messages sent using the PPMM are received only by the corresponding CPMM</li> + <li>Scripts loaded using the PPMM are loaded only into the corresponding child process.</li> + </ul> + + <p>Its most important functions are:</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcessScriptLoader#loadProcessScript()">loadProcessScript()</a></code> : load a process script into the content process</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageBroadcaster#broadcastAsyncMessage()">broadcastAsyncMessage()</a></code> : send a message to process scripts</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#addMessageListener()">addMessageListener()</a></code> : start listening to a specific message from process scripts</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#removeMessageListener()">removeMessageListener()</a></code> : stop listening to a specific message</p> + </td> + </tr> + <tr> + <td>Interfaces</td> + <td> + <p><code>nsIProcessChecker</code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcessScriptLoader">nsIProcessScriptLoader</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager">nsIMessageListenerManager</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageSender">nsIMessageSender</a></code></p> + </td> + </tr> + <tr> + <td>How to access</td> + <td> + <p>You can access a PPMM using the <code>getChildAt()</code> function in the GPPMM:</p> + + <pre class="brush: js"> +// parent process +let ppmm = Services.ppmm.getChildAt(1);</pre> + </td> + </tr> + </tbody> +</table> + +<h3 id="Child_process">Child process</h3> + +<h4 id="Child_process_message_manager">Child process message manager</h4> + +<table class="fullwidth-table standard-table"> + <tbody> + <tr> + <td style="width: 20%;">Description</td> + <td> + <p>There's one child process message manager (CPMM) in each child process. Messages sent using the CPMM are sent to the corresponding PPMM and are also relayed to the GPPMM.</p> + + <p>Its most important attributes and functions are:</p> + + <p><code><a href="/en-US/docs/Components_object">Components</a></code> : access privileged objects and APIs</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#addMessageListener()">addMessageListener()</a></code> : receive messages from the parent process</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageSender#sendAsyncMessage()">sendAsyncMessage()</a></code> : send asynchronous messages to the parent process</p> + + <p><code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsISyncMessageSender#sendSyncMessage()">sendSyncMessage()</a></code> : send synchronous messages to the parent process</p> + </td> + </tr> + <tr> + <td>Interfaces</td> + <td> + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager">nsIMessageListenerManager</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageSender">nsIMessageSender</a></code></p> + + <p><code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsISyncMessageSender">nsISyncMessageSender</a></code></p> + + <p><code>nsIContentProcessMessageManager</code></p> + </td> + </tr> + <tr> + <td>How to access</td> + <td> + <p>Code running in a child process can access the CPMM with code like this:</p> + + <pre class="brush: js"> +// child process script +let cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"] + .getService(Ci.nsISyncMessageSender);</pre> + + <p>You can also access it as the <code>cpmm</code> property of <a href="/en-US/docs/Mozilla/JavaScript_code_modules/Services.jsm">Services.jsm</a>, if you are in the child process.</p> + </td> + </tr> + </tbody> +</table> |