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://[ID of whitelisted extension]</code>. | |
134 This allows native messaging hosts to identify the source of the message when | |
135 multiple extensions are specified in the <code>allowed_origins</code> key in the | |
136 <a href="#native-messaging-host-manifest">native messaging host manifest</a>. | |
137 | |
138 <p> | |
132 When a messaging port is created using $(ref:runtime.connectNative) Chrome | 139 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 | 140 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 | 141 destroyed. On the other hand, when a message is sent using |
135 $(ref:runtime.sendNativeMessage), without creating a messaging port, Chrome star ts | 142 $(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 | 143 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 | 144 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 | 145 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 | 146 $(ref:runtime.sendNativeMessage) is called. All other messages generated by the |
140 native messaging host in that case are ignored. | 147 native messaging host in that case are ignored. |
141 | 148 |
142 <p> | 149 <p> |
143 On Windows, the native messaging host gets passed a command line argument with | 150 On Windows, the native messaging host gets passed a command line argument with |
Devlin
2016/09/29 15:14:51
nit: let's "s/gets/is also" to make it clear that
robwu
2016/09/29 17:38:22
Done. Also added an extra line in the docs to ment
| |
144 a handle to the calling chrome native window: <code>--parent-window=<decimal | 151 a handle to the calling chrome native window: <code>--parent-window=<decimal |
145 handle value></code>. This lets the native messaging host create native UI | 152 handle value></code>. This lets the native messaging host create native UI |
146 windows that are correctly focused. | 153 windows that are correctly focused. |
147 | 154 |
148 <h2 id="native-messaging-client">Connecting to a native application</h2> | 155 <h2 id="native-messaging-client">Connecting to a native application</h2> |
149 <p> | 156 <p> |
150 Sending and receiving messages to and from a native application is very similar | 157 Sending and receiving messages to and from a native application is very similar |
151 to cross-extension messaging. The main difference is that | 158 to cross-extension messaging. The main difference is that |
152 $(ref:runtime.connectNative) is used instead of $(ref:runtime.connect), | 159 $(ref:runtime.connectNative) is used instead of $(ref:runtime.connect), |
153 and $(ref:runtime.sendNativeMessage) is used instead of $(ref:runtime.sendMessag e). | 160 and $(ref:runtime.sendNativeMessage) is used instead of $(ref:runtime.sendMessag e). |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 and | 283 and |
277 <a href="https://developer.chrome.com/extensions/examples/api/nativeMessaging/ho st.zip">sample host</a>. | 284 <a href="https://developer.chrome.com/extensions/examples/api/nativeMessaging/ho st.zip">sample host</a>. |
278 | 285 |
279 Run <code>install_host.bat</code> (Windows) or | 286 Run <code>install_host.bat</code> (Windows) or |
280 <code>install_host.sh</code> (Linux / OS X) to install the native messaging | 287 <code>install_host.sh</code> (Linux / OS X) to install the native messaging |
281 host. | 288 host. |
282 Then <a href="getstarted#unpacked">load the app</a> and interact with the app. | 289 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 | 290 Run <code>uninstall_host.bat</code> or <code>uninstall_host.sh</code> to |
284 unregister the native messaging host when you are done. | 291 unregister the native messaging host when you are done. |
285 | 292 |
OLD | NEW |