gurl.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// found in the LICENSE file.
4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#ifndef URL_GURL_H_
6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#define URL_GURL_H_
7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
8c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include <iosfwd>
9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include <string>
10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/string16.h"
12c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "url/url_canon.h"
13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "url/url_canon_stdstring.h"
14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "url/url_parse.h"
15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class GURL {
17c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public:
18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  typedef url_canon::StdStringReplacements<std::string> Replacements;
19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  typedef url_canon::StdStringReplacements<string16> ReplacementsW;
20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Creates an empty, invalid URL.
22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL();
23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Copy construction is relatively inexpensive, with most of the time going
25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // to reallocating the string. It does not re-parse.
26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL(const GURL& other);
27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // The narrow version requires the input be UTF-8. Invalid UTF-8 input will
29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // result in an invalid URL.
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // The wide version should also take an encoding parameter so we know how to
32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // encode the query parameters. It is probably sufficient for the narrow
33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // version to assume the query parameter encoding should be the same as the
34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // input encoding.
35c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  explicit GURL(const std::string& url_string
36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                /*, output_param_encoding*/);
37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  explicit GURL(const string16& url_string
38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                /*, output_param_encoding*/);
39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Constructor for URLs that have already been parsed and canonicalized. This
41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // is used for conversions from KURL, for example. The caller must supply all
42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // information associated with the URL, which must be correct and consistent.
43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL(const char* canonical_spec, size_t canonical_spec_len,
44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)       const url_parse::Parsed& parsed, bool is_valid);
45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ~GURL();
47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL& operator=(const GURL& other);
49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns true when this object represents a valid parsed URL. When not
51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // valid, other functions will still succeed, but you will not get canonical
52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // data out in the format you may be expecting. Instead, we keep something
53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // "reasonable looking" so that the user can see how it's busted if
54c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // displayed to them.
55c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool is_valid() const {
56c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return is_valid_;
57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns true if the URL is zero-length. Note that empty URLs are also
60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // invalid, and is_valid() will return false for them. This is provided
61c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // because some users may want to treat the empty case differently.
62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool is_empty() const {
63c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return spec_.empty();
64c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
65c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
66c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns the raw spec, i.e., the full text of the URL, in canonical UTF-8,
67c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // if the URL is valid. If the URL is not valid, this will assert and return
68c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // the empty string (for safety in release builds, to keep them from being
69c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // misused which might be a security problem).
70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // The URL will be ASCII except the reference fragment, which may be UTF-8.
72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // It is guaranteed to be valid UTF-8.
73c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // The exception is for empty() URLs (which are !is_valid()) but this will
75c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // return the empty string without asserting.
76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Used invalid_spec() below to get the unusable spec of an invalid URL. This
78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // separation is designed to prevent errors that may cause security problems
79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // that could result from the mistaken use of an invalid URL.
80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const std::string& spec() const;
81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
82c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns the potentially invalid spec for a the URL. This spec MUST NOT be
83c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // modified or sent over the network. It is designed to be displayed in error
84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // messages to the user, as the apperance of the spec may explain the error.
85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // If the spec is valid, the valid spec will be returned.
86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // The returned string is guaranteed to be valid UTF-8.
88c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const std::string& possibly_invalid_spec() const {
89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return spec_;
90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Getter for the raw parsed structure. This allows callers to locate parts
93c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // of the URL within the spec themselves. Most callers should consider using
94c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // the individual component getters below.
95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // The returned parsed structure will reference into the raw spec, which may
97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // or may not be valid. If you are using this to index into the spec, BE
98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // SURE YOU ARE USING possibly_invalid_spec() to get the spec, and that you
99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // don't do anything "important" with invalid specs.
100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const url_parse::Parsed& parsed_for_possibly_invalid_spec() const {
101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return parsed_;
102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
103c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Defiant equality operator!
105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool operator==(const GURL& other) const {
106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return spec_ == other.spec_;
107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool operator!=(const GURL& other) const {
109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return spec_ != other.spec_;
110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Allows GURL to used as a key in STL (for example, a std::set or std::map).
113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool operator<(const GURL& other) const {
114c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return spec_ < other.spec_;
115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Resolves a URL that's possibly relative to this object's URL, and returns
118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // it. Absolute URLs are also handled according to the rules of URLs on web
119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // pages.
120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // It may be impossible to resolve the URLs properly. If the input is not
122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // "standard" (SchemeIsStandard() == false) and the input looks relative, we
123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // can't resolve it. In these cases, the result will be an empty, invalid
124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // GURL.
125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
126c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // The result may also be a nonempty, invalid URL if the input has some kind
127c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // of encoding error. In these cases, we will try to construct a "good" URL
128c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // that may have meaning to the user, but it will be marked invalid.
129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // It is an error to resolve a URL relative to an invalid URL. The result
131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // will be the empty URL.
132c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL Resolve(const std::string& relative) const;
133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL Resolve(const string16& relative) const;
134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Like Resolve() above but takes a character set encoder which will be used
136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // for any query text specified in the input. The charset converter parameter
137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // may be NULL, in which case it will be treated as UTF-8.
138c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
139c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TODO(brettw): These should be replaced with versions that take something
140c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // more friendly than a raw CharsetConverter (maybe like an ICU character set
141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // name).
142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL ResolveWithCharsetConverter(
143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const std::string& relative,
144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      url_canon::CharsetConverter* charset_converter) const;
145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL ResolveWithCharsetConverter(
146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const string16& relative,
147c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      url_canon::CharsetConverter* charset_converter) const;
148c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
149c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Creates a new GURL by replacing the current URL's components with the
150c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // supplied versions. See the Replacements class in url_canon.h for more.
151c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
152c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // These are not particularly quick, so avoid doing mutations when possible.
153c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Prefer the 8-bit version when possible.
154c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
155c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // It is an error to replace components of an invalid URL. The result will
156c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // be the empty URL.
157c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
158c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Note that we use the more general url_canon::Replacements type to give
159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // callers extra flexibility rather than our override.
160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL ReplaceComponents(
161c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const url_canon::Replacements<char>& replacements) const;
162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL ReplaceComponents(
163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      const url_canon::Replacements<char16>& replacements) const;
164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // A helper function that is equivalent to replacing the path with a slash
166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // and clearing out everything after that. We sometimes need to know just the
167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // scheme and the authority. If this URL is not a standard URL (it doesn't
168c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // have the regular authority and path sections), then the result will be
169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // an empty, invalid GURL. Note that this *does* work for file: URLs, which
170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // some callers may want to filter out before calling this.
171c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
172c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // It is an error to get an empty path on an invalid URL. The result
173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // will be the empty URL.
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL GetWithEmptyPath() const;
175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // A helper function to return a GURL containing just the scheme, host,
177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // and port from a URL. Equivalent to clearing any username and password,
178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // replacing the path with a slash, and clearing everything after that. If
179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // this URL is not a standard URL, then the result will be an empty,
180c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // invalid GURL. If the URL has neither username nor password, this
181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // degenerates to GetWithEmptyPath().
182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
183c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // It is an error to get the origin of an invalid URL. The result
184c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // will be the empty URL.
185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL GetOrigin() const;
186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
187c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns true if the scheme for the current URL is a known "standard"
188c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // scheme. Standard schemes have an authority and a path section. This
189c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // includes file: and filesystem:, which some callers may want to filter out
190c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // explicitly by calling SchemeIsFile[System].
191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool IsStandard() const;
192c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
193c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns true if the given parameter (should be lower-case ASCII to match
194c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // the canonicalized scheme) is the scheme for this URL. This call is more
195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // efficient than getting the scheme and comparing it because no copies or
196c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // object constructions are done.
197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool SchemeIs(const char* lower_ascii_scheme) const;
198c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // We often need to know if this is a file URL. File URLs are "standard", but
200c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // are often treated separately by some programs.
201c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool SchemeIsFile() const {
202c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return SchemeIs("file");
203c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
204c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // FileSystem URLs need to be treated differently in some cases.
206c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool SchemeIsFileSystem() const {
207c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return SchemeIs("filesystem");
208c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
209c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
210c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // If the scheme indicates a secure connection
211c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool SchemeIsSecure() const {
212c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return SchemeIs("https") || SchemeIs("wss") ||
213c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        (SchemeIsFileSystem() && inner_url() && inner_url()->SchemeIsSecure());
214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns true if the hostname is an IP address. Note: this function isn't
217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // as cheap as a simple getter because it re-parses the hostname to verify.
218c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // This currently identifies only IPv4 addresses (bug 822685).
219c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool HostIsIPAddress() const;
220c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
221c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Getters for various components of the URL. The returned string will be
222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // empty if the component is empty or is not present.
223c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string scheme() const {  // Not including the colon. See also SchemeIs.
224c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return ComponentString(parsed_.scheme);
225c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
226c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string username() const {
227c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return ComponentString(parsed_.username);
228c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
229c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string password() const {
230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return ComponentString(parsed_.password);
231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
232c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Note that this may be a hostname, an IPv4 address, or an IPv6 literal
233c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // surrounded by square brackets, like "[2001:db8::1]".  To exclude these
234c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // brackets, use HostNoBrackets() below.
235c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string host() const {
236c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return ComponentString(parsed_.host);
237c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
238c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string port() const {  // Returns -1 if "default"
239c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return ComponentString(parsed_.port);
240c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
241c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string path() const {  // Including first slash following host
242c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return ComponentString(parsed_.path);
243c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
244c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string query() const {  // Stuff following '?'
245c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return ComponentString(parsed_.query);
246c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
247c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string ref() const {  // Stuff following '#'
248c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return ComponentString(parsed_.ref);
249c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
250c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
251c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Existance querying. These functions will return true if the corresponding
252c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // URL component exists in this URL. Note that existance is different than
253c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // being nonempty. http://www.google.com/? has a query that just happens to
254c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // be empty, and has_query() will return true.
255c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool has_scheme() const {
256c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return parsed_.scheme.len >= 0;
257c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
258c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool has_username() const {
259c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return parsed_.username.len >= 0;
260c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
261c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool has_password() const {
262c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return parsed_.password.len >= 0;
263c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
264c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool has_host() const {
265c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // Note that hosts are special, absense of host means length 0.
266c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return parsed_.host.len > 0;
267c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
268c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool has_port() const {
269c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return parsed_.port.len >= 0;
270c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
271c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool has_path() const {
272c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // Note that http://www.google.com/" has a path, the path is "/". This can
273c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // return false only for invalid or nonstandard URLs.
274c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return parsed_.path.len >= 0;
275c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
276c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool has_query() const {
277c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return parsed_.query.len >= 0;
278c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
279c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool has_ref() const {
280c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return parsed_.ref.len >= 0;
281c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
282c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
283c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns a parsed version of the port. Can also be any of the special
284c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // values defined in Parsed for ExtractPort.
285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  int IntPort() const;
286c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
287c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns the port number of the url, or the default port number.
288c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // If the scheme has no concept of port (or unknown default) returns
289c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // PORT_UNSPECIFIED.
290c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  int EffectiveIntPort() const;
291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Extracts the filename portion of the path and returns it. The filename
293c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // is everything after the last slash in the path. This may be empty.
294c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string ExtractFileName() const;
295c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
296c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns the path that should be sent to the server. This is the path,
297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // parameter, and query portions of the URL. It is guaranteed to be ASCII.
298c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string PathForRequest() const;
299c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
300c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns the host, excluding the square brackets surrounding IPv6 address
301c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // literals.  This can be useful for passing to getaddrinfo().
302c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string HostNoBrackets() const;
303c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
304c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns true if this URL's host matches or is in the same domain as
305c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // the given input string. For example if this URL was "www.google.com",
306c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // this would match "com", "google.com", and "www.google.com
307c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // (input domain should be lower-case ASCII to match the canonicalized
308c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // scheme). This call is more efficient than getting the host and check
309c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // whether host has the specific domain or not because no copies or
310c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // object constructions are done.
311c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
312c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // If function DomainIs has parameter domain_len, which means the parameter
313c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // lower_ascii_domain does not gurantee to terminate with NULL character.
314c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool DomainIs(const char* lower_ascii_domain, int domain_len) const;
315c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // If function DomainIs only has parameter lower_ascii_domain, which means
317c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // domain string should be terminate with NULL character.
318c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool DomainIs(const char* lower_ascii_domain) const {
319c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return DomainIs(lower_ascii_domain,
320c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                    static_cast<int>(strlen(lower_ascii_domain)));
321c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
322c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
323c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Swaps the contents of this GURL object with the argument without doing
324c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // any memory allocations.
325c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void Swap(GURL* other);
326c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
327c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns a reference to a singleton empty GURL. This object is for callers
328c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // who return references but don't have anything to return in some cases.
329c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // This function may be called from any thread.
330c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static const GURL& EmptyGURL();
331c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
332c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns the inner URL of a nested URL [currently only non-null for
333c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // filesystem: URLs].
334c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  const GURL* inner_url() const {
335c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return inner_url_;
336c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
337c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
338c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private:
339c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns the substring of the input identified by the given component.
340c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string ComponentString(const url_parse::Component& comp) const {
341c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (comp.len <= 0)
342c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      return std::string();
343c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return std::string(spec_, comp.begin, comp.len);
344c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
345c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
346c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // The actual text of the URL, in canonical ASCII form.
347c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string spec_;
348c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
349c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Set when the given URL is valid. Otherwise, we may still have a spec and
350c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // components, but they may not identify valid resources (for example, an
351c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // invalid port number, invalid characters in the scheme, etc.).
352c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool is_valid_;
353c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
354c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Identified components of the canonical spec.
355c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  url_parse::Parsed parsed_;
356c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
357c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Used for nested schemes [currently only filesystem:].
358c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  GURL* inner_url_;
359c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
360c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TODO bug 684583: Add encoding for query params.
361c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)};
362c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
363c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Stream operator so GURL can be used in assertion statements.
364c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)std::ostream& operator<<(std::ostream& out, const GURL& url);
365c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
366c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif  // URL_GURL_H_
367