Chromium Code Reviews| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 | 82 |
| 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 // A convenience: Origin(GURL(url_string)). | |
| 93 explicit Origin(const std::string& url_string); | |
| 94 | |
| 92 // Creates an Origin from a |scheme|, |host|, and |port|. All the parameters | 95 // 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 | 96 // must be valid and canonicalized. In particular, note that this cannot be |
| 94 // used to create unique origins; 'url::Origin()' is the right way to do that. | 97 // used to create unique origins; 'url::Origin()' is the right way to do that. |
| 95 // | 98 // |
| 96 // This constructor should be used in order to pass 'Origin' objects back and | 99 // This constructor should be used in order to pass 'Origin' objects back and |
| 97 // forth over IPC (as transitioning through GURL would risk potentially | 100 // forth over IPC (as transitioning through GURL would risk potentially |
| 98 // dangerous recanonicalization); other potential callers should prefer the | 101 // dangerous recanonicalization); other potential callers should prefer the |
| 99 // 'GURL'-based constructor. | 102 // 'GURL'-based constructor. |
| 100 static Origin UnsafelyCreateOriginWithoutNormalization( | 103 static Origin UnsafelyCreateOriginWithoutNormalization( |
| 101 base::StringPiece scheme, | 104 base::StringPiece scheme, |
| 102 base::StringPiece host, | 105 base::StringPiece host, |
| 103 uint16_t port); | 106 uint16_t port); |
| 104 | 107 |
| 105 ~Origin(); | 108 ~Origin(); |
| 106 | 109 |
| 107 // For unique origins, these return ("", "", 0). | 110 // For unique origins, these return ("", "", 0). |
| 108 const std::string& scheme() const { return tuple_.scheme(); } | 111 const std::string& scheme() const { return tuple_.scheme(); } |
| 109 const std::string& host() const { return tuple_.host(); } | 112 const std::string& host() const { return tuple_.host(); } |
| 110 uint16_t port() const { return tuple_.port(); } | 113 uint16_t port() const { return tuple_.port(); } |
| 111 | 114 |
| 112 bool unique() const { return unique_; } | 115 bool unique() const { return unique_; } |
| 116 bool is_empty() const { return empty_; } | |
|
Mike West
2016/03/03 09:20:02
If we're going to distinguish between unique origi
palmer
2016/03/03 21:32:56
Done.
| |
| 113 | 117 |
| 114 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with | 118 // 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://". | 119 // the addition that all Origins with a 'file' scheme serialize to "file://". |
| 116 std::string Serialize() const; | 120 std::string Serialize() const; |
| 117 | 121 |
| 118 // Two Origins are "same-origin" if their schemes, hosts, and ports are exact | 122 // Two Origins are "same-origin" if their schemes, hosts, and ports are exact |
| 119 // matches; and neither is unique. | 123 // matches; and neither is unique. |
| 120 bool IsSameOriginWith(const Origin& other) const; | 124 bool IsSameOriginWith(const Origin& other) const; |
| 121 bool operator==(const Origin& other) const { | 125 bool operator==(const Origin& other) const { |
| 122 return IsSameOriginWith(other); | 126 return IsSameOriginWith(other); |
| 123 } | 127 } |
| 124 | 128 |
| 125 // Allows Origin to be used as a key in STL (for example, a std::set or | 129 // Allows Origin to be used as a key in STL (for example, a std::set or |
| 126 // std::map). | 130 // std::map). |
| 127 bool operator<(const Origin& other) const; | 131 bool operator<(const Origin& other) const; |
| 128 | 132 |
| 129 private: | 133 private: |
| 130 Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port); | 134 Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port); |
| 131 | 135 |
| 132 SchemeHostPort tuple_; | 136 SchemeHostPort tuple_; |
| 133 bool unique_; | 137 bool unique_; |
| 138 bool empty_; | |
| 134 }; | 139 }; |
| 135 | 140 |
| 136 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); | 141 URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); |
| 137 | 142 |
| 138 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); | 143 URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); |
| 139 | 144 |
| 140 } // namespace url | 145 } // namespace url |
| 141 | 146 |
| 142 #endif // URL_ORIGIN_H_ | 147 #endif // URL_ORIGIN_H_ |
| OLD | NEW |