| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // Creates an Origin from |url|, as described at | 83 // Creates an Origin from |url|, as described at |
| 84 // https://url.spec.whatwg.org/#origin, with the following additions: | 84 // https://url.spec.whatwg.org/#origin, with the following additions: |
| 85 // | 85 // |
| 86 // 1. If |url| is invalid or non-standard, a unique Origin is constructed. | 86 // 1. If |url| is invalid or non-standard, a unique Origin is constructed. |
| 87 // 2. 'filesystem' URLs behave as 'blob' URLs (that is, the origin is parsed | 87 // 2. 'filesystem' URLs behave as 'blob' URLs (that is, the origin is parsed |
| 88 // out of everything in the URL which follows the scheme). | 88 // out of everything in the URL which follows the scheme). |
| 89 // 3. 'file' URLs all parse as ("file", "", 0). | 89 // 3. 'file' URLs all parse as ("file", "", 0). |
| 90 explicit Origin(const GURL& url); | 90 explicit Origin(const GURL& url); |
| 91 | 91 |
| 92 // Creates an Origin from a |scheme|, |host|, and |port|. All the parameters | 92 // Creates an Origin from a |scheme|, |host|, and |port|. All the parameters |
| 93 // must be valid and canonicalized. In particular, note that this cannot be | 93 // must be valid and canonicalized. Do not use this method to create unique |
| 94 // used to create unique origins; 'url::Origin()' is the right way to do that. | 94 // origins. Use Origin() for that. |
| 95 // | 95 // |
| 96 // This constructor should be used in order to pass 'Origin' objects back and | 96 // This constructor should be used in order to pass 'Origin' objects back and |
| 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. |
| 106 // This should only be used when converting between already normalized types, |
| 107 // and should NOT be used for IPC. |
| 108 static Origin CreateFromNormalizedTuple(base::StringPiece scheme, |
| 109 base::StringPiece host, |
| 110 uint16_t port); |
| 111 |
| 105 ~Origin(); | 112 ~Origin(); |
| 106 | 113 |
| 107 // For unique origins, these return ("", "", 0). | 114 // For unique origins, these return ("", "", 0). |
| 108 const std::string& scheme() const { return tuple_.scheme(); } | 115 const std::string& scheme() const { return tuple_.scheme(); } |
| 109 const std::string& host() const { return tuple_.host(); } | 116 const std::string& host() const { return tuple_.host(); } |
| 110 uint16_t port() const { return tuple_.port(); } | 117 uint16_t port() const { return tuple_.port(); } |
| 111 | 118 |
| 112 bool unique() const { return unique_; } | 119 bool unique() const { return unique_; } |
| 113 | 120 |
| 114 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with | 121 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with |
| (...skipping 16 matching lines...) Expand all Loading... |
| 131 GURL GetURL() const; | 138 GURL GetURL() const; |
| 132 | 139 |
| 133 // Same as GURL::DomainIs. If |this| origin is unique, then returns false. | 140 // Same as GURL::DomainIs. If |this| origin is unique, then returns false. |
| 134 bool DomainIs(base::StringPiece lower_ascii_domain) const; | 141 bool DomainIs(base::StringPiece lower_ascii_domain) const; |
| 135 | 142 |
| 136 // Allows Origin to be used as a key in STL (for example, a std::set or | 143 // Allows Origin to be used as a key in STL (for example, a std::set or |
| 137 // std::map). | 144 // std::map). |
| 138 bool operator<(const Origin& other) const; | 145 bool operator<(const Origin& other) const; |
| 139 | 146 |
| 140 private: | 147 private: |
| 141 Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port); | 148 Origin(base::StringPiece scheme, |
| 149 base::StringPiece host, |
| 150 uint16_t port, |
| 151 SchemeHostPort::ConstructPolicy policy); |
| 142 | 152 |
| 143 SchemeHostPort tuple_; | 153 SchemeHostPort tuple_; |
| 144 bool unique_; | 154 bool unique_; |
| 145 }; | 155 }; |
| 146 | 156 |
| 147 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); | 157 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); |
| 148 | 158 |
| 149 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); | 159 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); |
| 150 | 160 |
| 151 } // namespace url | 161 } // namespace url |
| 152 | 162 |
| 153 #endif // URL_ORIGIN_H_ | 163 #endif // URL_ORIGIN_H_ |
| OLD | NEW |