feat: preliminary support for //extensions (#17440)

This commit is contained in:
Samuel Maddock 2019-07-24 19:01:08 -04:00 committed by Jeremy Apthorp
parent bd526f97a5
commit 95977291f7
54 changed files with 2483 additions and 36 deletions

View file

@ -0,0 +1,55 @@
// 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.
#include "shell/browser/extensions/api/runtime/atom_runtime_api_delegate.h"
#include <string>
#include "build/build_config.h"
#include "extensions/common/api/runtime.h"
#include "shell/browser/extensions/atom_extension_system.h"
using extensions::api::runtime::PlatformInfo;
namespace extensions {
AtomRuntimeAPIDelegate::AtomRuntimeAPIDelegate(
content::BrowserContext* browser_context)
: browser_context_(browser_context) {
DCHECK(browser_context_);
}
AtomRuntimeAPIDelegate::~AtomRuntimeAPIDelegate() = default;
void AtomRuntimeAPIDelegate::AddUpdateObserver(UpdateObserver* observer) {}
void AtomRuntimeAPIDelegate::RemoveUpdateObserver(UpdateObserver* observer) {}
void AtomRuntimeAPIDelegate::ReloadExtension(const std::string& extension_id) {
static_cast<AtomExtensionSystem*>(ExtensionSystem::Get(browser_context_))
->ReloadExtension(extension_id);
}
bool AtomRuntimeAPIDelegate::CheckForUpdates(
const std::string& extension_id,
const UpdateCheckCallback& callback) {
return false;
}
void AtomRuntimeAPIDelegate::OpenURL(const GURL& uninstall_url) {}
bool AtomRuntimeAPIDelegate::GetPlatformInfo(PlatformInfo* info) {
// TODO(nornagon): put useful information here.
#if defined(OS_LINUX)
info->os = api::runtime::PLATFORM_OS_LINUX;
#endif
return true;
} // namespace extensions
bool AtomRuntimeAPIDelegate::RestartDevice(std::string* error_message) {
*error_message = "Restart is not supported in Electron";
return false;
}
} // namespace extensions

View file

@ -0,0 +1,42 @@
// 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 SHELL_BROWSER_EXTENSIONS_API_RUNTIME_ATOM_RUNTIME_API_DELEGATE_H_
#define SHELL_BROWSER_EXTENSIONS_API_RUNTIME_ATOM_RUNTIME_API_DELEGATE_H_
#include <string>
#include "base/macros.h"
#include "extensions/browser/api/runtime/runtime_api_delegate.h"
namespace content {
class BrowserContext;
} // namespace content
namespace extensions {
class AtomRuntimeAPIDelegate : public RuntimeAPIDelegate {
public:
explicit AtomRuntimeAPIDelegate(content::BrowserContext* browser_context);
~AtomRuntimeAPIDelegate() override;
// RuntimeAPIDelegate implementation.
void AddUpdateObserver(UpdateObserver* observer) override;
void RemoveUpdateObserver(UpdateObserver* observer) override;
void ReloadExtension(const std::string& extension_id) override;
bool CheckForUpdates(const std::string& extension_id,
const UpdateCheckCallback& callback) override;
void OpenURL(const GURL& uninstall_url) override;
bool GetPlatformInfo(api::runtime::PlatformInfo* info) override;
bool RestartDevice(std::string* error_message) override;
private:
content::BrowserContext* browser_context_;
DISALLOW_COPY_AND_ASSIGN(AtomRuntimeAPIDelegate);
};
} // namespace extensions
#endif // SHELL_BROWSER_EXTENSIONS_API_RUNTIME_ATOM_RUNTIME_API_DELEGATE_H_

View file

@ -0,0 +1,25 @@
// 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.
#include "shell/browser/extensions/atom_browser_context_keyed_service_factories.h"
#include "extensions/browser/updater/update_service_factory.h"
// #include "extensions/shell/browser/api/identity/identity_api.h"
#include "shell/browser/extensions/atom_extension_system_factory.h"
namespace extensions {
namespace electron {
void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
// IdentityAPI::GetFactoryInstance();
// TODO(rockot): Remove this once UpdateService is supported across all
// extensions embedders (and namely chrome.)
UpdateServiceFactory::GetInstance();
AtomExtensionSystemFactory::GetInstance();
}
} // namespace electron
} // namespace extensions

View file

@ -0,0 +1,18 @@
// 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 SHELL_BROWSER_EXTENSIONS_ATOM_BROWSER_CONTEXT_KEYED_SERVICE_FACTORIES_H_
#define SHELL_BROWSER_EXTENSIONS_ATOM_BROWSER_CONTEXT_KEYED_SERVICE_FACTORIES_H_
namespace extensions {
namespace electron {
// Ensures the existence of any BrowserContextKeyedServiceFactory provided by
// the core extensions code.
void EnsureBrowserContextKeyedServiceFactoriesBuilt();
} // namespace electron
} // namespace extensions
#endif // SHELL_BROWSER_EXTENSIONS_ATOM_BROWSER_CONTEXT_KEYED_SERVICE_FACTORIES_H_

View file

@ -0,0 +1,11 @@
// 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.
#include "shell/browser/extensions/atom_display_info_provider.h"
namespace extensions {
AtomDisplayInfoProvider::AtomDisplayInfoProvider() = default;
} // namespace extensions

View file

