2015-02-14 00:17:08 +01:00
|
|
|
// Copyright (c) 2015 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/browser_context.h"
|
|
|
|
#include "libcef/browser/content_browser_client.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/browser/extensions/extension_system.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
2017-12-07 22:44:24 +01:00
|
|
|
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "components/keyed_service/content/browser_context_dependency_manager.h"
|
|
|
|
#include "components/user_prefs/user_prefs.h"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "content/public/browser/storage_partition.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "extensions/browser/process_manager.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2016-08-31 13:25:56 +02:00
|
|
|
CefBrowserContext::CefBrowserContext(bool is_proxy)
|
2017-05-17 11:29:28 +02:00
|
|
|
: is_proxy_(is_proxy), extension_system_(NULL) {}
|
2015-02-14 00:17:08 +01:00
|
|
|
|
|
|
|
CefBrowserContext::~CefBrowserContext() {
|
2015-10-17 02:44:00 +02:00
|
|
|
// Should be cleared in Shutdown().
|
|
|
|
DCHECK(!resource_context_.get());
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
void CefBrowserContext::Initialize() {
|
2016-03-16 03:55:59 +01:00
|
|
|
content::BrowserContext::Initialize(this, GetPath());
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
resource_context_.reset(
|
|
|
|
new CefResourceContext(IsOffTheRecord(), GetHandler()));
|
|
|
|
|
|
|
|
// This must be called before creating any services to avoid hitting
|
|
|
|
// DependencyManager::AssertContextWasntDestroyed when creating/destroying
|
|
|
|
// multiple browser contexts (due to pointer address reuse).
|
|
|
|
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
|
|
|
|
this);
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
const bool extensions_enabled = extensions::ExtensionsEnabled();
|
|
|
|
if (extensions_enabled) {
|
|
|
|
// Create the custom ExtensionSystem first because other KeyedServices
|
|
|
|
// depend on it.
|
2016-08-24 11:28:52 +02:00
|
|
|
// The same CefExtensionSystem instance is shared by CefBrowserContextImpl
|
|
|
|
// and CefBrowserContextProxy objects.
|
2015-07-16 23:40:01 +02:00
|
|
|
extension_system_ = static_cast<extensions::CefExtensionSystem*>(
|
|
|
|
extensions::ExtensionSystem::Get(this));
|
2016-08-31 13:25:56 +02:00
|
|
|
if (is_proxy_) {
|
|
|
|
DCHECK(extension_system_->initialized());
|
|
|
|
} else {
|
2016-08-24 11:28:52 +02:00
|
|
|
extension_system_->InitForRegularProfile(true);
|
2016-08-31 13:25:56 +02:00
|
|
|
}
|
2017-04-20 21:28:17 +02:00
|
|
|
resource_context_->set_extensions_info_map(extension_system_->info_map());
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
// Make sure the ProcessManager is created so that it receives extension
|
|
|
|
// load notifications. This is necessary for the proper initialization of
|
|
|
|
// background/event pages.
|
|
|
|
extensions::ProcessManager::Get(this);
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
2017-04-20 21:28:17 +02:00
|
|
|
}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
void CefBrowserContext::PostInitialize() {
|
2015-07-16 23:40:01 +02:00
|
|
|
// Spell checking support and possibly other subsystems retrieve the
|
|
|
|
// PrefService associated with a BrowserContext via UserPrefs::Get().
|
2015-09-09 16:05:39 +02:00
|
|
|
PrefService* pref_service = GetPrefs();
|
2015-07-16 23:40:01 +02:00
|
|
|
DCHECK(pref_service);
|
|
|
|
user_prefs::UserPrefs::Set(this, pref_service);
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
const bool extensions_enabled = extensions::ExtensionsEnabled();
|
2016-08-31 13:25:56 +02:00
|
|
|
if (extensions_enabled && !is_proxy_)
|
2015-07-16 23:40:01 +02:00
|
|
|
extension_system_->Init();
|
2017-12-07 22:44:24 +01:00
|
|
|
|
|
|
|
ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
|
|
|
|
this, resource_context_.get());
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
void CefBrowserContext::Shutdown() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2016-08-04 14:37:53 +02:00
|
|
|
// Send notifications to clean up objects associated with this Profile.
|
|
|
|
MaybeSendDestroyedNotification();
|
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext(
|
|
|
|
resource_context_.get());
|
|
|
|
|
2016-08-31 13:25:56 +02:00
|
|
|
// Remove any BrowserContextKeyedServiceFactory associations. This must be
|
|
|
|
// called before the ProxyService owned by CefBrowserContextImpl is destroyed.
|
|
|
|
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
|
|
|
|
this);
|
|
|
|
|
|
|
|
if (!is_proxy_) {
|
|
|
|
// Shuts down the storage partitions associated with this browser context.
|
|
|
|
// This must be called before the browser context is actually destroyed
|
|
|
|
// and before a clean-up task for its corresponding IO thread residents
|
|
|
|
// (e.g. ResourceContext) is posted, so that the classes that hung on
|
|
|
|
// StoragePartition can have time to do necessary cleanups on IO thread.
|
|
|
|
ShutdownStoragePartitions();
|
|
|
|
}
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
if (resource_context_.get()) {
|
|
|
|
// Destruction of the ResourceContext will trigger destruction of all
|
|
|
|
// associated URLRequests.
|
2017-05-17 11:29:28 +02:00
|
|
|
content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
|
|
|
|
resource_context_.release());
|
2015-10-17 02:44:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
content::ResourceContext* CefBrowserContext::GetResourceContext() {
|
|
|
|
return resource_context_.get();
|
|
|
|
}
|
2015-10-17 02:44:00 +02:00
|
|
|
|
2019-02-01 17:42:40 +01:00
|
|
|
content::ClientHintsControllerDelegate*
|
|
|
|
CefBrowserContext::GetClientHintsControllerDelegate() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
net::URLRequestContextGetter* CefBrowserContext::GetRequestContext() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
return GetDefaultStoragePartition(this)->GetURLRequestContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
net::URLRequestContextGetter* CefBrowserContext::CreateMediaRequestContext() {
|
|
|
|
return GetRequestContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
net::URLRequestContextGetter*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContext::CreateMediaRequestContextForStoragePartition(
|
2016-05-25 01:35:43 +02:00
|
|
|
const base::FilePath& partition_path,
|
|
|
|
bool in_memory) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
ChromeZoomLevelPrefs* CefBrowserContext::GetZoomLevelPrefs() {
|
|
|
|
return static_cast<ChromeZoomLevelPrefs*>(
|
|
|
|
GetStoragePartition(this, NULL)->GetZoomLevelDelegate());
|
|
|
|
}
|
2016-10-17 20:14:44 +02:00
|
|
|
|
2018-07-24 00:32:02 +02:00
|
|
|
scoped_refptr<network::SharedURLLoaderFactory>
|
|
|
|
CefBrowserContext::GetURLLoaderFactory() {
|
|
|
|
return GetDefaultStoragePartition(this)
|
|
|
|
->GetURLLoaderFactoryForBrowserProcess();
|
|
|
|
}
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
void CefBrowserContext::OnRenderFrameDeleted(int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
bool is_main_frame,
|
|
|
|
bool is_guest_view) {
|
2017-02-14 23:27:19 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
2016-10-17 20:14:44 +02:00
|
|
|
if (resource_context_ && is_main_frame) {
|
|
|
|
DCHECK_GE(render_process_id, 0);
|
2017-02-14 23:27:19 +01:00
|
|
|
// Using base::Unretained() is safe because both this callback and possible
|
|
|
|
// deletion of |resource_context_| will execute on the IO thread, and this
|
|
|
|
// callback will be executed first.
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
2017-05-17 11:29:28 +02:00
|
|
|
base::Bind(&CefResourceContext::ClearPluginLoadDecision,
|
|
|
|
base::Unretained(resource_context_.get()),
|
|
|
|
render_process_id));
|
2016-10-17 20:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
void CefBrowserContext::OnPurgePluginListCache() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
if (resource_context_) {
|
|
|
|
// Using base::Unretained() is safe because both this callback and possible
|
|
|
|
// deletion of |resource_context_| will execute on the IO thread, and this
|
|
|
|
// callback will be executed first.
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
2017-05-17 11:29:28 +02:00
|
|
|
base::Bind(&CefResourceContext::ClearPluginLoadDecision,
|
|
|
|
base::Unretained(resource_context_.get()), -1));
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
2016-10-17 20:14:44 +02:00
|
|
|
}
|