| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Brought to you by the letter D and the number 2. | 5 // Brought to you by the letter D and the number 2. |
| 6 | 6 |
| 7 #ifndef NET_BASE_COOKIE_MONSTER_H_ | 7 #ifndef NET_BASE_COOKIE_MONSTER_H_ |
| 8 #define NET_BASE_COOKIE_MONSTER_H_ | 8 #define NET_BASE_COOKIE_MONSTER_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // function expects each attribute to be well-formed. It will check for | 152 // function expects each attribute to be well-formed. It will check for |
| 153 // disallowed characters (e.g. the ';' character is disallowed within the | 153 // disallowed characters (e.g. the ';' character is disallowed within the |
| 154 // cookie value attribute) and will return false without setting the cookie | 154 // cookie value attribute) and will return false without setting the cookie |
| 155 // if such characters are found. | 155 // if such characters are found. |
| 156 bool SetCookieWithDetails(const GURL& url, | 156 bool SetCookieWithDetails(const GURL& url, |
| 157 const std::string& name, | 157 const std::string& name, |
| 158 const std::string& value, | 158 const std::string& value, |
| 159 const std::string& domain, | 159 const std::string& domain, |
| 160 const std::string& path, | 160 const std::string& path, |
| 161 const base::Time& expiration_time, | 161 const base::Time& expiration_time, |
| 162 bool secure, bool http_only); | 162 bool secure, bool http_only, bool origin); |
| 163 | 163 |
| 164 // Returns all the cookies, for use in management UI, etc. This does not mark | 164 // Returns all the cookies, for use in management UI, etc. This does not mark |
| 165 // the cookies as having been accessed. | 165 // the cookies as having been accessed. |
| 166 // The returned cookies are ordered by longest path, then by earliest | 166 // The returned cookies are ordered by longest path, then by earliest |
| 167 // creation date. | 167 // creation date. |
| 168 CookieList GetAllCookies(); | 168 CookieList GetAllCookies(); |
| 169 | 169 |
| 170 // Returns all the cookies, for use in management UI, etc. Filters results | 170 // Returns all the cookies, for use in management UI, etc. Filters results |
| 171 // using given url scheme, host / domain and path. This does not mark the | 171 // using given url scheme, host / domain and path. This does not mark the |
| 172 // cookies as having been accessed. | 172 // cookies as having been accessed. |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 // the resulting CanonicalCookies should not be relied on to be canonical | 480 // the resulting CanonicalCookies should not be relied on to be canonical |
| 481 // unless the caller has done appropriate validation and canonicalization | 481 // unless the caller has done appropriate validation and canonicalization |
| 482 // themselves. | 482 // themselves. |
| 483 CanonicalCookie(); | 483 CanonicalCookie(); |
| 484 CanonicalCookie(const std::string& name, | 484 CanonicalCookie(const std::string& name, |
| 485 const std::string& value, | 485 const std::string& value, |
| 486 const std::string& domain, | 486 const std::string& domain, |
| 487 const std::string& path, | 487 const std::string& path, |
| 488 bool secure, | 488 bool secure, |
| 489 bool httponly, | 489 bool httponly, |
| 490 bool origin, |
| 490 const base::Time& creation, | 491 const base::Time& creation, |
| 491 const base::Time& last_access, | 492 const base::Time& last_access, |
| 492 bool has_expires, | 493 bool has_expires, |
| 493 const base::Time& expires); | 494 const base::Time& expires); |
| 494 | 495 |
| 495 // This constructor does canonicalization but not validation. | 496 // This constructor does canonicalization but not validation. |
| 496 // The result of this constructor should not be relied on in contexts | 497 // The result of this constructor should not be relied on in contexts |
| 497 // in which pre-validation of the ParsedCookie has not been done. | 498 // in which pre-validation of the ParsedCookie has not been done. |
| 498 CanonicalCookie(const GURL& url, const ParsedCookie& pc); | 499 CanonicalCookie(const GURL& url, const ParsedCookie& pc); |
| 499 | 500 |
| 500 ~CanonicalCookie(); | 501 ~CanonicalCookie(); |
| 501 | 502 |
| 502 // Supports the default copy constructor. | 503 // Supports the default copy constructor. |
| 503 | 504 |
| 504 // Creates a canonical cookie from unparsed attribute values. | 505 // Creates a canonical cookie from unparsed attribute values. |
| 505 // Canonicalizes and validates inputs. May return NULL if an attribute | 506 // Canonicalizes and validates inputs. May return NULL if an attribute |
| 506 // value is invalid. | 507 // value is invalid. |
| 507 static CanonicalCookie* Create( | 508 static CanonicalCookie* Create( |
| 508 const GURL& url, const std::string& name, const std::string& value, | 509 const GURL& url, const std::string& name, const std::string& value, |
| 509 const std::string& domain, const std::string& path, | 510 const std::string& domain, const std::string& path, |
| 510 const base::Time& creation_time, const base::Time& expiration_time, | 511 const base::Time& creation_time, const base::Time& expiration_time, |
| 511 bool secure, bool http_only); | 512 bool secure, bool http_only, bool origin); |
| 512 | 513 |
| 513 const std::string& Name() const { return name_; } | 514 const std::string& Name() const { return name_; } |
| 514 const std::string& Value() const { return value_; } | 515 const std::string& Value() const { return value_; } |
| 515 const std::string& Domain() const { return domain_; } | 516 const std::string& Domain() const { return domain_; } |
| 516 const std::string& Path() const { return path_; } | 517 const std::string& Path() const { return path_; } |
| 517 const base::Time& CreationDate() const { return creation_date_; } | 518 const base::Time& CreationDate() const { return creation_date_; } |
| 518 const base::Time& LastAccessDate() const { return last_access_date_; } | 519 const base::Time& LastAccessDate() const { return last_access_date_; } |
| 519 bool DoesExpire() const { return has_expires_; } | 520 bool DoesExpire() const { return has_expires_; } |
| 520 bool IsPersistent() const { return DoesExpire(); } | 521 bool IsPersistent() const { return DoesExpire(); } |
| 521 const base::Time& ExpiryDate() const { return expiry_date_; } | 522 const base::Time& ExpiryDate() const { return expiry_date_; } |
| 522 bool IsSecure() const { return secure_; } | 523 bool IsSecure() const { return secure_; } |
| 523 bool IsHttpOnly() const { return httponly_; } | 524 bool IsHttpOnly() const { return httponly_; } |
| 525 bool IsOrigin() const { return origin_; } |
| 524 bool IsDomainCookie() const { | 526 bool IsDomainCookie() const { |
| 525 return !domain_.empty() && domain_[0] == '.'; } | 527 return !domain_.empty() && domain_[0] == '.'; } |
| 526 bool IsHostCookie() const { return !IsDomainCookie(); } | 528 bool IsHostCookie() const { return !IsDomainCookie(); } |
| 527 | 529 |
| 528 bool IsExpired(const base::Time& current) { | 530 bool IsExpired(const base::Time& current) { |
| 529 return has_expires_ && current >= expiry_date_; | 531 return has_expires_ && current >= expiry_date_; |
| 530 } | 532 } |
| 531 | 533 |
| 532 // Are the cookies considered equivalent in the eyes of RFC 2965. | 534 // Are the cookies considered equivalent in the eyes of RFC 2965. |
| 533 // The RFC says that name must match (case-sensitive), domain must | 535 // The RFC says that name must match (case-sensitive), domain must |
| 534 // match (case insensitive), and path must match (case sensitive). | 536 // match (case insensitive), and path must match (case sensitive). |
| 535 // For the case insensitive domain compare, we rely on the domain | 537 // For the case insensitive domain compare, we rely on the domain |
| 536 // having been canonicalized (in | 538 // having been canonicalized (in |
| 537 // GetCookieDomainWithString->CanonicalizeHost). | 539 // GetCookieDomainWithString->CanonicalizeHost). |
| 538 bool IsEquivalent(const CanonicalCookie& ecc) const { | 540 bool IsEquivalent(const CanonicalCookie& ecc) const { |
| 539 // It seems like it would make sense to take secure and httponly into | 541 if (origin_ != ecc.IsOrigin()) |
| 540 // account, but the RFC doesn't specify this. | 542 return false; |
| 541 // NOTE: Keep this logic in-sync with TrimDuplicateCookiesForHost(). | 543 if (origin_ && secure_ != ecc.IsSecure()) |
| 542 return (name_ == ecc.Name() && domain_ == ecc.Domain() | 544 return false; |
| 543 && path_ == ecc.Path()); | 545 return (name_ == ecc.Name() && |
| 546 domain_ == ecc.Domain() && |
| 547 path_ == ecc.Path()); |
| 544 } | 548 } |
| 545 | 549 |
| 546 void SetLastAccessDate(const base::Time& date) { | 550 void SetLastAccessDate(const base::Time& date) { |
| 547 last_access_date_ = date; | 551 last_access_date_ = date; |
| 548 } | 552 } |
| 549 | 553 |
| 550 bool IsOnPath(const std::string& url_path) const; | 554 bool IsOnPath(const std::string& url_path) const; |
| 551 bool IsDomainMatch(const std::string& scheme, const std::string& host) const; | 555 bool IsDomainMatch(const std::string& scheme, const std::string& host) const; |
| 552 | 556 |
| 553 std::string DebugString() const; | 557 std::string DebugString() const; |
| 554 private: | 558 private: |
| 555 std::string name_; | 559 std::string name_; |
| 556 std::string value_; | 560 std::string value_; |
| 557 std::string domain_; | 561 std::string domain_; |
| 558 std::string path_; | 562 std::string path_; |
| 559 base::Time creation_date_; | 563 base::Time creation_date_; |
| 560 base::Time last_access_date_; | 564 base::Time last_access_date_; |
| 561 base::Time expiry_date_; | 565 base::Time expiry_date_; |
| 562 bool has_expires_; | 566 bool has_expires_; |
| 563 bool secure_; | 567 bool secure_; |
| 564 bool httponly_; | 568 bool httponly_; |
| 569 bool origin_; |
| 565 }; | 570 }; |
| 566 | 571 |
| 567 class CookieMonster::Delegate | 572 class CookieMonster::Delegate |
| 568 : public base::RefCountedThreadSafe<CookieMonster::Delegate> { | 573 : public base::RefCountedThreadSafe<CookieMonster::Delegate> { |
| 569 public: | 574 public: |
| 570 // Will be called when a cookie is added or removed. The function is passed | 575 // Will be called when a cookie is added or removed. The function is passed |
| 571 // the respective |cookie| which was added to or removed from the cookies. | 576 // the respective |cookie| which was added to or removed from the cookies. |
| 572 // If |removed| is true, the cookie was deleted. | 577 // If |removed| is true, the cookie was deleted. |
| 573 virtual void OnCookieChanged(const CookieMonster::CanonicalCookie& cookie, | 578 virtual void OnCookieChanged(const CookieMonster::CanonicalCookie& cookie, |
| 574 bool removed) = 0; | 579 bool removed) = 0; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 601 bool HasPath() const { return path_index_ != 0; } | 606 bool HasPath() const { return path_index_ != 0; } |
| 602 const std::string& Path() const { return pairs_[path_index_].second; } | 607 const std::string& Path() const { return pairs_[path_index_].second; } |
| 603 bool HasDomain() const { return domain_index_ != 0; } | 608 bool HasDomain() const { return domain_index_ != 0; } |
| 604 const std::string& Domain() const { return pairs_[domain_index_].second; } | 609 const std::string& Domain() const { return pairs_[domain_index_].second; } |
| 605 bool HasExpires() const { return expires_index_ != 0; } | 610 bool HasExpires() const { return expires_index_ != 0; } |
| 606 const std::string& Expires() const { return pairs_[expires_index_].second; } | 611 const std::string& Expires() const { return pairs_[expires_index_].second; } |
| 607 bool HasMaxAge() const { return maxage_index_ != 0; } | 612 bool HasMaxAge() const { return maxage_index_ != 0; } |
| 608 const std::string& MaxAge() const { return pairs_[maxage_index_].second; } | 613 const std::string& MaxAge() const { return pairs_[maxage_index_].second; } |
| 609 bool IsSecure() const { return secure_index_ != 0; } | 614 bool IsSecure() const { return secure_index_ != 0; } |
| 610 bool IsHttpOnly() const { return httponly_index_ != 0; } | 615 bool IsHttpOnly() const { return httponly_index_ != 0; } |
| 616 bool IsOrigin() const { return origin_index_ != 0; } |
| 611 | 617 |
| 612 // Returns the number of attributes, for example, returning 2 for: | 618 // Returns the number of attributes, for example, returning 2 for: |
| 613 // "BLAH=hah; path=/; domain=.google.com" | 619 // "BLAH=hah; path=/; domain=.google.com" |
| 614 size_t NumberOfAttributes() const { return pairs_.size() - 1; } | 620 size_t NumberOfAttributes() const { return pairs_.size() - 1; } |
| 615 | 621 |
| 616 // For debugging only! | 622 // For debugging only! |
| 617 std::string DebugString() const; | 623 std::string DebugString() const; |
| 618 | 624 |
| 619 // Returns an iterator pointing to the first terminator character found in | 625 // Returns an iterator pointing to the first terminator character found in |
| 620 // the given string. | 626 // the given string. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 // These will default to 0, but that should never be valid since the | 665 // These will default to 0, but that should never be valid since the |
| 660 // 0th index is the user supplied token/value, not an attribute. | 666 // 0th index is the user supplied token/value, not an attribute. |
| 661 // We're really never going to have more than like 8 attributes, so we | 667 // We're really never going to have more than like 8 attributes, so we |
| 662 // could fit these into 3 bits each if we're worried about size... | 668 // could fit these into 3 bits each if we're worried about size... |
| 663 size_t path_index_; | 669 size_t path_index_; |
| 664 size_t domain_index_; | 670 size_t domain_index_; |
| 665 size_t expires_index_; | 671 size_t expires_index_; |
| 666 size_t maxage_index_; | 672 size_t maxage_index_; |
| 667 size_t secure_index_; | 673 size_t secure_index_; |
| 668 size_t httponly_index_; | 674 size_t httponly_index_; |
| 675 size_t origin_index_; |
| 669 | 676 |
| 670 DISALLOW_COPY_AND_ASSIGN(ParsedCookie); | 677 DISALLOW_COPY_AND_ASSIGN(ParsedCookie); |
| 671 }; | 678 }; |
| 672 | 679 |
| 673 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> | 680 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> |
| 674 RefcountedPersistentCookieStore; | 681 RefcountedPersistentCookieStore; |
| 675 | 682 |
| 676 class CookieMonster::PersistentCookieStore | 683 class CookieMonster::PersistentCookieStore |
| 677 : public RefcountedPersistentCookieStore { | 684 : public RefcountedPersistentCookieStore { |
| 678 public: | 685 public: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 689 protected: | 696 protected: |
| 690 PersistentCookieStore() { } | 697 PersistentCookieStore() { } |
| 691 | 698 |
| 692 private: | 699 private: |
| 693 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 700 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
| 694 }; | 701 }; |
| 695 | 702 |
| 696 } // namespace net | 703 } // namespace net |
| 697 | 704 |
| 698 #endif // NET_BASE_COOKIE_MONSTER_H_ | 705 #endif // NET_BASE_COOKIE_MONSTER_H_ |
| OLD | NEW |