@ -0,0 +1,23 @@
// 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 SHELL_BROWSER_EXTENSIONS_ATOM_DISPLAY_INFO_PROVIDER_H_
#define SHELL_BROWSER_EXTENSIONS_ATOM_DISPLAY_INFO_PROVIDER_H_
#include "base/macros.h"
#include "extensions/browser/api/system_display/display_info_provider.h"
namespace extensions {
class AtomDisplayInfoProvider : public DisplayInfoProvider {
public:
AtomDisplayInfoProvider();
private:
DISALLOW_COPY_AND_ASSIGN(AtomDisplayInfoProvider);
};
} // namespace extensions
#endif // SHELL_BROWSER_EXTENSIONS_ATOM_DISPLAY_INFO_PROVIDER_H_

View file

@ -0,0 +1,88 @@
// 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.
#include "shell/browser/extensions/atom_extension_host_delegate.h"
#include <memory>
#include <string>
#include <utility>
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "extensions/browser/media_capture_util.h"
#include "extensions/browser/serial_extension_host_queue.h"
#include "shell/browser/extensions/atom_extension_web_contents_observer.h"
namespace extensions {
AtomExtensionHostDelegate::AtomExtensionHostDelegate() {}
AtomExtensionHostDelegate::~AtomExtensionHostDelegate() {}
void AtomExtensionHostDelegate::OnExtensionHostCreated(
content::WebContents* web_contents) {
AtomExtensionWebContentsObserver::CreateForWebContents(web_contents);
}
void AtomExtensionHostDelegate::OnRenderViewCreatedForBackgroundPage(
ExtensionHost* host) {}
content::JavaScriptDialogManager*
AtomExtensionHostDelegate::GetJavaScriptDialogManager() {
// TODO(jamescook): Create a JavaScriptDialogManager or reuse the one from
// content_shell.
NOTREACHED();
return nullptr;
}
void AtomExtensionHostDelegate::CreateTab(
std::unique_ptr<content::WebContents> web_contents,
const std::string& extension_id,
WindowOpenDisposition disposition,
const gfx::Rect& initial_rect,
bool user_gesture) {
// TODO(jamescook): Should app_shell support opening popup windows?
NOTREACHED();
}
void AtomExtensionHostDelegate::ProcessMediaAccessRequest(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback,
const Extension* extension) {
// Allow access to the microphone and/or camera.
media_capture_util::GrantMediaStreamRequest(web_contents, request,
std::move(callback), extension);
}
bool AtomExtensionHostDelegate::CheckMediaAccessPermission(
content::RenderFrameHost* render_frame_host,
const GURL& security_origin,
blink::mojom::MediaStreamType type,
const Extension* extension) {
media_capture_util::VerifyMediaAccessPermission(type, extension);
return true;
}
static base::LazyInstance<SerialExtensionHostQueue>::DestructorAtExit g_queue =
LAZY_INSTANCE_INITIALIZER;
ExtensionHostQueue* AtomExtensionHostDelegate::GetExtensionHostQueue() const {
return g_queue.Pointer();
}
content::PictureInPictureResult
AtomExtensionHostDelegate::EnterPictureInPicture(
content::WebContents* web_contents,
const viz::SurfaceId& surface_id,
const gfx::Size& natural_size) {
NOTREACHED();
return content::PictureInPictureResult();
}
void AtomExtensionHostDelegate::ExitPictureInPicture() {
NOTREACHED();
}
} // namespace extensions

View file

@ -0,0 +1,52 @@
// 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 SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_HOST_DELEGATE_H_
#define SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_HOST_DELEGATE_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "extensions/browser/extension_host_delegate.h"
namespace extensions {
// A minimal ExtensionHostDelegate.
class AtomExtensionHostDelegate : public ExtensionHostDelegate {
public:
AtomExtensionHostDelegate();
~AtomExtensionHostDelegate() override;
// ExtensionHostDelegate implementation.
void OnExtensionHostCreated(content::WebContents* web_contents) override;
void OnRenderViewCreatedForBackgroundPage(ExtensionHost* host) override;
content::JavaScriptDialogManager* GetJavaScriptDialogManager() override;
void CreateTab(std::unique_ptr<content::WebContents> web_contents,
const std::string& extension_id,
WindowOpenDisposition disposition,
const gfx::Rect& initial_rect,
bool user_gesture) override;
void ProcessMediaAccessRequest(content::WebContents* web_contents,
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback,
const Extension* extension) override;
bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host,
const GURL& security_origin,
blink::mojom::MediaStreamType type,
const Extension* extension) override;
ExtensionHostQueue* GetExtensionHostQueue() const override;
content::PictureInPictureResult EnterPictureInPicture(
content::WebContents* web_contents,
const viz::SurfaceId& surface_id,
const gfx::Size& natural_size) override;
void ExitPictureInPicture() override;
private:
DISALLOW_COPY_AND_ASSIGN(AtomExtensionHostDelegate);
};
} // namespace extensions
#endif // SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_HOST_DELEGATE_H_

View file

