diff --git chrome/browser/net/profile_network_context_service.cc chrome/browser/net/profile_network_context_service.cc index 2b24d1ac1b5b..6577495d87a9 100644 --- chrome/browser/net/profile_network_context_service.cc +++ chrome/browser/net/profile_network_context_service.cc @@ -14,6 +14,7 @@ #include "base/logging.h" #include "base/metrics/histogram_macros.h" #include "base/task/post_task.h" +#include "cef/libcef/features/features.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h" @@ -411,16 +412,23 @@ ProfileNetworkContextService::CreateNetworkContextParams( CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings); network_context_params->cookie_manager_params->settings = std::move(settings); + network_context_params->cookieable_schemes = profile_->GetCookieableSchemes(); + // Configure on-disk storage for non-OTR profiles. OTR profiles just use // default behavior (in memory storage, default sizes). PrefService* prefs = profile_->GetPrefs(); if (!in_memory) { // Configure the HTTP cache path and size. base::FilePath base_cache_path; +#if BUILDFLAG(ENABLE_CEF) + base_cache_path = prefs->GetFilePath(prefs::kDiskCacheDir); + DCHECK(!base_cache_path.empty()); +#else chrome::GetUserCacheDirectory(path, &base_cache_path); base::FilePath disk_cache_dir = prefs->GetFilePath(prefs::kDiskCacheDir); if (!disk_cache_dir.empty()) base_cache_path = disk_cache_dir.Append(base_cache_path.BaseName()); +#endif network_context_params->http_cache_path = base_cache_path.Append(chrome::kCacheDirname); network_context_params->http_cache_max_size = diff --git chrome/browser/profiles/profile.h chrome/browser/profiles/profile.h index e77d8abd6601..88331e9af5e0 100644 --- chrome/browser/profiles/profile.h +++ chrome/browser/profiles/profile.h @@ -321,6 +321,11 @@ class Profile : public content::BrowserContext { virtual bool ShouldRestoreOldSessionCookies(); virtual bool ShouldPersistSessionCookies(); + // Returns schemes that should be cookieable, if other than the defaults. + virtual base::Optional> GetCookieableSchemes() { + return base::nullopt; + } + // Creates NetworkContext for the specified isolated app (or for the profile // itself, if |relative_path| is empty). virtual network::mojom::NetworkContextPtr CreateNetworkContext( diff --git net/cookies/cookie_monster.cc net/cookies/cookie_monster.cc index e7ad8df8817e..68ae3c88d6cc 100644 --- net/cookies/cookie_monster.cc +++ net/cookies/cookie_monster.cc @@ -508,6 +508,25 @@ void CookieMonster::SetCookieableSchemes( MaybeRunCookieCallback(std::move(callback), true); } +void CookieMonster::AddCookieableSchemes( + const std::vector& schemes, + SetCookieableSchemesCallback callback) { + DCHECK(thread_checker_.CalledOnValidThread()); + + // Calls to this method will have no effect if made after a WebView or + // CookieManager instance has been created. + if (initialized_) { + MaybeRunCookieCallback(std::move(callback), false); + return; + } + + if (!schemes.empty()) { + cookieable_schemes_.insert(cookieable_schemes_.begin(), schemes.begin(), + schemes.end()); + } + MaybeRunCookieCallback(std::move(callback), true); +} + // This function must be called before the CookieMonster is used. void CookieMonster::SetPersistSessionCookies(bool persist_session_cookies) { DCHECK(thread_checker_.CalledOnValidThread()); diff --git net/cookies/cookie_monster.h net/cookies/cookie_monster.h index 747b3789374a..d70c75ade666 100644 --- net/cookies/cookie_monster.h +++ net/cookies/cookie_monster.h @@ -176,6 +176,8 @@ class NET_EXPORT CookieMonster : public CookieStore { CookieChangeDispatcher& GetChangeDispatcher() override; void SetCookieableSchemes(const std::vector& schemes, SetCookieableSchemesCallback callback) override; + void AddCookieableSchemes(const std::vector& schemes, + SetCookieableSchemesCallback callback) override; // Enables writing session cookies into the cookie database. If this this // method is called, it must be called before first use of the instance diff --git net/cookies/cookie_store.h net/cookies/cookie_store.h index c1146a9e32f6..da1e54d423a7 100644 --- net/cookies/cookie_store.h +++ net/cookies/cookie_store.h @@ -145,6 +145,11 @@ class NET_EXPORT CookieStore { virtual void SetCookieableSchemes(const std::vector& schemes, SetCookieableSchemesCallback callback) = 0; + // Adds to the list of cookieable schemes. Does nothing if called after first + // use of the instance (i.e. after the instance initialization process). + virtual void AddCookieableSchemes(const std::vector& schemes, + SetCookieableSchemesCallback callback) = 0; + // Returns true if this cookie store is ephemeral, and false if it is backed // by some sort of persistence layer. // TODO(nharper): Remove this method once crbug.com/548423 has been closed. diff --git services/network/cookie_manager.cc services/network/cookie_manager.cc index 8be1b9dea5f7..30f23449ac51 100644 --- services/network/cookie_manager.cc +++ services/network/cookie_manager.cc @@ -214,14 +214,9 @@ void CookieManager::FlushCookieStore(FlushCookieStoreCallback callback) { void CookieManager::AllowFileSchemeCookies( bool allow, AllowFileSchemeCookiesCallback callback) { - std::vector cookieable_schemes( - net::CookieMonster::kDefaultCookieableSchemes, - net::CookieMonster::kDefaultCookieableSchemes + - net::CookieMonster::kDefaultCookieableSchemesCount); - if (allow) { - cookieable_schemes.push_back(url::kFileScheme); - } - cookie_store_->SetCookieableSchemes(cookieable_schemes, std::move(callback)); + if (!allow) + return; + cookie_store_->AddCookieableSchemes({url::kFileScheme}, std::move(callback)); } void CookieManager::SetForceKeepSessionState() { diff --git services/network/network_context.cc services/network/network_context.cc index 9d6f7b930e11..c16e5ca90c14 100644 --- services/network/network_context.cc +++ services/network/network_context.cc @@ -1742,6 +1742,7 @@ URLRequestContextOwner NetworkContext::ApplyContextParamsToBuilder( } scoped_refptr session_cleanup_cookie_store; + std::unique_ptr cookie_store; if (params_->cookie_path) { scoped_refptr client_task_runner = base::MessageLoopCurrent::Get()->task_runner(); @@ -1769,18 +1770,27 @@ URLRequestContextOwner NetworkContext::ApplyContextParamsToBuilder( session_cleanup_cookie_store = base::MakeRefCounted(sqlite_store); - std::unique_ptr cookie_store = + cookie_store = std::make_unique(session_cleanup_cookie_store.get(), net_log); if (params_->persist_session_cookies) cookie_store->SetPersistSessionCookies(true); - - builder->SetCookieStore(std::move(cookie_store)); } else { DCHECK(!params_->restore_old_session_cookies); DCHECK(!params_->persist_session_cookies); + + cookie_store = + std::make_unique(nullptr /* store */, net_log); } + if (params_->cookieable_schemes.has_value()) { + cookie_store->SetCookieableSchemes( + *params_->cookieable_schemes, + net::CookieStore::SetCookieableSchemesCallback()); + } + + builder->SetCookieStore(std::move(cookie_store)); + std::unique_ptr user_agent_settings = std::make_unique( params_->accept_language, params_->user_agent); diff --git services/network/public/mojom/network_context.mojom services/network/public/mojom/network_context.mojom index 9e29276e0e4c..9d5588efe7cf 100644 --- services/network/public/mojom/network_context.mojom +++ services/network/public/mojom/network_context.mojom @@ -203,6 +203,9 @@ struct NetworkContextParams { // cookies. Otherwise it should be false. bool persist_session_cookies = false; + // Schemes that will be passed to CookieMonster::SetCookieableSchemes. + array? cookieable_schemes; + // True if an HTTP cache should be used. bool http_cache_enabled = true; // Maximum size of the HTTP cache. 0 means to use the default size.