Commit 2641a901 authored by Dylan Cutler's avatar Dylan Cutler Committed by Commit Bot

Use net::CanonicalCookie::CreateSanitized cookie instead of constructor.

This is part of a larger cleanup effort of Chrome's use of cookies. The
eventual goal is to make the constructor private and to have other parts
of Chrome use CreateSanitizedCookie().

Bug: 1102874
Change-Id: Id27150b987d2303fc670aac8cdf83300d2238877
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303300
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Reviewed-by: default avatarLily Chen <chlily@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791881}
parent cf62759b
......@@ -87,16 +87,19 @@ static void JNI_CookiesFetcher_RestoreCookies(
jint same_site,
jint priority,
jint source_scheme) {
if (!ProfileManager::GetPrimaryUserProfile()->HasOffTheRecordProfile()) {
if (!ProfileManager::GetPrimaryUserProfile()->HasOffTheRecordProfile())
return; // Don't create it. There is nothing to do.
}
std::unique_ptr<net::CanonicalCookie> cookie(
std::make_unique<net::CanonicalCookie>(
base::android::ConvertJavaStringToUTF8(env, name),
base::android::ConvertJavaStringToUTF8(env, value),
base::android::ConvertJavaStringToUTF8(env, domain),
base::android::ConvertJavaStringToUTF8(env, path),
std::string domain_str(base::android::ConvertJavaStringToUTF8(env, domain));
std::string path_str(base::android::ConvertJavaStringToUTF8(env, path));
GURL url = net::cookie_util::CookieDomainAndPathToURL(
domain_str, path_str,
static_cast<net::CookieSourceScheme>(source_scheme));
std::unique_ptr<net::CanonicalCookie> cookie =
net::CanonicalCookie::CreateSanitizedCookie(
url, base::android::ConvertJavaStringToUTF8(env, name),
base::android::ConvertJavaStringToUTF8(env, value), domain_str,
path_str,
base::Time::FromDeltaSinceWindowsEpoch(
base::TimeDelta::FromMicroseconds(creation)),
base::Time::FromDeltaSinceWindowsEpoch(
......@@ -104,8 +107,10 @@ static void JNI_CookiesFetcher_RestoreCookies(
base::Time::FromDeltaSinceWindowsEpoch(
base::TimeDelta::FromMicroseconds(last_access)),
secure, httponly, static_cast<net::CookieSameSite>(same_site),
static_cast<net::CookiePriority>(priority),
static_cast<net::CookieSourceScheme>(source_scheme)));
static_cast<net::CookiePriority>(priority));
// These cookies were in the cookie store already so they should be valid.
DCHECK(cookie);
// Assume HTTPS - since the cookies are being restored from another store,
// they have already gone through the strict secure check.
......@@ -115,7 +120,8 @@ static void JNI_CookiesFetcher_RestoreCookies(
options.set_include_httponly();
options.set_same_site_cookie_context(
net::CookieOptions::SameSiteCookieContext::MakeInclusive());
// TODO(dylancutler) this updates the cookie's last_accessed_time.
GetCookieServiceClient()->SetCanonicalCookie(
*cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"),
options, network::mojom::CookieManager::SetCanonicalCookieCallback());
*cookie, url, options,
network::mojom::CookieManager::SetCanonicalCookieCallback());
}
......@@ -351,6 +351,13 @@ GURL CookieDomainAndPathToURL(const std::string& domain,
std::string(is_https ? url::kHttpsScheme : url::kHttpScheme));
}
GURL CookieDomainAndPathToURL(const std::string& domain,
const std::string& path,
CookieSourceScheme source_scheme) {
return CookieDomainAndPathToURL(domain, path,
source_scheme == CookieSourceScheme::kSecure);
}
GURL CookieOriginToURL(const std::string& domain, bool is_https) {
return CookieDomainAndPathToURL(domain, "/", is_https);
}
......
......@@ -93,6 +93,9 @@ NET_EXPORT GURL CookieDomainAndPathToURL(const std::string& domain,
NET_EXPORT GURL CookieDomainAndPathToURL(const std::string& domain,
const std::string& path,
bool is_https);
NET_EXPORT GURL CookieDomainAndPathToURL(const std::string& domain,
const std::string& path,
CookieSourceScheme source_scheme);
// Convenience for converting a cookie origin (domain and https pair) to a URL.
NET_EXPORT GURL CookieOriginToURL(const std::string& domain, bool is_https);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment