Remove methods that modify cookie storage at runtime (see issue #2622).

This change removes cookie and request handler functionality that will not
supported by the NetworkService. Specifically, it is no longer possible to
change cookie storage locations at runime by returning a different
CefCookieManager for an already initialized CefRequestContext. After this change
you will need to use a separate CefRequestContext when creating a CefBrowser if
you require separate cookie storage.

The following methods have been removed:
- CefCookieManager::CreateManager
- CefCookieManager::GetBlockingManager
- CefCookieManager::SetStoragePath
- CefRequestContextHandler::GetCookieManager

The following methods have been renamed:
- CefRequestContext::GetDefaultCookieManager to GetCookieManager.

This change substantially simplifies the network implementation in CEF because
it is no longer necessary to proxy objects that are normally owned by Chromium.
Chromium patches that are no longer necessary will be removed as a follow-up
commit.

To test: Verify that `ceftests --gtest_filter=-PluginTest.*` pass with
NetworkService disabled. Plugin tests will be fixed in a follow-up commit.
This commit is contained in:
Marshall Greenblatt 2019-03-22 18:11:51 -04:00
parent 6b2c1fe969
commit a23e845244
66 changed files with 1175 additions and 3939 deletions

View File

@ -258,12 +258,8 @@ static_library("libcef_static") {
"libcef/browser/audio_push_sink.h",
"libcef/browser/browser_context.cc",
"libcef/browser/browser_context.h",
"libcef/browser/browser_context_impl.cc",
"libcef/browser/browser_context_impl.h",
"libcef/browser/browser_context_keyed_service_factories.cc",
"libcef/browser/browser_context_keyed_service_factories.h",
"libcef/browser/browser_context_proxy.cc",
"libcef/browser/browser_context_proxy.h",
"libcef/browser/browser_host_impl.cc",
"libcef/browser/browser_host_impl.h",
"libcef/browser/browser_info.cc",
@ -377,10 +373,6 @@ static_library("libcef_static") {
"libcef/browser/navigation_entry_impl.h",
"libcef/browser/net/chrome_scheme_handler.cc",
"libcef/browser/net/chrome_scheme_handler.h",
"libcef/browser/net/cookie_store_proxy.cc",
"libcef/browser/net/cookie_store_proxy.h",
"libcef/browser/net/cookie_store_source.cc",
"libcef/browser/net/cookie_store_source.h",
"libcef/browser/net/crlset_file_util_impl.cc",
"libcef/browser/net/devtools_scheme_handler.cc",
"libcef/browser/net/devtools_scheme_handler.h",
@ -398,14 +390,8 @@ static_library("libcef_static") {
"libcef/browser/net/source_stream.h",
"libcef/browser/net/url_request_context.cc",
"libcef/browser/net/url_request_context.h",
"libcef/browser/net/url_request_context_getter.cc",
"libcef/browser/net/url_request_context_getter.h",
"libcef/browser/net/url_request_context_getter_impl.cc",
"libcef/browser/net/url_request_context_getter_impl.h",
"libcef/browser/net/url_request_context_getter_proxy.cc",
"libcef/browser/net/url_request_context_getter_proxy.h",
"libcef/browser/net/url_request_context_impl.h",
"libcef/browser/net/url_request_context_proxy.cc",
"libcef/browser/net/url_request_context_proxy.h",
"libcef/browser/net/url_request_interceptor.cc",
"libcef/browser/net/url_request_interceptor.h",
"libcef/browser/net/url_request_manager.cc",
@ -465,8 +451,6 @@ static_library("libcef_static") {
"libcef/browser/ssl_info_impl.h",
"libcef/browser/ssl_status_impl.cc",
"libcef/browser/ssl_status_impl.h",
"libcef/browser/storage_partition_proxy.cc",
"libcef/browser/storage_partition_proxy.h",
"libcef/browser/stream_impl.cc",
"libcef/browser/stream_impl.h",
"libcef/browser/trace_impl.cc",

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=48b5fa68109eed1ea30fa0c805218ebd258c0573$
// $hash=fd4529fcb0b4cebf7e94a5160854f13ee05bbab0$
//
#ifndef CEF_INCLUDE_CAPI_CEF_COOKIE_CAPI_H_
@ -123,22 +123,6 @@ typedef struct _cef_cookie_manager_t {
const cef_string_t* cookie_name,
struct _cef_delete_cookies_callback_t* callback);
///
// Sets the directory path that will be used for storing cookie data. If
// |path| is NULL data will be stored in memory only. Otherwise, data will be
// stored at the specified |path|. To persist session cookies (cookies without
// an expiry date or validity interval) set |persist_session_cookies| to true
// (1). Session cookies are generally intended to be transient and most Web
// browsers do not persist them. If |callback| is non-NULL it will be executed
// asnychronously on the IO thread after the manager's storage has been
// initialized. Returns false (0) if cookies cannot be accessed.
///
int(CEF_CALLBACK* set_storage_path)(
struct _cef_cookie_manager_t* self,
const cef_string_t* path,
int persist_session_cookies,
struct _cef_completion_callback_t* callback);
///
// Flush the backing store (if any) to disk. If |callback| is non-NULL it will
// be executed asnychronously on the IO thread after the flush is complete.
@ -153,36 +137,12 @@ typedef struct _cef_cookie_manager_t {
// CefSettings.cache_path if specified or in memory otherwise. If |callback| is
// non-NULL it will be executed asnychronously on the IO thread after the
// manager's storage has been initialized. Using this function is equivalent to
// calling cef_request_tContext::cef_request_context_get_global_context()->get_d
// efault_cookie_manager().
// calling cef_request_tContext::cef_request_context_get_global_context()->GetDe
// faultCookieManager().
///
CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_get_global_manager(
struct _cef_completion_callback_t* callback);
///
// Returns a cookie manager that neither stores nor retrieves cookies. All usage
// of cookies will be blocked including cookies accessed via the network
// (request/response headers), via JavaScript (document.cookie), and via
// cef_cookie_manager_t functions. No cookies will be displayed in DevTools. If
// you wish to only block cookies sent via the network use the
// cef_request_tHandler CanGetCookies and CanSetCookie functions instead.
///
CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_get_blocking_manager();
///
// Creates a new cookie manager. If |path| is NULL data will be stored in memory
// only. Otherwise, data will be stored at the specified |path|. To persist
// session cookies (cookies without an expiry date or validity interval) set
// |persist_session_cookies| to true (1). Session cookies are generally intended
// to be transient and most Web browsers do not persist them. If |callback| is
// non-NULL it will be executed asnychronously on the IO thread after the
// manager's storage has been initialized.
///
CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_create_manager(
const cef_string_t* path,
int persist_session_cookies,
struct _cef_completion_callback_t* callback);
///
// Structure to implement for visiting cookie values. The functions of this
// structure will always be called on the IO thread.

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=f7f1ec971c726a6a74bcc7f5cee7a8eb1911078d$
// $hash=1038c0c3db89ce0b829d66e166b063c96b15992d$
//
#ifndef CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_CAPI_H_
@ -130,14 +130,11 @@ typedef struct _cef_request_context_t {
struct _cef_request_context_t* self);
///
// Returns the default cookie manager for this object. This will be the global
// cookie manager if this object is the global request context. Otherwise,
// this will be the default cookie manager used when this request context does
// not receive a value via cef_request_tContextHandler::get_cookie_manager().
// If |callback| is non-NULL it will be executed asnychronously on the IO
// thread after the manager's storage has been initialized.
// Returns the cookie manager for this object. If |callback| is non-NULL it
// will be executed asnychronously on the IO thread after the manager's
// storage has been initialized.
///
struct _cef_cookie_manager_t*(CEF_CALLBACK* get_default_cookie_manager)(
struct _cef_cookie_manager_t*(CEF_CALLBACK* get_cookie_manager)(
struct _cef_request_context_t* self,
struct _cef_completion_callback_t* callback);

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=03c829d89f0b5b7ab12634fa2f11c4903cd8edb2$
// $hash=2bf745d270f474b3d5b36fc3fc2fca2b508ec16f$
//
#ifndef CEF_INCLUDE_CAPI_CEF_REQUEST_CONTEXT_HANDLER_CAPI_H_
@ -41,7 +41,6 @@
#pragma once
#include "include/capi/cef_base_capi.h"
#include "include/capi/cef_cookie_capi.h"
#include "include/capi/cef_web_plugin_capi.h"
#ifdef __cplusplus
@ -69,14 +68,6 @@ typedef struct _cef_request_context_handler_t {
struct _cef_request_context_handler_t* self,
struct _cef_request_context_t* request_context);
///
// Called on the browser process IO thread to retrieve the cookie manager. If
// this function returns NULL the default cookie manager retrievable via
// cef_request_tContext::get_default_cookie_manager() will be used.
///
struct _cef_cookie_manager_t*(CEF_CALLBACK* get_cookie_manager)(
struct _cef_request_context_handler_t* self);
///
// Called on multiple browser process threads before a plugin instance is
// loaded. |mime_type| is the mime type of the plugin that will be loaded.

View File

@ -34,7 +34,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=b5fa5783096eaa1af5e76645e2557e123af56848$
// $hash=fcc19532b6143e9c445fcde9947260b1c93a5e68$
//
#ifndef CEF_INCLUDE_API_HASH_H_
@ -47,13 +47,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "8ae24aac4bd16d2e2d87e7d6561985064990670e"
#define CEF_API_HASH_UNIVERSAL "114e74f2c52d90fbb3fe6b3855dba9e544e40e85"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "fe476e7a38a8270fe783981b4bc6fac4284ab9fe"
#define CEF_API_HASH_PLATFORM "25d0b5c8337691e2bcc21148686e4eacbe1255a6"
#elif defined(OS_MACOSX)
#define CEF_API_HASH_PLATFORM "ab1b4d8c4578b0bcdc97f28f13a10384057bdf95"
#define CEF_API_HASH_PLATFORM "905d65b97689874873222e99869c8c5a361bbdb7"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "73f24626e0179a3f5664d64ffe0fa2aab9edf7cf"
#define CEF_API_HASH_PLATFORM "ef345d85855d8d5c34de2fb26d25397c5e0e3534"
#endif
#ifdef __cplusplus

View File

@ -64,32 +64,6 @@ class CefCookieManager : public virtual CefBaseRefCounted {
static CefRefPtr<CefCookieManager> GetGlobalManager(
CefRefPtr<CefCompletionCallback> callback);
///
// Returns a cookie manager that neither stores nor retrieves cookies. All
// usage of cookies will be blocked including cookies accessed via the network
// (request/response headers), via JavaScript (document.cookie), and via
// CefCookieManager methods. No cookies will be displayed in DevTools. If you
// wish to only block cookies sent via the network use the CefRequestHandler
// CanGetCookies and CanSetCookie methods instead.
///
/*--cef()--*/
static CefRefPtr<CefCookieManager> GetBlockingManager();
///
// Creates a new cookie manager. If |path| is empty data will be stored in
// memory only. Otherwise, data will be stored at the specified |path|. To
// persist session cookies (cookies without an expiry date or validity
// interval) set |persist_session_cookies| to true. Session cookies are
// generally intended to be transient and most Web browsers do not persist
// them. If |callback| is non-NULL it will be executed asnychronously on the
// IO thread after the manager's storage has been initialized.
///
/*--cef(optional_param=path,optional_param=callback)--*/
static CefRefPtr<CefCookieManager> CreateManager(
const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback);
///
// Set the schemes supported by this manager. The default schemes ("http",
// "https", "ws" and "wss") will always be supported. If |callback| is non-
@ -152,21 +126,6 @@ class CefCookieManager : public virtual CefBaseRefCounted {
const CefString& cookie_name,
CefRefPtr<CefDeleteCookiesCallback> callback) = 0;
///
// Sets the directory path that will be used for storing cookie data. If
// |path| is empty data will be stored in memory only. Otherwise, data will be
// stored at the specified |path|. To persist session cookies (cookies without
// an expiry date or validity interval) set |persist_session_cookies| to true.
// Session cookies are generally intended to be transient and most Web
// browsers do not persist them. If |callback| is non-NULL it will be executed
// asnychronously on the IO thread after the manager's storage has been
// initialized. Returns false if cookies cannot be accessed.
///
/*--cef(optional_param=path,optional_param=callback)--*/
virtual bool SetStoragePath(const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback) = 0;
///
// Flush the backing store (if any) to disk. If |callback| is non-NULL it will
// be executed asnychronously on the IO thread after the flush is complete.

View File

@ -144,15 +144,12 @@ class CefRequestContext : public virtual CefBaseRefCounted {
virtual CefString GetCachePath() = 0;
///
// Returns the default cookie manager for this object. This will be the global
// cookie manager if this object is the global request context. Otherwise,
// this will be the default cookie manager used when this request context does
// not receive a value via CefRequestContextHandler::GetCookieManager(). If
// |callback| is non-NULL it will be executed asnychronously on the IO thread
// after the manager's storage has been initialized.
// Returns the cookie manager for this object. If |callback| is non-NULL it
// will be executed asnychronously on the IO thread after the manager's
// storage has been initialized.
///
/*--cef(optional_param=callback)--*/
virtual CefRefPtr<CefCookieManager> GetDefaultCookieManager(
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefCompletionCallback> callback) = 0;
///

View File

@ -39,7 +39,6 @@
#pragma once
#include "include/cef_base.h"
#include "include/cef_cookie.h"
#include "include/cef_web_plugin.h"
class CefRequestContext;
@ -62,14 +61,6 @@ class CefRequestContextHandler : public virtual CefBaseRefCounted {
virtual void OnRequestContextInitialized(
CefRefPtr<CefRequestContext> request_context) {}
///
// Called on the browser process IO thread to retrieve the cookie manager. If
// this method returns NULL the default cookie manager retrievable via
// CefRequestContext::GetDefaultCookieManager() will be used.
///
/*--cef()--*/
virtual CefRefPtr<CefCookieManager> GetCookieManager() { return NULL; }
///
// Called on multiple browser process threads before a plugin instance is
// loaded. |mime_type| is the mime type of the plugin that will be loaded.

View File

@ -1,32 +1,290 @@
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// 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.
#include "libcef/browser/browser_context.h"
#include <map>
#include <utility>
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/download_manager_delegate.h"
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/prefs/browser_prefs.h"
#include "libcef/browser/request_context_impl.h"
#include "libcef/browser/ssl_host_state_delegate.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/net_service/util.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/font_family_cache.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/prefs/pref_service.h"
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
#include "components/user_prefs/user_prefs.h"
#include "components/visitedlink/browser/visitedlink_event_listener.h"
#include "components/visitedlink/browser/visitedlink_master.h"
#include "components/zoom/zoom_event_manager.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/storage_partition.h"
#include "extensions/browser/extension_protocols.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/constants.h"
#include "net/proxy_resolution/proxy_config_service.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
CefBrowserContext::CefBrowserContext(bool is_proxy)
: is_proxy_(is_proxy), extension_system_(NULL) {}
using content::BrowserThread;
namespace {
// Manages the global list of Impl instances.
class ImplManager {
public:
typedef std::vector<CefBrowserContext*> Vector;
ImplManager() {}
~ImplManager() {
DCHECK(all_.empty());
DCHECK(map_.empty());
}
void AddImpl(CefBrowserContext* impl) {
CEF_REQUIRE_UIT();
DCHECK(!IsValidImpl(impl));
all_.push_back(impl);
}
void RemoveImpl(CefBrowserContext* 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 CefBrowserContext* impl) {
CEF_REQUIRE_UIT();
return GetImplPos(impl) != all_.end();
}
CefBrowserContext* GetImplForContext(const content::BrowserContext* context) {
CEF_REQUIRE_UIT();
if (!context)
return NULL;
Vector::iterator it = all_.begin();
for (; it != all_.end(); ++it) {
if (*it == context)
return *it;
}
return NULL;
}
void SetImplPath(CefBrowserContext* impl, const base::FilePath& path) {
CEF_REQUIRE_UIT();
DCHECK(!path.empty());
DCHECK(IsValidImpl(impl));
DCHECK(GetImplForPath(path) == NULL);
map_.insert(std::make_pair(path, impl));
}
CefBrowserContext* GetImplForPath(const base::FilePath& path) {
CEF_REQUIRE_UIT();
DCHECK(!path.empty());
PathMap::const_iterator it = map_.find(path);
if (it != map_.end())
return it->second;
return NULL;
}
const Vector GetAllImpl() const { return all_; }
private:
Vector::iterator GetImplPos(const CefBrowserContext* impl) {
Vector::iterator it = all_.begin();
for (; it != all_.end(); ++it) {
if (*it == impl)
return it;
}
return all_.end();
}
typedef std::map<base::FilePath, CefBrowserContext*> PathMap;
PathMap map_;
Vector all_;
DISALLOW_COPY_AND_ASSIGN(ImplManager);
};
#if DCHECK_IS_ON()
// Because of DCHECK()s in the object destructor.
base::LazyInstance<ImplManager>::DestructorAtExit g_manager =
LAZY_INSTANCE_INITIALIZER;
#else
base::LazyInstance<ImplManager>::Leaky g_manager = LAZY_INSTANCE_INITIALIZER;
#endif
} // namespace
// Creates and manages VisitedLinkEventListener objects for each
// CefBrowserContext sharing the same VisitedLinkMaster.
class CefVisitedLinkListener : public visitedlink::VisitedLinkMaster::Listener {
public:
CefVisitedLinkListener() { DCHECK(listener_map_.empty()); }
void CreateListenerForContext(const CefBrowserContext* context) {
CEF_REQUIRE_UIT();
auto listener = std::make_unique<visitedlink::VisitedLinkEventListener>(
const_cast<CefBrowserContext*>(context));
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.
void NewTable(base::ReadOnlySharedMemoryRegion* table_region) override {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.begin();
for (; it != listener_map_.end(); ++it)
it->second->NewTable(table_region);
}
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*,
std::unique_ptr<visitedlink::VisitedLinkEventListener>>
ListenerMap;
ListenerMap listener_map_;
DISALLOW_COPY_AND_ASSIGN(CefVisitedLinkListener);
};
CefBrowserContext::CefBrowserContext(const CefRequestContextSettings& settings)
: settings_(settings) {
g_manager.Get().AddImpl(this);
}
CefBrowserContext::~CefBrowserContext() {
// Should be cleared in Shutdown().
DCHECK(!resource_context_.get());
CEF_REQUIRE_UIT();
// No CefRequestContext should be referencing this object any longer.
DCHECK(request_context_set_.empty());
// Unregister the context first to avoid re-entrancy during shutdown.
g_manager.Get().RemoveImpl(this, cache_path_);
// Send notifications to clean up objects associated with this Profile.
MaybeSendDestroyedNotification();
ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext(
resource_context_.get());
// Remove any BrowserContextKeyedServiceFactory associations. This must be
// called before the ProxyService owned by CefBrowserContext is destroyed.
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
this);
// 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();
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());
}
visitedlink_listener_->RemoveListenerForContext(this);
// The FontFamilyCache references the ProxyService so delete it before the
// ProxyService is deleted.
SetUserData(&kFontFamilyCacheKey, NULL);
pref_proxy_config_tracker_->DetachFromPrefService();
if (url_request_getter_)
url_request_getter_->ShutdownOnUIThread();
if (host_content_settings_map_)
host_content_settings_map_->ShutdownOnUIThread();
// Delete the download manager delegate here because otherwise we'll crash
// when it's accessed from the content::BrowserContext destructor.
if (download_manager_delegate_)
download_manager_delegate_.reset(NULL);
}
void CefBrowserContext::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_)) {
LOG(ERROR) << "The cache_path directory could not be created: "
<< cache_path_.value();
cache_path_ = base::FilePath();
CefString(&settings_.cache_path).clear();
}
}
if (!cache_path_.empty())
g_manager.Get().SetImplPath(this, cache_path_);
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);
}
// Initialize the PrefService object.
pref_service_ = browser_prefs::CreatePrefService(
this, cache_path_, !!settings_.persist_user_preferences);
content::BrowserContext::Initialize(this, GetPath());
resource_context_.reset(
@ -42,15 +300,9 @@ void CefBrowserContext::Initialize() {
if (extensions_enabled) {
// Create the custom ExtensionSystem first because other KeyedServices
// depend on it.
// The same CefExtensionSystem instance is shared by CefBrowserContextImpl
// and CefBrowserContextProxy objects.
extension_system_ = static_cast<extensions::CefExtensionSystem*>(
extensions::ExtensionSystem::Get(this));
if (is_proxy_) {
DCHECK(extension_system_->initialized());
} else {
extension_system_->InitForRegularProfile(true);
}
extension_system_->InitForRegularProfile(true);
resource_context_->set_extensions_info_map(extension_system_->info_map());
// Make sure the ProcessManager is created so that it receives extension
@ -58,52 +310,93 @@ void CefBrowserContext::Initialize() {
// background/event pages.
extensions::ProcessManager::Get(this);
}
}
void CefBrowserContext::PostInitialize() {
// Initialize visited links management.
base::FilePath visited_link_path;
if (!cache_path_.empty())
visited_link_path = cache_path_.Append(FILE_PATH_LITERAL("Visited Links"));
visitedlink_listener_ = new CefVisitedLinkListener;
visitedlink_master_.reset(new visitedlink::VisitedLinkMaster(
visitedlink_listener_, this, !visited_link_path.empty(), false,
visited_link_path, 0));
visitedlink_listener_->CreateListenerForContext(this);
visitedlink_master_->Init();
// Initialize proxy configuration tracker.
pref_proxy_config_tracker_.reset(new PrefProxyConfigTrackerImpl(
GetPrefs(),
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO})));
// Spell checking support and possibly other subsystems retrieve the
// PrefService associated with a BrowserContext via UserPrefs::Get().
PrefService* pref_service = GetPrefs();
DCHECK(pref_service);
user_prefs::UserPrefs::Set(this, pref_service);
const bool extensions_enabled = extensions::ExtensionsEnabled();
if (extensions_enabled && !is_proxy_)
if (extensions_enabled)
extension_system_->Init();
ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
this, resource_context_.get());
if (!net_service::IsEnabled()) {
// Create the CefURLRequestContextGetter via an indirect call to
// CreateRequestContext. Triggers a call to CefURLRequestContextGetter::
// GetURLRequestContext() on the IO thread which creates the
// CefURLRequestContext.
GetRequestContext();
DCHECK(url_request_getter_.get());
}
}
void CefBrowserContext::Shutdown() {
void CefBrowserContext::AddCefRequestContext(CefRequestContextImpl* context) {
CEF_REQUIRE_UIT();
request_context_set_.insert(context);
}
void CefBrowserContext::RemoveCefRequestContext(
CefRequestContextImpl* context) {
CEF_REQUIRE_UIT();
// Send notifications to clean up objects associated with this Profile.
MaybeSendDestroyedNotification();
ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext(
resource_context_.get());
// 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();
if (extensions::ExtensionsEnabled()) {
extension_system()->OnRequestContextDeleted(context);
}
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());
request_context_set_.erase(context);
// Delete ourselves when the reference count reaches zero.
if (request_context_set_.empty())
delete this;
}
CefRequestContextImpl* CefBrowserContext::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;
}
if (impl_only)
return nullptr;
return *request_context_set_.begin();
}
// static
CefBrowserContext* CefBrowserContext::GetForCachePath(
const base::FilePath& cache_path) {
return g_manager.Get().GetImplForPath(cache_path);
}
// static
CefBrowserContext* CefBrowserContext::GetForContext(
content::BrowserContext* context) {
return g_manager.Get().GetImplForContext(context);
}
// static
std::vector<CefBrowserContext*> CefBrowserContext::GetAll() {
return g_manager.Get().GetAllImpl();
}
content::ResourceContext* CefBrowserContext::GetResourceContext() {
@ -152,6 +445,186 @@ CefBrowserContext::GetURLLoaderFactory() {
->GetURLLoaderFactoryForBrowserProcess();
}
base::FilePath CefBrowserContext::GetPath() const {
return cache_path_;
}
std::unique_ptr<content::ZoomLevelDelegate>
CefBrowserContext::CreateZoomLevelDelegate(
const base::FilePath& partition_path) {
if (cache_path_.empty())
return std::unique_ptr<content::ZoomLevelDelegate>();
return base::WrapUnique(new ChromeZoomLevelPrefs(
GetPrefs(), cache_path_, partition_path,
zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()));
}
bool CefBrowserContext::IsOffTheRecord() const {
// CEF contexts are never flagged as off-the-record. It causes problems
// for the extension system.
return false;
}
content::DownloadManagerDelegate*
CefBrowserContext::GetDownloadManagerDelegate() {
if (!download_manager_delegate_) {
content::DownloadManager* manager =
BrowserContext::GetDownloadManager(this);
download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager));
}
return download_manager_delegate_.get();
}
content::BrowserPluginGuestManager* CefBrowserContext::GetGuestManager() {
DCHECK(extensions::ExtensionsEnabled());
return guest_view::GuestViewManager::FromBrowserContext(this);
}
storage::SpecialStoragePolicy* CefBrowserContext::GetSpecialStoragePolicy() {
return NULL;
}
content::PushMessagingService* CefBrowserContext::GetPushMessagingService() {
return NULL;
}
content::SSLHostStateDelegate* CefBrowserContext::GetSSLHostStateDelegate() {
if (!ssl_host_state_delegate_.get())
ssl_host_state_delegate_.reset(new CefSSLHostStateDelegate());
return ssl_host_state_delegate_.get();
}
content::PermissionControllerDelegate*
CefBrowserContext::GetPermissionControllerDelegate() {
return nullptr;
}
content::BackgroundFetchDelegate*
CefBrowserContext::GetBackgroundFetchDelegate() {
return nullptr;
}
content::BackgroundSyncController*
CefBrowserContext::GetBackgroundSyncController() {
return nullptr;
}
content::BrowsingDataRemoverDelegate*
CefBrowserContext::GetBrowsingDataRemoverDelegate() {
return nullptr;
}
net::URLRequestContextGetter* CefBrowserContext::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
CEF_REQUIRE_UIT();
DCHECK(!net_service::IsEnabled());
DCHECK(!url_request_getter_.get());
auto io_thread_runner =
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO});
// Initialize the proxy configuration service.
// TODO(cef): Determine if we can use the Chrome/Mojo implementation from
// https://crrev.com/d0d0d050
std::unique_ptr<net::ProxyConfigService> base_service(
net::ProxyResolutionService::CreateSystemProxyConfigService(
io_thread_runner));
std::unique_ptr<net::ProxyConfigService> proxy_config_service(
pref_proxy_config_tracker_->CreateTrackingProxyConfigService(
std::move(base_service)));
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] =
extensions::CreateExtensionProtocolHandler(IsOffTheRecord(),
extension_info_map);
}
url_request_getter_ = new CefURLRequestContextGetter(
settings_, GetPrefs(), io_thread_runner, protocol_handlers,
std::move(proxy_config_service), std::move(request_interceptors));
return url_request_getter_.get();
}
net::URLRequestContextGetter*
CefBrowserContext::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
return nullptr;
}
PrefService* CefBrowserContext::GetPrefs() {
return pref_service_.get();
}
const PrefService* CefBrowserContext::GetPrefs() const {
return pref_service_.get();
}
SimpleFactoryKey* CefBrowserContext::GetSimpleFactoryKey() const {
return nullptr;
}
CefRequestContextImpl* CefBrowserContext::GetCefRequestContext() const {
return GetCefRequestContext(false);
}
const CefRequestContextSettings& CefBrowserContext::GetSettings() const {
return settings_;
}
CefRefPtr<CefRequestContextHandler> CefBrowserContext::GetHandler() const {
return NULL;
}
HostContentSettingsMap* CefBrowserContext::GetHostContentSettingsMap() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!host_content_settings_map_.get()) {
// 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_ =
new HostContentSettingsMap(GetPrefs(), false, false, false, false);
// Change the default plugin policy.
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
const std::string& plugin_policy_str =
command_line->GetSwitchValueASCII(switches::kPluginPolicy);
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();
}
void CefBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) {
visitedlink_master_->AddURLs(urls);
}
void CefBrowserContext::RebuildTable(
const scoped_refptr<URLEnumerator>& enumerator) {
// Called when visited links will not or cannot be loaded from disk.
enumerator->OnComplete(true);
}
void CefBrowserContext::OnRenderFrameDeleted(int render_process_id,
int render_frame_id,
bool is_main_frame,

View File

@ -1,16 +1,20 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
// Copyright (c) 2011 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 CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_
#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_
#pragma once
#include "include/cef_request_context_handler.h"
#include "libcef/browser/chrome_profile_stub.h"
#include "libcef/browser/net/url_request_context_getter_impl.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/resource_context.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "components/proxy_config/pref_proxy_config_tracker.h"
#include "components/visitedlink/browser/visitedlink_delegate.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
@ -20,7 +24,7 @@
//
// WC = WebContents
// Content API representation of a browser. Created by BHI or the system (for
// popups) and owned by BHI. Keeps a pointer to BCI/BCP.
// popups) and owned by BHI. Keeps a pointer to BC.
//
// BHI = CefBrowserHostImpl
// Implements the CefBrowser and CefBrowserHost interfaces which are exposed
@ -29,56 +33,32 @@
//
// RCI = CefRequestContextImpl
// Implements the CefRequestContext interface which is exposed to clients.
// References the isolated BCI or creates a new BCP.
// References the isolated BC.
//
// BCI = CefBrowserContextImpl
// BC = CefBrowserContext
// Entry point from WC when using an isolated RCI. Owns the RC and creates the
// SPI indirectly. Owned by CefBrowserMainParts for the global context or RCI
// for non-global contexts.
//
// BCP = CefBrowserContextProxy
// Entry point from WC when using a custom RCI. Owns the RC and creates the
// URCGP and SPP. Owned by RCI.
//
// SPI = content::StoragePartitionImpl
// Owns storage-related objects like Quota, IndexedDB, Cache, etc. Created by
// StoragePartitionImplMap::Get(). Provides access to the URCGI. Life span is
// controlled indirectly by BCI.
//
// SPP = CefStoragePartitionProxy
// Forwards requests for storage-related objects to SPI. Created by
// GetStoragePartitionFromConfig() calling BCI::GetStoragePartitionProxy().
// Provides access to the URCGP. Life span is controlled by BCP.
// StoragePartitionImplMap::Get(). Provides access to the URCG. Life span is
// controlled indirectly by BC.
//
// RC = CefResourceContext
// Acts as a bridge for resource loading. URLRequest life span is tied to this
// object. Must be destroyed before the associated URCGI/URCGP. Life span is
// controlled by BCI/BCP.
// object. Must be destroyed before the associated URCG. Life span is
// controlled by BC.
//
// URCGI = CefURLRequestContextGetterImpl
// Creates and owns the URCI. Created by StoragePartitionImplMap::Get()
// calling BCI::CreateRequestContext(). Life span is controlled by RC and (for
// URCG = CefURLRequestContextGetter
// Creates and owns the URC. Created by StoragePartitionImplMap::Get()
// calling BC::CreateRequestContext(). Life span is controlled by RC and (for
// the global context) CefBrowserMainParts, and SPI.
//
// URCGP = CefURLRequestContextGetterProxy
// Creates and owns the URCP. Created by GetStoragePartitionFromConfig()
// calling BCI::GetStoragePartitionProxy(). Life span is controlled by RC and
// SPP.
//
// URCI = CefURLRequestContextImpl
// URC = CefURLRequestContext
// Owns various network-related objects including the isolated cookie manager.
// Owns URLRequest objects which must be destroyed first. Life span is
// controlled by URCGI.
//
// URCP = CefURLRequestContextProxy
// Creates the CSP and forwards requests to the objects owned by URCI. Owns
// URLRequest objects which must be destroyed first. Life span is controlled
// by URCGP.
//
// CSP = CefCookieStoreProxy
// Gives the CefCookieManager instance retrieved via CefRequestContextHandler
// an opportunity to handle cookie requests. Otherwise forwards requests via
// URCI to the isolated cookie manager. Life span is controlled by URCP.
// controlled by URCG.
//
//
// Relationship diagram:
@ -86,17 +66,13 @@
// own = ownership (std::unique_ptr)
// ptr = raw pointer
//
// CefBrowserMainParts----\ isolated cookie manager, etc.
// | \ ^
// own ref ref/own
// v v |
// /---> BCI -own-> SPI -ref-> URCGI --own-> URCI <-ptr-- CSP
// / ^ ^ ^ ^
// ptr ptr ptr ref /
// / | | | /
// BHI -own-> WC -ptr-> BCP -own-> SPP -ref-> URCGP -own-> URCP --ref-/
// CefBrowserMainParts--\ isolated cookie manager, etc.
// | \ ^
// own ref ref/own
// v v |
// BHI -own-> WC -ptr-> BC -own-> SPI -ref-> URCG --own-> URC
//
// BHI -ref-> RCI -own-> BCI/BCP -own-> RC -ref-> URCGI/URCGP
// BHI -ref-> RCI -own-> BC -own-> RC -ref-> URCG
//
//
// How shutdown works:
@ -104,21 +80,24 @@
// ref release, etc.
// 2. CefRequestContextImpl is destroyed (possibly asynchronously) on the UI
// thread due to CefBrowserHostImpl destruction, ref release, etc.
// 3. CefBrowserContext* is destroyed on the UI thread due to
// CefRequestContextImpl destruction (*Impl, *Proxy) or deletion in
// CefBrowserMainParts::PostMainMessageLoopRun() (*Impl).
// 3. CefBrowserContext is destroyed on the UI thread due to
// CefRequestContextImpl destruction or deletion in
// CefBrowserMainParts::PostMainMessageLoopRun().
// 4. CefResourceContext is destroyed asynchronously on the IO thread due to
// CefBrowserContext* destruction. This cancels/destroys any pending
// CefBrowserContext destruction. This cancels/destroys any pending
// URLRequests.
// 5. CefURLRequestContextGetter* is destroyed asynchronously on the IO thread
// due to CefResourceContext destruction (*Impl, *Proxy) or ref release in
// CefBrowserMainParts::PostMainMessageLoopRun() (*Impl). This may be delayed
// if other network-related objects still have a reference to it.
// 6. CefURLRequestContext* is destroyed on the IO thread due to
// CefURLRequestContextGetter* destruction.
// 5. CefURLRequestContextGetter is destroyed asynchronously on the IO thread
// due to CefResourceContext destruction (or ref release in
// CefBrowserMainParts::PostMainMessageLoopRun. This may be delayed if other
// network-related objects still have a reference to it.
// 6. CefURLRequestContext is destroyed on the IO thread due to
// CefURLRequestContextGetter destruction.
*/
class CefDownloadManagerDelegate;
class CefRequestContextImpl;
class CefSSLHostStateDelegate;
class CefVisitedLinkListener;
class HostContentSettingsMap;
class PrefService;
@ -126,15 +105,36 @@ namespace extensions {
class CefExtensionSystem;
}
namespace visitedlink {
class VisitedLinkMaster;
}
// Main entry point for configuring behavior on a per-browser basis. An instance
// of this class is passed to WebContents::Create in CefBrowserHostImpl::
// CreateInternal. Only accessed on the UI thread unless otherwise indicated.
class CefBrowserContext : public ChromeProfileStub {
class CefBrowserContext : public ChromeProfileStub,
public visitedlink::VisitedLinkDelegate {
public:
explicit CefBrowserContext(bool is_proxy);
explicit CefBrowserContext(const CefRequestContextSettings& settings);
// Returns the existing instance, if any, associated with the specified
// |cache_path|.
static CefBrowserContext* GetForCachePath(const base::FilePath& cache_path);
// Returns the underlying CefBrowserContext if any.
static CefBrowserContext* GetForContext(content::BrowserContext* context);
// Returns all existing CefBrowserContext.
static std::vector<CefBrowserContext*> GetAll();
// Must be called immediately after this object is created.
virtual void Initialize();
void Initialize();
// Track associated CefRequestContextImpl objects. This object will delete
// itself when the count reaches zero.
void AddCefRequestContext(CefRequestContextImpl* context);
void RemoveCefRequestContext(CefRequestContextImpl* context);
CefRequestContextImpl* GetCefRequestContext(bool impl_only) const;
// BrowserContext methods.
content::ResourceContext* GetResourceContext() override;
@ -150,31 +150,59 @@ class CefBrowserContext : public ChromeProfileStub {
std::vector<network::mojom::CorsOriginPatternPtr> allow_patterns,
std::vector<network::mojom::CorsOriginPatternPtr> block_patterns,
base::OnceClosure closure) override;
base::FilePath GetPath() const override;
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath& partition_path) override;
bool IsOffTheRecord() const override;
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
content::PushMessagingService* GetPushMessagingService() override;
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::PermissionControllerDelegate* GetPermissionControllerDelegate()
override;
content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
content::BackgroundSyncController* GetBackgroundSyncController() override;
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
override;
net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
// Profile methods.
ChromeZoomLevelPrefs* GetZoomLevelPrefs() override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
PrefService* GetPrefs() override;
bool AllowsBrowserWindows() const override { return false; }
const PrefService* GetPrefs() const override;
SimpleFactoryKey* GetSimpleFactoryKey() const override;
// Returns a RequestContext associated with this object. If this object is a
// *Proxy then it will return the single associated proxy RequestContext. If
// this object is an *Impl then it will return the first non-proxy
// RequestContext, if one exists, otherwise the first proxy RequestContext.
virtual CefRequestContextImpl* GetCefRequestContext() const = 0;
// visitedlink::VisitedLinkDelegate methods.
void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override;
// Returns the first RequestContext without a handler, if one exists,
// otherwise the first RequestContext.
CefRequestContextImpl* GetCefRequestContext() const;
// Returns the settings associated with this object. Safe to call from any
// thread.
virtual const CefRequestContextSettings& GetSettings() const = 0;
const CefRequestContextSettings& GetSettings() const;
// Returns the handler associated with this object. Safe to call from any
// thread.
virtual CefRefPtr<CefRequestContextHandler> GetHandler() const = 0;
CefRefPtr<CefRequestContextHandler> GetHandler() const;
// Settings for plugins and extensions.
virtual HostContentSettingsMap* GetHostContentSettingsMap() = 0;
HostContentSettingsMap* GetHostContentSettingsMap();
// Called from CefBrowserHostImpl::DidNavigateAnyFrame to update the table of
// visited links.
virtual void AddVisitedURLs(const std::vector<GURL>& urls) = 0;
void AddVisitedURLs(const std::vector<GURL>& urls);
// Called from CefBrowserHostImpl::RenderFrameDeleted or
// CefMimeHandlerViewGuestDelegate::OnGuestDetached when a render frame is
@ -195,27 +223,41 @@ class CefBrowserContext : public ChromeProfileStub {
return extension_system_;
}
bool is_proxy() const { return is_proxy_; }
protected:
~CefBrowserContext() override;
// Must be called after all services have been initialized.
void PostInitialize();
// Must be called before the child object destructor has completed.
void Shutdown();
// Guaranteed to exist once this object has been initialized.
scoped_refptr<CefURLRequestContextGetter> request_context_getter() const {
return url_request_getter_;
}
private:
// True if this CefBrowserContext is a CefBrowserContextProxy.
const bool is_proxy_;
// Allow deletion via std::unique_ptr().
friend std::default_delete<CefBrowserContext>;
~CefBrowserContext() override;
// Members initialized during construction are safe to access from any thread.
CefRequestContextSettings settings_;
base::FilePath cache_path_;
// CefRequestContextImpl objects referencing this object.
std::set<CefRequestContextImpl*> request_context_set_;
std::unique_ptr<PrefService> pref_service_;
std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
std::unique_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<CefURLRequestContextGetter> url_request_getter_;
std::unique_ptr<CefSSLHostStateDelegate> ssl_host_state_delegate_;
scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
std::unique_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
// |visitedlink_listener_| is owned by visitedlink_master_.
CefVisitedLinkListener* visitedlink_listener_;
std::unique_ptr<CefResourceContext> resource_context_;
// Owned by the KeyedService system.
extensions::CefExtensionSystem* extension_system_;
extensions::CefExtensionSystem* extension_system_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContext);
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_

View File

@ -1,562 +0,0 @@
// 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.
#include "libcef/browser/browser_context_impl.h"
#include <map>
#include <utility>
#include "libcef/browser/browser_context_proxy.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/download_manager_delegate.h"
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/prefs/browser_prefs.h"
#include "libcef/browser/request_context_impl.h"
#include "libcef/browser/ssl_host_state_delegate.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/net_service/util.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/font_family_cache.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "components/prefs/pref_service.h"
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
#include "components/visitedlink/browser/visitedlink_event_listener.h"
#include "components/visitedlink/browser/visitedlink_master.h"
#include "components/zoom/zoom_event_manager.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/storage_partition.h"
#include "extensions/browser/extension_protocols.h"
#include "extensions/common/constants.h"
#include "net/proxy_resolution/proxy_config_service.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
using content::BrowserThread;
namespace {
// Manages the global list of Impl instances.
class ImplManager {
public:
typedef std::vector<CefBrowserContextImpl*> Vector;
ImplManager() {}
~ImplManager() {
DCHECK(all_.empty());
DCHECK(map_.empty());
}
void AddImpl(CefBrowserContextImpl* impl) {
CEF_REQUIRE_UIT();
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();
if (!context)
return NULL;
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);
}
Vector::iterator it = all_.begin();
for (; it != all_.end(); ++it) {
if (*it == cef_context_impl)
return *it;
}
return NULL;
}
void SetImplPath(CefBrowserContextImpl* impl, const base::FilePath& path) {
CEF_REQUIRE_UIT();
DCHECK(!path.empty());
DCHECK(IsValidImpl(impl));
DCHECK(GetImplForPath(path) == NULL);
map_.insert(std::make_pair(path, impl));
}
CefBrowserContextImpl* GetImplForPath(const base::FilePath& path) {
CEF_REQUIRE_UIT();
DCHECK(!path.empty());
PathMap::const_iterator it = map_.find(path);
if (it != map_.end())
return it->second;
return NULL;
}
const Vector GetAllImpl() const { return all_; }
private:
Vector::iterator GetImplPos(const CefBrowserContextImpl* impl) {
Vector::iterator it = all_.begin();
for (; it != all_.end(); ++it) {
if (*it == impl)
return it;
}
return all_.end();
}
typedef std::map<base::FilePath, CefBrowserContextImpl*> PathMap;
PathMap map_;
Vector all_;
DISALLOW_COPY_AND_ASSIGN(ImplManager);
};
#if DCHECK_IS_ON()
// Because of DCHECK()s in the object destructor.
base::LazyInstance<ImplManager>::DestructorAtExit g_manager =
LAZY_INSTANCE_INITIALIZER;
#else
base::LazyInstance<ImplManager>::Leaky g_manager = LAZY_INSTANCE_INITIALIZER;
#endif
} // namespace
// Creates and manages VisitedLinkEventListener objects for each
// CefBrowserContext sharing the same VisitedLinkMaster.
class CefVisitedLinkListener : public visitedlink::VisitedLinkMaster::Listener {
public:
CefVisitedLinkListener() { DCHECK(listener_map_.empty()); }
void CreateListenerForContext(const CefBrowserContext* context) {
CEF_REQUIRE_UIT();
auto listener = std::make_unique<visitedlink::VisitedLinkEventListener>(
const_cast<CefBrowserContext*>(context));
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.
void NewTable(base::ReadOnlySharedMemoryRegion* table_region) override {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.begin();
for (; it != listener_map_.end(); ++it)
it->second->NewTable(table_region);
}
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*,
std::unique_ptr<visitedlink::VisitedLinkEventListener>>
ListenerMap;
ListenerMap listener_map_;
DISALLOW_COPY_AND_ASSIGN(CefVisitedLinkListener);
};
CefBrowserContextImpl::CefBrowserContextImpl(
const CefRequestContextSettings& settings)
: CefBrowserContext(false), settings_(settings) {
g_manager.Get().AddImpl(this);
}
CefBrowserContextImpl::~CefBrowserContextImpl() {
CEF_REQUIRE_UIT();
// No CefRequestContextImpl should be referencing this object any longer.
DCHECK(request_context_set_.empty());
// Unregister the context first to avoid re-entrancy during shutdown.
g_manager.Get().RemoveImpl(this, cache_path_);
Shutdown();
visitedlink_listener_->RemoveListenerForContext(this);
// The FontFamilyCache references the ProxyService so delete it before the
// ProxyService is deleted.
SetUserData(&kFontFamilyCacheKey, NULL);
pref_proxy_config_tracker_->DetachFromPrefService();
if (url_request_getter_)
url_request_getter_->ShutdownOnUIThread();
if (host_content_settings_map_)
host_content_settings_map_->ShutdownOnUIThread();
// Delete the download manager delegate here because otherwise we'll crash
// when it's accessed from the content::BrowserContext destructor.
if (download_manager_delegate_)
download_manager_delegate_.reset(NULL);
}
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_)) {
LOG(ERROR) << "The cache_path directory could not be created: "
<< cache_path_.value();
cache_path_ = base::FilePath();
CefString(&settings_.cache_path).clear();
}
}
if (!cache_path_.empty())
g_manager.Get().SetImplPath(this, cache_path_);
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);
}
// Initialize the PrefService object.
pref_service_ = browser_prefs::CreatePrefService(
this, cache_path_, !!settings_.persist_user_preferences);
CefBrowserContext::Initialize();
// Initialize visited links management.
base::FilePath visited_link_path;
if (!cache_path_.empty())
visited_link_path = cache_path_.Append(FILE_PATH_LITERAL("Visited Links"));
visitedlink_listener_ = new CefVisitedLinkListener;
visitedlink_master_.reset(new visitedlink::VisitedLinkMaster(
visitedlink_listener_, this, !visited_link_path.empty(), false,
visited_link_path, 0));
visitedlink_listener_->CreateListenerForContext(this);
visitedlink_master_->Init();
// Initialize proxy configuration tracker.
pref_proxy_config_tracker_.reset(new PrefProxyConfigTrackerImpl(
GetPrefs(),
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO})));
CefBrowserContext::PostInitialize();
if (!net_service::IsEnabled()) {
// 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());
}
// 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);
}
void CefBrowserContextImpl::AddProxy(const CefBrowserContextProxy* proxy) {
CEF_REQUIRE_UIT();
visitedlink_listener_->CreateListenerForContext(proxy);
}
void CefBrowserContextImpl::RemoveProxy(const CefBrowserContextProxy* proxy) {
CEF_REQUIRE_UIT();
visitedlink_listener_->RemoveListenerForContext(proxy);
}
void CefBrowserContextImpl::AddCefRequestContext(
CefRequestContextImpl* context) {
CEF_REQUIRE_UIT();
request_context_set_.insert(context);
}
void CefBrowserContextImpl::RemoveCefRequestContext(
CefRequestContextImpl* context) {
CEF_REQUIRE_UIT();
if (extensions::ExtensionsEnabled()) {
extension_system()->OnRequestContextDeleted(context);
}
request_context_set_.erase(context);
// Delete ourselves when the reference count reaches zero.
if (request_context_set_.empty())
delete this;
}
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;
}
if (impl_only)
return nullptr;
return *request_context_set_.begin();
}
// static
CefBrowserContextImpl* CefBrowserContextImpl::GetForCachePath(
const base::FilePath& cache_path) {
return g_manager.Get().GetImplForPath(cache_path);
}
// static
CefBrowserContextImpl* CefBrowserContextImpl::GetForContext(
content::BrowserContext* context) {
return g_manager.Get().GetImplForContext(context);
}
// static
std::vector<CefBrowserContextImpl*> CefBrowserContextImpl::GetAll() {
return g_manager.Get().GetAllImpl();
}
base::FilePath CefBrowserContextImpl::GetPath() const {
return cache_path_;
}
std::unique_ptr<content::ZoomLevelDelegate>
CefBrowserContextImpl::CreateZoomLevelDelegate(
const base::FilePath& partition_path) {
if (cache_path_.empty())
return std::unique_ptr<content::ZoomLevelDelegate>();
return base::WrapUnique(new ChromeZoomLevelPrefs(
GetPrefs(), cache_path_, partition_path,
zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()));
}
bool CefBrowserContextImpl::IsOffTheRecord() const {
// CEF contexts are never flagged as off-the-record. It causes problems
// for the extension system.
return false;
}
content::DownloadManagerDelegate*
CefBrowserContextImpl::GetDownloadManagerDelegate() {
if (!download_manager_delegate_) {
content::DownloadManager* manager =
BrowserContext::GetDownloadManager(this);
download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager));
}
return download_manager_delegate_.get();
}
content::BrowserPluginGuestManager* CefBrowserContextImpl::GetGuestManager() {
DCHECK(extensions::ExtensionsEnabled());
return guest_view::GuestViewManager::FromBrowserContext(this);
}
storage::SpecialStoragePolicy*
CefBrowserContextImpl::GetSpecialStoragePolicy() {
return NULL;
}
content::PushMessagingService*
CefBrowserContextImpl::GetPushMessagingService() {
return NULL;
}
content::SSLHostStateDelegate*
CefBrowserContextImpl::GetSSLHostStateDelegate() {
if (!ssl_host_state_delegate_.get())
ssl_host_state_delegate_.reset(new CefSSLHostStateDelegate());
return ssl_host_state_delegate_.get();
}
content::PermissionControllerDelegate*
CefBrowserContextImpl::GetPermissionControllerDelegate() {
return nullptr;
}
content::BackgroundFetchDelegate*
CefBrowserContextImpl::GetBackgroundFetchDelegate() {
return nullptr;
}
content::BackgroundSyncController*
CefBrowserContextImpl::GetBackgroundSyncController() {
return nullptr;
}
content::BrowsingDataRemoverDelegate*
CefBrowserContextImpl::GetBrowsingDataRemoverDelegate() {
return nullptr;
}
net::URLRequestContextGetter* CefBrowserContextImpl::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
CEF_REQUIRE_UIT();
DCHECK(!net_service::IsEnabled());
DCHECK(!url_request_getter_.get());
auto io_thread_runner =
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO});
// Initialize the proxy configuration service.
// TODO(cef): Determine if we can use the Chrome/Mojo implementation from
// https://crrev.com/d0d0d050
std::unique_ptr<net::ProxyConfigService> base_service(
net::ProxyResolutionService::CreateSystemProxyConfigService(
io_thread_runner));
std::unique_ptr<net::ProxyConfigService> proxy_config_service(
pref_proxy_config_tracker_->CreateTrackingProxyConfigService(
std::move(base_service)));
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] =
extensions::CreateExtensionProtocolHandler(IsOffTheRecord(),
extension_info_map);
}
url_request_getter_ = new CefURLRequestContextGetterImpl(
settings_, GetPrefs(), io_thread_runner, protocol_handlers,
std::move(proxy_config_service), std::move(request_interceptors));
return url_request_getter_.get();
}
net::URLRequestContextGetter*
CefBrowserContextImpl::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
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();
}
SimpleFactoryKey* CefBrowserContextImpl::GetSimpleFactoryKey() const {
return nullptr;
}
CefRequestContextImpl* CefBrowserContextImpl::GetCefRequestContext() const {
return GetCefRequestContext(false);
}
const CefRequestContextSettings& CefBrowserContextImpl::GetSettings() const {
return settings_;
}
CefRefPtr<CefRequestContextHandler> CefBrowserContextImpl::GetHandler() const {
return NULL;
}
HostContentSettingsMap* CefBrowserContextImpl::GetHostContentSettingsMap() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!host_content_settings_map_.get()) {
// 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_ =
new HostContentSettingsMap(GetPrefs(), false, false, false, false);
// Change the default plugin policy.
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
const std::string& plugin_policy_str =
command_line->GetSwitchValueASCII(switches::kPluginPolicy);
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();
}
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);
}

