Add CookieManagerImpl for NetworkService (see issue #2622).

To test: Run `ceftests --gtest_filter=CookieTest.*:-CookieTest.GetCookieManager*
                       --enable-network-service`

There should be no functional change when running without the NetworkService
enabled.

Known issues:
- CefCookieManager::SetSupportedSchemes is not yet implemented.
This commit is contained in:
Marshall Greenblatt 2019-03-25 14:14:23 -04:00
parent b65f336f81
commit 85c34c4dcf
10 changed files with 419 additions and 100 deletions

View File

@ -292,8 +292,6 @@ static_library("libcef_static") {
"libcef/browser/context.h", "libcef/browser/context.h",
"libcef/browser/context_menu_params_impl.cc", "libcef/browser/context_menu_params_impl.cc",
"libcef/browser/context_menu_params_impl.h", "libcef/browser/context_menu_params_impl.h",
"libcef/browser/cookie_manager_impl.cc",
"libcef/browser/cookie_manager_impl.h",
"libcef/browser/devtools/devtools_file_manager.cc", "libcef/browser/devtools/devtools_file_manager.cc",
"libcef/browser/devtools/devtools_file_manager.h", "libcef/browser/devtools/devtools_file_manager.h",
"libcef/browser/devtools/devtools_frontend.cc", "libcef/browser/devtools/devtools_frontend.cc",
@ -373,6 +371,8 @@ static_library("libcef_static") {
"libcef/browser/navigation_entry_impl.h", "libcef/browser/navigation_entry_impl.h",
"libcef/browser/net/chrome_scheme_handler.cc", "libcef/browser/net/chrome_scheme_handler.cc",
"libcef/browser/net/chrome_scheme_handler.h", "libcef/browser/net/chrome_scheme_handler.h",
"libcef/browser/net/cookie_manager_old_impl.cc",
"libcef/browser/net/cookie_manager_old_impl.h",
"libcef/browser/net/crlset_file_util_impl.cc", "libcef/browser/net/crlset_file_util_impl.cc",
"libcef/browser/net/devtools_scheme_handler.cc", "libcef/browser/net/devtools_scheme_handler.cc",
"libcef/browser/net/devtools_scheme_handler.h", "libcef/browser/net/devtools_scheme_handler.h",
@ -398,6 +398,8 @@ static_library("libcef_static") {
"libcef/browser/net/url_request_manager.h", "libcef/browser/net/url_request_manager.h",
"libcef/browser/net/url_request_user_data.cc", "libcef/browser/net/url_request_user_data.cc",
"libcef/browser/net/url_request_user_data.h", "libcef/browser/net/url_request_user_data.h",
"libcef/browser/net_service/cookie_manager_impl.cc",
"libcef/browser/net_service/cookie_manager_impl.h",
"libcef/browser/origin_whitelist_impl.cc", "libcef/browser/origin_whitelist_impl.cc",
"libcef/browser/origin_whitelist_impl.h", "libcef/browser/origin_whitelist_impl.h",
"libcef/browser/osr/browser_platform_delegate_osr.cc", "libcef/browser/osr/browser_platform_delegate_osr.cc",

View File

@ -11,6 +11,7 @@
#include "libcef/browser/prefs/browser_prefs.h" #include "libcef/browser/prefs/browser_prefs.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h" #include "libcef/common/cef_switches.h"
#include "libcef/common/net_service/util.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "chrome/browser/net/chrome_net_log_helper.h" #include "chrome/browser/net/chrome_net_log_helper.h"
@ -80,6 +81,10 @@ void ChromeBrowserProcessStub::Shutdown() {
profile_manager_.reset(); profile_manager_.reset();
event_router_forwarder_ = nullptr; event_router_forwarder_ = nullptr;
if (net_service::IsEnabled()) {
SystemNetworkContextManager::DeleteInstance();
}
local_state_.reset(); local_state_.reset();
browser_policy_connector_.reset(); browser_policy_connector_.reset();

View File

@ -2,7 +2,7 @@
// reserved. Use of this source code is governed by a BSD-style license that can // reserved. Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file. // be found in the LICENSE file.
#include "libcef/browser/cookie_manager_impl.h" #include "libcef/browser/net/cookie_manager_old_impl.h"
#include <set> #include <set>
#include <string> #include <string>
@ -11,7 +11,6 @@
#include "libcef/browser/content_browser_client.h" #include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h" #include "libcef/browser/context.h"
#include "libcef/browser/net/network_delegate.h" #include "libcef/browser/net/network_delegate.h"
#include "libcef/common/net_service/util.h"
#include "libcef/common/task_runner_impl.h" #include "libcef/common/task_runner_impl.h"
#include "libcef/common/time_util.h" #include "libcef/common/time_util.h"
@ -36,7 +35,7 @@ namespace {
class VisitCookiesCallback : public base::RefCounted<VisitCookiesCallback> { class VisitCookiesCallback : public base::RefCounted<VisitCookiesCallback> {
public: public:
explicit VisitCookiesCallback( explicit VisitCookiesCallback(
const CefCookieManagerImpl::CookieStoreGetter& cookie_store_getter, const CefCookieManagerOldImpl::CookieStoreGetter& cookie_store_getter,
CefRefPtr<CefCookieVisitor> visitor) CefRefPtr<CefCookieVisitor> visitor)
: cookie_store_getter_(cookie_store_getter), visitor_(visitor) {} : cookie_store_getter_(cookie_store_getter), visitor_(visitor) {}
@ -50,7 +49,7 @@ class VisitCookiesCallback : public base::RefCounted<VisitCookiesCallback> {
for (; it != list.end(); ++it, ++count) { for (; it != list.end(); ++it, ++count) {
CefCookie cookie; CefCookie cookie;
const net::CanonicalCookie& cc = *(it); const net::CanonicalCookie& cc = *(it);
CefCookieManagerImpl::GetCefCookie(cc, cookie); CefCookieManagerOldImpl::GetCefCookie(cc, cookie);
bool deleteCookie = false; bool deleteCookie = false;
bool keepLooping = visitor_->Visit(cookie, count, total, deleteCookie); bool keepLooping = visitor_->Visit(cookie, count, total, deleteCookie);
@ -71,7 +70,7 @@ class VisitCookiesCallback : public base::RefCounted<VisitCookiesCallback> {
~VisitCookiesCallback() {} ~VisitCookiesCallback() {}
CefCookieManagerImpl::CookieStoreGetter cookie_store_getter_; CefCookieManagerOldImpl::CookieStoreGetter cookie_store_getter_;
CefRefPtr<CefCookieVisitor> visitor_; CefRefPtr<CefCookieVisitor> visitor_;
}; };
@ -119,46 +118,42 @@ void SetCookieCallbackImpl(CefRefPtr<CefSetCookieCallback> callback,
} // namespace } // namespace
CefCookieManagerImpl::CefCookieManagerImpl() : weak_ptr_factory_(this) {} CefCookieManagerOldImpl::CefCookieManagerOldImpl() {}
CefCookieManagerImpl::~CefCookieManagerImpl() { CefCookieManagerOldImpl::~CefCookieManagerOldImpl() {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
} }
void CefCookieManagerImpl::Initialize( void CefCookieManagerOldImpl::Initialize(
CefRefPtr<CefRequestContextImpl> request_context, CefRefPtr<CefRequestContextImpl> request_context,
const CefString& path, const CefString& path,
bool persist_session_cookies, bool persist_session_cookies,
CefRefPtr<CefCompletionCallback> callback) { CefRefPtr<CefCompletionCallback> callback) {
DCHECK(request_context.get()); DCHECK(request_context.get());
request_context_ = request_context; request_context_ = request_context;
if (!net_service::IsEnabled()) { request_context_->GetRequestContextImpl(
request_context_->GetRequestContextImpl( base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}), base::Bind(&CefCookieManagerOldImpl::InitWithContext, this, callback));
base::Bind(&CefCookieManagerImpl::InitWithContext, this, callback));
} else {
RunAsyncCompletionOnIOThread(callback);
}
} }
void CefCookieManagerImpl::GetCookieStore( void CefCookieManagerOldImpl::GetCookieStore(
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const CookieStoreCallback& callback) { const CookieStoreCallback& callback) {
if (!task_runner.get()) if (!task_runner.get())
task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner(); task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner();
if (!CEF_CURRENTLY_ON_IOT()) { if (!CEF_CURRENTLY_ON_IOT()) {
CEF_POST_TASK(CEF_IOT, base::Bind(&CefCookieManagerImpl::GetCookieStore, CEF_POST_TASK(CEF_IOT, base::Bind(&CefCookieManagerOldImpl::GetCookieStore,
this, task_runner, callback)); this, task_runner, callback));
return; return;
} }
RunMethodWithContext( RunMethodWithContext(
base::Bind(&CefCookieManagerImpl::GetCookieStoreWithContext, this, base::Bind(&CefCookieManagerOldImpl::GetCookieStoreWithContext, this,
task_runner, callback)); task_runner, callback));
} }
net::CookieStore* CefCookieManagerImpl::GetExistingCookieStore() { net::CookieStore* CefCookieManagerOldImpl::GetExistingCookieStore() {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
if (request_context_impl_.get()) { if (request_context_impl_.get()) {
net::CookieStore* cookie_store = net::CookieStore* cookie_store =
@ -171,13 +166,13 @@ net::CookieStore* CefCookieManagerImpl::GetExistingCookieStore() {
return nullptr; return nullptr;
} }
void CefCookieManagerImpl::SetSupportedSchemes( void CefCookieManagerOldImpl::SetSupportedSchemes(
const std::vector<CefString>& schemes, const std::vector<CefString>& schemes,
CefRefPtr<CefCompletionCallback> callback) { CefRefPtr<CefCompletionCallback> callback) {
if (!CEF_CURRENTLY_ON_IOT()) { if (!CEF_CURRENTLY_ON_IOT()) {
CEF_POST_TASK(CEF_IOT, CEF_POST_TASK(
base::Bind(&CefCookieManagerImpl::SetSupportedSchemes, this, CEF_IOT, base::Bind(&CefCookieManagerOldImpl::SetSupportedSchemes, this,
schemes, callback)); schemes, callback));
return; return;
} }
@ -189,41 +184,42 @@ void CefCookieManagerImpl::SetSupportedSchemes(
SetSupportedSchemesInternal(scheme_set, callback); SetSupportedSchemesInternal(scheme_set, callback);
} }
bool CefCookieManagerImpl::VisitAllCookies( bool CefCookieManagerOldImpl::VisitAllCookies(
CefRefPtr<CefCookieVisitor> visitor) { CefRefPtr<CefCookieVisitor> visitor) {
GetCookieStore( GetCookieStore(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}), base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerImpl::VisitAllCookiesInternal, this, base::Bind(&CefCookieManagerOldImpl::VisitAllCookiesInternal, this,
visitor)); visitor));
return true; return true;
} }
bool CefCookieManagerImpl::VisitUrlCookies( bool CefCookieManagerOldImpl::VisitUrlCookies(
const CefString& url, const CefString& url,
bool includeHttpOnly, bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor) { CefRefPtr<CefCookieVisitor> visitor) {
GetCookieStore( GetCookieStore(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}), base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerImpl::VisitUrlCookiesInternal, this, url, base::Bind(&CefCookieManagerOldImpl::VisitUrlCookiesInternal, this, url,
includeHttpOnly, visitor)); includeHttpOnly, visitor));
return true; return true;
} }
bool CefCookieManagerImpl::SetCookie(const CefString& url, bool CefCookieManagerOldImpl::SetCookie(
const CefCookie& cookie, const CefString& url,
CefRefPtr<CefSetCookieCallback> callback) { const CefCookie& cookie,
CefRefPtr<CefSetCookieCallback> callback) {
GURL gurl = GURL(url.ToString()); GURL gurl = GURL(url.ToString());
if (!gurl.is_valid()) if (!gurl.is_valid())
return false; return false;
GetCookieStore( GetCookieStore(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}), base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerImpl::SetCookieInternal, this, gurl, cookie, base::Bind(&CefCookieManagerOldImpl::SetCookieInternal, this, gurl,
callback)); cookie, callback));
return true; return true;
} }
bool CefCookieManagerImpl::DeleteCookies( bool CefCookieManagerOldImpl::DeleteCookies(
const CefString& url, const CefString& url,
const CefString& cookie_name, const CefString& cookie_name,
CefRefPtr<CefDeleteCookiesCallback> callback) { CefRefPtr<CefDeleteCookiesCallback> callback) {
@ -234,22 +230,22 @@ bool CefCookieManagerImpl::DeleteCookies(
GetCookieStore( GetCookieStore(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}), base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerImpl::DeleteCookiesInternal, this, gurl, base::Bind(&CefCookieManagerOldImpl::DeleteCookiesInternal, this, gurl,
cookie_name, callback)); cookie_name, callback));
return true; return true;
} }
bool CefCookieManagerImpl::FlushStore( bool CefCookieManagerOldImpl::FlushStore(
CefRefPtr<CefCompletionCallback> callback) { CefRefPtr<CefCompletionCallback> callback) {
GetCookieStore( GetCookieStore(
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}), base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
base::Bind(&CefCookieManagerImpl::FlushStoreInternal, this, callback)); base::Bind(&CefCookieManagerOldImpl::FlushStoreInternal, this, callback));
return true; return true;
} }
// static // static
bool CefCookieManagerImpl::GetCefCookie(const net::CanonicalCookie& cc, bool CefCookieManagerOldImpl::GetCefCookie(const net::CanonicalCookie& cc,
CefCookie& cookie) { CefCookie& cookie) {
CefString(&cookie.name).FromString(cc.Name()); CefString(&cookie.name).FromString(cc.Name());
CefString(&cookie.value).FromString(cc.Value()); CefString(&cookie.value).FromString(cc.Value());
CefString(&cookie.domain).FromString(cc.Domain()); CefString(&cookie.domain).FromString(cc.Domain());
@ -266,9 +262,9 @@ bool CefCookieManagerImpl::GetCefCookie(const net::CanonicalCookie& cc,
} }
// static // static
bool CefCookieManagerImpl::GetCefCookie(const GURL& url, bool CefCookieManagerOldImpl::GetCefCookie(const GURL& url,
const std::string& cookie_line, const std::string& cookie_line,
CefCookie& cookie) { CefCookie& cookie) {
// Parse the cookie. // Parse the cookie.
net::ParsedCookie pc(cookie_line); net::ParsedCookie pc(cookie_line);
if (!pc.IsValid()) if (!pc.IsValid())
@ -303,7 +299,7 @@ bool CefCookieManagerImpl::GetCefCookie(const GURL& url,
} }
// static // static
void CefCookieManagerImpl::SetCookieMonsterSchemes( void CefCookieManagerOldImpl::SetCookieMonsterSchemes(
net::CookieMonster* cookie_monster, net::CookieMonster* cookie_monster,
const std::vector<std::string>& schemes) { const std::vector<std::string>& schemes) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
@ -319,7 +315,7 @@ void CefCookieManagerImpl::SetCookieMonsterSchemes(
cookie_monster->SetCookieableSchemes(all_schemes); cookie_monster->SetCookieableSchemes(all_schemes);
} }
void CefCookieManagerImpl::RunMethodWithContext( void CefCookieManagerOldImpl::RunMethodWithContext(
const CefRequestContextImpl::RequestContextCallback& method) { const CefRequestContextImpl::RequestContextCallback& method) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
if (request_context_impl_.get()) { if (request_context_impl_.get()) {
@ -334,7 +330,7 @@ void CefCookieManagerImpl::RunMethodWithContext(
} }
} }
void CefCookieManagerImpl::InitWithContext( void CefCookieManagerOldImpl::InitWithContext(
CefRefPtr<CefCompletionCallback> callback, CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context) { scoped_refptr<CefURLRequestContextGetter> request_context) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
@ -351,7 +347,7 @@ void CefCookieManagerImpl::InitWithContext(
RunAsyncCompletionOnIOThread(callback); RunAsyncCompletionOnIOThread(callback);
} }
void CefCookieManagerImpl::SetSupportedSchemesWithContext( void CefCookieManagerOldImpl::SetSupportedSchemesWithContext(
const std::vector<std::string>& schemes, const std::vector<std::string>& schemes,
CefRefPtr<CefCompletionCallback> callback, CefRefPtr<CefCompletionCallback> callback,
scoped_refptr<CefURLRequestContextGetter> request_context) { scoped_refptr<CefURLRequestContextGetter> request_context) {
@ -362,7 +358,7 @@ void CefCookieManagerImpl::SetSupportedSchemesWithContext(
RunAsyncCompletionOnIOThread(callback); RunAsyncCompletionOnIOThread(callback);
} }
void CefCookieManagerImpl::GetCookieStoreWithContext( void CefCookieManagerOldImpl::GetCookieStoreWithContext(
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const CookieStoreCallback& callback, const CookieStoreCallback& callback,
scoped_refptr<CefURLRequestContextGetter> request_context) { scoped_refptr<CefURLRequestContextGetter> request_context) {
@ -381,22 +377,17 @@ void CefCookieManagerImpl::GetCookieStoreWithContext(
} }
} }
void CefCookieManagerImpl::SetSupportedSchemesInternal( void CefCookieManagerOldImpl::SetSupportedSchemesInternal(
const std::vector<std::string>& schemes, const std::vector<std::string>& schemes,
CefRefPtr<CefCompletionCallback> callback) { CefRefPtr<CefCompletionCallback> callback) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
if (!net_service::IsEnabled()) { RunMethodWithContext(
RunMethodWithContext( base::Bind(&CefCookieManagerOldImpl::SetSupportedSchemesWithContext, this,
base::Bind(&CefCookieManagerImpl::SetSupportedSchemesWithContext, this, schemes, callback));
schemes, callback));
} else {
NOTIMPLEMENTED();
RunAsyncCompletionOnIOThread(callback);
}
} }
void CefCookieManagerImpl::VisitAllCookiesInternal( void CefCookieManagerOldImpl::VisitAllCookiesInternal(
CefRefPtr<CefCookieVisitor> visitor, CefRefPtr<CefCookieVisitor> visitor,
const CookieStoreGetter& cookie_store_getter) { const CookieStoreGetter& cookie_store_getter) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
@ -412,7 +403,7 @@ void CefCookieManagerImpl::VisitAllCookiesInternal(
base::Bind(&VisitCookiesCallback::Run, callback.get())); base::Bind(&VisitCookiesCallback::Run, callback.get()));
} }
void CefCookieManagerImpl::VisitUrlCookiesInternal( void CefCookieManagerOldImpl::VisitUrlCookiesInternal(
const CefString& url, const CefString& url,
bool includeHttpOnly, bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor, CefRefPtr<CefCookieVisitor> visitor,
@ -435,7 +426,7 @@ void CefCookieManagerImpl::VisitUrlCookiesInternal(
gurl, options, base::Bind(&VisitCookiesCallback::Run, callback.get())); gurl, options, base::Bind(&VisitCookiesCallback::Run, callback.get()));
} }
void CefCookieManagerImpl::SetCookieInternal( void CefCookieManagerOldImpl::SetCookieInternal(
const GURL& url, const GURL& url,
const CefCookie& cookie, const CefCookie& cookie,
CefRefPtr<CefSetCookieCallback> callback, CefRefPtr<CefSetCookieCallback> callback,
@ -472,7 +463,7 @@ void CefCookieManagerImpl::SetCookieInternal(
base::Bind(SetCookieCallbackImpl, callback)); base::Bind(SetCookieCallbackImpl, callback));
} }
void CefCookieManagerImpl::DeleteCookiesInternal( void CefCookieManagerOldImpl::DeleteCookiesInternal(
const GURL& url, const GURL& url,
const CefString& cookie_name, const CefString& cookie_name,
CefRefPtr<CefDeleteCookiesCallback> callback, CefRefPtr<CefDeleteCookiesCallback> callback,
@ -508,7 +499,7 @@ void CefCookieManagerImpl::DeleteCookiesInternal(
} }
} }
void CefCookieManagerImpl::FlushStoreInternal( void CefCookieManagerOldImpl::FlushStoreInternal(
CefRefPtr<CefCompletionCallback> callback, CefRefPtr<CefCompletionCallback> callback,
const CookieStoreGetter& cookie_store_getter) { const CookieStoreGetter& cookie_store_getter) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
@ -521,17 +512,3 @@ void CefCookieManagerImpl::FlushStoreInternal(
cookie_store->FlushStore(base::Bind(RunAsyncCompletionOnIOThread, callback)); cookie_store->FlushStore(base::Bind(RunAsyncCompletionOnIOThread, callback));
} }
// CefCookieManager methods ----------------------------------------------------
// static
CefRefPtr<CefCookieManager> CefCookieManager::GetGlobalManager(
CefRefPtr<CefCompletionCallback> callback) {
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return NULL;
}
return CefRequestContext::GetGlobalContext()->GetCookieManager(callback);
}

