Fix crash using CefCookieManager::SetStoragePath (issue #2522)
This commit is contained in:
parent
da53451f97
commit
1928572b52
2
BUILD.gn
2
BUILD.gn
|
@ -405,6 +405,8 @@ static_library("libcef_static") {
|
||||||
"libcef/browser/net/chrome_scheme_handler.h",
|
"libcef/browser/net/chrome_scheme_handler.h",
|
||||||
"libcef/browser/net/cookie_store_proxy.cc",
|
"libcef/browser/net/cookie_store_proxy.cc",
|
||||||
"libcef/browser/net/cookie_store_proxy.h",
|
"libcef/browser/net/cookie_store_proxy.h",
|
||||||
|
"libcef/browser/net/cookie_store_source.cc",
|
||||||
|
"libcef/browser/net/cookie_store_source.h",
|
||||||
"libcef/browser/net/crlset_file_util_impl.cc",
|
"libcef/browser/net/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",
|
||||||
|
|
|
@ -10,12 +10,12 @@
|
||||||
|
|
||||||
#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/cookie_store_source.h"
|
||||||
#include "libcef/browser/net/network_delegate.h"
|
#include "libcef/browser/net/network_delegate.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"
|
||||||
|
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "base/files/file_util.h"
|
|
||||||
#include "base/format_macros.h"
|
#include "base/format_macros.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/threading/thread_restrictions.h"
|
#include "base/threading/thread_restrictions.h"
|
||||||
|
@ -25,7 +25,6 @@
|
||||||
#include "content/public/browser/browser_task_traits.h"
|
#include "content/public/browser/browser_task_traits.h"
|
||||||
#include "net/cookies/cookie_util.h"
|
#include "net/cookies/cookie_util.h"
|
||||||
#include "net/cookies/parsed_cookie.h"
|
#include "net/cookies/parsed_cookie.h"
|
||||||
#include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
|
|
||||||
#include "net/url_request/url_request_context.h"
|
#include "net/url_request/url_request_context.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
|
|
||||||
|
@ -165,7 +164,7 @@ void CefCookieManagerImpl::GetCookieStore(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DCHECK(is_blocking_ || cookie_store_.get());
|
DCHECK(is_blocking_ || cookie_source_);
|
||||||
|
|
||||||
// Binding ref-counted |this| to CookieStoreGetter may result in
|
// Binding ref-counted |this| to CookieStoreGetter may result in
|
||||||
// heap-use-after-free if (a) the CookieStoreGetter contains the last
|
// heap-use-after-free if (a) the CookieStoreGetter contains the last
|
||||||
|
@ -188,8 +187,8 @@ void CefCookieManagerImpl::GetCookieStore(
|
||||||
|
|
||||||
net::CookieStore* CefCookieManagerImpl::GetExistingCookieStore() {
|
net::CookieStore* CefCookieManagerImpl::GetExistingCookieStore() {
|
||||||
CEF_REQUIRE_IOT();
|
CEF_REQUIRE_IOT();
|
||||||
if (cookie_store_.get()) {
|
if (cookie_source_) {
|
||||||
return cookie_store_.get();
|
return cookie_source_->GetCookieStore();
|
||||||
} else if (request_context_impl_.get()) {
|
} else if (request_context_impl_.get()) {
|
||||||
net::CookieStore* cookie_store =
|
net::CookieStore* cookie_store =
|
||||||
request_context_impl_->GetExistingCookieStore();
|
request_context_impl_->GetExistingCookieStore();
|
||||||
|
@ -294,46 +293,14 @@ bool CefCookieManagerImpl::SetStoragePath(
|
||||||
if (!path.empty())
|
if (!path.empty())
|
||||||
new_path = base::FilePath(path);
|
new_path = base::FilePath(path);
|
||||||
|
|
||||||
if (cookie_store_.get() &&
|
if (!cookie_source_) {
|
||||||
((storage_path_.empty() && path.empty()) || storage_path_ == new_path)) {
|
cookie_source_.reset(new CefCookieStoreOwnerSource());
|
||||||
// The path has not changed so don't do anything.
|
|
||||||
RunAsyncCompletionOnIOThread(callback);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scoped_refptr<net::SQLitePersistentCookieStore> persistent_store;
|
cookie_source_->SetCookieStoragePath(new_path, persist_session_cookies,
|
||||||
if (!new_path.empty()) {
|
g_browser_process->net_log());
|
||||||
// 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(new_path) || base::CreateDirectory(new_path)) {
|
|
||||||
const base::FilePath& cookie_path = new_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, nullptr);
|
|
||||||
} else {
|
|
||||||
NOTREACHED() << "The cookie storage directory could not be created";
|
|
||||||
storage_path_.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
cookie_store_.reset(new net::CookieMonster(persistent_store.get(), nullptr,
|
|
||||||
g_browser_process->net_log()));
|
|
||||||
if (persistent_store.get() && persist_session_cookies)
|
|
||||||
cookie_store_->SetPersistSessionCookies(true);
|
|
||||||
storage_path_ = new_path;
|
|
||||||
|
|
||||||
// Restore the previously supported schemes.
|
|
||||||
SetSupportedSchemesInternal(supported_schemes_, callback);
|
|
||||||
|
|
||||||
|
RunAsyncCompletionOnIOThread(callback);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,10 +479,9 @@ void CefCookieManagerImpl::SetSupportedSchemesInternal(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DCHECK(is_blocking_ || cookie_store_.get());
|
DCHECK(is_blocking_ || cookie_source_);
|
||||||
if (cookie_store_) {
|
if (cookie_source_) {
|
||||||
supported_schemes_ = schemes;
|
cookie_source_->SetCookieSupportedSchemes(schemes);
|
||||||
SetCookieMonsterSchemes(cookie_store_.get(), supported_schemes_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RunAsyncCompletionOnIOThread(callback);
|
RunAsyncCompletionOnIOThread(callback);
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "net/cookies/cookie_monster.h"
|
#include "net/cookies/cookie_monster.h"
|
||||||
|
|
||||||
|
class CefCookieStoreOwnerSource;
|
||||||
|
|
||||||
// Implementation of the CefCookieManager interface.
|
// Implementation of the CefCookieManager interface.
|
||||||
class CefCookieManagerImpl : public CefCookieManager {
|
class CefCookieManagerImpl : public CefCookieManager {
|
||||||
public:
|
public:
|
||||||
|
@ -122,9 +124,7 @@ class CefCookieManagerImpl : public CefCookieManager {
|
||||||
scoped_refptr<CefURLRequestContextGetterImpl> request_context_impl_;
|
scoped_refptr<CefURLRequestContextGetterImpl> request_context_impl_;
|
||||||
|
|
||||||
// Used for cookie monsters owned by this object.
|
// Used for cookie monsters owned by this object.
|
||||||
base::FilePath storage_path_;
|
std::unique_ptr<CefCookieStoreOwnerSource> cookie_source_;
|
||||||
std::vector<std::string> supported_schemes_;
|
|
||||||
std::unique_ptr<net::CookieMonster> cookie_store_;
|
|
||||||
|
|
||||||
// Must be the last member.
|
// Must be the last member.
|
||||||
base::WeakPtrFactory<CefCookieManagerImpl> weak_ptr_factory_;
|
base::WeakPtrFactory<CefCookieManagerImpl> weak_ptr_factory_;
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
|
|
||||||
#include "libcef/browser/net/cookie_store_proxy.h"
|
#include "libcef/browser/net/cookie_store_proxy.h"
|
||||||
|
|
||||||
#include "libcef/browser/cookie_manager_impl.h"
|
#include "include/cef_request_context.h"
|
||||||
#include "libcef/browser/net/url_request_context_impl.h"
|
#include "libcef/browser/net/cookie_store_source.h"
|
||||||
#include "libcef/browser/thread_util.h"
|
#include "libcef/browser/thread_util.h"
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "net/url_request/url_request_context.h"
|
#include "net/cookies/cookie_change_dispatcher.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -44,12 +44,10 @@ class NullCookieChangeDispatcher : public net::CookieChangeDispatcher {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
CefCookieStoreProxy::CefCookieStoreProxy(
|
CefCookieStoreProxy::CefCookieStoreProxy(
|
||||||
CefURLRequestContextImpl* parent,
|
std::unique_ptr<CefCookieStoreSource> source)
|
||||||
CefRefPtr<CefRequestContextHandler> handler)
|
: source_(std::move(source)) {
|
||||||
: parent_(parent), handler_(handler) {
|
|
||||||
CEF_REQUIRE_IOT();
|
CEF_REQUIRE_IOT();
|
||||||
DCHECK(parent_);
|
DCHECK(source_);
|
||||||
DCHECK(handler_.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CefCookieStoreProxy::~CefCookieStoreProxy() {
|
CefCookieStoreProxy::~CefCookieStoreProxy() {
|
||||||
|
@ -189,24 +187,5 @@ bool CefCookieStoreProxy::IsEphemeral() {
|
||||||
|
|
||||||
net::CookieStore* CefCookieStoreProxy::GetCookieStore() {
|
net::CookieStore* CefCookieStoreProxy::GetCookieStore() {
|
||||||
CEF_REQUIRE_IOT();
|
CEF_REQUIRE_IOT();
|
||||||
|
return source_->GetCookieStore();
|
||||||
CefRefPtr<CefCookieManager> manager = handler_->GetCookieManager();
|
|
||||||
if (manager.get()) {
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,19 +6,15 @@
|
||||||
#define CEF_LIBCEF_BROWSER_COOKIE_STORE_PROXY_H_
|
#define CEF_LIBCEF_BROWSER_COOKIE_STORE_PROXY_H_
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "include/cef_request_context_handler.h"
|
|
||||||
|
|
||||||
#include "net/cookies/cookie_store.h"
|
#include "net/cookies/cookie_store.h"
|
||||||
|
|
||||||
class CefURLRequestContextImpl;
|
class CefCookieStoreSource;
|
||||||
|
|
||||||
// Proxies cookie requests to the CefRequestContextHandler or global cookie
|
// Proxies cookie requests to a CefCookieStoreSource (see comments on the
|
||||||
// store. Life span is controlled by CefURLRequestContextProxy. Only accessed on
|
// implementation classes for details). Only accessed on the IO thread.
|
||||||
// the IO thread. See browser_context.h for an object relationship diagram.
|
|
||||||
class CefCookieStoreProxy : public net::CookieStore {
|
class CefCookieStoreProxy : public net::CookieStore {
|
||||||
public:
|
public:
|
||||||
CefCookieStoreProxy(CefURLRequestContextImpl* parent,
|
explicit CefCookieStoreProxy(std::unique_ptr<CefCookieStoreSource> source);
|
||||||
CefRefPtr<CefRequestContextHandler> handler);
|
|
||||||
~CefCookieStoreProxy() override;
|
~CefCookieStoreProxy() override;
|
||||||
|
|
||||||
// net::CookieStore methods.
|
// net::CookieStore methods.
|
||||||
|
@ -52,11 +48,7 @@ class CefCookieStoreProxy : public net::CookieStore {
|
||||||
private:
|
private:
|
||||||
net::CookieStore* GetCookieStore();
|
net::CookieStore* GetCookieStore();
|
||||||
|
|
||||||
// The |parent_| pointer is kept alive by CefURLRequestContextGetterProxy
|
std::unique_ptr<CefCookieStoreSource> const source_;
|
||||||
// which has a ref to the owning CefURLRequestContextGetterImpl.
|
|
||||||
CefURLRequestContextImpl* parent_;
|
|
||||||
CefRefPtr<CefRequestContextHandler> handler_;
|
|
||||||
|
|
||||||
std::unique_ptr<net::CookieChangeDispatcher> null_dispatcher_;
|
std::unique_ptr<net::CookieChangeDispatcher> null_dispatcher_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CefCookieStoreProxy);
|
DISALLOW_COPY_AND_ASSIGN(CefCookieStoreProxy);
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
// 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();
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
// 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_
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include "libcef/browser/content_browser_client.h"
|
#include "libcef/browser/content_browser_client.h"
|
||||||
#include "libcef/browser/cookie_manager_impl.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/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"
|
||||||
|
@ -18,7 +20,6 @@
|
||||||
#include "libcef/common/content_client.h"
|
#include "libcef/common/content_client.h"
|
||||||
|
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
#include "base/files/file_util.h"
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/memory/ptr_util.h"
|
#include "base/memory/ptr_util.h"
|
||||||
#include "base/stl_util.h"
|
#include "base/stl_util.h"
|
||||||
|
@ -44,7 +45,6 @@
|
||||||
#include "net/cert/multi_log_ct_verifier.h"
|
#include "net/cert/multi_log_ct_verifier.h"
|
||||||
#include "net/cookies/cookie_monster.h"
|
#include "net/cookies/cookie_monster.h"
|
||||||
#include "net/dns/host_resolver.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/ftp/ftp_network_layer.h"
|
||||||
#include "net/http/http_auth_handler_factory.h"
|
#include "net/http/http_auth_handler_factory.h"
|
||||||
#include "net/http/http_auth_preferences.h"
|
#include "net/http/http_auth_preferences.h"
|
||||||
|
@ -474,58 +474,21 @@ void CefURLRequestContextGetterImpl::SetCookieStoragePath(
|
||||||
const base::FilePath& path,
|
const base::FilePath& path,
|
||||||
bool persist_session_cookies) {
|
bool persist_session_cookies) {
|
||||||
CEF_REQUIRE_IOT();
|
CEF_REQUIRE_IOT();
|
||||||
|
if (!io_state_->cookie_source_) {
|
||||||
if (io_state_->url_request_context_->cookie_store() &&
|
// Use a proxy because we can't change the URLRequestContext's CookieStore
|
||||||
((io_state_->cookie_store_path_.empty() && path.empty()) ||
|
// during runtime.
|
||||||
io_state_->cookie_store_path_ == path)) {
|
io_state_->cookie_source_ = new CefCookieStoreOwnerSource();
|
||||||
// The path has not changed so don't do anything.
|
io_state_->storage_->set_cookie_store(std::make_unique<CefCookieStoreProxy>(
|
||||||
return;
|
base::WrapUnique(io_state_->cookie_source_)));
|
||||||
}
|
}
|
||||||
|
io_state_->cookie_source_->SetCookieStoragePath(path, persist_session_cookies,
|
||||||
scoped_refptr<net::SQLitePersistentCookieStore> persistent_store;
|
io_state_->net_log_);
|
||||||
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 CefURLRequestContextGetterImpl::SetCookieSupportedSchemes(
|
void CefURLRequestContextGetterImpl::SetCookieSupportedSchemes(
|
||||||
const std::vector<std::string>& schemes) {
|
const std::vector<std::string>& schemes) {
|
||||||
CEF_REQUIRE_IOT();
|
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 CefURLRequestContextGetterImpl::AddHandler(
|
||||||
|
@ -542,9 +505,8 @@ void CefURLRequestContextGetterImpl::AddHandler(
|
||||||
net::CookieStore* CefURLRequestContextGetterImpl::GetExistingCookieStore()
|
net::CookieStore* CefURLRequestContextGetterImpl::GetExistingCookieStore()
|
||||||
const {
|
const {
|
||||||
CEF_REQUIRE_IOT();
|
CEF_REQUIRE_IOT();
|
||||||
if (io_state_->url_request_context_ &&
|
if (io_state_->cookie_source_) {
|
||||||
io_state_->url_request_context_->cookie_store()) {
|
return io_state_->cookie_source_->GetCookieStore();
|
||||||
return io_state_->url_request_context_->cookie_store();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(ERROR) << "Cookie store does not exist";
|
LOG(ERROR) << "Cookie store does not exist";
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "content/public/browser/browser_context.h"
|
#include "content/public/browser/browser_context.h"
|
||||||
#include "net/url_request/url_request_job_factory.h"
|
#include "net/url_request/url_request_job_factory.h"
|
||||||
|
|
||||||
|
class CefCookieStoreOwnerSource;
|
||||||
class PrefRegistrySimple;
|
class PrefRegistrySimple;
|
||||||
class PrefService;
|
class PrefService;
|
||||||
|
|
||||||
|
@ -113,8 +114,8 @@ class CefURLRequestContextGetterImpl : public CefURLRequestContextGetter {
|
||||||
content::ProtocolHandlerMap protocol_handlers_;
|
content::ProtocolHandlerMap protocol_handlers_;
|
||||||
content::URLRequestInterceptorScopedVector request_interceptors_;
|
content::URLRequestInterceptorScopedVector request_interceptors_;
|
||||||
|
|
||||||
base::FilePath cookie_store_path_;
|
// Owned by the URLRequestContextStorage.
|
||||||
std::vector<std::string> cookie_supported_schemes_;
|
CefCookieStoreOwnerSource* cookie_source_ = nullptr;
|
||||||
|
|
||||||
std::vector<CefRefPtr<CefRequestContextHandler>> handler_list_;
|
std::vector<CefRefPtr<CefRequestContextHandler>> handler_list_;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "libcef/browser/net/url_request_context_proxy.h"
|
#include "libcef/browser/net/url_request_context_proxy.h"
|
||||||
|
|
||||||
#include "libcef/browser/net/cookie_store_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/net/url_request_context_impl.h"
|
||||||
#include "libcef/browser/thread_util.h"
|
#include "libcef/browser/thread_util.h"
|
||||||
|
|
||||||
|
@ -16,7 +17,8 @@ CefURLRequestContextProxy::CefURLRequestContextProxy(
|
||||||
DCHECK(handler.get());
|
DCHECK(handler.get());
|
||||||
|
|
||||||
// Cookie store that proxies to the browser implementation.
|
// Cookie store that proxies to the browser implementation.
|
||||||
cookie_store_proxy_.reset(new CefCookieStoreProxy(parent, handler));
|
cookie_store_proxy_.reset(new CefCookieStoreProxy(
|
||||||
|
std::make_unique<CefCookieStoreHandlerSource>(parent, handler)));
|
||||||
set_cookie_store(cookie_store_proxy_.get());
|
set_cookie_store(cookie_store_proxy_.get());
|
||||||
|
|
||||||
// All other values refer to the parent request context.
|
// All other values refer to the parent request context.
|
||||||
|
|
Loading…
Reference in New Issue