| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef URL_ORIGIN_H_ | 5 #ifndef URL_ORIGIN_H_ |
| 6 #define URL_ORIGIN_H_ | 6 #define URL_ORIGIN_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 base::StringPiece host, | 102 base::StringPiece host, |
| 103 uint16_t port); | 103 uint16_t port); |
| 104 | 104 |
| 105 ~Origin(); | 105 ~Origin(); |
| 106 | 106 |
| 107 // For unique origins, these return ("", "", 0). | 107 // For unique origins, these return ("", "", 0). |
| 108 const std::string& scheme() const { return tuple_.scheme(); } | 108 const std::string& scheme() const { return tuple_.scheme(); } |
| 109 const std::string& host() const { return tuple_.host(); } | 109 const std::string& host() const { return tuple_.host(); } |
| 110 uint16_t port() const { return tuple_.port(); } | 110 uint16_t port() const { return tuple_.port(); } |
| 111 | 111 |
| 112 // Note that an origin without a suborgin will return the empty string. |
| 113 const std::string& suborigin() const { return suborigin_; } |
| 114 |
| 112 bool unique() const { return unique_; } | 115 bool unique() const { return unique_; } |
| 113 | 116 |
| 114 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with | 117 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with |
| 115 // the addition that all Origins with a 'file' scheme serialize to "file://". | 118 // the addition that all Origins with a 'file' scheme serialize to "file://". |
| 119 // If the Origin has a suborigin, it will be serialized per |
| 120 // https://w3c.github.io/webappsec-suborigins/#serializing. |
| 116 std::string Serialize() const; | 121 std::string Serialize() const; |
| 117 | 122 |
| 123 // Same as above, but ignores the suborigin component of the origin, if it |
| 124 // exists, returning only the physical origin. For example, when |
| 125 // SerializePhysicalOrigin() is called on the origin |
| 126 // https-so://foobar.example.com, it will return https://example.com. |
| 127 std::string SerializePhysicalOrigin() const; |
| 128 |
| 118 // Two Origins are "same-origin" if their schemes, hosts, and ports are exact | 129 // Two Origins are "same-origin" if their schemes, hosts, and ports are exact |
| 119 // matches; and neither is unique. | 130 // matches; and neither is unique. If either of the origins have suborigins, |
| 131 // the suborigins also must be exact matches. |
| 120 bool IsSameOriginWith(const Origin& other) const; | 132 bool IsSameOriginWith(const Origin& other) const; |
| 121 bool operator==(const Origin& other) const { | 133 bool operator==(const Origin& other) const { |
| 122 return IsSameOriginWith(other); | 134 return IsSameOriginWith(other); |
| 123 } | 135 } |
| 124 | 136 |
| 137 // Same as above, but ignores suborigins if they exist. |
| 138 bool IsSamePhysicalOriginWith(const Origin& other) const; |
| 139 |
| 125 // Efficiently returns what GURL(Serialize()) would without re-parsing the | 140 // Efficiently returns what GURL(Serialize()) would without re-parsing the |
| 126 // URL. This can be used for the (rare) times a GURL representation is needed | 141 // URL. This can be used for the (rare) times a GURL representation is needed |
| 127 // for an Origin. | 142 // for an Origin. |
| 128 // Note: The returned URL will not necessarily be serialized to the same value | 143 // Note: The returned URL will not necessarily be serialized to the same value |
| 129 // as the Origin would. The GURL will have an added "/" path for Origins with | 144 // as the Origin would. The GURL will have an added "/" path for Origins with |
| 130 // valid SchemeHostPorts and file Origins. | 145 // valid SchemeHostPorts and file Origins. |
| 131 GURL GetURL() const; | 146 GURL GetURL() const; |
| 132 | 147 |
| 133 // Same as GURL::DomainIs. If |this| origin is unique, then returns false. | 148 // Same as GURL::DomainIs. If |this| origin is unique, then returns false. |
| 134 bool DomainIs(base::StringPiece lower_ascii_domain) const; | 149 bool DomainIs(base::StringPiece lower_ascii_domain) const; |
| 135 | 150 |
| 136 // Allows Origin to be used as a key in STL (for example, a std::set or | 151 // Allows Origin to be used as a key in STL (for example, a std::set or |
| 137 // std::map). | 152 // std::map). |
| 138 bool operator<(const Origin& other) const; | 153 bool operator<(const Origin& other) const; |
| 139 | 154 |
| 140 private: | 155 private: |
| 141 Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port); | 156 Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port); |
| 142 | 157 |
| 143 SchemeHostPort tuple_; | 158 SchemeHostPort tuple_; |
| 144 bool unique_; | 159 bool unique_; |
| 160 std::string suborigin_; |
| 145 }; | 161 }; |
| 146 | 162 |
| 147 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); | 163 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); |
| 148 | 164 |
| 149 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); | 165 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); |
| 166 URL_EXPORT bool IsSamePhysicalOriginWith(const GURL& a, const GURL& b); |
| 150 | 167 |
| 151 } // namespace url | 168 } // namespace url |
| 152 | 169 |
| 153 #endif // URL_ORIGIN_H_ | 170 #endif // URL_ORIGIN_H_ |
| OLD | NEW |