Browse Source

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

Jeremy Apthorp 5 years ago
parent
commit
d802fe0fdd

+ 2 - 0
chromium_src/BUILD.gn

@@ -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",
     ]

+ 4 - 1
shell/common/extensions/api/BUILD.gn

@@ -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"

+ 8 - 0
shell/common/extensions/api/_api_features.json

@@ -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"]
   }
 }

+ 37 - 0
shell/common/extensions/api/extension.json

@@ -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": [
+    ]
+  }
+]

+ 4 - 0
shell/renderer/extensions/electron_extensions_dispatcher_delegate.cc

@@ -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()));