feat: [extensions] implement a couple of tabs APIs (#21779)
This commit is contained in:
parent
8278a64e00
commit
b9eb68c0b4
21 changed files with 568 additions and 17 deletions
|
@ -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" ]
|
||||
}
|
||||
|
|
7
shell/common/extensions/api/_api_features.json
Normal file
7
shell/common/extensions/api/_api_features.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"tabs": {
|
||||
"channel": "stable",
|
||||
"extension_types": ["extension"],
|
||||
"contexts": ["blessed_extension"]
|
||||
}
|
||||
}
|
86
shell/common/extensions/api/tabs.json
Normal file
86
shell/common/extensions/api/tabs.json
Normal 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."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -11,13 +11,17 @@
|
|||
#include "base/containers/span.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "electron/shell/common/extensions/api/generated_schemas.h"
|
||||
#include "extensions/common/alias.h"
|
||||
#include "extensions/common/features/feature_provider.h"
|
||||
#include "extensions/common/features/json_feature_provider_source.h"
|
||||
#include "extensions/common/features/simple_feature.h"
|
||||
#include "extensions/common/manifest_constants.h"
|
||||
#include "extensions/common/manifest_handler.h"
|
||||
#include "extensions/common/manifest_handlers/permissions_parser.h"
|
||||
#include "extensions/common/manifest_url_handlers.h"
|
||||
#include "extensions/common/permissions/permissions_info.h"
|
||||
#include "shell/common/extensions/api/api_features.h"
|
||||
#include "shell/common/extensions/api/manifest_features.h"
|
||||
|
||||
namespace extensions {
|
||||
|
@ -73,19 +77,14 @@ namespace electron {
|
|||
AtomExtensionsAPIProvider::AtomExtensionsAPIProvider() = default;
|
||||
AtomExtensionsAPIProvider::~AtomExtensionsAPIProvider() = default;
|
||||
|
||||
// TODO(samuelmaddock): generate API features?
|
||||
|
||||
void AtomExtensionsAPIProvider::AddAPIFeatures(
|
||||
extensions::FeatureProvider* provider) {
|
||||
// AddShellAPIFeatures(provider);
|
||||
extensions::AddElectronAPIFeatures(provider);
|
||||
}
|
||||
|
||||
void AtomExtensionsAPIProvider::AddManifestFeatures(
|
||||
extensions::FeatureProvider* provider) {
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
// TODO(samuelmaddock): why is the extensions namespace generated?
|
||||
extensions::AddAtomManifestFeatures(provider);
|
||||
#endif
|
||||
extensions::AddElectronManifestFeatures(provider);
|
||||
}
|
||||
|
||||
void AtomExtensionsAPIProvider::AddPermissionFeatures(
|
||||
|
@ -104,14 +103,12 @@ void AtomExtensionsAPIProvider::AddAPIJSONSources(
|
|||
}
|
||||
|
||||
bool AtomExtensionsAPIProvider::IsAPISchemaGenerated(const std::string& name) {
|
||||
// return shell::api::ShellGeneratedSchemas::IsGenerated(name);
|
||||
return false;
|
||||
return extensions::api::ElectronGeneratedSchemas::IsGenerated(name);
|
||||
}
|
||||
|
||||
base::StringPiece AtomExtensionsAPIProvider::GetAPISchema(
|
||||
const std::string& name) {
|
||||
// return shell::api::ShellGeneratedSchemas::Get(name);
|
||||
return "";
|
||||
return extensions::api::ElectronGeneratedSchemas::Get(name);
|
||||
}
|
||||
|
||||
void AtomExtensionsAPIProvider::RegisterPermissions(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue