OLD | NEW |
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 Loading... |
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 kFirstPartyOnlyTokenName[] = "first-party-only"; |
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 Loading... |
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 firstpartyonly_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 Loading... |
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::SetIsFirstPartyOnly(bool is_first_party_only) { |
| 234 return SetBool(&firstpartyonly_index_, kFirstPartyOnlyTokenName, |
| 235 is_first_party_only); |
| 236 } |
| 237 |
231 bool ParsedCookie::SetPriority(const std::string& priority) { | 238 bool ParsedCookie::SetPriority(const std::string& priority) { |
232 return SetString(&priority_index_, kPriorityTokenName, priority); | 239 return SetString(&priority_index_, kPriorityTokenName, priority); |
233 } | 240 } |
234 | 241 |
235 std::string ParsedCookie::ToCookieLine() const { | 242 std::string ParsedCookie::ToCookieLine() const { |
236 std::string out; | 243 std::string out; |
237 for (PairList::const_iterator it = pairs_.begin(); it != pairs_.end(); ++it) { | 244 for (PairList::const_iterator it = pairs_.begin(); it != pairs_.end(); ++it) { |
238 if (!out.empty()) | 245 if (!out.empty()) |
239 out.append("; "); | 246 out.append("; "); |
240 out.append(it->first); | 247 out.append(it->first); |
241 if (it->first != kSecureTokenName && it->first != kHttpOnlyTokenName) { | 248 if (it->first != kSecureTokenName && it->first != kHttpOnlyTokenName && |
| 249 it->first != kFirstPartyOnlyTokenName) { |
242 out.append("="); | 250 out.append("="); |
243 out.append(it->second); | 251 out.append(it->second); |
244 } | 252 } |
245 } | 253 } |
246 return out; | 254 return out; |
247 } | 255 } |
248 | 256 |
249 std::string::const_iterator ParsedCookie::FindFirstTerminator( | 257 std::string::const_iterator ParsedCookie::FindFirstTerminator( |
250 const std::string& s) { | 258 const std::string& s) { |
251 std::string::const_iterator end = s.end(); | 259 std::string::const_iterator end = s.end(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 } else if (pairs_[i].first == kDomainTokenName) { | 430 } else if (pairs_[i].first == kDomainTokenName) { |
423 domain_index_ = i; | 431 domain_index_ = i; |
424 } else if (pairs_[i].first == kExpiresTokenName) { | 432 } else if (pairs_[i].first == kExpiresTokenName) { |
425 expires_index_ = i; | 433 expires_index_ = i; |
426 } else if (pairs_[i].first == kMaxAgeTokenName) { | 434 } else if (pairs_[i].first == kMaxAgeTokenName) { |
427 maxage_index_ = i; | 435 maxage_index_ = i; |
428 } else if (pairs_[i].first == kSecureTokenName) { | 436 } else if (pairs_[i].first == kSecureTokenName) { |
429 secure_index_ = i; | 437 secure_index_ = i; |
430 } else if (pairs_[i].first == kHttpOnlyTokenName) { | 438 } else if (pairs_[i].first == kHttpOnlyTokenName) { |
431 httponly_index_ = i; | 439 httponly_index_ = i; |
| 440 } else if (pairs_[i].first == kFirstPartyOnlyTokenName) { |
| 441 firstpartyonly_index_ = i; |
432 } else if (pairs_[i].first == kPriorityTokenName) { | 442 } else if (pairs_[i].first == kPriorityTokenName) { |
433 priority_index_ = i; | 443 priority_index_ = i; |
434 } else { | 444 } else { |
435 /* some attribute we don't know or don't care about. */ | 445 /* some attribute we don't know or don't care about. */ |
436 } | 446 } |
437 } | 447 } |
438 } | 448 } |
439 | 449 |
440 bool ParsedCookie::SetString(size_t* index, | 450 bool ParsedCookie::SetString(size_t* index, |
441 const std::string& key, | 451 const std::string& key, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 // with an index being equal to 0. | 489 // with an index being equal to 0. |
480 if (index == 0) | 490 if (index == 0) |
481 return; | 491 return; |
482 | 492 |
483 size_t* indexes[] = {&path_index_, | 493 size_t* indexes[] = {&path_index_, |
484 &domain_index_, | 494 &domain_index_, |
485 &expires_index_, | 495 &expires_index_, |
486 &maxage_index_, | 496 &maxage_index_, |
487 &secure_index_, | 497 &secure_index_, |
488 &httponly_index_, | 498 &httponly_index_, |
| 499 &firstpartyonly_index_, |
489 &priority_index_}; | 500 &priority_index_}; |
490 for (size_t i = 0; i < arraysize(indexes); ++i) { | 501 for (size_t i = 0; i < arraysize(indexes); ++i) { |
491 if (*indexes[i] == index) | 502 if (*indexes[i] == index) |
492 *indexes[i] = 0; | 503 *indexes[i] = 0; |
493 else if (*indexes[i] > index) | 504 else if (*indexes[i] > index) |
494 --*indexes[i]; | 505 --*indexes[i]; |
495 } | 506 } |
496 pairs_.erase(pairs_.begin() + index); | 507 pairs_.erase(pairs_.begin() + index); |
497 } | 508 } |
498 | 509 |
499 } // namespace | 510 } // namespace |
OLD | NEW |