@ -0,0 +1,158 @@
// 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/atom_extension_loader.h"
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/sequenced_task_runner.h"
#include "base/task_runner_util.h"
#include "base/threading/thread_restrictions.h"
#include "extensions/browser/extension_file_task_runner.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/file_util.h"
namespace extensions {
using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior;
namespace {
scoped_refptr<const Extension> LoadUnpacked(
const base::FilePath& extension_dir) {
// app_shell only supports unpacked extensions.
// NOTE: If you add packed extension support consider removing the flag
// FOLLOW_SYMLINKS_ANYWHERE below. Packed extensions should not have symlinks.
if (!base::DirectoryExists(extension_dir)) {
LOG(ERROR) << "Extension directory not found: "
<< extension_dir.AsUTF8Unsafe();
return nullptr;
}
int load_flags = Extension::FOLLOW_SYMLINKS_ANYWHERE;
std::string load_error;
scoped_refptr<Extension> extension = file_util::LoadExtension(
extension_dir, Manifest::COMMAND_LINE, load_flags, &load_error);
if (!extension.get()) {
LOG(ERROR) << "Loading extension at " << extension_dir.value()
<< " failed with: " << load_error;
return nullptr;
}
// Log warnings.
if (extension->install_warnings().size()) {
LOG(WARNING) << "Warnings loading extension at " << extension_dir.value()
<< ":";
for (const auto& warning : extension->install_warnings())
LOG(WARNING) << warning.message;
}
return extension;
}
} // namespace
AtomExtensionLoader::AtomExtensionLoader(
content::BrowserContext* browser_context)
: browser_context_(browser_context),
extension_registrar_(browser_context, this),
weak_factory_(this) {}
AtomExtensionLoader::~AtomExtensionLoader() = default;
const Extension* AtomExtensionLoader::LoadExtension(
const base::FilePath& extension_dir) {
// TODO(nornagon): load extensions asynchronously on
// GetExtensionFileTaskRunner()
base::ScopedAllowBlockingForTesting allow_blocking;
scoped_refptr<const Extension> extension = LoadUnpacked(extension_dir);
if (extension)
extension_registrar_.AddExtension(extension);
return extension.get();
}
void AtomExtensionLoader::ReloadExtension(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 AtomExtensionLoader::FinishExtensionReload(
const ExtensionId old_extension_id,
scoped_refptr<const Extension> extension) {
if (extension) {
extension_registrar_.AddExtension(extension);
}
}
void AtomExtensionLoader::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 AtomExtensionLoader::PostActivateExtension(
scoped_refptr<const Extension> extension) {}
void AtomExtensionLoader::PostDeactivateExtension(
scoped_refptr<const Extension> extension) {}
void AtomExtensionLoader::LoadExtensionForReload(
const ExtensionId& extension_id,
const base::FilePath& path,
LoadErrorBehavior load_error_behavior) {
CHECK(!path.empty());
base::PostTaskAndReplyWithResult(
GetExtensionFileTaskRunner().get(), FROM_HERE,
base::BindOnce(&LoadUnpacked, path),
base::BindOnce(&AtomExtensionLoader::FinishExtensionReload,
weak_factory_.GetWeakPtr(), extension_id));
did_schedule_reload_ = true;
}
bool AtomExtensionLoader::CanEnableExtension(const Extension* extension) {
return true;
}
bool AtomExtensionLoader::CanDisableExtension(const Extension* extension) {
// Extensions cannot be disabled by the user.
return false;
}
bool AtomExtensionLoader::ShouldBlockExtension(const Extension* extension) {
return false;
}
} // namespace extensions

View file

@ -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 SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_LOADER_H_
#define SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_LOADER_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "extensions/browser/extension_registrar.h"
#include "extensions/common/extension_id.h"
namespace base {
class FilePath;
} // namespace base
namespace content {
class BrowserContext;
} // namespace content
namespace extensions {
class Extension;
// Handles extension loading and reloading using ExtensionRegistrar.
class AtomExtensionLoader : public ExtensionRegistrar::Delegate {
public:
explicit AtomExtensionLoader(content::BrowserContext* browser_context);
~AtomExtensionLoader() override;
// Loads an unpacked extension from a directory synchronously. Returns the
// extension on success, or nullptr otherwise.
const Extension* LoadExtension(const base::FilePath& extension_dir);
// 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(ExtensionId extension_id);
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,
scoped_refptr<const Extension> extension);
// 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 LoadExtensionForReload(
const ExtensionId& extension_id,
const base::FilePath& path,
ExtensionRegistrar::LoadErrorBehavior load_error_behavior) override;
bool CanEnableExtension(const Extension* extension) override;
bool CanDisableExtension(const Extension* extension) override;
bool ShouldBlockExtension(const Extension* extension) override;
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<AtomExtensionLoader> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AtomExtensionLoader);
};
} // namespace extensions
#endif // SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_LOADER_H_

View file

