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
3// found in the LICENSE file.
4
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
7// marked "nocompile."
8[
9  {
10    "namespace": "runtime",
11    "description": "Use the <code>chrome.runtime</code> API to retrieve the background page, return details about the manifest, and listen for and respond to events 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": [
13      {
14        "id": "Port",
15        "type": "object",
16        "nocompile": true,
17        "description": "An object which allows two way communication with other pages.",
18        "properties": {
19          "name": {"type": "string"},
20          "disconnect": { "type": "function" },
21          "onDisconnect": { "$ref": "events.Event" },
22          "onMessage": { "$ref": "events.Event" },
23          "postMessage": {"type": "function"},
24          "sender": {
25            "$ref": "MessageSender",
26            "optional": true,
27            "description": "This property will <b>only</b> be present on ports passed to onConnect/onConnectExternal listeners."
28          }
29        },
30        "additionalProperties": { "type": "any"}
31      },
32      {
33        "id": "MessageSender",
34        "type": "object",
35        "nocompile": true,
36        "description": "An object containing information about the script context that sent a message or request.",
37        "properties": {
38          "tab": {"$ref": "tabs.Tab", "optional": true, "description": "The $(ref:tabs.Tab) which opened the connection, if any. This property will <strong>only</strong> be present when the connection was opened from a tab (including content scripts), and <strong>only</strong> if the receiver is an extension, not an app.", "extension_types": ["extension", "legacy_packaged_app"]},
39          "id": {"type": "string", "optional": true, "description": "The ID of the extension or app that opened the connection, if any."},
40          "url": {"type": "string", "optional": true, "description": "The URL of the page or frame that opened the connection, if any. This property will <strong>only</strong> be present when the connection was opened from a tab or content script."},
41          "tlsChannelId": {"type": "string", "optional": true, "description": "The TLS channel ID of the web page that opened the connection, if requested by the extension or app, and if available."}
42        }
43      },
44      {
45        "id": "PlatformInfo",
46        "type": "object",
47        "description": "An object containing information about the current platform.",
48        "properties": {
49          "os": {
50            "type": "string",
51            "description": "The operating system chrome is running on.",
52            "enum": ["mac", "win", "android", "cros", "linux", "openbsd"]
53          },
54          "arch": {
55            "type": "string",
56            "enum": ["arm", "x86-32", "x86-64"],
57            "description": "The machine's processor architecture."
58          },
59          "nacl_arch" : {
60            "description": "The native client architecture. This may be different from arch on some platforms.",
61            "type": "string",
62            "enum": ["arm", "x86-32", "x86-64"]
63          }
64        }
65      }
66    ],
67    "properties": {
68      "lastError": {
69        "type": "object",
70        "optional": true,
71        "description": "This will be defined during an API method callback if there was an error",
72        "properties": {
73          "message": {
74            "optional": true,
75            "type": "string",
76            "description": "Details about the error which occurred."
77          }
78        }
79      },
80      "id": {
81        "type": "string",
82        "description": "The ID of the extension/app."
83      }
84    },
85    "functions": [
86      {
87        "name": "getBackgroundPage",
88        "type": "function",
89        "description": "Retrieves the JavaScript 'window' object for the background page running inside the current extension/app. If the background page is an event page, the system will ensure it is loaded before calling the callback. If there is no background page, an error is set.",
90        "parameters": [
91          {
92            "type": "function",
93            "name": "callback",
94            "parameters": [
95              {
96                "name": "backgroundPage",
97                // Note: Only optional because we don't support validation
98                // for custom callbacks.
99                "optional": true,
100                "type": "object",
101                "isInstanceOf": "Window",
102                "additionalProperties": { "type": "any" },
103                "description": "The JavaScript 'window' object for the background page."
104              }
105            ]
106          }
107        ]
108      },
109      {
110        "name": "getManifest",
111        "description": "Returns details about the app or extension from the manifest. The object returned is a serialization of the full <a href=\"manifest.html\">manifest file</a>.",
112        "type": "function",
113        "nocompile": true,
114        "parameters": [],
115        "returns": {
116          "type": "object",
117          "properties": {},
118          "additionalProperties": { "type": "any" },
119          "description": "The manifest details."
120        }
121      },
122      {
123        "name": "getURL",
124        "type": "function",
125        "nocompile": true,
126        "description": "Converts a relative path within an app/extension install directory to a fully-qualified URL.",
127        "parameters": [
128          {
129            "type": "string",
130            "name": "path",
131            "description": "A path to a resource within an app/extension expressed relative to its install directory."
132          }
133        ],
134        "returns": {
135          "type": "string",
136          "description": "The fully-qualified URL to the resource."
137        }
138      },
139      {
140        "name": "setUninstallURL",
141        "type": "function",
142        "description": "Sets the URL to be visited upon uninstallation. This may be used to clean up server-side data, do analytics, and implement surveys. Maximum 255 characters.",
143        "parameters": [
144          {
145            "type": "string",
146            "name": "url",
147            "maxLength": 255
148          }
149        ]
150      },
151      {
152        "name": "reload",
153        "description": "Reloads the app or extension.",
154        "type": "function",
155        "parameters": []
156      },
157      {
158        "name": "requestUpdateCheck",
159        "type": "function",
160        "description": "Requests an update check for this app/extension.",
161        "parameters": [
162          {
163            "type": "function",
164            "name": "callback",
165            "parameters": [
166              {
167                "name": "status",
168                "type": "string",
169                "enum": ["throttled", "no_update", "update_available"],
170                "description": "Result of the update check."
171              },
172              {
173                "name": "details",
174                "type": "object",
175                "optional": true,
176                "properties": {
177                  "version": {
178                    "type": "string",
179                    "description": "The version of the available update."
180                  }
181                },
182                "description": "If an update is available, this contains more information about the available update."
183              }
184            ]
185          }
186        ]
187      },
188      {
189        "name": "restart",
190        "description": "Restart the ChromeOS device when the app runs in kiosk mode. Otherwise, it's no-op.",
191        "type": "function",
192        "parameters": []
193      },
194      {
195        "name": "connect",
196        "type": "function",
197        "nocompile": true,
198        "description": "Attempts to connect to connect listeners within an extension/app (such as the background page), or other extensions/apps. This is useful for content scripts connecting to their extension processes, inter-app/extension communication, and <a href=\"manifest/externally_connectable.html\">web messaging</a>. Note that this does not connect to any listeners in a content script. Extensions may connect to content scripts embedded in tabs via <a href=\"extensions/tabs#method-connect\">tabs.connect</a>.",
199        "parameters": [
200          {"type": "string", "name": "extensionId", "optional": true, "description": "The ID of the extension or app to connect to. If omitted, a connection will be attempted with your own extension. Required if sending messages from a web page for <a href=\"manifest/externally_connectable.html\">web messaging</a>."},
201          {
202            "type": "object",
203            "name": "connectInfo",
204            "properties": {
205              "name": { "type": "string", "optional": true, "description": "Will be passed into onConnect for processes that are listening for the connection event." },
206              "includeTlsChannelId": { "type": "boolean", "optional": true, "description": "Whether the TLS channel ID will be passed into onConnectExternal for processes that are listening for the connection event." }
207            },
208            "optional": true
209          }
210        ],
211        "returns": {
212          "$ref": "Port",
213          "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. "
214        }
215      },
216      {
217        "name": "connectNative",
218        "type": "function",
219        "nocompile": true,
220        "description": "Connects to a native application in the host machine.",
221        "parameters": [
222          {
223            "type": "string",
224            "name": "application",
225            "description": "The name of the registered application to connect to."
226          }
227        ],
228        "returns": {
229          "$ref": "Port",
230          "description": "Port through which messages can be sent and received with the application"
231        }
232      },
233      {
234        "name": "sendMessage",
235        "type": "function",
236        "nocompile": true,
237        "allowAmbiguousOptionalArguments": true,
238        "description": "Sends a single message to event listeners within your extension/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 extension, the $(ref:runtime.onMessage) event will be fired in each page, or $(ref:runtime.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>.",
239        "parameters": [
240          {"type": "string", "name": "extensionId", "optional": true, "description": "The ID of the extension/app to send the message to. If omitted, the message will be sent to your own extension/app. Required if sending messages from a web page for <a href=\"manifest/externally_connectable.html\">web messaging</a>."},
241          { "type": "any", "name": "message" },
242          {
243            "type": "object",
244            "name": "options",
245            "properties": {
246              "includeTlsChannelId": { "type": "boolean", "optional": true, "description": "Whether the TLS channel ID will be passed into onMessageExternal for processes that are listening for the connection event." }
247            },
248            "optional": true
249          },
250          {
251            "type": "function",
252            "name": "responseCallback",
253            "optional": true,
254            "parameters": [
255              {
256                "name": "response",
257                "type": "any",
258                "description": "The JSON response object sent by the handler of the message. If an error occurs while connecting to the extension, the callback will be called with no arguments and $(ref:runtime.lastError) will be set to the error message."
259              }
260            ]
261          }
262        ]
263      },
264      {
265        "name": "sendNativeMessage",
266        "type": "function",
267        "nocompile": true,
268        "description": "Send a single message to a native application.",
269        "parameters": [
270          {
271            "name": "application",
272            "description": "The name of the native messaging host.",
273            "type": "string"
274          },
275          {
276            "name": "message",
277            "description": "The message that will be passed to the native messaging host.",
278            "type": "object",
279            "additionalProperties": {
280              "type": "any"
281            }
282          },
283          {
284            "type": "function",
285            "name": "responseCallback",
286            "optional": true,
287            "parameters": [
288              {
289                "name": "response",
290                "type": "any",
291                "description": "The response message sent by the native messaging host. If an error occurs while connecting to the native messaging host, the callback will be called with no arguments and $(ref:runtime.lastError) will be set to the error message.",
292                "additionalProperties": {
293                  "type": "any"
294                }
295              }
296            ]
297          }
298        ]
299      },
300      {
301        "name": "getPlatformInfo",
302        "type": "function",
303        "description": "Returns information about the current platform.",
304        "parameters": [
305          {
306            "type": "function",
307            "name": "callback",
308            "description": "Called with results",
309            "parameters": [
310              {
311                "name": "platformInfo",
312                "$ref": "PlatformInfo"
313              }
314            ]
315          }
316        ]
317      },
318      {
319        "name": "getPackageDirectoryEntry",
320        "type": "function",
321        "description": "Returns a DirectoryEntry for the package directory.",
322        "parameters": [
323          {
324            "type": "function",
325            "name": "callback",
326            "parameters": [
327              {
328                "name": "directoryEntry",
329                "type": "object",
330                "additionalProperties": { "type": "any" },
331                "isInstanceOf": "DirectoryEntry"
332              }
333            ]
334          }
335        ]
336      }
337    ],
338    "events": [
339      {
340        "name": "onStartup",
341        "type": "function",
342        "description": "Fired when a profile that has this extension installed first starts up. This event is not fired when an incognito profile is started, even if this extension is operating in 'split' incognito mode."
343      },
344      {
345        "name": "onInstalled",
346        "type": "function",
347        "description": "Fired when the extension is first installed, when the extension is updated to a new version, and when Chrome is updated to a new version.",
348        "parameters": [
349          {
350            "type": "object",
351            "name": "details",
352            "properties": {
353              "reason": {
354                "type": "string",
355                "enum": ["install", "update", "chrome_update", "shared_module_update"],
356                "description": "The reason that this event is being dispatched."
357              },
358              "previousVersion": {
359                "type": "string",
360                "optional": true,
361                "description": "Indicates the previous version of the extension, which has just been updated. This is present only if 'reason' is 'update'."
362              },
363              "id": {
364                "type": "string",
365                "optional": true,
366                "description": "Indicates the ID of the imported shared module extension which updated. This is present only if 'reason' is 'shared_module_update'."
367              }
368            }
369          }
370        ]
371      },
372      {
373        "name": "onSuspend",
374        "type": "function",
375        "description": "Sent to the event page just before it is unloaded. This gives the extension opportunity to do some clean up. Note that since the page is unloading, any asynchronous operations started while handling this event are not guaranteed to complete. If more activity for the event page occurs before it gets unloaded the onSuspendCanceled event will be sent and the page won't be unloaded. "
376      },
377      {
378        "name": "onSuspendCanceled",
379        "type": "function",
380        "description": "Sent after onSuspend to indicate that the app won't be unloaded after all."
381      },
382      {
383        "name": "onUpdateAvailable",
384        "type": "function",
385        "description": "Fired when an update is available, but isn't installed immediately because the app is currently running. If you do nothing, the update will be installed the next time the background page gets unloaded, if you want it to be installed sooner you can explicitly call chrome.runtime.reload(). If your extension is using a persistent background page, the background page of course never gets unloaded, so unless you call chrome.runtime.reload() manually in response to this event the update will not get installed until the next time chrome itself restarts. If no handlers are listening for this event, and your extension has a persistent background page, it behaves as if chrome.runtime.reload() is called in response to this event.",
386        "parameters": [
387          {
388            "type": "object",
389            "name": "details",
390            "properties": {
391              "version": {
392                "type": "string",
393                "description": "The version number of the available update."
394              }
395            },
396            "additionalProperties": { "type": "any" },
397            "description": "The manifest details of the available update."
398          }
399        ]
400      },
401      {
402        // TODO(xiyuan): onBrowserUpdateAvailable is deprecated in favor of
403        // onRestartRequired. We should remove it when we are sure it is unused.
404        "name": "onBrowserUpdateAvailable",
405        "type": "function",
406        "description": "Fired when a Chrome update is available, but isn't installed immediately because a browser restart is required.",
407        "deprecated": "Please use $(ref:runtime.onRestartRequired).",
408        "parameters": []
409      },
410      {
411        "name": "onConnect",
412        "type": "function",
413        "nocompile": true,
414        "options": {
415          "unmanaged": true
416        },
417        "description": "Fired when a connection is made from either an extension process or a content script.",
418        "parameters": [
419          {"$ref": "Port", "name": "port"}
420        ]
421      },
422      {
423        "name": "onConnectExternal",
424        "type": "function",
425        "nocompile": true,
426        "options": {
427          "unmanaged": true
428        },
429        "description": "Fired when a connection is made from another extension.",
430        "parameters": [
431          {"$ref": "Port", "name": "port"}
432        ]
433      },
434      {
435        "name": "onMessage",
436        "type": "function",
437        "options": {
438          "unmanaged": true
439        },
440        "nocompile": true,
441        "description": "Fired when a message is sent from either an extension process or a content script.",
442        "parameters": [
443          {"name": "message", "type": "any", "optional": true, "description": "The message sent by the calling script."},
444          {"name": "sender", "$ref": "MessageSender" },
445          {"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 the same document, then only one may send a response. This function becomes invalid when the event listener returns, unless you return true 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</code> is called)." }
446        ],
447        "returns": {
448          "type": "boolean",
449          "optional": true,
450          "description": "Return true from the event listener if you wish to call <code>sendResponse</code> after the event listener returns."
451        }
452      },
453      {
454        "name": "onMessageExternal",
455        "type": "function",
456        "options": {
457          "unmanaged": true
458        },
459        "nocompile": true,
460        "description": "Fired when a message is sent from another extension/app. Cannot be used in a content script.",
461        "parameters": [
462          {"name": "message", "type": "any", "optional": true, "description": "The message sent by the calling script."},
463          {"name": "sender", "$ref": "MessageSender" },
464          {"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 the same document, then only one may send a response. This function becomes invalid when the event listener returns, unless you return true 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</code> is called)." }
465        ],
466        "returns": {
467          "type": "boolean",
468          "optional": true,
469          "description": "Return true from the event listener if you wish to call <code>sendResponse</code> after the event listener returns."
470        }
471      },
472      {
473        "name": "onRestartRequired",
474        "type": "function",
475        "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 time to let the restart to happen. If the app does nothing, a restart will be enforced after a 24-hour grace period has passed. Currently, this event is only fired for Chrome OS kiosk apps.",
476        "parameters": [
477          {
478            "type": "string",
479            "name": "reason",
480            "description": "The reason that the event is being dispatched. 'app_update' is used when the restart is needed because the application is updated to a newer version. 'os_update' is used when the restart is needed because the browser/OS is updated to a newer version. 'periodic' is used when the system runs for more than the permitted uptime set in the enterprise policy.",
481            "enum": ["app_update", "os_update", "periodic"]
482          }
483        ]
484      }
485    ]
486  }
487]
488