mirror of
https://github.com/electron/electron.git
synced 2026-02-26 03:01:17 -05:00
Compare commits
7 Commits
roller/nod
...
feat/toggl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2551c8f89a | ||
|
|
663fd64451 | ||
|
|
4d7cb66db4 | ||
|
|
22d4e1f916 | ||
|
|
0c825b08b6 | ||
|
|
0da62a6dd5 | ||
|
|
478b4a3c30 |
@@ -1541,6 +1541,25 @@ Unloads an extension.
|
|||||||
**Note:** This API cannot be called before the `ready` event of the `app` module
|
**Note:** This API cannot be called before the `ready` event of the `app` module
|
||||||
is emitted.
|
is emitted.
|
||||||
|
|
||||||
|
#### `ses.enableExtension(extensionId)`
|
||||||
|
|
||||||
|
* `extensionId` string - ID of extension to enable
|
||||||
|
|
||||||
|
Enables the extension and activates it for use by starting any background
|
||||||
|
workers. If the extension is disabled, marks it as enabled.
|
||||||
|
|
||||||
|
**Note:** This API cannot be called before the `ready` event of the `app` module
|
||||||
|
is emitted.
|
||||||
|
|
||||||
|
#### `ses.disableExtension(extensionId)`
|
||||||
|
|
||||||
|
* `extensionId` string - ID of extension to disable
|
||||||
|
|
||||||
|
Disables the extension and deactives it.
|
||||||
|
|
||||||
|
**Note:** This API cannot be called before the `ready` event of the `app` module
|
||||||
|
is emitted.
|
||||||
|
|
||||||
#### `ses.getExtension(extensionId)`
|
#### `ses.getExtension(extensionId)`
|
||||||
|
|
||||||
* `extensionId` string - ID of extension to query
|
* `extensionId` string - ID of extension to query
|
||||||
|
|||||||
@@ -763,6 +763,8 @@ filenames = {
|
|||||||
"shell/browser/extensions/electron_extension_host_delegate.h",
|
"shell/browser/extensions/electron_extension_host_delegate.h",
|
||||||
"shell/browser/extensions/electron_extension_loader.cc",
|
"shell/browser/extensions/electron_extension_loader.cc",
|
||||||
"shell/browser/extensions/electron_extension_loader.h",
|
"shell/browser/extensions/electron_extension_loader.h",
|
||||||
|
"shell/browser/extensions/electron_extension_registrar_delegate.cc",
|
||||||
|
"shell/browser/extensions/electron_extension_registrar_delegate.h",
|
||||||
"shell/browser/extensions/electron_extension_system_factory.cc",
|
"shell/browser/extensions/electron_extension_system_factory.cc",
|
||||||
"shell/browser/extensions/electron_extension_system_factory.h",
|
"shell/browser/extensions/electron_extension_system_factory.h",
|
||||||
"shell/browser/extensions/electron_extension_system.cc",
|
"shell/browser/extensions/electron_extension_system.cc",
|
||||||
|
|||||||
@@ -98,6 +98,7 @@
|
|||||||
|
|
||||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||||
#include "extensions/browser/extension_registry.h"
|
#include "extensions/browser/extension_registry.h"
|
||||||
|
#include "shell/browser/extensions/electron_extension_info.h"
|
||||||
#include "shell/browser/extensions/electron_extension_system.h"
|
#include "shell/browser/extensions/electron_extension_system.h"
|
||||||
#include "shell/common/gin_converters/extension_converter.h"
|
#include "shell/common/gin_converters/extension_converter.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -1309,7 +1310,8 @@ v8::Local<v8::Promise> Session::GetSharedDictionaryUsageInfo() {
|
|||||||
v8::Local<v8::Promise> Session::LoadExtension(
|
v8::Local<v8::Promise> Session::LoadExtension(
|
||||||
const base::FilePath& extension_path,
|
const base::FilePath& extension_path,
|
||||||
gin::Arguments* args) {
|
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();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
if (!extension_path.IsAbsolute()) {
|
if (!extension_path.IsAbsolute()) {
|
||||||
@@ -1338,27 +1340,37 @@ v8::Local<v8::Promise> Session::LoadExtension(
|
|||||||
extension_system->LoadExtension(
|
extension_system->LoadExtension(
|
||||||
extension_path, load_flags,
|
extension_path, load_flags,
|
||||||
base::BindOnce(
|
base::BindOnce(
|
||||||
[](gin_helper::Promise<const extensions::Extension*> promise,
|
[](gin_helper::Promise<const extensions::ElectronExtensionInfo&>
|
||||||
|
promise,
|
||||||
|
base::WeakPtr<ElectronBrowserContext> browser_context,
|
||||||
const extensions::Extension* extension,
|
const extensions::Extension* extension,
|
||||||
const std::string& error_msg) {
|
const std::string& error_msg) {
|
||||||
if (extension) {
|
if (extension && browser_context) {
|
||||||
if (!error_msg.empty())
|
if (!error_msg.empty())
|
||||||
util::EmitWarning(promise.isolate(), error_msg,
|
util::EmitWarning(promise.isolate(), error_msg,
|
||||||
"ExtensionLoadWarning");
|
"ExtensionLoadWarning");
|
||||||
promise.Resolve(extension);
|
const auto& extension_info = extensions::ElectronExtensionInfo(
|
||||||
|
extension, browser_context.get());
|
||||||
|
promise.Resolve(extension_info);
|
||||||
} else {
|
} else {
|
||||||
promise.RejectWithErrorMessage(error_msg);
|
promise.RejectWithErrorMessage(error_msg);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
std::move(promise)));
|
std::move(promise), browser_context()->GetWeakPtr()));
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::RemoveExtension(const std::string& extension_id) {
|
void Session::RemoveExtension(const std::string& extension_id) {
|
||||||
auto* extension_system = static_cast<extensions::ElectronExtensionSystem*>(
|
browser_context()->extension_system()->RemoveExtension(extension_id);
|
||||||
extensions::ExtensionSystem::Get(browser_context()));
|
}
|
||||||
extension_system->RemoveExtension(extension_id);
|
|
||||||
|
void Session::EnableExtension(const std::string& extension_id) {
|
||||||
|
browser_context()->extension_system()->EnableExtension(extension_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Session::DisableExtension(const std::string& extension_id) {
|
||||||
|
browser_context()->extension_system()->DisableExtension(extension_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> Session::GetExtension(const std::string& extension_id) {
|
v8::Local<v8::Value> Session::GetExtension(const std::string& extension_id) {
|
||||||
@@ -1366,7 +1378,9 @@ v8::Local<v8::Value> Session::GetExtension(const std::string& extension_id) {
|
|||||||
const extensions::Extension* extension =
|
const extensions::Extension* extension =
|
||||||
registry->GetInstalledExtension(extension_id);
|
registry->GetInstalledExtension(extension_id);
|
||||||
if (extension) {
|
if (extension) {
|
||||||
return gin::ConvertToV8(isolate_, extension);
|
const auto& extension_info =
|
||||||
|
extensions::ElectronExtensionInfo(extension, browser_context());
|
||||||
|
return gin::ConvertToV8(isolate_, extension_info);
|
||||||
} else {
|
} else {
|
||||||
return v8::Null(isolate_);
|
return v8::Null(isolate_);
|
||||||
}
|
}
|
||||||
@@ -1376,29 +1390,40 @@ v8::Local<v8::Value> Session::GetAllExtensions() {
|
|||||||
auto* registry = extensions::ExtensionRegistry::Get(browser_context());
|
auto* registry = extensions::ExtensionRegistry::Get(browser_context());
|
||||||
const extensions::ExtensionSet extensions =
|
const extensions::ExtensionSet extensions =
|
||||||
registry->GenerateInstalledExtensionsSet();
|
registry->GenerateInstalledExtensionsSet();
|
||||||
std::vector<const extensions::Extension*> extensions_vector;
|
std::vector<extensions::ElectronExtensionInfo> extensions_vector;
|
||||||
for (const auto& extension : extensions) {
|
for (const auto& extension : extensions) {
|
||||||
if (extension->location() !=
|
if (extension->location() !=
|
||||||
extensions::mojom::ManifestLocation::kComponent)
|
extensions::mojom::ManifestLocation::kComponent) {
|
||||||
extensions_vector.emplace_back(extension.get());
|
const auto& extension_info =
|
||||||
|
extensions::ElectronExtensionInfo(extension.get(), browser_context());
|
||||||
|
extensions_vector.emplace_back(extension_info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return gin::ConvertToV8(isolate_, extensions_vector);
|
return gin::ConvertToV8(isolate_, extensions_vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::OnExtensionLoaded(content::BrowserContext* browser_context,
|
void Session::OnExtensionLoaded(
|
||||||
const extensions::Extension* extension) {
|
content::BrowserContext* content_browser_context,
|
||||||
Emit("extension-loaded", extension);
|
const extensions::Extension* extension) {
|
||||||
|
const auto& extension_info =
|
||||||
|
extensions::ElectronExtensionInfo(extension, browser_context());
|
||||||
|
Emit("extension-loaded", extension_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::OnExtensionUnloaded(content::BrowserContext* browser_context,
|
void Session::OnExtensionUnloaded(
|
||||||
const extensions::Extension* extension,
|
content::BrowserContext* content_browser_context,
|
||||||
extensions::UnloadedExtensionReason reason) {
|
const extensions::Extension* extension,
|
||||||
Emit("extension-unloaded", extension);
|
extensions::UnloadedExtensionReason reason) {
|
||||||
|
const auto& extension_info =
|
||||||
|
extensions::ElectronExtensionInfo(extension, browser_context());
|
||||||
|
Emit("extension-unloaded", extension_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::OnExtensionReady(content::BrowserContext* browser_context,
|
void Session::OnExtensionReady(content::BrowserContext* content_browser_context,
|
||||||
const extensions::Extension* extension) {
|
const extensions::Extension* extension) {
|
||||||
Emit("extension-ready", extension);
|
const auto& extension_info =
|
||||||
|
extensions::ElectronExtensionInfo(extension, browser_context());
|
||||||
|
Emit("extension-ready", extension_info);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1875,6 +1900,8 @@ void Session::FillObjectTemplate(v8::Isolate* isolate,
|
|||||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||||
.SetMethod("loadExtension", &Session::LoadExtension)
|
.SetMethod("loadExtension", &Session::LoadExtension)
|
||||||
.SetMethod("removeExtension", &Session::RemoveExtension)
|
.SetMethod("removeExtension", &Session::RemoveExtension)
|
||||||
|
.SetMethod("enableExtension", &Session::EnableExtension)
|
||||||
|
.SetMethod("disableExtension", &Session::DisableExtension)
|
||||||
.SetMethod("getExtension", &Session::GetExtension)
|
.SetMethod("getExtension", &Session::GetExtension)
|
||||||
.SetMethod("getAllExtensions", &Session::GetAllExtensions)
|
.SetMethod("getAllExtensions", &Session::GetAllExtensions)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ namespace net {
|
|||||||
class ProxyConfig;
|
class ProxyConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||||
|
namespace extensions {
|
||||||
|
class ElectronExtensionSystem;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
class ElectronBrowserContext;
|
class ElectronBrowserContext;
|
||||||
@@ -182,6 +188,8 @@ class Session final : public gin::Wrappable<Session>,
|
|||||||
v8::Local<v8::Promise> LoadExtension(const base::FilePath& extension_path,
|
v8::Local<v8::Promise> LoadExtension(const base::FilePath& extension_path,
|
||||||
gin::Arguments* args);
|
gin::Arguments* args);
|
||||||
void RemoveExtension(const std::string& extension_id);
|
void RemoveExtension(const std::string& extension_id);
|
||||||
|
void EnableExtension(const std::string& extension_id);
|
||||||
|
void DisableExtension(const std::string& extension_id);
|
||||||
v8::Local<v8::Value> GetExtension(const std::string& extension_id);
|
v8::Local<v8::Value> GetExtension(const std::string& extension_id);
|
||||||
v8::Local<v8::Value> GetAllExtensions();
|
v8::Local<v8::Value> GetAllExtensions();
|
||||||
|
|
||||||
|
|||||||
@@ -155,10 +155,7 @@ class ElectronBrowserContext : public content::BrowserContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||||
extensions::ElectronExtensionSystem* extension_system() {
|
extensions::ElectronExtensionSystem* extension_system() const {
|
||||||
// Guard usages of extension_system() with !IsOffTheRecord()
|
|
||||||
// There is no extension system for in-memory sessions
|
|
||||||
DCHECK(!IsOffTheRecord());
|
|
||||||
return extension_system_;
|
return extension_system_;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
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 <utility>
|
||||||
|
|
||||||
#include "base/auto_reset.h"
|
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "base/files/file_util.h"
|
#include "base/files/file_util.h"
|
||||||
#include "base/functional/bind.h"
|
#include "base/functional/bind.h"
|
||||||
@@ -17,16 +16,14 @@
|
|||||||
#include "base/time/time.h"
|
#include "base/time/time.h"
|
||||||
#include "extensions/browser/extension_file_task_runner.h"
|
#include "extensions/browser/extension_file_task_runner.h"
|
||||||
#include "extensions/browser/extension_prefs.h"
|
#include "extensions/browser/extension_prefs.h"
|
||||||
#include "extensions/browser/extension_registry.h"
|
|
||||||
#include "extensions/browser/pref_names.h"
|
#include "extensions/browser/pref_names.h"
|
||||||
#include "extensions/common/error_utils.h"
|
#include "extensions/common/error_utils.h"
|
||||||
#include "extensions/common/file_util.h"
|
#include "extensions/common/file_util.h"
|
||||||
#include "extensions/common/manifest_constants.h"
|
#include "extensions/common/manifest_constants.h"
|
||||||
|
#include "shell/browser/extensions/electron_extension_system.h"
|
||||||
|
|
||||||
namespace extensions {
|
namespace extensions {
|
||||||
|
|
||||||
using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::pair<scoped_refptr<const Extension>, std::string> LoadUnpacked(
|
std::pair<scoped_refptr<const Extension>, std::string> LoadUnpacked(
|
||||||
@@ -92,9 +89,9 @@ std::pair<scoped_refptr<const Extension>, std::string> LoadUnpacked(
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ElectronExtensionLoader::ElectronExtensionLoader(
|
ElectronExtensionLoader::ElectronExtensionLoader(
|
||||||
content::BrowserContext* browser_context)
|
content::BrowserContext* browser_context,
|
||||||
: browser_context_(browser_context),
|
ElectronExtensionSystem* extension_system)
|
||||||
extension_registrar_(browser_context, this) {}
|
: browser_context_(browser_context), extension_system_(extension_system) {}
|
||||||
|
|
||||||
ElectronExtensionLoader::~ElectronExtensionLoader() = default;
|
ElectronExtensionLoader::~ElectronExtensionLoader() = default;
|
||||||
|
|
||||||
@@ -108,34 +105,12 @@ void ElectronExtensionLoader::LoadExtension(
|
|||||||
weak_factory_.GetWeakPtr(), std::move(cb)));
|
weak_factory_.GetWeakPtr(), std::move(cb)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronExtensionLoader::ReloadExtension(const ExtensionId& extension_id) {
|
|
||||||
const Extension* extension = ExtensionRegistry::Get(browser_context_)
|
|
||||||
->GetInstalledExtension(extension_id);
|
|
||||||
// We shouldn't be trying to reload extensions that haven't been added.
|
|
||||||
DCHECK(extension);
|
|
||||||
|
|
||||||
// This should always start false since it's only set here, or in
|
|
||||||
// LoadExtensionForReload() as a result of the call below.
|
|
||||||
DCHECK_EQ(false, did_schedule_reload_);
|
|
||||||
base::AutoReset<bool> reset_did_schedule_reload(&did_schedule_reload_, false);
|
|
||||||
|
|
||||||
extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kQuiet);
|
|
||||||
if (did_schedule_reload_)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronExtensionLoader::UnloadExtension(
|
|
||||||
const ExtensionId& extension_id,
|
|
||||||
extensions::UnloadedExtensionReason reason) {
|
|
||||||
extension_registrar_.RemoveExtension(extension_id, reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronExtensionLoader::FinishExtensionLoad(
|
void ElectronExtensionLoader::FinishExtensionLoad(
|
||||||
base::OnceCallback<void(const Extension*, const std::string&)> cb,
|
base::OnceCallback<void(const Extension*, const std::string&)> cb,
|
||||||
std::pair<scoped_refptr<const Extension>, std::string> result) {
|
std::pair<scoped_refptr<const Extension>, std::string> result) {
|
||||||
scoped_refptr<const Extension> extension = result.first;
|
scoped_refptr<const Extension> extension = result.first;
|
||||||
if (extension) {
|
if (extension) {
|
||||||
extension_registrar_.AddExtension(extension);
|
extension_system_->AddExtension(extension.get());
|
||||||
|
|
||||||
// Write extension install time to ExtensionPrefs. This is required by
|
// Write extension install time to ExtensionPrefs. This is required by
|
||||||
// WebRequestAPI which calls extensions::ExtensionPrefs::GetInstallTime.
|
// WebRequestAPI which calls extensions::ExtensionPrefs::GetInstallTime.
|
||||||
@@ -158,90 +133,4 @@ void ElectronExtensionLoader::FinishExtensionLoad(
|
|||||||
std::move(cb).Run(extension.get(), result.second);
|
std::move(cb).Run(extension.get(), result.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronExtensionLoader::FinishExtensionReload(
|
|
||||||
const ExtensionId& old_extension_id,
|
|
||||||
std::pair<scoped_refptr<const Extension>, std::string> result) {
|
|
||||||
scoped_refptr<const Extension> extension = result.first;
|
|
||||||
if (extension) {
|
|
||||||
extension_registrar_.AddExtension(extension);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronExtensionLoader::PreAddExtension(const Extension* extension,
|
|
||||||
const Extension* old_extension) {
|
|
||||||
if (old_extension)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// The extension might be disabled if a previous reload attempt failed. In
|
|
||||||
// that case, we want to remove that disable reason.
|
|
||||||
ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(browser_context_);
|
|
||||||
if (extension_prefs->IsExtensionDisabled(extension->id()) &&
|
|
||||||
extension_prefs->HasDisableReason(extension->id(),
|
|
||||||
disable_reason::DISABLE_RELOAD)) {
|
|
||||||
extension_prefs->RemoveDisableReason(extension->id(),
|
|
||||||
disable_reason::DISABLE_RELOAD);
|
|
||||||
// Only re-enable the extension if there are no other disable reasons.
|
|
||||||
if (extension_prefs->GetDisableReasons(extension->id()) ==
|
|
||||||
disable_reason::DISABLE_NONE) {
|
|
||||||
extension_prefs->SetExtensionEnabled(extension->id());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronExtensionLoader::PostActivateExtension(
|
|
||||||
scoped_refptr<const Extension> extension) {}
|
|
||||||
|
|
||||||
void ElectronExtensionLoader::PostDeactivateExtension(
|
|
||||||
scoped_refptr<const Extension> extension) {}
|
|
||||||
|
|
||||||
void ElectronExtensionLoader::PreUninstallExtension(
|
|
||||||
scoped_refptr<const Extension> extension) {}
|
|
||||||
|
|
||||||
void ElectronExtensionLoader::PostUninstallExtension(
|
|
||||||
scoped_refptr<const Extension> extension,
|
|
||||||
base::OnceClosure done_callback) {}
|
|
||||||
|
|
||||||
void ElectronExtensionLoader::PostNotifyUninstallExtension(
|
|
||||||
scoped_refptr<const Extension> extension) {}
|
|
||||||
|
|
||||||
void ElectronExtensionLoader::LoadExtensionForReload(
|
|
||||||
const ExtensionId& extension_id,
|
|
||||||
const base::FilePath& path,
|
|
||||||
LoadErrorBehavior load_error_behavior) {
|
|
||||||
CHECK(!path.empty());
|
|
||||||
|
|
||||||
// TODO(nornagon): we should save whether file access was granted
|
|
||||||
// when loading this extension and retain it here. As is, reloading an
|
|
||||||
// extension will cause the file access permission to be dropped.
|
|
||||||
int load_flags = Extension::FOLLOW_SYMLINKS_ANYWHERE;
|
|
||||||
GetExtensionFileTaskRunner()->PostTaskAndReplyWithResult(
|
|
||||||
FROM_HERE, base::BindOnce(&LoadUnpacked, path, load_flags),
|
|
||||||
base::BindOnce(&ElectronExtensionLoader::FinishExtensionReload,
|
|
||||||
weak_factory_.GetWeakPtr(), extension_id));
|
|
||||||
did_schedule_reload_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ElectronExtensionLoader::ShowExtensionDisabledError(
|
|
||||||
const Extension* extension,
|
|
||||||
bool is_remote_install) {}
|
|
||||||
|
|
||||||
void ElectronExtensionLoader::FinishDelayedInstallationsIfAny() {}
|
|
||||||
|
|
||||||
bool ElectronExtensionLoader::CanAddExtension(const Extension* extension) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ElectronExtensionLoader::CanEnableExtension(const Extension* extension) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ElectronExtensionLoader::CanDisableExtension(const Extension* extension) {
|
|
||||||
// Extensions cannot be disabled by the user.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ElectronExtensionLoader::ShouldBlockExtension(const Extension* extension) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace extensions
|
} // namespace extensions
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include "base/functional/callback.h"
|
#include "base/functional/callback.h"
|
||||||
#include "base/memory/raw_ptr.h"
|
#include "base/memory/raw_ptr.h"
|
||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "extensions/browser/extension_registrar.h"
|
|
||||||
#include "extensions/common/extension_id.h"
|
#include "extensions/common/extension_id.h"
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
@@ -25,12 +24,14 @@ class BrowserContext;
|
|||||||
namespace extensions {
|
namespace extensions {
|
||||||
|
|
||||||
class Extension;
|
class Extension;
|
||||||
|
class ElectronExtensionSystem;
|
||||||
|
|
||||||
// Handles extension loading and reloading using ExtensionRegistrar.
|
// Handles extension loading.
|
||||||
class ElectronExtensionLoader : public ExtensionRegistrar::Delegate {
|
class ElectronExtensionLoader {
|
||||||
public:
|
public:
|
||||||
explicit ElectronExtensionLoader(content::BrowserContext* browser_context);
|
explicit ElectronExtensionLoader(content::BrowserContext* browser_context,
|
||||||
~ElectronExtensionLoader() override;
|
ElectronExtensionSystem* extension_system);
|
||||||
|
~ElectronExtensionLoader();
|
||||||
|
|
||||||
// disable copy
|
// disable copy
|
||||||
ElectronExtensionLoader(const ElectronExtensionLoader&) = delete;
|
ElectronExtensionLoader(const ElectronExtensionLoader&) = delete;
|
||||||
@@ -43,64 +44,13 @@ class ElectronExtensionLoader : public ExtensionRegistrar::Delegate {
|
|||||||
base::OnceCallback<void(const Extension* extension,
|
base::OnceCallback<void(const Extension* extension,
|
||||||
const std::string&)> cb);
|
const std::string&)> cb);
|
||||||
|
|
||||||
// Starts reloading the extension. A keep-alive is maintained until the
|
|
||||||
// reload succeeds/fails. If the extension is an app, it will be launched upon
|
|
||||||
// reloading.
|
|
||||||
// This may invalidate references to the old Extension object, so it takes the
|
|
||||||
// ID by value.
|
|
||||||
void ReloadExtension(const ExtensionId& extension_id);
|
|
||||||
|
|
||||||
void UnloadExtension(const ExtensionId& extension_id,
|
|
||||||
extensions::UnloadedExtensionReason reason);
|
|
||||||
|
|
||||||
ExtensionRegistrar* registrar() { return &extension_registrar_; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// If the extension loaded successfully, enables it. If it's an app, launches
|
|
||||||
// it. If the load failed, updates ShellKeepAliveRequester.
|
|
||||||
void FinishExtensionReload(
|
|
||||||
const ExtensionId& old_extension_id,
|
|
||||||
std::pair<scoped_refptr<const Extension>, std::string> result);
|
|
||||||
|
|
||||||
void FinishExtensionLoad(
|
void FinishExtensionLoad(
|
||||||
base::OnceCallback<void(const Extension*, const std::string&)> cb,
|
base::OnceCallback<void(const Extension*, const std::string&)> cb,
|
||||||
std::pair<scoped_refptr<const Extension>, std::string> result);
|
std::pair<scoped_refptr<const Extension>, std::string> result);
|
||||||
|
|
||||||
// ExtensionRegistrar::Delegate:
|
raw_ptr<content::BrowserContext> browser_context_; // Not owned.
|
||||||
void PreAddExtension(const Extension* extension,
|
raw_ptr<ElectronExtensionSystem> extension_system_; // Not owned.
|
||||||
const Extension* old_extension) override;
|
|
||||||
void PostActivateExtension(scoped_refptr<const Extension> extension) override;
|
|
||||||
void PostDeactivateExtension(
|
|
||||||
scoped_refptr<const Extension> extension) override;
|
|
||||||
void PreUninstallExtension(scoped_refptr<const Extension> extension) override;
|
|
||||||
void PostUninstallExtension(scoped_refptr<const Extension> extension,
|
|
||||||
base::OnceClosure done_callback) override;
|
|
||||||
void PostNotifyUninstallExtension(
|
|
||||||
scoped_refptr<const Extension> extension) override;
|
|
||||||
void LoadExtensionForReload(
|
|
||||||
const ExtensionId& extension_id,
|
|
||||||
const base::FilePath& path,
|
|
||||||
ExtensionRegistrar::LoadErrorBehavior load_error_behavior) override;
|
|
||||||
void ShowExtensionDisabledError(const Extension* extension,
|
|
||||||
bool is_remote_install) override;
|
|
||||||
void FinishDelayedInstallationsIfAny() override;
|
|
||||||
bool CanAddExtension(const Extension* extension) override;
|
|
||||||
bool CanEnableExtension(const Extension* extension) override;
|
|
||||||
bool CanDisableExtension(const Extension* extension) override;
|
|
||||||
bool ShouldBlockExtension(const Extension* extension) override;
|
|
||||||
|
|
||||||
raw_ptr<content::BrowserContext> browser_context_; // Not owned.
|
|
||||||
|
|
||||||
// Registers and unregisters extensions.
|
|
||||||
ExtensionRegistrar extension_registrar_;
|
|
||||||
|
|
||||||
// Holds keep-alives for relaunching apps.
|
|
||||||
// ShellKeepAliveRequester keep_alive_requester_;
|
|
||||||
|
|
||||||
// Indicates that we posted the (asynchronous) task to start reloading.
|
|
||||||
// Used by ReloadExtension() to check whether ExtensionRegistrar calls
|
|
||||||
// LoadExtensionForReload().
|
|
||||||
bool did_schedule_reload_ = false;
|
|
||||||
|
|
||||||
base::WeakPtrFactory<ElectronExtensionLoader> weak_factory_{this};
|
base::WeakPtrFactory<ElectronExtensionLoader> weak_factory_{this};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,127 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#include "shell/browser/extensions/electron_extension_registrar_delegate.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "base/auto_reset.h"
|
||||||
|
#include "base/files/file_path.h"
|
||||||
|
#include "base/files/file_util.h"
|
||||||
|
#include "base/functional/bind.h"
|
||||||
|
#include "base/logging.h"
|
||||||
|
#include "base/strings/utf_string_conversions.h"
|
||||||
|
#include "base/task/sequenced_task_runner.h"
|
||||||
|
#include "base/threading/thread_restrictions.h"
|
||||||
|
#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 {
|
||||||
|
|
||||||
|
using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior;
|
||||||
|
|
||||||
|
ElectronExtensionRegistrarDelegate::ElectronExtensionRegistrarDelegate(
|
||||||
|
content::BrowserContext* browser_context,
|
||||||
|
ElectronExtensionSystem* extension_system)
|
||||||
|
: browser_context_(browser_context), extension_system_(extension_system) {}
|
||||||
|
|
||||||
|
ElectronExtensionRegistrarDelegate::~ElectronExtensionRegistrarDelegate() =
|
||||||
|
default;
|
||||||
|
|
||||||
|
void ElectronExtensionRegistrarDelegate::PreAddExtension(
|
||||||
|
const Extension* extension,
|
||||||
|
const Extension* old_extension) {
|
||||||
|
if (old_extension)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// The extension might be disabled if a previous reload attempt failed. In
|
||||||
|
// that case, we want to remove that disable reason.
|
||||||
|
ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(browser_context_);
|
||||||
|
if (extension_prefs->IsExtensionDisabled(extension->id()) &&
|
||||||
|
extension_prefs->HasDisableReason(extension->id(),
|
||||||
|
disable_reason::DISABLE_RELOAD)) {
|
||||||
|
extension_prefs->RemoveDisableReason(extension->id(),
|
||||||
|
disable_reason::DISABLE_RELOAD);
|
||||||
|
// Only re-enable the extension if there are no other disable reasons.
|
||||||
|
if (extension_prefs->GetDisableReasons(extension->id()) ==
|
||||||
|
disable_reason::DISABLE_NONE) {
|
||||||
|
extension_prefs->SetExtensionEnabled(extension->id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronExtensionRegistrarDelegate::PostActivateExtension(
|
||||||
|
scoped_refptr<const Extension> extension) {}
|
||||||
|
|
||||||
|
void ElectronExtensionRegistrarDelegate::PostDeactivateExtension(
|
||||||
|
scoped_refptr<const Extension> extension) {}
|
||||||
|
|
||||||
|
void ElectronExtensionRegistrarDelegate::PreUninstallExtension(
|
||||||
|
scoped_refptr<const Extension> extension) {}
|
||||||
|
|
||||||
|
void ElectronExtensionRegistrarDelegate::PostUninstallExtension(
|
||||||
|
scoped_refptr<const Extension> extension,
|
||||||
|
base::OnceClosure done_callback) {}
|
||||||
|
|
||||||
|
void ElectronExtensionRegistrarDelegate::PostNotifyUninstallExtension(
|
||||||
|
scoped_refptr<const Extension> extension) {}
|
||||||
|
|
||||||
|
void ElectronExtensionRegistrarDelegate::LoadExtensionForReload(
|
||||||
|
const ExtensionId& extension_id,
|
||||||
|
const base::FilePath& path,
|
||||||
|
LoadErrorBehavior load_error_behavior) {
|
||||||
|
CHECK(!path.empty());
|
||||||
|
|
||||||
|
// TODO(nornagon): we should save whether file access was granted
|
||||||
|
// when loading this extension and retain it here. As is, reloading an
|
||||||
|
// extension will cause the file access permission to be dropped.
|
||||||
|
int load_flags = Extension::FOLLOW_SYMLINKS_ANYWHERE;
|
||||||
|
extension_system_->LoadExtension(
|
||||||
|
path, load_flags,
|
||||||
|
base::BindOnce(&ElectronExtensionRegistrarDelegate::FinishExtensionReload,
|
||||||
|
weak_factory_.GetWeakPtr()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronExtensionRegistrarDelegate::FinishExtensionReload(
|
||||||
|
const Extension* extension,
|
||||||
|
const ExtensionId& extension_id) {
|
||||||
|
if (extension) {
|
||||||
|
extension_system_->AddExtension(extension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronExtensionRegistrarDelegate::ShowExtensionDisabledError(
|
||||||
|
const Extension* extension,
|
||||||
|
bool is_remote_install) {}
|
||||||
|
|
||||||
|
void ElectronExtensionRegistrarDelegate::FinishDelayedInstallationsIfAny() {}
|
||||||
|
|
||||||
|
bool ElectronExtensionRegistrarDelegate::CanAddExtension(
|
||||||
|
const Extension* extension) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ElectronExtensionRegistrarDelegate::CanEnableExtension(
|
||||||
|
const Extension* extension) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ElectronExtensionRegistrarDelegate::CanDisableExtension(
|
||||||
|
const Extension* extension) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ElectronExtensionRegistrarDelegate::ShouldBlockExtension(
|
||||||
|
const Extension* extension) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace extensions
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
// 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_REGISTRAR_DELEGATE_H_
|
||||||
|
#define ELECTRON_SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_REGISTRAR_DELEGATE_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "base/functional/callback.h"
|
||||||
|
#include "base/memory/raw_ptr.h"
|
||||||
|
#include "base/memory/weak_ptr.h"
|
||||||
|
#include "extensions/browser/extension_registrar.h"
|
||||||
|
#include "extensions/common/extension_id.h"
|
||||||
|
|
||||||
|
namespace base {
|
||||||
|
class FilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace content {
|
||||||
|
class BrowserContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace extensions {
|
||||||
|
|
||||||
|
class Extension;
|
||||||
|
class ElectronExtensionSystem;
|
||||||
|
|
||||||
|
// Handles extension loading and reloading using ExtensionRegistrar.
|
||||||
|
class ElectronExtensionRegistrarDelegate : public ExtensionRegistrar::Delegate {
|
||||||
|
public:
|
||||||
|
explicit ElectronExtensionRegistrarDelegate(
|
||||||
|
content::BrowserContext* browser_context,
|
||||||
|
ElectronExtensionSystem* extension_system);
|
||||||
|
~ElectronExtensionRegistrarDelegate() override;
|
||||||
|
|
||||||
|
// disable copy
|
||||||
|
ElectronExtensionRegistrarDelegate(
|
||||||
|
const ElectronExtensionRegistrarDelegate&) = delete;
|
||||||
|
ElectronExtensionRegistrarDelegate& operator=(
|
||||||
|
const ElectronExtensionRegistrarDelegate&) = delete;
|
||||||
|
|
||||||
|
void set_extension_registrar(ExtensionRegistrar* registrar) {
|
||||||
|
extension_registrar_ = registrar;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// ExtensionRegistrar::Delegate:
|
||||||
|
void PreAddExtension(const Extension* extension,
|
||||||
|
const Extension* old_extension) override;
|
||||||
|
void PostActivateExtension(scoped_refptr<const Extension> extension) override;
|
||||||
|
void PostDeactivateExtension(
|
||||||
|
scoped_refptr<const Extension> extension) override;
|
||||||
|
void PreUninstallExtension(scoped_refptr<const Extension> extension) override;
|
||||||
|
void PostUninstallExtension(scoped_refptr<const Extension> extension,
|
||||||
|
base::OnceClosure done_callback) override;
|
||||||
|
void PostNotifyUninstallExtension(
|
||||||
|
scoped_refptr<const Extension> extension) override;
|
||||||
|
void LoadExtensionForReload(
|
||||||
|
const ExtensionId& extension_id,
|
||||||
|
const base::FilePath& path,
|
||||||
|
ExtensionRegistrar::LoadErrorBehavior load_error_behavior) override;
|
||||||
|
void ShowExtensionDisabledError(const Extension* extension,
|
||||||
|
bool is_remote_install) override;
|
||||||
|
void FinishDelayedInstallationsIfAny() override;
|
||||||
|
bool CanAddExtension(const Extension* extension) override;
|
||||||
|
bool CanEnableExtension(const Extension* extension) override;
|
||||||
|
bool CanDisableExtension(const Extension* extension) override;
|
||||||
|
bool ShouldBlockExtension(const Extension* extension) override;
|
||||||
|
|
||||||
|
// If the extension loaded successfully, enables it. If it's an app, launches
|
||||||
|
// it. If the load failed, updates ShellKeepAliveRequester.
|
||||||
|
void FinishExtensionReload(const Extension* extension,
|
||||||
|
const ExtensionId& extension_id);
|
||||||
|
|
||||||
|
raw_ptr<content::BrowserContext> browser_context_; // Not owned.
|
||||||
|
raw_ptr<ElectronExtensionSystem> extension_system_; // Not owned.
|
||||||
|
raw_ptr<ExtensionRegistrar> extension_registrar_ = nullptr;
|
||||||
|
|
||||||
|
base::WeakPtrFactory<ElectronExtensionRegistrarDelegate> weak_factory_{this};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace extensions
|
||||||
|
|
||||||
|
#endif // ELECTRON_SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_REGISTRAR_DELEGATE_H_
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "extensions/browser/user_script_manager.h"
|
#include "extensions/browser/user_script_manager.h"
|
||||||
#include "extensions/common/constants.h"
|
#include "extensions/common/constants.h"
|
||||||
#include "shell/browser/extensions/electron_extension_loader.h"
|
#include "shell/browser/extensions/electron_extension_loader.h"
|
||||||
|
#include "shell/browser/extensions/electron_extension_registrar_delegate.h"
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||||
#include "chrome/browser/pdf/pdf_extension_util.h" // nogncheck
|
#include "chrome/browser/pdf/pdf_extension_util.h" // nogncheck
|
||||||
@@ -39,6 +40,8 @@ using content::BrowserThread;
|
|||||||
|
|
||||||
namespace extensions {
|
namespace extensions {
|
||||||
|
|
||||||
|
using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior;
|
||||||
|
|
||||||
ElectronExtensionSystem::ElectronExtensionSystem(
|
ElectronExtensionSystem::ElectronExtensionSystem(
|
||||||
BrowserContext* browser_context)
|
BrowserContext* browser_context)
|
||||||
: browser_context_(browser_context),
|
: browser_context_(browser_context),
|
||||||
@@ -47,6 +50,10 @@ ElectronExtensionSystem::ElectronExtensionSystem(
|
|||||||
|
|
||||||
ElectronExtensionSystem::~ElectronExtensionSystem() = default;
|
ElectronExtensionSystem::~ElectronExtensionSystem() = default;
|
||||||
|
|
||||||
|
void ElectronExtensionSystem::AddExtension(const Extension* extension) {
|
||||||
|
extension_registrar_->AddExtension(extension);
|
||||||
|
}
|
||||||
|
|
||||||
void ElectronExtensionSystem::LoadExtension(
|
void ElectronExtensionSystem::LoadExtension(
|
||||||
const base::FilePath& extension_dir,
|
const base::FilePath& extension_dir,
|
||||||
int load_flags,
|
int load_flags,
|
||||||
@@ -60,26 +67,56 @@ void ElectronExtensionSystem::FinishInitialization() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ElectronExtensionSystem::ReloadExtension(const ExtensionId& extension_id) {
|
void ElectronExtensionSystem::ReloadExtension(const ExtensionId& extension_id) {
|
||||||
extension_loader_->ReloadExtension(extension_id);
|
const Extension* extension = ExtensionRegistry::Get(browser_context_)
|
||||||
|
->GetInstalledExtension(extension_id);
|
||||||
|
// We shouldn't be trying to reload extensions that haven't been added.
|
||||||
|
DCHECK(extension);
|
||||||
|
|
||||||
|
extension_registrar_->ReloadExtension(extension_id,
|
||||||
|
LoadErrorBehavior::kQuiet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronExtensionSystem::RemoveExtension(const ExtensionId& extension_id) {
|
void ElectronExtensionSystem::RemoveExtension(const ExtensionId& extension_id) {
|
||||||
extension_loader_->UnloadExtension(
|
extension_registrar_->RemoveExtension(
|
||||||
extension_id, extensions::UnloadedExtensionReason::UNINSTALL);
|
extension_id, extensions::UnloadedExtensionReason::UNINSTALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ElectronExtensionSystem::EnableExtension(const std::string& extension_id) {
|
||||||
|
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||||
|
extension_registrar_->EnableExtension(extension_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElectronExtensionSystem::DisableExtension(
|
||||||
|
const ExtensionId& extension_id) {
|
||||||
|
extension_registrar_->DisableExtension(
|
||||||
|
extension_id, disable_reason::DisableReason::DISABLE_USER_ACTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ElectronExtensionSystem::IsExtensionEnabled(
|
||||||
|
const ExtensionId& extension_id) const {
|
||||||
|
return extension_registrar_->IsExtensionEnabled(extension_id);
|
||||||
|
}
|
||||||
|
|
||||||
void ElectronExtensionSystem::Shutdown() {
|
void ElectronExtensionSystem::Shutdown() {
|
||||||
extension_loader_.reset();
|
extension_loader_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
|
void ElectronExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
|
||||||
|
extension_registrar_delegate_ =
|
||||||
|
std::make_unique<ElectronExtensionRegistrarDelegate>(browser_context_,
|
||||||
|
this);
|
||||||
|
extension_registrar_ = std::make_unique<ExtensionRegistrar>(
|
||||||
|
browser_context_, extension_registrar_delegate_.get());
|
||||||
|
extension_registrar_delegate_->set_extension_registrar(
|
||||||
|
extension_registrar_.get());
|
||||||
|
|
||||||
service_worker_manager_ =
|
service_worker_manager_ =
|
||||||
std::make_unique<ServiceWorkerManager>(browser_context_);
|
std::make_unique<ServiceWorkerManager>(browser_context_);
|
||||||
quota_service_ = std::make_unique<QuotaService>();
|
quota_service_ = std::make_unique<QuotaService>();
|
||||||
user_script_manager_ = std::make_unique<UserScriptManager>(browser_context_);
|
user_script_manager_ = std::make_unique<UserScriptManager>(browser_context_);
|
||||||
app_sorting_ = std::make_unique<NullAppSorting>();
|
app_sorting_ = std::make_unique<NullAppSorting>();
|
||||||
extension_loader_ =
|
extension_loader_ =
|
||||||
std::make_unique<ElectronExtensionLoader>(browser_context_);
|
std::make_unique<ElectronExtensionLoader>(browser_context_, this);
|
||||||
|
|
||||||
if (!browser_context_->IsOffTheRecord())
|
if (!browser_context_->IsOffTheRecord())
|
||||||
LoadComponentExtensions();
|
LoadComponentExtensions();
|
||||||
@@ -120,7 +157,7 @@ void ElectronExtensionSystem::LoadComponentExtensions() {
|
|||||||
extensions::Extension::Create(
|
extensions::Extension::Create(
|
||||||
root_directory, extensions::mojom::ManifestLocation::kComponent,
|
root_directory, extensions::mojom::ManifestLocation::kComponent,
|
||||||
*pdf_manifest, extensions::Extension::REQUIRE_KEY, &utf8_error);
|
*pdf_manifest, extensions::Extension::REQUIRE_KEY, &utf8_error);
|
||||||
extension_loader_->registrar()->AddExtension(pdf_extension);
|
AddExtension(pdf_extension.get());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#include "base/one_shot_event.h"
|
#include "base/one_shot_event.h"
|
||||||
#include "components/value_store/value_store_factory.h"
|
#include "components/value_store/value_store_factory.h"
|
||||||
#include "components/value_store/value_store_factory_impl.h"
|
#include "components/value_store/value_store_factory_impl.h"
|
||||||
|
#include "extensions/browser/disable_reason.h"
|
||||||
|
#include "extensions/browser/extension_registrar.h"
|
||||||
#include "extensions/browser/extension_system.h"
|
#include "extensions/browser/extension_system.h"
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
@@ -26,6 +28,7 @@ class BrowserContext;
|
|||||||
namespace extensions {
|
namespace extensions {
|
||||||
|
|
||||||
class ElectronExtensionLoader;
|
class ElectronExtensionLoader;
|
||||||
|
class ElectronExtensionRegistrarDelegate;
|
||||||
class ValueStoreFactory;
|
class ValueStoreFactory;
|
||||||
|
|
||||||
// A simplified version of ExtensionSystem for app_shell. Allows
|
// A simplified version of ExtensionSystem for app_shell. Allows
|
||||||
@@ -40,6 +43,10 @@ class ElectronExtensionSystem : public ExtensionSystem {
|
|||||||
ElectronExtensionSystem(const ElectronExtensionSystem&) = delete;
|
ElectronExtensionSystem(const ElectronExtensionSystem&) = delete;
|
||||||
ElectronExtensionSystem& operator=(const ElectronExtensionSystem&) = delete;
|
ElectronExtensionSystem& operator=(const ElectronExtensionSystem&) = delete;
|
||||||
|
|
||||||
|
// Adds |extension| to this ExtensionService and notifies observers that the
|
||||||
|
// extension has been loaded.
|
||||||
|
void AddExtension(const Extension* extension);
|
||||||
|
|
||||||
// Loads an unpacked extension from a directory. Returns the extension on
|
// Loads an unpacked extension from a directory. Returns the extension on
|
||||||
// success, or nullptr otherwise.
|
// success, or nullptr otherwise.
|
||||||
void LoadExtension(
|
void LoadExtension(
|
||||||
@@ -55,6 +62,17 @@ class ElectronExtensionSystem : public ExtensionSystem {
|
|||||||
|
|
||||||
void RemoveExtension(const ExtensionId& extension_id);
|
void RemoveExtension(const ExtensionId& extension_id);
|
||||||
|
|
||||||
|
// Enables the extension. If the extension is already enabled, does
|
||||||
|
// nothing.
|
||||||
|
void EnableExtension(const ExtensionId& extension_id);
|
||||||
|
|
||||||
|
// Disables the extension. If the extension is already disabled, just adds
|
||||||
|
// the incoming disable reason(s). If the extension cannot be disabled (due to
|
||||||
|
// policy), does nothing.
|
||||||
|
void DisableExtension(const ExtensionId& extension_id);
|
||||||
|
|
||||||
|
bool IsExtensionEnabled(const ExtensionId& extension_id) const;
|
||||||
|
|
||||||
// KeyedService implementation:
|
// KeyedService implementation:
|
||||||
void Shutdown() override;
|
void Shutdown() override;
|
||||||
|
|
||||||
@@ -86,6 +104,10 @@ class ElectronExtensionSystem : public ExtensionSystem {
|
|||||||
const std::string& extension_id,
|
const std::string& extension_id,
|
||||||
const base::Value::Dict& attributes) override;
|
const base::Value::Dict& attributes) override;
|
||||||
|
|
||||||
|
base::WeakPtr<ElectronExtensionSystem> GetWeakPtr() {
|
||||||
|
return weak_factory_.GetWeakPtr();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnExtensionRegisteredWithRequestContexts(
|
void OnExtensionRegisteredWithRequestContexts(
|
||||||
scoped_refptr<Extension> extension);
|
scoped_refptr<Extension> extension);
|
||||||
@@ -99,6 +121,12 @@ class ElectronExtensionSystem : public ExtensionSystem {
|
|||||||
std::unique_ptr<AppSorting> app_sorting_;
|
std::unique_ptr<AppSorting> app_sorting_;
|
||||||
std::unique_ptr<ManagementPolicy> management_policy_;
|
std::unique_ptr<ManagementPolicy> management_policy_;
|
||||||
|
|
||||||
|
std::unique_ptr<ElectronExtensionRegistrarDelegate>
|
||||||
|
extension_registrar_delegate_;
|
||||||
|
|
||||||
|
// Helper to register and unregister extensions.
|
||||||
|
std::unique_ptr<ExtensionRegistrar> extension_registrar_;
|
||||||
|
|
||||||
std::unique_ptr<ElectronExtensionLoader> extension_loader_;
|
std::unique_ptr<ElectronExtensionLoader> extension_loader_;
|
||||||
|
|
||||||
scoped_refptr<value_store::ValueStoreFactory> store_factory_;
|
scoped_refptr<value_store::ValueStoreFactory> store_factory_;
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
#include "extensions/common/extension.h"
|
#include "extensions/common/extension.h"
|
||||||
#include "gin/dictionary.h"
|
#include "gin/dictionary.h"
|
||||||
|
#include "shell/browser/electron_browser_context.h"
|
||||||
|
#include "shell/browser/extensions/electron_extension_info.h"
|
||||||
|
#include "shell/browser/extensions/electron_extension_system.h"
|
||||||
#include "shell/common/gin_converters/file_path_converter.h"
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
#include "shell/common/gin_converters/gurl_converter.h"
|
#include "shell/common/gin_converters/gurl_converter.h"
|
||||||
#include "shell/common/gin_converters/value_converter.h"
|
#include "shell/common/gin_converters/value_converter.h"
|
||||||
@@ -13,16 +16,20 @@
|
|||||||
namespace gin {
|
namespace gin {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
v8::Local<v8::Value> Converter<const extensions::Extension*>::ToV8(
|
v8::Local<v8::Value> Converter<extensions::ElectronExtensionInfo>::ToV8(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
const extensions::Extension* extension) {
|
const extensions::ElectronExtensionInfo& info) {
|
||||||
|
auto extension_id = info.extension->id();
|
||||||
auto dict = gin::Dictionary::CreateEmpty(isolate);
|
auto dict = gin::Dictionary::CreateEmpty(isolate);
|
||||||
dict.Set("id", extension->id());
|
dict.Set("id", extension_id);
|
||||||
dict.Set("name", extension->name());
|
dict.Set("name", info.extension->name());
|
||||||
dict.Set("path", extension->path());
|
dict.Set("path", info.extension->path());
|
||||||
dict.Set("url", extension->url());
|
dict.Set("url", info.extension->url());
|
||||||
dict.Set("version", extension->VersionString());
|
dict.Set("version", info.extension->VersionString());
|
||||||
dict.Set("manifest", *extension->manifest()->value());
|
dict.Set("manifest", *info.extension->manifest()->value());
|
||||||
|
|
||||||
|
auto* ext_system = info.browser_context->extension_system();
|
||||||
|
dict.Set("enabled", ext_system->IsExtensionEnabled(extension_id));
|
||||||
|
|
||||||
return gin::ConvertToV8(isolate, dict);
|
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
|
// Use of this source code is governed by the MIT license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
@@ -8,15 +8,16 @@
|
|||||||
#include "gin/converter.h"
|
#include "gin/converter.h"
|
||||||
|
|
||||||
namespace extensions {
|
namespace extensions {
|
||||||
class Extension;
|
struct ElectronExtensionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace gin {
|
namespace gin {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<const extensions::Extension*> {
|
struct Converter<extensions::ElectronExtensionInfo> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(
|
||||||
const extensions::Extension* val);
|
v8::Isolate* isolate,
|
||||||
|
const extensions::ElectronExtensionInfo& val);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gin
|
} // namespace gin
|
||||||
|
|||||||
Reference in New Issue
Block a user