Merge pull request #14107 from electron/channel_id_patch

fix: create persistent channel ID store when cookie store is persistent
This commit is contained in:
John Kleinschmidt 2018-08-28 14:10:04 -04:00 committed by GitHub
commit 98b7a9ce9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 12 deletions

View file

@ -13,6 +13,7 @@ static_library("brightray") {
"//components/prefs",
"//content/public/browser",
"//content/shell:resources",
"//net:extras",
"//net:net_with_v8",
"//skia",
"//ui/views",

View file

@ -112,6 +112,7 @@
'libraries': [
# Following libraries are always linked statically.
'<(libchromiumcontent_dir)/libbase_static.a',
'<(libchromiumcontent_dir)/libextras.a',
'<(libchromiumcontent_dir)/libgtkui.a',
'<(libchromiumcontent_dir)/libhttp_server.a',
'<(libchromiumcontent_dir)/libdevice_service.a',
@ -206,6 +207,7 @@
'libraries': [
# Following libraries are always linked statically.
'<(libchromiumcontent_dir)/libbase_static.a',
'<(libchromiumcontent_dir)/libextras.a',
'<(libchromiumcontent_dir)/libhttp_server.a',
'<(libchromiumcontent_dir)/libdevice_service.a',
'<(libchromiumcontent_dir)/libdom_keycode_converter.a',
@ -342,6 +344,7 @@
'-ldxgi.lib',
# Following libs are always linked statically.
'<(libchromiumcontent_dir)/base_static.lib',
'<(libchromiumcontent_dir)/extras.lib',
'<(libchromiumcontent_dir)/sandbox.lib',
'<(libchromiumcontent_dir)/sandbox_helper_win.lib',
'<(libchromiumcontent_dir)/http_server.lib',

View file

@ -30,6 +30,7 @@
#include "net/cookies/cookie_monster.h"
#include "net/cookies/cookie_store.h"
#include "net/dns/mapped_host_resolver.h"
#include "net/extras/sqlite/sqlite_channel_id_store.h"
#include "net/http/http_auth_filter.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_auth_preferences.h"
@ -215,29 +216,46 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
storage_->set_network_delegate(delegate_->CreateNetworkDelegate());
std::unique_ptr<net::CookieStore> cookie_store;
scoped_refptr<net::SQLiteChannelIDStore> channel_id_db;
// Create a single task runner to use with the CookieStore and
// ChannelIDStore.
scoped_refptr<base::SequencedTaskRunner> cookie_background_task_runner =
base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN});
auto cookie_path = in_memory_
? base::FilePath()
: base_path_.Append(FILE_PATH_LITERAL("Cookies"));
std::unique_ptr<net::CookieStore> cookie_store = content::CreateCookieStore(
content::CookieStoreConfig(cookie_path, false, false, nullptr));
storage_->set_cookie_store(std::move(cookie_store));
if (!in_memory_) {
channel_id_db = new net::SQLiteChannelIDStore(
base_path_.Append(FILE_PATH_LITERAL("Origin Bound Certs")),
cookie_background_task_runner);
}
std::unique_ptr<net::ChannelIDService> channel_id_service(
new net::ChannelIDService(
new net::DefaultChannelIDStore(channel_id_db.get())));
content::CookieStoreConfig cookie_config(cookie_path, false, false,
nullptr);
cookie_config.channel_id_service = channel_id_service.get();
cookie_config.background_task_runner = cookie_background_task_runner;
cookie_store = content::CreateCookieStore(cookie_config);
cookie_store->SetChannelIDServiceID(channel_id_service->GetUniqueID());
// Set custom schemes that can accept cookies.
net::CookieMonster* cookie_monster =
static_cast<net::CookieMonster*>(url_request_context_->cookie_store());
static_cast<net::CookieMonster*>(cookie_store.get());
std::vector<std::string> cookie_schemes({"http", "https", "ws", "wss"});
delegate_->GetCookieableSchemes(&cookie_schemes);
cookie_monster->SetCookieableSchemes(cookie_schemes);
// Cookie store will outlive notifier by order of declaration
// in the header.
cookie_change_sub_ = url_request_context_->cookie_store()
->GetChangeDispatcher()
.AddCallbackForAllChanges(base::Bind(
&URLRequestContextGetter::OnCookieChanged,
base::RetainedRef(this)));
storage_->set_channel_id_service(std::make_unique<net::ChannelIDService>(
new net::DefaultChannelIDStore(nullptr)));
cookie_change_sub_ =
cookie_store->GetChangeDispatcher().AddCallbackForAllChanges(
base::Bind(&URLRequestContextGetter::OnCookieChanged,
base::RetainedRef(this)));
storage_->set_cookie_store(std::move(cookie_store));
storage_->set_channel_id_service(std::move(channel_id_service));
storage_->set_http_user_agent_settings(
base::WrapUnique(new net::StaticHttpUserAgentSettings(