2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 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.
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/browser_context_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include <map>
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/browser/browser_context_proxy.h"
|
2017-02-14 23:27:19 +01:00
|
|
|
#include "libcef/browser/content_browser_client.h"
|
2012-06-25 20:22:50 +02:00
|
|
|
#include "libcef/browser/context.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/download_manager_delegate.h"
|
2016-08-24 11:28:52 +02:00
|
|
|
#include "libcef/browser/extensions/extension_system.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "libcef/browser/prefs/browser_prefs.h"
|
2017-05-04 23:53:27 +02:00
|
|
|
#include "libcef/browser/request_context_impl.h"
|
2015-05-19 19:55:58 +02:00
|
|
|
#include "libcef/browser/ssl_host_state_delegate.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "libcef/common/cef_switches.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "base/command_line.h"
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "base/files/file_util.h"
|
|
|
|
#include "base/lazy_instance.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/logging.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "base/strings/string_util.h"
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "base/threading/thread_restrictions.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "chrome/browser/font_family_cache.h"
|
|
|
|
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "components/content_settings/core/browser/host_content_settings_map.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "components/guest_view/browser/guest_view_manager.h"
|
2016-02-05 01:49:19 +01:00
|
|
|
#include "components/prefs/pref_service.h"
|
2018-02-15 01:12:09 +01:00
|
|
|
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
|
2016-01-12 01:19:51 +01:00
|
|
|
#include "components/visitedlink/browser/visitedlink_event_listener.h"
|
|
|
|
#include "components/visitedlink/browser/visitedlink_master.h"
|
2016-06-21 00:59:23 +02:00
|
|
|
#include "components/zoom/zoom_event_manager.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "content/public/browser/download_manager.h"
|
2013-02-23 01:43:28 +01:00
|
|
|
#include "content/public/browser/storage_partition.h"
|
2016-08-24 11:28:52 +02:00
|
|
|
#include "extensions/browser/extension_protocols.h"
|
|
|
|
#include "extensions/common/constants.h"
|
2018-03-20 21:15:08 +01:00
|
|
|
#include "net/proxy_resolution/proxy_config_service.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "net/proxy_resolution/proxy_resolution_service.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
using content::BrowserThread;
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
namespace {
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
// Manages the global list of Impl instances.
|
2015-03-02 21:25:14 +01:00
|
|
|
class ImplManager {
|
|
|
|
public:
|
2015-07-16 23:40:01 +02:00
|
|
|
typedef std::vector<CefBrowserContextImpl*> Vector;
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
ImplManager() {}
|
|
|
|
~ImplManager() {
|
2015-07-16 23:40:01 +02:00
|
|
|
DCHECK(all_.empty());
|
2015-03-02 21:25:14 +01:00
|
|
|
DCHECK(map_.empty());
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
void AddImpl(CefBrowserContextImpl* impl) {
|
2015-03-02 21:25:14 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
2015-07-16 23:40:01 +02:00
|
|
|
DCHECK(!IsValidImpl(impl));
|
|
|
|
all_.push_back(impl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveImpl(CefBrowserContextImpl* impl, const base::FilePath& path) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
Vector::iterator it = GetImplPos(impl);
|
|
|
|
DCHECK(it != all_.end());
|
|
|
|
all_.erase(it);
|
|
|
|
|
|
|
|
if (!path.empty()) {
|
|
|
|
PathMap::iterator it = map_.find(path);
|
|
|
|
DCHECK(it != map_.end());
|
|
|
|
if (it != map_.end())
|
|
|
|
map_.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsValidImpl(const CefBrowserContextImpl* impl) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
return GetImplPos(impl) != all_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserContextImpl* GetImplForContext(
|
|
|
|
const content::BrowserContext* context) {
|
|
|
|
CEF_REQUIRE_UIT();
|
2017-04-20 21:28:17 +02:00
|
|
|
if (!context)
|
|
|
|
return NULL;
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
const CefBrowserContext* cef_context =
|
|
|
|
static_cast<const CefBrowserContext*>(context);
|
|
|
|
const CefBrowserContextImpl* cef_context_impl = nullptr;
|
|
|
|
if (cef_context->is_proxy()) {
|
|
|
|
cef_context_impl =
|
|
|
|
static_cast<const CefBrowserContextProxy*>(cef_context)->parent();
|
|
|
|
} else {
|
|
|
|
cef_context_impl = static_cast<const CefBrowserContextImpl*>(cef_context);
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
Vector::iterator it = all_.begin();
|
|
|
|
for (; it != all_.end(); ++it) {
|
2017-02-14 23:27:19 +01:00
|
|
|
if (*it == cef_context_impl)
|
2015-07-16 23:40:01 +02:00
|
|
|
return *it;
|
|
|
|
}
|
2015-03-02 21:25:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
void SetImplPath(CefBrowserContextImpl* impl, const base::FilePath& path) {
|
2015-03-02 21:25:14 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
DCHECK(!path.empty());
|
2015-07-16 23:40:01 +02:00
|
|
|
DCHECK(IsValidImpl(impl));
|
|
|
|
DCHECK(GetImplForPath(path) == NULL);
|
2015-03-02 21:25:14 +01:00
|
|
|
map_.insert(std::make_pair(path, impl));
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
CefBrowserContextImpl* GetImplForPath(const base::FilePath& path) {
|
2015-03-02 21:25:14 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
DCHECK(!path.empty());
|
2015-07-16 23:40:01 +02:00
|
|
|
PathMap::const_iterator it = map_.find(path);
|
2015-03-02 21:25:14 +01:00
|
|
|
if (it != map_.end())
|
2015-07-16 23:40:01 +02:00
|
|
|
return it->second;
|
|
|
|
return NULL;
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
const Vector GetAllImpl() const { return all_; }
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
private:
|
2015-07-16 23:40:01 +02:00
|
|
|
Vector::iterator GetImplPos(const CefBrowserContextImpl* impl) {
|
|
|
|
Vector::iterator it = all_.begin();
|
|
|
|
for (; it != all_.end(); ++it) {
|
|
|
|
if (*it == impl)
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
return all_.end();
|
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
typedef std::map<base::FilePath, CefBrowserContextImpl*> PathMap;
|
|
|
|
PathMap map_;
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
Vector all_;
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ImplManager);
|
|
|
|
};
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
#if DCHECK_IS_ON()
|
|
|
|
// Because of DCHECK()s in the object destructor.
|
|
|
|
base::LazyInstance<ImplManager>::DestructorAtExit g_manager =
|
|
|
|
LAZY_INSTANCE_INITIALIZER;
|
|
|
|
#else
|
2017-05-17 11:29:28 +02:00
|
|
|
base::LazyInstance<ImplManager>::Leaky g_manager = LAZY_INSTANCE_INITIALIZER;
|
2017-04-20 21:28:17 +02:00
|
|
|
#endif
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-01-12 01:19:51 +01:00
|
|
|
// Creates and manages VisitedLinkEventListener objects for each
|
|
|
|
// CefBrowserContext sharing the same VisitedLinkMaster.
|
|
|
|
class CefVisitedLinkListener : public visitedlink::VisitedLinkMaster::Listener {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
CefVisitedLinkListener() { DCHECK(listener_map_.empty()); }
|
2016-01-12 01:19:51 +01:00
|
|
|
|
|
|
|
void CreateListenerForContext(const CefBrowserContext* context) {
|
|
|
|
CEF_REQUIRE_UIT();
|
2018-03-20 21:15:08 +01:00
|
|
|
auto listener = std::make_unique<visitedlink::VisitedLinkEventListener>(
|
2016-10-21 21:52:29 +02:00
|
|
|
const_cast<CefBrowserContext*>(context));
|
2016-01-12 01:19:51 +01:00
|
|
|
listener_map_.insert(std::make_pair(context, std::move(listener)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveListenerForContext(const CefBrowserContext* context) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
ListenerMap::iterator it = listener_map_.find(context);
|
|
|
|
DCHECK(it != listener_map_.end());
|
|
|
|
listener_map_.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
// visitedlink::VisitedLinkMaster::Listener methods.
|
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
void NewTable(base::ReadOnlySharedMemoryRegion* table_region) override {
|
2016-01-12 01:19:51 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
ListenerMap::iterator it = listener_map_.begin();
|
|
|
|
for (; it != listener_map_.end(); ++it)
|
2018-04-19 17:44:42 +02:00
|
|
|
it->second->NewTable(table_region);
|
2016-01-12 01:19:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Add(visitedlink::VisitedLinkCommon::Fingerprint fingerprint) override {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
ListenerMap::iterator it = listener_map_.begin();
|
|
|
|
for (; it != listener_map_.end(); ++it)
|
|
|
|
it->second->Add(fingerprint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reset(bool invalidate_hashes) override {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
ListenerMap::iterator it = listener_map_.begin();
|
|
|
|
for (; it != listener_map_.end(); ++it)
|
|
|
|
it->second->Reset(invalidate_hashes);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Map of CefBrowserContext to the associated VisitedLinkEventListener.
|
|
|
|
typedef std::map<const CefBrowserContext*,
|
2017-05-17 11:29:28 +02:00
|
|
|
std::unique_ptr<visitedlink::VisitedLinkEventListener>>
|
2016-10-21 21:52:29 +02:00
|
|
|
ListenerMap;
|
2016-01-12 01:19:51 +01:00
|
|
|
ListenerMap listener_map_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefVisitedLinkListener);
|
|
|
|
};
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
CefBrowserContextImpl::CefBrowserContextImpl(
|
|
|
|
const CefRequestContextSettings& settings)
|
2017-05-17 11:29:28 +02:00
|
|
|
: CefBrowserContext(false), settings_(settings) {
|
2015-07-16 23:40:01 +02:00
|
|
|
g_manager.Get().AddImpl(this);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
CefBrowserContextImpl::~CefBrowserContextImpl() {
|
2017-02-14 23:27:19 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
// No CefRequestContextImpl should be referencing this object any longer.
|
2017-05-04 23:53:27 +02:00
|
|
|
DCHECK(request_context_set_.empty());
|
2017-02-14 23:27:19 +01:00
|
|
|
|
2016-08-24 11:28:52 +02:00
|
|
|
// Unregister the context first to avoid re-entrancy during shutdown.
|
|
|
|
g_manager.Get().RemoveImpl(this, cache_path_);
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
Shutdown();
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
visitedlink_listener_->RemoveListenerForContext(this);
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
// The FontFamilyCache references the ProxyService so delete it before the
|
|
|
|
// ProxyService is deleted.
|
|
|
|
SetUserData(&kFontFamilyCacheKey, NULL);
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
pref_proxy_config_tracker_->DetachFromPrefService();
|
|
|
|
|
2016-06-07 20:44:59 +02:00
|
|
|
if (url_request_getter_)
|
|
|
|
url_request_getter_->ShutdownOnUIThread();
|
|
|
|
if (host_content_settings_map_)
|
2015-09-09 16:05:39 +02:00
|
|
|
host_content_settings_map_->ShutdownOnUIThread();
|
|
|
|
|
2012-11-30 20:08:20 +01:00
|
|
|
// Delete the download manager delegate here because otherwise we'll crash
|
2012-06-28 19:21:18 +02:00
|
|
|
// when it's accessed from the content::BrowserContext destructor.
|
2016-06-07 20:44:59 +02:00
|
|
|
if (download_manager_delegate_)
|
2012-11-30 20:08:20 +01:00
|
|
|
download_manager_delegate_.reset(NULL);
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserContextImpl::Initialize() {
|
|
|
|
cache_path_ = base::FilePath(CefString(&settings_.cache_path));
|
|
|
|
if (!cache_path_.empty()) {
|
|
|
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
|
|
|
if (!base::DirectoryExists(cache_path_) &&
|
|
|
|
!base::CreateDirectory(cache_path_)) {
|
2017-05-17 11:29:28 +02:00
|
|
|
LOG(ERROR) << "The cache_path directory could not be created: "
|
|
|
|
<< cache_path_.value();
|
2015-03-02 21:25:14 +01:00
|
|
|
cache_path_ = base::FilePath();
|
|
|
|
CefString(&settings_.cache_path).clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cache_path_.empty())
|
2015-07-16 23:40:01 +02:00
|
|
|
g_manager.Get().SetImplPath(this, cache_path_);
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
if (settings_.accept_language_list.length == 0) {
|
|
|
|
// Use the global language list setting.
|
|
|
|
CefString(&settings_.accept_language_list) =
|
|
|
|
CefString(&CefContext::Get()->settings().accept_language_list);
|
|
|
|
}
|
|
|
|
|
2017-09-25 15:11:17 +02:00
|
|
|
// Initialize the PrefService object.
|
|
|
|
pref_service_ = browser_prefs::CreatePrefService(
|
|
|
|
this, cache_path_, !!settings_.persist_user_preferences);
|
2017-04-20 21:28:17 +02:00
|
|
|
|
|
|
|
CefBrowserContext::Initialize();
|
|
|
|
|
2016-01-12 01:19:51 +01:00
|
|
|
// Initialize visited links management.
|
|
|
|
base::FilePath visited_link_path;
|
|
|
|
if (!cache_path_.empty())
|
2017-05-17 11:29:28 +02:00
|
|
|
visited_link_path = cache_path_.Append(FILE_PATH_LITERAL("Visited Links"));
|
2016-01-12 01:19:51 +01:00
|
|
|
visitedlink_listener_ = new CefVisitedLinkListener;
|
2017-05-17 11:29:28 +02:00
|
|
|
visitedlink_master_.reset(new visitedlink::VisitedLinkMaster(
|
|
|
|
visitedlink_listener_, this, !visited_link_path.empty(), false,
|
|
|
|
visited_link_path, 0));
|
2016-01-12 01:19:51 +01:00
|
|
|
visitedlink_listener_->CreateListenerForContext(this);
|
|
|
|
visitedlink_master_->Init();
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Initialize proxy configuration tracker.
|
2018-02-15 01:12:09 +01:00
|
|
|
pref_proxy_config_tracker_.reset(new PrefProxyConfigTrackerImpl(
|
|
|
|
GetPrefs(), BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
CefBrowserContext::PostInitialize();
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Create the CefURLRequestContextGetterImpl via an indirect call to
|
|
|
|
// CreateRequestContext. Triggers a call to CefURLRequestContextGetterImpl::
|
|
|
|
// GetURLRequestContext() on the IO thread which creates the
|
|
|
|
// CefURLRequestContextImpl.
|
|
|
|
GetRequestContext();
|
|
|
|
DCHECK(url_request_getter_.get());
|
2016-08-31 13:25:56 +02:00
|
|
|
|
|
|
|
// Create the StoragePartitionImplMap and StoragePartitionImpl for this
|
|
|
|
// object. This must be done before the first WebContents is created using a
|
|
|
|
// CefBrowserContextProxy of this object, otherwise the StoragePartitionProxy
|
|
|
|
// will not be created (in that case
|
|
|
|
// CefBrowserContextProxy::CreateRequestContext will be called, which is
|
|
|
|
// incorrect).
|
|
|
|
GetDefaultStoragePartition(this);
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
void CefBrowserContextImpl::AddProxy(const CefBrowserContextProxy* proxy) {
|
|
|
|
CEF_REQUIRE_UIT();
|
2016-01-12 01:19:51 +01:00
|
|
|
visitedlink_listener_->CreateListenerForContext(proxy);
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserContextImpl::RemoveProxy(const CefBrowserContextProxy* proxy) {
|
|
|
|
CEF_REQUIRE_UIT();
|
2016-01-12 01:19:51 +01:00
|
|
|
visitedlink_listener_->RemoveListenerForContext(proxy);
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
2016-01-12 01:19:51 +01:00
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
void CefBrowserContextImpl::AddCefRequestContext(
|
|
|
|
CefRequestContextImpl* context) {
|
2017-02-14 23:27:19 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
2017-05-04 23:53:27 +02:00
|
|
|
request_context_set_.insert(context);
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
void CefBrowserContextImpl::RemoveCefRequestContext(
|
|
|
|
CefRequestContextImpl* context) {
|
2015-07-16 23:40:01 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
if (extensions::ExtensionsEnabled()) {
|
|
|
|
extension_system()->OnRequestContextDeleted(context);
|
|
|
|
}
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
request_context_set_.erase(context);
|
2017-02-14 23:27:19 +01:00
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
// Delete ourselves when the reference count reaches zero.
|
|
|
|
if (request_context_set_.empty())
|
2017-02-14 23:27:19 +01:00
|
|
|
delete this;
|
2017-05-04 23:53:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRequestContextImpl* CefBrowserContextImpl::GetCefRequestContext(
|
|
|
|
bool impl_only) const {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
// First try to find a non-proxy RequestContext.
|
|
|
|
for (CefRequestContextImpl* impl : request_context_set_) {
|
|
|
|
if (!impl->GetHandler())
|
|
|
|
return impl;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
2017-05-04 23:53:27 +02:00
|
|
|
if (impl_only)
|
|
|
|
return nullptr;
|
|
|
|
return *request_context_set_.begin();
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// static
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContextImpl* CefBrowserContextImpl::GetForCachePath(
|
2015-03-02 21:25:14 +01:00
|
|
|
const base::FilePath& cache_path) {
|
2015-07-16 23:40:01 +02:00
|
|
|
return g_manager.Get().GetImplForPath(cache_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContextImpl* CefBrowserContextImpl::GetForContext(
|
2015-07-16 23:40:01 +02:00
|
|
|
content::BrowserContext* context) {
|
|
|
|
return g_manager.Get().GetImplForContext(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
std::vector<CefBrowserContextImpl*> CefBrowserContextImpl::GetAll() {
|
|
|
|
return g_manager.Get().GetAllImpl();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
base::FilePath CefBrowserContextImpl::GetPath() const {
|
2015-03-02 21:25:14 +01:00
|
|
|
return cache_path_;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<content::ZoomLevelDelegate>
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextImpl::CreateZoomLevelDelegate(
|
|
|
|
const base::FilePath& partition_path) {
|
2015-10-17 02:44:00 +02:00
|
|
|
if (cache_path_.empty())
|
2016-04-27 22:38:52 +02:00
|
|
|
return std::unique_ptr<content::ZoomLevelDelegate>();
|
2015-10-17 02:44:00 +02:00
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
return base::WrapUnique(new ChromeZoomLevelPrefs(
|
2015-10-17 02:44:00 +02:00
|
|
|
GetPrefs(), cache_path_, partition_path,
|
2016-06-21 00:59:23 +02:00
|
|
|
zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()));
|
2014-12-13 21:18:31 +01:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
bool CefBrowserContextImpl::IsOffTheRecord() const {
|
2017-08-04 00:55:19 +02:00
|
|
|
// CEF contexts are never flagged as off-the-record. It causes problems
|
|
|
|
// for the extension system.
|
|
|
|
return false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-06-22 00:50:34 +02:00
|
|
|
content::DownloadManagerDelegate*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextImpl::GetDownloadManagerDelegate() {
|
2017-12-07 22:44:24 +01:00
|
|
|
if (!download_manager_delegate_) {
|
|
|
|
content::DownloadManager* manager =
|
|
|
|
BrowserContext::GetDownloadManager(this);
|
|
|
|
download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager));
|
|
|
|
}
|
2012-06-22 00:50:34 +02:00
|
|
|
return download_manager_delegate_.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-05-29 19:15:34 +02:00
|
|
|
content::BrowserPluginGuestManager* CefBrowserContextImpl::GetGuestManager() {
|
2015-07-16 23:40:01 +02:00
|
|
|
DCHECK(extensions::ExtensionsEnabled());
|
|
|
|
return guest_view::GuestViewManager::FromBrowserContext(this);
|
2014-05-29 19:15:34 +02:00
|
|
|
}
|
|
|
|
|
2014-09-04 19:53:40 +02:00
|
|
|
storage::SpecialStoragePolicy*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextImpl::GetSpecialStoragePolicy() {
|
2012-04-03 03:34:16 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-21 01:40:15 +01:00
|
|
|
|
2014-07-02 20:25:22 +02:00
|
|
|
content::PushMessagingService*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextImpl::GetPushMessagingService() {
|
2014-07-02 20:25:22 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-04 19:53:40 +02:00
|
|
|
content::SSLHostStateDelegate*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextImpl::GetSSLHostStateDelegate() {
|
2015-05-19 19:55:58 +02:00
|
|
|
if (!ssl_host_state_delegate_.get())
|
|
|
|
ssl_host_state_delegate_.reset(new CefSSLHostStateDelegate());
|
|
|
|
return ssl_host_state_delegate_.get();
|
2014-09-04 19:53:40 +02:00
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
content::PermissionManager* CefBrowserContextImpl::GetPermissionManager() {
|
2018-02-13 00:51:11 +01:00
|
|
|
return nullptr;
|
2015-04-20 13:11:11 +02:00
|
|
|
}
|
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
content::BackgroundFetchDelegate*
|
|
|
|
CefBrowserContextImpl::GetBackgroundFetchDelegate() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-11-10 21:18:16 +01:00
|
|
|
content::BackgroundSyncController*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextImpl::GetBackgroundSyncController() {
|
2015-11-10 21:18:16 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
content::BrowsingDataRemoverDelegate*
|
|
|
|
CefBrowserContextImpl::GetBrowsingDataRemoverDelegate() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
net::URLRequestContextGetter* CefBrowserContextImpl::CreateRequestContext(
|
2014-04-04 18:50:38 +02:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-06-12 22:28:58 +02:00
|
|
|
content::URLRequestInterceptorScopedVector request_interceptors) {
|
2015-03-02 21:25:14 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
2014-09-27 01:48:19 +02:00
|
|
|
DCHECK(!url_request_getter_.get());
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
auto io_thread_runner =
|
|
|
|
content::BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Initialize the proxy configuration service.
|
2018-02-15 01:12:09 +01:00
|
|
|
// TODO(cef): Determine if we can use the Chrome/Mojo implementation from
|
|
|
|
// https://crrev.com/d0d0d050
|
|
|
|
std::unique_ptr<net::ProxyConfigService> base_service(
|
2018-03-20 21:15:08 +01:00
|
|
|
net::ProxyResolutionService::CreateSystemProxyConfigService(
|
|
|
|
io_thread_runner));
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::ProxyConfigService> proxy_config_service(
|
2018-02-15 01:12:09 +01:00
|
|
|
pref_proxy_config_tracker_->CreateTrackingProxyConfigService(
|
|
|
|
std::move(base_service)));
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2016-08-24 11:28:52 +02:00
|
|
|
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).
|
2017-05-17 11:29:28 +02:00
|
|
|
extensions::InfoMap* extension_info_map = extension_system()->info_map();
|
2016-08-24 11:28:52 +02:00
|
|
|
(*protocol_handlers)[extensions::kExtensionScheme] =
|
2018-04-19 17:44:42 +02:00
|
|
|
extensions::CreateExtensionProtocolHandler(IsOffTheRecord(),
|
|
|
|
extension_info_map);
|
2016-08-24 11:28:52 +02:00
|
|
|
}
|
2016-04-27 22:38:52 +02:00
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
url_request_getter_ = new CefURLRequestContextGetterImpl(
|
2018-02-15 01:12:09 +01:00
|
|
|
settings_, GetPrefs(), io_thread_runner, protocol_handlers,
|
|
|
|
std::move(proxy_config_service), std::move(request_interceptors));
|
2015-02-14 00:17:08 +01:00
|
|
|
resource_context()->set_url_request_context_getter(url_request_getter_.get());
|
2013-02-23 01:43:28 +01:00
|
|
|
return url_request_getter_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
net::URLRequestContextGetter*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextImpl::CreateRequestContextForStoragePartition(
|
|
|
|
const base::FilePath& partition_path,
|
|
|
|
bool in_memory,
|
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
|
|
|
content::URLRequestInterceptorScopedVector request_interceptors) {
|
2016-08-24 11:28:52 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::StoragePartition* CefBrowserContextImpl::GetStoragePartitionProxy(
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
content::StoragePartition* partition_impl) {
|
|
|
|
CefBrowserContextProxy* proxy =
|
|
|
|
static_cast<CefBrowserContextProxy*>(browser_context);
|
|
|
|
return proxy->GetOrCreateStoragePartitionProxy(partition_impl);
|
|
|
|
}
|
|
|
|
|
|
|
|
PrefService* CefBrowserContextImpl::GetPrefs() {
|
|
|
|
return pref_service_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const PrefService* CefBrowserContextImpl::GetPrefs() const {
|
|
|
|
return pref_service_.get();
|
|
|
|
}
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
CefRequestContextImpl* CefBrowserContextImpl::GetCefRequestContext() const {
|
|
|
|
return GetCefRequestContext(false);
|
|
|
|
}
|
|
|
|
|
2016-08-24 11:28:52 +02:00
|
|
|
const CefRequestContextSettings& CefBrowserContextImpl::GetSettings() const {
|
|
|
|
return settings_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestContextHandler> CefBrowserContextImpl::GetHandler() const {
|
2013-02-23 01:43:28 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
HostContentSettingsMap* CefBrowserContextImpl::GetHostContentSettingsMap() {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
if (!host_content_settings_map_.get()) {
|
2016-02-05 01:49:19 +01:00
|
|
|
// The |is_incognito_profile| and |is_guest_profile| arguments are
|
|
|
|
// intentionally set to false as they otherwise limit the types of values
|
|
|
|
// that can be stored in the settings map (for example, default values set
|
|
|
|
// via DefaultProvider::SetWebsiteSetting).
|
|
|
|
host_content_settings_map_ =
|
2017-05-31 17:33:30 +02:00
|
|
|
new HostContentSettingsMap(GetPrefs(), false, false, false);
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
// Change the default plugin policy.
|
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
const std::string& plugin_policy_str =
|
2017-05-17 11:29:28 +02:00
|
|
|
command_line->GetSwitchValueASCII(switches::kPluginPolicy);
|
2015-09-09 16:05:39 +02:00
|
|
|
if (!plugin_policy_str.empty()) {
|
|
|
|
ContentSetting plugin_policy = CONTENT_SETTING_ALLOW;
|
|
|
|
if (base::LowerCaseEqualsASCII(plugin_policy_str,
|
|
|
|
switches::kPluginPolicy_Detect)) {
|
|
|
|
plugin_policy = CONTENT_SETTING_DETECT_IMPORTANT_CONTENT;
|
|
|
|
} else if (base::LowerCaseEqualsASCII(plugin_policy_str,
|
|
|
|
switches::kPluginPolicy_Block)) {
|
|
|
|
plugin_policy = CONTENT_SETTING_BLOCK;
|
|
|
|
}
|
|
|
|
host_content_settings_map_->SetDefaultContentSetting(
|
|
|
|
CONTENT_SETTINGS_TYPE_PLUGINS, plugin_policy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return host_content_settings_map_.get();
|
|
|
|
}
|
2016-01-12 01:19:51 +01:00
|
|
|
|
|
|
|
void CefBrowserContextImpl::AddVisitedURLs(const std::vector<GURL>& urls) {
|
|
|
|
visitedlink_master_->AddURLs(urls);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserContextImpl::RebuildTable(
|
|
|
|
const scoped_refptr<URLEnumerator>& enumerator) {
|
|
|
|
// Called when visited links will not or cannot be loaded from disk.
|
|
|
|
enumerator->OnComplete(true);
|
|
|
|
}
|