| 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> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 11 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 12 #include "url/scheme_host_port.h" | 14 #include "url/scheme_host_port.h" |
| 13 #include "url/third_party/mozilla/url_parse.h" | 15 #include "url/third_party/mozilla/url_parse.h" |
| 14 #include "url/url_canon.h" | 16 #include "url/url_canon.h" |
| 15 #include "url/url_constants.h" | 17 #include "url/url_constants.h" |
| 16 #include "url/url_export.h" | 18 #include "url/url_export.h" |
| 17 | 19 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // must be valid and canonicalized. In particular, note that this cannot be | 93 // must be valid and canonicalized. In particular, note that this cannot be |
| 92 // used to create unique origins; 'url::Origin()' is the right way to do that. | 94 // used to create unique origins; 'url::Origin()' is the right way to do that. |
| 93 // | 95 // |
| 94 // 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 |
| 95 // forth over IPC (as transitioning through GURL would risk potentially | 97 // forth over IPC (as transitioning through GURL would risk potentially |
| 96 // dangerous recanonicalization); other potential callers should prefer the | 98 // dangerous recanonicalization); other potential callers should prefer the |
| 97 // 'GURL'-based constructor. | 99 // 'GURL'-based constructor. |
| 98 static Origin UnsafelyCreateOriginWithoutNormalization( | 100 static Origin UnsafelyCreateOriginWithoutNormalization( |
| 99 base::StringPiece scheme, | 101 base::StringPiece scheme, |
| 100 base::StringPiece host, | 102 base::StringPiece host, |
| 101 uint16 port); | 103 uint16_t port); |
| 102 | 104 |
| 103 ~Origin(); | 105 ~Origin(); |
| 104 | 106 |
| 105 // For unique origins, these return ("", "", 0). | 107 // For unique origins, these return ("", "", 0). |
| 106 const std::string& scheme() const { return tuple_.scheme(); } | 108 const std::string& scheme() const { return tuple_.scheme(); } |
| 107 const std::string& host() const { return tuple_.host(); } | 109 const std::string& host() const { return tuple_.host(); } |
| 108 uint16 port() const { return tuple_.port(); } | 110 uint16_t port() const { return tuple_.port(); } |
| 109 | 111 |
| 110 bool unique() const { return unique_; } | 112 bool unique() const { return unique_; } |
| 111 | 113 |
| 112 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with | 114 // An ASCII serialization of the Origin as per Section 6.2 of RFC 6454, with |
| 113 // 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://". |
| 114 std::string Serialize() const; | 116 std::string Serialize() const; |
| 115 | 117 |
| 116 // 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 |
| 117 // matches; and neither is unique. | 119 // matches; and neither is unique. |
| 118 bool IsSameOriginWith(const Origin& other) const; | 120 bool IsSameOriginWith(const Origin& other) const; |
| 119 | 121 |
| 120 // Allows Origin to be used as a key in STL (for example, a std::set or | 122 // Allows Origin to be used as a key in STL (for example, a std::set or |
| 121 // std::map). | 123 // std::map). |
| 122 bool operator<(const Origin& other) const; | 124 bool operator<(const Origin& other) const; |
| 123 | 125 |
| 124 private: | 126 private: |
| 125 Origin(base::StringPiece scheme, base::StringPiece host, uint16 port); | 127 Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port); |
| 126 | 128 |
| 127 SchemeHostPort tuple_; | 129 SchemeHostPort tuple_; |
| 128 bool unique_; | 130 bool unique_; |
| 129 }; | 131 }; |
| 130 | 132 |
| 131 URL_EXPORT std::ostream& operator<<(std::ostream& out, | 133 URL_EXPORT std::ostream& operator<<(std::ostream& out, |
| 132 const Origin& origin); | 134 const Origin& origin); |
| 133 | 135 |
| 134 } // namespace url | 136 } // namespace url |
| 135 | 137 |
| 136 #endif // URL_ORIGIN_H_ | 138 #endif // URL_ORIGIN_H_ |
| OLD | NEW |