OLD | NEW |
---|---|
1 <h1>Native Messaging</h1> | 1 <h1>Native Messaging</h1> |
2 <p> | 2 <p> |
3 Extensions and apps can exchange messages with native applications using an API | 3 Extensions and apps can exchange messages with native applications using an API |
4 that is similar to the other <a href="messaging">message passing APIs</a>. | 4 that is similar to the other <a href="messaging">message passing APIs</a>. |
5 Native applications that support this feature must register a | 5 Native applications that support this feature must register a |
6 <em>native messaging host</em> that knows how to communicate with the extension. | 6 <em>native messaging host</em> that knows how to communicate with the extension. |
7 Chrome starts the host in a separate process and communicates with it using | 7 Chrome starts the host in a separate process and communicates with it using |
8 standard input and standard output streams. | 8 standard input and standard output streams. |
9 | 9 |
10 <h2 id="native-messaging-host">Native messaging host</h2> | 10 <h2 id="native-messaging-host">Native messaging host</h2> |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 Chrome starts each native messaging host in a separate process and communicates | 122 Chrome starts each native messaging host in a separate process and communicates |
123 with it using standard input (<code>stdin</code>) and standard output | 123 with it using standard input (<code>stdin</code>) and standard output |
124 (<code>stdout</code>). The same format is used to send messages in both | 124 (<code>stdout</code>). The same format is used to send messages in both |
125 directions: each message is serialized using JSON, UTF-8 encoded | 125 directions: each message is serialized using JSON, UTF-8 encoded |
126 and is preceded with 32-bit message length in native byte order. | 126 and is preceded with 32-bit message length in native byte order. |
127 The maximum size of a single message from the native messaging host is 1 MB, | 127 The maximum size of a single message from the native messaging host is 1 MB, |
128 mainly to protect Chrome from misbehaving native applications. The maximum | 128 mainly to protect Chrome from misbehaving native applications. The maximum |
129 size of the message sent to the native messaging host is 4 GB. | 129 size of the message sent to the native messaging host is 4 GB. |
130 | 130 |
131 <p> | 131 <p> |
132 The first argument to the native messaging host is the origin of the caller, | |
133 usually <code>chrome-extension://[extension ID of whitelisted extension]</code>. | |
Devlin
2016/09/26 15:53:59
nit: s/extension ID of whitelisted extension/ID of
robwu
2016/09/28 09:07:09
Done.
| |
134 This allows native messaging hosts to identify the source of the message when it | |
135 has allowed multiple extensions to use the native messaging host via the | |
136 <code>allowed_origins</code> key in the | |
137 <a href="#native-messaging-host-manifest">native messaging host manifest</a>. | |
Devlin
2016/09/26 15:53:59
This sentence reads a little funny. Maybe
"This
robwu
2016/09/28 09:07:09
SGTM. I used "native messaging host manifest" inst
| |
138 | |
139 <p> | |
132 When a messaging port is created using $(ref:runtime.connectNative) Chrome | 140 When a messaging port is created using $(ref:runtime.connectNative) Chrome |
133 starts native messaging host process and keeps it running until the port is | 141 starts native messaging host process and keeps it running until the port is |
134 destroyed. On the other hand, when a message is sent using | 142 destroyed. On the other hand, when a message is sent using |
135 $(ref:runtime.sendNativeMessage), without creating a messaging port, Chrome star ts | 143 $(ref:runtime.sendNativeMessage), without creating a messaging port, Chrome star ts |
136 a new native messaging host process for each message. In that case the first | 144 a new native messaging host process for each message. In that case the first |
137 message generated by the host process is handled as a response to the original | 145 message generated by the host process is handled as a response to the original |
138 request, i.e. Chrome will pass it to the response callback specified when | 146 request, i.e. Chrome will pass it to the response callback specified when |
139 $(ref:runtime.sendNativeMessage) is called. All other messages generated by the | 147 $(ref:runtime.sendNativeMessage) is called. All other messages generated by the |
140 native messaging host in that case are ignored. | 148 native messaging host in that case are ignored. |
141 | 149 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 and | 284 and |
277 <a href="https://developer.chrome.com/extensions/examples/api/nativeMessaging/ho st.zip">sample host</a>. | 285 <a href="https://developer.chrome.com/extensions/examples/api/nativeMessaging/ho st.zip">sample host</a>. |
278 | 286 |
279 Run <code>install_host.bat</code> (Windows) or | 287 Run <code>install_host.bat</code> (Windows) or |
280 <code>install_host.sh</code> (Linux / OS X) to install the native messaging | 288 <code>install_host.sh</code> (Linux / OS X) to install the native messaging |
281 host. | 289 host. |
282 Then <a href="getstarted#unpacked">load the app</a> and interact with the app. | 290 Then <a href="getstarted#unpacked">load the app</a> and interact with the app. |
283 Run <code>uninstall_host.bat</code> or <code>uninstall_host.sh</code> to | 291 Run <code>uninstall_host.bat</code> or <code>uninstall_host.sh</code> to |
284 unregister the native messaging host when you are done. | 292 unregister the native messaging host when you are done. |
285 | 293 |
OLD | NEW |