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

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

Issue 876973003: Implement the "first-party-only" cookie flag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tiny bug. Created 5 years, 10 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "base/strings/string_util.h" 48 #include "base/strings/string_util.h"
49 49
50 namespace { 50 namespace {
51 51
52 const char kPathTokenName[] = "path"; 52 const char kPathTokenName[] = "path";
53 const char kDomainTokenName[] = "domain"; 53 const char kDomainTokenName[] = "domain";
54 const char kExpiresTokenName[] = "expires"; 54 const char kExpiresTokenName[] = "expires";
55 const char kMaxAgeTokenName[] = "max-age"; 55 const char kMaxAgeTokenName[] = "max-age";
56 const char kSecureTokenName[] = "secure"; 56 const char kSecureTokenName[] = "secure";
57 const char kHttpOnlyTokenName[] = "httponly"; 57 const char kHttpOnlyTokenName[] = "httponly";
58 const char kFirstPartyTokenName[] = "first-party";
58 const char kPriorityTokenName[] = "priority"; 59 const char kPriorityTokenName[] = "priority";
59 60
60 const char kTerminator[] = "\n\r\0"; 61 const char kTerminator[] = "\n\r\0";
61 const int kTerminatorLen = sizeof(kTerminator) - 1; 62 const int kTerminatorLen = sizeof(kTerminator) - 1;
62 const char kWhitespace[] = " \t"; 63 const char kWhitespace[] = " \t";
63 const char kValueSeparator[] = ";"; 64 const char kValueSeparator[] = ";";
64 const char kTokenSeparator[] = ";="; 65 const char kTokenSeparator[] = ";=";
65 66
66 // Returns true if |c| occurs in |chars| 67 // Returns true if |c| occurs in |chars|
67 // TODO(erikwright): maybe make this take an iterator, could check for end also? 68 // TODO(erikwright): maybe make this take an iterator, could check for end also?
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 156
156 namespace net { 157 namespace net {
157 158
158 ParsedCookie::ParsedCookie(const std::string& cookie_line) 159 ParsedCookie::ParsedCookie(const std::string& cookie_line)
159 : path_index_(0), 160 : path_index_(0),
160 domain_index_(0), 161 domain_index_(0),
161 expires_index_(0), 162 expires_index_(0),
162 maxage_index_(0), 163 maxage_index_(0),
163 secure_index_(0), 164 secure_index_(0),
164 httponly_index_(0), 165 httponly_index_(0),
166 firstparty_index_(0),
165 priority_index_(0) { 167 priority_index_(0) {
166 if (cookie_line.size() > kMaxCookieSize) { 168 if (cookie_line.size() > kMaxCookieSize) {
167 VLOG(1) << "Not parsing cookie, too large: " << cookie_line.size(); 169 VLOG(1) << "Not parsing cookie, too large: " << cookie_line.size();
168 return; 170 return;
169 } 171 }
170 172
171 ParseTokenValuePairs(cookie_line); 173 ParseTokenValuePairs(cookie_line);
172 if (!pairs_.empty()) 174 if (!pairs_.empty())
173 SetupAttributes(); 175 SetupAttributes();
174 } 176 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 223 }
222 224
223 bool ParsedCookie::SetIsSecure(bool is_secure) { 225 bool ParsedCookie::SetIsSecure(bool is_secure) {
224 return SetBool(&secure_index_, kSecureTokenName, is_secure); 226 return SetBool(&secure_index_, kSecureTokenName, is_secure);
225 } 227 }
226 228
227 bool ParsedCookie::SetIsHttpOnly(bool is_http_only) { 229 bool ParsedCookie::SetIsHttpOnly(bool is_http_only) {
228 return SetBool(&httponly_index_, kHttpOnlyTokenName, is_http_only); 230 return SetBool(&httponly_index_, kHttpOnlyTokenName, is_http_only);
229 } 231 }
230 232
233 bool ParsedCookie::SetIsFirstParty(bool is_first_party) {
234 return SetBool(&firstparty_index_, kFirstPartyTokenName, is_first_party);
235 }
236
231 bool ParsedCookie::SetPriority(const std::string& priority) { 237 bool ParsedCookie::SetPriority(const std::string& priority) {
232 return SetString(&priority_index_, kPriorityTokenName, priority); 238 return SetString(&priority_index_, kPriorityTokenName, priority);
233 } 239 }
234 240
235 std::string ParsedCookie::ToCookieLine() const { 241 std::string ParsedCookie::ToCookieLine() const {
236 std::string out; 242 std::string out;
237 for (PairList::const_iterator it = pairs_.begin(); it != pairs_.end(); ++it) { 243 for (PairList::const_iterator it = pairs_.begin(); it != pairs_.end(); ++it) {
238 if (!out.empty()) 244 if (!out.empty())
239 out.append("; "); 245 out.append("; ");
240 out.append(it->first); 246 out.append(it->first);
241 if (it->first != kSecureTokenName && it->first != kHttpOnlyTokenName) { 247 if (it->first != kSecureTokenName && it->first != kHttpOnlyTokenName &&
248 it->first != kFirstPartyTokenName) {
242 out.append("="); 249 out.append("=");
243 out.append(it->second); 250 out.append(it->second);
244 } 251 }
245 } 252 }
246 return out; 253 return out;
247 } 254 }
248 255
249 std::string::const_iterator ParsedCookie::FindFirstTerminator( 256 std::string::const_iterator ParsedCookie::FindFirstTerminator(
250 const std::string& s) { 257 const std::string& s) {
251 std::string::const_iterator end = s.end(); 258 std::string::const_iterator end = s.end();
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } else if (pairs_[i].first == kDomainTokenName) { 429 } else if (pairs_[i].first == kDomainTokenName) {
423 domain_index_ = i; 430 domain_index_ = i;
424 } else if (pairs_[i].first == kExpiresTokenName) { 431 } else if (pairs_[i].first == kExpiresTokenName) {
425 expires_index_ = i; 432 expires_index_ = i;
426 } else if (pairs_[i].first == kMaxAgeTokenName) { 433 } else if (pairs_[i].first == kMaxAgeTokenName) {
427 maxage_index_ = i; 434 maxage_index_ = i;
428 } else if (pairs_[i].first == kSecureTokenName) { 435 } else if (pairs_[i].first == kSecureTokenName) {
429 secure_index_ = i; 436 secure_index_ = i;
430 } else if (pairs_[i].first == kHttpOnlyTokenName) { 437 } else if (pairs_[i].first == kHttpOnlyTokenName) {
431 httponly_index_ = i; 438 httponly_index_ = i;
439 } else if (pairs_[i].first == kFirstPartyTokenName) {
440 firstparty_index_ = i;
432 } else if (pairs_[i].first == kPriorityTokenName) { 441 } else if (pairs_[i].first == kPriorityTokenName) {
433 priority_index_ = i; 442 priority_index_ = i;
434 } else { 443 } else {
435 /* some attribute we don't know or don't care about. */ 444 /* some attribute we don't know or don't care about. */
436 } 445 }
437 } 446 }
438 } 447 }
439 448
440 bool ParsedCookie::SetString(size_t* index, 449 bool ParsedCookie::SetString(size_t* index,
441 const std::string& key, 450 const std::string& key,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 // with an index being equal to 0. 488 // with an index being equal to 0.
480 if (index == 0) 489 if (index == 0)
481 return; 490 return;
482 491
483 size_t* indexes[] = {&path_index_, 492 size_t* indexes[] = {&path_index_,
484 &domain_index_, 493 &domain_index_,
485 &expires_index_, 494 &expires_index_,
486 &maxage_index_, 495 &maxage_index_,
487 &secure_index_, 496 &secure_index_,
488 &httponly_index_, 497 &httponly_index_,
498 &firstparty_index_,
489 &priority_index_}; 499 &priority_index_};
490 for (size_t i = 0; i < arraysize(indexes); ++i) { 500 for (size_t i = 0; i < arraysize(indexes); ++i) {
491 if (*indexes[i] == index) 501 if (*indexes[i] == index)
492 *indexes[i] = 0; 502 *indexes[i] = 0;
493 else if (*indexes[i] > index) 503 else if (*indexes[i] > index)
494 --*indexes[i]; 504 --*indexes[i];
495 } 505 }
496 pairs_.erase(pairs_.begin() + index); 506 pairs_.erase(pairs_.begin() + index);
497 } 507 }
498 508
499 } // namespace 509 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698