@ -0,0 +1,186 @@
// 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.
#include "shell/browser/extensions/atom_extension_system.h"
#include <memory>
#include <string>
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/task/post_task.h"
#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"
#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"
#include "shell/browser/extensions/atom_extension_loader.h"
using content::BrowserContext;
using content::BrowserThread;
namespace extensions {
AtomExtensionSystem::AtomExtensionSystem(BrowserContext* browser_context)
: browser_context_(browser_context),
store_factory_(new ValueStoreFactoryImpl(browser_context->GetPath())),
weak_factory_(this) {}
AtomExtensionSystem::~AtomExtensionSystem() = default;
const Extension* AtomExtensionSystem::LoadExtension(
const base::FilePath& extension_dir) {
return extension_loader_->LoadExtension(extension_dir);
}
const Extension* AtomExtensionSystem::LoadApp(const base::FilePath& app_dir) {
CHECK(false); // Should never call LoadApp
return nullptr;
}
void AtomExtensionSystem::FinishInitialization() {
// Inform the rest of the extensions system to start.
ready_.Signal();
content::NotificationService::current()->Notify(
NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
content::Source<BrowserContext>(browser_context_),
content::NotificationService::NoDetails());
}
void AtomExtensionSystem::ReloadExtension(const ExtensionId& extension_id) {
extension_loader_->ReloadExtension(extension_id);
}
void AtomExtensionSystem::Shutdown() {
extension_loader_.reset();
}
void AtomExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
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>();
extension_loader_ = std::make_unique<AtomExtensionLoader>(browser_context_);
}
void AtomExtensionSystem::InitForIncognitoProfile() {
NOTREACHED();
}
ExtensionService* AtomExtensionSystem::extension_service() {
return nullptr;
}
RuntimeData* AtomExtensionSystem::runtime_data() {
return runtime_data_.get();
}
ManagementPolicy* AtomExtensionSystem::management_policy() {
return nullptr;
}
ServiceWorkerManager* AtomExtensionSystem::service_worker_manager() {
return service_worker_manager_.get();
}
SharedUserScriptMaster* AtomExtensionSystem::shared_user_script_master() {
return new SharedUserScriptMaster(browser_context_);
}
StateStore* AtomExtensionSystem::state_store() {
return nullptr;
}
StateStore* AtomExtensionSystem::rules_store() {
return nullptr;
}
scoped_refptr<ValueStoreFactory> AtomExtensionSystem::store_factory() {
return store_factory_;
}
InfoMap* AtomExtensionSystem::info_map() {
if (!info_map_.get())
info_map_ = new InfoMap;
return info_map_.get();
}
QuotaService* AtomExtensionSystem::quota_service() {
return quota_service_.get();
}
AppSorting* AtomExtensionSystem::app_sorting() {
return app_sorting_.get();
}
void AtomExtensionSystem::RegisterExtensionWithRequestContexts(
const Extension* extension,
const base::Closure& callback) {
base::PostTaskWithTraitsAndReply(
FROM_HERE, {BrowserThread::IO},
base::Bind(&InfoMap::AddExtension, info_map(),
base::RetainedRef(extension), base::Time::Now(), false, false),
callback);
}
void AtomExtensionSystem::UnregisterExtensionWithRequestContexts(
const std::string& extension_id,
const UnloadedExtensionReason reason) {}
const base::OneShotEvent& AtomExtensionSystem::ready() const {
return ready_;
}
ContentVerifier* AtomExtensionSystem::content_verifier() {
return nullptr;
}
std::unique_ptr<ExtensionSet> AtomExtensionSystem::GetDependentExtensions(
const Extension* extension) {
return std::make_unique<ExtensionSet>();
}
void AtomExtensionSystem::InstallUpdate(
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 */);
}
bool AtomExtensionSystem::FinishDelayedInstallationIfReady(
const std::string& extension_id,
bool install_immediately) {
NOTREACHED();
return false;
}
void AtomExtensionSystem::OnExtensionRegisteredWithRequestContexts(
scoped_refptr<Extension> extension) {
ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_);
registry->AddReady(extension);
registry->TriggerOnReady(extension.get());
}
} // namespace extensions

View file

@ -0,0 +1,119 @@
// 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 SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_SYSTEM_H_
#define SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_SYSTEM_H_
#include <memory>
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/one_shot_event.h"
#include "extensions/browser/extension_system.h"
namespace base {
class FilePath;
}
namespace content {
class BrowserContext;
}
namespace extensions {
class AtomExtensionLoader;
class ValueStoreFactory;
// A simplified version of ExtensionSystem for app_shell. Allows
// app_shell to skip initialization of services it doesn't need.
class AtomExtensionSystem : public ExtensionSystem {
public:
using InstallUpdateCallback = ExtensionSystem::InstallUpdateCallback;
explicit AtomExtensionSystem(content::BrowserContext* browser_context);
~AtomExtensionSystem() override;
// Loads an unpacked extension from a directory. Returns the extension on
// success, or nullptr otherwise.
const Extension* LoadExtension(const base::FilePath& extension_dir);
// Loads an unpacked platform app from a directory. Returns the extension on
// success, or nullptr otherwise.
// Currently this just calls LoadExtension, as apps are not loaded differently
// than other extensions. Use LaunchApp() to actually launch the loaded app.
const Extension* LoadApp(const base::FilePath& app_dir);
// Finish initialization for the shell extension system.
void FinishInitialization();
// Reloads the extension with id |extension_id|.
void ReloadExtension(const ExtensionId& extension_id);
// KeyedService implementation:
void Shutdown() override;
// ExtensionSystem implementation:
void InitForRegularProfile(bool extensions_enabled) override;
void InitForIncognitoProfile() override;
ExtensionService* extension_service() override;
RuntimeData* runtime_data() override;
ManagementPolicy* management_policy() override;
ServiceWorkerManager* service_worker_manager() override;
SharedUserScriptMaster* shared_user_script_master() override;
StateStore* state_store() override;
StateStore* rules_store() override;
scoped_refptr<ValueStoreFactory> store_factory() override;
InfoMap* info_map() override;
QuotaService* quota_service() override;
AppSorting* app_sorting() override;
void RegisterExtensionWithRequestContexts(
const Extension* extension,
const base::Closure& callback) override;
void UnregisterExtensionWithRequestContexts(
const std::string& extension_id,
const UnloadedExtensionReason reason) override;
const base::OneShotEvent& ready() const override;
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;
private:
void OnExtensionRegisteredWithRequestContexts(
scoped_refptr<Extension> extension);
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<RuntimeData> runtime_data_;
std::unique_ptr<QuotaService> quota_service_;
std::unique_ptr<SharedUserScriptMaster> shared_user_script_master_;
std::unique_ptr<AppSorting> app_sorting_;
std::unique_ptr<AtomExtensionLoader> extension_loader_;
scoped_refptr<ValueStoreFactory> store_factory_;
// Signaled when the extension system has completed its startup tasks.
base::OneShotEvent ready_;
base::WeakPtrFactory<AtomExtensionSystem> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AtomExtensionSystem);
};
} // namespace extensions
#endif // SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_SYSTEM_H_

