Add CefCookieManager::GetBlockingManager (issue #2374)
This commit is contained in:
parent
a98c6b1f52
commit
e030236c36
|
@ -33,7 +33,7 @@
|
|||
// by hand. See the translator.README.txt file in the tools directory for
|
||||
// more information.
|
||||
//
|
||||
// $hash=e0605a0c9918e225b9282b6d5e6138a7d697945b$
|
||||
// $hash=00e6d1aa80d5998d89cc272dcb199cde0add12fa$
|
||||
//
|
||||
|
||||
#ifndef CEF_INCLUDE_CAPI_CEF_COOKIE_CAPI_H_
|
||||
|
@ -159,6 +159,16 @@ typedef struct _cef_cookie_manager_t {
|
|||
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
|
||||
|
|
|
@ -64,6 +64,17 @@ 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
|
||||
|
|
|
@ -120,7 +120,8 @@ net::CookieStore* GetExistingCookieStoreHelper(
|
|||
|
||||
} // namespace
|
||||
|
||||
CefCookieManagerImpl::CefCookieManagerImpl() : weak_ptr_factory_(this) {}
|
||||
CefCookieManagerImpl::CefCookieManagerImpl(bool is_blocking)
|
||||
: is_blocking_(is_blocking), weak_ptr_factory_(this) {}
|
||||
|
||||
CefCookieManagerImpl::~CefCookieManagerImpl() {
|
||||
CEF_REQUIRE_IOT();
|
||||
|
@ -131,6 +132,7 @@ void CefCookieManagerImpl::Initialize(
|
|||
const CefString& path,
|
||||
bool persist_session_cookies,
|
||||
CefRefPtr<CefCompletionCallback> callback) {
|
||||
CHECK(!is_blocking_);
|
||||
if (request_context.get()) {
|
||||
request_context_ = request_context;
|
||||
request_context_->GetRequestContextImpl(
|
||||
|
@ -160,7 +162,7 @@ void CefCookieManagerImpl::GetCookieStore(
|
|||
return;
|
||||
}
|
||||
|
||||
DCHECK(cookie_store_.get());
|
||||
DCHECK(is_blocking_ || cookie_store_.get());
|
||||
|
||||
// Binding ref-counted |this| to CookieStoreGetter may result in
|
||||
// heap-use-after-free if (a) the CookieStoreGetter contains the last
|
||||
|
@ -192,7 +194,9 @@ net::CookieStore* CefCookieManagerImpl::GetExistingCookieStore() {
|
|||
return cookie_store;
|
||||
}
|
||||
|
||||
LOG(ERROR) << "Cookie store does not exist";
|
||||
DCHECK(is_blocking_);
|
||||
if (!is_blocking_)
|
||||
LOG(ERROR) << "Cookie store does not exist";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -495,12 +499,11 @@ void CefCookieManagerImpl::SetSupportedSchemesInternal(
|
|||
return;
|
||||
}
|
||||
|
||||
DCHECK(cookie_store_.get());
|
||||
if (!cookie_store_.get())
|
||||
return;
|
||||
|
||||
supported_schemes_ = schemes;
|
||||
SetCookieMonsterSchemes(cookie_store_.get(), supported_schemes_);
|
||||
DCHECK(is_blocking_ || cookie_store_.get());
|
||||
if (cookie_store_) {
|
||||
supported_schemes_ = schemes;
|
||||
SetCookieMonsterSchemes(cookie_store_.get(), supported_schemes_);
|
||||
}
|
||||
|
||||
RunAsyncCompletionOnIOThread(callback);
|
||||
}
|
||||
|
@ -552,8 +555,13 @@ void CefCookieManagerImpl::SetCookieInternal(
|
|||
CEF_REQUIRE_IOT();
|
||||
|
||||
net::CookieStore* cookie_store = cookie_store_getter.Run();
|
||||
if (!cookie_store)
|
||||
if (!cookie_store) {
|
||||
if (callback.get()) {
|
||||
CEF_POST_TASK(CEF_IOT, base::Bind(&CefSetCookieCallback::OnComplete,
|
||||
callback.get(), false));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::string name = CefString(&cookie.name).ToString();
|
||||
std::string value = CefString(&cookie.value).ToString();
|
||||
|
@ -584,8 +592,13 @@ void CefCookieManagerImpl::DeleteCookiesInternal(
|
|||
CEF_REQUIRE_IOT();
|
||||
|
||||
net::CookieStore* cookie_store = cookie_store_getter.Run();
|
||||
if (!cookie_store)
|
||||
if (!cookie_store) {
|
||||
if (callback.get()) {
|
||||
CEF_POST_TASK(CEF_IOT, base::Bind(&CefDeleteCookiesCallback::OnComplete,
|
||||
callback.get(), 0));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (url.is_empty()) {
|
||||
// Delete all cookies.
|
||||
|
@ -610,8 +623,10 @@ void CefCookieManagerImpl::FlushStoreInternal(
|
|||
CEF_REQUIRE_IOT();
|
||||
|
||||
net::CookieStore* cookie_store = cookie_store_getter.Run();
|
||||
if (!cookie_store)
|
||||
if (!cookie_store) {
|
||||
RunAsyncCompletionOnIOThread(callback);
|
||||
return;
|
||||
}
|
||||
|
||||
cookie_store->FlushStore(base::Bind(RunAsyncCompletionOnIOThread, callback));
|
||||
}
|
||||
|
@ -631,6 +646,11 @@ CefRefPtr<CefCookieManager> CefCookieManager::GetGlobalManager(
|
|||
callback);
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefCookieManager> CefCookieManager::GetBlockingManager() {
|
||||
return new CefCookieManagerImpl(true);
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefCookieManager> CefCookieManager::CreateManager(
|
||||
const CefString& path,
|
||||
|
@ -642,7 +662,8 @@ CefRefPtr<CefCookieManager> CefCookieManager::CreateManager(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
CefRefPtr<CefCookieManagerImpl> cookie_manager = new CefCookieManagerImpl();
|
||||
CefRefPtr<CefCookieManagerImpl> cookie_manager =
|
||||
new CefCookieManagerImpl(false);
|
||||
cookie_manager->Initialize(NULL, path, persist_session_cookies, callback);
|
||||
return cookie_manager.get();
|
||||
}
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
// Implementation of the CefCookieManager interface.
|
||||
class CefCookieManagerImpl : public CefCookieManager {
|
||||
public:
|
||||
CefCookieManagerImpl();
|
||||
explicit CefCookieManagerImpl(bool is_blocking);
|
||||
~CefCookieManagerImpl() override;
|
||||
|
||||
// Must be called immediately after this object is created.
|
||||
// Must be called immediately after this object is created when |is_blocking|
|
||||
// is false.
|
||||
void Initialize(CefRefPtr<CefRequestContextImpl> request_context,
|
||||
const CefString& path,
|
||||
bool persist_session_cookies,
|
||||
|
@ -113,6 +114,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.
|
||||
CefRefPtr<CefRequestContextImpl> request_context_;
|
||||
scoped_refptr<CefURLRequestContextGetterImpl> request_context_impl_;
|
||||
|
|
|
@ -33,6 +33,8 @@ void CefCookieStoreProxy::SetCookieWithOptionsAsync(
|
|||
if (cookie_store) {
|
||||
cookie_store->SetCookieWithOptionsAsync(url, cookie_line, options,
|
||||
std::move(callback));
|
||||
} else if (!callback.is_null()) {
|
||||
std::move(callback).Run(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,6 +48,8 @@ void CefCookieStoreProxy::SetCanonicalCookieAsync(
|
|||
cookie_store->SetCanonicalCookieAsync(std::move(cookie), secure_source,
|
||||
modify_http_only,
|
||||
std::move(callback));
|
||||
} else if (!callback.is_null()) {
|
||||
std::move(callback).Run(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,8 +58,11 @@ void CefCookieStoreProxy::GetCookiesWithOptionsAsync(
|
|||
const net::CookieOptions& options,
|
||||
GetCookiesCallback callback) {
|
||||
net::CookieStore* cookie_store = GetCookieStore();
|
||||
if (cookie_store)
|
||||
if (cookie_store) {
|
||||
cookie_store->GetCookiesWithOptionsAsync(url, options, std::move(callback));
|
||||
} else if (!callback.is_null()) {
|
||||
std::move(callback).Run(std::string());
|
||||
}
|
||||
}
|
||||
|
||||
void CefCookieStoreProxy::GetCookieListWithOptionsAsync(
|
||||
|
@ -63,31 +70,43 @@ void CefCookieStoreProxy::GetCookieListWithOptionsAsync(
|
|||
const net::CookieOptions& options,
|
||||
GetCookieListCallback callback) {
|
||||
net::CookieStore* cookie_store = GetCookieStore();
|
||||
if (cookie_store)
|
||||
if (cookie_store) {
|
||||
cookie_store->GetCookieListWithOptionsAsync(url, options,
|
||||
std::move(callback));
|
||||
} else if (!callback.is_null()) {
|
||||
std::move(callback).Run(net::CookieList());
|
||||
}
|
||||
}
|
||||
|
||||
void CefCookieStoreProxy::GetAllCookiesAsync(GetCookieListCallback callback) {
|
||||
net::CookieStore* cookie_store = GetCookieStore();
|
||||
if (cookie_store)
|
||||
if (cookie_store) {
|
||||
cookie_store->GetAllCookiesAsync(std::move(callback));
|
||||
} else if (!callback.is_null()) {
|
||||
std::move(callback).Run(net::CookieList());
|
||||
}
|
||||
}
|
||||
|
||||
void CefCookieStoreProxy::DeleteCookieAsync(const GURL& url,
|
||||
const std::string& cookie_name,
|
||||
base::OnceClosure callback) {
|
||||
net::CookieStore* cookie_store = GetCookieStore();
|
||||
if (cookie_store)
|
||||
if (cookie_store) {
|
||||
cookie_store->DeleteCookieAsync(url, cookie_name, std::move(callback));
|
||||
} else if (!callback.is_null()) {
|
||||
std::move(callback).Run();
|
||||
}
|
||||
}
|
||||
|
||||
void CefCookieStoreProxy::DeleteCanonicalCookieAsync(
|
||||
const net::CanonicalCookie& cookie,
|
||||
DeleteCallback callback) {
|
||||
net::CookieStore* cookie_store = GetCookieStore();
|
||||
if (cookie_store)
|
||||
if (cookie_store) {
|
||||
cookie_store->DeleteCanonicalCookieAsync(cookie, std::move(callback));
|
||||
} else if (!callback.is_null()) {
|
||||
std::move(callback).Run(0);
|
||||
}
|
||||
}
|
||||
|
||||
void CefCookieStoreProxy::DeleteAllCreatedBetweenAsync(
|
||||
|
@ -98,6 +117,8 @@ void CefCookieStoreProxy::DeleteAllCreatedBetweenAsync(
|
|||
if (cookie_store) {
|
||||
cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end,
|
||||
std::move(callback));
|
||||
} else if (!callback.is_null()) {
|
||||
std::move(callback).Run(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,19 +131,27 @@ void CefCookieStoreProxy::DeleteAllCreatedBetweenWithPredicateAsync(
|
|||
if (cookie_store) {
|
||||
cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(
|
||||
delete_begin, delete_end, predicate, 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)
|
||||
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)
|
||||
if (cookie_store) {
|
||||
cookie_store->FlushStore(std::move(callback));
|
||||
} else if (!callback.is_null()) {
|
||||
std::move(callback).Run();
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<net::CookieStore::CookieChangedSubscription>
|
||||
|
@ -131,8 +160,9 @@ CefCookieStoreProxy::AddCallbackForCookie(
|
|||
const std::string& name,
|
||||
const CookieChangedCallback& callback) {
|
||||
net::CookieStore* cookie_store = GetCookieStore();
|
||||
if (cookie_store)
|
||||
if (cookie_store) {
|
||||
return cookie_store->AddCallbackForCookie(url, name, callback);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -140,8 +170,9 @@ std::unique_ptr<net::CookieStore::CookieChangedSubscription>
|
|||
CefCookieStoreProxy::AddCallbackForAllChanges(
|
||||
const CookieChangedCallback& callback) {
|
||||
net::CookieStore* cookie_store = GetCookieStore();
|
||||
if (cookie_store)
|
||||
if (cookie_store) {
|
||||
return cookie_store->AddCallbackForAllChanges(callback);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -155,25 +186,23 @@ bool CefCookieStoreProxy::IsEphemeral() {
|
|||
net::CookieStore* CefCookieStoreProxy::GetCookieStore() {
|
||||
CEF_REQUIRE_IOT();
|
||||
|
||||
net::CookieStore* cookie_store = nullptr;
|
||||
|
||||
CefRefPtr<CefCookieManager> manager = handler_->GetCookieManager();
|
||||
if (manager.get()) {
|
||||
// Use the cookie store provided by the manager.
|
||||
cookie_store = reinterpret_cast<CefCookieManagerImpl*>(manager.get())
|
||||
->GetExistingCookieStore();
|
||||
DCHECK(cookie_store);
|
||||
return cookie_store;
|
||||
// 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.
|
||||
cookie_store = parent_->cookie_store();
|
||||
net::CookieStore* cookie_store = parent_->cookie_store();
|
||||
DCHECK(cookie_store);
|
||||
if (!cookie_store)
|
||||
LOG(ERROR) << "Cookie store does not exist";
|
||||
return cookie_store;
|
||||
}
|
||||
|
||||
return cookie_store;
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -293,7 +293,8 @@ CefString CefRequestContextImpl::GetCachePath() {
|
|||
|
||||
CefRefPtr<CefCookieManager> CefRequestContextImpl::GetDefaultCookieManager(
|
||||
CefRefPtr<CefCompletionCallback> callback) {
|
||||
CefRefPtr<CefCookieManagerImpl> cookie_manager = new CefCookieManagerImpl();
|
||||
CefRefPtr<CefCookieManagerImpl> cookie_manager =
|
||||
new CefCookieManagerImpl(false);
|
||||
cookie_manager->Initialize(this, CefString(), false, callback);
|
||||
return cookie_manager.get();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=0b1ea8f0568d1fbbf7359429d1cab3d0df845e93$
|
||||
// $hash=807ba668c5bc70deae472558afa6e7026ca54de5$
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/cookie_manager_cpptoc.h"
|
||||
|
@ -35,6 +35,16 @@ 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,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=5a754788197bd0d5e1e18db5dc1643285baa848f$
|
||||
// $hash=5a5ae9a4567ba338efa8477ba1dc53435ada8c6b$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/cookie_manager_ctocpp.h"
|
||||
|
@ -35,6 +35,16 @@ CefRefPtr<CefCookieManager> CefCookieManager::GetGlobalManager(
|
|||
return CefCookieManagerCToCpp::Wrap(_retval);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
CefRefPtr<CefCookieManager> CefCookieManager::CreateManager(
|
||||
const CefString& path,
|
||||
bool persist_session_cookies,
|
||||
|
|
|
@ -22,7 +22,14 @@ namespace {
|
|||
class ClientRequestContextHandler : public CefRequestContextHandler,
|
||||
public CefExtensionHandler {
|
||||
public:
|
||||
ClientRequestContextHandler() {}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// CefRequestContextHandler methods:
|
||||
bool OnBeforePluginLoad(const CefString& mime_type,
|
||||
|
@ -73,6 +80,10 @@ class ClientRequestContextHandler : public CefRequestContextHandler,
|
|||
}
|
||||
}
|
||||
|
||||
CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE {
|
||||
return cookie_manager_;
|
||||
}
|
||||
|
||||
// CefExtensionHandler methods:
|
||||
void OnExtensionLoaded(CefRefPtr<CefExtension> extension) OVERRIDE {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
@ -99,6 +110,8 @@ class ClientRequestContextHandler : public CefRequestContextHandler,
|
|||
}
|
||||
|
||||
private:
|
||||
CefRefPtr<CefCookieManager> cookie_manager_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(ClientRequestContextHandler);
|
||||
DISALLOW_COPY_AND_ASSIGN(ClientRequestContextHandler);
|
||||
};
|
||||
|
|
|
@ -2180,14 +2180,46 @@ class CookieAccessTestHandler : public RoutingTestHandler {
|
|||
ALLOW = 0,
|
||||
BLOCK_READ = 1 << 0,
|
||||
BLOCK_WRITE = 1 << 1,
|
||||
BLOCK_ALL = BLOCK_READ | BLOCK_WRITE,
|
||||
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 {
|
||||
cookie_manager_ = CefCookieManager::GetGlobalManager(nullptr);
|
||||
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);
|
||||
}
|
||||
SetTestTimeout();
|
||||
|
||||
CefPostTask(TID_UI,
|
||||
|
@ -2204,88 +2236,130 @@ class CookieAccessTestHandler : public RoutingTestHandler {
|
|||
}
|
||||
|
||||
cookie_manager_ = NULL;
|
||||
|
||||
// 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_);
|
||||
|
||||
// Always get the JS cookie via JS.
|
||||
EXPECT_TRUE(got_cookie_js1_);
|
||||
EXPECT_TRUE(got_cookie_js2_);
|
||||
EXPECT_TRUE(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_);
|
||||
} else {
|
||||
EXPECT_TRUE(got_cookie_net1_);
|
||||
EXPECT_TRUE(got_cookie_net2_);
|
||||
EXPECT_TRUE(got_cookie_net3_);
|
||||
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_);
|
||||
|
||||
// No cookies sent for the 1st network request.
|
||||
EXPECT_FALSE(data1_.got_cookie_js_);
|
||||
EXPECT_FALSE(data1_.got_cookie_net_);
|
||||
if (test_mode_ == BLOCK_ALL) {
|
||||
EXPECT_TRUE(got_cookie_manager_);
|
||||
|
||||
// 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_);
|
||||
} 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 {
|
||||
// All cookies sent.
|
||||
EXPECT_TRUE(data2_.got_cookie_js_);
|
||||
EXPECT_TRUE(data2_.got_cookie_net_);
|
||||
}
|
||||
// The callback to set the cookie comes before the actual storage fails.
|
||||
EXPECT_TRUE(got_can_set_cookie1_);
|
||||
|
||||
if (!server_backend_) {
|
||||
// No query to get cookies with the 1st network request because none have
|
||||
// been set yet.
|
||||
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_);
|
||||
}
|
||||
|
||||
// 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_);
|
||||
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_);
|
||||
|
||||
// JS cookie is not set via a network request.
|
||||
EXPECT_FALSE(data1_.got_can_set_cookie_js_);
|
||||
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_);
|
||||
|
||||
// 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_);
|
||||
} else {
|
||||
EXPECT_FALSE(got_cookie_manager_);
|
||||
|
||||
// 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_);
|
||||
// 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_);
|
||||
|
||||
// Always get the JS cookie via JS.
|
||||
EXPECT_TRUE(got_cookie_js1_);
|
||||
EXPECT_TRUE(got_cookie_js2_);
|
||||
EXPECT_TRUE(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_);
|
||||
} else {
|
||||
EXPECT_TRUE(data2_.got_can_get_cookie_js_);
|
||||
EXPECT_TRUE(got_cookie_net1_);
|
||||
EXPECT_TRUE(got_cookie_net2_);
|
||||
EXPECT_TRUE(got_cookie_net3_);
|
||||
}
|
||||
|
||||
// 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_);
|
||||
// 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_);
|
||||
} 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_TRUE(data2_.got_can_get_cookie_net_);
|
||||
// All cookies sent.
|
||||
EXPECT_TRUE(data2_.got_cookie_js_);
|
||||
EXPECT_TRUE(data2_.got_cookie_net_);
|
||||
}
|
||||
|
||||
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_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2413,8 +2487,13 @@ class CookieAccessTestHandler : public RoutingTestHandler {
|
|||
// Add the factory registration.
|
||||
scheme_factory_ = new CookieAccessSchemeHandlerFactory();
|
||||
AddResponses(scheme_factory_.get());
|
||||
CefRegisterSchemeHandlerFactory(kCookieAccessScheme, kCookieAccessDomain,
|
||||
scheme_factory_.get());
|
||||
if (context_) {
|
||||
context_->RegisterSchemeHandlerFactory(
|
||||
kCookieAccessScheme, kCookieAccessDomain, scheme_factory_.get());
|
||||
} else {
|
||||
CefRegisterSchemeHandlerFactory(kCookieAccessScheme, kCookieAccessDomain,
|
||||
scheme_factory_.get());
|
||||
}
|
||||
|
||||
complete_callback.Run();
|
||||
}
|
||||
|
@ -2426,7 +2505,7 @@ class CookieAccessTestHandler : public RoutingTestHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
CreateBrowser(GetCookieAccessUrl1(server_backend_));
|
||||
CreateBrowser(GetCookieAccessUrl1(server_backend_), context_);
|
||||
}
|
||||
|
||||
void FinishTest() {
|
||||
|
@ -2487,14 +2566,21 @@ class CookieAccessTestHandler : public RoutingTestHandler {
|
|||
void ShutdownSchemeHandler(const base::Closure& complete_callback) {
|
||||
EXPECT_TRUE(scheme_factory_);
|
||||
|
||||
CefRegisterSchemeHandlerFactory(kCookieAccessScheme, kCookieAccessDomain,
|
||||
nullptr);
|
||||
if (context_) {
|
||||
context_->RegisterSchemeHandlerFactory(kCookieAccessScheme,
|
||||
kCookieAccessDomain, nullptr);
|
||||
} else {
|
||||
CefRegisterSchemeHandlerFactory(kCookieAccessScheme, kCookieAccessDomain,
|
||||
nullptr);
|
||||
}
|
||||
scheme_factory_->Shutdown(complete_callback);
|
||||
scheme_factory_ = nullptr;
|
||||
}
|
||||
|
||||
TestMode test_mode_;
|
||||
bool server_backend_;
|
||||
CefRefPtr<RequestContextHandler> context_handler_;
|
||||
CefRefPtr<CefRequestContext> context_;
|
||||
CefRefPtr<CefCookieManager> cookie_manager_;
|
||||
|
||||
CefRefPtr<CookieAccessServerHandler> server_handler_;
|
||||
|
@ -2503,6 +2589,8 @@ class CookieAccessTestHandler : public RoutingTestHandler {
|
|||
CookieAccessData data1_;
|
||||
CookieAccessData data2_;
|
||||
|
||||
TrackCallback got_cookie_manager_;
|
||||
|
||||
// 1st request.
|
||||
TrackCallback got_can_set_cookie1_;
|
||||
TrackCallback got_cookie_js1_;
|
||||
|
@ -2548,6 +2636,14 @@ TEST(RequestHandlerTest, CookieAccessServerBlockWrite) {
|
|||
}
|
||||
|
||||
// Block reading and writing of cookies with server backend.
|
||||
TEST(RequestHandlerTest, CookieAccessServerBlockReadWrite) {
|
||||
CefRefPtr<CookieAccessTestHandler> handler = new CookieAccessTestHandler(
|
||||
CookieAccessTestHandler::BLOCK_READ_WRITE, true);
|
||||
handler->ExecuteTest();
|
||||
ReleaseAndWaitForDestructor(handler);
|
||||
}
|
||||
|
||||
// Block all cookies with server backend.
|
||||
TEST(RequestHandlerTest, CookieAccessServerBlockAll) {
|
||||
CefRefPtr<CookieAccessTestHandler> handler =
|
||||
new CookieAccessTestHandler(CookieAccessTestHandler::BLOCK_ALL, true);
|
||||
|
@ -2580,6 +2676,14 @@ TEST(RequestHandlerTest, CookieAccessSchemeBlockWrite) {
|
|||
}
|
||||
|
||||
// Block reading and writing of cookies with scheme handler backend.
|
||||
TEST(RequestHandlerTest, CookieAccessSchemeBlockReadWrite) {
|
||||
CefRefPtr<CookieAccessTestHandler> handler = new CookieAccessTestHandler(
|
||||
CookieAccessTestHandler::BLOCK_READ_WRITE, false);
|
||||
handler->ExecuteTest();
|
||||
ReleaseAndWaitForDestructor(handler);
|
||||
}
|
||||
|
||||
// Block all cookies with scheme handler backend.
|
||||
TEST(RequestHandlerTest, CookieAccessSchemeBlockAll) {
|
||||
CefRefPtr<CookieAccessTestHandler> handler =
|
||||
new CookieAccessTestHandler(CookieAccessTestHandler::BLOCK_ALL, false);
|
||||
|
|
|
@ -28,6 +28,7 @@ const char kShowUpdateRect[] = "show-update-rect";
|
|||
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";
|
||||
|
|
|
@ -22,6 +22,7 @@ extern const char kShowUpdateRect[];
|
|||
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[];
|
||||
|
|
Loading…
Reference in New Issue