Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: net/cookies/cookie_monster.cc

Issue 1783813002: SameSite: Strict/Lax behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@strict-lax
Patch Set: Moar. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Portions of this code based on Mozilla: 5 // Portions of this code based on Mozilla:
6 // (netwerk/cookie/src/nsCookieService.cpp) 6 // (netwerk/cookie/src/nsCookieService.cpp)
7 /* ***** BEGIN LICENSE BLOCK ***** 7 /* ***** BEGIN LICENSE BLOCK *****
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
9 * 9 *
10 * The contents of this file are subject to the Mozilla Public License Version 10 * The contents of this file are subject to the Mozilla Public License Version
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 secure, http_only, same_site, enforce_strict_secure, priority)); 1037 secure, http_only, same_site, enforce_strict_secure, priority));
1038 1038
1039 if (!cc.get()) 1039 if (!cc.get())
1040 return false; 1040 return false;
1041 1041
1042 if (!last_access_time.is_null()) 1042 if (!last_access_time.is_null())
1043 cc->SetLastAccessDate(last_access_time); 1043 cc->SetLastAccessDate(last_access_time);
1044 1044
1045 CookieOptions options; 1045 CookieOptions options;
1046 options.set_include_httponly(); 1046 options.set_include_httponly();
1047 options.set_include_same_site(); 1047 options.set_same_site_mode(
1048 CookieOptions::SameSiteMode::INCLUDE_STRICT_AND_LAX);
1048 if (enforce_strict_secure) 1049 if (enforce_strict_secure)
1049 options.set_enforce_strict_secure(); 1050 options.set_enforce_strict_secure();
1050 return SetCanonicalCookie(std::move(cc), options); 1051 return SetCanonicalCookie(std::move(cc), options);
1051 } 1052 }
1052 1053
1053 CookieList CookieMonster::GetAllCookies() { 1054 CookieList CookieMonster::GetAllCookies() {
1054 DCHECK(thread_checker_.CalledOnValidThread()); 1055 DCHECK(thread_checker_.CalledOnValidThread());
1055 1056
1056 // This function is being called to scrape the cookie list for management UI 1057 // This function is being called to scrape the cookie list for management UI
1057 // or similar. We shouldn't show expired cookies in this list since it will 1058 // or similar. We shouldn't show expired cookies in this list since it will
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 1192
1192 void CookieMonster::DeleteCookie(const GURL& url, 1193 void CookieMonster::DeleteCookie(const GURL& url,
1193 const std::string& cookie_name) { 1194 const std::string& cookie_name) {
1194 DCHECK(thread_checker_.CalledOnValidThread()); 1195 DCHECK(thread_checker_.CalledOnValidThread());
1195 1196
1196 if (!HasCookieableScheme(url)) 1197 if (!HasCookieableScheme(url))
1197 return; 1198 return;
1198 1199
1199 CookieOptions options; 1200 CookieOptions options;
1200 options.set_include_httponly(); 1201 options.set_include_httponly();
1201 options.set_include_same_site(); 1202 options.set_same_site_mode(
1203 CookieOptions::SameSiteMode::INCLUDE_STRICT_AND_LAX);
1202 // Get the cookies for this host and its domain(s). 1204 // Get the cookies for this host and its domain(s).
1203 std::vector<CanonicalCookie*> cookies; 1205 std::vector<CanonicalCookie*> cookies;
1204 FindCookiesForHostAndDomain(url, options, &cookies); 1206 FindCookiesForHostAndDomain(url, options, &cookies);
1205 std::set<CanonicalCookie*> matching_cookies; 1207 std::set<CanonicalCookie*> matching_cookies;
1206 1208
1207 for (const auto& cookie : cookies) { 1209 for (const auto& cookie : cookies) {
1208 if (cookie->Name() != cookie_name) 1210 if (cookie->Name() != cookie_name)
1209 continue; 1211 continue;
1210 if (!cookie->IsOnPath(url.path())) 1212 if (!cookie->IsOnPath(url.path()))
1211 continue; 1213 continue;
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 DCHECK(thread_checker_.CalledOnValidThread()); 2327 DCHECK(thread_checker_.CalledOnValidThread());
2326 callback.Run(); 2328 callback.Run();
2327 } 2329 }
2328 2330
2329 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie, 2331 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie,
2330 bool removed) { 2332 bool removed) {
2331 DCHECK(thread_checker_.CalledOnValidThread()); 2333 DCHECK(thread_checker_.CalledOnValidThread());
2332 2334
2333 CookieOptions opts; 2335 CookieOptions opts;
2334 opts.set_include_httponly(); 2336 opts.set_include_httponly();
2335 opts.set_include_same_site(); 2337 opts.set_same_site_mode(CookieOptions::SameSiteMode::INCLUDE_STRICT_AND_LAX);
2336 // Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they 2338 // Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they
2337 // are guaranteed to not take long - they just post a RunAsync task back to 2339 // are guaranteed to not take long - they just post a RunAsync task back to
2338 // the appropriate thread's message loop and return. 2340 // the appropriate thread's message loop and return.
2339 // TODO(mmenke): Consider running these synchronously? 2341 // TODO(mmenke): Consider running these synchronously?
2340 for (CookieChangedHookMap::iterator it = hook_map_.begin(); 2342 for (CookieChangedHookMap::iterator it = hook_map_.begin();
2341 it != hook_map_.end(); ++it) { 2343 it != hook_map_.end(); ++it) {
2342 std::pair<GURL, std::string> key = it->first; 2344 std::pair<GURL, std::string> key = it->first;
2343 if (cookie.IncludeForRequestURL(key.first, opts) && 2345 if (cookie.IncludeForRequestURL(key.first, opts) &&
2344 cookie.Name() == key.second) { 2346 cookie.Name() == key.second) {
2345 it->second->Notify(cookie, removed); 2347 it->second->Notify(cookie, removed);
2346 } 2348 }
2347 } 2349 }
2348 } 2350 }
2349 2351
2350 } // namespace net 2352 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698