View file

@ -0,0 +1,51 @@
// 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.
#include "shell/browser/extensions/atom_extension_system_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/extension_prefs_factory.h"
#include "extensions/browser/extension_registry_factory.h"
#include "shell/browser/extensions/atom_extension_system.h"
using content::BrowserContext;
namespace extensions {
ExtensionSystem* AtomExtensionSystemFactory::GetForBrowserContext(
BrowserContext* context) {
return static_cast<AtomExtensionSystem*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}
// static
AtomExtensionSystemFactory* AtomExtensionSystemFactory::GetInstance() {
return base::Singleton<AtomExtensionSystemFactory>::get();
}
AtomExtensionSystemFactory::AtomExtensionSystemFactory()
: ExtensionSystemProvider("AtomExtensionSystem",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(ExtensionPrefsFactory::GetInstance());
DependsOn(ExtensionRegistryFactory::GetInstance());
}
AtomExtensionSystemFactory::~AtomExtensionSystemFactory() {}
KeyedService* AtomExtensionSystemFactory::BuildServiceInstanceFor(
BrowserContext* context) const {
return new AtomExtensionSystem(context);
}
BrowserContext* AtomExtensionSystemFactory::GetBrowserContextToUse(
BrowserContext* context) const {
// Use a separate instance for incognito.
return context;
}
bool AtomExtensionSystemFactory::ServiceIsCreatedWithBrowserContext() const {
return true;
}
} // namespace extensions

View file

@ -0,0 +1,41 @@
// 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 SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_SYSTEM_FACTORY_H_
#define SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_SYSTEM_FACTORY_H_
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "extensions/browser/extension_system_provider.h"
namespace extensions {
// A factory that provides AtomExtensionSystem.
class AtomExtensionSystemFactory : public ExtensionSystemProvider {
public:
// ExtensionSystemProvider implementation:
ExtensionSystem* GetForBrowserContext(
content::BrowserContext* context) override;
static AtomExtensionSystemFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<AtomExtensionSystemFactory>;
AtomExtensionSystemFactory();
~AtomExtensionSystemFactory() override;
// BrowserContextKeyedServiceFactory implementation:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
DISALLOW_COPY_AND_ASSIGN(AtomExtensionSystemFactory);
};
} // namespace extensions
#endif // SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_SYSTEM_FACTORY_H_

View file

@ -0,0 +1,26 @@
// 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.
#include "shell/browser/extensions/atom_extension_web_contents_observer.h"
namespace extensions {
AtomExtensionWebContentsObserver::AtomExtensionWebContentsObserver(
content::WebContents* web_contents)
: ExtensionWebContentsObserver(web_contents) {}
AtomExtensionWebContentsObserver::~AtomExtensionWebContentsObserver() {}
void AtomExtensionWebContentsObserver::CreateForWebContents(
content::WebContents* web_contents) {
content::WebContentsUserData<
AtomExtensionWebContentsObserver>::CreateForWebContents(web_contents);
// Initialize this instance if necessary.
FromWebContents(web_contents)->Initialize();
}
WEB_CONTENTS_USER_DATA_KEY_IMPL(AtomExtensionWebContentsObserver)
} // namespace extensions

View file

@ -0,0 +1,37 @@
// 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 SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_WEB_CONTENTS_OBSERVER_H_
#define SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_WEB_CONTENTS_OBSERVER_H_
#include "base/macros.h"
#include "content/public/browser/web_contents_user_data.h"
#include "extensions/browser/extension_web_contents_observer.h"
namespace extensions {
// The app_shell version of ExtensionWebContentsObserver.
class AtomExtensionWebContentsObserver
: public ExtensionWebContentsObserver,
public content::WebContentsUserData<AtomExtensionWebContentsObserver> {
public:
~AtomExtensionWebContentsObserver() override;
// Creates and initializes an instance of this class for the given
// |web_contents|, if it doesn't already exist.
static void CreateForWebContents(content::WebContents* web_contents);
private:
friend class content::WebContentsUserData<AtomExtensionWebContentsObserver>;
explicit AtomExtensionWebContentsObserver(content::WebContents* web_contents);
WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(AtomExtensionWebContentsObserver);
};
} // namespace extensions
#endif // SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSION_WEB_CONTENTS_OBSERVER_H_

View file

