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 // 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_COOKIES_COOKIE_MONSTER_H_ | 7 #ifndef NET_COOKIES_COOKIE_MONSTER_H_ |
8 #define NET_COOKIES_COOKIE_MONSTER_H_ | 8 #define NET_COOKIES_COOKIE_MONSTER_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 const std::string& name, | 673 const std::string& name, |
674 const std::string& value, | 674 const std::string& value, |
675 const std::string& domain, | 675 const std::string& domain, |
676 const std::string& path, | 676 const std::string& path, |
677 const std::string& mac_key, | 677 const std::string& mac_key, |
678 const std::string& mac_algorithm, | 678 const std::string& mac_algorithm, |
679 const base::Time& creation, | 679 const base::Time& creation, |
680 const base::Time& expiration, | 680 const base::Time& expiration, |
681 const base::Time& last_access, | 681 const base::Time& last_access, |
682 bool secure, | 682 bool secure, |
683 bool httponly, | 683 bool httponly); |
684 bool has_expires, | |
685 bool is_persistent); | |
686 | 684 |
687 // This constructor does canonicalization but not validation. | 685 // This constructor does canonicalization but not validation. |
688 // The result of this constructor should not be relied on in contexts | 686 // The result of this constructor should not be relied on in contexts |
689 // in which pre-validation of the ParsedCookie has not been done. | 687 // in which pre-validation of the ParsedCookie has not been done. |
690 CanonicalCookie(const GURL& url, const ParsedCookie& pc); | 688 CanonicalCookie(const GURL& url, const ParsedCookie& pc); |
691 | 689 |
692 ~CanonicalCookie(); | 690 ~CanonicalCookie(); |
693 | 691 |
694 // Supports the default copy constructor. | 692 // Supports the default copy constructor. |
695 | 693 |
696 // Creates a canonical cookie from parsed cookie. | 694 // Creates a canonical cookie from parsed cookie. |
697 // Canonicalizes and validates inputs. May return NULL if an attribute | 695 // Canonicalizes and validates inputs. May return NULL if an attribute |
698 // value is invalid. | 696 // value is invalid. |
699 static CanonicalCookie* Create(const GURL& url, | 697 static CanonicalCookie* Create(const GURL& url, |
700 const ParsedCookie& pc); | 698 const ParsedCookie& pc); |
701 | 699 |
702 // Creates a canonical cookie from unparsed attribute values. | 700 // Creates a canonical cookie from unparsed attribute values. |
703 // Canonicalizes and validates inputs. May return NULL if an attribute | 701 // Canonicalizes and validates inputs. May return NULL if an attribute |
704 // value is invalid. | 702 // value is invalid. |
705 static CanonicalCookie* Create(const GURL& url, | 703 static CanonicalCookie* Create(const GURL& url, |
706 const std::string& name, | 704 const std::string& name, |
707 const std::string& value, | 705 const std::string& value, |
708 const std::string& domain, | 706 const std::string& domain, |
709 const std::string& path, | 707 const std::string& path, |
710 const std::string& mac_key, | 708 const std::string& mac_key, |
711 const std::string& mac_algorithm, | 709 const std::string& mac_algorithm, |
712 const base::Time& creation, | 710 const base::Time& creation, |
713 const base::Time& expiration, | 711 const base::Time& expiration, |
714 bool secure, | 712 bool secure, |
715 bool http_only, | 713 bool http_only); |
716 bool is_persistent); | |
717 | 714 |
718 const std::string& Source() const { return source_; } | 715 const std::string& Source() const { return source_; } |
719 const std::string& Name() const { return name_; } | 716 const std::string& Name() const { return name_; } |
720 const std::string& Value() const { return value_; } | 717 const std::string& Value() const { return value_; } |
721 const std::string& Domain() const { return domain_; } | 718 const std::string& Domain() const { return domain_; } |
722 const std::string& Path() const { return path_; } | 719 const std::string& Path() const { return path_; } |
723 const std::string& MACKey() const { return mac_key_; } | 720 const std::string& MACKey() const { return mac_key_; } |
724 const std::string& MACAlgorithm() const { return mac_algorithm_; } | 721 const std::string& MACAlgorithm() const { return mac_algorithm_; } |
725 const base::Time& CreationDate() const { return creation_date_; } | 722 const base::Time& CreationDate() const { return creation_date_; } |
726 const base::Time& LastAccessDate() const { return last_access_date_; } | 723 const base::Time& LastAccessDate() const { return last_access_date_; } |
727 bool DoesExpire() const { return has_expires_; } | 724 bool IsPersistent() const { return !expiry_date_.is_null(); } |
728 bool IsPersistent() const { return is_persistent_; } | |
729 const base::Time& ExpiryDate() const { return expiry_date_; } | 725 const base::Time& ExpiryDate() const { return expiry_date_; } |
730 bool IsSecure() const { return secure_; } | 726 bool IsSecure() const { return secure_; } |
731 bool IsHttpOnly() const { return httponly_; } | 727 bool IsHttpOnly() const { return httponly_; } |
732 bool IsDomainCookie() const { | 728 bool IsDomainCookie() const { |
733 return !domain_.empty() && domain_[0] == '.'; } | 729 return !domain_.empty() && domain_[0] == '.'; } |
734 bool IsHostCookie() const { return !IsDomainCookie(); } | 730 bool IsHostCookie() const { return !IsDomainCookie(); } |
735 | 731 |
736 bool IsExpired(const base::Time& current) { | 732 bool IsExpired(const base::Time& current) { |
737 return has_expires_ && current >= expiry_date_; | 733 return !expiry_date_.is_null() && current >= expiry_date_; |
738 } | 734 } |
739 | 735 |
740 // Are the cookies considered equivalent in the eyes of RFC 2965. | 736 // Are the cookies considered equivalent in the eyes of RFC 2965. |
741 // The RFC says that name must match (case-sensitive), domain must | 737 // The RFC says that name must match (case-sensitive), domain must |
742 // match (case insensitive), and path must match (case sensitive). | 738 // match (case insensitive), and path must match (case sensitive). |
743 // For the case insensitive domain compare, we rely on the domain | 739 // For the case insensitive domain compare, we rely on the domain |
744 // having been canonicalized (in | 740 // having been canonicalized (in |
745 // GetCookieDomainWithString->CanonicalizeHost). | 741 // GetCookieDomainWithString->CanonicalizeHost). |
746 bool IsEquivalent(const CanonicalCookie& ecc) const { | 742 bool IsEquivalent(const CanonicalCookie& ecc) const { |
747 // It seems like it would make sense to take secure and httponly into | 743 // It seems like it would make sense to take secure and httponly into |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 std::string value_; | 778 std::string value_; |
783 std::string domain_; | 779 std::string domain_; |
784 std::string path_; | 780 std::string path_; |
785 std::string mac_key_; // TODO(abarth): Persist to disk. | 781 std::string mac_key_; // TODO(abarth): Persist to disk. |
786 std::string mac_algorithm_; // TODO(abarth): Persist to disk. | 782 std::string mac_algorithm_; // TODO(abarth): Persist to disk. |
787 base::Time creation_date_; | 783 base::Time creation_date_; |
788 base::Time expiry_date_; | 784 base::Time expiry_date_; |
789 base::Time last_access_date_; | 785 base::Time last_access_date_; |
790 bool secure_; | 786 bool secure_; |
791 bool httponly_; | 787 bool httponly_; |
792 bool has_expires_; | |
793 bool is_persistent_; | |
794 }; | 788 }; |
795 | 789 |
796 class CookieMonster::Delegate | 790 class CookieMonster::Delegate |
797 : public base::RefCountedThreadSafe<CookieMonster::Delegate> { | 791 : public base::RefCountedThreadSafe<CookieMonster::Delegate> { |
798 public: | 792 public: |
799 // The publicly relevant reasons a cookie might be changed. | 793 // The publicly relevant reasons a cookie might be changed. |
800 enum ChangeCause { | 794 enum ChangeCause { |
801 // The cookie was changed directly by a consumer's action. | 795 // The cookie was changed directly by a consumer's action. |
802 CHANGE_COOKIE_EXPLICIT, | 796 CHANGE_COOKIE_EXPLICIT, |
803 // The cookie was automatically removed due to an insert operation that | 797 // The cookie was automatically removed due to an insert operation that |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 friend class base::RefCountedThreadSafe<PersistentCookieStore>; | 965 friend class base::RefCountedThreadSafe<PersistentCookieStore>; |
972 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 966 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
973 }; | 967 }; |
974 | 968 |
975 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { | 969 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { |
976 }; | 970 }; |
977 | 971 |
978 } // namespace net | 972 } // namespace net |
979 | 973 |
980 #endif // NET_COOKIES_COOKIE_MONSTER_H_ | 974 #endif // NET_COOKIES_COOKIE_MONSTER_H_ |
OLD | NEW |