aboutsummaryrefslogtreecommitdiff
path: root/files/es/mozilla/firefox/multiprocess_firefox/message_manager
diff options
context:
space:
mode:
Diffstat (limited to 'files/es/mozilla/firefox/multiprocess_firefox/message_manager')
-rw-r--r--files/es/mozilla/firefox/multiprocess_firefox/message_manager/index.html74
-rw-r--r--files/es/mozilla/firefox/multiprocess_firefox/message_manager/process_scripts/index.html81
2 files changed, 155 insertions, 0 deletions
diff --git a/files/es/mozilla/firefox/multiprocess_firefox/message_manager/index.html b/files/es/mozilla/firefox/multiprocess_firefox/message_manager/index.html
new file mode 100644
index 0000000000..5d3214a425
--- /dev/null
+++ b/files/es/mozilla/firefox/multiprocess_firefox/message_manager/index.html
@@ -0,0 +1,74 @@
+---
+title: Message manager
+slug: Mozilla/Firefox/Multiprocess_Firefox/Message_Manager
+tags:
+ - API
+ - Guide
+ - JavaScript
+ - NeedsTranslation
+ - TopicStub
+translation_of: Mozilla/Firefox/Multiprocess_Firefox/Message_Manager
+---
+<div>{{FirefoxSidebar}}</div><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 code and extension's code, to access web content while 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 on 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/es/mozilla/firefox/multiprocess_firefox/message_manager/process_scripts/index.html b/files/es/mozilla/firefox/multiprocess_firefox/message_manager/process_scripts/index.html
new file mode 100644
index 0000000000..f6011c7836
--- /dev/null
+++ b/files/es/mozilla/firefox/multiprocess_firefox/message_manager/process_scripts/index.html
@@ -0,0 +1,81 @@
+---
+title: Process scripts
+slug: Mozilla/Firefox/Multiprocess_Firefox/Message_Manager/Process_scripts
+tags:
+ - Necesita traducción
+translation_of: Mozilla/Firefox/Multiprocess_Firefox/Message_Manager/Process_scripts
+---
+<div>{{FirefoxSidebar}}</div><div class="geckoVersionNote">
+<p>Los scripts de proceso son nuevos en Firefox 38.</p>
+</div>
+
+<div class="note">
+<p>Si esta utilizando el addon sdk, puede utilizar el <a href="/en-US/docs/Mozilla/Add-ons/SDK/Low-Level_APIs/remote_parent">remote/parent</a> módulo <code>remoteRequire</code> en su lugar.</p>
+</div>
+
+<p><span id="result_box" lang="es"><span>Cuando necesite ejecutar código en el proceso de contenido para acceder al contenido web, debe utilizar secuencias de</span></span> frame scripts. <span id="result_box" lang="es"><span>Sin embargo, un problema con</span></span> los scripts <span id="result_box" lang="es"><span>es que se pueden cargar varias veces en el proceso de contenido, en varios ámbitos que están aislados unos de otros.</span> <span>Por ejemplo, si llama a la funcion </span></span><code>loadFrameScript()</code> del gestor de mensajes de script, <span id="result_box" lang="es"><span>entonces el script se cargará por separado en todas las pestañas abiertas.</span> <span>Esto puede causar un problema que las secuencias de scripts de trama están interactuando con un servicio global en el proceso de contenido.</span></span></p>
+
+<p><span id="result_box" lang="es"><span>Por ejemplo, en multiprocesos Firefox, si necesita usar</span></span> <code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentPolicy">nsIContentPolicy</a></code> to register a content policy, <a href="/en-US/Firefox/Multiprocess_Firefox/Limitations_of_chrome_scripts#nsIContentPolicy">you must do this in the content process</a>. <span id="result_box" lang="es"><span>para registrar una política de contenido, debe hacerlo en el proceso de contenido.</span> <span>Pero si lo registra en una secuencia de frame script la secuencia de frame script se carga más de una vez, registrará la política de contenido más de una vez, lo que probablemente no es lo que pretende.</span></span></p>
+
+<p>De forma similar, algunas notificaciones de observadores deben registrarse en el frame script, pero si lo hace en una secuencia de frame scrip, se cargara más de una vez, recibirá varias notificaciones, para ese evento.</p>
+
+<p><span id="result_box" lang="es"><span>La solución en estos casos es usar un script de proceso en lugar de un frame script.</span></span></p>
+
+<p>You can load a process script by accessing a <a href="/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Message_manager_overview#Parent_process">parent process message manager</a> and calling its <code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcessScriptLoader#loadProcessScript()">loadProcessScript()</a></code> function. The following code uses the global parent process message manager, which will load the script into the the chrome process and any child processes:</p>
+
+<pre class="brush: js">// chrome code
+let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"]
+ .getService(Ci.nsIProcessScriptLoader);
+ppmm.loadProcessScript("chrome://whatever/process-script.js", true);
+ppmm.addMessageListener("Hello", function(msg) { ... });</pre>
+
+<p>The process script's global is a <a href="/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Message_manager_overview#Child_process_message_manager">child process message manager</a>, which enables the process script to receive messages from the chrome side, and to send messages to the chrome side:</p>
+
+<pre class="brush: js">// process-script.js
+if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
+ dump("Welcome to the process script in a content process");
+} else {
+ dump("Welcome to the process script in the main process");
+}
+
+// Message is sent using <code>ContentProcessMessageManager</code>
+sendAsyncMessage("Hello");</pre>
+
+<p>In this example, the <code>dump()</code> statement will run once in each content process as well as in the main process. This example also figures out whether it is running in the chrome or in a content process by looking at the <a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIXULRuntime#Process_type_constants">process type</a> in <code><a href="/en-US/docs/Mozilla/JavaScript_code_modules/Services.jsm">Services.appinfo</a></code>.</p>
+
+<p>In just about every respect, using process scripts is like using frame scripts:</p>
+
+<ul>
+ <li>you can pass the allowDelayedLoad to <code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcessScriptLoader#loadProcessScript()">loadProcessScript()</a></code>. If you do, you must call <code><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcessScriptLoader#removeDelayedProcessScript()">removeDelayedProcessScript()</a></code> when your extension is disabled or removed</li>
+ <li>the message-passing APIs are the same: <code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageSender#sendAsyncMessage()">sendAsyncMessage()</a></code> is available in both directions, while <code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsISyncMessageSender#sendSyncMessage()">sendSyncMessage()</a></code> is available from content to chrome only</li>
+ <li>process scripts are system-privileged, and have access to the <code><a href="/en-US/docs/Components_object">Components</a></code> object. However, process scripts are subject to <a href="/en-US/Firefox/Multiprocess_Firefox/Limitations_of_frame_scripts">the same kinds of limitations as frame scripts</a> (for example, no file system access).</li>
+ <li>process scripts stay loaded until their host process is closed.</li>
+ <li>the environment for process scripts is similar to that for frame scripts. However, you don't get access to web content or DOM events from a process script.</li>
+</ul>
+
+<h2 id="Retrieving_the_content_frame_message_manager_for_a_content_window">Retrieving the content frame message manager for a content window</h2>
+
+<p>When an observer notification in a process script contains a content document or window it can be useful to not use talk through the child/parent process message managers but through the window's content frame message manager, e.g. if responses should be processed by a frame script instead of the process script.</p>
+
+<p>This can be achieved by traversing the docshell tree up to the top window and then retrieving its content message manager, as follows:</p>
+
+<pre class="brush: js">function contentMMFromContentWindow(window) {
+ let tree = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.<span class="pl-c1">nsIDocShellTreeItem</span>);
+ let top = tree.sameTypeRootTreeItem;
+ let iface = QueryInterface(Ci.nsIDocShell).QueryInterface(Ci.nsIInterfaceRequestor);
+ return iface.getInterface(Ci.nsIContentFrameMessageManager);
+}
+</pre>
+
+<div class="note">
+<p>This is intended for unprivileged pages running in a content process. Chrome-privileged pages or things running in the parent process may require special treatment.</p>
+</div>
+
+<p>If the above doesn't work try this:</p>
+
+<pre class="brush: js">function contentMMFromContentWindow_Method2(aContentWindow) {
+ return aContentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDocShell)
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIContentFrameMessageManager);
+}</pre>