@ -0,0 +1,300 @@
// 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.
#include "shell/browser/extensions/atom_extensions_browser_client.h"
#include <utility>
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/task/post_task.h"
#include "build/build_config.h"
#include "components/version_info/version_info.h"
#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/render_frame_host.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/common/user_agent.h"
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/component_extension_resource_manager.h"
#include "extensions/browser/core_extensions_browser_api_provider.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/mojo/interface_registration.h"
#include "extensions/browser/null_app_sorting.h"
#include "extensions/browser/updater/null_extension_cache.h"
#include "extensions/browser/url_request_util.h"
#include "extensions/common/features/feature_channel.h"
#include "shell/browser/atom_browser_client.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/browser.h"
#include "shell/browser/extensions/api/runtime/atom_runtime_api_delegate.h"
#include "shell/browser/extensions/atom_extension_host_delegate.h"
#include "shell/browser/extensions/atom_extension_system_factory.h"
#include "shell/browser/extensions/atom_extension_web_contents_observer.h"
// #include "shell/browser/extensions/atom_extensions_api_client.h"
// #include "shell/browser/extensions/atom_extensions_browser_api_provider.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "shell/browser/extensions/atom_navigation_ui_data.h"
using content::BrowserContext;
using content::BrowserThread;
namespace electron {
AtomExtensionsBrowserClient::AtomExtensionsBrowserClient()
: api_client_(new extensions::ExtensionsAPIClient),
// : api_client_(new extensions::AtomExtensionsAPIClient),
extension_cache_(new extensions::NullExtensionCache()) {
// app_shell does not have a concept of channel yet, so leave UNKNOWN to
// enable all channel-dependent extension APIs.
extensions::SetCurrentChannel(version_info::Channel::UNKNOWN);
AddAPIProvider(
std::make_unique<extensions::CoreExtensionsBrowserAPIProvider>());
// AddAPIProvider(std::make_unique<AtomExtensionsBrowserAPIProvider>());
}
AtomExtensionsBrowserClient::~AtomExtensionsBrowserClient() {}
bool AtomExtensionsBrowserClient::IsShuttingDown() {
return electron::Browser::Get()->is_shutting_down();
}
bool AtomExtensionsBrowserClient::AreExtensionsDisabled(
const base::CommandLine& command_line,
BrowserContext* context) {
return false;
}
bool AtomExtensionsBrowserClient::IsValidContext(BrowserContext* context) {
auto context_map = AtomBrowserContext::browser_context_map();
for (auto const& entry : context_map) {
if (entry.second && entry.second.get() == context)
return true;
}
return false;
}
bool AtomExtensionsBrowserClient::IsSameContext(BrowserContext* first,
BrowserContext* second) {
return first == second;
}
bool AtomExtensionsBrowserClient::HasOffTheRecordContext(
BrowserContext* context) {
return false;
}
BrowserContext* AtomExtensionsBrowserClient::GetOffTheRecordContext(
BrowserContext* context) {
// app_shell only supports a single context.
return nullptr;
}
BrowserContext* AtomExtensionsBrowserClient::GetOriginalContext(
BrowserContext* context) {
DCHECK(context);
if (context->IsOffTheRecord()) {
return AtomBrowserContext::From("", false).get();
} else {
return context;
}
}
bool AtomExtensionsBrowserClient::IsGuestSession(
BrowserContext* context) const {
return false;
}
bool AtomExtensionsBrowserClient::IsExtensionIncognitoEnabled(
const std::string& extension_id,
content::BrowserContext* context) const {
return false;
}
bool AtomExtensionsBrowserClient::CanExtensionCrossIncognito(
const extensions::Extension* extension,
content::BrowserContext* context) const {
return false;
}
base::FilePath AtomExtensionsBrowserClient::GetBundleResourcePath(
const network::ResourceRequest& request,
const base::FilePath& extension_resources_path,
int* resource_id) const {
*resource_id = 0;
return base::FilePath();
}
void AtomExtensionsBrowserClient::LoadResourceFromResourceBundle(
const network::ResourceRequest& request,
network::mojom::URLLoaderRequest loader,
const base::FilePath& resource_relative_path,
int resource_id,
const std::string& content_security_policy,
network::mojom::URLLoaderClientPtr client,
bool send_cors_header) {
NOTREACHED() << "Load resources from bundles not supported.";
}
bool AtomExtensionsBrowserClient::AllowCrossRendererResourceLoad(
const GURL& url,
content::ResourceType resource_type,
ui::PageTransition page_transition,
int child_id,
bool is_incognito,
const extensions::Extension* extension,
const extensions::ExtensionSet& extensions,
const extensions::ProcessMap& process_map) {
bool allowed = false;
if (extensions::url_request_util::AllowCrossRendererResourceLoad(
url, resource_type, page_transition, child_id, is_incognito,
extension, extensions, process_map, &allowed)) {
return allowed;
}
// Couldn't determine if resource is allowed. Block the load.
return false;
}
PrefService* AtomExtensionsBrowserClient::GetPrefServiceForContext(
BrowserContext* context) {
return static_cast<AtomBrowserContext*>(context)->prefs();
}
void AtomExtensionsBrowserClient::GetEarlyExtensionPrefsObservers(
content::BrowserContext* context,
std::vector<extensions::EarlyExtensionPrefsObserver*>* observers) const {}
extensions::ProcessManagerDelegate*
AtomExtensionsBrowserClient::GetProcessManagerDelegate() const {
return NULL;
}
std::unique_ptr<extensions::ExtensionHostDelegate> AtomExtensionsBrowserClient::
CreateExtensionHostDelegate() { // TODO(samuelmaddock):
return base::WrapUnique(new extensions::AtomExtensionHostDelegate);
}
bool AtomExtensionsBrowserClient::DidVersionUpdate(BrowserContext* context) {
// TODO(jamescook): We might want to tell extensions when app_shell updates.
return false;
}
void AtomExtensionsBrowserClient::PermitExternalProtocolHandler() {}
bool AtomExtensionsBrowserClient::IsInDemoMode() {
return false;
}
bool AtomExtensionsBrowserClient::IsScreensaverInDemoMode(
const std::string& app_id) {
return false;
}
bool AtomExtensionsBrowserClient::IsRunningInForcedAppMode() {
return false;
}
bool AtomExtensionsBrowserClient::IsAppModeForcedForApp(
const extensions::ExtensionId& extension_id) {
return false;
}
bool AtomExtensionsBrowserClient::IsLoggedInAsPublicAccount() {
return false;
}
extensions::ExtensionSystemProvider*
AtomExtensionsBrowserClient::GetExtensionSystemFactory() {
return extensions::AtomExtensionSystemFactory::GetInstance();
}
void AtomExtensionsBrowserClient::RegisterExtensionInterfaces(
service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>*
registry,
content::RenderFrameHost* render_frame_host,
const extensions::Extension* extension) const {
RegisterInterfacesForExtension(registry, render_frame_host, extension);
}
std::unique_ptr<extensions::RuntimeAPIDelegate>
AtomExtensionsBrowserClient::CreateRuntimeAPIDelegate(
content::BrowserContext* context) const {
return std::make_unique<extensions::AtomRuntimeAPIDelegate>(context);
}
const extensions::ComponentExtensionResourceManager*
AtomExtensionsBrowserClient::GetComponentExtensionResourceManager() {
return NULL;
}
void AtomExtensionsBrowserClient::BroadcastEventToRenderers(
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> args) {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&AtomExtensionsBrowserClient::BroadcastEventToRenderers,
base::Unretained(this), histogram_value, event_name,
std::move(args)));
return;
}
std::unique_ptr<extensions::Event> event(
new extensions::Event(histogram_value, event_name, std::move(args)));
auto context_map = AtomBrowserContext::browser_context_map();
for (auto const& entry : context_map) {
if (entry.second) {
extensions::EventRouter::Get(entry.second.get())
->BroadcastEvent(std::move(event));
}
}
}
extensions::ExtensionCache* AtomExtensionsBrowserClient::GetExtensionCache() {
return extension_cache_.get();
}
bool AtomExtensionsBrowserClient::IsBackgroundUpdateAllowed() {
return true;
}
bool AtomExtensionsBrowserClient::IsMinBrowserVersionSupported(
const std::string& min_version) {
return true;
}
void AtomExtensionsBrowserClient::SetAPIClientForTest(
extensions::ExtensionsAPIClient* api_client) {
api_client_.reset(api_client);
}
extensions::ExtensionWebContentsObserver*
AtomExtensionsBrowserClient::GetExtensionWebContentsObserver(
content::WebContents* web_contents) {
return extensions::AtomExtensionWebContentsObserver::FromWebContents(
web_contents);
}
extensions::KioskDelegate* AtomExtensionsBrowserClient::GetKioskDelegate() {
return nullptr;
}
bool AtomExtensionsBrowserClient::IsLockScreenContext(
content::BrowserContext* context) {
return false;
}
std::string AtomExtensionsBrowserClient::GetApplicationLocale() {
return AtomBrowserClient::Get()->GetApplicationLocale();
}
std::string AtomExtensionsBrowserClient::GetUserAgent() const {
return AtomBrowserClient::Get()->GetUserAgent();
}
} // namespace electron