View File

@ -1,136 +0,0 @@
// Copyright (c) 2011 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 CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_
#pragma once
#include "libcef/browser/browser_context.h"
#include "libcef/browser/net/url_request_context_getter_impl.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "components/proxy_config/pref_proxy_config_tracker.h"
#include "components/visitedlink/browser/visitedlink_delegate.h"
class CefBrowserContextProxy;
class CefDownloadManagerDelegate;
class CefSSLHostStateDelegate;
class CefVisitedLinkListener;
namespace visitedlink {
class VisitedLinkMaster;
}
// Isolated BrowserContext implementation. Life span is controlled by
// CefBrowserMainParts for the global context and CefRequestContextImpl
// for non-global contexts. Only accessed on the UI thread unless otherwise
// indicated. See browser_context.h for an object relationship diagram.
class CefBrowserContextImpl : public CefBrowserContext,
public visitedlink::VisitedLinkDelegate {
public:
explicit CefBrowserContextImpl(const CefRequestContextSettings& settings);
// Returns the existing instance, if any, associated with the specified
// |cache_path|.
static CefBrowserContextImpl* GetForCachePath(
const base::FilePath& cache_path);
// Returns the underlying CefBrowserContextImpl if any.
static CefBrowserContextImpl* GetForContext(content::BrowserContext* context);
// Returns all existing CefBrowserContextImpl.
static std::vector<CefBrowserContextImpl*> GetAll();
// Must be called immediately after this object is created.
void Initialize() override;
// Track associated CefBrowserContextProxy objects.
void AddProxy(const CefBrowserContextProxy* proxy);
void RemoveProxy(const CefBrowserContextProxy* proxy);
// Track associated CefRequestContextImpl objects. This object will delete
// itself when the count reaches zero.
void AddCefRequestContext(CefRequestContextImpl* context);
void RemoveCefRequestContext(CefRequestContextImpl* context);
CefRequestContextImpl* GetCefRequestContext(bool impl_only) const;
// BrowserContext methods.
base::FilePath GetPath() const override;
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath& partition_path) override;
bool IsOffTheRecord() const override;
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
content::PushMessagingService* GetPushMessagingService() override;
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::PermissionControllerDelegate* GetPermissionControllerDelegate()
override;
content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
content::BackgroundSyncController* GetBackgroundSyncController() override;
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
override;
net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
content::StoragePartition* GetStoragePartitionProxy(
content::BrowserContext* browser_context,
content::StoragePartition* partition_impl) override;
// Profile methods.
PrefService* GetPrefs() override;
bool AllowsBrowserWindows() const override { return false; }
const PrefService* GetPrefs() const override;
SimpleFactoryKey* GetSimpleFactoryKey() const override;
// CefBrowserContext methods.
CefRequestContextImpl* GetCefRequestContext() const override;
const CefRequestContextSettings& GetSettings() const override;
CefRefPtr<CefRequestContextHandler> GetHandler() const override;
HostContentSettingsMap* GetHostContentSettingsMap() override;
void AddVisitedURLs(const std::vector<GURL>& urls) override;
// visitedlink::VisitedLinkDelegate methods.
void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override;
// Guaranteed to exist once this object has been initialized.
scoped_refptr<CefURLRequestContextGetterImpl> request_context_getter() const {
return url_request_getter_;
}
private:
// Allow deletion via std::unique_ptr().
friend std::default_delete<CefBrowserContextImpl>;
~CefBrowserContextImpl() override;
// Members initialized during construction are safe to access from any thread.
CefRequestContextSettings settings_;
base::FilePath cache_path_;
// CefRequestContextImpl objects referencing this object.
std::set<CefRequestContextImpl*> request_context_set_;
std::unique_ptr<PrefService> pref_service_;
std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
std::unique_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<CefURLRequestContextGetterImpl> url_request_getter_;
std::unique_ptr<CefSSLHostStateDelegate> ssl_host_state_delegate_;
scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
std::unique_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
// |visitedlink_listener_| is owned by visitedlink_master_.
CefVisitedLinkListener* visitedlink_listener_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContextImpl);
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_