View File

@ -2,8 +2,8 @@
// reserved. Use of this source code is governed by a BSD-style license that can // reserved. Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file. // be found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_COOKIE_MANAGER_IMPL_H_ #ifndef CEF_LIBCEF_BROWSER_NET_COOKIE_MANAGER_OLD_IMPL_H_
#define CEF_LIBCEF_BROWSER_COOKIE_MANAGER_IMPL_H_ #define CEF_LIBCEF_BROWSER_NET_COOKIE_MANAGER_OLD_IMPL_H_
#include <set> #include <set>
@ -12,14 +12,13 @@
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/weak_ptr.h"
#include "net/cookies/cookie_monster.h" #include "net/cookies/cookie_monster.h"
// Implementation of the CefCookieManager interface. // Implementation of the CefCookieManager interface.
class CefCookieManagerImpl : public CefCookieManager { class CefCookieManagerOldImpl : public CefCookieManager {
public: public:
CefCookieManagerImpl(); CefCookieManagerOldImpl();
~CefCookieManagerImpl() override; ~CefCookieManagerOldImpl() override;
// Must be called immediately after this object is created when |is_blocking| // Must be called immediately after this object is created when |is_blocking|
// is false. // is false.
@ -107,10 +106,7 @@ class CefCookieManagerImpl : public CefCookieManager {
CefRefPtr<CefRequestContextImpl> request_context_; CefRefPtr<CefRequestContextImpl> request_context_;
scoped_refptr<CefURLRequestContextGetter> request_context_impl_; scoped_refptr<CefURLRequestContextGetter> request_context_impl_;
// Must be the last member. IMPLEMENT_REFCOUNTING_DELETE_ON_IOT(CefCookieManagerOldImpl);
base::WeakPtrFactory<CefCookieManagerImpl> weak_ptr_factory_;
IMPLEMENT_REFCOUNTING_DELETE_ON_IOT(CefCookieManagerImpl);
}; };
#endif // CEF_LIBCEF_BROWSER_COOKIE_MANAGER_IMPL_H_ #endif // CEF_LIBCEF_BROWSER_NET_COOKIE_MANAGER_OLD_IMPL_H_

View File

@ -9,7 +9,7 @@
#include "include/cef_urlrequest.h" #include "include/cef_urlrequest.h"
#include "libcef/browser/browser_host_impl.h" #include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/cookie_manager_impl.h" #include "libcef/browser/net/cookie_manager_old_impl.h"
#include "libcef/browser/net/net_util.h" #include "libcef/browser/net/net_util.h"
#include "libcef/browser/net/source_stream.h" #include "libcef/browser/net/source_stream.h"
#include "libcef/browser/net/url_request_user_data.h" #include "libcef/browser/net/url_request_user_data.h"
@ -504,7 +504,7 @@ bool CefNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
cefRequest->SetReadOnly(true); cefRequest->SetReadOnly(true);
CefCookie cefCookie; CefCookie cefCookie;
if (!CefCookieManagerImpl::GetCefCookie(cookie, cefCookie)) if (!CefCookieManagerOldImpl::GetCefCookie(cookie, cefCookie))
return true; return true;
return handler->CanSetCookie(browser.get(), frame, cefRequest.get(), return handler->CanSetCookie(browser.get(), frame, cefRequest.get(),

View File

@ -10,7 +10,7 @@
#include "include/cef_callback.h" #include "include/cef_callback.h"
#include "include/cef_parser.h" #include "include/cef_parser.h"
#include "libcef/browser/cookie_manager_impl.h" #include "libcef/browser/net/cookie_manager_old_impl.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/request_impl.h" #include "libcef/common/request_impl.h"
#include "libcef/common/response_impl.h" #include "libcef/common/response_impl.h"
@ -457,7 +457,7 @@ void CefResourceRequestJob::CheckCookiePolicyAndLoad(
net::CookieList::const_iterator it = cookie_list.begin(); net::CookieList::const_iterator it = cookie_list.begin();
for (; it != cookie_list.end(); ++it) { for (; it != cookie_list.end(); ++it) {
CefCookie cookie; CefCookie cookie;
if (!CefCookieManagerImpl::GetCefCookie(*it, cookie) || if (!CefCookieManagerOldImpl::GetCefCookie(*it, cookie) ||
!handler_->CanGetCookie(cookie)) { !handler_->CanGetCookie(cookie)) {
can_get_cookies = false; can_get_cookies = false;
break; break;
@ -556,8 +556,8 @@ void CefResourceRequestJob::SaveNextCookie() {
bool can_set_cookie = cookie && CanSetCookie(*cookie, &options); bool can_set_cookie = cookie && CanSetCookie(*cookie, &options);
if (can_set_cookie) { if (can_set_cookie) {
CefCookie cef_cookie; CefCookie cef_cookie;
if (CefCookieManagerImpl::GetCefCookie(request_->url(), cookie_line, if (CefCookieManagerOldImpl::GetCefCookie(request_->url(), cookie_line,
cef_cookie)) { cef_cookie)) {
can_set_cookie = handler_->CanSetCookie(cef_cookie); can_set_cookie = handler_->CanSetCookie(cef_cookie);
} else { } else {
can_set_cookie = false; can_set_cookie = false;

View File

@ -9,7 +9,7 @@
#include <vector> #include <vector>
#include "libcef/browser/content_browser_client.h" #include "libcef/browser/content_browser_client.h"
#include "libcef/browser/cookie_manager_impl.h" #include "libcef/browser/net/cookie_manager_old_impl.h"
#include "libcef/browser/net/network_delegate.h" #include "libcef/browser/net/network_delegate.h"
#include "libcef/browser/net/scheme_handler.h" #include "libcef/browser/net/scheme_handler.h"
#include "libcef/browser/net/url_request_interceptor.h" #include "libcef/browser/net/url_request_interceptor.h"
@ -484,7 +484,7 @@ void CefURLRequestContextGetter::SetCookieSupportedSchemes(
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
io_state_->cookie_supported_schemes_ = schemes; io_state_->cookie_supported_schemes_ = schemes;
CefCookieManagerImpl::SetCookieMonsterSchemes( CefCookieManagerOldImpl::SetCookieMonsterSchemes(
static_cast<net::CookieMonster*>(GetExistingCookieStore()), static_cast<net::CookieMonster*>(GetExistingCookieStore()),
io_state_->cookie_supported_schemes_); io_state_->cookie_supported_schemes_);
} }
@ -548,7 +548,7 @@ void CefURLRequestContextGetter::SetCookieStoragePath(
io_state_->cookie_store_path_ = path; io_state_->cookie_store_path_ = path;
// Restore the previously supported schemes. // Restore the previously supported schemes.
CefCookieManagerImpl::SetCookieMonsterSchemes( CefCookieManagerOldImpl::SetCookieMonsterSchemes(
cookie_monster.get(), io_state_->cookie_supported_schemes_); cookie_monster.get(), io_state_->cookie_supported_schemes_);
io_state_->storage_->set_cookie_store(std::move(cookie_monster)); io_state_->storage_->set_cookie_store(std::move(cookie_monster));

View File

@ -0,0 +1,285 @@
// Copyright (c) 2019 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_service/cookie_manager_impl.h"
#include "libcef/common/time_util.h"
#include "base/bind.h"
#include "base/logging.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"
#include "url/gurl.h"
using network::mojom::CookieManager;
namespace {
// Do not keep a reference to the CookieManager returned by this method.
CookieManager* GetCookieManager(CefRequestContextImpl* request_context) {
CEF_REQUIRE_UIT();
return content::BrowserContext::GetDefaultStoragePartition(
request_context->GetBrowserContext())
->GetCookieManagerForBrowserProcess();
}
// Always execute the callback asynchronously.
void RunAsyncCompletionOnIOThread(CefRefPtr<CefCompletionCallback> callback) {
if (!callback.get())
return;
CEF_POST_TASK(CEF_IOT,
base::Bind(&CefCompletionCallback::OnComplete, callback.get()));
}
// Always execute the callback asynchronously.
void SetCookieCallbackImpl(CefRefPtr<CefSetCookieCallback> callback,
bool success) {
if (!callback.get())
return;
CEF_POST_TASK(CEF_IOT, base::Bind(&CefSetCookieCallback::OnComplete,
callback.get(), success));
}
// Always execute the callback asynchronously.
void DeleteCookiesCallbackImpl(CefRefPtr<CefDeleteCookiesCallback> callback,
uint32_t num_deleted) {
if (!callback.get())
return;
CEF_POST_TASK(CEF_IOT, base::Bind(&CefDeleteCookiesCallback::OnComplete,
callback.get(), num_deleted));
}
void GetCefCookie(const net::CanonicalCookie& cc, CefCookie& cookie) {
CefString(&cookie.name).FromString(cc.Name());
CefString(&cookie.value).FromString(cc.Value());
CefString(&cookie.domain).FromString(cc.Domain());
CefString(&cookie.path).FromString(cc.Path());
cookie.secure = cc.IsSecure();
cookie.httponly = cc.IsHttpOnly();
cef_time_from_basetime(cc.CreationDate(), cookie.creation);
cef_time_from_basetime(cc.LastAccessDate(), cookie.last_access);
cookie.has_expires = cc.IsPersistent();
if (cookie.has_expires)
cef_time_from_basetime(cc.ExpiryDate(), cookie.expires);
}
void DeleteCanonicalCookie(CefRefPtr<CefRequestContextImpl> request_context,
const net::CanonicalCookie& cc) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT,
base::Bind(&DeleteCanonicalCookie, request_context, cc));
return;
}
GetCookieManager(request_context.get())
->DeleteCanonicalCookie(cc,
CookieManager::DeleteCanonicalCookieCallback());
}
void ExecuteVisitor(CefRefPtr<CefCookieVisitor> visitor,
CefRefPtr<CefRequestContextImpl> request_context,
const std::vector<net::CanonicalCookie>& cookies) {
CEF_REQUIRE_IOT();
int total = cookies.size(), count = 0;
for (const auto& cc : cookies) {
CefCookie cookie;
GetCefCookie(cc, cookie);
bool deleteCookie = false;
bool keepLooping = visitor->Visit(cookie, count, total, deleteCookie);
if (deleteCookie) {
DeleteCanonicalCookie(request_context, cc);
}
if (!keepLooping)
break;
count++;
}
}
// Always execute the callback asynchronously.
void GetCookiesCallbackImpl(CefRefPtr<CefCookieVisitor> visitor,
CefRefPtr<CefRequestContextImpl> request_context,
const std::vector<net::CanonicalCookie>& cookies) {
CEF_POST_TASK(CEF_IOT,
base::Bind(&ExecuteVisitor, visitor, request_context, cookies));
}
} // namespace
CefCookieManagerImpl::CefCookieManagerImpl() {}
void CefCookieManagerImpl::Initialize(
CefRefPtr<CefRequestContextImpl> request_context,
CefRefPtr<CefCompletionCallback> callback) {
DCHECK(request_context);
DCHECK(!request_context_);
request_context_ = request_context;
RunAsyncCompletionOnIOThread(callback);
}
void CefCookieManagerImpl::SetSupportedSchemes(
const std::vector<CefString>& schemes,
CefRefPtr<CefCompletionCallback> callback) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT,
base::Bind(&CefCookieManagerImpl::SetSupportedSchemes, this,
schemes, callback));
return;
}
// TODO(network): Figure out how to route this to
// CookieMonster::SetCookieableSchemes via the NetworkService.
NOTIMPLEMENTED();
RunAsyncCompletionOnIOThread(callback);
}
bool CefCookieManagerImpl::VisitAllCookies(
CefRefPtr<CefCookieVisitor> visitor) {
if (!visitor.get())
return false;
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(
CEF_UIT,
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::VisitAllCookies),
this, visitor));
return true;
}
GetCookieManager(request_context_.get())
->GetAllCookies(
base::Bind(&GetCookiesCallbackImpl, visitor, request_context_));
return true;
}
bool CefCookieManagerImpl::VisitUrlCookies(
const CefString& url,
bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor) {
if (!visitor.get())
return false;
GURL gurl = GURL(url.ToString());
if (!gurl.is_valid())
return false;
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(
CEF_UIT,
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::VisitUrlCookies),
this, url, includeHttpOnly, visitor));
return true;
}
net::CookieOptions options;
if (includeHttpOnly)
options.set_include_httponly();
GetCookieManager(request_context_.get())
->GetCookieList(
gurl, options,
base::Bind(&GetCookiesCallbackImpl, visitor, request_context_));
return true;
}
bool CefCookieManagerImpl::SetCookie(const CefString& url,
const CefCookie& cookie,
CefRefPtr<CefSetCookieCallback> callback) {
GURL gurl = GURL(url.ToString());
if (!gurl.is_valid())
return false;
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(
CEF_UIT,
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::SetCookie), this,
url, cookie, callback));
return true;
}
std::string name = CefString(&cookie.name).ToString();
std::string value = CefString(&cookie.value).ToString();
std::string domain = CefString(&cookie.domain).ToString();
std::string path = CefString(&cookie.path).ToString();
base::Time expiration_time;
if (cookie.has_expires)
cef_time_to_basetime(cookie.expires, expiration_time);
auto canonical_cookie = net::CanonicalCookie::CreateSanitizedCookie(
gurl, name, value, domain, path,
base::Time(), // Creation time.
expiration_time,
base::Time(), // Last access time.
cookie.secure ? true : false, cookie.httponly ? true : false,
net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT);
GetCookieManager(request_context_.get())
->SetCanonicalCookie(*canonical_cookie, gurl.scheme(),
cookie.httponly ? true : false,
base::Bind(SetCookieCallbackImpl, callback));
return true;
}
bool CefCookieManagerImpl::DeleteCookies(
const CefString& url,
const CefString& cookie_name,
CefRefPtr<CefDeleteCookiesCallback> callback) {
// Empty URLs are allowed but not invalid URLs.
GURL gurl = GURL(url.ToString());
if (!gurl.is_empty() && !gurl.is_valid())
return false;
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(
CEF_UIT,
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::DeleteCookies),
this, url, cookie_name, callback));
return true;
}
network::mojom::CookieDeletionFilterPtr deletion_filter =
network::mojom::CookieDeletionFilter::New();
if (gurl.is_empty()) {
// Delete all cookies.
} else if (cookie_name.empty()) {
// Delete all matching host cookies.
deletion_filter->host_name = gurl.host();
} else {
// Delete all matching host and domain cookies.
deletion_filter->url = gurl;
deletion_filter->cookie_name = cookie_name;
}
GetCookieManager(request_context_.get())
->DeleteCookies(std::move(deletion_filter),
base::Bind(DeleteCookiesCallbackImpl, callback));
return true;
}
bool CefCookieManagerImpl::FlushStore(
CefRefPtr<CefCompletionCallback> callback) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(
CEF_UIT,
base::Bind(base::IgnoreResult(&CefCookieManagerImpl::FlushStore), this,
callback));
return true;
}
GetCookieManager(request_context_.get())
->FlushCookieStore(base::Bind(RunAsyncCompletionOnIOThread, callback));
return true;
}
// CefCookieManager methods ----------------------------------------------------
// static
CefRefPtr<CefCookieManager> CefCookieManager::GetGlobalManager(
CefRefPtr<CefCompletionCallback> callback) {
CefRefPtr<CefRequestContext> context = CefRequestContext::GetGlobalContext();
return context ? context->GetCookieManager(callback) : nullptr;
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2019 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_SERVICE_COOKIE_MANAGER_IMPL_H_
#define CEF_LIBCEF_BROWSER_NET_SERVICE_COOKIE_MANAGER_IMPL_H_
#include "include/cef_cookie.h"
#include "libcef/browser/request_context_impl.h"
#include "libcef/browser/thread_util.h"
#include "base/files/file_path.h"
// Implementation of the CefCookieManager interface.
class CefCookieManagerImpl : public CefCookieManager {
public:
CefCookieManagerImpl();
// Must be called immediately after this object is created when |is_blocking|
// is false.
void Initialize(CefRefPtr<CefRequestContextImpl> request_context,
CefRefPtr<CefCompletionCallback> callback);
// CefCookieManager methods.
void SetSupportedSchemes(const std::vector<CefString>& schemes,
CefRefPtr<CefCompletionCallback> callback) override;
bool VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor) override;
bool VisitUrlCookies(const CefString& url,
bool includeHttpOnly,
CefRefPtr<CefCookieVisitor> visitor) override;
bool SetCookie(const CefString& url,
const CefCookie& cookie,
CefRefPtr<CefSetCookieCallback> callback) override;
bool DeleteCookies(const CefString& url,
const CefString& cookie_name,
CefRefPtr<CefDeleteCookiesCallback> callback) override;
bool FlushStore(CefRefPtr<CefCompletionCallback> callback) override;
private:
// Context that owns the cookie manager.
CefRefPtr<CefRequestContextImpl> request_context_;
IMPLEMENT_REFCOUNTING(CefCookieManagerImpl);
};
#endif // CEF_LIBCEF_BROWSER_NET_SERVICE_COOKIE_MANAGER_IMPL_H_

