| 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_SCHEME_HOST_PORT_H_ | 5 #ifndef URL_SCHEME_HOST_PORT_H_ |
| 6 #define URL_SCHEME_HOST_PORT_H_ | 6 #define URL_SCHEME_HOST_PORT_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "url/url_export.h" | 13 #include "url/url_export.h" |
| 14 | 14 |
| 15 class GURL; | 15 class GURL; |
| 16 | 16 |
| 17 namespace url { | 17 namespace url { |
| 18 | 18 |
| 19 struct Parsed; |
| 20 |
| 19 // This class represents a (scheme, host, port) tuple extracted from a URL. | 21 // This class represents a (scheme, host, port) tuple extracted from a URL. |
| 20 // | 22 // |
| 21 // The primary purpose of this class is to represent relevant network-authority | 23 // The primary purpose of this class is to represent relevant network-authority |
| 22 // information for a URL. It is _not_ an Origin, as described in RFC 6454. In | 24 // information for a URL. It is _not_ an Origin, as described in RFC 6454. In |
| 23 // particular, it is generally NOT the right thing to use for security | 25 // particular, it is generally NOT the right thing to use for security |
| 24 // decisions. | 26 // decisions. |
| 25 // | 27 // |
| 26 // Instead, this class is a mechanism for simplifying URLs with standard schemes | 28 // Instead, this class is a mechanism for simplifying URLs with standard schemes |
| 27 // (that is, those which follow the generic syntax of RFC 3986) down to the | 29 // (that is, those which follow the generic syntax of RFC 3986) down to the |
| 28 // uniquely identifying information necessary for network fetches. This makes it | 30 // uniquely identifying information necessary for network fetches. This makes it |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 bool IsInvalid() const; | 106 bool IsInvalid() const; |
| 105 | 107 |
| 106 // Serializes the SchemeHostPort tuple to a canonical form. | 108 // Serializes the SchemeHostPort tuple to a canonical form. |
| 107 // | 109 // |
| 108 // While this string form resembles the Origin serialization specified in | 110 // While this string form resembles the Origin serialization specified in |
| 109 // Section 6.2 of RFC 6454, it is important to note that invalid | 111 // Section 6.2 of RFC 6454, it is important to note that invalid |
| 110 // SchemeHostPort tuples serialize to the empty string, rather than being | 112 // SchemeHostPort tuples serialize to the empty string, rather than being |
| 111 // serialized as a unique Origin. | 113 // serialized as a unique Origin. |
| 112 std::string Serialize() const; | 114 std::string Serialize() const; |
| 113 | 115 |
| 116 // Efficiently returns what GURL(Serialize()) would return, without needing to |
| 117 // re-parse the URL. |
| 118 GURL GetURL() const; |
| 119 |
| 114 // Two SchemeHostPort objects are "equal" iff their schemes, hosts, and ports | 120 // Two SchemeHostPort objects are "equal" iff their schemes, hosts, and ports |
| 115 // are exact matches. | 121 // are exact matches. |
| 116 // | 122 // |
| 117 // Note that this comparison is _not_ the same as an origin-based comparison. | 123 // Note that this comparison is _not_ the same as an origin-based comparison. |
| 118 // In particular, invalid SchemeHostPort objects match each other (and | 124 // In particular, invalid SchemeHostPort objects match each other (and |
| 119 // themselves). Unique origins, on the other hand, would not. | 125 // themselves). Unique origins, on the other hand, would not. |
| 120 bool Equals(const SchemeHostPort& other) const; | 126 bool Equals(const SchemeHostPort& other) const; |
| 121 | 127 |
| 122 // Allows SchemeHostPort to be used as a key in STL (for example, a std::set | 128 // Allows SchemeHostPort to be used as a key in STL (for example, a std::set |
| 123 // or std::map). | 129 // or std::map). |
| 124 bool operator<(const SchemeHostPort& other) const; | 130 bool operator<(const SchemeHostPort& other) const; |
| 125 | 131 |
| 126 private: | 132 private: |
| 133 std::string SerializeInternal(url::Parsed* parsed) const; |
| 134 |
| 127 std::string scheme_; | 135 std::string scheme_; |
| 128 std::string host_; | 136 std::string host_; |
| 129 uint16_t port_; | 137 uint16_t port_; |
| 130 }; | 138 }; |
| 131 | 139 |
| 132 } // namespace url | 140 } // namespace url |
| 133 | 141 |
| 134 #endif // URL_SCHEME_HOST_PORT_H_ | 142 #endif // URL_SCHEME_HOST_PORT_H_ |
| OLD | NEW |