View File

@ -1,267 +0,0 @@
// 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.
#include "libcef/browser/browser_context_proxy.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/download_manager_delegate.h"
#include "libcef/browser/net/url_request_context_getter_proxy.h"
#include "libcef/browser/storage_partition_proxy.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/net_service/util.h"
#include "base/logging.h"
#include "chrome/browser/font_family_cache.h"
#include "components/guest_view/common/guest_view_constants.h"
#include "components/visitedlink/browser/visitedlink_master.h"
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
#include "content/browser/resource_context_impl.h"
#include "content/browser/streams/stream_context.h"
#include "content/browser/webui/url_data_manager.h"
#include "content/public/browser/storage_partition.h"
#include "services/service_manager/public/cpp/service.h"
namespace {
bool ShouldProxyUserData(const void* key) {
// If this value is not proxied then multiple StoragePartitionImpl objects
// will be created and filesystem API access will fail, among other things.
if (key == content::BrowserContext::GetStoragePartitionMapUserDataKey())
return true;
// If these values are not proxied then blob data fails to load for the PDF
// extension.
// See also the call to InitializeResourceContext().
if (key == content::ChromeBlobStorageContext::GetUserDataKey() ||
key == content::StreamContext::GetUserDataKey()) {
return true;
}
// If this value is not proxied then CefBrowserContextImpl::GetGuestManager()
// returns NULL.
// See also CefExtensionsAPIClient::CreateGuestViewManagerDelegate.
if (key == guest_view::kGuestViewManagerKeyName)
return true;
// If this value is not proxied then there will be a use-after-free while
// destroying the FontFamilyCache because it will try to access the
// ProxyService owned by CefBrowserContextImpl (which has already been freed).
if (key == kFontFamilyCacheKey)
return true;
// If this value is not proxied WebUI will fail to load.
if (key == content::URLDataManager::GetUserDataKey())
return true;
return false;
}
} // namespace
CefBrowserContextProxy::CefBrowserContextProxy(
CefRequestContextImpl* const request_context,
CefRefPtr<CefRequestContextHandler> handler,
CefBrowserContextImpl* parent)
: CefBrowserContext(true),
request_context_(request_context),
handler_(handler),
parent_(parent) {
DCHECK(handler_.get());
DCHECK(parent_);
parent_->AddProxy(this);
}
CefBrowserContextProxy::~CefBrowserContextProxy() {
CEF_REQUIRE_UIT();
Shutdown();
parent_->RemoveProxy(this);
}
void CefBrowserContextProxy::Initialize() {
CefBrowserContext::Initialize();
// This object's CefResourceContext needs to proxy some UserData requests to
// the parent object's CefResourceContext.
resource_context()->set_parent(parent_->resource_context());
CefBrowserContext::PostInitialize();
}
base::SupportsUserData::Data* CefBrowserContextProxy::GetUserData(
const void* key) const {
if (ShouldProxyUserData(key))
return parent_->GetUserData(key);
return BrowserContext::GetUserData(key);
}
void CefBrowserContextProxy::SetUserData(const void* key,
std::unique_ptr<Data> data) {
if (ShouldProxyUserData(key))
parent_->SetUserData(key, std::move(data));
else
BrowserContext::SetUserData(key, std::move(data));
}
void CefBrowserContextProxy::RemoveUserData(const void* key) {
if (ShouldProxyUserData(key))
parent_->RemoveUserData(key);
else
BrowserContext::RemoveUserData(key);
}
base::FilePath CefBrowserContextProxy::GetPath() const {
return parent_->GetPath();
}
std::unique_ptr<content::ZoomLevelDelegate>
CefBrowserContextProxy::CreateZoomLevelDelegate(
const base::FilePath& partition_path) {
return parent_->CreateZoomLevelDelegate(partition_path);
}
bool CefBrowserContextProxy::IsOffTheRecord() const {
return parent_->IsOffTheRecord();
}
content::DownloadManagerDelegate*
CefBrowserContextProxy::GetDownloadManagerDelegate() {
if (!download_manager_delegate_) {
content::DownloadManager* manager =
BrowserContext::GetDownloadManager(this);
download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager));
}
return download_manager_delegate_.get();
}
content::BrowserPluginGuestManager* CefBrowserContextProxy::GetGuestManager() {
return parent_->GetGuestManager();
}
storage::SpecialStoragePolicy*
CefBrowserContextProxy::GetSpecialStoragePolicy() {
return parent_->GetSpecialStoragePolicy();
}
content::PushMessagingService*
CefBrowserContextProxy::GetPushMessagingService() {
return parent_->GetPushMessagingService();
}
content::SSLHostStateDelegate*
CefBrowserContextProxy::GetSSLHostStateDelegate() {
return parent_->GetSSLHostStateDelegate();
}
content::ClientHintsControllerDelegate*
CefBrowserContextProxy::GetClientHintsControllerDelegate() {
return parent_->GetClientHintsControllerDelegate();
}
content::PermissionControllerDelegate*
CefBrowserContextProxy::GetPermissionControllerDelegate() {
return parent_->GetPermissionControllerDelegate();
}
content::BackgroundFetchDelegate*
CefBrowserContextProxy::GetBackgroundFetchDelegate() {
return parent_->GetBackgroundFetchDelegate();
}
content::BackgroundSyncController*
CefBrowserContextProxy::GetBackgroundSyncController() {
return parent_->GetBackgroundSyncController();
}
content::BrowsingDataRemoverDelegate*
CefBrowserContextProxy::GetBrowsingDataRemoverDelegate() {
return parent_->GetBrowsingDataRemoverDelegate();
}
net::URLRequestContextGetter* CefBrowserContextProxy::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
// CefBrowserContextImpl::GetOrCreateStoragePartitionProxy is called instead
// of this method.
NOTREACHED();
return nullptr;
}
net::URLRequestContextGetter*
CefBrowserContextProxy::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
return nullptr;
}
std::unique_ptr<service_manager::Service>
CefBrowserContextProxy::HandleServiceRequest(
const std::string& service_name,
service_manager::mojom::ServiceRequest request) {
return parent_->HandleServiceRequest(service_name, std::move(request));
}
PrefService* CefBrowserContextProxy::GetPrefs() {
return parent_->GetPrefs();
}
bool CefBrowserContextProxy::AllowsBrowserWindows() const {
return parent_->AllowsBrowserWindows();
}
const PrefService* CefBrowserContextProxy::GetPrefs() const {
return parent_->GetPrefs();
}
SimpleFactoryKey* CefBrowserContextProxy::GetSimpleFactoryKey() const {
return parent_->GetSimpleFactoryKey();
}
CefRequestContextImpl* CefBrowserContextProxy::GetCefRequestContext() const {
return request_context_;
}
const CefRequestContextSettings& CefBrowserContextProxy::GetSettings() const {
return parent_->GetSettings();
}
CefRefPtr<CefRequestContextHandler> CefBrowserContextProxy::GetHandler() const {
return handler_;
}
HostContentSettingsMap* CefBrowserContextProxy::GetHostContentSettingsMap() {
return parent_->GetHostContentSettingsMap();
}
void CefBrowserContextProxy::AddVisitedURLs(const std::vector<GURL>& urls) {
parent_->AddVisitedURLs(urls);
}
content::StoragePartition*
CefBrowserContextProxy::GetOrCreateStoragePartitionProxy(
content::StoragePartition* partition_impl) {
CEF_REQUIRE_UIT();
if (!storage_partition_proxy_) {
scoped_refptr<CefURLRequestContextGetterProxy> url_request_getter;
if (!net_service::IsEnabled()) {
url_request_getter = new CefURLRequestContextGetterProxy(
handler_, parent_->request_context_getter());
}
storage_partition_proxy_.reset(
new CefStoragePartitionProxy(partition_impl, url_request_getter.get()));
// Associates UserData keys with the ResourceContext.
// Called from StoragePartitionImplMap::Get() for CefBrowserContextImpl.
content::InitializeResourceContext(this);
}
// There should only be one CefStoragePartitionProxy for this
// CefBrowserContextProxy.
DCHECK_EQ(storage_partition_proxy_->parent(), partition_impl);
return storage_partition_proxy_.get();
}

View File

@ -1,102 +0,0 @@
// Copyright (c) 2011 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 CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_
#pragma once
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_context_impl.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
class CefDownloadManagerDelegate;
class CefStoragePartitionProxy;
// BrowserContext implementation for a particular CefRequestContext. Life span
// is controlled by CefRequestContextImpl. Only accessed on the UI thread. See
// browser_context.h for an object relationship diagram.
class CefBrowserContextProxy : public CefBrowserContext {
public:
CefBrowserContextProxy(CefRequestContextImpl* const request_context,
CefRefPtr<CefRequestContextHandler> handler,
CefBrowserContextImpl* parent);
// Must be called immediately after this object is created.
void Initialize() override;
// SupportsUserData methods.
Data* GetUserData(const void* key) const override;
void SetUserData(const void* key, std::unique_ptr<Data> data) override;
void RemoveUserData(const void* key) override;
// BrowserContext methods.
base::FilePath GetPath() const override;
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath& partition_path) override;
bool IsOffTheRecord() const override;
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
content::PushMessagingService* GetPushMessagingService() override;
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate()
override;
content::PermissionControllerDelegate* GetPermissionControllerDelegate()
override;
content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
content::BackgroundSyncController* GetBackgroundSyncController() override;
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
override;
net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
std::unique_ptr<service_manager::Service> HandleServiceRequest(
const std::string& service_name,
service_manager::mojom::ServiceRequest request) override;
// Profile methods.
PrefService* GetPrefs() override;
bool AllowsBrowserWindows() const override;
const PrefService* GetPrefs() const override;
SimpleFactoryKey* GetSimpleFactoryKey() const override;
// CefBrowserContext methods.
CefRequestContextImpl* GetCefRequestContext() const override;
const CefRequestContextSettings& GetSettings() const override;
CefRefPtr<CefRequestContextHandler> GetHandler() const override;
HostContentSettingsMap* GetHostContentSettingsMap() override;
void AddVisitedURLs(const std::vector<GURL>& urls) override;
content::StoragePartition* GetOrCreateStoragePartitionProxy(
content::StoragePartition* partition_impl);
CefBrowserContextImpl* parent() const { return parent_; }
private:
// Allow deletion via std::unique_ptr() only.
friend std::default_delete<CefBrowserContextProxy>;
~CefBrowserContextProxy() override;
// Guaranteed to outlive this object.
CefRequestContextImpl* const request_context_;
// Members initialized during construction are safe to access from any thread.
CefRefPtr<CefRequestContextHandler> handler_;
CefBrowserContextImpl* parent_; // Guaranteed to outlive this object.
std::unique_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
std::unique_ptr<CefStoragePartitionProxy> storage_partition_proxy_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContextProxy);
};
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_PROXY_H_

View File

