| 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 #include "url/scheme_host_port.h" | 5 #include "url/scheme_host_port.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 7 #include <string.h> | 8 #include <string.h> |
| 8 | 9 |
| 9 #include <tuple> | 10 #include <tuple> |
| 10 | 11 |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 #include "url/url_canon.h" | 16 #include "url/url_canon.h" |
| 16 #include "url/url_canon_stdstring.h" | 17 #include "url/url_canon_stdstring.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 40 } else { | 41 } else { |
| 41 // Empty host, or canonicalization failed. | 42 // Empty host, or canonicalization failed. |
| 42 canon_host.clear(); | 43 canon_host.clear(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 return host == canon_host; | 46 return host == canon_host; |
| 46 } | 47 } |
| 47 | 48 |
| 48 bool IsValidInput(const base::StringPiece& scheme, | 49 bool IsValidInput(const base::StringPiece& scheme, |
| 49 const base::StringPiece& host, | 50 const base::StringPiece& host, |
| 50 uint16 port) { | 51 uint16_t port) { |
| 51 SchemeType scheme_type = SCHEME_WITH_PORT; | 52 SchemeType scheme_type = SCHEME_WITH_PORT; |
| 52 bool is_standard = GetStandardSchemeType( | 53 bool is_standard = GetStandardSchemeType( |
| 53 scheme.data(), | 54 scheme.data(), |
| 54 Component(0, base::checked_cast<int>(scheme.length())), | 55 Component(0, base::checked_cast<int>(scheme.length())), |
| 55 &scheme_type); | 56 &scheme_type); |
| 56 if (!is_standard) | 57 if (!is_standard) |
| 57 return false; | 58 return false; |
| 58 | 59 |
| 59 // These schemes do not follow the generic URL syntax, so we treat them as | 60 // These schemes do not follow the generic URL syntax, so we treat them as |
| 60 // invalid (scheme, host, port) tuples (even though such URLs' _Origin_ might | 61 // invalid (scheme, host, port) tuples (even though such URLs' _Origin_ might |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 | 99 |
| 99 } // namespace | 100 } // namespace |
| 100 | 101 |
| 101 SchemeHostPort::SchemeHostPort() : port_(0) { | 102 SchemeHostPort::SchemeHostPort() : port_(0) { |
| 102 } | 103 } |
| 103 | 104 |
| 104 SchemeHostPort::SchemeHostPort(base::StringPiece scheme, | 105 SchemeHostPort::SchemeHostPort(base::StringPiece scheme, |
| 105 base::StringPiece host, | 106 base::StringPiece host, |
| 106 uint16 port) | 107 uint16_t port) |
| 107 : port_(0) { | 108 : port_(0) { |
| 108 if (!IsValidInput(scheme, host, port)) | 109 if (!IsValidInput(scheme, host, port)) |
| 109 return; | 110 return; |
| 110 | 111 |
| 111 scheme.CopyToString(&scheme_); | 112 scheme.CopyToString(&scheme_); |
| 112 host.CopyToString(&host_); | 113 host.CopyToString(&host_); |
| 113 port_ = port; | 114 port_ = port; |
| 114 } | 115 } |
| 115 | 116 |
| 116 SchemeHostPort::SchemeHostPort(const GURL& url) : port_(0) { | 117 SchemeHostPort::SchemeHostPort(const GURL& url) : port_(0) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 return port_ == other.port() && scheme_ == other.scheme() && | 171 return port_ == other.port() && scheme_ == other.scheme() && |
| 171 host_ == other.host(); | 172 host_ == other.host(); |
| 172 } | 173 } |
| 173 | 174 |
| 174 bool SchemeHostPort::operator<(const SchemeHostPort& other) const { | 175 bool SchemeHostPort::operator<(const SchemeHostPort& other) const { |
| 175 return std::tie(port_, scheme_, host_) < | 176 return std::tie(port_, scheme_, host_) < |
| 176 std::tie(other.port_, other.scheme_, other.host_); | 177 std::tie(other.port_, other.scheme_, other.host_); |
| 177 } | 178 } |
| 178 | 179 |
| 179 } // namespace url | 180 } // namespace url |
| OLD | NEW |