fix: [extensions] some chrome.extension APIs (#21804)

This commit is contained in:
Jeremy Apthorp 2020-01-20 16:44:09 -08:00 committed by Cheng Zhao
parent ebe8bddc31
commit d802fe0fdd
5 changed files with 55 additions and 1 deletions

View file

@ -233,6 +233,8 @@ static_library("chrome") {
if (enable_electron_extensions) {
sources += [
"//chrome/renderer/extensions/extension_hooks_delegate.cc",
"//chrome/renderer/extensions/extension_hooks_delegate.h",
"//chrome/renderer/extensions/tabs_hooks_delegate.cc",
"//chrome/renderer/extensions/tabs_hooks_delegate.h",
]

View file

@ -34,7 +34,10 @@ group("extensions_features") {
# Private Targets
generated_json_strings("generated_api_json_strings") {
sources = [ "tabs.json" ]
sources = [
"extension.json",
"tabs.json",
]
configs = [ "//build/config:precompiled_headers" ]
bundle_name = "Electron"

View file

@ -3,5 +3,13 @@
"channel": "stable",
"extension_types": ["extension"],
"contexts": ["blessed_extension"]
},
"extension": {
"channel": "stable",
"extension_types": ["extension"],
"contexts": ["blessed_extension"]
},
"extension.getURL": {
"contexts": ["blessed_extension", "unblessed_extension", "content_script"]
}
}

View file

@ -0,0 +1,37 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
{
"namespace": "extension",
"description": "The <code>chrome.extension</code> API has utilities that can be used by any extension page. It includes support for exchanging messages between an extension and its content scripts or between extensions, as described in detail in <a href='messaging'>Message Passing</a>.",
"compiler_options": {
"implemented_in": "chrome/browser/extensions/api/module/module.h"
},
"properties": {
},
"functions": [
{
"name": "getURL",
"deprecated": "Please use $(ref:runtime.getURL).",
"nocompile": true,
"type": "function",
"description": "Converts a relative path within an extension install directory to a fully-qualified URL.",
"parameters": [
{
"type": "string",
"name": "path",
"description": "A path to a resource within an extension expressed relative to its install directory."
}
],
"returns": {
"type": "string",
"description": "The fully-qualified URL to the resource."
}
}
],
"events": [
]
}
]

View file

@ -8,6 +8,7 @@
#include <set>
#include <string>
#include "chrome/renderer/extensions/extension_hooks_delegate.h"
#include "chrome/renderer/extensions/tabs_hooks_delegate.h"
#include "extensions/renderer/bindings/api_bindings_system.h"
#include "extensions/renderer/lazy_background_page_native_handler.h"
@ -45,6 +46,9 @@ void ElectronExtensionsDispatcherDelegate::InitializeBindingsSystem(
extensions::Dispatcher* dispatcher,
extensions::NativeExtensionBindingsSystem* bindings_system) {
extensions::APIBindingsSystem* bindings = bindings_system->api_system();
bindings->GetHooksForAPI("extension")
->SetDelegate(std::make_unique<extensions::ExtensionHooksDelegate>(
bindings_system->messaging_service()));
bindings->GetHooksForAPI("tabs")->SetDelegate(
std::make_unique<extensions::TabsHooksDelegate>(
bindings_system->messaging_service()));