@ -9,7 +9,7 @@
#include <utility>
#include "libcef/browser/audio_mirror_destination.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_info.h"
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/browser_platform_delegate.h"
@ -317,7 +317,7 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
DCHECK(browser_context);
// A StoragePartitionImplMap must already exist for the BrowserContext. See
// additional comments in CefBrowserContextImpl::Initialize().
// additional comments in CefBrowserContext::Initialize().
DCHECK(browser_context->GetUserData(
content::BrowserContext::GetStoragePartitionMapUserDataKey()));
@ -3353,16 +3353,11 @@ void CefBrowserHostImpl::CreateExtensionHost(
extensions::ViewType host_type) {
DCHECK(!extension_host_);
// Use the *Impl context because ProcessManager expects it for notification
// registration.
CefBrowserContextImpl* impl_context =
CefBrowserContextImpl::GetForContext(browser_context);
if (host_type == extensions::VIEW_TYPE_EXTENSION_DIALOG ||
host_type == extensions::VIEW_TYPE_EXTENSION_POPUP) {
// Create an extension host that we own.
extension_host_ = new extensions::CefExtensionViewHost(
this, extension, impl_context, host_contents, url, host_type);
this, extension, browser_context, host_contents, url, host_type);
// Trigger load of the extension URL.
extension_host_->CreateRenderViewSoon();
} else if (host_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) {
@ -3370,7 +3365,7 @@ void CefBrowserHostImpl::CreateExtensionHost(
// Create an extension host that will be owned by ProcessManager.
extension_host_ = new extensions::CefExtensionBackgroundHost(
this, base::BindOnce(&CefBrowserHostImpl::OnExtensionHostDeleted, this),
extension, impl_context, host_contents, url, host_type);
extension, browser_context, host_contents, url, host_type);
// Load will be triggered by ProcessManager::CreateBackgroundHost.
} else {
NOTREACHED() << " Unsupported extension host type: " << host_type;

View File

@ -8,7 +8,7 @@
#include <string>
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_context_keyed_service_factories.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
@ -198,7 +198,7 @@ void CefBrowserMainParts::PreMainMessageLoopRun() {
// Create the global RequestContext.
global_request_context_ =
CefRequestContextImpl::CreateGlobalRequestContext(settings);
CefBrowserContextImpl* browser_context = static_cast<CefBrowserContextImpl*>(
CefBrowserContext* browser_context = static_cast<CefBrowserContext*>(
global_request_context_->GetBrowserContext());
PostProfileInit();

View File

@ -6,7 +6,7 @@
#define CEF_LIBCEF_BROWSER_BROWSER_MAIN_H_
#pragma once
#include "libcef/browser/net/url_request_context_getter_impl.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/request_context_impl.h"
#include "base/macros.h"

View File

@ -5,7 +5,7 @@
#include "libcef/browser/chrome_browser_process_stub.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/chrome_profile_manager_stub.h"
#include "libcef/browser/prefs/browser_prefs.h"
#include "libcef/browser/thread_util.h"
@ -389,7 +389,7 @@ ChromeBrowserProcessStub::pref_service_factory() const {
content::BrowserContext*
ChromeBrowserProcessStub::GetBrowserContextRedirectedInIncognito(
content::BrowserContext* context) {
return CefBrowserContextImpl::GetForContext(context);
return CefBrowserContext::GetForContext(context);
}
content::BrowserContext*

View File

@ -5,7 +5,7 @@
#include "libcef/browser/chrome_profile_manager_stub.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/content_browser_client.h"
namespace {
@ -20,8 +20,8 @@ namespace {
// context for the currently active browser (e.g. the browser with input focus).
// Return the main context for now since we don't currently have a good way to
// determine that.
CefBrowserContextImpl* GetActiveBrowserContext() {
return static_cast<CefBrowserContextImpl*>(
CefBrowserContext* GetActiveBrowserContext() {
return static_cast<CefBrowserContext*>(
CefContentBrowserClient::Get()->request_context()->GetBrowserContext());
}
@ -34,8 +34,8 @@ ChromeProfileManagerStub::~ChromeProfileManagerStub() {}
Profile* ChromeProfileManagerStub::GetProfile(
const base::FilePath& profile_dir) {
CefBrowserContextImpl* browser_context =
CefBrowserContextImpl::GetForCachePath(profile_dir);
CefBrowserContext* browser_context =
CefBrowserContext::GetForCachePath(profile_dir);
if (!browser_context) {
// ProfileManager makes assumptions about profile directory paths that do
// not match CEF usage. For example, the default Chrome profile name is
@ -51,7 +51,7 @@ Profile* ChromeProfileManagerStub::GetProfile(
bool ChromeProfileManagerStub::IsValidProfile(const void* profile) {
if (!profile)
return false;
return !!CefBrowserContextImpl::GetForContext(
return !!CefBrowserContext::GetForContext(
reinterpret_cast<content::BrowserContext*>(const_cast<void*>(profile)));
}

View File

@ -8,7 +8,7 @@
#include <utility>
#include "include/cef_version.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/browser_info.h"
#include "libcef/browser/browser_info_manager.h"
@ -699,8 +699,8 @@ CefContentBrowserClient::GetExtraServiceManifests() {
bool CefContentBrowserClient::IsSameBrowserContext(
content::BrowserContext* context1,
content::BrowserContext* context2) {
return CefBrowserContextImpl::GetForContext(context1) ==
CefBrowserContextImpl::GetForContext(context2);
return CefBrowserContext::GetForContext(context1) ==
CefBrowserContext::GetForContext(context2);
}
void CefContentBrowserClient::AppendExtraCommandLineSwitches(

View File

@ -10,7 +10,7 @@
#include <utility>
#include "include/cef_request_context_handler.h"
#include "libcef/browser/net/url_request_context_getter_impl.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/request_context_impl.h"
#include "base/macros.h"

View File

@ -10,7 +10,6 @@
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/net/cookie_store_source.h"
#include "libcef/browser/net/network_delegate.h"
#include "libcef/common/net_service/util.h"
#include "libcef/common/task_runner_impl.h"
@ -118,17 +117,9 @@ void SetCookieCallbackImpl(CefRefPtr<CefSetCookieCallback> callback,
status == net::CanonicalCookie::CookieInclusionStatus::INCLUDE));
}
net::CookieStore* GetExistingCookieStoreHelper(
base::WeakPtr<CefCookieManagerImpl> cookie_manager) {
if (cookie_manager.get())
return cookie_manager->GetExistingCookieStore();
return nullptr;
}
} // namespace
CefCookieManagerImpl::CefCookieManagerImpl(bool is_blocking)
: is_blocking_(is_blocking), weak_ptr_factory_(this) {}
CefCookieManagerImpl::CefCookieManagerImpl() : weak_ptr_factory_(this) {}
CefCookieManagerImpl::~CefCookieManagerImpl() {
CEF_REQUIRE_IOT();
@ -139,18 +130,14 @@ void CefCookieManagerImpl::Initialize(
const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback) {
CHECK(!is_blocking_);
if (request_context.get()) {
request_context_ = request_context;
if (!net_service::IsEnabled()) {
request_context_->GetRequestContextImpl(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerImpl::InitWithContext, this, callback));
} else {
RunAsyncCompletionOnIOThread(callback);
}
DCHECK(request_context.get());
request_context_ = request_context;
if (!net_service::IsEnabled()) {
request_context_->GetRequestContextImpl(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerImpl::InitWithContext, this, callback));
} else {
SetStoragePath(path, persist_session_cookies, callback);
RunAsyncCompletionOnIOThread(callback);
}
}
@ -166,48 +153,21 @@ void CefCookieManagerImpl::GetCookieStore(
return;
}
if (HasContext()) {
RunMethodWithContext(
base::Bind(&CefCookieManagerImpl::GetCookieStoreWithContext, this,
task_runner, callback));
return;
}
DCHECK(is_blocking_ || cookie_source_);
// Binding ref-counted |this| to CookieStoreGetter may result in
// heap-use-after-free if (a) the CookieStoreGetter contains the last
// CefCookieManagerImpl reference and (b) that reference is released during
// execution of a CookieMonster callback (which then results in the
// CookieManager being deleted). Use WeakPtr instead of |this| so that, in
// that case, the CookieStoreGetter will return nullptr instead of keeping
// the CefCookieManagerImpl alive (see issue #1882).
const CookieStoreGetter& cookie_store_getter =
base::Bind(GetExistingCookieStoreHelper, weak_ptr_factory_.GetWeakPtr());
if (task_runner->BelongsToCurrentThread()) {
// Execute the callback immediately.
callback.Run(cookie_store_getter);
} else {
// Execute the callback on the target thread.
task_runner->PostTask(FROM_HERE, base::Bind(callback, cookie_store_getter));
}
RunMethodWithContext(
base::Bind(&CefCookieManagerImpl::GetCookieStoreWithContext, this,
task_runner, callback));
}
net::CookieStore* CefCookieManagerImpl::GetExistingCookieStore() {
CEF_REQUIRE_IOT();
if (cookie_source_) {
return cookie_source_->GetCookieStore();
} else if (request_context_impl_.get()) {
if (request_context_impl_.get()) {
net::CookieStore* cookie_store =
request_context_impl_->GetExistingCookieStore();
DCHECK(cookie_store);
return cookie_store;
}
DCHECK(is_blocking_);
if (!is_blocking_)
LOG(ERROR) << "Cookie store does not exist";
LOG(ERROR) << "Cookie store does not exist";
return nullptr;
}
@ -279,40 +239,6 @@ bool CefCookieManagerImpl::DeleteCookies(
return true;
}
bool CefCookieManagerImpl::SetStoragePath(
const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback) {
if (!CEF_CURRENTLY_ON_IOT()) {
CEF_POST_TASK(
CEF_IOT,
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::SetStoragePath),
this, path, persist_session_cookies, callback));
return true;
}
if (HasContext()) {
RunMethodWithContext(
base::Bind(&CefCookieManagerImpl::SetStoragePathWithContext, this, path,
persist_session_cookies, callback));
return true;
}
base::FilePath new_path;
if (!path.empty())
new_path = base::FilePath(path);
if (!cookie_source_) {
cookie_source_.reset(new CefCookieStoreOwnerSource());
}
cookie_source_->SetCookieStoragePath(new_path, persist_session_cookies,
g_browser_process->net_log());
RunAsyncCompletionOnIOThread(callback);
return true;
}
bool CefCookieManagerImpl::FlushStore(
CefRefPtr<CefCompletionCallback> callback) {
GetCookieStore(
@ -393,11 +319,6 @@ void CefCookieManagerImpl::SetCookieMonsterSchemes(
cookie_monster->SetCookieableSchemes(all_schemes);
}
bool CefCookieManagerImpl::HasContext() {
CEF_REQUIRE_IOT();
return (request_context_impl_.get() || request_context_.get());
}
void CefCookieManagerImpl::RunMethodWithContext(
const CefRequestContextImpl::RequestContextCallback& method) {
CEF_REQUIRE_IOT();
@ -415,7 +336,7 @@ void CefCookieManagerImpl::RunMethodWithContext(
void CefCookieManagerImpl::InitWithContext(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context) {
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
DCHECK(!request_context_impl_.get());
@ -430,26 +351,10 @@ void CefCookieManagerImpl::InitWithContext(
RunAsyncCompletionOnIOThread(callback);
}
void CefCookieManagerImpl::SetStoragePathWithContext(
const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context) {
CEF_REQUIRE_IOT();
base::FilePath new_path;
if (!path.empty())
new_path = base::FilePath(path);
request_context->SetCookieStoragePath(new_path, persist_session_cookies);
RunAsyncCompletionOnIOThread(callback);
}
void CefCookieManagerImpl::SetSupportedSchemesWithContext(
const std::vector<std::string>& schemes,
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context) {
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
request_context->SetCookieSupportedSchemes(schemes);
@ -460,12 +365,12 @@ void CefCookieManagerImpl::SetSupportedSchemesWithContext(
void CefCookieManagerImpl::GetCookieStoreWithContext(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const CookieStoreCallback& callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context) {
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
DCHECK(request_context->GetExistingCookieStore());
const CookieStoreGetter& cookie_store_getter = base::Bind(
&CefURLRequestContextGetterImpl::GetExistingCookieStore, request_context);
&CefURLRequestContextGetter::GetExistingCookieStore, request_context);
if (task_runner->BelongsToCurrentThread()) {
// Execute the callback immediately.
@ -481,24 +386,14 @@ void CefCookieManagerImpl::SetSupportedSchemesInternal(
CefRefPtr<CefCompletionCallback> callback) {
CEF_REQUIRE_IOT();
if (HasContext()) {
if (!net_service::IsEnabled()) {
RunMethodWithContext(
base::Bind(&CefCookieManagerImpl::SetSupportedSchemesWithContext,
this, schemes, callback));
} else {
NOTIMPLEMENTED();
RunAsyncCompletionOnIOThread(callback);
}
return;
if (!net_service::IsEnabled()) {
RunMethodWithContext(
base::Bind(&CefCookieManagerImpl::SetSupportedSchemesWithContext, this,
schemes, callback));
} else {
NOTIMPLEMENTED();
RunAsyncCompletionOnIOThread(callback);
}
DCHECK(is_blocking_ || cookie_source_);
if (cookie_source_) {
cookie_source_->SetCookieSupportedSchemes(schemes);
}
RunAsyncCompletionOnIOThread(callback);
}
void CefCookieManagerImpl::VisitAllCookiesInternal(
@ -638,28 +533,5 @@ CefRefPtr<CefCookieManager> CefCookieManager::GetGlobalManager(
return NULL;
}
return CefRequestContext::GetGlobalContext()->GetDefaultCookieManager(
callback);
}
// static
CefRefPtr<CefCookieManager> CefCookieManager::GetBlockingManager() {
return new CefCookieManagerImpl(true);
}
// static
CefRefPtr<CefCookieManager> CefCookieManager::CreateManager(
const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback) {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return NULL;
}
CefRefPtr<CefCookieManagerImpl> cookie_manager =
new CefCookieManagerImpl(false);
cookie_manager->Initialize(NULL, path, persist_session_cookies, callback);
return cookie_manager.get();
return CefRequestContext::GetGlobalContext()->GetCookieManager(callback);
}

View File

@ -15,12 +15,10 @@
#include "base/memory/weak_ptr.h"
#include "net/cookies/cookie_monster.h"
class CefCookieStoreOwnerSource;
// Implementation of the CefCookieManager interface.
class CefCookieManagerImpl : public CefCookieManager {
public:
explicit CefCookieManagerImpl(bool is_blocking);
CefCookieManagerImpl();
~CefCookieManagerImpl() override;
// Must be called immediately after this object is created when |is_blocking|
@ -57,9 +55,6 @@ class CefCookieManagerImpl : public CefCookieManager {
bool DeleteCookies(const CefString& url,
const CefString& cookie_name,
CefRefPtr<CefDeleteCookiesCallback> callback) override;
bool SetStoragePath(const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback) override;
bool FlushStore(CefRefPtr<CefCompletionCallback> callback) override;
static bool GetCefCookie(const net::CanonicalCookie& cc, CefCookie& cookie);
@ -73,29 +68,21 @@ class CefCookieManagerImpl : public CefCookieManager {
const std::vector<std::string>& schemes);
private:
// Returns true if a context is or will be available.
bool HasContext();
// Execute |method| on the IO thread once the request context is available.
void RunMethodWithContext(
const CefRequestContextImpl::RequestContextCallback& method);
void InitWithContext(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
void SetStoragePathWithContext(
const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
scoped_refptr<CefURLRequestContextGetter> request_context);
void SetSupportedSchemesWithContext(
const std::vector<std::string>& schemes,
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
scoped_refptr<CefURLRequestContextGetter> request_context);
void GetCookieStoreWithContext(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const CookieStoreCallback& callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
scoped_refptr<CefURLRequestContextGetter> request_context);
void SetSupportedSchemesInternal(const std::vector<std::string>& schemes,
CefRefPtr<CefCompletionCallback> callback);
@ -116,15 +103,9 @@ class CefCookieManagerImpl : public CefCookieManager {
void FlushStoreInternal(CefRefPtr<CefCompletionCallback> callback,
const CookieStoreGetter& cookie_store_getter);
// If true all cookies will be blocked.
const bool is_blocking_;
// Used for cookie monsters owned by the context.
// Context that owns the cookie monster.
CefRefPtr<CefRequestContextImpl> request_context_;
scoped_refptr<CefURLRequestContextGetterImpl> request_context_impl_;
// Used for cookie monsters owned by this object.
std::unique_ptr<CefCookieStoreOwnerSource> cookie_source_;
scoped_refptr<CefURLRequestContextGetter> request_context_impl_;
// Must be the last member.
base::WeakPtrFactory<CefCookieManagerImpl> weak_ptr_factory_;

View File

@ -4,7 +4,7 @@
#include "libcef/browser/extensions/browser_extensions_util.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/extensions/extensions_util.h"
@ -140,8 +140,8 @@ CefRefPtr<CefBrowserHostImpl> GetBrowserForTabId(
if (tab_id < 0 || !browser_context)
return nullptr;
CefBrowserContextImpl* browser_context_impl =
CefBrowserContextImpl::GetForContext(browser_context);
CefBrowserContext* browser_context_impl =
CefBrowserContext::GetForContext(browser_context);
CefBrowserInfoManager::BrowserInfoList list;
CefBrowserInfoManager::GetInstance()->GetBrowserInfoList(list);
@ -149,7 +149,7 @@ CefRefPtr<CefBrowserHostImpl> GetBrowserForTabId(
CefRefPtr<CefBrowserHostImpl> current_browser = browser_info->browser();
if (current_browser && current_browser->GetIdentifier() == tab_id) {
// Make sure we're operating in the same BrowserContextImpl.
if (CefBrowserContextImpl::GetForContext(
if (CefBrowserContext::GetForContext(
current_browser->GetBrowserContext()) == browser_context_impl) {
return current_browser;
} else {

View File

@ -4,7 +4,7 @@
#include "libcef/browser/extensions/extension_function_details.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/extensions/browser_extensions_util.h"
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/navigate_params.h"
@ -168,9 +168,8 @@ CefRefPtr<CefBrowserHostImpl> CefExtensionFunctionDetails::GetCurrentBrowser()
static_cast<CefBrowserHostImpl*>(active_browser.get());
// Make sure we're operating in the same BrowserContextImpl.
if (CefBrowserContextImpl::GetForContext(
browser->GetBrowserContext()) ==
CefBrowserContextImpl::GetForContext(
if (CefBrowserContext::GetForContext(browser->GetBrowserContext()) ==
CefBrowserContext::GetForContext(
active_browser_impl->GetBrowserContext())) {
browser = active_browser_impl;
} else {
@ -349,8 +348,8 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab(
if (params.index.get())
index = *params.index;
CefBrowserContextImpl* browser_context_impl =
CefBrowserContextImpl::GetForContext(active_browser->GetBrowserContext());
CefBrowserContext* browser_context_impl =
CefBrowserContext::GetForContext(active_browser->GetBrowserContext());
// A CEF representation should always exist.
CefRefPtr<CefExtension> cef_extension =
@ -361,7 +360,6 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab(
return nullptr;
// Always use the same request context that the extension was registered with.
// May represent an *Impl or *Proxy BrowserContext.
// GetLoaderContext() will return NULL for internal extensions.
CefRefPtr<CefRequestContext> request_context =
cef_extension->GetLoaderContext();

View File

@ -6,7 +6,7 @@
#include "libcef/browser/extensions/extensions_api_client.h"
#include "include/internal/cef_types_wrappers.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/extensions/api/storage/sync_value_store_cache.h"
#include "libcef/browser/extensions/extension_web_contents_observer.h"
#include "libcef/browser/extensions/mime_handler_view_guest_delegate.h"
@ -35,14 +35,9 @@ CefExtensionsAPIClient::CreateGuestViewManagerDelegate(
content::BrowserContext* context) const {
// The GuestViewManager instance associated with the returned Delegate, which
// will be retrieved in the future via GuestViewManager::FromBrowserContext,
// will be associated with the CefBrowserContextImpl instead of |context| due
// to ShouldProxyUserData in browser_context_proxy.cc. Because the
// GuestViewManagerDelegate keeps a reference to the passed-in context we need
// to provide the *Impl object instead of |context| which may be a *Proxy
// object. If we don't do this then the Delegate may attempt to access a
// *Proxy object that has already been deleted.
// will be associated with the CefBrowserContext.
return base::WrapUnique(new extensions::ExtensionsGuestViewManagerDelegate(
CefBrowserContextImpl::GetForContext(context)));
CefBrowserContext::GetForContext(context)));
}
std::unique_ptr<MimeHandlerViewGuestDelegate>

View File

@ -7,7 +7,7 @@
#include <utility>
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/extensions/component_extension_resource_manager.h"
#include "libcef/browser/extensions/extension_system.h"
@ -65,13 +65,13 @@ bool CefExtensionsBrowserClient::AreExtensionsDisabled(
}
bool CefExtensionsBrowserClient::IsValidContext(BrowserContext* context) {
return CefBrowserContextImpl::GetForContext(context) != NULL;
return CefBrowserContext::GetForContext(context) != NULL;
}
bool CefExtensionsBrowserClient::IsSameContext(BrowserContext* first,
BrowserContext* second) {
// Returns true if |first| and |second| share the same underlying
// CefBrowserContextImpl.
// CefBrowserContext.
return GetCefImplContext(first) == GetCefImplContext(second);
}
@ -93,7 +93,7 @@ BrowserContext* CefExtensionsBrowserClient::GetOriginalContext(
BrowserContext* CefExtensionsBrowserClient::GetCefImplContext(
BrowserContext* context) {
return CefBrowserContextImpl::GetForContext(context);
return CefBrowserContext::GetForContext(context);
}
bool CefExtensionsBrowserClient::IsGuestSession(BrowserContext* context) const {
@ -196,10 +196,8 @@ bool CefExtensionsBrowserClient::CreateBackgroundExtensionHost(
content::BrowserContext* browser_context,
const GURL& url,
ExtensionHost** host) {
// The BrowserContext referenced by ProcessManager should always be an *Impl.
DCHECK(!static_cast<CefBrowserContext*>(browser_context)->is_proxy());
CefBrowserContextImpl* browser_context_impl =
CefBrowserContextImpl::GetForContext(browser_context);
CefBrowserContext* browser_context_impl =
CefBrowserContext::GetForContext(browser_context);
// A CEF representation should always exist.
CefRefPtr<CefExtension> cef_extension =
@ -211,7 +209,6 @@ bool CefExtensionsBrowserClient::CreateBackgroundExtensionHost(
}
// Always use the same request context that the extension was registered with.
// May represent an *Impl or *Proxy BrowserContext.
// GetLoaderContext() will return NULL for internal extensions.
CefRefPtr<CefRequestContext> request_context =
cef_extension->GetLoaderContext();

View File

@ -1,182 +0,0 @@
// Copyright (c) 2015 The Chromium Embedded Framework 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/net/cookie_store_proxy.h"
#include "include/cef_request_context.h"
#include "libcef/browser/net/cookie_store_source.h"
#include "libcef/browser/thread_util.h"
#include "base/logging.h"
#include "net/cookies/cookie_change_dispatcher.h"
namespace {
class NullCookieChangeDispatcher : public net::CookieChangeDispatcher {
public:
NullCookieChangeDispatcher() {}
~NullCookieChangeDispatcher() override {}
// net::CookieChangeDispatcher
std::unique_ptr<net::CookieChangeSubscription> AddCallbackForCookie(
const GURL& url,
const std::string& name,
net::CookieChangeCallback callback) override {
return nullptr;
}
std::unique_ptr<net::CookieChangeSubscription> AddCallbackForUrl(
const GURL& url,
net::CookieChangeCallback callback) override {
return nullptr;
}
std::unique_ptr<net::CookieChangeSubscription> AddCallbackForAllChanges(
net::CookieChangeCallback callback) override {
return nullptr;
}
private:
DISALLOW_COPY_AND_ASSIGN(NullCookieChangeDispatcher);
};
} // namespace
CefCookieStoreProxy::CefCookieStoreProxy(
std::unique_ptr<CefCookieStoreSource> source)
: source_(std::move(source)) {
CEF_REQUIRE_IOT();
DCHECK(source_);
}
CefCookieStoreProxy::~CefCookieStoreProxy() {
CEF_REQUIRE_IOT();
}
void CefCookieStoreProxy::SetCookieWithOptionsAsync(
const GURL& url,
const std::string& cookie_line,
const net::CookieOptions& options,
SetCookiesCallback callback) {
net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store) {
cookie_store->SetCookieWithOptionsAsync(url, cookie_line, options,
std::move(callback));
} else if (!callback.is_null()) {
std::move(callback).Run(
net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_FAILURE_TO_STORE);
}
}
void CefCookieStoreProxy::SetCanonicalCookieAsync(
std::unique_ptr<net::CanonicalCookie> cookie,
std::string source_scheme,
bool modify_http_only,
SetCookiesCallback callback) {
net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store) {
cookie_store->SetCanonicalCookieAsync(std::move(cookie), source_scheme,
modify_http_only,
std::move(callback));
} else if (!callback.is_null()) {
std::move(callback).Run(
net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_FAILURE_TO_STORE);
}
}
void CefCookieStoreProxy::GetCookieListWithOptionsAsync(
const GURL& url,
const net::CookieOptions& options,
GetCookieListCallback callback) {
net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store) {
cookie_store->GetCookieListWithOptionsAsync(url, options,
std::move(callback));
} else if (!callback.is_null()) {
std::move(callback).Run(net::CookieList(), net::CookieStatusList());
}
}
void CefCookieStoreProxy::GetAllCookiesAsync(GetCookieListCallback callback) {
net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store) {
cookie_store->GetAllCookiesAsync(std::move(callback));
} else if (!callback.is_null()) {
std::move(callback).Run(net::CookieList(), net::CookieStatusList());
}
}
void CefCookieStoreProxy::DeleteCanonicalCookieAsync(
const net::CanonicalCookie& cookie,
DeleteCallback callback) {
net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store) {
cookie_store->DeleteCanonicalCookieAsync(cookie, std::move(callback));
} else if (!callback.is_null()) {
std::move(callback).Run(0);
}
}
void CefCookieStoreProxy::DeleteAllCreatedInTimeRangeAsync(
const net::CookieDeletionInfo::TimeRange& creation_range,
DeleteCallback callback) {
net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store) {
cookie_store->DeleteAllCreatedInTimeRangeAsync(creation_range,
std::move(callback));
} else if (!callback.is_null()) {
std::move(callback).Run(0);
}
}
void CefCookieStoreProxy::DeleteAllMatchingInfoAsync(
net::CookieDeletionInfo delete_info,
DeleteCallback callback) {
net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store) {
cookie_store->DeleteAllMatchingInfoAsync(delete_info, std::move(callback));
} else if (!callback.is_null()) {
std::move(callback).Run(0);
}
}
void CefCookieStoreProxy::DeleteSessionCookiesAsync(DeleteCallback callback) {
net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store) {
cookie_store->DeleteSessionCookiesAsync(std::move(callback));
} else if (!callback.is_null()) {
std::move(callback).Run(0);
}
}
void CefCookieStoreProxy::FlushStore(base::OnceClosure callback) {
net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store) {
cookie_store->FlushStore(std::move(callback));
} else if (!callback.is_null()) {
std::move(callback).Run();
}
}
net::CookieChangeDispatcher& CefCookieStoreProxy::GetChangeDispatcher() {
net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store)
return cookie_store->GetChangeDispatcher();
if (!null_dispatcher_)
null_dispatcher_.reset(new NullCookieChangeDispatcher());
return *null_dispatcher_;
}
bool CefCookieStoreProxy::IsEphemeral() {
net::CookieStore* cookie_store = GetCookieStore();
if (cookie_store)
return cookie_store->IsEphemeral();
return true;
}
net::CookieStore* CefCookieStoreProxy::GetCookieStore() {
CEF_REQUIRE_IOT();
return source_->GetCookieStore();
}

View File

@ -1,54 +0,0 @@
// Copyright (c) 2015 The Chromium Embedded Framework 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 CEF_LIBCEF_BROWSER_COOKIE_STORE_PROXY_H_
#define CEF_LIBCEF_BROWSER_COOKIE_STORE_PROXY_H_
#pragma once
#include "net/cookies/cookie_store.h"
class CefCookieStoreSource;
// Proxies cookie requests to a CefCookieStoreSource (see comments on the
// implementation classes for details). Only accessed on the IO thread.
class CefCookieStoreProxy : public net::CookieStore {
public:
explicit CefCookieStoreProxy(std::unique_ptr<CefCookieStoreSource> source);
~CefCookieStoreProxy() override;
// net::CookieStore methods.
void SetCookieWithOptionsAsync(const GURL& url,
const std::string& cookie_line,
const net::CookieOptions& options,
SetCookiesCallback callback) override;
void SetCanonicalCookieAsync(std::unique_ptr<net::CanonicalCookie> cookie,
std::string source_scheme,
bool modify_http_only,
SetCookiesCallback callback) override;
void GetCookieListWithOptionsAsync(const GURL& url,
const net::CookieOptions& options,
GetCookieListCallback callback) override;
void GetAllCookiesAsync(GetCookieListCallback callback) override;
void DeleteCanonicalCookieAsync(const net::CanonicalCookie& cookie,
DeleteCallback callback) override;
void DeleteAllCreatedInTimeRangeAsync(
const net::CookieDeletionInfo::TimeRange& creation_range,
DeleteCallback callback) override;
void DeleteAllMatchingInfoAsync(net::CookieDeletionInfo delete_info,
DeleteCallback callback) override;
void DeleteSessionCookiesAsync(DeleteCallback callback) override;
void FlushStore(base::OnceClosure callback) override;
net::CookieChangeDispatcher& GetChangeDispatcher() override;
bool IsEphemeral() override;
private:
net::CookieStore* GetCookieStore();
std::unique_ptr<CefCookieStoreSource> const source_;
std::unique_ptr<net::CookieChangeDispatcher> null_dispatcher_;
DISALLOW_COPY_AND_ASSIGN(CefCookieStoreProxy);
};
#endif // CEF_LIBCEF_BROWSER_COOKIE_STORE_PROXY_H_

View File

@ -1,111 +0,0 @@
// Copyright (c) 2018 The Chromium Embedded Framework 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/net/cookie_store_source.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/cookie_manager_impl.h"
#include "libcef/browser/net/url_request_context_impl.h"
#include "libcef/browser/thread_util.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
CefCookieStoreHandlerSource::CefCookieStoreHandlerSource(
CefURLRequestContextImpl* parent,
CefRefPtr<CefRequestContextHandler> handler)
: parent_(parent), handler_(handler) {
DCHECK(parent_);
DCHECK(handler_);
}
net::CookieStore* CefCookieStoreHandlerSource::GetCookieStore() {
CEF_REQUIRE_IOT();
CefRefPtr<CefCookieManager> manager = handler_->GetCookieManager();
if (manager) {
// Use the cookie store provided by the manager. May be nullptr if the
// cookie manager is blocking.
return reinterpret_cast<CefCookieManagerImpl*>(manager.get())
->GetExistingCookieStore();
}
DCHECK(parent_);
if (parent_) {
// Use the cookie store from the parent.
net::CookieStore* cookie_store = parent_->cookie_store();
DCHECK(cookie_store);
if (!cookie_store)
LOG(ERROR) << "Cookie store does not exist";
return cookie_store;
}
return nullptr;
}
CefCookieStoreOwnerSource::CefCookieStoreOwnerSource() {}
void CefCookieStoreOwnerSource::SetCookieStoragePath(
const base::FilePath& path,
bool persist_session_cookies,
net::NetLog* net_log) {
CEF_REQUIRE_IOT();
if (cookie_store_ && ((path_.empty() && path.empty()) || path_ == path)) {
// The path has not changed so don't do anything.
return;
}
scoped_refptr<net::SQLitePersistentCookieStore> persistent_store;
if (!path.empty()) {
// TODO(cef): Move directory creation to the blocking pool instead of
// allowing file IO on this thread.
base::ThreadRestrictions::ScopedAllowIO allow_io;
if (base::DirectoryExists(path) || base::CreateDirectory(path)) {
const base::FilePath& cookie_path = path.AppendASCII("Cookies");
persistent_store = new net::SQLitePersistentCookieStore(
cookie_path,
base::CreateSingleThreadTaskRunnerWithTraits(
{content::BrowserThread::IO}),
// Intentionally using the background task runner exposed by CEF to
// facilitate unit test expectations. This task runner MUST be
// configured with BLOCK_SHUTDOWN.
CefContentBrowserClient::Get()->background_task_runner(),
persist_session_cookies, NULL);
} else {
NOTREACHED() << "The cookie storage directory could not be created";
}
}
// Set the new cookie store that will be used for all new requests. The old
// cookie store, if any, will be automatically flushed and closed when no
// longer referenced.
std::unique_ptr<net::CookieMonster> cookie_monster(
new net::CookieMonster(persistent_store.get(), nullptr, net_log));
if (persistent_store.get() && persist_session_cookies)
cookie_monster->SetPersistSessionCookies(true);
path_ = path;
// Restore the previously supported schemes.
CefCookieManagerImpl::SetCookieMonsterSchemes(cookie_monster.get(),
supported_schemes_);
cookie_store_ = std::move(cookie_monster);
}
void CefCookieStoreOwnerSource::SetCookieSupportedSchemes(
const std::vector<std::string>& schemes) {
CEF_REQUIRE_IOT();
supported_schemes_ = schemes;
CefCookieManagerImpl::SetCookieMonsterSchemes(
static_cast<net::CookieMonster*>(cookie_store_.get()),
supported_schemes_);
}
net::CookieStore* CefCookieStoreOwnerSource::GetCookieStore() {
CEF_REQUIRE_IOT();
return cookie_store_.get();
}

View File

@ -1,75 +0,0 @@
// Copyright (c) 2018 The Chromium Embedded Framework 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 CEF_LIBCEF_BROWSER_COOKIE_STORE_SOURCE_H_
#define CEF_LIBCEF_BROWSER_COOKIE_STORE_SOURCE_H_
#pragma once
#include <memory>
#include <string>
#include <vector>
#include "include/cef_request_context_handler.h"
#include "base/macros.h"
namespace base {
class FilePath;
}
namespace net {
class CookieStore;
class NetLog;
} // namespace net
class CefURLRequestContextImpl;
// Abstract base class for CookieStore sources. Only accessed on the IO thread.
class CefCookieStoreSource {
public:
virtual net::CookieStore* GetCookieStore() = 0;
virtual ~CefCookieStoreSource() {}
};
// Sources a cookie store that is created/owned by a CefCookieManager or the
// parent context. Life span is controlled by CefURLRequestContextProxy. See
// browser_context.h for an object relationship diagram.
class CefCookieStoreHandlerSource : public CefCookieStoreSource {
public:
CefCookieStoreHandlerSource(CefURLRequestContextImpl* parent,
CefRefPtr<CefRequestContextHandler> handler);
net::CookieStore* GetCookieStore() override;
private:
// The |parent_| pointer is kept alive by CefURLRequestContextGetterProxy
// which has a ref to the owning CefURLRequestContextGetterImpl.
CefURLRequestContextImpl* parent_;
CefRefPtr<CefRequestContextHandler> handler_;
DISALLOW_COPY_AND_ASSIGN(CefCookieStoreHandlerSource);
};
// Sources a cookie store that is created/owned by this object. Life span is
// controlled by the owning URLRequestContext.
class CefCookieStoreOwnerSource : public CefCookieStoreSource {
public:
CefCookieStoreOwnerSource();
void SetCookieStoragePath(const base::FilePath& path,
bool persist_session_cookies,
net::NetLog* net_log);
void SetCookieSupportedSchemes(const std::vector<std::string>& schemes);
net::CookieStore* GetCookieStore() override;
private:
std::unique_ptr<net::CookieStore> cookie_store_;
base::FilePath path_;
std::vector<std::string> supported_schemes_;
DISALLOW_COPY_AND_ASSIGN(CefCookieStoreOwnerSource);
};
#endif // CEF_LIBCEF_BROWSER_COOKIE_STORE_SOURCE_H_

View File

@ -51,7 +51,7 @@ class CefNetworkDelegate : public net::NetworkDelegateImpl {
const base::FilePath& original_path,
const base::FilePath& absolute_path) const override;
// Weak, owned by our owner (CefURLRequestContextGetterImpl).
// Weak, owned by our owner (CefURLRequestContextGetter).
BooleanPrefMember* force_google_safesearch_;
DISALLOW_COPY_AND_ASSIGN(CefNetworkDelegate);

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "libcef/browser/net/url_request_context_getter_impl.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include <string>
#include <utility>
@ -10,8 +10,6 @@
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/cookie_manager_impl.h"
#include "libcef/browser/net/cookie_store_proxy.h"
#include "libcef/browser/net/cookie_store_source.h"
#include "libcef/browser/net/network_delegate.h"
#include "libcef/browser/net/scheme_handler.h"
#include "libcef/browser/net/url_request_interceptor.h"
@ -20,6 +18,7 @@
#include "libcef/common/content_client.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
@ -45,6 +44,7 @@
#include "net/cert/multi_log_ct_verifier.h"
#include "net/cookies/cookie_monster.h"
#include "net/dns/host_resolver.h"
#include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_auth_preferences.h"
@ -179,7 +179,7 @@ CreateLogVerifiersForKnownLogs() {
} // namespace
CefURLRequestContextGetterImpl::CefURLRequestContextGetterImpl(
CefURLRequestContextGetter::CefURLRequestContextGetter(
const CefRequestContextSettings& settings,
PrefService* pref_service,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
@ -220,26 +220,25 @@ CefURLRequestContextGetterImpl::CefURLRequestContextGetterImpl(
auth_server_whitelist_.Init(
prefs::kAuthServerWhitelist, pref_service,
base::Bind(&CefURLRequestContextGetterImpl::UpdateServerWhitelist,
base::Bind(&CefURLRequestContextGetter::UpdateServerWhitelist,
base::Unretained(this)));
auth_server_whitelist_.MoveToThread(io_thread_proxy);
auth_negotiate_delegate_whitelist_.Init(
prefs::kAuthNegotiateDelegateWhitelist, pref_service,
base::Bind(&CefURLRequestContextGetterImpl::UpdateDelegateWhitelist,
base::Bind(&CefURLRequestContextGetter::UpdateDelegateWhitelist,
base::Unretained(this)));
auth_negotiate_delegate_whitelist_.MoveToThread(io_thread_proxy);
}
CefURLRequestContextGetterImpl::~CefURLRequestContextGetterImpl() {
CefURLRequestContextGetter::~CefURLRequestContextGetter() {
CEF_REQUIRE_IOT();
// This destructor may not be called during shutdown. Perform any required
// shutdown in ShutdownOnIOThread() instead.
}
// static
void CefURLRequestContextGetterImpl::RegisterPrefs(
PrefRegistrySimple* registry) {
void CefURLRequestContextGetter::RegisterPrefs(PrefRegistrySimple* registry) {
// Based on IOThread::RegisterPrefs.
#if defined(OS_POSIX) && !defined(OS_ANDROID)
registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string());
@ -255,7 +254,7 @@ void CefURLRequestContextGetterImpl::RegisterPrefs(
registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, "");
}
void CefURLRequestContextGetterImpl::ShutdownOnUIThread() {
void CefURLRequestContextGetter::ShutdownOnUIThread() {
CEF_REQUIRE_UIT();
quick_check_enabled_.Destroy();
pac_https_url_stripping_enabled_.Destroy();
@ -265,10 +264,10 @@ void CefURLRequestContextGetterImpl::ShutdownOnUIThread() {
CEF_POST_TASK(
CEF_IOT,
base::Bind(&CefURLRequestContextGetterImpl::ShutdownOnIOThread, this));
base::Bind(&CefURLRequestContextGetter::ShutdownOnIOThread, this));
}
void CefURLRequestContextGetterImpl::ShutdownOnIOThread() {
void CefURLRequestContextGetter::ShutdownOnIOThread() {
CEF_REQUIRE_IOT();
shutting_down_ = true;
@ -282,7 +281,7 @@ void CefURLRequestContextGetterImpl::ShutdownOnIOThread() {
NotifyContextShuttingDown();
}
net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() {
net::URLRequestContext* CefURLRequestContextGetter::GetURLRequestContext() {
CEF_REQUIRE_IOT();
if (shutting_down_)
@ -296,7 +295,7 @@ net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() {
if (settings_.cache_path.length > 0)
cache_path = base::FilePath(CefString(&settings_.cache_path));
io_state_->url_request_context_.reset(new CefURLRequestContextImpl());
io_state_->url_request_context_.reset(new CefURLRequestContext());
io_state_->url_request_context_->set_net_log(io_state_->net_log_);
io_state_->url_request_context_->set_enable_brotli(true);
@ -472,63 +471,95 @@ net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() {
}
scoped_refptr<base::SingleThreadTaskRunner>
CefURLRequestContextGetterImpl::GetNetworkTaskRunner() const {
CefURLRequestContextGetter::GetNetworkTaskRunner() const {
return base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO});
}
net::HostResolver* CefURLRequestContextGetterImpl::GetHostResolver() const {
net::HostResolver* CefURLRequestContextGetter::GetHostResolver() const {
return io_state_->url_request_context_->host_resolver();
}
void CefURLRequestContextGetterImpl::SetCookieStoragePath(
const base::FilePath& path,
bool persist_session_cookies) {
CEF_REQUIRE_IOT();
if (!io_state_->cookie_source_) {
// Use a proxy because we can't change the URLRequestContext's CookieStore
// during runtime.
io_state_->cookie_source_ = new CefCookieStoreOwnerSource();
io_state_->storage_->set_cookie_store(std::make_unique<CefCookieStoreProxy>(
base::WrapUnique(io_state_->cookie_source_)));
}
io_state_->cookie_source_->SetCookieStoragePath(path, persist_session_cookies,
io_state_->net_log_);
}
void CefURLRequestContextGetterImpl::SetCookieSupportedSchemes(
void CefURLRequestContextGetter::SetCookieSupportedSchemes(
const std::vector<std::string>& schemes) {
CEF_REQUIRE_IOT();
io_state_->cookie_source_->SetCookieSupportedSchemes(schemes);
io_state_->cookie_supported_schemes_ = schemes;
CefCookieManagerImpl::SetCookieMonsterSchemes(
static_cast<net::CookieMonster*>(GetExistingCookieStore()),
io_state_->cookie_supported_schemes_);
}
void CefURLRequestContextGetterImpl::AddHandler(
void CefURLRequestContextGetter::AddHandler(
CefRefPtr<CefRequestContextHandler> handler) {
if (!CEF_CURRENTLY_ON_IOT()) {
CEF_POST_TASK(
CEF_IOT,
base::Bind(&CefURLRequestContextGetterImpl::AddHandler, this, handler));
CEF_POST_TASK(CEF_IOT, base::Bind(&CefURLRequestContextGetter::AddHandler,
this, handler));
return;
}
io_state_->handler_list_.push_back(handler);
}
net::CookieStore* CefURLRequestContextGetterImpl::GetExistingCookieStore()
const {
net::CookieStore* CefURLRequestContextGetter::GetExistingCookieStore() const {
CEF_REQUIRE_IOT();
if (io_state_->cookie_source_) {
return io_state_->cookie_source_->GetCookieStore();
if (io_state_->url_request_context_ &&
io_state_->url_request_context_->cookie_store()) {
return io_state_->url_request_context_->cookie_store();
}
LOG(ERROR) << "Cookie store does not exist";
return nullptr;
}
void CefURLRequestContextGetterImpl::UpdateServerWhitelist() {
void CefURLRequestContextGetter::SetCookieStoragePath(
const base::FilePath& path,
bool persist_session_cookies) {
CEF_REQUIRE_IOT();
// The cookie store can't be changed during runtime.
DCHECK(!io_state_->url_request_context_->cookie_store());
scoped_refptr<net::SQLitePersistentCookieStore> persistent_store;
if (!path.empty()) {
// TODO(cef): Move directory creation to the blocking pool instead of
// allowing file IO on this thread.
base::ThreadRestrictions::ScopedAllowIO allow_io;
if (base::DirectoryExists(path) || base::CreateDirectory(path)) {
const base::FilePath& cookie_path = path.AppendASCII("Cookies");
persistent_store = new net::SQLitePersistentCookieStore(
cookie_path,
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
// Intentionally using the background task runner exposed by CEF to
// facilitate unit test expectations. This task runner MUST be
// configured with BLOCK_SHUTDOWN.
CefContentBrowserClient::Get()->background_task_runner(),
persist_session_cookies, NULL);
} else {
NOTREACHED() << "The cookie storage directory could not be created";
}
}
// Set the new cookie store that will be used for all new requests. The old
// cookie store, if any, will be automatically flushed and closed when no
// longer referenced.
std::unique_ptr<net::CookieMonster> cookie_monster(new net::CookieMonster(
persistent_store.get(), nullptr, io_state_->net_log_));
if (persistent_store.get() && persist_session_cookies)
cookie_monster->SetPersistSessionCookies(true);
io_state_->cookie_store_path_ = path;
// Restore the previously supported schemes.
CefCookieManagerImpl::SetCookieMonsterSchemes(
cookie_monster.get(), io_state_->cookie_supported_schemes_);
io_state_->storage_->set_cookie_store(std::move(cookie_monster));
}
void CefURLRequestContextGetter::UpdateServerWhitelist() {
io_state_->http_auth_preferences_->SetServerWhitelist(
auth_server_whitelist_.GetValue());
}
void CefURLRequestContextGetterImpl::UpdateDelegateWhitelist() {
void CefURLRequestContextGetter::UpdateDelegateWhitelist() {
io_state_->http_auth_preferences_->SetDelegateWhitelist(
auth_negotiate_delegate_whitelist_.GetValue());
}

View File

@ -1,30 +1,138 @@
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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 CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_H_
#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_H_
#ifndef CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_
#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_
#pragma once
#include "net/url_request/url_request_context_getter.h"
#include <set>
#include <string>
namespace net {
class HostResolver;
#include "include/internal/cef_types_wrappers.h"
#include "libcef/browser/net/url_request_context.h"
#include "libcef/browser/net/url_request_manager.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/net/chrome_mojo_proxy_resolver_factory.h"
#include "components/prefs/pref_member.h"
#include "content/public/browser/browser_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_job_factory.h"
class PrefRegistrySimple;
class PrefService;
namespace base {
class MessageLoop;
}
// Responsible for creating and owning the URLRequestContext and all network-
// related functionality. Life span is primarily controlled by
// CefResourceContext*. See browser_context.h for an object relationship
// diagram.
namespace net {
class CookieMonster;
class FtpTransactionFactory;
class HttpAuthPreferences;
class ProxyConfigService;
class URLRequestContextStorage;
class URLRequestJobFactory;
class URLRequestJobFactoryImpl;
} // namespace net
// Isolated URLRequestContextGetter implementation. Life span is primarily
// controlled by CefResourceContext and (for the global context)
// CefBrowserMainParts. Created on the UI thread but accessed and destroyed on
// the IO thread. See browser_context.h for an object relationship diagram.
class CefURLRequestContextGetter : public net::URLRequestContextGetter {
public:
CefURLRequestContextGetter() {}
CefURLRequestContextGetter(
const CefRequestContextSettings& settings,
PrefService* pref_service,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
content::ProtocolHandlerMap* protocol_handlers,
std::unique_ptr<net::ProxyConfigService> proxy_config_service,
content::URLRequestInterceptorScopedVector request_interceptors);
~CefURLRequestContextGetter() override;
// Called from CefResourceContext::GetHostResolver().
virtual net::HostResolver* GetHostResolver() const = 0;
// Register preferences. Called from browser_prefs::CreatePrefService().
static void RegisterPrefs(PrefRegistrySimple* registry);
// Called when the BrowserContextImpl is destroyed.
void ShutdownOnUIThread();
// net::URLRequestContextGetter implementation.
net::URLRequestContext* GetURLRequestContext() override;
scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
const override;
// CefURLRequestContextGetter implementation.
net::HostResolver* GetHostResolver() const;
void SetCookieSupportedSchemes(const std::vector<std::string>& schemes);
// Keep a reference to all handlers sharing this context so that they'll be
// kept alive until the context is destroyed.
void AddHandler(CefRefPtr<CefRequestContextHandler> handler);
// Returns the existing cookie store object. Logs an error if the cookie
// store does not yet exist. Must be called on the IO thread.
net::CookieStore* GetExistingCookieStore() const;
CefURLRequestManager* request_manager() const {
return io_state_->url_request_manager_.get();
}
private:
void SetCookieStoragePath(const base::FilePath& path,
bool persist_session_cookies);
void UpdateServerWhitelist();
void UpdateDelegateWhitelist();
void ShutdownOnIOThread();
const CefRequestContextSettings settings_;
bool shutting_down_ = false;
// State that is only accessed on the IO thread and will be reset in
// ShutdownOnIOThread().
struct IOState {
net::NetLog* net_log_ = nullptr; // Guaranteed to outlive this object.
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
#if defined(OS_POSIX) && !defined(OS_ANDROID)
std::string gsapi_library_name_;
#endif
std::unique_ptr<net::ProxyConfigService> proxy_config_service_;
std::unique_ptr<net::URLRequestContextStorage> storage_;
std::unique_ptr<net::HttpAuthPreferences> http_auth_preferences_;
std::unique_ptr<CefURLRequestContext> url_request_context_;
std::unique_ptr<CefURLRequestManager> url_request_manager_;
content::ProtocolHandlerMap protocol_handlers_;
content::URLRequestInterceptorScopedVector request_interceptors_;
base::FilePath cookie_store_path_;
std::vector<std::string> cookie_supported_schemes_;
std::vector<CefRefPtr<CefRequestContextHandler>> handler_list_;
proxy_resolver::mojom::ProxyResolverFactoryPtr proxy_resolver_factory_;
};
std::unique_ptr<IOState> io_state_;
BooleanPrefMember quick_check_enabled_;
BooleanPrefMember pac_https_url_stripping_enabled_;
// Member variables which are pointed to by the various context objects.
mutable BooleanPrefMember force_google_safesearch_;
StringPrefMember auth_server_whitelist_;
StringPrefMember auth_negotiate_delegate_whitelist_;
DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextGetter);
};
#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_H_
#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_

View File

@ -1,138 +0,0 @@
// Copyright (c) 2011 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 CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_
#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_
#pragma once
#include <set>
#include <string>
#include "include/internal/cef_types_wrappers.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/net/url_request_context_impl.h"
#include "libcef/browser/net/url_request_manager.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/net/chrome_mojo_proxy_resolver_factory.h"
#include "components/prefs/pref_member.h"
#include "content/public/browser/browser_context.h"
#include "net/url_request/url_request_job_factory.h"
class CefCookieStoreOwnerSource;
class PrefRegistrySimple;
class PrefService;
namespace base {
class MessageLoop;
}
namespace net {
class CookieMonster;
class FtpTransactionFactory;
class HttpAuthPreferences;
class ProxyConfigService;
class URLRequestContextStorage;
class URLRequestJobFactory;
class URLRequestJobFactoryImpl;
} // namespace net
// Isolated URLRequestContextGetter implementation. Life span is primarily
// controlled by CefResourceContext and (for the global context)
// CefBrowserMainParts. Created on the UI thread but accessed and destroyed on
// the IO thread. See browser_context.h for an object relationship diagram.
class CefURLRequestContextGetterImpl : public CefURLRequestContextGetter {
public:
CefURLRequestContextGetterImpl(
const CefRequestContextSettings& settings,
PrefService* pref_service,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
content::ProtocolHandlerMap* protocol_handlers,
std::unique_ptr<net::ProxyConfigService> proxy_config_service,
content::URLRequestInterceptorScopedVector request_interceptors);
~CefURLRequestContextGetterImpl() override;
// Register preferences. Called from browser_prefs::CreatePrefService().
static void RegisterPrefs(PrefRegistrySimple* registry);
// Called when the BrowserContextImpl is destroyed.
void ShutdownOnUIThread();
// net::URLRequestContextGetter implementation.
net::URLRequestContext* GetURLRequestContext() override;
scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
const override;
// CefURLRequestContextGetter implementation.
net::HostResolver* GetHostResolver() const override;
void SetCookieStoragePath(const base::FilePath& path,
bool persist_session_cookies);
void SetCookieSupportedSchemes(const std::vector<std::string>& schemes);
// Keep a reference to all handlers sharing this context so that they'll be
// kept alive until the context is destroyed.
void AddHandler(CefRefPtr<CefRequestContextHandler> handler);
// Returns the existing cookie store object. Logs an error if the cookie
// store does not yet exist. Must be called on the IO thread.
net::CookieStore* GetExistingCookieStore() const;
CefURLRequestManager* request_manager() const {
return io_state_->url_request_manager_.get();
}
private:
void UpdateServerWhitelist();
void UpdateDelegateWhitelist();
void ShutdownOnIOThread();
const CefRequestContextSettings settings_;
bool shutting_down_ = false;
// State that is only accessed on the IO thread and will be reset in
// ShutdownOnIOThread().
struct IOState {
net::NetLog* net_log_ = nullptr; // Guaranteed to outlive this object.
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
#if defined(OS_POSIX) && !defined(OS_ANDROID)
std::string gsapi_library_name_;
#endif
std::unique_ptr<net::ProxyConfigService> proxy_config_service_;
std::unique_ptr<net::URLRequestContextStorage> storage_;
std::unique_ptr<net::HttpAuthPreferences> http_auth_preferences_;
std::unique_ptr<CefURLRequestContextImpl> url_request_context_;
std::unique_ptr<CefURLRequestManager> url_request_manager_;
content::ProtocolHandlerMap protocol_handlers_;
content::URLRequestInterceptorScopedVector request_interceptors_;
// Owned by the URLRequestContextStorage.
CefCookieStoreOwnerSource* cookie_source_ = nullptr;
std::vector<CefRefPtr<CefRequestContextHandler>> handler_list_;
proxy_resolver::mojom::ProxyResolverFactoryPtr proxy_resolver_factory_;
};
std::unique_ptr<IOState> io_state_;
BooleanPrefMember quick_check_enabled_;
BooleanPrefMember pac_https_url_stripping_enabled_;
// Member variables which are pointed to by the various context objects.
mutable BooleanPrefMember force_google_safesearch_;
StringPrefMember auth_server_whitelist_;
StringPrefMember auth_negotiate_delegate_whitelist_;
DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextGetterImpl);
};
#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_IMPL_H_

View File

@ -1,59 +0,0 @@
// Copyright (c) 2012 The Chromium Embedded Framework 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/net/url_request_context_getter_proxy.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/net/url_request_context_proxy.h"
#include "libcef/browser/thread_util.h"
CefURLRequestContextGetterProxy::CefURLRequestContextGetterProxy(
CefRefPtr<CefRequestContextHandler> handler,
scoped_refptr<CefURLRequestContextGetterImpl> parent)
: handler_(handler), parent_(parent) {
DCHECK(handler_.get());
DCHECK(parent_.get());
}
CefURLRequestContextGetterProxy::~CefURLRequestContextGetterProxy() {
CEF_REQUIRE_IOT();
}
void CefURLRequestContextGetterProxy::ShutdownOnUIThread() {
CEF_REQUIRE_UIT();
CEF_POST_TASK(
CEF_IOT,
base::Bind(&CefURLRequestContextGetterProxy::ShutdownOnIOThread, this));
}
void CefURLRequestContextGetterProxy::ShutdownOnIOThread() {
CEF_REQUIRE_IOT();
shutting_down_ = true;
context_proxy_.reset();
NotifyContextShuttingDown();
}
net::URLRequestContext*
CefURLRequestContextGetterProxy::GetURLRequestContext() {
CEF_REQUIRE_IOT();
if (shutting_down_)
return nullptr;
if (!context_proxy_) {
context_proxy_.reset(new CefURLRequestContextProxy(
static_cast<CefURLRequestContextImpl*>(parent_->GetURLRequestContext()),
handler_));
}
return context_proxy_.get();
}
scoped_refptr<base::SingleThreadTaskRunner>
CefURLRequestContextGetterProxy::GetNetworkTaskRunner() const {
return parent_->GetNetworkTaskRunner();
}
net::HostResolver* CefURLRequestContextGetterProxy::GetHostResolver() const {
return parent_->GetHostResolver();
}

View File

@ -1,57 +0,0 @@
// Copyright (c) 2012 The Chromium Embedded Framework 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 CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_PROXY_H_
#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_PROXY_H_
#pragma once
#include "include/cef_request_context.h"
#include "include/cef_request_context_handler.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/net/url_request_context_getter_impl.h"
class CefURLRequestContextProxy;
// URLRequestContextGetter implementation for a particular CefRequestContext.
// Life span is primarily controlled by CefResourceContext. Created on the UI
// thread but accessed and destroyed on the IO thread. See browser_context.h for
// an object relationship diagram.
class CefURLRequestContextGetterProxy : public CefURLRequestContextGetter {
public:
CefURLRequestContextGetterProxy(
CefRefPtr<CefRequestContextHandler> handler,
scoped_refptr<CefURLRequestContextGetterImpl> parent);
~CefURLRequestContextGetterProxy() override;
// Called when the StoragePartitionProxy is destroyed.
void ShutdownOnUIThread();
// net::URLRequestContextGetter implementation.
net::URLRequestContext* GetURLRequestContext() override;
scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
const override;
// CefURLRequestContextGetter implementation.
net::HostResolver* GetHostResolver() const override;
CefRefPtr<CefRequestContextHandler> handler() const { return handler_; }
private:
void ShutdownOnIOThread();
CefRefPtr<CefRequestContextHandler> handler_;
// The CefURLRequestContextImpl owned by |parent_| is passed as a raw pointer
// to CefURLRequestContextProxy and CefCookieStoreProxy. This reference is
// necessary to keep it alive.
scoped_refptr<CefURLRequestContextGetterImpl> parent_;
std::unique_ptr<CefURLRequestContextProxy> context_proxy_;
bool shutting_down_ = false;
DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextGetterProxy);
};
#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_PROXY_H_

View File

@ -1,22 +0,0 @@
// Copyright (c) 2015 The Chromium Embedded Framework 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 CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_IMPL_H_
#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_IMPL_H_
#pragma once
#include "libcef/browser/net/url_request_context.h"
// Isolated URLRequestContext implementation. Life span is controlled by
// CefURLRequestContextGetterImpl. Only accessed on the IO thread. See
// browser_context.h for an object relationship diagram.
class CefURLRequestContextImpl : public CefURLRequestContext {
public:
CefURLRequestContextImpl() {}
private:
DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextImpl);
};
#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_IMPL_H_

View File

@ -1,47 +0,0 @@
// Copyright (c) 2012 The Chromium Embedded Framework 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/net/url_request_context_proxy.h"
#include "libcef/browser/net/cookie_store_proxy.h"
#include "libcef/browser/net/cookie_store_source.h"
#include "libcef/browser/net/url_request_context_impl.h"
#include "libcef/browser/thread_util.h"
CefURLRequestContextProxy::CefURLRequestContextProxy(
CefURLRequestContextImpl* parent,
CefRefPtr<CefRequestContextHandler> handler) {
CEF_REQUIRE_IOT();
DCHECK(parent);
DCHECK(handler.get());
// Cookie store that proxies to the browser implementation.
cookie_store_proxy_.reset(new CefCookieStoreProxy(
std::make_unique<CefCookieStoreHandlerSource>(parent, handler)));
set_cookie_store(cookie_store_proxy_.get());
// All other values refer to the parent request context.
set_net_log(parent->net_log());
set_enable_brotli(parent->enable_brotli());
set_host_resolver(parent->host_resolver());
set_cert_verifier(parent->cert_verifier());
set_transport_security_state(parent->transport_security_state());
set_cert_transparency_verifier(parent->cert_transparency_verifier());
set_ct_policy_enforcer(parent->ct_policy_enforcer());
set_channel_id_service(parent->channel_id_service());
set_proxy_resolution_service(parent->proxy_resolution_service());
set_ssl_config_service(parent->ssl_config_service());
set_http_auth_handler_factory(parent->http_auth_handler_factory());
set_http_transaction_factory(parent->http_transaction_factory());
set_network_delegate(parent->network_delegate());
set_http_server_properties(parent->http_server_properties());
set_transport_security_state(parent->transport_security_state());
set_http_user_agent_settings(const_cast<net::HttpUserAgentSettings*>(
parent->http_user_agent_settings()));
set_job_factory(parent->job_factory());
}
CefURLRequestContextProxy::~CefURLRequestContextProxy() {
CEF_REQUIRE_IOT();
}

View File

@ -1,35 +0,0 @@
// Copyright (c) 2012 The Chromium Embedded Framework 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 CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_PROXY_H_
#define CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_PROXY_H_
#pragma once
#include "include/cef_request_context.h"
#include "include/cef_request_context_handler.h"
#include "libcef/browser/net/url_request_context.h"
class CefBrowserHostImpl;
class CefCookieStoreProxy;
class CefURLRequestContextImpl;
// URLRequestContext implementation for a particular CefRequestContext. Life
// span is controlled by CefURLRequestContextGetterProxy. Only accessed on the
// IO thread. See browser_context.h for an object relationship diagram.
class CefURLRequestContextProxy : public CefURLRequestContext {
public:
// The |parent| pointer is kept alive by CefURLRequestContextGetterProxy
// which has a ref to the owning CefURLRequestContextGetterImpl. It is
// guaranteed to outlive this object.
CefURLRequestContextProxy(CefURLRequestContextImpl* parent,
CefRefPtr<CefRequestContextHandler> handler);
~CefURLRequestContextProxy() override;
private:
std::unique_ptr<CefCookieStoreProxy> cookie_store_proxy_;
DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextProxy);
};
#endif // CEF_LIBCEF_BROWSER_NET_URL_REQUEST_CONTEXT_PROXY_H_

View File

@ -15,7 +15,7 @@ class NetworkDelegate;
class URLRequest;
class URLRequestJob;
class URLRequestJobFactoryImpl;
}
} // namespace net
class CefProtocolHandler;
@ -66,7 +66,7 @@ class CefURLRequestManager {
const std::string& scheme);
// Life span of |job_factory_| is guaranteed by
// CefURLRequestContextGetterImpl which also owns this object.
// CefURLRequestContextGetter which also owns this object.
net::URLRequestJobFactoryImpl* job_factory_;
// Map (scheme, domain) to factories.

View File

@ -5,7 +5,7 @@
#include "libcef/browser/prefs/browser_prefs.h"
#include "libcef/browser/media_capture_devices_dispatcher.h"
#include "libcef/browser/net/url_request_context_getter_impl.h"
#include "libcef/browser/net/url_request_context_getter.h"
#include "libcef/browser/prefs/pref_store.h"
#include "libcef/browser/prefs/renderer_prefs.h"
#include "libcef/common/cef_switches.h"
@ -153,7 +153,7 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
update_client::RegisterPrefs(registry.get());
if (!command_line->HasSwitch(switches::kEnableNetworkService)) {
CefURLRequestContextGetterImpl::RegisterPrefs(registry.get());
CefURLRequestContextGetter::RegisterPrefs(registry.get());
} else if (!profile) {
SystemNetworkContextManager::RegisterPrefs(registry.get());
}

View File

@ -3,8 +3,7 @@
// can be found in the LICENSE file.
#include "libcef/browser/request_context_impl.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_context_proxy.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/cookie_manager_impl.h"
@ -140,14 +139,10 @@ CefRefPtr<CefRequestContext> CefRequestContext::CreateContext(
CefRequestContextImpl::~CefRequestContextImpl() {
CEF_REQUIRE_UIT();
// Delete the proxy first because it also references |browser_context_impl_|.
if (browser_context_proxy_)
browser_context_proxy_.reset(nullptr);
if (browser_context_impl_) {
// May result in |browser_context_impl_| being deleted if no other
if (browser_context_) {
// May result in |browser_context_| being deleted if no other
// CefRequestContextImpl are referencing it.
browser_context_impl_->RemoveCefRequestContext(this);
browser_context_->RemoveCefRequestContext(this);
}
}
@ -198,7 +193,7 @@ void CefRequestContextImpl::GetRequestContextImpl(
DCHECK(!net_service::IsEnabled());
if (!task_runner.get())
task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner();
if (request_context_getter_impl_) {
if (request_context_getter_) {
// The browser context already exists.
DCHECK(browser_context());
GetRequestContextImplOnIOThread(task_runner, callback, browser_context());
@ -223,15 +218,6 @@ bool CefRequestContextImpl::IsSame(CefRefPtr<CefRequestContext> other) {
// Compare CefBrowserContext pointers if one has been associated.
if (browser_context() && other_impl->browser_context()) {
if (browser_context()->is_proxy() &&
other_impl->browser_context()->is_proxy()) {
CefBrowserContextProxy* proxy =
static_cast<CefBrowserContextProxy*>(browser_context());
CefBrowserContextProxy* other_proxy =
static_cast<CefBrowserContextProxy*>(other_impl->browser_context());
return (proxy->parent() == other_proxy->parent() &&
proxy->GetHandler() == other_proxy->GetHandler());
}
return (browser_context() == other_impl->browser_context());
} else if (browser_context() || other_impl->browser_context()) {
return false;
@ -264,11 +250,9 @@ bool CefRequestContextImpl::IsSharingWith(CefRefPtr<CefRequestContext> other) {
return pending_other->IsSharingWith(this);
}
if (request_context_getter_impl_ &&
other_impl->request_context_getter_impl_) {
if (request_context_getter_ && other_impl->request_context_getter_) {
// Both objects are initialized. Compare the request context objects.
return (request_context_getter_impl_ ==
other_impl->request_context_getter_impl_);
return (request_context_getter_ == other_impl->request_context_getter_);
}
// This or the other object is not initialized. Compare the cache path values.
@ -295,10 +279,9 @@ CefString CefRequestContextImpl::GetCachePath() {
return CefString(&config_.settings.cache_path);
}
CefRefPtr<CefCookieManager> CefRequestContextImpl::GetDefaultCookieManager(
CefRefPtr<CefCookieManager> CefRequestContextImpl::GetCookieManager(
CefRefPtr<CefCompletionCallback> callback) {
CefRefPtr<CefCookieManagerImpl> cookie_manager =
new CefCookieManagerImpl(false);
CefRefPtr<CefCookieManagerImpl> cookie_manager = new CefCookieManagerImpl();
cookie_manager->Initialize(this, CefString(), false, callback);
return cookie_manager.get();
}
@ -580,65 +563,54 @@ CefRequestContextImpl::CefRequestContextImpl(
void CefRequestContextImpl::Initialize() {
CEF_REQUIRE_UIT();
DCHECK(!browser_context_impl_);
DCHECK(!request_context_getter_impl_);
DCHECK(!browser_context_);
DCHECK(!request_context_getter_);
if (config_.other) {
// Share storage with |config_.other|.
browser_context_impl_ = CefBrowserContextImpl::GetForContext(
config_.other->GetBrowserContext());
browser_context_ =
CefBrowserContext::GetForContext(config_.other->GetBrowserContext());
}
if (!browser_context_impl_) {
if (!browser_context_) {
const base::FilePath& cache_path =
base::FilePath(CefString(&config_.settings.cache_path));
if (!cache_path.empty()) {
// Check if a CefBrowserContextImpl is already globally registered for
// Check if a CefBrowserContext is already globally registered for
// the specified cache path. If so then use it.
browser_context_impl_ =
CefBrowserContextImpl::GetForCachePath(cache_path);
browser_context_ = CefBrowserContext::GetForCachePath(cache_path);
}
}
if (!browser_context_impl_) {
// Create a new CefBrowserContextImpl instance. If the cache path is non-
if (!browser_context_) {
// Create a new CefBrowserContext instance. If the cache path is non-
// empty then this new instance will become the globally registered
// CefBrowserContextImpl for that path. Otherwise, this new instance will
// CefBrowserContext for that path. Otherwise, this new instance will
// be a completely isolated "incongento mode" context.
browser_context_impl_ = new CefBrowserContextImpl(config_.settings);
browser_context_impl_->Initialize();
browser_context_ = new CefBrowserContext(config_.settings);
browser_context_->Initialize();
}
// We'll disassociate from |browser_context_impl_| on destruction.
browser_context_impl_->AddCefRequestContext(this);
// We'll disassociate from |browser_context_| on destruction.
browser_context_->AddCefRequestContext(this);
// Force our settings to match |browser_context_impl_|.
config_.settings = browser_context_impl_->GetSettings();
if (config_.handler.get()) {
// Use a proxy that will execute handler callbacks where appropriate and
// otherwise forward all requests to |browser_context_impl_|.
browser_context_proxy_.reset(new CefBrowserContextProxy(
this, config_.handler, browser_context_impl_));
browser_context_proxy_->Initialize();
DCHECK(!config_.is_global);
}
// Force our settings to match |browser_context_|.
config_.settings = browser_context_->GetSettings();
if (!net_service::IsEnabled()) {
request_context_getter_impl_ =
browser_context_impl_->request_context_getter().get();
DCHECK(request_context_getter_impl_);
request_context_getter_ = browser_context_->request_context_getter().get();
DCHECK(request_context_getter_);
if (config_.handler.get()) {
// Keep the handler alive until the associated request context is
// destroyed.
request_context_getter_impl_->AddHandler(config_.handler);
request_context_getter_->AddHandler(config_.handler);
}
}
if (config_.other) {
// Clear the reference to |config_.other| after setting
// |request_context_getter_impl_|. This is the reverse order of checks in
// |request_context_getter_|. This is the reverse order of checks in
// IsSharedWith().
config_.other = NULL;
}
@ -652,7 +624,7 @@ void CefRequestContextImpl::EnsureBrowserContext() {
if (!browser_context())
Initialize();
DCHECK(browser_context());
DCHECK(net_service::IsEnabled() || request_context_getter_impl_);
DCHECK(net_service::IsEnabled() || request_context_getter_);
}
void CefRequestContextImpl::GetBrowserContextOnUIThread(
@ -690,19 +662,19 @@ void CefRequestContextImpl::GetRequestContextImplOnIOThread(
}
DCHECK(!net_service::IsEnabled());
DCHECK(request_context_getter_impl_);
DCHECK(request_context_getter_);
// Make sure the request context exists.
request_context_getter_impl_->GetURLRequestContext();
request_context_getter_->GetURLRequestContext();
if (task_runner->BelongsToCurrentThread()) {
// Execute the callback immediately.
callback.Run(request_context_getter_impl_);
callback.Run(request_context_getter_);
} else {
// Execute the callback on the target thread.
task_runner->PostTask(
FROM_HERE, base::Bind(callback, base::WrapRefCounted(
request_context_getter_impl_)));
FROM_HERE,
base::Bind(callback, base::WrapRefCounted(request_context_getter_)));
}
}
@ -710,14 +682,14 @@ void CefRequestContextImpl::RegisterSchemeHandlerFactoryInternal(
const CefString& scheme_name,
const CefString& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory,
scoped_refptr<CefURLRequestContextGetterImpl> request_context) {
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
request_context->request_manager()->AddFactory(scheme_name, domain_name,
factory);
}
void CefRequestContextImpl::ClearSchemeHandlerFactoriesInternal(
scoped_refptr<CefURLRequestContextGetterImpl> request_context) {
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
request_context->request_manager()->ClearFactories();
}
@ -749,7 +721,7 @@ void CefRequestContextImpl::ClearCertificateExceptionsInternal(
void CefRequestContextImpl::CloseAllConnectionsInternal(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context) {
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
net::URLRequestContext* url_context = request_context->GetURLRequestContext();
@ -772,7 +744,7 @@ void CefRequestContextImpl::CloseAllConnectionsInternal(
void CefRequestContextImpl::ResolveHostInternal(
const CefString& origin,
CefRefPtr<CefResolveCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context) {
scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT();
int retval = ERR_FAILED;
@ -797,7 +769,5 @@ void CefRequestContextImpl::ResolveHostInternal(
}
CefBrowserContext* CefRequestContextImpl::browser_context() const {
if (browser_context_proxy_)
return browser_context_proxy_.get();
return browser_context_impl_;
return browser_context_;
}

View File

@ -10,8 +10,7 @@
#include "libcef/browser/browser_context.h"
#include "libcef/browser/thread_util.h"
class CefBrowserContextImpl;
class CefBrowserContextProxy;
class CefBrowserContext;
// Implementation of the CefRequestContext interface. All methods are thread-
// safe unless otherwise indicated. Will be deleted on the UI thread.
@ -45,7 +44,7 @@ class CefRequestContextImpl : public CefRequestContext {
// context object when it's available. If |task_runner| is NULL the callback
// will be executed on the originating thread. The resulting context object
// can only be accessed on the IO thread.
typedef base::Callback<void(scoped_refptr<CefURLRequestContextGetterImpl>)>
typedef base::Callback<void(scoped_refptr<CefURLRequestContextGetter>)>
RequestContextCallback;
void GetRequestContextImpl(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
@ -56,7 +55,7 @@ class CefRequestContextImpl : public CefRequestContext {
bool IsGlobal() override;
CefRefPtr<CefRequestContextHandler> GetHandler() override;
CefString GetCachePath() override;
CefRefPtr<CefCookieManager> GetDefaultCookieManager(
CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefCompletionCallback> callback) override;
bool RegisterSchemeHandlerFactory(
const CefString& scheme_name,
@ -101,8 +100,7 @@ class CefRequestContextImpl : public CefRequestContext {
CefRequestContextSettings settings;
CefRefPtr<CefRequestContextImpl> other;
// Optionally use this handler, in which case a CefBrowserContextProxy will
// be created.
// Optionally use this handler.
CefRefPtr<CefRequestContextHandler> handler;
// Used to uniquely identify CefRequestContext objects before an associated
@ -133,9 +131,9 @@ class CefRequestContextImpl : public CefRequestContext {
const CefString& scheme_name,
const CefString& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory,
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
scoped_refptr<CefURLRequestContextGetter> request_context);
void ClearSchemeHandlerFactoriesInternal(
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
scoped_refptr<CefURLRequestContextGetter> request_context);
void PurgePluginListCacheInternal(bool reload_pages,
CefBrowserContext* browser_context);
void ClearCertificateExceptionsInternal(
@ -143,23 +141,21 @@ class CefRequestContextImpl : public CefRequestContext {
CefBrowserContext* browser_context);
void CloseAllConnectionsInternal(
CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
scoped_refptr<CefURLRequestContextGetter> request_context);
void ResolveHostInternal(
const CefString& origin,
CefRefPtr<CefResolveCallback> callback,
scoped_refptr<CefURLRequestContextGetterImpl> request_context);
scoped_refptr<CefURLRequestContextGetter> request_context);
CefBrowserContext* browser_context() const;
// If *Impl then we must disassociate from it on destruction.
CefBrowserContextImpl* browser_context_impl_ = nullptr;
// If *Proxy then we own it.
std::unique_ptr<CefBrowserContextProxy> browser_context_proxy_;
// We must disassociate from this on destruction.
CefBrowserContext* browser_context_ = nullptr;
Config config_;
// Owned by the CefBrowserContext.
CefURLRequestContextGetterImpl* request_context_getter_impl_ = nullptr;
CefURLRequestContextGetter* request_context_getter_ = nullptr;
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefRequestContextImpl);
DISALLOW_COPY_AND_ASSIGN(CefRequestContextImpl);

View File

@ -23,49 +23,13 @@
#include "net/ssl/client_cert_store_mac.h"
#endif
namespace {
bool ShouldProxyUserData(const void* key) {
// If this value is not proxied WebUI will fail to load.
if (key == content::GetURLDataManagerBackendUserDataKey())
return true;
return false;
}
} // namespace
CefResourceContext::CefResourceContext(
bool is_off_the_record,
CefRefPtr<CefRequestContextHandler> handler)
: parent_(nullptr),
is_off_the_record_(is_off_the_record),
handler_(handler) {}
: is_off_the_record_(is_off_the_record), handler_(handler) {}
CefResourceContext::~CefResourceContext() {}
base::SupportsUserData::Data* CefResourceContext::GetUserData(
const void* key) const {
if (parent_ && ShouldProxyUserData(key))
return parent_->GetUserData(key);
return content::ResourceContext::GetUserData(key);
}
void CefResourceContext::SetUserData(const void* key,
std::unique_ptr<Data> data) {
if (parent_ && ShouldProxyUserData(key))
parent_->SetUserData(key, std::move(data));
else
content::ResourceContext::SetUserData(key, std::move(data));
}
void CefResourceContext::RemoveUserData(const void* key) {
if (parent_ && ShouldProxyUserData(key))
parent_->RemoveUserData(key);
else
content::ResourceContext::RemoveUserData(key);
}
std::unique_ptr<net::ClientCertStore>
CefResourceContext::CreateClientCertStore() {
#if defined(USE_NSS_CERTS)
@ -91,12 +55,6 @@ void CefResourceContext::set_extensions_info_map(
extension_info_map_ = extensions_info_map;
}
void CefResourceContext::set_parent(CefResourceContext* parent) {
DCHECK(!parent_);
DCHECK(parent);
parent_ = parent;
}
void CefResourceContext::AddPluginLoadDecision(
int render_process_id,
const base::FilePath& plugin_path,

View File

@ -32,15 +32,9 @@ class CefResourceContext : public content::ResourceContext {
CefRefPtr<CefRequestContextHandler> handler);
~CefResourceContext() override;
// SupportsUserData implementation.
Data* GetUserData(const void* key) const override;
void SetUserData(const void* key, std::unique_ptr<Data> data) override;
void RemoveUserData(const void* key) override;
std::unique_ptr<net::ClientCertStore> CreateClientCertStore();
void set_extensions_info_map(extensions::InfoMap* extensions_info_map);
void set_parent(CefResourceContext* parent);
// Remember the plugin load decision for plugin status requests that arrive
// via CefPluginServiceFilter::IsPluginAvailable.
@ -67,11 +61,6 @@ class CefResourceContext : public content::ResourceContext {
CefRefPtr<CefRequestContextHandler> GetHandler() const { return handler_; }
private:
// Non-NULL when this object is owned by a CefBrowserContextProxy. |parent_|
// is guaranteed to outlive this object because CefBrowserContextProxy has a
// refptr to the CefBrowserContextImpl that owns |parent_|.
CefResourceContext* parent_;
// Only accessed on the IO thread.
bool is_off_the_record_;
scoped_refptr<extensions::InfoMap> extension_info_map_;

View File

@ -1,264 +0,0 @@
// Copyright (c) 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 "libcef/browser/storage_partition_proxy.h"
#include "libcef/common/net_service/util.h"
#include "base/logging.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
CefStoragePartitionProxy::CefStoragePartitionProxy(
content::StoragePartition* parent,
CefURLRequestContextGetterProxy* url_request_context)
: parent_(parent), url_request_context_(url_request_context) {
DCHECK(net_service::IsEnabled() || url_request_context_);
}
CefStoragePartitionProxy::~CefStoragePartitionProxy() {
if (url_request_context_)
url_request_context_->ShutdownOnUIThread();
}
base::FilePath CefStoragePartitionProxy::GetPath() {
return parent_->GetPath();
}
net::URLRequestContextGetter* CefStoragePartitionProxy::GetURLRequestContext() {
return url_request_context_.get();
}
net::URLRequestContextGetter*
CefStoragePartitionProxy::GetMediaURLRequestContext() {
return GetURLRequestContext();
}
network::mojom::NetworkContext* CefStoragePartitionProxy::GetNetworkContext() {
return parent_->GetNetworkContext();
}
scoped_refptr<network::SharedURLLoaderFactory>
CefStoragePartitionProxy::GetURLLoaderFactoryForBrowserProcess() {
return parent_->GetURLLoaderFactoryForBrowserProcess();
}
std::unique_ptr<network::SharedURLLoaderFactoryInfo>
CefStoragePartitionProxy::GetURLLoaderFactoryForBrowserProcessIOThread() {
return parent_->GetURLLoaderFactoryForBrowserProcessIOThread();
}
network::mojom::CookieManager*
CefStoragePartitionProxy::GetCookieManagerForBrowserProcess() {
return parent_->GetCookieManagerForBrowserProcess();
}
storage::QuotaManager* CefStoragePartitionProxy::GetQuotaManager() {
return parent_->GetQuotaManager();
}
content::AppCacheService* CefStoragePartitionProxy::GetAppCacheService() {
return parent_->GetAppCacheService();
}
storage::FileSystemContext* CefStoragePartitionProxy::GetFileSystemContext() {
return parent_->GetFileSystemContext();
}
storage::DatabaseTracker* CefStoragePartitionProxy::GetDatabaseTracker() {
return parent_->GetDatabaseTracker();
}
content::DOMStorageContext* CefStoragePartitionProxy::GetDOMStorageContext() {
return parent_->GetDOMStorageContext();
}
content::IdleManager* CefStoragePartitionProxy::GetIdleManager() {
return parent_->GetIdleManager();
}
content::LockManager* CefStoragePartitionProxy::GetLockManager() {
return parent_->GetLockManager();
}
content::IndexedDBContext* CefStoragePartitionProxy::GetIndexedDBContext() {
return parent_->GetIndexedDBContext();
}
content::ServiceWorkerContext*
CefStoragePartitionProxy::GetServiceWorkerContext() {
return parent_->GetServiceWorkerContext();
}
content::SharedWorkerService*
CefStoragePartitionProxy::GetSharedWorkerService() {
return parent_->GetSharedWorkerService();
}
content::CacheStorageContext*
CefStoragePartitionProxy::GetCacheStorageContext() {
return parent_->GetCacheStorageContext();
}
content::GeneratedCodeCacheContext*
CefStoragePartitionProxy::GetGeneratedCodeCacheContext() {
return parent_->GetGeneratedCodeCacheContext();
}
content::HostZoomMap* CefStoragePartitionProxy::GetHostZoomMap() {
return parent_->GetHostZoomMap();
}
content::HostZoomLevelContext*
CefStoragePartitionProxy::GetHostZoomLevelContext() {
return parent_->GetHostZoomLevelContext();
}
content::ZoomLevelDelegate* CefStoragePartitionProxy::GetZoomLevelDelegate() {
return parent_->GetZoomLevelDelegate();
}
content::PlatformNotificationContext*
CefStoragePartitionProxy::GetPlatformNotificationContext() {
return parent_->GetPlatformNotificationContext();
}
void CefStoragePartitionProxy::ClearDataForOrigin(
uint32_t remove_mask,
uint32_t quota_storage_remove_mask,
const GURL& storage_origin) {
parent_->ClearDataForOrigin(remove_mask, quota_storage_remove_mask,
storage_origin);
}
void CefStoragePartitionProxy::ClearData(uint32_t remove_mask,
uint32_t quota_storage_remove_mask,
const GURL& storage_origin,
const base::Time begin,
const base::Time end,
base::OnceClosure callback) {
parent_->ClearData(remove_mask, quota_storage_remove_mask, storage_origin,
begin, end, std::move(callback));
}
void CefStoragePartitionProxy::ClearData(
uint32_t remove_mask,
uint32_t quota_storage_remove_mask,
const OriginMatcherFunction& origin_matcher,
network::mojom::CookieDeletionFilterPtr cookie_deletion_filter,
bool perform_cleanup,
const base::Time begin,
const base::Time end,
base::OnceClosure callback) {
parent_->ClearData(remove_mask, quota_storage_remove_mask, origin_matcher,
std::move(cookie_deletion_filter), perform_cleanup, begin,
end, std::move(callback));
}
void CefStoragePartitionProxy::ClearHttpAndMediaCaches(
const base::Time begin,
const base::Time end,
const base::Callback<bool(const GURL&)>& url_matcher,
base::OnceClosure callback) {
parent_->ClearHttpAndMediaCaches(begin, end, url_matcher,
std::move(callback));
}
void CefStoragePartitionProxy::ClearCodeCaches(
base::Time begin,
base::Time end,
const base::RepeatingCallback<bool(const GURL&)>& url_matcher,
base::OnceClosure callback) {
parent_->ClearCodeCaches(begin, end, url_matcher, std::move(callback));
}
void CefStoragePartitionProxy::Flush() {
parent_->Flush();
}
void CefStoragePartitionProxy::ResetURLLoaderFactories() {
parent_->ResetURLLoaderFactories();
}
void CefStoragePartitionProxy::ClearBluetoothAllowedDevicesMapForTesting() {
parent_->ClearBluetoothAllowedDevicesMapForTesting();
}
void CefStoragePartitionProxy::FlushNetworkInterfaceForTesting() {
parent_->FlushNetworkInterfaceForTesting();
}
void CefStoragePartitionProxy::WaitForDeletionTasksForTesting() {
parent_->WaitForDeletionTasksForTesting();
}
content::BackgroundFetchContext*
CefStoragePartitionProxy::GetBackgroundFetchContext() {
return parent_->GetBackgroundFetchContext();
}
content::BackgroundSyncContext*
CefStoragePartitionProxy::GetBackgroundSyncContext() {
return parent_->GetBackgroundSyncContext();
}
content::PaymentAppContextImpl*
CefStoragePartitionProxy::GetPaymentAppContext() {
return parent_->GetPaymentAppContext();
}
content::BroadcastChannelProvider*
CefStoragePartitionProxy::GetBroadcastChannelProvider() {
return parent_->GetBroadcastChannelProvider();
}
content::BluetoothAllowedDevicesMap*
CefStoragePartitionProxy::GetBluetoothAllowedDevicesMap() {
return parent_->GetBluetoothAllowedDevicesMap();
}
content::BlobRegistryWrapper* CefStoragePartitionProxy::GetBlobRegistry() {
return parent_->GetBlobRegistry();
}
content::PrefetchURLLoaderService*
CefStoragePartitionProxy::GetPrefetchURLLoaderService() {
return parent_->GetPrefetchURLLoaderService();
}
content::CookieStoreContext* CefStoragePartitionProxy::GetCookieStoreContext() {
return parent_->GetCookieStoreContext();
}
content::DevToolsBackgroundServicesContext*
CefStoragePartitionProxy::GetDevToolsBackgroundServicesContext() {
return parent_->GetDevToolsBackgroundServicesContext();
}
content::URLLoaderFactoryGetter*
CefStoragePartitionProxy::url_loader_factory_getter() {
return parent_->url_loader_factory_getter();
}
content::BrowserContext* CefStoragePartitionProxy::browser_context() const {
return parent_->browser_context();
}
mojo::BindingId CefStoragePartitionProxy::Bind(
int process_id,
mojo::InterfaceRequest<blink::mojom::StoragePartitionService> request) {
return parent_->Bind(process_id, std::move(request));
}
void CefStoragePartitionProxy::Unbind(mojo::BindingId binding_id) {
parent_->Unbind(binding_id);
}
void CefStoragePartitionProxy::set_site_for_service_worker(
const GURL& site_for_service_worker) {
parent_->set_site_for_service_worker(site_for_service_worker);
}
const GURL& CefStoragePartitionProxy::site_for_service_worker() const {
return parent_->site_for_service_worker();
}

View File

@ -1,112 +0,0 @@
// Copyright (c) 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 CEF_LIBCEF_BROWSER_STORAGE_PARTITION_PROXY_H_
#define CEF_LIBCEF_BROWSER_STORAGE_PARTITION_PROXY_H_
#pragma once
#include "libcef/browser/net/url_request_context_getter_proxy.h"
#include "content/public/browser/storage_partition.h"
// StoragePartition implementation for a particular CefBrowserContextProxy. Life
// span is controlled by CefBrowserContextProxy. Only accessed on the UI thread.
// See browser_context.h for an object relationship diagram.
class CefStoragePartitionProxy : public content::StoragePartition {
public:
CefStoragePartitionProxy(
content::StoragePartition* parent,
CefURLRequestContextGetterProxy* url_request_context);
~CefStoragePartitionProxy() override;
// StoragePartition methods:
base::FilePath GetPath() override;
net::URLRequestContextGetter* GetURLRequestContext() override;
net::URLRequestContextGetter* GetMediaURLRequestContext() override;
network::mojom::NetworkContext* GetNetworkContext() override;
scoped_refptr<network::SharedURLLoaderFactory>
GetURLLoaderFactoryForBrowserProcess() override;
std::unique_ptr<network::SharedURLLoaderFactoryInfo>
GetURLLoaderFactoryForBrowserProcessIOThread() override;
network::mojom::CookieManager* GetCookieManagerForBrowserProcess() override;
storage::QuotaManager* GetQuotaManager() override;
content::AppCacheService* GetAppCacheService() override;
storage::FileSystemContext* GetFileSystemContext() override;
storage::DatabaseTracker* GetDatabaseTracker() override;
content::DOMStorageContext* GetDOMStorageContext() override;
content::IdleManager* GetIdleManager() override;
content::LockManager* GetLockManager() override;
content::IndexedDBContext* GetIndexedDBContext() override;
content::ServiceWorkerContext* GetServiceWorkerContext() override;
content::SharedWorkerService* GetSharedWorkerService() override;
content::CacheStorageContext* GetCacheStorageContext() override;
content::GeneratedCodeCacheContext* GetGeneratedCodeCacheContext() override;
content::HostZoomMap* GetHostZoomMap() override;
content::HostZoomLevelContext* GetHostZoomLevelContext() override;
content::ZoomLevelDelegate* GetZoomLevelDelegate() override;
content::PlatformNotificationContext* GetPlatformNotificationContext()
override;
void ClearDataForOrigin(uint32_t remove_mask,
uint32_t quota_storage_remove_mask,
const GURL& storage_origin) override;
void ClearData(uint32_t remove_mask,
uint32_t quota_storage_remove_mask,
const GURL& storage_origin,
const base::Time begin,
const base::Time end,
base::OnceClosure callback) override;
void ClearData(uint32_t remove_mask,
uint32_t quota_storage_remove_mask,
const OriginMatcherFunction& origin_matcher,
network::mojom::CookieDeletionFilterPtr cookie_deletion_filter,
bool perform_cleanup,
const base::Time begin,
const base::Time end,
base::OnceClosure callback) override;
void ClearHttpAndMediaCaches(
const base::Time begin,
const base::Time end,
const base::Callback<bool(const GURL&)>& url_matcher,
base::OnceClosure callback) override;
void ClearCodeCaches(
base::Time begin,
base::Time end,
const base::RepeatingCallback<bool(const GURL&)>& url_matcher,
base::OnceClosure callback) override;
void Flush() override;
void ResetURLLoaderFactories() override;
void ClearBluetoothAllowedDevicesMapForTesting() override;
void FlushNetworkInterfaceForTesting() override;
void WaitForDeletionTasksForTesting() override;
content::BackgroundFetchContext* GetBackgroundFetchContext() override;
content::BackgroundSyncContext* GetBackgroundSyncContext() override;
content::PaymentAppContextImpl* GetPaymentAppContext() override;
content::BroadcastChannelProvider* GetBroadcastChannelProvider() override;
content::BluetoothAllowedDevicesMap* GetBluetoothAllowedDevicesMap() override;
content::BlobRegistryWrapper* GetBlobRegistry() override;
content::PrefetchURLLoaderService* GetPrefetchURLLoaderService() override;
content::CookieStoreContext* GetCookieStoreContext() override;
content::DevToolsBackgroundServicesContext*
GetDevToolsBackgroundServicesContext() override;
content::URLLoaderFactoryGetter* url_loader_factory_getter() override;
content::BrowserContext* browser_context() const override;
mojo::BindingId Bind(
int process_id,
mojo::InterfaceRequest<blink::mojom::StoragePartitionService> request)
override;
void Unbind(mojo::BindingId binding_id) override;
void set_site_for_service_worker(
const GURL& site_for_service_worker) override;
const GURL& site_for_service_worker() const override;
content::StoragePartition* parent() const { return parent_; }
private:
content::StoragePartition* parent_; // Not owned.
scoped_refptr<CefURLRequestContextGetterProxy> url_request_context_;
DISALLOW_COPY_AND_ASSIGN(CefStoragePartitionProxy);
};
#endif // CEF_LIBCEF_BROWSER_STORAGE_PARTITION_PROXY_H_

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=229d455bfe9f7c8536f7bc03734eaf29e9e637b1$
// $hash=a672fab541f9c28f77a06c31d89f5a9d66c78751$
//
#include "libcef_dll/cpptoc/cookie_manager_cpptoc.h"
@ -35,33 +35,6 @@ CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_get_global_manager(
return CefCookieManagerCppToC::Wrap(_retval);
}
CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_get_blocking_manager() {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
CefRefPtr<CefCookieManager> _retval = CefCookieManager::GetBlockingManager();
// Return type: refptr_same
return CefCookieManagerCppToC::Wrap(_retval);
}
CEF_EXPORT cef_cookie_manager_t* cef_cookie_manager_create_manager(
const cef_string_t* path,
int persist_session_cookies,
cef_completion_callback_t* callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: path, callback
// Execute
CefRefPtr<CefCookieManager> _retval = CefCookieManager::CreateManager(
CefString(path), persist_session_cookies ? true : false,
CefCompletionCallbackCToCpp::Wrap(callback));
// Return type: refptr_same
return CefCookieManagerCppToC::Wrap(_retval);
}
namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
@ -193,27 +166,6 @@ cookie_manager_delete_cookies(struct _cef_cookie_manager_t* self,
return _retval;
}
int CEF_CALLBACK
cookie_manager_set_storage_path(struct _cef_cookie_manager_t* self,
const cef_string_t* path,
int persist_session_cookies,
cef_completion_callback_t* callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Unverified params: path, callback
// Execute
bool _retval = CefCookieManagerCppToC::Get(self)->SetStoragePath(
CefString(path), persist_session_cookies ? true : false,
CefCompletionCallbackCToCpp::Wrap(callback));
// Return type: bool
return _retval;
}
int CEF_CALLBACK
cookie_manager_flush_store(struct _cef_cookie_manager_t* self,
cef_completion_callback_t* callback) {
@ -242,7 +194,6 @@ CefCookieManagerCppToC::CefCookieManagerCppToC() {
GetStruct()->visit_url_cookies = cookie_manager_visit_url_cookies;
GetStruct()->set_cookie = cookie_manager_set_cookie;
GetStruct()->delete_cookies = cookie_manager_delete_cookies;
GetStruct()->set_storage_path = cookie_manager_set_storage_path;
GetStruct()->flush_store = cookie_manager_flush_store;
}

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=f4724d1d945c06c5113ba9e1b7f7ad8d4b735b9c$
// $hash=29ac900a92c4ec966cc115aae96c49b545bc9db9$
//
#include "libcef_dll/cpptoc/request_context_cpptoc.h"
@ -171,9 +171,9 @@ request_context_get_cache_path(struct _cef_request_context_t* self) {
return _retval.DetachToUserFree();
}
cef_cookie_manager_t* CEF_CALLBACK request_context_get_default_cookie_manager(
struct _cef_request_context_t* self,
cef_completion_callback_t* callback) {
cef_cookie_manager_t* CEF_CALLBACK
request_context_get_cookie_manager(struct _cef_request_context_t* self,
cef_completion_callback_t* callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
@ -183,7 +183,7 @@ cef_cookie_manager_t* CEF_CALLBACK request_context_get_default_cookie_manager(
// Execute
CefRefPtr<CefCookieManager> _retval =
CefRequestContextCppToC::Get(self)->GetDefaultCookieManager(
CefRequestContextCppToC::Get(self)->GetCookieManager(
CefCompletionCallbackCToCpp::Wrap(callback));
// Return type: refptr_same
@ -535,8 +535,7 @@ CefRequestContextCppToC::CefRequestContextCppToC() {
GetStruct()->is_global = request_context_is_global;
GetStruct()->get_handler = request_context_get_handler;
GetStruct()->get_cache_path = request_context_get_cache_path;
GetStruct()->get_default_cookie_manager =
request_context_get_default_cookie_manager;
GetStruct()->get_cookie_manager = request_context_get_cookie_manager;
GetStruct()->register_scheme_handler_factory =
request_context_register_scheme_handler_factory;
GetStruct()->clear_scheme_handler_factories =

View File

@ -9,11 +9,10 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=2decd7941020bd2b96ebfa736624d1729a82fa55$
// $hash=b98ed34333ccd44a004c88c0ca496f7821f49e18$
//
#include "libcef_dll/cpptoc/request_context_handler_cpptoc.h"
#include "libcef_dll/ctocpp/cookie_manager_ctocpp.h"
#include "libcef_dll/ctocpp/request_context_ctocpp.h"
#include "libcef_dll/ctocpp/web_plugin_info_ctocpp.h"
@ -39,22 +38,6 @@ void CEF_CALLBACK request_context_handler_on_request_context_initialized(
CefRequestContextCToCpp::Wrap(request_context));
}
cef_cookie_manager_t* CEF_CALLBACK request_context_handler_get_cookie_manager(
struct _cef_request_context_handler_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Execute
CefRefPtr<CefCookieManager> _retval =
CefRequestContextHandlerCppToC::Get(self)->GetCookieManager();
// Return type: refptr_diff
return CefCookieManagerCToCpp::Unwrap(_retval);
}
int CEF_CALLBACK request_context_handler_on_before_plugin_load(
struct _cef_request_context_handler_t* self,
const cef_string_t* mime_type,
@ -99,7 +82,6 @@ int CEF_CALLBACK request_context_handler_on_before_plugin_load(
CefRequestContextHandlerCppToC::CefRequestContextHandlerCppToC() {
GetStruct()->on_request_context_initialized =
request_context_handler_on_request_context_initialized;
GetStruct()->get_cookie_manager = request_context_handler_get_cookie_manager;
GetStruct()->on_before_plugin_load =
request_context_handler_on_before_plugin_load;
}

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=bd8fe0f41380bc1e5ecedbcab726bc2ed875f827$
// $hash=fdbb50cba70b9638aaaadc2e4040b18390ae3a6d$
//
#include "libcef_dll/ctocpp/cookie_manager_ctocpp.h"
@ -36,35 +36,6 @@ CefRefPtr<CefCookieManager> CefCookieManager::GetGlobalManager(
return CefCookieManagerCToCpp::Wrap(_retval);
}
NO_SANITIZE("cfi-icall")
CefRefPtr<CefCookieManager> CefCookieManager::GetBlockingManager() {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
cef_cookie_manager_t* _retval = cef_cookie_manager_get_blocking_manager();
// Return type: refptr_same
return CefCookieManagerCToCpp::Wrap(_retval);
}
NO_SANITIZE("cfi-icall")
CefRefPtr<CefCookieManager> CefCookieManager::CreateManager(
const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: path, callback
// Execute
cef_cookie_manager_t* _retval = cef_cookie_manager_create_manager(
path.GetStruct(), persist_session_cookies,
CefCompletionCallbackCppToC::Wrap(callback));
// Return type: refptr_same
return CefCookieManagerCToCpp::Wrap(_retval);
}
// VIRTUAL METHODS - Body may be edited by hand.
NO_SANITIZE("cfi-icall")
@ -192,28 +163,6 @@ bool CefCookieManagerCToCpp::DeleteCookies(
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall")
bool CefCookieManagerCToCpp::SetStoragePath(
const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback) {
cef_cookie_manager_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, set_storage_path))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: path, callback
// Execute
int _retval = _struct->set_storage_path(
_struct, path.GetStruct(), persist_session_cookies,
CefCompletionCallbackCppToC::Wrap(callback));
// Return type: bool
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall")
bool CefCookieManagerCToCpp::FlushStore(
CefRefPtr<CefCompletionCallback> callback) {

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=2363533e3c6b78e16b93dd428121cd45b797ce6a$
// $hash=99bb8be3c19be11e4abf2cf904d75667723ae643$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_COOKIE_MANAGER_CTOCPP_H_
@ -48,9 +48,6 @@ class CefCookieManagerCToCpp
bool DeleteCookies(const CefString& url,
const CefString& cookie_name,
CefRefPtr<CefDeleteCookiesCallback> callback) OVERRIDE;
bool SetStoragePath(const CefString& path,
bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback) OVERRIDE;
bool FlushStore(CefRefPtr<CefCompletionCallback> callback) OVERRIDE;
};

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=ed414e127773ef135584c3c61a386615177feb59$
// $hash=8155639f093ff697fd30a9e330ae3470108251e5$
//
#include "libcef_dll/ctocpp/request_context_ctocpp.h"
@ -165,10 +165,10 @@ NO_SANITIZE("cfi-icall") CefString CefRequestContextCToCpp::GetCachePath() {
}
NO_SANITIZE("cfi-icall")
CefRefPtr<CefCookieManager> CefRequestContextCToCpp::GetDefaultCookieManager(
CefRefPtr<CefCookieManager> CefRequestContextCToCpp::GetCookieManager(
CefRefPtr<CefCompletionCallback> callback) {
cef_request_context_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, get_default_cookie_manager))
if (CEF_MEMBER_MISSING(_struct, get_cookie_manager))
return NULL;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
@ -176,7 +176,7 @@ CefRefPtr<CefCookieManager> CefRequestContextCToCpp::GetDefaultCookieManager(
// Unverified params: callback
// Execute
cef_cookie_manager_t* _retval = _struct->get_default_cookie_manager(
cef_cookie_manager_t* _retval = _struct->get_cookie_manager(
_struct, CefCompletionCallbackCppToC::Wrap(callback));
// Return type: refptr_same

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=52475096e498cd28cbd25676eaab24e14c1438b0$
// $hash=73f229f21f0d9ce78f3897fd8a2ec94261a52f48$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_REQUEST_CONTEXT_CTOCPP_H_
@ -43,7 +43,7 @@ class CefRequestContextCToCpp
bool IsGlobal() OVERRIDE;
CefRefPtr<CefRequestContextHandler> GetHandler() OVERRIDE;
CefString GetCachePath() OVERRIDE;
CefRefPtr<CefCookieManager> GetDefaultCookieManager(
CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefCompletionCallback> callback) OVERRIDE;
bool RegisterSchemeHandlerFactory(
const CefString& scheme_name,

View File

@ -9,11 +9,10 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=80c600e8a2f2035219c00bad1bf28a58b6dabf53$
// $hash=4b25ca3feb69361cc3b6525fdc0c3a56710b65ec$
//
#include "libcef_dll/ctocpp/request_context_handler_ctocpp.h"
#include "libcef_dll/cpptoc/cookie_manager_cpptoc.h"
#include "libcef_dll/cpptoc/request_context_cpptoc.h"
#include "libcef_dll/cpptoc/web_plugin_info_cpptoc.h"
@ -38,21 +37,6 @@ void CefRequestContextHandlerCToCpp::OnRequestContextInitialized(
_struct, CefRequestContextCppToC::Wrap(request_context));
}
NO_SANITIZE("cfi-icall")
CefRefPtr<CefCookieManager> CefRequestContextHandlerCToCpp::GetCookieManager() {
cef_request_context_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, get_cookie_manager))
return NULL;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
cef_cookie_manager_t* _retval = _struct->get_cookie_manager(_struct);
// Return type: refptr_diff
return CefCookieManagerCppToC::Unwrap(_retval);
}
NO_SANITIZE("cfi-icall")
bool CefRequestContextHandlerCToCpp::OnBeforePluginLoad(
const CefString& mime_type,

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=f60c9110cba752df545af2fe5905a01d30ff588e$
// $hash=3cf1dba9c137bc586d91149920ff4558bce74a58$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_REQUEST_CONTEXT_HANDLER_CTOCPP_H_
@ -39,7 +39,6 @@ class CefRequestContextHandlerCToCpp
// CefRequestContextHandler methods.
void OnRequestContextInitialized(
CefRefPtr<CefRequestContext> request_context) override;
CefRefPtr<CefCookieManager> GetCookieManager() override;
bool OnBeforePluginLoad(const CefString& mime_type,
const CefString& plugin_url,
bool is_main_frame,

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=4a4744491587c5f5b1ce8726d8dd08ad04646b92$
// $hash=7c87ef36c39355a02bb9544b8228acac7a7abee9$
//
#include <dlfcn.h>
@ -198,12 +198,6 @@ typedef struct _cef_command_line_t* (*cef_command_line_get_global_ptr)();
typedef struct _cef_cookie_manager_t* (
*cef_cookie_manager_get_global_manager_ptr)(
struct _cef_completion_callback_t*);
typedef struct _cef_cookie_manager_t* (
*cef_cookie_manager_get_blocking_manager_ptr)();
typedef struct _cef_cookie_manager_t* (*cef_cookie_manager_create_manager_ptr)(
const cef_string_t*,
int,
struct _cef_completion_callback_t*);
typedef struct _cef_drag_data_t* (*cef_drag_data_create_ptr)();
typedef struct _cef_image_t* (*cef_image_create_ptr)();
typedef struct _cef_menu_model_t* (*cef_menu_model_create_ptr)(
@ -580,9 +574,6 @@ struct libcef_pointers {
cef_command_line_get_global_ptr cef_command_line_get_global;
cef_cookie_manager_get_global_manager_ptr
cef_cookie_manager_get_global_manager;
cef_cookie_manager_get_blocking_manager_ptr
cef_cookie_manager_get_blocking_manager;
cef_cookie_manager_create_manager_ptr cef_cookie_manager_create_manager;
cef_drag_data_create_ptr cef_drag_data_create;
cef_image_create_ptr cef_image_create;
cef_menu_model_create_ptr cef_menu_model_create;
@ -797,8 +788,6 @@ int libcef_init_pointers(const char* path) {
INIT_ENTRY(cef_command_line_create);
INIT_ENTRY(cef_command_line_get_global);
INIT_ENTRY(cef_cookie_manager_get_global_manager);
INIT_ENTRY(cef_cookie_manager_get_blocking_manager);
INIT_ENTRY(cef_cookie_manager_create_manager);
INIT_ENTRY(cef_drag_data_create);
INIT_ENTRY(cef_image_create);
INIT_ENTRY(cef_menu_model_create);
@ -1309,20 +1298,6 @@ struct _cef_cookie_manager_t* cef_cookie_manager_get_global_manager(
return g_libcef_pointers.cef_cookie_manager_get_global_manager(callback);
}
NO_SANITIZE("cfi-icall")
struct _cef_cookie_manager_t* cef_cookie_manager_get_blocking_manager() {
return g_libcef_pointers.cef_cookie_manager_get_blocking_manager();
}
NO_SANITIZE("cfi-icall")
struct _cef_cookie_manager_t* cef_cookie_manager_create_manager(
const cef_string_t* path,
int persist_session_cookies,
struct _cef_completion_callback_t* callback) {
return g_libcef_pointers.cef_cookie_manager_create_manager(
path, persist_session_cookies, callback);
}
NO_SANITIZE("cfi-icall") struct _cef_drag_data_t* cef_drag_data_create() {
return g_libcef_pointers.cef_drag_data_create();
}

View File

@ -22,14 +22,7 @@ namespace {
class ClientRequestContextHandler : public CefRequestContextHandler,
public CefExtensionHandler {
public:
ClientRequestContextHandler() {
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
if (command_line->HasSwitch(switches::kRequestContextBlockCookies)) {
// Use a cookie manager that neither stores nor retrieves cookies.
cookie_manager_ = CefCookieManager::GetBlockingManager();
}
}
ClientRequestContextHandler() {}
// CefRequestContextHandler methods:
bool OnBeforePluginLoad(const CefString& mime_type,
@ -80,10 +73,6 @@ class ClientRequestContextHandler : public CefRequestContextHandler,
}
}
CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE {
return cookie_manager_;
}
// CefExtensionHandler methods:
void OnExtensionLoaded(CefRefPtr<CefExtension> extension) OVERRIDE {
CEF_REQUIRE_UI_THREAD();
@ -110,8 +99,6 @@ class ClientRequestContextHandler : public CefRequestContextHandler,
}
private:
CefRefPtr<CefCookieManager> cookie_manager_;
IMPLEMENT_REFCOUNTING(ClientRequestContextHandler);
DISALLOW_COPY_AND_ASSIGN(ClientRequestContextHandler);
};

View File

@ -11,15 +11,12 @@
#include "include/cef_scheme.h"
#include "include/cef_waitable_event.h"
#include "include/wrapper/cef_closure_task.h"
#include "include/wrapper/cef_scoped_temp_dir.h"
#include "tests/ceftests/test_handler.h"
#include "tests/ceftests/test_suite.h"
#include "tests/gtest/include/gtest/gtest.h"
namespace {
const int kCacheDeleteDelay = 50;
const char* kTestUrl = "http://www.test.com/path/to/cookietest/foo.html";
const char* kTestDomain = "www.test.com";
const char* kTestPath = "/path/to/cookietest";
@ -465,63 +462,10 @@ void TestAllCookies(CefRefPtr<CefCookieManager> manager,
VerifyNoCookies(manager, event, false);
}
void TestChangeDirectory(CefRefPtr<CefCookieManager> manager,
CefRefPtr<CefWaitableEvent> event,
const CefString& original_dir) {
CefCookie cookie;
CefScopedTempDir temp_dir;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
// Delete all of the system cookies.
DeleteAllCookies(manager, event);
// Set the new temporary directory as the storage location.
EXPECT_TRUE(manager->SetStoragePath(temp_dir.GetPath(), false, NULL));
// Wait for the storage location change to complete on the IO thread.
WaitForIOThread();
// Verify that no cookies exist.
VerifyNoCookies(manager, event, true);
// Create a domain cookie.
CreateCookie(manager, cookie, true, false, event);
// Retrieve and verify the domain cookie.
GetCookie(manager, cookie, true, event, false);
// Restore the original storage location.
EXPECT_TRUE(manager->SetStoragePath(original_dir, false, NULL));
// Wait for the storage location change to complete on the IO thread.
WaitForIOThread();
// Verify that no cookies exist.
VerifyNoCookies(manager, event, true);
// Set the new temporary directory as the storage location.
EXPECT_TRUE(manager->SetStoragePath(temp_dir.GetPath(), false, NULL));
// Wait for the storage location change to complete on the IO thread.
WaitForIOThread();
// Retrieve and verify the domain cookie that was set previously.
GetCookie(manager, cookie, true, event, false);
// Restore the original storage location.
EXPECT_TRUE(manager->SetStoragePath(original_dir, false, NULL));
// Wait for the storage location change to complete on the IO thread.
WaitForIOThread();
}
} // namespace
// Test creation of a domain cookie.
TEST(CookieTest, DomainCookieGlobal) {
TEST(CookieTest, DomainCookie) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
@ -533,44 +477,8 @@ TEST(CookieTest, DomainCookieGlobal) {
TestDomainCookie(manager, event);
}
// Test creation of a domain cookie.
TEST(CookieTest, DomainCookieInMemory) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
CefString(), false, new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
TestDomainCookie(manager, event);
}
// Test creation of a domain cookie.
TEST(CookieTest, DomainCookieOnDisk) {
CefScopedTempDir temp_dir;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
temp_dir.GetPath(), false, new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
TestDomainCookie(manager, event);
// The backing store will be closed on the FILE thread after the CookieManager
// is destroyed.
manager = NULL;
WaitForFILEThreadWithDelay(kCacheDeleteDelay);
}
// Test creation of a host cookie.
TEST(CookieTest, HostCookieGlobal) {
TEST(CookieTest, HostCookie) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
@ -582,44 +490,8 @@ TEST(CookieTest, HostCookieGlobal) {
TestHostCookie(manager, event);
}
// Test creation of a host cookie.
TEST(CookieTest, HostCookieInMemory) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
CefString(), false, new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
TestHostCookie(manager, event);
}
// Test creation of a host cookie.
TEST(CookieTest, HostCookieOnDisk) {
CefScopedTempDir temp_dir;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
temp_dir.GetPath(), false, new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
TestHostCookie(manager, event);
// The backing store will be closed on the FILE thread after the CookieManager
// is destroyed.
manager = NULL;
WaitForFILEThreadWithDelay(kCacheDeleteDelay);
}
// Test creation of multiple cookies.
TEST(CookieTest, MultipleCookiesGlobal) {
TEST(CookieTest, MultipleCookies) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
@ -631,43 +503,7 @@ TEST(CookieTest, MultipleCookiesGlobal) {
TestMultipleCookies(manager, event);
}
// Test creation of multiple cookies.
TEST(CookieTest, MultipleCookiesInMemory) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
CefString(), false, new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
TestMultipleCookies(manager, event);
}
// Test creation of multiple cookies.
TEST(CookieTest, MultipleCookiesOnDisk) {
CefScopedTempDir temp_dir;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
temp_dir.GetPath(), false, new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
TestMultipleCookies(manager, event);
// The backing store will be closed on the FILE thread after the CookieManager
// is destroyed.
manager = NULL;
WaitForFILEThreadWithDelay(kCacheDeleteDelay);
}
TEST(CookieTest, AllCookiesGlobal) {
TEST(CookieTest, AllCookies) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
@ -679,135 +515,6 @@ TEST(CookieTest, AllCookiesGlobal) {
TestAllCookies(manager, event);
}
TEST(CookieTest, AllCookiesInMemory) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
CefString(), false, new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
TestAllCookies(manager, event);
}
TEST(CookieTest, AllCookiesOnDisk) {
CefScopedTempDir temp_dir;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
temp_dir.GetPath(), false, new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
TestAllCookies(manager, event);
// The backing store will be closed on the FILE thread after the CookieManager
// is destroyed.
manager = NULL;
WaitForFILEThreadWithDelay(kCacheDeleteDelay);
}
TEST(CookieTest, ChangeDirectoryGlobal) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefRefPtr<CefCookieManager> manager =
CefCookieManager::GetGlobalManager(new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
std::string cache_path;
CefTestSuite::GetInstance()->GetCachePath(cache_path);
TestChangeDirectory(manager, event, cache_path);
}
TEST(CookieTest, ChangeDirectoryCreated) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
CefString(), false, new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
TestChangeDirectory(manager, event, CefString());
}
TEST(CookieTest, SessionCookieNoPersist) {
CefScopedTempDir temp_dir;
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefCookie cookie;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
temp_dir.GetPath(), false, new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
// Create a session cookie.
CreateCookie(manager, cookie, true, true, event);
// Retrieve and verify the cookie.
GetCookie(manager, cookie, true, event, false);
// Flush the cookie store to disk.
manager->FlushStore(new TestCompletionCallback(event));
event->Wait();
// Create a new manager to read the same cookie store.
manager = CefCookieManager::CreateManager(temp_dir.GetPath(), false,
new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
// Verify that the cookie doesn't exist.
VerifyNoCookies(manager, event, true);
}
TEST(CookieTest, SessionCookieWillPersist) {
CefScopedTempDir temp_dir;
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefCookie cookie;
// Create a new temporary directory.
EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
temp_dir.GetPath(), true, new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
// Create a session cookie.
CreateCookie(manager, cookie, true, true, event);
// Retrieve and verify the cookie.
GetCookie(manager, cookie, true, event, false);
// Flush the cookie store to disk.
manager->FlushStore(new TestCompletionCallback(event));
event->Wait();
// Create a new manager to read the same cookie store.
manager = CefCookieManager::CreateManager(temp_dir.GetPath(), true,
new TestCompletionCallback(event));
event->Wait();
EXPECT_TRUE(manager.get());
// Verify that the cookie exists.
GetCookie(manager, cookie, true, event, false);
}
namespace {
const char* kCookieJSUrl1 = "http://tests/cookie1.html";
@ -815,44 +522,9 @@ const char* kCookieJSUrl2 = "http://tests/cookie2.html";
class CookieTestJSHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(CookieTestJSHandler* handler)
: handler_(handler) {}
CefRefPtr<CefCookieManager> GetCookieManager() override {
EXPECT_TRUE(handler_);
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
if (url_ == kCookieJSUrl1) {
// Return the first cookie manager.
handler_->got_cookie_manager1_.yes();
return handler_->manager1_;
} else {
// Return the second cookie manager.
handler_->got_cookie_manager2_.yes();
return handler_->manager2_;
}
}
void SetURL(const std::string& url) { url_ = url; }
void Detach() { handler_ = NULL; }
private:
std::string url_;
CookieTestJSHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
CookieTestJSHandler() {}
void RunTest() override {
// Create new in-memory managers.
manager1_ = CefCookieManager::CreateManager(CefString(), false, NULL);
manager2_ = CefCookieManager::CreateManager(CefString(), false, NULL);
std::string page =
"<html><head>"
"<script>"
@ -869,13 +541,11 @@ class CookieTestJSHandler : public TestHandler {
"</head><body>COOKIE TEST2</body></html>";
AddResource(kCookieJSUrl2, page, "text/html");
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(kCookieJSUrl1);
// Create the request context that will use an in-memory cache.
CefRequestContextSettings settings;
CefRefPtr<CefRequestContext> request_context =
CefRequestContext::CreateContext(settings, context_handler_.get());
CefRequestContext::CreateContext(settings, NULL);
manager_ = request_context->GetCookieManager(NULL);
// Create the browser.
CreateBrowser(kCookieJSUrl1, request_context);
@ -892,7 +562,6 @@ class CookieTestJSHandler : public TestHandler {
return;
}
context_handler_->SetURL(kCookieJSUrl2);
frame->LoadURL(kCookieJSUrl2);
}
@ -911,32 +580,26 @@ class CookieTestJSHandler : public TestHandler {
std::string url = frame->GetURL();
if (url == kCookieJSUrl1) {
got_load_end1_.yes();
VerifyCookie(manager1_, url, "name1", "value1", &got_cookie1_,
VerifyCookie(manager_, url, "name1", "value1", true, &got_cookie1_,
base::Bind(&CookieTestJSHandler::LoadNextURL, this, frame));
} else {
got_load_end2_.yes();
VerifyCookie(manager2_, url, "name2", "value2", &got_cookie2_,
VerifyCookie(manager_, url, "name2", "value2", true, &got_cookie2_,
base::Bind(&CookieTestJSHandler::CompleteTest, this));
}
}
void DestroyTest() override {
context_handler_->Detach();
context_handler_ = NULL;
TestHandler::DestroyTest();
}
// Verify that the cookie was set successfully.
void VerifyCookie(CefRefPtr<CefCookieManager> manager,
const std::string& url,
const std::string& name,
const std::string& value,
bool deleteCookie,
TrackCallback* callback,
const base::Closure& continue_callback) {
// Get the cookie.
EXPECT_TRUE(cookies_.empty());
VisitUrlCookies(manager, url, false, cookies_, false,
VisitUrlCookies(manager, url, false, cookies_, deleteCookie,
base::Bind(&CookieTestJSHandler::VerifyCookieComplete, this,
name, value, callback, continue_callback));
}
@ -954,15 +617,10 @@ class CookieTestJSHandler : public TestHandler {
continue_callback.Run();
}
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> manager1_;
CefRefPtr<CefCookieManager> manager2_;
CefRefPtr<CefCookieManager> manager_;
CookieVector cookies_;
TrackCallback got_cookie_manager1_;
TrackCallback got_cookie_manager2_;
TrackCallback got_load_end1_;
TrackCallback got_load_end2_;
TrackCallback got_cookie1_;
@ -978,8 +636,6 @@ TEST(CookieTest, GetCookieManagerJS) {
CefRefPtr<CookieTestJSHandler> handler = new CookieTestJSHandler();
handler->ExecuteTest();
EXPECT_TRUE(handler->got_cookie_manager1_);
EXPECT_TRUE(handler->got_cookie_manager2_);
EXPECT_TRUE(handler->got_load_end1_);
EXPECT_TRUE(handler->got_load_end2_);
EXPECT_TRUE(handler->got_cookie1_);
@ -990,6 +646,8 @@ TEST(CookieTest, GetCookieManagerJS) {
namespace {
const char kCustomCookieScheme[] = "ccustom";
class CookieTestSchemeHandler : public TestHandler {
public:
class SchemeHandler : public CefResourceHandler {
@ -1100,75 +758,62 @@ class CookieTestSchemeHandler : public TestHandler {
IMPLEMENT_REFCOUNTING(SchemeHandlerFactory);
};
class RequestContextHandler : public CefRequestContextHandler {
class CompletionCallback : public CefCompletionCallback {
public:
explicit RequestContextHandler(CookieTestSchemeHandler* handler)
: handler_(handler) {}
explicit CompletionCallback(const base::Closure& callback)
: callback_(callback) {}
CefRefPtr<CefCookieManager> GetCookieManager() override {
EXPECT_TRUE(handler_);
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
if (url_ == handler_->url1_) {
// Return the first cookie manager.
handler_->got_cookie_manager1_.yes();
return handler_->manager1_;
} else {
// Return the second cookie manager.
handler_->got_cookie_manager2_.yes();
return handler_->manager2_;
}
void OnComplete() override {
callback_.Run();
callback_.Reset();
}
void SetURL(const std::string& url) { url_ = url; }
void Detach() { handler_ = NULL; }
private:
std::string url_;
CookieTestSchemeHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
base::Closure callback_;
IMPLEMENT_REFCOUNTING(CompletionCallback);
};
CookieTestSchemeHandler(const std::string& scheme) : scheme_(scheme) {
CookieTestSchemeHandler(const std::string& scheme, bool use_global)
: scheme_(scheme), use_global_(use_global) {
url1_ = scheme + "://cookie-tests/cookie1.html";
url2_ = scheme + "://cookie-tests/cookie2.html";
url3_ = scheme + "://cookie-tests/cookie3.html";
}
void RunTest() override {
// Create new in-memory managers.
manager1_ = CefCookieManager::CreateManager(CefString(), false, NULL);
manager2_ = CefCookieManager::CreateManager(CefString(), false, NULL);
if (scheme_ != "http") {
std::vector<CefString> schemes;
schemes.push_back(scheme_);
manager1_->SetSupportedSchemes(schemes, NULL);
manager2_->SetSupportedSchemes(schemes, NULL);
if (use_global_) {
request_context_ = CefRequestContext::GetGlobalContext();
} else {
// Create the request context that will use an in-memory cache.
CefRequestContextSettings settings;
request_context_ = CefRequestContext::CreateContext(settings, NULL);
}
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(url1_);
// Create the request context that will use an in-memory cache.
CefRequestContextSettings settings;
CefRefPtr<CefRequestContext> request_context =
CefRequestContext::CreateContext(settings, context_handler_.get());
// Register the scheme handler.
request_context->RegisterSchemeHandlerFactory(
request_context_->RegisterSchemeHandlerFactory(
scheme_, "cookie-tests", new SchemeHandlerFactory(this));
manager_ = request_context_->GetCookieManager(NULL);
if (!use_global_) {
std::vector<CefString> schemes;
schemes.push_back(kCustomCookieScheme);
// Create the browser.
CreateBrowser(url1_, request_context);
// Need to wait for completion before creating the browser.
manager_->SetSupportedSchemes(
schemes, new CompletionCallback(base::Bind(
&CookieTestSchemeHandler::CreateBrowserContinue, this)));
} else {
CreateBrowserContinue();
}
// Time out the test after a reasonable period of time.
SetTestTimeout();
}
void CreateBrowserContinue() {
// Create the browser.
CreateBrowser(url1_, request_context_);
}
// Go to the next URL.
void LoadNextURL(CefRefPtr<CefFrame> frame, const std::string& url) {
if (!CefCurrentlyOn(TID_UI)) {
@ -1177,7 +822,6 @@ class CookieTestSchemeHandler : public TestHandler {
return;
}
context_handler_->SetURL(url);
frame->LoadURL(url);
}
@ -1201,25 +845,39 @@ class CookieTestSchemeHandler : public TestHandler {
std::string url = frame->GetURL();
if (url == url1_) {
got_load_end1_.yes();
VerifyCookie(manager1_, url, "name1", "value1", &got_cookie1_,
VerifyCookie(manager_, url, "name1", "value1", true, &got_cookie1_,
base::Bind(&CookieTestSchemeHandler::LoadNextURL, this,
frame, url2_));
} else if (url == url2_) {
got_load_end2_.yes();
VerifyCookie(manager2_, url, "name2", "value2", &got_cookie2_,
VerifyCookie(manager_, url, "name2", "value2", false, &got_cookie2_,
base::Bind(&CookieTestSchemeHandler::LoadNextURL, this,
frame, url3_));
} else {
got_load_end3_.yes();
VerifyCookie(
manager2_, url, "name2", "value2", &got_cookie3_,
manager_, url, "name2", "value2", true, &got_cookie3_,
base::Bind(&CookieTestSchemeHandler::CompleteTest, this, browser));
}
}
void DestroyTest() override {
context_handler_->Detach();
context_handler_ = NULL;
EXPECT_TRUE(got_process_request1_);
EXPECT_TRUE(got_process_request2_);
EXPECT_TRUE(got_process_request3_);
EXPECT_FALSE(got_create_cookie_);
EXPECT_TRUE(got_process_request_cookie_);
EXPECT_TRUE(got_load_end1_);
EXPECT_TRUE(got_load_end2_);
EXPECT_TRUE(got_load_end3_);
EXPECT_TRUE(got_cookie1_);
EXPECT_TRUE(got_cookie2_);
EXPECT_TRUE(got_cookie3_);
// Unregister the scheme handler.
request_context_->RegisterSchemeHandlerFactory(scheme_, "cookie-tests",
NULL);
request_context_ = NULL;
TestHandler::DestroyTest();
}
@ -1229,11 +887,12 @@ class CookieTestSchemeHandler : public TestHandler {
const std::string& url,
const std::string& name,
const std::string& value,
bool deleteCookie,
TrackCallback* callback,
const base::Closure& continue_callback) {
// Get the cookie.
EXPECT_TRUE(cookies_.empty());
VisitUrlCookies(manager, url, false, cookies_, false,
VisitUrlCookies(manager, url, false, cookies_, deleteCookie,
base::Bind(&CookieTestSchemeHandler::VerifyCookieComplete,
this, name, value, callback, continue_callback));
}
@ -1251,15 +910,14 @@ class CookieTestSchemeHandler : public TestHandler {
continue_callback.Run();
}
std::string scheme_;
const std::string scheme_;
const bool use_global_;
std::string url1_;
std::string url2_;
std::string url3_;
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> manager1_;
CefRefPtr<CefCookieManager> manager2_;
CefRefPtr<CefRequestContext> request_context_;
CefRefPtr<CefCookieManager> manager_;
CookieVector cookies_;
@ -1268,8 +926,6 @@ class CookieTestSchemeHandler : public TestHandler {
TrackCallback got_process_request3_;
TrackCallback got_create_cookie_;
TrackCallback got_process_request_cookie_;
TrackCallback got_cookie_manager1_;
TrackCallback got_cookie_manager2_;
TrackCallback got_load_end1_;
TrackCallback got_load_end2_;
TrackCallback got_load_end3_;
@ -1282,49 +938,35 @@ class CookieTestSchemeHandler : public TestHandler {
} // namespace
// Verify use of multiple cookie managers via HTTP.
TEST(CookieTest, GetCookieManagerHttp) {
// Verify use of the global cookie manager with HTTP.
TEST(CookieTest, GetCookieManagerHttpGlobal) {
CefRefPtr<CookieTestSchemeHandler> handler =
new CookieTestSchemeHandler("http");
new CookieTestSchemeHandler("http", true);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_process_request1_);
EXPECT_TRUE(handler->got_process_request2_);
EXPECT_TRUE(handler->got_process_request3_);
EXPECT_FALSE(handler->got_create_cookie_);
EXPECT_TRUE(handler->got_process_request_cookie_);
EXPECT_TRUE(handler->got_cookie_manager1_);
EXPECT_TRUE(handler->got_cookie_manager2_);
EXPECT_TRUE(handler->got_load_end1_);
EXPECT_TRUE(handler->got_load_end2_);
EXPECT_TRUE(handler->got_load_end3_);
EXPECT_TRUE(handler->got_cookie1_);
EXPECT_TRUE(handler->got_cookie2_);
EXPECT_TRUE(handler->got_cookie3_);
ReleaseAndWaitForDestructor(handler);
}
// Verify use of multiple cookie managers via a custom scheme.
TEST(CookieTest, GetCookieManagerCustom) {
// Verify use of an in-memory cookie manager with HTTP.
TEST(CookieTest, GetCookieManagerHttpInMemory) {
CefRefPtr<CookieTestSchemeHandler> handler =
new CookieTestSchemeHandler("ccustom");
new CookieTestSchemeHandler("http", false);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
EXPECT_TRUE(handler->got_process_request1_);
EXPECT_TRUE(handler->got_process_request2_);
EXPECT_TRUE(handler->got_process_request3_);
EXPECT_FALSE(handler->got_create_cookie_);
EXPECT_TRUE(handler->got_process_request_cookie_);
EXPECT_TRUE(handler->got_cookie_manager1_);
EXPECT_TRUE(handler->got_cookie_manager2_);
EXPECT_TRUE(handler->got_load_end1_);
EXPECT_TRUE(handler->got_load_end2_);
EXPECT_TRUE(handler->got_load_end3_);
EXPECT_TRUE(handler->got_cookie1_);
EXPECT_TRUE(handler->got_cookie2_);
EXPECT_TRUE(handler->got_cookie3_);
// Verify use of the global cookie manager with a custom scheme.
TEST(CookieTest, GetCookieManagerCustomGlobal) {
CefRefPtr<CookieTestSchemeHandler> handler =
new CookieTestSchemeHandler(kCustomCookieScheme, true);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
// Verify use of an in-memory cookie manager with a custom scheme.
TEST(CookieTest, GetCookieManagerCustomInMemory) {
CefRefPtr<CookieTestSchemeHandler> handler =
new CookieTestSchemeHandler(kCustomCookieScheme, false);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
@ -1332,7 +974,9 @@ TEST(CookieTest, GetCookieManagerCustom) {
// Called from client_app_delegates.cc.
void RegisterCookieCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar,
std::vector<CefString>& cookiable_schemes) {
// Used by GetCookieManagerCustom test.
// Used by GetCookieManagerCustom* tests.
registrar->AddCustomScheme(
"ccustom", CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_CORS_ENABLED);
kCustomCookieScheme,
CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_CORS_ENABLED);
cookiable_schemes.push_back(kCustomCookieScheme);
}

View File

@ -180,11 +180,7 @@ void ExtensionTestHandler::VerifyExtensionInContext(
EXPECT_FALSE(extension_id.empty());
if (has_access) {
if (is_loader) {
EXPECT_TRUE(context->DidLoadExtension(extension_id));
} else {
EXPECT_FALSE(context->DidLoadExtension(extension_id));
}
EXPECT_TRUE(context->DidLoadExtension(extension_id));
EXPECT_TRUE(context->HasExtension(extension_id));
} else {
EXPECT_FALSE(context->DidLoadExtension(extension_id));

View File

@ -34,7 +34,6 @@ TEST(RequestContextTest, CreateContext) {
class Handler : public CefRequestContextHandler {
public:
Handler() {}
CefRefPtr<CefCookieManager> GetCookieManager() override { return NULL; }
private:
IMPLEMENT_REFCOUNTING(Handler);
@ -197,157 +196,8 @@ TEST(RequestContextTest, CreateContextSharedOnDisk) {
namespace {
class CookieTestHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(CookieTestHandler* handler)
: handler_(handler) {}
CefRefPtr<CefCookieManager> GetCookieManager() override {
EXPECT_TRUE(handler_);
handler_->got_get_cookie_manager_.yes();
return handler_->cookie_manager_;
}
void Detach() { handler_ = NULL; }
private:
CookieTestHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
CookieTestHandler(const std::string& url) : url_(url) {}
void RunTest() override {
AddResource(url_,
"<html>"
"<head><script>document.cookie='name1=value1';</script></head>"
"<body>Nav1</body>"
"</html>",
"text/html");
CefRequestContextSettings settings;
context_handler_ = new RequestContextHandler(this);
context_ =
CefRequestContext::CreateContext(settings, context_handler_.get());
cookie_manager_ = CefCookieManager::CreateManager(CefString(), true, NULL);
// Create browser that loads the 1st URL.
CreateBrowser(url_, context_);
// Time out the test after a reasonable period of time.
SetTestTimeout();
}
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) override {
CefRefPtr<CefRequestContext> context =
browser->GetHost()->GetRequestContext();
EXPECT_TRUE(context.get());
EXPECT_TRUE(context->IsSame(context_));
EXPECT_FALSE(context->IsGlobal());
EXPECT_EQ(context->GetHandler().get(), context_handler_.get());
FinishTest();
}
protected:
void FinishTest() {
// Verify that the cookie was set correctly.
class TestVisitor : public CefCookieVisitor {
public:
explicit TestVisitor(CookieTestHandler* handler) : handler_(handler) {}
~TestVisitor() override {
// Destroy the test.
CefPostTask(TID_UI,
base::Bind(&CookieTestHandler::DestroyTest, handler_));
}
bool Visit(const CefCookie& cookie,
int count,
int total,
bool& deleteCookie) override {
const std::string& name = CefString(&cookie.name);
const std::string& value = CefString(&cookie.value);
if (name == "name1" && value == "value1")
handler_->got_cookie_.yes();
return true;
}
private:
CookieTestHandler* handler_;
IMPLEMENT_REFCOUNTING(TestVisitor);
};
cookie_manager_->VisitAllCookies(new TestVisitor(this));
}
void DestroyTest() override {
// Verify test expectations.
EXPECT_TRUE(got_get_cookie_manager_);
EXPECT_TRUE(got_cookie_);
context_handler_->Detach();
context_handler_ = NULL;
context_ = NULL;
TestHandler::DestroyTest();
}
std::string url_;
CefRefPtr<CefRequestContext> context_;
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> cookie_manager_;
TrackCallback got_get_cookie_manager_;
TrackCallback got_cookie_;
IMPLEMENT_REFCOUNTING(CookieTestHandler);
};
} // namespace
// Test that the cookie manager is retrieved via the associated request context.
TEST(RequestContextTest, GetCookieManager) {
CefRefPtr<CookieTestHandler> handler =
new CookieTestHandler("http://tests-simple-rch.com/nav1.html");
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
namespace {
class PopupTestHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(PopupTestHandler* handler)
: handler_(handler) {}
CefRefPtr<CefCookieManager> GetCookieManager() override {
EXPECT_TRUE(handler_);
if (url_ == handler_->url_)
handler_->got_get_cookie_manager1_.yes();
else if (url_ == handler_->popup_url_)
handler_->got_get_cookie_manager2_.yes();
return handler_->cookie_manager_;
}
void SetURL(const std::string& url) { url_ = url; }
void Detach() { handler_ = NULL; }
private:
PopupTestHandler* handler_;
std::string url_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
enum Mode {
MODE_WINDOW_OPEN,
MODE_TARGETED_LINK,
@ -394,11 +244,8 @@ class PopupTestHandler : public TestHandler {
CefRequestContextSettings settings;
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(url_);
context_ =
CefRequestContext::CreateContext(settings, context_handler_.get());
cookie_manager_ = CefCookieManager::CreateManager(CefString(), true, NULL);
context_ = CefRequestContext::CreateContext(settings, NULL);
cookie_manager_ = context_->GetCookieManager(NULL);
// Create browser that loads the 1st URL.
CreateBrowser(url_, context_);
@ -421,7 +268,6 @@ class PopupTestHandler : public TestHandler {
const std::string& url = frame->GetURL();
if (url == url_) {
got_load_end1_.yes();
context_handler_->SetURL(popup_url_);
LaunchPopup(browser);
} else if (url == popup_url_) {
got_load_end2_.yes();
@ -497,10 +343,13 @@ class PopupTestHandler : public TestHandler {
bool& deleteCookie) override {
const std::string& name = CefString(&cookie.name);
const std::string& value = CefString(&cookie.value);
if (name == "name1" && value == "value1")
if (name == "name1" && value == "value1") {
handler_->got_cookie1_.yes();
else if (name == "name2" && value == "value2")
deleteCookie = true;
} else if (name == "name2" && value == "value2") {
handler_->got_cookie2_.yes();
deleteCookie = true;
}
return true;
}
@ -514,16 +363,11 @@ class PopupTestHandler : public TestHandler {
void DestroyTest() override {
// Verify test expectations.
EXPECT_TRUE(got_get_cookie_manager1_);
EXPECT_TRUE(got_load_end1_);
EXPECT_TRUE(got_on_before_popup_);
EXPECT_TRUE(got_get_cookie_manager2_);
EXPECT_TRUE(got_load_end2_);
EXPECT_TRUE(got_cookie1_);
EXPECT_TRUE(got_cookie2_);
context_handler_->Detach();
context_handler_ = NULL;
context_ = NULL;
TestHandler::DestroyTest();
@ -534,13 +378,10 @@ class PopupTestHandler : public TestHandler {
Mode mode_;
CefRefPtr<CefRequestContext> context_;
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> cookie_manager_;
TrackCallback got_get_cookie_manager1_;
TrackCallback got_load_end1_;
TrackCallback got_on_before_popup_;
TrackCallback got_get_cookie_manager2_;
TrackCallback got_load_end2_;
TrackCallback got_cookie1_;
TrackCallback got_cookie2_;

View File

@ -60,36 +60,6 @@ class NetNotifyBrowserTest : public ClientAppBrowser::Delegate {
// Browser side.
class NetNotifyTestHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(NetNotifyTestHandler* handler)
: handler_(handler) {}
CefRefPtr<CefCookieManager> GetCookieManager() override {
EXPECT_TRUE(handler_);
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
if (url_.find(handler_->url1_) == 0)
handler_->got_get_cookie_manager1_.yes();
else if (url_.find(handler_->url2_) == 0)
handler_->got_get_cookie_manager2_.yes();
else
EXPECT_TRUE(false); // Not reached
return handler_->cookie_manager_;
}
void SetURL(const std::string& url) { url_ = url; }
void Detach() { handler_ = NULL; }
private:
std::string url_;
NetNotifyTestHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
NetNotifyTestHandler(CompletionState* completion_state,
NetNotifyTestType test_type,
bool same_origin)
@ -106,8 +76,6 @@ class NetNotifyTestHandler : public TestHandler {
<< "nav2.html?t=" << test_type_;
url2_ = ss.str();
cookie_manager_ = CefCookieManager::CreateManager(CefString(), true, NULL);
const std::string& resource1 =
"<html>"
"<head><script>document.cookie='name1=value1';</script></head>"
@ -124,13 +92,11 @@ class NetNotifyTestHandler : public TestHandler {
response_length2_ = static_cast<int64>(resource2.size());
AddResource(url2_, resource2, "text/html");
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(url1_);
// Create the request context that will use an in-memory cache.
CefRequestContextSettings settings;
CefRefPtr<CefRequestContext> request_context =
CefRequestContext::CreateContext(settings, context_handler_.get());
CefRequestContext::CreateContext(settings, NULL);
cookie_manager_ = request_context->GetCookieManager(NULL);
// Create browser that loads the 1st URL.
CreateBrowser(url1_, request_context);
@ -138,7 +104,6 @@ class NetNotifyTestHandler : public TestHandler {
void RunTest() override {
// Navigate to the 2nd URL.
context_handler_->SetURL(url2_);
GetBrowser()->GetMainFrame()->LoadURL(url2_);
// Time out the test after a reasonable period of time.
@ -320,10 +285,13 @@ class NetNotifyTestHandler : public TestHandler {
bool& deleteCookie) override {
const std::string& name = CefString(&cookie.name);
const std::string& value = CefString(&cookie.value);
if (name == "name1" && value == "value1")
if (name == "name1" && value == "value1") {
handler_->got_cookie1_.yes();
else if (name == "name2" && value == "value2")
deleteCookie = true;
} else if (name == "name2" && value == "value2") {
handler_->got_cookie2_.yes();
deleteCookie = true;
}
return true;
}
@ -344,7 +312,6 @@ class NetNotifyTestHandler : public TestHandler {
EXPECT_TRUE(got_before_resource_load1_) << " browser " << browser_id;
EXPECT_TRUE(got_get_resource_handler1_) << " browser " << browser_id;
EXPECT_TRUE(got_resource_load_complete1_) << " browser " << browser_id;
EXPECT_TRUE(got_get_cookie_manager1_) << " browser " << browser_id;
EXPECT_TRUE(got_cookie1_) << " browser " << browser_id;
EXPECT_TRUE(got_process_message1_) << " browser " << browser_id;
EXPECT_TRUE(got_before_browse2_) << " browser " << browser_id;
@ -352,7 +319,6 @@ class NetNotifyTestHandler : public TestHandler {
EXPECT_TRUE(got_before_resource_load2_) << " browser " << browser_id;
EXPECT_TRUE(got_get_resource_handler2_) << " browser " << browser_id;
EXPECT_TRUE(got_resource_load_complete2_) << " browser " << browser_id;
EXPECT_TRUE(got_get_cookie_manager2_) << " browser " << browser_id;
EXPECT_TRUE(got_cookie2_) << " browser " << browser_id;
EXPECT_TRUE(got_process_message2_) << " browser " << browser_id;
@ -365,8 +331,6 @@ class NetNotifyTestHandler : public TestHandler {
EXPECT_FALSE(got_before_browse2_delayed_) << " browser " << browser_id;
}
context_handler_->Detach();
context_handler_ = NULL;
cookie_manager_ = NULL;
TestHandler::DestroyTest();
@ -377,8 +341,6 @@ class NetNotifyTestHandler : public TestHandler {
std::string url1_;
std::string url2_;
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> cookie_manager_;
TrackCallback got_before_browse1_;
@ -386,7 +348,6 @@ class NetNotifyTestHandler : public TestHandler {
TrackCallback got_before_resource_load1_;
TrackCallback got_get_resource_handler1_;
TrackCallback got_resource_load_complete1_;
TrackCallback got_get_cookie_manager1_;
TrackCallback got_cookie1_;
TrackCallback got_process_message1_;
TrackCallback got_before_browse2_;
@ -394,7 +355,6 @@ class NetNotifyTestHandler : public TestHandler {
TrackCallback got_before_resource_load2_;
TrackCallback got_get_resource_handler2_;
TrackCallback got_resource_load_complete2_;
TrackCallback got_get_cookie_manager2_;
TrackCallback got_cookie2_;
TrackCallback got_process_message2_;
TrackCallback got_before_browse2_will_delay_;
@ -2183,45 +2143,13 @@ class CookieAccessTestHandler : public RoutingTestHandler {
BLOCK_READ = 1 << 0,
BLOCK_WRITE = 1 << 1,
BLOCK_READ_WRITE = BLOCK_READ | BLOCK_WRITE,
BLOCK_ALL = 1 << 2,
};
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(CookieAccessTestHandler* handler)
: handler_(handler) {}
CefRefPtr<CefCookieManager> GetCookieManager() override {
EXPECT_TRUE(handler_);
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
handler_->got_cookie_manager_.yes();
return handler_->cookie_manager_;
}
void Detach() { handler_ = NULL; }
private:
CookieAccessTestHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
CookieAccessTestHandler(TestMode test_mode, bool server_backend)
: test_mode_(test_mode), server_backend_(server_backend) {}
void RunTest() override {
if (test_mode_ == BLOCK_ALL) {
cookie_manager_ = CefCookieManager::GetBlockingManager();
context_handler_ = new RequestContextHandler(this);
// Create a request context that uses |context_handler_|.
CefRequestContextSettings settings;
context_ =
CefRequestContext::CreateContext(settings, context_handler_.get());
} else {
cookie_manager_ = CefCookieManager::GetGlobalManager(nullptr);
}
cookie_manager_ = CefCookieManager::GetGlobalManager(nullptr);
SetTestTimeout();
CefPostTask(TID_UI,
@ -2240,128 +2168,90 @@ class CookieAccessTestHandler : public RoutingTestHandler {
cookie_manager_ = NULL;
if (context_)
context_ = NULL;
if (context_handler_) {
context_handler_->Detach();
context_handler_ = NULL;
}
// Got both network requests.
EXPECT_TRUE(data1_.got_request_);
EXPECT_TRUE(data2_.got_request_);
if (test_mode_ == BLOCK_ALL) {
EXPECT_TRUE(got_cookie_manager_);
EXPECT_FALSE(got_cookie_manager_);
// The callback to set the cookie comes before the actual storage fails.
EXPECT_TRUE(got_can_set_cookie1_);
// Always get a call to CanSetCookie for the 1st network request due to
// the network cookie.
EXPECT_TRUE(got_can_set_cookie1_);
// Always get a call to CanGetCookies for the 2nd network request due to
// the JS cookie.
EXPECT_TRUE(got_can_get_cookies2_);
if (!server_backend_) {
// The callback to set the cookie comes before the actual storage fails.
EXPECT_TRUE(data1_.got_can_set_cookie_net_);
} else {
EXPECT_FALSE(data1_.got_can_set_cookie_net_);
}
// Always get the JS cookie via JS.
EXPECT_TRUE(got_cookie_js1_);
EXPECT_TRUE(got_cookie_js2_);
EXPECT_TRUE(got_cookie_js3_);
// No cookies stored anywhere.
EXPECT_FALSE(got_can_get_cookies2_);
EXPECT_FALSE(got_cookie_js1_);
EXPECT_FALSE(got_cookie_js2_);
EXPECT_FALSE(got_cookie_js3_);
// Only get the net cookie via JS if cookie write was allowed.
if (test_mode_ & BLOCK_WRITE) {
EXPECT_FALSE(got_cookie_net1_);
EXPECT_FALSE(got_cookie_net2_);
EXPECT_FALSE(got_cookie_net3_);
EXPECT_FALSE(data1_.got_cookie_js_);
EXPECT_FALSE(data1_.got_cookie_net_);
EXPECT_FALSE(data1_.got_can_get_cookie_js_);
EXPECT_FALSE(data1_.got_can_get_cookie_net_);
EXPECT_FALSE(data1_.got_can_set_cookie_js_);
} else {
EXPECT_TRUE(got_cookie_net1_);
EXPECT_TRUE(got_cookie_net2_);
EXPECT_TRUE(got_cookie_net3_);
}
// No cookies sent for the 1st network request.
EXPECT_FALSE(data1_.got_cookie_js_);
EXPECT_FALSE(data1_.got_cookie_net_);
// 2nd network request...
if (test_mode_ & BLOCK_READ) {
// No cookies sent if reading was blocked.
EXPECT_FALSE(data2_.got_cookie_js_);
EXPECT_FALSE(data2_.got_cookie_net_);
EXPECT_FALSE(data2_.got_can_get_cookie_js_);
EXPECT_FALSE(data2_.got_can_get_cookie_net_);
EXPECT_FALSE(data2_.got_can_set_cookie_js_);
EXPECT_FALSE(data2_.got_can_set_cookie_net_);
} else if (test_mode_ & BLOCK_WRITE) {
// Only JS cookie sent if writing was blocked.
EXPECT_TRUE(data2_.got_cookie_js_);
EXPECT_FALSE(data2_.got_cookie_net_);
} else {
EXPECT_FALSE(got_cookie_manager_);
// All cookies sent.
EXPECT_TRUE(data2_.got_cookie_js_);
EXPECT_TRUE(data2_.got_cookie_net_);
}
// Always get a call to CanSetCookie for the 1st network request due to
// the network cookie.
EXPECT_TRUE(got_can_set_cookie1_);
// Always get a call to CanGetCookies for the 2nd network request due to
// the JS cookie.
EXPECT_TRUE(got_can_get_cookies2_);
if (!server_backend_) {
// No query to get cookies with the 1st network request because none
// have been set yet.
EXPECT_FALSE(data1_.got_can_get_cookie_js_);
EXPECT_FALSE(data1_.got_can_get_cookie_net_);
// Always get the JS cookie via JS.
EXPECT_TRUE(got_cookie_js1_);
EXPECT_TRUE(got_cookie_js2_);
EXPECT_TRUE(got_cookie_js3_);
// JS cookie is not set via a network request.
EXPECT_FALSE(data1_.got_can_set_cookie_js_);
EXPECT_FALSE(data2_.got_can_set_cookie_js_);
// Only get the net cookie via JS if cookie write was allowed.
// No query to set the net cookie for the 1st network request if write
// was blocked.
if (test_mode_ & BLOCK_WRITE) {
EXPECT_FALSE(got_cookie_net1_);
EXPECT_FALSE(got_cookie_net2_);
EXPECT_FALSE(got_cookie_net3_);
EXPECT_FALSE(data1_.got_can_set_cookie_net_);
} else {
EXPECT_TRUE(got_cookie_net1_);
EXPECT_TRUE(got_cookie_net2_);
EXPECT_TRUE(got_cookie_net3_);
EXPECT_TRUE(data1_.got_can_set_cookie_net_);
}
// No cookies sent for the 1st network request.
EXPECT_FALSE(data1_.got_cookie_js_);
EXPECT_FALSE(data1_.got_cookie_net_);
// Net cookie is not set via the 2nd network request.
EXPECT_FALSE(data2_.got_can_set_cookie_net_);
// 2nd network request...
// No query to get the JS cookie for the 2nd network request if read was
// blocked.
if (test_mode_ & BLOCK_READ) {
// No cookies sent if reading was blocked.
EXPECT_FALSE(data2_.got_cookie_js_);
EXPECT_FALSE(data2_.got_cookie_net_);
} else if (test_mode_ & BLOCK_WRITE) {
// Only JS cookie sent if writing was blocked.
EXPECT_TRUE(data2_.got_cookie_js_);
EXPECT_FALSE(data2_.got_cookie_net_);
EXPECT_FALSE(data2_.got_can_get_cookie_js_);
} else {
// All cookies sent.
EXPECT_TRUE(data2_.got_cookie_js_);
EXPECT_TRUE(data2_.got_cookie_net_);
EXPECT_TRUE(data2_.got_can_get_cookie_js_);
}
if (!server_backend_) {
// No query to get cookies with the 1st network request because none
// have been set yet.
EXPECT_FALSE(data1_.got_can_get_cookie_js_);
EXPECT_FALSE(data1_.got_can_get_cookie_net_);
// JS cookie is not set via a network request.
EXPECT_FALSE(data1_.got_can_set_cookie_js_);
EXPECT_FALSE(data2_.got_can_set_cookie_js_);
// No query to set the net cookie for the 1st network request if write
// was blocked.
if (test_mode_ & BLOCK_WRITE) {
EXPECT_FALSE(data1_.got_can_set_cookie_net_);
} else {
EXPECT_TRUE(data1_.got_can_set_cookie_net_);
}
// Net cookie is not set via the 2nd network request.
EXPECT_FALSE(data2_.got_can_set_cookie_net_);
// No query to get the JS cookie for the 2nd network request if read was
// blocked.
if (test_mode_ & BLOCK_READ) {
EXPECT_FALSE(data2_.got_can_get_cookie_js_);
} else {
EXPECT_TRUE(data2_.got_can_get_cookie_js_);
}
// No query to get the net cookie for the 2nd network request if read or
// write (of the net cookie) was blocked.
if (test_mode_ & (BLOCK_READ | BLOCK_WRITE)) {
EXPECT_FALSE(data2_.got_can_get_cookie_net_);
} else {
EXPECT_TRUE(data2_.got_can_get_cookie_net_);
}
// No query to get the net cookie for the 2nd network request if read or
// write (of the net cookie) was blocked.
if (test_mode_ & (BLOCK_READ | BLOCK_WRITE)) {
EXPECT_FALSE(data2_.got_can_get_cookie_net_);
} else {
EXPECT_TRUE(data2_.got_can_get_cookie_net_);
}
}
@ -2581,7 +2471,6 @@ class CookieAccessTestHandler : public RoutingTestHandler {
TestMode test_mode_;
bool server_backend_;
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefRequestContext> context_;
CefRefPtr<CefCookieManager> cookie_manager_;
@ -2645,14 +2534,6 @@ TEST(RequestHandlerTest, CookieAccessServerBlockReadWrite) {
ReleaseAndWaitForDestructor(handler);
}
// Block all cookies with server backend.
TEST(RequestHandlerTest, CookieAccessServerBlockAll) {
CefRefPtr<CookieAccessTestHandler> handler =
new CookieAccessTestHandler(CookieAccessTestHandler::BLOCK_ALL, true);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
// Allow reading and writing of cookies with scheme handler backend.
TEST(RequestHandlerTest, CookieAccessSchemeAllow) {
CefRefPtr<CookieAccessTestHandler> handler =
@ -2685,14 +2566,6 @@ TEST(RequestHandlerTest, CookieAccessSchemeBlockReadWrite) {
ReleaseAndWaitForDestructor(handler);
}
// Block all cookies with scheme handler backend.
TEST(RequestHandlerTest, CookieAccessSchemeBlockAll) {
CefRefPtr<CookieAccessTestHandler> handler =
new CookieAccessTestHandler(CookieAccessTestHandler::BLOCK_ALL, false);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
// Entry point for creating request handler browser test objects.
// Called from client_app_delegates.cc.
void CreateRequestHandlerBrowserTests(

View File

@ -343,7 +343,7 @@ void SetTestCookie(CefRefPtr<CefRequestContext> request_context,
CefString(&cookie.domain) = GetRequestHost(server_backend, false);
CefString(&cookie.path) = "/";
cookie.has_expires = false;
EXPECT_TRUE(request_context->GetDefaultCookieManager(NULL)->SetCookie(
EXPECT_TRUE(request_context->GetCookieManager(NULL)->SetCookie(
GetRequestOrigin(server_backend), cookie, new Callback(callback)));
}
@ -383,7 +383,7 @@ void GetTestCookie(CefRefPtr<CefRequestContext> request_context,
};
CefRefPtr<CefCookieManager> cookie_manager =
request_context->GetDefaultCookieManager(NULL);
request_context->GetCookieManager(NULL);
cookie_manager->VisitUrlCookies(GetRequestOrigin(server_backend), true,
new Visitor(callback));
}
@ -2183,7 +2183,7 @@ class RequestTestHandler : public TestHandler {
supported_schemes.push_back(GetRequestScheme(false));
// Continue the test once supported schemes has been set.
request_context->GetDefaultCookieManager(NULL)->SetSupportedSchemes(
request_context->GetCookieManager(NULL)->SetSupportedSchemes(
supported_schemes,
new SupportedSchemesCompletionCallback(
base::Bind(&RequestTestHandler::PreSetupComplete, this)));

View File

@ -30,7 +30,6 @@ const char kExternalBeginFrameEnabled[] = "external-begin-frame-enabled";
const char kMouseCursorChangeDisabled[] = "mouse-cursor-change-disabled";
const char kRequestContextPerBrowser[] = "request-context-per-browser";
const char kRequestContextSharedCache[] = "request-context-shared-cache";
const char kRequestContextBlockCookies[] = "request-context-block-cookies";
const char kBackgroundColor[] = "background-color";
const char kEnableGPU[] = "enable-gpu";
const char kFilterURL[] = "filter-url";

View File

@ -24,7 +24,6 @@ extern const char kExternalBeginFrameEnabled[];
extern const char kMouseCursorChangeDisabled[];
extern const char kRequestContextPerBrowser[];
extern const char kRequestContextSharedCache[];
extern const char kRequestContextBlockCookies[];
extern const char kBackgroundColor[];
extern const char kEnableGPU[];
extern const char kFilterURL[];