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

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

Issue 1773133002: SameSite: Implement 'Strict'/'Lax' attribute parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mmenke@ 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
« no previous file with comments | « net/cookies/parsed_cookie.h ('k') | net/cookies/parsed_cookie_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 SetupAttributes(); 175 SetupAttributes();
176 } 176 }
177 177
178 ParsedCookie::~ParsedCookie() { 178 ParsedCookie::~ParsedCookie() {
179 } 179 }
180 180
181 bool ParsedCookie::IsValid() const { 181 bool ParsedCookie::IsValid() const {
182 return !pairs_.empty(); 182 return !pairs_.empty();
183 } 183 }
184 184
185 CookieSameSite ParsedCookie::SameSite() const {
186 return (same_site_index_ == 0)
187 ? CookieSameSite::DEFAULT_MODE
188 : StringToCookieSameSite(pairs_[same_site_index_].second);
189 }
190
185 CookiePriority ParsedCookie::Priority() const { 191 CookiePriority ParsedCookie::Priority() const {
186 return (priority_index_ == 0) 192 return (priority_index_ == 0)
187 ? COOKIE_PRIORITY_DEFAULT 193 ? COOKIE_PRIORITY_DEFAULT
188 : StringToCookiePriority(pairs_[priority_index_].second); 194 : StringToCookiePriority(pairs_[priority_index_].second);
189 } 195 }
190 196
191 bool ParsedCookie::SetName(const std::string& name) { 197 bool ParsedCookie::SetName(const std::string& name) {
192 if (!IsValidToken(name)) 198 if (!IsValidToken(name))
193 return false; 199 return false;
194 if (pairs_.empty()) 200 if (pairs_.empty())
(...skipping 28 matching lines...) Expand all
223 } 229 }
224 230
225 bool ParsedCookie::SetIsSecure(bool is_secure) { 231 bool ParsedCookie::SetIsSecure(bool is_secure) {
226 return SetBool(&secure_index_, kSecureTokenName, is_secure); 232 return SetBool(&secure_index_, kSecureTokenName, is_secure);
227 } 233 }
228 234
229 bool ParsedCookie::SetIsHttpOnly(bool is_http_only) { 235 bool ParsedCookie::SetIsHttpOnly(bool is_http_only) {
230 return SetBool(&httponly_index_, kHttpOnlyTokenName, is_http_only); 236 return SetBool(&httponly_index_, kHttpOnlyTokenName, is_http_only);
231 } 237 }
232 238
233 bool ParsedCookie::SetIsSameSite(bool is_same_site) { 239 bool ParsedCookie::SetSameSite(const std::string& is_same_site) {
234 return SetBool(&same_site_index_, kSameSiteTokenName, is_same_site); 240 return SetString(&same_site_index_, kSameSiteTokenName, is_same_site);
235 } 241 }
236 242
237 bool ParsedCookie::SetPriority(const std::string& priority) { 243 bool ParsedCookie::SetPriority(const std::string& priority) {
238 return SetString(&priority_index_, kPriorityTokenName, priority); 244 return SetString(&priority_index_, kPriorityTokenName, priority);
239 } 245 }
240 246
241 std::string ParsedCookie::ToCookieLine() const { 247 std::string ParsedCookie::ToCookieLine() const {
242 std::string out; 248 std::string out;
243 for (PairList::const_iterator it = pairs_.begin(); it != pairs_.end(); ++it) { 249 for (PairList::const_iterator it = pairs_.begin(); it != pairs_.end(); ++it) {
244 if (!out.empty()) 250 if (!out.empty())
245 out.append("; "); 251 out.append("; ");
246 out.append(it->first); 252 out.append(it->first);
247 if (it->first != kSecureTokenName && it->first != kHttpOnlyTokenName && 253 if (it->first != kSecureTokenName && it->first != kHttpOnlyTokenName) {
248 it->first != kSameSiteTokenName) {
249 out.append("="); 254 out.append("=");
250 out.append(it->second); 255 out.append(it->second);
251 } 256 }
252 } 257 }
253 return out; 258 return out;
254 } 259 }
255 260
256 std::string::const_iterator ParsedCookie::FindFirstTerminator( 261 std::string::const_iterator ParsedCookie::FindFirstTerminator(
257 const std::string& s) { 262 const std::string& s) {
258 std::string::const_iterator end = s.end(); 263 std::string::const_iterator end = s.end();
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 for (size_t i = 0; i < arraysize(indexes); ++i) { 500 for (size_t i = 0; i < arraysize(indexes); ++i) {
496 if (*indexes[i] == index) 501 if (*indexes[i] == index)
497 *indexes[i] = 0; 502 *indexes[i] = 0;
498 else if (*indexes[i] > index) 503 else if (*indexes[i] > index)
499 --*indexes[i]; 504 --*indexes[i];
500 } 505 }
501 pairs_.erase(pairs_.begin() + index); 506 pairs_.erase(pairs_.begin() + index);
502 } 507 }
503 508
504 } // namespace 509 } // namespace
OLDNEW
« no previous file with comments | « net/cookies/parsed_cookie.h ('k') | net/cookies/parsed_cookie_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698