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.
|
|
|
|
|
|
|
|
#include "libcef/browser/extensions/extensions_browser_client.h"
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
#include "libcef/browser/browser_context.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/browser/extensions/component_extension_resource_manager.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "libcef/browser/extensions/extension_system.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/browser/extensions/extension_system_factory.h"
|
2015-07-24 02:06:56 +02:00
|
|
|
#include "libcef/browser/extensions/extension_web_contents_observer.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/browser/extensions/extensions_api_client.h"
|
2018-09-04 11:43:21 +02:00
|
|
|
#include "libcef/browser/extensions/extensions_browser_api_provider.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "libcef/browser/request_context_impl.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2016-07-18 23:22:22 +02:00
|
|
|
#include "chrome/browser/browser_process.h"
|
2016-08-04 14:37:53 +02:00
|
|
|
#include "chrome/browser/extensions/chrome_url_request_util.h"
|
2016-07-18 23:22:22 +02:00
|
|
|
#include "chrome/browser/extensions/event_router_forwarder.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "content/public/browser/browser_context.h"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "content/public/browser/render_frame_host.h"
|
|
|
|
#include "extensions/browser/api/extensions_api_client.h"
|
|
|
|
#include "extensions/browser/api/runtime/runtime_api_delegate.h"
|
|
|
|
#include "extensions/browser/app_sorting.h"
|
2018-09-04 11:43:21 +02:00
|
|
|
#include "extensions/browser/core_extensions_browser_api_provider.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "extensions/browser/event_router.h"
|
|
|
|
#include "extensions/browser/extension_host_delegate.h"
|
2017-09-06 23:40:58 +02:00
|
|
|
#include "extensions/browser/mojo/interface_registration.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "extensions/browser/serial_extension_host_queue.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "extensions/browser/url_request_util.h"
|
2016-06-21 00:59:23 +02:00
|
|
|
#include "extensions/common/constants.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
using content::BrowserContext;
|
|
|
|
using content::BrowserThread;
|
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
CefExtensionsBrowserClient::CefExtensionsBrowserClient()
|
|
|
|
: api_client_(new CefExtensionsAPIClient),
|
2018-09-04 11:43:21 +02:00
|
|
|
resource_manager_(new CefComponentExtensionResourceManager) {
|
|
|
|
AddAPIProvider(std::make_unique<CoreExtensionsBrowserAPIProvider>());
|
|
|
|
AddAPIProvider(std::make_unique<CefExtensionsBrowserAPIProvider>());
|
|
|
|
}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefExtensionsBrowserClient::~CefExtensionsBrowserClient() {}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// static
|
|
|
|
CefExtensionsBrowserClient* CefExtensionsBrowserClient::Get() {
|
|
|
|
return static_cast<CefExtensionsBrowserClient*>(
|
|
|
|
ExtensionsBrowserClient::Get());
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
bool CefExtensionsBrowserClient::IsShuttingDown() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionsBrowserClient::AreExtensionsDisabled(
|
|
|
|
const base::CommandLine& command_line,
|
|
|
|
BrowserContext* context) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionsBrowserClient::IsValidContext(BrowserContext* context) {
|
2019-03-24 01:39:54 +01:00
|
|
|
return GetOriginalContext(context) != NULL;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionsBrowserClient::IsSameContext(BrowserContext* first,
|
|
|
|
BrowserContext* second) {
|
2016-08-24 11:28:52 +02:00
|
|
|
// Returns true if |first| and |second| share the same underlying
|
2019-03-22 23:11:51 +01:00
|
|
|
// CefBrowserContext.
|
2019-03-24 01:39:54 +01:00
|
|
|
return GetOriginalContext(first) == GetOriginalContext(second);
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionsBrowserClient::HasOffTheRecordContext(
|
|
|
|
BrowserContext* context) {
|
2017-08-04 00:55:19 +02:00
|
|
|
// CEF doesn't use incognito contexts.
|
2015-07-16 23:40:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserContext* CefExtensionsBrowserClient::GetOffTheRecordContext(
|
|
|
|
BrowserContext* context) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserContext* CefExtensionsBrowserClient::GetOriginalContext(
|
|
|
|
BrowserContext* context) {
|
2019-03-22 23:11:51 +01:00
|
|
|
return CefBrowserContext::GetForContext(context);
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool CefExtensionsBrowserClient::IsGuestSession(BrowserContext* context) const {
|
2015-07-16 23:40:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionsBrowserClient::IsExtensionIncognitoEnabled(
|
|
|
|
const std::string& extension_id,
|
|
|
|
content::BrowserContext* context) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionsBrowserClient::CanExtensionCrossIncognito(
|
|
|
|
const Extension* extension,
|
|
|
|
content::BrowserContext* context) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
base::FilePath CefExtensionsBrowserClient::GetBundleResourcePath(
|
|
|
|
const network::ResourceRequest& request,
|
|
|
|
const base::FilePath& extension_resources_path,
|
2019-07-16 19:59:21 +02:00
|
|
|
int* resource_id) const {
|
2019-05-01 21:09:59 +02:00
|
|
|
return chrome_url_request_util::GetBundleResourcePath(
|
2019-07-16 19:59:21 +02:00
|
|
|
request, extension_resources_path, resource_id);
|
2018-03-20 21:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefExtensionsBrowserClient::LoadResourceFromResourceBundle(
|
|
|
|
const network::ResourceRequest& request,
|
|
|
|
network::mojom::URLLoaderRequest loader,
|
|
|
|
const base::FilePath& resource_relative_path,
|
2019-07-16 19:59:21 +02:00
|
|
|
const int resource_id,
|
2018-03-20 21:15:08 +01:00
|
|
|
const std::string& content_security_policy,
|
|
|
|
network::mojom::URLLoaderClientPtr client,
|
|
|
|
bool send_cors_header) {
|
2019-05-01 21:09:59 +02:00
|
|
|
chrome_url_request_util::LoadResourceFromResourceBundle(
|
2019-07-16 19:59:21 +02:00
|
|
|
request, std::move(loader), resource_relative_path, resource_id,
|
2019-05-01 21:09:59 +02:00
|
|
|
content_security_policy, std::move(client), send_cors_header);
|
2018-03-20 21:15:08 +01:00
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
bool CefExtensionsBrowserClient::AllowCrossRendererResourceLoad(
|
2017-12-07 22:44:24 +01:00
|
|
|
const GURL& url,
|
|
|
|
content::ResourceType resource_type,
|
|
|
|
ui::PageTransition page_transition,
|
|
|
|
int child_id,
|
2015-07-16 23:40:01 +02:00
|
|
|
bool is_incognito,
|
|
|
|
const Extension* extension,
|
2017-12-07 22:44:24 +01:00
|
|
|
const ExtensionSet& extensions,
|
|
|
|
const ProcessMap& process_map) {
|
2015-07-16 23:40:01 +02:00
|
|
|
bool allowed = false;
|
|
|
|
if (url_request_util::AllowCrossRendererResourceLoad(
|
2017-12-07 22:44:24 +01:00
|
|
|
url, resource_type, page_transition, child_id, is_incognito,
|
|
|
|
extension, extensions, process_map, &allowed)) {
|
2015-07-16 23:40:01 +02:00
|
|
|
return allowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Couldn't determine if resource is allowed. Block the load.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrefService* CefExtensionsBrowserClient::GetPrefServiceForContext(
|
|
|
|
BrowserContext* context) {
|
2015-10-03 01:03:16 +02:00
|
|
|
return static_cast<CefBrowserContext*>(context)->GetPrefs();
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefExtensionsBrowserClient::GetEarlyExtensionPrefsObservers(
|
|
|
|
content::BrowserContext* context,
|
2019-07-16 19:59:21 +02:00
|
|
|
std::vector<EarlyExtensionPrefsObserver*>* observers) const {}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
ProcessManagerDelegate* CefExtensionsBrowserClient::GetProcessManagerDelegate()
|
|
|
|
const {
|
2015-07-16 23:40:01 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<ExtensionHostDelegate>
|
2015-07-16 23:40:01 +02:00
|
|
|
CefExtensionsBrowserClient::CreateExtensionHostDelegate() {
|
2017-08-04 00:55:19 +02:00
|
|
|
// CEF does not use the ExtensionHost constructor that calls this method.
|
2015-07-16 23:40:01 +02:00
|
|
|
NOTREACHED();
|
2016-04-27 22:38:52 +02:00
|
|
|
return std::unique_ptr<ExtensionHostDelegate>();
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
bool CefExtensionsBrowserClient::CreateBackgroundExtensionHost(
|
|
|
|
const Extension* extension,
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& url,
|
|
|
|
ExtensionHost** host) {
|
2019-03-22 23:11:51 +01:00
|
|
|
CefBrowserContext* browser_context_impl =
|
|
|
|
CefBrowserContext::GetForContext(browser_context);
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
// A CEF representation should always exist.
|
|
|
|
CefRefPtr<CefExtension> cef_extension =
|
|
|
|
browser_context_impl->extension_system()->GetExtension(extension->id());
|
|
|
|
DCHECK(cef_extension);
|
|
|
|
if (!cef_extension) {
|
|
|
|
// Cancel the background host creation.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always use the same request context that the extension was registered with.
|
|
|
|
// GetLoaderContext() will return NULL for internal extensions.
|
|
|
|
CefRefPtr<CefRequestContext> request_context =
|
|
|
|
cef_extension->GetLoaderContext();
|
|
|
|
if (!request_context) {
|
|
|
|
// Cancel the background host creation.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserHostImpl::CreateParams create_params;
|
|
|
|
create_params.url = url;
|
|
|
|
create_params.request_context = request_context;
|
|
|
|
|
|
|
|
CefRefPtr<CefExtensionHandler> handler = cef_extension->GetHandler();
|
|
|
|
if (handler.get() && handler->OnBeforeBackgroundBrowser(
|
|
|
|
cef_extension, url.spec(), create_params.client,
|
|
|
|
create_params.settings)) {
|
|
|
|
// Cancel the background host creation.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This triggers creation of the background host.
|
|
|
|
create_params.extension = extension;
|
|
|
|
create_params.extension_host_type =
|
|
|
|
extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
|
|
|
|
|
|
|
|
// Browser creation may fail under certain rare circumstances. Fail the
|
|
|
|
// background host creation in that case.
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
CefBrowserHostImpl::Create(create_params);
|
|
|
|
if (browser) {
|
|
|
|
*host = browser->extension_host();
|
|
|
|
DCHECK(*host);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
bool CefExtensionsBrowserClient::DidVersionUpdate(BrowserContext* context) {
|
|
|
|
// TODO(jamescook): We might want to tell extensions when app_shell updates.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefExtensionsBrowserClient::PermitExternalProtocolHandler() {}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2018-07-24 00:32:02 +02:00
|
|
|
bool CefExtensionsBrowserClient::IsInDemoMode() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
bool CefExtensionsBrowserClient::IsScreensaverInDemoMode(
|
|
|
|
const std::string& app_id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
bool CefExtensionsBrowserClient::IsRunningInForcedAppMode() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
bool CefExtensionsBrowserClient::IsAppModeForcedForApp(
|
|
|
|
const ExtensionId& extension_id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool CefExtensionsBrowserClient::IsLoggedInAsPublicAccount() {
|
2015-10-09 17:23:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
ExtensionSystemProvider*
|
|
|
|
CefExtensionsBrowserClient::GetExtensionSystemFactory() {
|
|
|
|
return CefExtensionSystemFactory::GetInstance();
|
|
|
|
}
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
void CefExtensionsBrowserClient::RegisterExtensionInterfaces(
|
|
|
|
service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>*
|
|
|
|
registry,
|
2015-07-16 23:40:01 +02:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
const Extension* extension) const {
|
2017-09-06 23:40:58 +02:00
|
|
|
RegisterInterfacesForExtension(registry, render_frame_host, extension);
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<RuntimeAPIDelegate>
|
2015-07-16 23:40:01 +02:00
|
|
|
CefExtensionsBrowserClient::CreateRuntimeAPIDelegate(
|
|
|
|
content::BrowserContext* context) const {
|
|
|
|
// TODO(extensions): Implement to support Apps.
|
|
|
|
NOTREACHED();
|
2016-08-31 13:25:56 +02:00
|
|
|
return nullptr;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const ComponentExtensionResourceManager*
|
|
|
|
CefExtensionsBrowserClient::GetComponentExtensionResourceManager() {
|
|
|
|
return resource_manager_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefExtensionsBrowserClient::BroadcastEventToRenderers(
|
2015-08-14 16:41:08 +02:00
|
|
|
events::HistogramValue histogram_value,
|
2015-07-16 23:40:01 +02:00
|
|
|
const std::string& event_name,
|
2019-10-01 15:55:16 +02:00
|
|
|
std::unique_ptr<base::ListValue> args,
|
|
|
|
bool dispatch_to_off_the_record_profiles) {
|
2017-05-17 11:29:28 +02:00
|
|
|
g_browser_process->extension_event_router_forwarder()
|
|
|
|
->BroadcastEventToRenderers(histogram_value, event_name, std::move(args),
|
2019-10-01 15:55:16 +02:00
|
|
|
GURL(), dispatch_to_off_the_record_profiles);
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ExtensionCache* CefExtensionsBrowserClient::GetExtensionCache() {
|
|
|
|
// Only used by Chrome via ExtensionService.
|
|
|
|
NOTREACHED();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionsBrowserClient::IsBackgroundUpdateAllowed() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionsBrowserClient::IsMinBrowserVersionSupported(
|
|
|
|
const std::string& min_version) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-24 02:06:56 +02:00
|
|
|
ExtensionWebContentsObserver*
|
|
|
|
CefExtensionsBrowserClient::GetExtensionWebContentsObserver(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
return CefExtensionWebContentsObserver::FromWebContents(web_contents);
|
|
|
|
}
|
|
|
|
|
2016-10-21 21:52:29 +02:00
|
|
|
KioskDelegate* CefExtensionsBrowserClient::GetKioskDelegate() {
|
|
|
|
NOTREACHED();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
bool CefExtensionsBrowserClient::IsLockScreenContext(
|
|
|
|
content::BrowserContext* context) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
std::string CefExtensionsBrowserClient::GetApplicationLocale() {
|
|
|
|
return g_browser_process->GetApplicationLocale();
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
ExtensionHostQueue* CefExtensionsBrowserClient::GetExtensionHostQueue() {
|
|
|
|
if (!extension_host_queue_)
|
|
|
|
extension_host_queue_.reset(new SerialExtensionHostQueue);
|
|
|
|
return extension_host_queue_.get();
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace extensions
|