feat: enable native extensions support (#21814)

This commit is contained in:
Jeremy Apthorp 2020-02-03 14:01:10 -08:00 committed by GitHub
parent bdf65a75d0
commit a061c87e56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
61 changed files with 1054 additions and 941 deletions

View file

@ -12,13 +12,13 @@
#include "content/public/browser/child_process_security_policy.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/browser.h"
#include "shell/common/deprecate_util.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/net_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/options_switches.h"
#include "shell/common/process_util.h"
#include "url/url_util.h"
namespace {
@ -217,12 +217,11 @@ bool Protocol::IsProtocolIntercepted(const std::string& scheme) {
v8::Local<v8::Promise> Protocol::IsProtocolHandled(const std::string& scheme,
gin::Arguments* args) {
node::Environment* env = node::Environment::GetCurrent(args->isolate());
EmitDeprecationWarning(
env,
"The protocol.isProtocolHandled API is deprecated, use "
"protocol.isProtocolRegistered or protocol.isProtocolIntercepted "
"instead.",
"ProtocolDeprecateIsProtocolHandled");
EmitWarning(env,
"The protocol.isProtocolHandled API is deprecated, use "
"protocol.isProtocolRegistered or protocol.isProtocolIntercepted "
"instead.",
"ProtocolDeprecateIsProtocolHandled");
return gin_helper::Promise<bool>::ResolvedPromise(
isolate(), IsProtocolRegistered(scheme) ||
IsProtocolIntercepted(scheme) ||
@ -241,7 +240,7 @@ void Protocol::HandleOptionalCallback(gin::Arguments* args,
CompletionCallback callback;
if (args->GetNext(&callback)) {
node::Environment* env = node::Environment::GetCurrent(args->isolate());
EmitDeprecationWarning(
EmitWarning(
env,
"The callback argument of protocol module APIs is no longer needed.",
"ProtocolDeprecateCallback");

View file

@ -63,11 +63,12 @@
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
#include "shell/common/process_util.h"
#include "ui/base/l10n/l10n_util.h"
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
#include "extensions/browser/extension_registry.h"
#include "shell/browser/extensions/atom_extension_system.h"
#include "shell/browser/extensions/electron_extension_system.h"
#include "shell/common/gin_converters/extension_converter.h"
#endif
@ -613,19 +614,23 @@ v8::Local<v8::Promise> Session::LoadExtension(
gin_helper::Promise<const extensions::Extension*> promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
auto* extension_system = static_cast<extensions::AtomExtensionSystem*>(
auto* extension_system = static_cast<extensions::ElectronExtensionSystem*>(
extensions::ExtensionSystem::Get(browser_context()));
extension_system->LoadExtension(
extension_path,
base::BindOnce(
[](gin_helper::Promise<const extensions::Extension*> promise,
const extensions::Extension* extension) {
const extensions::Extension* extension,
const std::string& error_msg) {
if (extension) {
if (!error_msg.empty()) {
node::Environment* env =
node::Environment::GetCurrent(v8::Isolate::GetCurrent());
EmitWarning(env, error_msg, "ExtensionLoadWarning");
}
promise.Resolve(extension);
} else {
// TODO(nornagon): plumb through error message from extension
// loader.
promise.RejectWithErrorMessage("Failed to load extension");
promise.RejectWithErrorMessage(error_msg);
}
},
std::move(promise)));
@ -634,7 +639,7 @@ v8::Local<v8::Promise> Session::LoadExtension(
}
void Session::RemoveExtension(const std::string& extension_id) {
auto* extension_system = static_cast<extensions::AtomExtensionSystem*>(
auto* extension_system = static_cast<extensions::ElectronExtensionSystem*>(
extensions::ExtensionSystem::Get(browser_context()));
extension_system->RemoveExtension(extension_id);
}

View file

@ -26,9 +26,9 @@
#include "shell/browser/mac/atom_application.h"
#include "shell/browser/mac/dict_util.h"
#include "shell/browser/ui/cocoa/NSColor+Hex.h"
#include "shell/common/deprecate_util.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/value_converter.h"
#include "shell/common/process_util.h"
#include "ui/native_theme/native_theme.h"
namespace gin {
@ -504,7 +504,7 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
NSColor* sysColor = nil;
if (color == "alternate-selected-control-text") {
sysColor = [NSColor alternateSelectedControlTextColor];
EmitDeprecationWarning(
EmitWarning(
node::Environment::GetCurrent(thrower.isolate()),
"'alternate-selected-control-text' is deprecated as an input to "
"getColor. Use 'selected-content-background' instead.",

View file

@ -114,7 +114,7 @@
#endif
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
#include "shell/browser/extensions/atom_extension_web_contents_observer.h"
#include "shell/browser/extensions/electron_extension_web_contents_observer.h"
#endif
namespace gin {
@ -385,7 +385,7 @@ WebContents::WebContents(v8::Isolate* isolate,
AttachAsUserData(web_contents);
InitZoomController(web_contents, gin::Dictionary::CreateEmpty(isolate));
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
extensions::AtomExtensionWebContentsObserver::CreateForWebContents(
extensions::ElectronExtensionWebContentsObserver::CreateForWebContents(
web_contents);
script_executor_.reset(new extensions::ScriptExecutor(web_contents));
#endif
@ -546,7 +546,7 @@ void WebContents::InitWithSessionAndOptions(
SecurityStateTabHelper::CreateForWebContents(web_contents());
InitZoomController(web_contents(), options);
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
extensions::AtomExtensionWebContentsObserver::CreateForWebContents(
extensions::ElectronExtensionWebContentsObserver::CreateForWebContents(
web_contents());
script_executor_.reset(new extensions::ScriptExecutor(web_contents()));
#endif