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.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_SYSTEM_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_SYSTEM_H_
|
2019-07-24 23:01:08 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
#include "base/memory/ref_counted.h"
|
|
|
|
#include "base/memory/weak_ptr.h"
|
|
|
|
#include "base/one_shot_event.h"
|
2021-10-06 02:21:00 +00:00
|
|
|
#include "components/value_store/value_store_factory.h"
|
|
|
|
#include "components/value_store/value_store_factory_impl.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "extensions/browser/extension_system.h"
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class BrowserContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
class ElectronExtensionLoader;
|
2019-07-24 23:01:08 +00:00
|
|
|
class ValueStoreFactory;
|
|
|
|
|
|
|
|
// A simplified version of ExtensionSystem for app_shell. Allows
|
|
|
|
// app_shell to skip initialization of services it doesn't need.
|
2020-02-03 22:01:10 +00:00
|
|
|
class ElectronExtensionSystem : public ExtensionSystem {
|
2019-07-24 23:01:08 +00:00
|
|
|
public:
|
|
|
|
using InstallUpdateCallback = ExtensionSystem::InstallUpdateCallback;
|
2020-02-03 22:01:10 +00:00
|
|
|
explicit ElectronExtensionSystem(content::BrowserContext* browser_context);
|
|
|
|
~ElectronExtensionSystem() override;
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
ElectronExtensionSystem(const ElectronExtensionSystem&) = delete;
|
|
|
|
ElectronExtensionSystem& operator=(const ElectronExtensionSystem&) = delete;
|
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
// Loads an unpacked extension from a directory. Returns the extension on
|
|
|
|
// success, or nullptr otherwise.
|
2020-02-03 22:01:10 +00:00
|
|
|
void LoadExtension(
|
|
|
|
const base::FilePath& extension_dir,
|
2021-02-01 22:41:08 +00:00
|
|
|
int load_flags,
|
2020-02-03 22:01:10 +00:00
|
|
|
base::OnceCallback<void(const Extension*, const std::string&)> cb);
|
2019-07-24 23:01:08 +00:00
|
|
|
|
|
|
|
// Finish initialization for the shell extension system.
|
|
|
|
void FinishInitialization();
|
|
|
|
|
|
|
|
// Reloads the extension with id |extension_id|.
|
|
|
|
void ReloadExtension(const ExtensionId& extension_id);
|
|
|
|
|
2020-01-13 22:56:28 +00:00
|
|
|
void RemoveExtension(const ExtensionId& extension_id);
|
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
// KeyedService implementation:
|
|
|
|
void Shutdown() override;
|
|
|
|
|
|
|
|
// ExtensionSystem implementation:
|
|
|
|
void InitForRegularProfile(bool extensions_enabled) override;
|
|
|
|
ExtensionService* extension_service() override;
|
|
|
|
ManagementPolicy* management_policy() override;
|
|
|
|
ServiceWorkerManager* service_worker_manager() override;
|
2021-03-05 23:15:58 +00:00
|
|
|
UserScriptManager* user_script_manager() override;
|
2019-07-24 23:01:08 +00:00
|
|
|
StateStore* state_store() override;
|
|
|
|
StateStore* rules_store() override;
|
2021-10-21 18:51:36 +00:00
|
|
|
StateStore* dynamic_user_scripts_store() override;
|
2021-10-06 02:21:00 +00:00
|
|
|
scoped_refptr<value_store::ValueStoreFactory> store_factory() override;
|
2019-07-24 23:01:08 +00:00
|
|
|
InfoMap* info_map() override;
|
|
|
|
QuotaService* quota_service() override;
|
|
|
|
AppSorting* app_sorting() override;
|
|
|
|
void RegisterExtensionWithRequestContexts(
|
|
|
|
const Extension* extension,
|
2020-01-29 12:01:37 +00:00
|
|
|
base::OnceClosure callback) override;
|
2019-07-24 23:01:08 +00:00
|
|
|
void UnregisterExtensionWithRequestContexts(
|
|
|
|
const std::string& extension_id,
|
|
|
|
const UnloadedExtensionReason reason) override;
|
|
|
|
const base::OneShotEvent& ready() const override;
|
2020-06-22 17:35:10 +00:00
|
|
|
bool is_ready() const override;
|
2019-07-24 23:01:08 +00:00
|
|
|
ContentVerifier* content_verifier() override;
|
|
|
|
std::unique_ptr<ExtensionSet> GetDependentExtensions(
|
|
|
|
const Extension* extension) override;
|
|
|
|
void InstallUpdate(const std::string& extension_id,
|
|
|
|
const std::string& public_key,
|
|
|
|
const base::FilePath& temp_dir,
|
|
|
|
bool install_immediately,
|
|
|
|
InstallUpdateCallback install_update_callback) override;
|
|
|
|
bool FinishDelayedInstallationIfReady(const std::string& extension_id,
|
|
|
|
bool install_immediately) override;
|
2020-04-13 23:39:26 +00:00
|
|
|
void PerformActionBasedOnOmahaAttributes(
|
|
|
|
const std::string& extension_id,
|
|
|
|
const base::Value& attributes) override;
|
2019-07-24 23:01:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void OnExtensionRegisteredWithRequestContexts(
|
|
|
|
scoped_refptr<Extension> extension);
|
2020-02-13 00:39:12 +00:00
|
|
|
void LoadComponentExtensions();
|
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
content::BrowserContext* browser_context_; // Not owned.
|
|
|
|
|
|
|
|
// Data to be accessed on the IO thread. Must outlive process_manager_.
|
|
|
|
scoped_refptr<InfoMap> info_map_;
|
|
|
|
|
|
|
|
std::unique_ptr<ServiceWorkerManager> service_worker_manager_;
|
|
|
|
std::unique_ptr<QuotaService> quota_service_;
|
2021-03-05 23:15:58 +00:00
|
|
|
std::unique_ptr<UserScriptManager> user_script_manager_;
|
2019-07-24 23:01:08 +00:00
|
|
|
std::unique_ptr<AppSorting> app_sorting_;
|
2020-09-02 00:59:56 +00:00
|
|
|
std::unique_ptr<ManagementPolicy> management_policy_;
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
std::unique_ptr<ElectronExtensionLoader> extension_loader_;
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2021-10-06 02:21:00 +00:00
|
|
|
scoped_refptr<value_store::ValueStoreFactory> store_factory_;
|
2019-07-24 23:01:08 +00:00
|
|
|
|
|
|
|
// Signaled when the extension system has completed its startup tasks.
|
|
|
|
base::OneShotEvent ready_;
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<ElectronExtensionSystem> weak_factory_{this};
|
2019-07-24 23:01:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace extensions
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_EXTENSIONS_ELECTRON_EXTENSION_SYSTEM_H_
|