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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // the addition that all Origins with a 'file' scheme serialize to "file://". | 115 // the addition that all Origins with a 'file' scheme serialize to "file://". |
116 std::string Serialize() const; | 116 std::string Serialize() const; |
117 | 117 |
118 // Two Origins are "same-origin" if their schemes, hosts, and ports are exact | 118 // Two Origins are "same-origin" if their schemes, hosts, and ports are exact |
119 // matches; and neither is unique. | 119 // matches; and neither is unique. |
120 bool IsSameOriginWith(const Origin& other) const; | 120 bool IsSameOriginWith(const Origin& other) const; |
121 bool operator==(const Origin& other) const { | 121 bool operator==(const Origin& other) const { |
122 return IsSameOriginWith(other); | 122 return IsSameOriginWith(other); |
123 } | 123 } |
124 | 124 |
| 125 // 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 |
| 127 // for an Origin. |
| 128 // 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 |
| 130 // valid SchemeHostPorts and file Origins. |
| 131 GURL GetURL() const; |
| 132 |
125 // Same as GURL::DomainIs. If |this| origin is unique, then returns false. | 133 // Same as GURL::DomainIs. If |this| origin is unique, then returns false. |
126 bool DomainIs(base::StringPiece lower_ascii_domain) const; | 134 bool DomainIs(base::StringPiece lower_ascii_domain) const; |
127 | 135 |
128 // Allows Origin to be used as a key in STL (for example, a std::set or | 136 // Allows Origin to be used as a key in STL (for example, a std::set or |
129 // std::map). | 137 // std::map). |
130 bool operator<(const Origin& other) const; | 138 bool operator<(const Origin& other) const; |
131 | 139 |
132 private: | 140 private: |
133 Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port); | 141 Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port); |
134 | 142 |
135 SchemeHostPort tuple_; | 143 SchemeHostPort tuple_; |
136 bool unique_; | 144 bool unique_; |
137 }; | 145 }; |
138 | 146 |
139 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); | 147 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); |
140 | 148 |
141 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); | 149 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); |
142 | 150 |
143 } // namespace url | 151 } // namespace url |
144 | 152 |
145 #endif // URL_ORIGIN_H_ | 153 #endif // URL_ORIGIN_H_ |
OLD | NEW |