2019-07-24 23:01:08 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/browser/extensions/electron_extension_system.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2020-01-21 17:43:18 +00:00
|
|
|
#include <utility>
|
2019-07-24 23:01:08 +00:00
|
|
|
|
|
|
|
#include "base/bind.h"
|
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/files/file_util.h"
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "base/json/json_string_value_serializer.h"
|
|
|
|
#include "base/path_service.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "base/task/post_task.h"
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "content/public/browser/browser_context.h"
|
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "content/public/browser/notification_details.h"
|
|
|
|
#include "content/public/browser/notification_service.h"
|
|
|
|
#include "content/public/browser/notification_source.h"
|
2020-04-29 06:16:10 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "extensions/browser/api/app_runtime/app_runtime_api.h"
|
|
|
|
#include "extensions/browser/extension_registry.h"
|
|
|
|
#include "extensions/browser/info_map.h"
|
|
|
|
#include "extensions/browser/notification_types.h"
|
|
|
|
#include "extensions/browser/null_app_sorting.h"
|
|
|
|
#include "extensions/browser/quota_service.h"
|
|
|
|
#include "extensions/browser/runtime_data.h"
|
|
|
|
#include "extensions/browser/service_worker_manager.h"
|
|
|
|
#include "extensions/browser/shared_user_script_master.h"
|
|
|
|
#include "extensions/browser/value_store/value_store_factory_impl.h"
|
|
|
|
#include "extensions/common/constants.h"
|
|
|
|
#include "extensions/common/file_util.h"
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/browser/extensions/electron_extension_loader.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2020-04-29 06:16:10 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
|
|
|
#include "chrome/browser/pdf/pdf_extension_util.h"
|
|
|
|
#endif
|
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
using content::BrowserContext;
|
|
|
|
using content::BrowserThread;
|
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
ElectronExtensionSystem::ElectronExtensionSystem(
|
|
|
|
BrowserContext* browser_context)
|
2019-07-24 23:01:08 +00:00
|
|
|
: browser_context_(browser_context),
|
|
|
|
store_factory_(new ValueStoreFactoryImpl(browser_context->GetPath())),
|
|
|
|
weak_factory_(this) {}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
ElectronExtensionSystem::~ElectronExtensionSystem() = default;
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionSystem::LoadExtension(
|
2020-01-21 17:43:18 +00:00
|
|
|
const base::FilePath& extension_dir,
|
2020-02-03 22:01:10 +00:00
|
|
|
base::OnceCallback<void(const Extension*, const std::string&)> cb) {
|
|
|
|
extension_loader_->LoadExtension(extension_dir, std::move(cb));
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionSystem::FinishInitialization() {
|
2019-07-24 23:01:08 +00:00
|
|
|
// Inform the rest of the extensions system to start.
|
|
|
|
ready_.Signal();
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionSystem::ReloadExtension(const ExtensionId& extension_id) {
|
2019-07-24 23:01:08 +00:00
|
|
|
extension_loader_->ReloadExtension(extension_id);
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionSystem::RemoveExtension(const ExtensionId& extension_id) {
|
2020-01-13 22:56:28 +00:00
|
|
|
extension_loader_->UnloadExtension(
|
|
|
|
extension_id, extensions::UnloadedExtensionReason::UNINSTALL);
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionSystem::Shutdown() {
|
2019-07-24 23:01:08 +00:00
|
|
|
extension_loader_.reset();
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
|
2019-07-24 23:01:08 +00:00
|
|
|
service_worker_manager_ =
|
|
|
|
std::make_unique<ServiceWorkerManager>(browser_context_);
|
|
|
|
runtime_data_ =
|
|
|
|
std::make_unique<RuntimeData>(ExtensionRegistry::Get(browser_context_));
|
|
|
|
quota_service_ = std::make_unique<QuotaService>();
|
|
|
|
shared_user_script_master_ =
|
|
|
|
std::make_unique<SharedUserScriptMaster>(browser_context_);
|
|
|
|
app_sorting_ = std::make_unique<NullAppSorting>();
|
2020-02-03 22:01:10 +00:00
|
|
|
extension_loader_ =
|
|
|
|
std::make_unique<ElectronExtensionLoader>(browser_context_);
|
2020-02-13 00:39:12 +00:00
|
|
|
|
|
|
|
if (!browser_context_->IsOffTheRecord())
|
|
|
|
LoadComponentExtensions();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<base::DictionaryValue> ParseManifest(
|
|
|
|
base::StringPiece manifest_contents) {
|
|
|
|
JSONStringValueDeserializer deserializer(manifest_contents);
|
|
|
|
std::unique_ptr<base::Value> manifest = deserializer.Deserialize(NULL, NULL);
|
|
|
|
|
|
|
|
if (!manifest.get() || !manifest->is_dict()) {
|
|
|
|
LOG(ERROR) << "Failed to parse extension manifest.";
|
|
|
|
return std::unique_ptr<base::DictionaryValue>();
|
|
|
|
}
|
|
|
|
return base::DictionaryValue::From(std::move(manifest));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElectronExtensionSystem::LoadComponentExtensions() {
|
2020-04-29 06:16:10 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
2020-02-13 00:39:12 +00:00
|
|
|
std::string utf8_error;
|
|
|
|
std::string pdf_manifest_string = pdf_extension_util::GetManifest();
|
|
|
|
std::unique_ptr<base::DictionaryValue> pdf_manifest =
|
|
|
|
ParseManifest(pdf_manifest_string);
|
|
|
|
base::FilePath root_directory;
|
|
|
|
CHECK(base::PathService::Get(chrome::DIR_RESOURCES, &root_directory));
|
|
|
|
root_directory = root_directory.Append(FILE_PATH_LITERAL("pdf"));
|
|
|
|
scoped_refptr<const Extension> pdf_extension = extensions::Extension::Create(
|
|
|
|
root_directory, extensions::Manifest::COMPONENT, *pdf_manifest,
|
|
|
|
extensions::Extension::REQUIRE_KEY, &utf8_error);
|
|
|
|
extension_loader_->registrar()->AddExtension(pdf_extension);
|
2020-04-29 06:16:10 +00:00
|
|
|
#endif
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
ExtensionService* ElectronExtensionSystem::extension_service() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
RuntimeData* ElectronExtensionSystem::runtime_data() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return runtime_data_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
ManagementPolicy* ElectronExtensionSystem::management_policy() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
ServiceWorkerManager* ElectronExtensionSystem::service_worker_manager() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return service_worker_manager_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
SharedUserScriptMaster* ElectronExtensionSystem::shared_user_script_master() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return new SharedUserScriptMaster(browser_context_);
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
StateStore* ElectronExtensionSystem::state_store() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
StateStore* ElectronExtensionSystem::rules_store() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
scoped_refptr<ValueStoreFactory> ElectronExtensionSystem::store_factory() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return store_factory_;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
InfoMap* ElectronExtensionSystem::info_map() {
|
2019-07-24 23:01:08 +00:00
|
|
|
if (!info_map_.get())
|
|
|
|
info_map_ = new InfoMap;
|
|
|
|
return info_map_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
QuotaService* ElectronExtensionSystem::quota_service() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return quota_service_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
AppSorting* ElectronExtensionSystem::app_sorting() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return app_sorting_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionSystem::RegisterExtensionWithRequestContexts(
|
2019-07-24 23:01:08 +00:00
|
|
|
const Extension* extension,
|
2020-01-29 12:01:37 +00:00
|
|
|
base::OnceClosure callback) {
|
2019-09-18 19:58:00 +00:00
|
|
|
base::PostTaskAndReply(
|
2019-07-24 23:01:08 +00:00
|
|
|
FROM_HERE, {BrowserThread::IO},
|
|
|
|
base::Bind(&InfoMap::AddExtension, info_map(),
|
|
|
|
base::RetainedRef(extension), base::Time::Now(), false, false),
|
2020-01-29 12:01:37 +00:00
|
|
|
std::move(callback));
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionSystem::UnregisterExtensionWithRequestContexts(
|
2019-07-24 23:01:08 +00:00
|
|
|
const std::string& extension_id,
|
|
|
|
const UnloadedExtensionReason reason) {}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
const base::OneShotEvent& ElectronExtensionSystem::ready() const {
|
2019-07-24 23:01:08 +00:00
|
|
|
return ready_;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
ContentVerifier* ElectronExtensionSystem::content_verifier() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
std::unique_ptr<ExtensionSet> ElectronExtensionSystem::GetDependentExtensions(
|
2019-07-24 23:01:08 +00:00
|
|
|
const Extension* extension) {
|
|
|
|
return std::make_unique<ExtensionSet>();
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionSystem::InstallUpdate(
|
2019-07-24 23:01:08 +00:00
|
|
|
const std::string& extension_id,
|
|
|
|
const std::string& public_key,
|
|
|
|
const base::FilePath& temp_dir,
|
|
|
|
bool install_immediately,
|
|
|
|
InstallUpdateCallback install_update_callback) {
|
|
|
|
NOTREACHED();
|
|
|
|
base::DeleteFile(temp_dir, true /* recursive */);
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
bool ElectronExtensionSystem::FinishDelayedInstallationIfReady(
|
2019-07-24 23:01:08 +00:00
|
|
|
const std::string& extension_id,
|
|
|
|
bool install_immediately) {
|
|
|
|
NOTREACHED();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-13 23:39:26 +00:00
|
|
|
void ElectronExtensionSystem::PerformActionBasedOnOmahaAttributes(
|
|
|
|
const std::string& extension_id,
|
|
|
|
const base::Value& attributes) {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionSystem::OnExtensionRegisteredWithRequestContexts(
|
2019-07-24 23:01:08 +00:00
|
|
|
scoped_refptr<Extension> extension) {
|
|
|
|
ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_);
|
|
|
|
registry->AddReady(extension);
|
|
|
|
registry->TriggerOnReady(extension.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace extensions
|