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"
|
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"
|
2016-04-27 22:38:52 +02:00
|
|
|
#include "extensions/browser/extension_protocols.h"
|
|
|
|
#include "extensions/common/constants.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
base::AtomicRefCount CefBrowserContext::DebugObjCt = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CefBrowserContext::CefBrowserContext()
|
2015-07-16 23:40:01 +02:00
|
|
|
: extension_system_(NULL) {
|
2015-02-14 00:17:08 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
base::AtomicRefCountInc(&DebugObjCt);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
base::AtomicRefCountDec(&DebugObjCt);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
void CefBrowserContext::Initialize() {
|
2016-03-16 03:55:59 +01:00
|
|
|
content::BrowserContext::Initialize(this, GetPath());
|
|
|
|
|
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.
|
|
|
|
extension_system_ = static_cast<extensions::CefExtensionSystem*>(
|
|
|
|
extensions::ExtensionSystem::Get(this));
|
|
|
|
extension_system_->InitForRegularProfile(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
resource_context_.reset(new CefResourceContext(
|
|
|
|
IsOffTheRecord(),
|
2015-09-25 13:59:30 +02:00
|
|
|
extensions_enabled ? extension_system_->info_map() : NULL,
|
|
|
|
GetHandler()));
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
|
|
|
|
this);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
if (extensions_enabled)
|
|
|
|
extension_system_->Init();
|
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
void CefBrowserContext::CreateProtocolHandlers(
|
|
|
|
content::ProtocolHandlerMap* protocol_handlers) {
|
|
|
|
if (extensions::ExtensionsEnabled()) {
|
|
|
|
// Handle only chrome-extension:// requests. CEF does not support
|
|
|
|
// chrome-extension-resource:// requests (it does not store shared extension
|
|
|
|
// data in its installation directory).
|
|
|
|
extensions::InfoMap* extension_info_map =
|
|
|
|
extension_system()->info_map();
|
|
|
|
(*protocol_handlers)[extensions::kExtensionScheme] =
|
|
|
|
linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
|
|
|
|
extensions::CreateExtensionProtocolHandler(
|
|
|
|
IsOffTheRecord(), extension_info_map).release());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
void CefBrowserContext::Shutdown() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
if (resource_context_.get()) {
|
|
|
|
// Destruction of the ResourceContext will trigger destruction of all
|
|
|
|
// associated URLRequests.
|
|
|
|
content::BrowserThread::DeleteSoon(
|
|
|
|
content::BrowserThread::IO, FROM_HERE, resource_context_.release());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove any BrowserContextKeyedServiceFactory associations. This must be
|
|
|
|
// called before the ProxyService owned by CefBrowserContextImpl is destroyed.
|
|
|
|
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
|
|
|
|
this);
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
content::ResourceContext* CefBrowserContext::GetResourceContext() {
|
|
|
|
return resource_context_.get();
|
|
|
|
}
|
2015-10-17 02:44:00 +02:00
|
|
|
|
|
|
|
ChromeZoomLevelPrefs* CefBrowserContext::GetZoomLevelPrefs() {
|
|
|
|
return static_cast<ChromeZoomLevelPrefs*>(
|
|
|
|
GetStoragePartition(this, NULL)->GetZoomLevelDelegate());
|
|
|
|
}
|