View file

@ -0,0 +1,139 @@
// 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 SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSIONS_BROWSER_CLIENT_H_
#define SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSIONS_BROWSER_CLIENT_H_
#include <memory>
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "extensions/browser/extensions_browser_client.h"
class PrefService;
namespace extensions {
class ExtensionsAPIClient;
class KioskDelegate;
class ProcessManagerDelegate;
class ProcessMap;
} // namespace extensions
namespace electron {
// An ExtensionsBrowserClient that supports a single content::BrowserContext
// with no related incognito context.
// Must be initialized via InitWithBrowserContext() once the BrowserContext is
// created.
class AtomExtensionsBrowserClient : public extensions::ExtensionsBrowserClient {
public:
AtomExtensionsBrowserClient();
~AtomExtensionsBrowserClient() override;
// ExtensionsBrowserClient overrides:
bool IsShuttingDown() override;
bool AreExtensionsDisabled(const base::CommandLine& command_line,
content::BrowserContext* context) override;
bool IsValidContext(content::BrowserContext* context) override;
bool IsSameContext(content::BrowserContext* first,
content::BrowserContext* second) override;
bool HasOffTheRecordContext(content::BrowserContext* context) override;
content::BrowserContext* GetOffTheRecordContext(
content::BrowserContext* context) override;
content::BrowserContext* GetOriginalContext(
content::BrowserContext* context) override;
bool IsGuestSession(content::BrowserContext* context) const override;
bool IsExtensionIncognitoEnabled(
const std::string& extension_id,
content::BrowserContext* context) const override;
bool CanExtensionCrossIncognito(
const extensions::Extension* extension,
content::BrowserContext* context) const override;
base::FilePath GetBundleResourcePath(
const network::ResourceRequest& request,
const base::FilePath& extension_resources_path,
int* resource_id) const override;
void LoadResourceFromResourceBundle(
const network::ResourceRequest& request,
network::mojom::URLLoaderRequest loader,
const base::FilePath& resource_relative_path,
int resource_id,
const std::string& content_security_policy,
network::mojom::URLLoaderClientPtr client,
bool send_cors_header) override;
bool AllowCrossRendererResourceLoad(
const GURL& url,
content::ResourceType resource_type,
ui::PageTransition page_transition,
int child_id,
bool is_incognito,
const extensions::Extension* extension,
const extensions::ExtensionSet& extensions,
const extensions::ProcessMap& process_map) override;
PrefService* GetPrefServiceForContext(
content::BrowserContext* context) override;
void GetEarlyExtensionPrefsObservers(
content::BrowserContext* context,
std::vector<extensions::EarlyExtensionPrefsObserver*>* observers)
const override;
extensions::ProcessManagerDelegate* GetProcessManagerDelegate()
const override;
std::unique_ptr<extensions::ExtensionHostDelegate>
CreateExtensionHostDelegate() override;
bool DidVersionUpdate(content::BrowserContext* context) override;
void PermitExternalProtocolHandler() override;
bool IsInDemoMode() override;
bool IsScreensaverInDemoMode(const std::string& app_id) override;
bool IsRunningInForcedAppMode() override;
bool IsAppModeForcedForApp(
const extensions::ExtensionId& extension_id) override;
bool IsLoggedInAsPublicAccount() override;
extensions::ExtensionSystemProvider* GetExtensionSystemFactory() override;
void RegisterExtensionInterfaces(
service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>*
registry,
content::RenderFrameHost* render_frame_host,
const extensions::Extension* extension) const override;
std::unique_ptr<extensions::RuntimeAPIDelegate> CreateRuntimeAPIDelegate(
content::BrowserContext* context) const override;
const extensions::ComponentExtensionResourceManager*
GetComponentExtensionResourceManager() override;
void BroadcastEventToRenderers(
extensions::events::HistogramValue histogram_value,
const std::string& event_name,
std::unique_ptr<base::ListValue> args) override;
extensions::ExtensionCache* GetExtensionCache() override;
bool IsBackgroundUpdateAllowed() override;
bool IsMinBrowserVersionSupported(const std::string& min_version) override;
extensions::ExtensionWebContentsObserver* GetExtensionWebContentsObserver(
content::WebContents* web_contents) override;
extensions::KioskDelegate* GetKioskDelegate() override;
bool IsLockScreenContext(content::BrowserContext* context) override;
std::string GetApplicationLocale() override;
std::string GetUserAgent() const override;
// |context| is the single BrowserContext used for IsValidContext().
// |pref_service| is used for GetPrefServiceForContext().
void InitWithBrowserContext(content::BrowserContext* context,
PrefService* pref_service);
// Sets the API client.
void SetAPIClientForTest(extensions::ExtensionsAPIClient* api_client);
private:
// Support for extension APIs.
std::unique_ptr<extensions::ExtensionsAPIClient> api_client_;
// The extension cache used for download and installation.
std::unique_ptr<extensions::ExtensionCache> extension_cache_;
DISALLOW_COPY_AND_ASSIGN(AtomExtensionsBrowserClient);
};
} // namespace electron
#endif // SHELL_BROWSER_EXTENSIONS_ATOM_EXTENSIONS_BROWSER_CLIENT_H_

