Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_GURL_H_ | 5 #ifndef URL_GURL_H_ |
| 6 #define URL_GURL_H_ | 6 #define URL_GURL_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 // are often treated separately by some programs. | 216 // are often treated separately by some programs. |
| 217 bool SchemeIsFile() const { | 217 bool SchemeIsFile() const { |
| 218 return SchemeIs(url::kFileScheme); | 218 return SchemeIs(url::kFileScheme); |
| 219 } | 219 } |
| 220 | 220 |
| 221 // FileSystem URLs need to be treated differently in some cases. | 221 // FileSystem URLs need to be treated differently in some cases. |
| 222 bool SchemeIsFileSystem() const { | 222 bool SchemeIsFileSystem() const { |
| 223 return SchemeIs(url::kFileSystemScheme); | 223 return SchemeIs(url::kFileSystemScheme); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // If the scheme indicates a secure connection | 226 // Returns true if the scheme indicates a secure connection. |
| 227 // | |
| 228 // NOTE: This function is deprecated. You probably want |SchemeUsesTLS| (if | |
| 229 // you just want to know if a scheme uses TLS for network transport) or | |
| 230 // Chromium's |IsOriginSecure| for a higher-level test about an origin's | |
| 231 // security. See those functions' documentation for more detail. | |
| 232 // | |
| 233 // TODO(palmer): Audit callers and change them to |SchemeUsesTLS| or | |
| 234 // |IsOriginSecure|, as appropriate. Then remove |SchemeIsSecure|. | |
| 235 // crbug.com/362214 | |
| 227 bool SchemeIsSecure() const { | 236 bool SchemeIsSecure() const { |
| 228 return SchemeIs(url::kHttpsScheme) || SchemeIs(url::kWssScheme) || | 237 return SchemeIs(url::kHttpsScheme) || SchemeIs(url::kWssScheme) || |
| 229 (SchemeIsFileSystem() && inner_url() && inner_url()->SchemeIsSecure()); | 238 (SchemeIsFileSystem() && inner_url() && |
| 239 inner_url()->SchemeIsSecure()); | |
| 240 } | |
| 241 | |
| 242 // Returns true if the scheme indicates a network connection that uses TLS for | |
| 243 // security. | |
| 244 // | |
| 245 // This function is a not a complete test of whether or not an origin's code | |
| 246 // is minimally trustworthy. For that, see Chromium's |IsOriginSecure| for a | |
| 247 // higher-level and more complete semantics. See that function's documentation | |
| 248 // for more detail. | |
| 249 bool SchemeUsesTLS() const { | |
|
Ryan Sleevi
2015/04/16 19:39:34
Suuuuuper-annoying pedantry: These schemes could u
| |
| 250 return SchemeIs(url::kHttpsScheme) || SchemeIs(url::kWssScheme); | |
| 230 } | 251 } |
| 231 | 252 |
| 232 // Returns true if the scheme is "blob". | 253 // Returns true if the scheme is "blob". |
| 233 bool SchemeIsBlob() const { | 254 bool SchemeIsBlob() const { |
| 234 return SchemeIs(url::kBlobScheme); | 255 return SchemeIs(url::kBlobScheme); |
| 235 } | 256 } |
| 236 | 257 |
| 237 // The "content" of the URL is everything after the scheme (skipping the | 258 // The "content" of the URL is everything after the scheme (skipping the |
| 238 // scheme delimiting colon). It is an error to get the origin of an invalid | 259 // scheme delimiting colon). It is an error to get the origin of an invalid |
| 239 // URL. The result will be an empty string. | 260 // URL. The result will be an empty string. |
| 240 std::string GetContent() const; | 261 std::string GetContent() const; |
| 241 | 262 |
| 242 // Returns true if the hostname is an IP address. Note: this function isn't | 263 // Returns true if the hostname is an IP address. Note: this function isn't |
| 243 // as cheap as a simple getter because it re-parses the hostname to verify. | 264 // as cheap as a simple getter because it re-parses the hostname to verify. |
| 244 // This currently identifies only IPv4 addresses (bug 822685). | |
| 245 bool HostIsIPAddress() const; | 265 bool HostIsIPAddress() const; |
| 246 | 266 |
| 247 // Getters for various components of the URL. The returned string will be | 267 // Getters for various components of the URL. The returned string will be |
| 248 // empty if the component is empty or is not present. | 268 // empty if the component is empty or is not present. |
| 249 std::string scheme() const { // Not including the colon. See also SchemeIs. | 269 std::string scheme() const { // Not including the colon. See also SchemeIs. |
| 250 return ComponentString(parsed_.scheme); | 270 return ComponentString(parsed_.scheme); |
| 251 } | 271 } |
| 252 std::string username() const { | 272 std::string username() const { |
| 253 return ComponentString(parsed_.username); | 273 return ComponentString(parsed_.username); |
| 254 } | 274 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 return parsed_.query.len >= 0; | 323 return parsed_.query.len >= 0; |
| 304 } | 324 } |
| 305 bool has_ref() const { | 325 bool has_ref() const { |
| 306 return parsed_.ref.len >= 0; | 326 return parsed_.ref.len >= 0; |
| 307 } | 327 } |
| 308 | 328 |
| 309 // Returns a parsed version of the port. Can also be any of the special | 329 // Returns a parsed version of the port. Can also be any of the special |
| 310 // values defined in Parsed for ExtractPort. | 330 // values defined in Parsed for ExtractPort. |
| 311 int IntPort() const; | 331 int IntPort() const; |
| 312 | 332 |
| 313 // Returns the port number of the url, or the default port number. | 333 // Returns the port number of the URL, or the default port number. |
| 314 // If the scheme has no concept of port (or unknown default) returns | 334 // If the scheme has no concept of port (or unknown default) returns |
| 315 // PORT_UNSPECIFIED. | 335 // PORT_UNSPECIFIED. |
| 316 int EffectiveIntPort() const; | 336 int EffectiveIntPort() const; |
| 317 | 337 |
| 318 // Extracts the filename portion of the path and returns it. The filename | 338 // Extracts the filename portion of the path and returns it. The filename |
| 319 // is everything after the last slash in the path. This may be empty. | 339 // is everything after the last slash in the path. This may be empty. |
| 320 std::string ExtractFileName() const; | 340 std::string ExtractFileName() const; |
| 321 | 341 |
| 322 // Returns the path that should be sent to the server. This is the path, | 342 // Returns the path that should be sent to the server. This is the path, |
| 323 // parameter, and query portions of the URL. It is guaranteed to be ASCII. | 343 // parameter, and query portions of the URL. It is guaranteed to be ASCII. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 // Used for nested schemes [currently only filesystem:]. | 416 // Used for nested schemes [currently only filesystem:]. |
| 397 scoped_ptr<GURL> inner_url_; | 417 scoped_ptr<GURL> inner_url_; |
| 398 | 418 |
| 399 // TODO bug 684583: Add encoding for query params. | 419 // TODO bug 684583: Add encoding for query params. |
| 400 }; | 420 }; |
| 401 | 421 |
| 402 // Stream operator so GURL can be used in assertion statements. | 422 // Stream operator so GURL can be used in assertion statements. |
| 403 URL_EXPORT std::ostream& operator<<(std::ostream& out, const GURL& url); | 423 URL_EXPORT std::ostream& operator<<(std::ostream& out, const GURL& url); |
| 404 | 424 |
| 405 #endif // URL_GURL_H_ | 425 #endif // URL_GURL_H_ |
| OLD | NEW |