mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
wip
This commit is contained in:
@@ -98,6 +98,7 @@
|
||||
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "shell/browser/extensions/electron_extension_info.h"
|
||||
#include "shell/browser/extensions/electron_extension_system.h"
|
||||
#include "shell/common/gin_converters/extension_converter.h"
|
||||
#endif
|
||||
@@ -1309,7 +1310,7 @@ v8::Local<v8::Promise> Session::GetSharedDictionaryUsageInfo() {
|
||||
v8::Local<v8::Promise> Session::LoadExtension(
|
||||
const base::FilePath& extension_path,
|
||||
gin::Arguments* args) {
|
||||
gin_helper::Promise<const extensions::Extension*> promise(isolate_);
|
||||
gin_helper::Promise<const extensions::ElectronExtensionInfo&> promise(isolate_);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
if (!extension_path.IsAbsolute()) {
|
||||
@@ -1335,22 +1336,23 @@ v8::Local<v8::Promise> Session::LoadExtension(
|
||||
|
||||
auto* extension_system = static_cast<extensions::ElectronExtensionSystem*>(
|
||||
extensions::ExtensionSystem::Get(browser_context()));
|
||||
extension_system->LoadExtension(
|
||||
extension_path, load_flags,
|
||||
extension_system->LoadExtension(extension_path, load_flags,
|
||||
base::BindOnce(
|
||||
[](gin_helper::Promise<const extensions::Extension*> promise,
|
||||
base::WeakPtr<ElectronBrowserContext> browser_context,
|
||||
const extensions::Extension* extension,
|
||||
const std::string& error_msg) {
|
||||
if (extension) {
|
||||
if (extension && browser_context) {
|
||||
if (!error_msg.empty())
|
||||
util::EmitWarning(promise.isolate(), error_msg,
|
||||
"ExtensionLoadWarning");
|
||||
promise.Resolve(extension);
|
||||
auto& info = extensions::ElectronExtensionInfo(extension, browser_context.get());
|
||||
promise.Resolve(info);
|
||||
} else {
|
||||
promise.RejectWithErrorMessage(error_msg);
|
||||
}
|
||||
},
|
||||
std::move(promise)));
|
||||
std::move(promise), browser_context()->GetWeakPtr()));
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,12 @@ namespace net {
|
||||
class ProxyConfig;
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
namespace extensions {
|
||||
class ElectronExtensionSystem;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace electron {
|
||||
|
||||
class ElectronBrowserContext;
|
||||
|
||||
33
shell/browser/extensions/electron_extension_info.h
Normal file
33
shell/browser/extensions/electron_extension_info.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2018 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.
|
||||
|
||||
#ifndef ELECTRON_SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_INFO_H_
|
||||
#define ELECTRON_SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_INFO_H_
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
|
||||
namespace electron {
|
||||
class ElectronBrowserContext;
|
||||
}
|
||||
|
||||
namespace extensions {
|
||||
|
||||
class Extension;
|
||||
|
||||
struct ElectronExtensionInfo {
|
||||
explicit ElectronExtensionInfo(const Extension* extension_in,
|
||||
const electron::ElectronBrowserContext* browser_context_in)
|
||||
: extension(extension_in),
|
||||
browser_context(browser_context_in) {
|
||||
DCHECK(extension_in);
|
||||
DCHECK(browser_context_in);
|
||||
}
|
||||
|
||||
raw_ptr<const Extension> extension;
|
||||
raw_ptr<const electron::ElectronBrowserContext> browser_context;
|
||||
};
|
||||
|
||||
} // namespace extensions
|
||||
|
||||
#endif // ELECTRON_SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_INFO_H_
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/auto_reset.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/functional/bind.h"
|
||||
@@ -17,11 +16,11 @@
|
||||
#include "base/time/time.h"
|
||||
#include "extensions/browser/extension_file_task_runner.h"
|
||||
#include "extensions/browser/extension_prefs.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/pref_names.h"
|
||||
#include "extensions/common/error_utils.h"
|
||||
#include "extensions/common/file_util.h"
|
||||
#include "extensions/common/manifest_constants.h"
|
||||
#include "shell/browser/extensions/electron_extension_system.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
@@ -111,7 +110,7 @@ void ElectronExtensionLoader::FinishExtensionLoad(
|
||||
std::pair<scoped_refptr<const Extension>, std::string> result) {
|
||||
scoped_refptr<const Extension> extension = result.first;
|
||||
if (extension) {
|
||||
extension_system_.AddExtension(extension.get());
|
||||
extension_system_->AddExtension(extension.get());
|
||||
|
||||
// Write extension install time to ExtensionPrefs. This is required by
|
||||
// WebRequestAPI which calls extensions::ExtensionPrefs::GetInstallTime.
|
||||
@@ -139,7 +138,7 @@ void ElectronExtensionLoader::FinishExtensionReload(
|
||||
std::pair<scoped_refptr<const Extension>, std::string> result) {
|
||||
scoped_refptr<const Extension> extension = result.first;
|
||||
if (extension) {
|
||||
extension_system_.AddExtension(extension.get());
|
||||
extension_system_->AddExtension(extension.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
|
||||
#include "shell/common/gin_converters/extension_converter.h"
|
||||
|
||||
|
||||
#include "extensions/common/extension.h"
|
||||
#include "gin/dictionary.h"
|
||||
#include "shell/browser/extensions/electron_extension_info.h"
|
||||
#include "shell/common/gin_converters/file_path_converter.h"
|
||||
#include "shell/common/gin_converters/gurl_converter.h"
|
||||
#include "shell/common/gin_converters/value_converter.h"
|
||||
@@ -13,16 +15,16 @@
|
||||
namespace gin {
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<const extensions::Extension*>::ToV8(
|
||||
v8::Local<v8::Value> Converter<const extensions::ElectronExtensionInfo*>::ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const extensions::Extension* extension) {
|
||||
const extensions::ElectronExtensionInfo& info) {
|
||||
auto dict = gin::Dictionary::CreateEmpty(isolate);
|
||||
dict.Set("id", extension->id());
|
||||
dict.Set("name", extension->name());
|
||||
dict.Set("path", extension->path());
|
||||
dict.Set("url", extension->url());
|
||||
dict.Set("version", extension->VersionString());
|
||||
dict.Set("manifest", *extension->manifest()->value());
|
||||
dict.Set("id", info.extension->id());
|
||||
dict.Set("name", info.extension->name());
|
||||
dict.Set("path", info.extension->path());
|
||||
dict.Set("url", info.extension->url());
|
||||
dict.Set("version", info.extension->VersionString());
|
||||
dict.Set("manifest", *info.extension->manifest()->value());
|
||||
|
||||
return gin::ConvertToV8(isolate, dict);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2019 Slack Technologies, Inc.
|
||||
// Copyright (c) 2025 Salesforce, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
#include "gin/converter.h"
|
||||
|
||||
namespace extensions {
|
||||
class Extension;
|
||||
struct ElectronExtensionInfo;
|
||||
}
|
||||
|
||||
namespace gin {
|
||||
|
||||
template <>
|
||||
struct Converter<const extensions::Extension*> {
|
||||
struct Converter<const extensions::ElectronExtensionInfo> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const extensions::Extension* val);
|
||||
const extensions::ElectronExtensionInfo& val);
|
||||
};
|
||||
|
||||
} // namespace gin
|
||||
|
||||
Reference in New Issue
Block a user