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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // forth over IPC (as transitioning through GURL would risk potentially | 97 // forth over IPC (as transitioning through GURL would risk potentially |
98 // dangerous recanonicalization); other potential callers should prefer the | 98 // dangerous recanonicalization); other potential callers should prefer the |
99 // 'GURL'-based constructor. | 99 // 'GURL'-based constructor. |
100 static Origin UnsafelyCreateOriginWithoutNormalization( | 100 static Origin UnsafelyCreateOriginWithoutNormalization( |
101 base::StringPiece scheme, | 101 base::StringPiece scheme, |
102 base::StringPiece host, | 102 base::StringPiece host, |
103 uint16_t port); | 103 uint16_t port); |
104 | 104 |
105 // Creates an origin without sanity checking that the host is canonicalized. | 105 // Creates an origin without sanity checking that the host is canonicalized. |
106 // This should only be used when converting between already normalized types, | 106 // This should only be used when converting between already normalized types, |
107 // and should NOT be used for IPC. | 107 // and should NOT be used for IPC. Method takes std::strings for use with move |
108 static Origin CreateFromNormalizedTuple(base::StringPiece scheme, | 108 // operators to avoid copies. |
109 base::StringPiece host, | |
110 uint16_t port); | |
111 | |
112 // Same as CreateFromNormalizedTuple() above, but adds a suborigin component | |
113 // as well. | |
114 static Origin CreateFromNormalizedTupleWithSuborigin( | 109 static Origin CreateFromNormalizedTupleWithSuborigin( |
115 base::StringPiece scheme, | 110 std::string scheme, |
116 base::StringPiece host, | 111 std::string host, |
117 uint16_t port, | 112 uint16_t port, |
118 base::StringPiece suborigin); | 113 std::string suborigin); |
119 | 114 |
120 ~Origin(); | 115 ~Origin(); |
121 | 116 |
122 // For unique origins, these return ("", "", 0). | 117 // For unique origins, these return ("", "", 0). |
123 const std::string& scheme() const { return tuple_.scheme(); } | 118 const std::string& scheme() const { return tuple_.scheme(); } |
124 const std::string& host() const { return tuple_.host(); } | 119 const std::string& host() const { return tuple_.host(); } |
125 uint16_t port() const { return tuple_.port(); } | 120 uint16_t port() const { return tuple_.port(); } |
126 | 121 |
127 // Note that an origin without a suborgin will return the empty string. | 122 // Note that an origin without a suborgin will return the empty string. |
128 const std::string& suborigin() const { return suborigin_; } | 123 const std::string& suborigin() const { return suborigin_; } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // Allows Origin to be used as a key in STL (for example, a std::set or | 161 // Allows Origin to be used as a key in STL (for example, a std::set or |
167 // std::map). | 162 // std::map). |
168 bool operator<(const Origin& other) const; | 163 bool operator<(const Origin& other) const; |
169 | 164 |
170 private: | 165 private: |
171 Origin(base::StringPiece scheme, | 166 Origin(base::StringPiece scheme, |
172 base::StringPiece host, | 167 base::StringPiece host, |
173 uint16_t port, | 168 uint16_t port, |
174 base::StringPiece suborigin, | 169 base::StringPiece suborigin, |
175 SchemeHostPort::ConstructPolicy policy); | 170 SchemeHostPort::ConstructPolicy policy); |
| 171 Origin(std::string scheme, |
| 172 std::string host, |
| 173 uint16_t port, |
| 174 std::string suborigin, |
| 175 SchemeHostPort::ConstructPolicy policy); |
176 | 176 |
177 SchemeHostPort tuple_; | 177 SchemeHostPort tuple_; |
178 bool unique_; | 178 bool unique_; |
179 std::string suborigin_; | 179 std::string suborigin_; |
180 }; | 180 }; |
181 | 181 |
182 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); | 182 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); |
183 | 183 |
184 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); | 184 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); |
185 URL_EXPORT bool IsSamePhysicalOriginWith(const GURL& a, const GURL& b); | 185 URL_EXPORT bool IsSamePhysicalOriginWith(const GURL& a, const GURL& b); |
186 | 186 |
187 } // namespace url | 187 } // namespace url |
188 | 188 |
189 #endif // URL_ORIGIN_H_ | 189 #endif // URL_ORIGIN_H_ |
OLD | NEW |