feat: [extensions] implement a couple of tabs APIs (#21779)

This commit is contained in:
Jeremy Apthorp 2020-01-15 15:11:51 -08:00 committed by GitHub
parent 8278a64e00
commit b9eb68c0b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 568 additions and 17 deletions

View file

@ -11,8 +11,16 @@ assert(enable_extensions)
################################################################################
# Public Targets
group("api") {
public_deps = [
":generated_api_json_strings",
":generated_api_types",
]
}
group("extensions_features") {
public_deps = [
":api_features",
":manifest_features",
# TODO(devlin): It would be nicer to have this dependency hoisted up to
@ -25,11 +33,52 @@ group("extensions_features") {
################################################################################
# Private Targets
generated_json_strings("generated_api_json_strings") {
sources = [
"tabs.json",
]
configs = [ "//build/config:precompiled_headers" ]
bundle_name = "Electron"
schema_include_rules = "extensions/common/api:extensions::api::%(namespace)s"
root_namespace = "extensions::api::%(namespace)s"
deps = [
"//extensions/common/api",
]
visibility = [ ":api" ]
}
generated_types("generated_api_types") {
sources = [
"tabs.json",
]
configs = [ "//build/config:precompiled_headers" ]
schema_include_rules = "extensions/common/api:extensions::api::%(namespace)s"
root_namespace = "extensions::api::%(namespace)s"
deps = [
"//extensions/common/api",
]
visibility = [ ":api" ]
}
json_features("manifest_features") {
feature_type = "ManifestFeature"
method_name = "AddAtomManifestFeatures"
method_name = "AddElectronManifestFeatures"
sources = [
"_manifest_features.json",
]
visibility = [ ":extensions_features" ]
}
json_features("api_features") {
feature_type = "APIFeature"
method_name = "AddElectronAPIFeatures"
sources = [
"_api_features.json",
]
visibility = [ ":extensions_features" ]
}

View file

@ -0,0 +1,7 @@
{
"tabs": {
"channel": "stable",
"extension_types": ["extension"],
"contexts": ["blessed_extension"]
}
}

View file

@ -0,0 +1,86 @@
[
{
"namespace": "tabs",
"functions": [
{
"name": "executeScript",
"type": "function",
"parameters": [
{
"type": "integer",
"name": "tabId",
"minimum": 0,
"optional": true,
"description": "The ID of the tab in which to run the script; defaults to the active tab of the current window."
},
{
"$ref": "extensionTypes.InjectDetails",
"name": "details",
"description": "Details of the script to run. Either the code or the file property must be set, but both may not be set at the same time."
},
{
"type": "function",
"name": "callback",
"optional": true,
"description": "Called after all the JavaScript has been executed.",
"parameters": [
{
"name": "result",
"optional": true,
"type": "array",
"items": {
"type": "any",
"minimum": 0
},
"description": "The result of the script in every injected frame."
}
]
}
]
},
{
"name": "sendMessage",
"nocompile": true,
"type": "function",
"description": "Sends a single message to the content script(s) in the specified tab, with an optional callback to run when a response is sent back. The $(ref:runtime.onMessage) event is fired in each content script running in the specified tab for the current extension.",
"parameters": [
{
"type": "integer",
"name": "tabId",
"minimum": 0
},
{
"type": "any",
"name": "message",
"description": "The message to send. This message should be a JSON-ifiable object."
},
{
"type": "object",
"name": "options",
"properties": {
"frameId": {
"type": "integer",
"optional": true,
"minimum": 0,
"description": "Send a message to a specific <a href='webNavigation#frame_ids'>frame</a> identified by <code>frameId</code> instead of all frames in the tab."
}
},
"optional": true
},
{
"type": "function",
"name": "responseCallback",
"optional": true,
"parameters": [
{
"name": "response",
"type": "any",
"description": "The JSON response object sent by the handler of the message. If an error occurs while connecting to the specified tab, the callback is called with no arguments and $(ref:runtime.lastError) is set to the error message."
}
]
}
]
}
]
}
]