| 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> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 12 #include "url/url_export.h" | 13 #include "url/url_export.h" |
| 13 | 14 |
| 14 class GURL; | 15 class GURL; |
| 15 | 16 |
| 16 namespace url { | 17 namespace url { |
| 17 | 18 |
| 18 // This class represents a (scheme, host, port) tuple extracted from a URL. | 19 // This class represents a (scheme, host, port) tuple extracted from a URL. |
| 19 // | 20 // |
| 20 // The primary purpose of this class is to represent relevant network-authority | 21 // The primary purpose of this class is to represent relevant network-authority |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // Creates an invalid (scheme, host, port) tuple, which represents an invalid | 75 // Creates an invalid (scheme, host, port) tuple, which represents an invalid |
| 75 // or non-standard URL. | 76 // or non-standard URL. |
| 76 SchemeHostPort(); | 77 SchemeHostPort(); |
| 77 | 78 |
| 78 // Creates a (scheme, host, port) tuple. |host| must be a canonicalized | 79 // Creates a (scheme, host, port) tuple. |host| must be a canonicalized |
| 79 // A-label (that is, '☃.net' must be provided as 'xn--n3h.net'). |scheme| | 80 // A-label (that is, '☃.net' must be provided as 'xn--n3h.net'). |scheme| |
| 80 // must be a standard scheme. |port| must not be 0, unless |scheme| does not | 81 // must be a standard scheme. |port| must not be 0, unless |scheme| does not |
| 81 // support ports (e.g. 'file'). In that case, |port| must be 0. | 82 // support ports (e.g. 'file'). In that case, |port| must be 0. |
| 82 // | 83 // |
| 83 // Copies the data in |scheme| and |host|. | 84 // Copies the data in |scheme| and |host|. |
| 84 SchemeHostPort(base::StringPiece scheme, base::StringPiece host, uint16 port); | 85 SchemeHostPort(base::StringPiece scheme, |
| 86 base::StringPiece host, |
| 87 uint16_t port); |
| 85 | 88 |
| 86 // Creates a (scheme, host, port) tuple from |url|, as described at | 89 // Creates a (scheme, host, port) tuple from |url|, as described at |
| 87 // https://tools.ietf.org/html/rfc6454#section-4 | 90 // https://tools.ietf.org/html/rfc6454#section-4 |
| 88 // | 91 // |
| 89 // If |url| is invalid or non-standard, the result will be an invalid | 92 // If |url| is invalid or non-standard, the result will be an invalid |
| 90 // SchemeHostPort object. | 93 // SchemeHostPort object. |
| 91 explicit SchemeHostPort(const GURL& url); | 94 explicit SchemeHostPort(const GURL& url); |
| 92 | 95 |
| 93 ~SchemeHostPort(); | 96 ~SchemeHostPort(); |
| 94 | 97 |
| 95 // Returns the host component, in URL form. That is all IDN domain names will | 98 // Returns the host component, in URL form. That is all IDN domain names will |
| 96 // be expressed as A-Labels ('☃.net' will be returned as 'xn--n3h.net'), and | 99 // be expressed as A-Labels ('☃.net' will be returned as 'xn--n3h.net'), and |
| 97 // and all IPv6 addresses will be enclosed in brackets ("[2001:db8::1]"). | 100 // and all IPv6 addresses will be enclosed in brackets ("[2001:db8::1]"). |
| 98 const std::string& host() const { return host_; } | 101 const std::string& host() const { return host_; } |
| 99 const std::string& scheme() const { return scheme_; } | 102 const std::string& scheme() const { return scheme_; } |
| 100 uint16 port() const { return port_; } | 103 uint16_t port() const { return port_; } |
| 101 bool IsInvalid() const; | 104 bool IsInvalid() const; |
| 102 | 105 |
| 103 // Serializes the SchemeHostPort tuple to a canonical form. | 106 // Serializes the SchemeHostPort tuple to a canonical form. |
| 104 // | 107 // |
| 105 // While this string form resembles the Origin serialization specified in | 108 // While this string form resembles the Origin serialization specified in |
| 106 // Section 6.2 of RFC 6454, it is important to note that invalid | 109 // Section 6.2 of RFC 6454, it is important to note that invalid |
| 107 // SchemeHostPort tuples serialize to the empty string, rather than being | 110 // SchemeHostPort tuples serialize to the empty string, rather than being |
| 108 // serialized as a unique Origin. | 111 // serialized as a unique Origin. |
| 109 std::string Serialize() const; | 112 std::string Serialize() const; |
| 110 | 113 |
| 111 // Two SchemeHostPort objects are "equal" iff their schemes, hosts, and ports | 114 // Two SchemeHostPort objects are "equal" iff their schemes, hosts, and ports |
| 112 // are exact matches. | 115 // are exact matches. |
| 113 // | 116 // |
| 114 // Note that this comparison is _not_ the same as an origin-based comparison. | 117 // Note that this comparison is _not_ the same as an origin-based comparison. |
| 115 // In particular, invalid SchemeHostPort objects match each other (and | 118 // In particular, invalid SchemeHostPort objects match each other (and |
| 116 // themselves). Unique origins, on the other hand, would not. | 119 // themselves). Unique origins, on the other hand, would not. |
| 117 bool Equals(const SchemeHostPort& other) const; | 120 bool Equals(const SchemeHostPort& other) const; |
| 118 | 121 |
| 119 // Allows SchemeHostPort to be used as a key in STL (for example, a std::set | 122 // Allows SchemeHostPort to be used as a key in STL (for example, a std::set |
| 120 // or std::map). | 123 // or std::map). |
| 121 bool operator<(const SchemeHostPort& other) const; | 124 bool operator<(const SchemeHostPort& other) const; |
| 122 | 125 |
| 123 private: | 126 private: |
| 124 std::string scheme_; | 127 std::string scheme_; |
| 125 std::string host_; | 128 std::string host_; |
| 126 uint16 port_; | 129 uint16_t port_; |
| 127 }; | 130 }; |
| 128 | 131 |
| 129 } // namespace url | 132 } // namespace url |
| 130 | 133 |
| 131 #endif // URL_SCHEME_HOST_PORT_H_ | 134 #endif // URL_SCHEME_HOST_PORT_H_ |
| OLD | NEW |