Commit 24da3e42 authored by Lily Chen's avatar Lily Chen Committed by Commit Bot

Use CookieOptions::MakeAllInclusive() in //net/cookies/

This replaces two uses of net::CookieOptions where we used to manually
set include_httponly and same_site_cookie_context to "strict", with
the recently added CookieOptions::MakeAllInclusive(), which does both
of those things automatically (and also sets do_not_update_access_time,
which doesn't matter because that field is not read for these two
usages). There isn't really any reason for this aside from saving a
few lines of code for readability and eliminating a member variable.

Bug: None
Change-Id: I2311e3cb8ea06301deb3eb72d86edfe986e8cf89
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832302Reviewed-by: default avatarMaks Orlovich <morlovich@chromium.org>
Commit-Queue: Lily Chen <chlily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701586}
parent f183ff7b
...@@ -75,14 +75,7 @@ CookieDeletionInfo::CookieDeletionInfo() ...@@ -75,14 +75,7 @@ CookieDeletionInfo::CookieDeletionInfo()
CookieDeletionInfo::CookieDeletionInfo(base::Time start_time, CookieDeletionInfo::CookieDeletionInfo(base::Time start_time,
base::Time end_time) base::Time end_time)
: creation_range(start_time, end_time) { : creation_range(start_time, end_time) {}
// Options to use for deletion of cookies associated with
// a particular URL. These options will make sure that all
// cookies associated with the URL are deleted.
cookie_options.set_include_httponly();
cookie_options.set_same_site_cookie_context(
net::CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT);
}
CookieDeletionInfo::CookieDeletionInfo(CookieDeletionInfo&& other) = default; CookieDeletionInfo::CookieDeletionInfo(CookieDeletionInfo&& other) = default;
...@@ -120,8 +113,12 @@ bool CookieDeletionInfo::Matches(const CanonicalCookie& cookie) const { ...@@ -120,8 +113,12 @@ bool CookieDeletionInfo::Matches(const CanonicalCookie& cookie) const {
return false; return false;
} }
// |CookieOptions::MakeAllInclusive()| options will make sure that all
// cookies associated with the URL are deleted.
if (url.has_value() && if (url.has_value() &&
!cookie.IncludeForRequestURL(url.value(), cookie_options).IsInclude()) { !cookie
.IncludeForRequestURL(url.value(), CookieOptions::MakeAllInclusive())
.IsInclude()) {
return false; return false;
} }
......
...@@ -108,9 +108,6 @@ struct NET_EXPORT CookieDeletionInfo { ...@@ -108,9 +108,6 @@ struct NET_EXPORT CookieDeletionInfo {
// included for a request of |url|. // included for a request of |url|.
base::Optional<GURL> url; base::Optional<GURL> url;
// Only used for |url| comparison.
CookieOptions cookie_options;
// If this is not empty then any cookie with a domain/ip contained in this // If this is not empty then any cookie with a domain/ip contained in this
// will be deleted (assuming other fields match). // will be deleted (assuming other fields match).
// Domains must not have a leading period. e.g "example.com" and not // Domains must not have a leading period. e.g "example.com" and not
......
...@@ -38,13 +38,6 @@ CookieMonsterChangeDispatcher::Subscription::Subscription( ...@@ -38,13 +38,6 @@ CookieMonsterChangeDispatcher::Subscription::Subscription(
task_runner_(base::ThreadTaskRunnerHandle::Get()) { task_runner_(base::ThreadTaskRunnerHandle::Get()) {
DCHECK(url_.is_valid() || url_.is_empty()); DCHECK(url_.is_valid() || url_.is_empty());
DCHECK_EQ(url_.is_empty(), domain_key_ == kGlobalDomainKey); DCHECK_EQ(url_.is_empty(), domain_key_ == kGlobalDomainKey);
// The net::CookieOptions are hard-coded for now, but future APIs may set
// different options. For example, JavaScript observers will not be allowed to
// see HTTP-only changes.
options_.set_include_httponly();
options_.set_same_site_cookie_context(
CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT);
} }
CookieMonsterChangeDispatcher::Subscription::~Subscription() { CookieMonsterChangeDispatcher::Subscription::~Subscription() {
...@@ -60,8 +53,12 @@ void CookieMonsterChangeDispatcher::Subscription::DispatchChange( ...@@ -60,8 +53,12 @@ void CookieMonsterChangeDispatcher::Subscription::DispatchChange(
net::CookieChangeCause change_cause) { net::CookieChangeCause change_cause) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
// The net::CookieOptions are hard-coded for now, but future APIs may set
// different options. For example, JavaScript observers will not be allowed to
// see HTTP-only changes.
if (!url_.is_empty() && if (!url_.is_empty() &&
!cookie.IncludeForRequestURL(url_, options_).IsInclude()) { !cookie.IncludeForRequestURL(url_, CookieOptions::MakeAllInclusive())
.IsInclude()) {
return; return;
} }
......
...@@ -92,7 +92,6 @@ class CookieMonsterChangeDispatcher : public CookieChangeDispatcher { ...@@ -92,7 +92,6 @@ class CookieMonsterChangeDispatcher : public CookieChangeDispatcher {
const std::string domain_key_; // kGlobalDomainKey means no filtering. const std::string domain_key_; // kGlobalDomainKey means no filtering.
const std::string name_key_; // kGlobalNameKey means no filtering. const std::string name_key_; // kGlobalNameKey means no filtering.
const GURL url_; // empty() means no URL-based filtering. const GURL url_; // empty() means no URL-based filtering.
net::CookieOptions options_;
const net::CookieChangeCallback callback_; const net::CookieChangeCallback callback_;
void DoDispatchChange(const net::CanonicalCookie& cookie, void DoDispatchChange(const net::CanonicalCookie& cookie,
......
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