View file

@ -0,0 +1,40 @@
// Copyright 2016 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/atom_navigation_ui_data.h"
#include <utility>
#include "content/public/browser/navigation_handle.h"
#include "extensions/common/constants.h"
namespace extensions {
AtomNavigationUIData::AtomNavigationUIData() {}
AtomNavigationUIData::AtomNavigationUIData(
content::NavigationHandle* navigation_handle) {
extension_data_ = std::make_unique<ExtensionNavigationUIData>(
navigation_handle, extension_misc::kUnknownTabId,
extension_misc::kUnknownWindowId);
}
AtomNavigationUIData::~AtomNavigationUIData() {}
std::unique_ptr<content::NavigationUIData> AtomNavigationUIData::Clone() {
std::unique_ptr<AtomNavigationUIData> copy =
std::make_unique<AtomNavigationUIData>();
if (extension_data_)
copy->SetExtensionNavigationUIData(extension_data_->DeepCopy());
return std::move(copy);
}
void AtomNavigationUIData::SetExtensionNavigationUIData(
std::unique_ptr<ExtensionNavigationUIData> extension_data) {
extension_data_ = std::move(extension_data);
}
} // namespace extensions

View file

@ -0,0 +1,48 @@
// Copyright 2016 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 SHELL_BROWSER_EXTENSIONS_ATOM_NAVIGATION_UI_DATA_H_
#define SHELL_BROWSER_EXTENSIONS_ATOM_NAVIGATION_UI_DATA_H_
#include <memory>
#include "base/macros.h"
#include "content/public/browser/navigation_ui_data.h"
#include "extensions/browser/extension_navigation_ui_data.h"
namespace extensions {
// PlzNavigate
// Contains data that is passed from the UI thread to the IO thread at the
// beginning of each navigation. The class is instantiated on the UI thread,
// then a copy created using Clone is passed to the content::ResourceRequestInfo
// on the IO thread.
class AtomNavigationUIData : public content::NavigationUIData {
public:
AtomNavigationUIData();
explicit AtomNavigationUIData(content::NavigationHandle* navigation_handle);
~AtomNavigationUIData() override;
// Creates a new ChromeNavigationUIData that is a deep copy of the original.
// Any changes to the original after the clone is created will not be
// reflected in the clone. |extension_data_| is deep copied.
std::unique_ptr<content::NavigationUIData> Clone() override;
void SetExtensionNavigationUIData(
std::unique_ptr<ExtensionNavigationUIData> extension_data);
ExtensionNavigationUIData* GetExtensionNavigationUIData() const {
return extension_data_.get();
}
private:
// Manages the lifetime of optional ExtensionNavigationUIData information.
std::unique_ptr<ExtensionNavigationUIData> extension_data_;
DISALLOW_COPY_AND_ASSIGN(AtomNavigationUIData);
};
} // namespace extensions
#endif // SHELL_BROWSER_EXTENSIONS_ATOM_NAVIGATION_UI_DATA_H_