View File

@ -6,8 +6,9 @@
#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_context.h"
#include "libcef/browser/content_browser_client.h" #include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h" #include "libcef/browser/context.h"
#include "libcef/browser/cookie_manager_impl.h"
#include "libcef/browser/extensions/extension_system.h" #include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/net/cookie_manager_old_impl.h"
#include "libcef/browser/net_service/cookie_manager_impl.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/extensions/extensions_util.h" #include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/net_service/util.h" #include "libcef/common/net_service/util.h"
@ -281,9 +282,16 @@ CefString CefRequestContextImpl::GetCachePath() {
CefRefPtr<CefCookieManager> CefRequestContextImpl::GetCookieManager( CefRefPtr<CefCookieManager> CefRequestContextImpl::GetCookieManager(
CefRefPtr<CefCompletionCallback> callback) { CefRefPtr<CefCompletionCallback> callback) {
CefRefPtr<CefCookieManagerImpl> cookie_manager = new CefCookieManagerImpl(); if (!net_service::IsEnabled()) {
cookie_manager->Initialize(this, CefString(), false, callback); CefRefPtr<CefCookieManagerOldImpl> cookie_manager =
return cookie_manager.get(); new CefCookieManagerOldImpl();
cookie_manager->Initialize(this, CefString(), false, callback);
return cookie_manager.get();
} else {
CefRefPtr<CefCookieManagerImpl> cookie_manager = new CefCookieManagerImpl();
cookie_manager->Initialize(this, callback);
return cookie_manager.get();
}
} }
bool CefRequestContextImpl::RegisterSchemeHandlerFactory( bool CefRequestContextImpl::RegisterSchemeHandlerFactory(