Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: extensions/common/api/runtime.json

Issue 1874133002: Improve documentation of extension messaging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix refs, clarify API parameters Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Note: Many of these functions and events are implemented by hand and should 5 // Note: Many of these functions and events are implemented by hand and should
6 // not elicit any code generation from the schema compiler. These items are 6 // not elicit any code generation from the schema compiler. These items are
7 // marked "nocompile." 7 // marked "nocompile."
8 [ 8 [
9 { 9 {
10 "namespace": "runtime", 10 "namespace": "runtime",
11 "description": "Use the <code>chrome.runtime</code> API to retrieve the back ground page, return details about the manifest, and listen for and respond to ev ents in the app or extension lifecycle. You can also use this API to convert the relative path of URLs to fully-qualified URLs.", 11 "description": "Use the <code>chrome.runtime</code> API to retrieve the back ground page, return details about the manifest, and listen for and respond to ev ents in the app or extension lifecycle. You can also use this API to convert the relative path of URLs to fully-qualified URLs.",
12 "types": [ 12 "types": [
13 { 13 {
14 "id": "Port", 14 "id": "Port",
15 "type": "object", 15 "type": "object",
16 "nocompile": true, 16 "nocompile": true,
17 "description": "An object which allows two way communication with other pages.", 17 "description": "An object which allows two way communication with other pages. See <a href=\"messaging#connect\">Long-lived connections</a> for more inf ormation.",
18 "properties": { 18 "properties": {
19 "name": {"type": "string"}, 19 "name": {
20 "disconnect": { "type": "function" }, 20 "type": "string",
21 "onDisconnect": { "$ref": "events.Event" }, 21 "description": "The name of the port, as specified in the call to $( ref:runtime.connect)."
22 "onMessage": { "$ref": "events.Event" }, 22 },
23 "postMessage": {"type": "function"}, 23 "disconnect": {
24 "type": "function",
25 "description": "Immediately disconnect the port. Calling <code>disco nnect()</code> on an already-disconnected port has no effect. When a port is dis connected, no <em>new</em> events are generated any more on this port. If <code> disconnect()</code> was called while dispatching an $(ref:Port.onMessage onMessa ge) event, then the existing handlers still continue to be fired for that event. "
Devlin 2016/04/13 20:15:33 remove "any more"
Devlin 2016/04/13 20:15:33 Here, too, I worry that we're getting too much int
robwu 2016/04/13 21:03:05 Done.
robwu 2016/04/13 21:03:05 Done.
26 },
27 "onDisconnect": {
28 "$ref": "events.Event",
29 "description": "Fired when the port is disconnected from the other e nd(s). $(ref:runtime.lastError) may be set if the port was disconnected by an er ror. If the port is closed via $(ref:Port.disconnect disconnect), then this even t is <em>only</em> fired on the other end. This event is fired at most once (see also <a href=\"messaging#port-lifetime\">Port lifetime</a>). The first and only parameter to the event handler is this disconnected port."
30 },
31 "onMessage": {
32 "$ref": "events.Event",
33 "description": "This event is fired when $(ref:Port.postMessage post Message) is called by the other end of the port. The first parameter is the mess age, the second parameter is the port that received the message."
34 },
35 "postMessage": {
36 "type": "function",
37 "description": "Send a message to the other end of the port. If the port is disconnected, an error is thrown.",
38 "parameters": [
39 {"name": "message", "type": "any", "description": "The message to send. This object should be JSON-ifiable."}
40 ]
41 },
24 "sender": { 42 "sender": {
25 "$ref": "MessageSender", 43 "$ref": "MessageSender",
26 "optional": true, 44 "optional": true,
27 "description": "This property will <b>only</b> be present on ports p assed to onConnect/onConnectExternal listeners." 45 "description": "This property will <b>only</b> be present on ports p assed to $(ref:runtime.onConnect onConnect) / $(ref:runtime.onConnectExternal on ConnectExternal) listeners."
28 } 46 }
29 }, 47 },
30 "additionalProperties": { "type": "any"} 48 "additionalProperties": { "type": "any"}
31 }, 49 },
32 { 50 {
33 "id": "MessageSender", 51 "id": "MessageSender",
34 "type": "object", 52 "type": "object",
35 "nocompile": true, 53 "nocompile": true,
36 "description": "An object containing information about the script contex t that sent a message or request.", 54 "description": "An object containing information about the script contex t that sent a message or request.",
37 "properties": { 55 "properties": {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 { 260 {
243 "name": "restart", 261 "name": "restart",
244 "description": "Restart the ChromeOS device when the app runs in kiosk m ode. Otherwise, it's no-op.", 262 "description": "Restart the ChromeOS device when the app runs in kiosk m ode. Otherwise, it's no-op.",
245 "type": "function", 263 "type": "function",
246 "parameters": [] 264 "parameters": []
247 }, 265 },
248 { 266 {
249 "name": "connect", 267 "name": "connect",
250 "type": "function", 268 "type": "function",
251 "nocompile": true, 269 "nocompile": true,
252 "description": "Attempts to connect to connect listeners within an exten sion/app (such as the background page), or other extensions/apps. This is useful for content scripts connecting to their extension processes, inter-app/extensio n communication, and <a href=\"manifest/externally_connectable.html\">web messag ing</a>. Note that this does not connect to any listeners in a content script. E xtensions may connect to content scripts embedded in tabs via <a href=\"extensio ns/tabs#method-connect\">tabs.connect</a>.", 270 "description": "Attempts to connect to connect listeners within an exten sion/app (such as the background page), or other extensions/apps. This is useful for content scripts connecting to their extension processes, inter-app/extensio n communication, and <a href=\"manifest/externally_connectable.html\">web messag ing</a>. Note that this does not connect to any listeners in a content script. E xtensions may connect to content scripts embedded in tabs via $(ref:tabs.connect ).",
253 "parameters": [ 271 "parameters": [
254 {"type": "string", "name": "extensionId", "optional": true, "descripti on": "The ID of the extension or app to connect to. If omitted, a connection wil l be attempted with your own extension. Required if sending messages from a web page for <a href=\"manifest/externally_connectable.html\">web messaging</a>."}, 272 {"type": "string", "name": "extensionId", "optional": true, "descripti on": "The ID of the extension or app to connect to. If omitted, a connection wil l be attempted with your own extension. Required if sending messages from a web page for <a href=\"manifest/externally_connectable.html\">web messaging</a>."},
255 { 273 {
256 "type": "object", 274 "type": "object",
257 "name": "connectInfo", 275 "name": "connectInfo",
258 "properties": { 276 "properties": {
259 "name": { "type": "string", "optional": true, "description": "Will be passed into onConnect for processes that are listening for the connection ev ent." }, 277 "name": { "type": "string", "optional": true, "description": "Will be passed into onConnect for processes that are listening for the connection ev ent." },
260 "includeTlsChannelId": { "type": "boolean", "optional": true, "des cription": "Whether the TLS channel ID will be passed into onConnectExternal for processes that are listening for the connection event." } 278 "includeTlsChannelId": { "type": "boolean", "optional": true, "des cription": "Whether the TLS channel ID will be passed into onConnectExternal for processes that are listening for the connection event." }
261 }, 279 },
262 "optional": true 280 "optional": true
263 } 281 }
264 ], 282 ],
265 "returns": { 283 "returns": {
266 "$ref": "Port", 284 "$ref": "Port",
267 "description": "Port through which messages can be sent and received. The port's $(ref:runtime.Port onDisconnect) event is fired if the extension/app does not exist. " 285 // TODO(robwu): This description should appear in the documentation, b ut the docserver does not render it.
286 "description": "Port through which messages can be sent and received. The port's $(ref:Port onDisconnect) event is fired if the extension/app does not exist. "
268 } 287 }
269 }, 288 },
270 { 289 {
271 "name": "connectNative", 290 "name": "connectNative",
272 "type": "function", 291 "type": "function",
273 "nocompile": true, 292 "nocompile": true,
274 "description": "Connects to a native application in the host machine.", 293 "description": "Connects to a native application in the host machine. Se e <a href=\"nativeMessaging\">Native Messaging</a> for more information.",
275 "parameters": [ 294 "parameters": [
276 { 295 {
277 "type": "string", 296 "type": "string",
278 "name": "application", 297 "name": "application",
279 "description": "The name of the registered application to connect to ." 298 "description": "The name of the registered application to connect to ."
280 } 299 }
281 ], 300 ],
282 "returns": { 301 "returns": {
283 "$ref": "Port", 302 "$ref": "Port",
284 "description": "Port through which messages can be sent and received w ith the application" 303 "description": "Port through which messages can be sent and received w ith the application"
285 } 304 }
286 }, 305 },
287 { 306 {
288 "name": "sendMessage", 307 "name": "sendMessage",
289 "type": "function", 308 "type": "function",
290 "nocompile": true, 309 "nocompile": true,
291 "allowAmbiguousOptionalArguments": true, 310 "allowAmbiguousOptionalArguments": true,
292 "description": "Sends a single message to event listeners within your ex tension/app or a different extension/app. Similar to $(ref:runtime.connect) but only sends a single message, with an optional response. If sending to your exten sion, the $(ref:runtime.onMessage) event will be fired in each page, or $(ref:ru ntime.onMessageExternal), if a different extension. Note that extensions cannot send messages to content scripts using this method. To send messages to content scripts, use <a href=\"extensions/tabs#method-sendMessage\">tabs.sendMessage</a> .", 311 "description": "Sends a single message to event listeners within your ex tension/app or a different extension/app. Similar to $(ref:runtime.connect) but only sends a single message, with an optional response. If sending to your exten sion, the $(ref:runtime.onMessage) event will be fired in each page, or $(ref:ru ntime.onMessageExternal), if a different extension. Note that extensions cannot send messages to content scripts using this method. To send messages to content scripts, use $(ref:tabs.sendMessage).",
293 "parameters": [ 312 "parameters": [
294 {"type": "string", "name": "extensionId", "optional": true, "descripti on": "The ID of the extension/app to send the message to. If omitted, the messag e will be sent to your own extension/app. Required if sending messages from a we b page for <a href=\"manifest/externally_connectable.html\">web messaging</a>."} , 313 {"type": "string", "name": "extensionId", "optional": true, "descripti on": "The ID of the extension/app to send the message to. If omitted, the messag e will be sent to your own extension/app. Required if sending messages from a we b page for <a href=\"manifest/externally_connectable.html\">web messaging</a>."} ,
295 { "type": "any", "name": "message" }, 314 { "type": "any", "name": "message", "description": "The message to sen d. This message should be JSON-ifiable object." },
296 { 315 {
297 "type": "object", 316 "type": "object",
298 "name": "options", 317 "name": "options",
299 "properties": { 318 "properties": {
300 "includeTlsChannelId": { "type": "boolean", "optional": true, "des cription": "Whether the TLS channel ID will be passed into onMessageExternal for processes that are listening for the connection event." } 319 "includeTlsChannelId": { "type": "boolean", "optional": true, "des cription": "Whether the TLS channel ID will be passed into onMessageExternal for processes that are listening for the connection event." }
301 }, 320 },
302 "optional": true 321 "optional": true
303 }, 322 },
304 { 323 {
305 "type": "function", 324 "type": "function",
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 "deprecated": "Please use $(ref:runtime.onRestartRequired).", 479 "deprecated": "Please use $(ref:runtime.onRestartRequired).",
461 "parameters": [] 480 "parameters": []
462 }, 481 },
463 { 482 {
464 "name": "onConnect", 483 "name": "onConnect",
465 "type": "function", 484 "type": "function",
466 "nocompile": true, 485 "nocompile": true,
467 "options": { 486 "options": {
468 "unmanaged": true 487 "unmanaged": true
469 }, 488 },
470 "description": "Fired when a connection is made from either an extension process or a content script.", 489 "description": "Fired when a connection is made from either an extension process or a content script (by $(ref:runtime.connect)).",
471 "parameters": [ 490 "parameters": [
472 {"$ref": "Port", "name": "port"} 491 {"$ref": "Port", "name": "port"}
473 ] 492 ]
474 }, 493 },
475 { 494 {
476 "name": "onConnectExternal", 495 "name": "onConnectExternal",
477 "type": "function", 496 "type": "function",
478 "nocompile": true, 497 "nocompile": true,
479 "description": "Fired when a connection is made from another extension." , 498 "description": "Fired when a connection is made from another extension ( by $(ref:runtime.connect)).",
480 "parameters": [ 499 "parameters": [
481 {"$ref": "Port", "name": "port"} 500 {"$ref": "Port", "name": "port"}
482 ] 501 ]
483 }, 502 },
484 { 503 {
485 "name": "onMessage", 504 "name": "onMessage",
486 "type": "function", 505 "type": "function",
487 "nocompile": true, 506 "nocompile": true,
488 "options": { 507 "options": {
489 "unmanaged": true 508 "unmanaged": true
490 }, 509 },
491 "description": "Fired when a message is sent from either an extension pr ocess or a content script.", 510 "description": "Fired when a message is sent from either an extension pr ocess (by $(ref:runtime.sendMessage)) or a content script (by $(ref:tabs.sendMes sage)).",
492 "parameters": [ 511 "parameters": [
493 {"name": "message", "type": "any", "optional": true, "description": "T he message sent by the calling script."}, 512 {"name": "message", "type": "any", "optional": true, "description": "T he message sent by the calling script."},
494 {"name": "sender", "$ref": "MessageSender" }, 513 {"name": "sender", "$ref": "MessageSender" },
495 {"name": "sendResponse", "type": "function", "description": "Function to call (at most once) when you have a response. The argument should be any JSON -ifiable object. If you have more than one <code>onMessage</code> listener in th e same document, then only one may send a response. This function becomes invali d when the event listener returns, unless you return true from the event listene r to indicate you wish to send a response asynchronously (this will keep the mes sage channel open to the other end until <code>sendResponse</code> is called)." } 514 {"name": "sendResponse", "type": "function", "description": "Function to call (at most once) when you have a response. The argument should be any JSON -ifiable object. If you have more than one <code>onMessage</code> listener in th e same document, then only one may send a response. This function becomes invali d when the event listener returns, <strong>unless you return true</strong> from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end until <code>sendResponse</co de> is called)." }
496 ], 515 ],
497 "returns": { 516 "returns": {
498 "type": "boolean", 517 "type": "boolean",
499 "optional": true, 518 "optional": true,
500 "description": "Return true from the event listener if you wish to cal l <code>sendResponse</code> after the event listener returns." 519 "description": "Return true from the event listener if you wish to cal l <code>sendResponse</code> after the event listener returns."
501 } 520 }
502 }, 521 },
503 { 522 {
504 "name": "onMessageExternal", 523 "name": "onMessageExternal",
505 "type": "function", 524 "type": "function",
506 "nocompile": true, 525 "nocompile": true,
507 "description": "Fired when a message is sent from another extension/app. Cannot be used in a content script.", 526 "description": "Fired when a message is sent from another extension/app (by $(ref:runtime.sendMessage)). Cannot be used in a content script.",
508 "parameters": [ 527 "parameters": [
509 {"name": "message", "type": "any", "optional": true, "description": "T he message sent by the calling script."}, 528 {"name": "message", "type": "any", "optional": true, "description": "T he message sent by the calling script."},
510 {"name": "sender", "$ref": "MessageSender" }, 529 {"name": "sender", "$ref": "MessageSender" },
511 {"name": "sendResponse", "type": "function", "description": "Function to call (at most once) when you have a response. The argument should be any JSON -ifiable object. If you have more than one <code>onMessage</code> listener in th e same document, then only one may send a response. This function becomes invali d when the event listener returns, unless you return true from the event listene r to indicate you wish to send a response asynchronously (this will keep the mes sage channel open to the other end until <code>sendResponse</code> is called)." } 530 {"name": "sendResponse", "type": "function", "description": "Function to call (at most once) when you have a response. The argument should be any JSON -ifiable object. If you have more than one <code>onMessage</code> listener in th e same document, then only one may send a response. This function becomes invali d when the event listener returns, <strong>unless you return true</strong> from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end until <code>sendResponse</co de> is called)." }
512 ], 531 ],
513 "returns": { 532 "returns": {
514 "type": "boolean", 533 "type": "boolean",
515 "optional": true, 534 "optional": true,
516 "description": "Return true from the event listener if you wish to cal l <code>sendResponse</code> after the event listener returns." 535 "description": "Return true from the event listener if you wish to cal l <code>sendResponse</code> after the event listener returns."
517 } 536 }
518 }, 537 },
519 { 538 {
520 "name": "onRestartRequired", 539 "name": "onRestartRequired",
521 "type": "function", 540 "type": "function",
522 "description": "Fired when an app or the device that it runs on needs to be restarted. The app should close all its windows at its earliest convenient t ime to let the restart to happen. If the app does nothing, a restart will be enf orced after a 24-hour grace period has passed. Currently, this event is only fir ed for Chrome OS kiosk apps.", 541 "description": "Fired when an app or the device that it runs on needs to be restarted. The app should close all its windows at its earliest convenient t ime to let the restart to happen. If the app does nothing, a restart will be enf orced after a 24-hour grace period has passed. Currently, this event is only fir ed for Chrome OS kiosk apps.",
523 "parameters": [ 542 "parameters": [
524 { 543 {
525 "$ref": "OnRestartRequiredReason", 544 "$ref": "OnRestartRequiredReason",
526 "name": "reason", 545 "name": "reason",
527 "description": "The reason that the event is being dispatched." 546 "description": "The reason that the event is being dispatched."
528 } 547 }
529 ] 548 ]
530 } 549 }
531 ] 550 ]
532 } 551 }
533 ] 552 ]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698