2015-07-16 23:40:01 +02:00
|
|
|
// Copyright 2015 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions 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.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "include/cef_extension_handler.h"
|
|
|
|
#include "include/cef_request_context.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2015-08-14 16:41:08 +02:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2019-06-05 16:15:45 +02:00
|
|
|
#include "base/one_shot_event.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "extensions/browser/extension_system.h"
|
|
|
|
|
|
|
|
namespace base {
|
2017-08-04 00:55:19 +02:00
|
|
|
class DictionaryValue;
|
2020-07-08 19:23:29 +02:00
|
|
|
}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class BrowserContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
class ExtensionRegistry;
|
|
|
|
class ProcessManager;
|
|
|
|
class RendererStartupHelper;
|
|
|
|
|
|
|
|
// Used to manage extensions.
|
|
|
|
class CefExtensionSystem : public ExtensionSystem {
|
|
|
|
public:
|
|
|
|
explicit CefExtensionSystem(content::BrowserContext* browser_context);
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefExtensionSystem(const CefExtensionSystem&) = delete;
|
|
|
|
CefExtensionSystem& operator=(const CefExtensionSystem&) = delete;
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
~CefExtensionSystem() override;
|
|
|
|
|
|
|
|
// Initializes the extension system.
|
|
|
|
void Init();
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// Load an extension. For internal (built-in) extensions set |internal| to
|
|
|
|
// true and |loader_context| and |handler| to NULL. For external extensions
|
|
|
|
// set |internal| to false and |loader_context| must be the request context
|
|
|
|
// that loaded the extension. |handler| is optional for internal extensions
|
|
|
|
// and, if specified, will receive extension-related callbacks.
|
|
|
|
void LoadExtension(const base::FilePath& root_directory,
|
|
|
|
bool internal,
|
|
|
|
CefRefPtr<CefRequestContext> loader_context,
|
|
|
|
CefRefPtr<CefExtensionHandler> handler);
|
|
|
|
void LoadExtension(const std::string& manifest_contents,
|
|
|
|
const base::FilePath& root_directory,
|
|
|
|
bool internal,
|
|
|
|
CefRefPtr<CefRequestContext> loader_context,
|
|
|
|
CefRefPtr<CefExtensionHandler> handler);
|
2023-01-03 00:34:43 +01:00
|
|
|
void LoadExtension(base::Value::Dict manifest,
|
2017-08-04 00:55:19 +02:00
|
|
|
const base::FilePath& root_directory,
|
|
|
|
bool internal,
|
|
|
|
CefRefPtr<CefRequestContext> loader_context,
|
|
|
|
CefRefPtr<CefExtensionHandler> handler);
|
|
|
|
|
|
|
|
// Unload the external extension identified by |extension_id|.
|
|
|
|
bool UnloadExtension(const std::string& extension_id);
|
|
|
|
|
|
|
|
// Returns true if an extension matching |extension_id| is loaded.
|
|
|
|
bool HasExtension(const std::string& extension_id) const;
|
|
|
|
|
|
|
|
// Returns the loaded extention matching |extension_id| or NULL if not found.
|
|
|
|
CefRefPtr<CefExtension> GetExtension(const std::string& extension_id) const;
|
|
|
|
|
|
|
|
using ExtensionMap = std::map<std::string, CefRefPtr<CefExtension>>;
|
|
|
|
|
|
|
|
// Returns the map of all loaded extensions.
|
|
|
|
ExtensionMap GetExtensions() const;
|
|
|
|
|
|
|
|
// Called when a request context is deleted. Unregisters any external
|
|
|
|
// extensions that were registered with this context.
|
|
|
|
void OnRequestContextDeleted(CefRequestContext* context);
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
// KeyedService implementation:
|
|
|
|
void Shutdown() override;
|
|
|
|
|
|
|
|
// ExtensionSystem implementation:
|
|
|
|
void InitForRegularProfile(bool extensions_enabled) override;
|
|
|
|
ExtensionService* extension_service() override;
|
|
|
|
ManagementPolicy* management_policy() override;
|
2015-10-09 17:23:12 +02:00
|
|
|
ServiceWorkerManager* service_worker_manager() override;
|
2021-03-04 23:36:57 +01:00
|
|
|
UserScriptManager* user_script_manager() override;
|
2015-07-16 23:40:01 +02:00
|
|
|
StateStore* state_store() override;
|
|
|
|
StateStore* rules_store() override;
|
2021-10-19 00:17:16 +02:00
|
|
|
StateStore* dynamic_user_scripts_store() override;
|
2021-09-20 11:06:23 +02:00
|
|
|
scoped_refptr<value_store::ValueStoreFactory> store_factory() override;
|
2015-07-16 23:40:01 +02:00
|
|
|
QuotaService* quota_service() override;
|
2015-08-14 16:41:08 +02:00
|
|
|
AppSorting* app_sorting() override;
|
2019-06-05 16:15:45 +02:00
|
|
|
const base::OneShotEvent& ready() const override;
|
2020-07-08 19:23:29 +02:00
|
|
|
bool is_ready() const override;
|
2015-07-16 23:40:01 +02:00
|
|
|
ContentVerifier* content_verifier() override;
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<ExtensionSet> GetDependentExtensions(
|
2015-07-16 23:40:01 +02:00
|
|
|
const Extension* extension) override;
|
2015-11-10 21:18:16 +01:00
|
|
|
void InstallUpdate(const std::string& extension_id,
|
2018-02-15 01:12:09 +01:00
|
|
|
const std::string& public_key,
|
|
|
|
const base::FilePath& temp_dir,
|
2018-07-02 19:11:49 +02:00
|
|
|
bool install_immediately,
|
2018-02-15 01:12:09 +01:00
|
|
|
InstallUpdateCallback install_update_callback) override;
|
2020-06-09 19:48:00 +02:00
|
|
|
void PerformActionBasedOnOmahaAttributes(
|
|
|
|
const std::string& extension_id,
|
2023-05-30 10:55:32 +02:00
|
|
|
const base::Value::Dict& attributes) override;
|
2018-03-20 21:15:08 +01:00
|
|
|
bool FinishDelayedInstallationIfReady(const std::string& extension_id,
|
|
|
|
bool install_immediately) override;
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2016-08-24 11:28:52 +02:00
|
|
|
bool initialized() const { return initialized_; }
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
private:
|
2017-09-11 20:42:30 +02:00
|
|
|
virtual void InitPrefs();
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
// Information about a registered component extension.
|
|
|
|
struct ComponentExtensionInfo {
|
2023-01-03 00:34:43 +01:00
|
|
|
ComponentExtensionInfo(base::Value::Dict manifest,
|
2017-08-04 00:55:19 +02:00
|
|
|
const base::FilePath& root_directory,
|
|
|
|
bool internal);
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
// The parsed contents of the extensions's manifest file.
|
2023-01-03 00:34:43 +01:00
|
|
|
base::Value::Dict manifest;
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
// Directory where the extension is stored.
|
|
|
|
base::FilePath root_directory;
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// True if the extension is an internal (built-in) component.
|
|
|
|
bool internal;
|
2015-07-16 23:40:01 +02:00
|
|
|
};
|
|
|
|
|
2015-07-24 02:06:56 +02:00
|
|
|
scoped_refptr<const Extension> CreateExtension(
|
2017-05-17 11:29:28 +02:00
|
|
|
const ComponentExtensionInfo& info,
|
|
|
|
std::string* utf8_error);
|
2015-07-24 02:06:56 +02:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
// Loads a registered component extension.
|
2017-08-04 00:55:19 +02:00
|
|
|
const Extension* LoadExtension(const ComponentExtensionInfo& info,
|
|
|
|
CefRefPtr<CefRequestContext> loader_context,
|
|
|
|
CefRefPtr<CefExtensionHandler> handler);
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
// Unload the specified extension.
|
2017-05-17 11:29:28 +02:00
|
|
|
void UnloadExtension(const std::string& extension_id,
|
2017-05-31 17:33:30 +02:00
|
|
|
extensions::UnloadedExtensionReason reason);
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
// Handles sending notification that |extension| was loaded.
|
|
|
|
void NotifyExtensionLoaded(const Extension* extension);
|
|
|
|
|
|
|
|
// Handles sending notification that |extension| was unloaded.
|
2017-05-17 11:29:28 +02:00
|
|
|
void NotifyExtensionUnloaded(const Extension* extension,
|
2017-05-31 17:33:30 +02:00
|
|
|
UnloadedExtensionReason reason);
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
content::BrowserContext* browser_context_; // Not owned.
|
|
|
|
|
2016-08-24 11:28:52 +02:00
|
|
|
bool initialized_;
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<ServiceWorkerManager> service_worker_manager_;
|
|
|
|
std::unique_ptr<QuotaService> quota_service_;
|
|
|
|
std::unique_ptr<AppSorting> app_sorting_;
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2017-09-11 20:42:30 +02:00
|
|
|
std::unique_ptr<StateStore> state_store_;
|
|
|
|
std::unique_ptr<StateStore> rules_store_;
|
2021-09-20 11:06:23 +02:00
|
|
|
scoped_refptr<value_store::ValueStoreFactory> store_factory_;
|
2017-09-11 20:42:30 +02:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
// Signaled when the extension system has completed its startup tasks.
|
2019-06-05 16:15:45 +02:00
|
|
|
base::OneShotEvent ready_;
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
// Sets of enabled/disabled/terminated/blacklisted extensions. Not owned.
|
|
|
|
ExtensionRegistry* registry_;
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
// The associated RendererStartupHelper. Guaranteed to outlive the
|
|
|
|
// ExtensionSystem, and thus us.
|
|
|
|
extensions::RendererStartupHelper* renderer_helper_;
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// Map of extension ID to CEF extension object.
|
|
|
|
ExtensionMap extension_map_;
|
|
|
|
|
2015-08-14 16:41:08 +02:00
|
|
|
// Must be the last member.
|
|
|
|
base::WeakPtrFactory<CefExtensionSystem> weak_ptr_factory_;
|
2015-07-16 23:40:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace extensions
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_
|