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 // TODO(palmer): Consider removing this function and changing its callers to | |
229 // call |OriginIsSecure|, or a wrapper around |OriginIsSecure| that takes the | |
230 // schemes registered with |WebSecurityPolicy::registerURLSchemeAsSecure| into | |
231 // account. crbug.com/362214. | |
227 bool SchemeIsSecure() const { | 232 bool SchemeIsSecure() const { |
228 return SchemeIs(url::kHttpsScheme) || SchemeIs(url::kWssScheme) || | 233 return SchemeIs(url::kFileScheme) || SchemeIs(url::kHttpsScheme) || |
229 (SchemeIsFileSystem() && inner_url() && inner_url()->SchemeIsSecure()); | 234 SchemeIs(url::kWssScheme) || (SchemeIsFileSystem() && inner_url() && |
235 inner_url()->SchemeIsSecure()); | |
230 } | 236 } |
231 | 237 |
238 // Returns true if the origin is secure. See | |
239 // https://www.w3.org/TR/powerful-features/#is-origin-trustworthy. | |
240 // | |
241 // TODO(palmer): In a higher layer, such as content/, add a new function that | |
242 // wraps this function and takes into account the schemes registered with | |
243 // |WebSecurityPolicy::registerURLSchemeAsSecure| in Blink. crbug.com/362214. | |
244 bool OriginIsSecure() const { return SchemeIsSecure() || HostIsLocal(); } | |
245 | |
232 // Returns true if the scheme is "blob". | 246 // Returns true if the scheme is "blob". |
233 bool SchemeIsBlob() const { | 247 bool SchemeIsBlob() const { |
234 return SchemeIs(url::kBlobScheme); | 248 return SchemeIs(url::kBlobScheme); |
235 } | 249 } |
236 | 250 |
237 // The "content" of the URL is everything after the scheme (skipping the | 251 // 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 | 252 // scheme delimiting colon). It is an error to get the origin of an invalid |
239 // URL. The result will be an empty string. | 253 // URL. The result will be an empty string. |
240 std::string GetContent() const; | 254 std::string GetContent() const; |
241 | 255 |
242 // Returns true if the hostname is an IP address. Note: this function isn't | 256 // 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. | 257 // 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; | 258 bool HostIsIPAddress() const; |
246 | 259 |
260 // Returns true if the hostname is "localhost" or if it is the IPv6 localhost | |
261 // address (::1) or if it is a localhost IPv4 address (127/8). | |
262 bool HostIsLocal() const; | |
felt
2015/04/01 18:03:18
this seems redundant with net::IsLocalhost (also w
palmer
2015/04/03 22:59:29
Yes, I have 2 reasons to move this code to content
| |
263 | |
247 // Getters for various components of the URL. The returned string will be | 264 // Getters for various components of the URL. The returned string will be |
248 // empty if the component is empty or is not present. | 265 // empty if the component is empty or is not present. |
249 std::string scheme() const { // Not including the colon. See also SchemeIs. | 266 std::string scheme() const { // Not including the colon. See also SchemeIs. |
250 return ComponentString(parsed_.scheme); | 267 return ComponentString(parsed_.scheme); |
251 } | 268 } |
252 std::string username() const { | 269 std::string username() const { |
253 return ComponentString(parsed_.username); | 270 return ComponentString(parsed_.username); |
254 } | 271 } |
255 std::string password() const { | 272 std::string password() const { |
256 return ComponentString(parsed_.password); | 273 return ComponentString(parsed_.password); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 return parsed_.query.len >= 0; | 320 return parsed_.query.len >= 0; |
304 } | 321 } |
305 bool has_ref() const { | 322 bool has_ref() const { |
306 return parsed_.ref.len >= 0; | 323 return parsed_.ref.len >= 0; |
307 } | 324 } |
308 | 325 |
309 // Returns a parsed version of the port. Can also be any of the special | 326 // Returns a parsed version of the port. Can also be any of the special |
310 // values defined in Parsed for ExtractPort. | 327 // values defined in Parsed for ExtractPort. |
311 int IntPort() const; | 328 int IntPort() const; |
312 | 329 |
313 // Returns the port number of the url, or the default port number. | 330 // 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 | 331 // If the scheme has no concept of port (or unknown default) returns |
315 // PORT_UNSPECIFIED. | 332 // PORT_UNSPECIFIED. |
316 int EffectiveIntPort() const; | 333 int EffectiveIntPort() const; |
317 | 334 |
318 // Extracts the filename portion of the path and returns it. The filename | 335 // 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. | 336 // is everything after the last slash in the path. This may be empty. |
320 std::string ExtractFileName() const; | 337 std::string ExtractFileName() const; |
321 | 338 |
322 // Returns the path that should be sent to the server. This is the path, | 339 // 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. | 340 // 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:]. | 413 // Used for nested schemes [currently only filesystem:]. |
397 scoped_ptr<GURL> inner_url_; | 414 scoped_ptr<GURL> inner_url_; |
398 | 415 |
399 // TODO bug 684583: Add encoding for query params. | 416 // TODO bug 684583: Add encoding for query params. |
400 }; | 417 }; |
401 | 418 |
402 // Stream operator so GURL can be used in assertion statements. | 419 // Stream operator so GURL can be used in assertion statements. |
403 URL_EXPORT std::ostream& operator<<(std::ostream& out, const GURL& url); | 420 URL_EXPORT std::ostream& operator<<(std::ostream& out, const GURL& url); |
404 | 421 |
405 #endif // URL_GURL_H_ | 422 #endif // URL_GURL_H_ |
OLD | NEW |