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

@ -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.