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_URL_UTIL_H_ | 5 #ifndef URL_URL_UTIL_H_ |
6 #define URL_URL_UTIL_H_ | 6 #define URL_URL_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/strings/string_piece.h" |
11 #include "url/third_party/mozilla/url_parse.h" | 12 #include "url/third_party/mozilla/url_parse.h" |
12 #include "url/url_canon.h" | 13 #include "url/url_canon.h" |
13 #include "url/url_constants.h" | 14 #include "url/url_constants.h" |
14 #include "url/url_export.h" | 15 #include "url/url_export.h" |
15 | 16 |
16 namespace url { | 17 namespace url { |
17 | 18 |
18 // Init ------------------------------------------------------------------------ | 19 // Init ------------------------------------------------------------------------ |
19 | 20 |
20 // Initialization is NOT required, it will be implicitly initialized when first | 21 // Initialization is NOT required, it will be implicitly initialized when first |
21 // used. However, this implicit initialization is NOT threadsafe. If you are | 22 // used. However, this implicit initialization is NOT threadsafe. If you are |
22 // using this library in a threaded environment and don't have a consistent | 23 // using this library in a threaded environment and don't have a consistent |
23 // "first call" (an example might be calling Add*Scheme with your special | 24 // "first call" (an example might be calling Add*Scheme with your special |
24 // application-specific schemes) then you will want to call initialize before | 25 // application-specific schemes) then you will want to call initialize before |
25 // spawning any threads. | 26 // spawning any threads. |
26 // | 27 // |
27 // It is OK to call this function more than once, subsequent calls will be | 28 // It is OK to call this function more than once, subsequent calls will be |
28 // no-ops, unless Shutdown was called in the mean time. This will also be a | 29 // no-ops, unless Shutdown was called in the mean time. This will also be a |
29 // no-op if other calls to the library have forced an initialization beforehand. | 30 // no-op if other calls to the library have forced an initialization beforehand. |
30 URL_EXPORT void Initialize(); | 31 URL_EXPORT void Initialize(); |
31 | 32 |
32 // Cleanup is not required, except some strings may leak. For most user | 33 // Cleanup is not required, except some strings may leak. For most user |
33 // applications, this is fine. If you're using it in a library that may get | 34 // applications, this is fine. If you're using it in a library that may get |
34 // loaded and unloaded, you'll want to unload to properly clean up your | 35 // loaded and unloaded, you'll want to unload to properly clean up your |
35 // library. | 36 // library. |
36 URL_EXPORT void Shutdown(); | 37 URL_EXPORT void Shutdown(); |
37 | 38 |
38 // Schemes -------------------------------------------------------------------- | 39 // Schemes --------------------------------------------------------------------- |
39 | 40 |
40 // Types of a scheme representing the requirements on the data represented by | 41 // Types of a scheme representing the requirements on the data represented by |
41 // the authority component of a URL with the scheme. | 42 // the authority component of a URL with the scheme. |
42 enum SchemeType { | 43 enum SchemeType { |
43 // The authority component of a URL with the scheme, if any, has the port | 44 // The authority component of a URL with the scheme, if any, has the port |
44 // (the default values may be omitted in a serialization). | 45 // (the default values may be omitted in a serialization). |
45 SCHEME_WITH_PORT, | 46 SCHEME_WITH_PORT, |
46 // The authority component of a URL with the scheme, if any, doesn't have a | 47 // The authority component of a URL with the scheme, if any, doesn't have a |
47 // port. | 48 // port. |
48 SCHEME_WITHOUT_PORT, | 49 SCHEME_WITHOUT_PORT, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // the list of allowed schemes for referrers (see AddReferrerScheme). | 126 // the list of allowed schemes for referrers (see AddReferrerScheme). |
126 URL_EXPORT bool IsReferrerScheme(const char* spec, const Component& scheme); | 127 URL_EXPORT bool IsReferrerScheme(const char* spec, const Component& scheme); |
127 | 128 |
128 // Returns true and sets |type| to the SchemeType of the given scheme | 129 // Returns true and sets |type| to the SchemeType of the given scheme |
129 // identified by |scheme| within |spec| if the scheme is in the list of known | 130 // identified by |scheme| within |spec| if the scheme is in the list of known |
130 // standard-format schemes (see AddStandardScheme). | 131 // standard-format schemes (see AddStandardScheme). |
131 URL_EXPORT bool GetStandardSchemeType(const char* spec, | 132 URL_EXPORT bool GetStandardSchemeType(const char* spec, |
132 const Component& scheme, | 133 const Component& scheme, |
133 SchemeType* type); | 134 SchemeType* type); |
134 | 135 |
135 // URL library wrappers ------------------------------------------------------- | 136 // Domains --------------------------------------------------------------------- |
| 137 |
| 138 // Returns true if the |canonicalized_host| matches or is in the same domain as |
| 139 // the given |lower_ascii_domain| string. For example, if the canonicalized |
| 140 // hostname is "www.google.com", this will return true for "com", "google.com", |
| 141 // and "www.google.com" domains. |
| 142 // |
| 143 // If either of the input StringPieces is empty, the return value is false. The |
| 144 // input domain should be a lower-case ASCII string in order to match the |
| 145 // canonicalized host. |
| 146 URL_EXPORT bool DomainIs(base::StringPiece canonicalized_host, |
| 147 base::StringPiece lower_ascii_domain); |
| 148 |
| 149 // URL library wrappers -------------------------------------------------------- |
136 | 150 |
137 // Parses the given spec according to the extracted scheme type. Normal users | 151 // Parses the given spec according to the extracted scheme type. Normal users |
138 // should use the URL object, although this may be useful if performance is | 152 // should use the URL object, although this may be useful if performance is |
139 // critical and you don't want to do the heap allocation for the std::string. | 153 // critical and you don't want to do the heap allocation for the std::string. |
140 // | 154 // |
141 // As with the Canonicalize* functions, the charset converter can | 155 // As with the Canonicalize* functions, the charset converter can |
142 // be NULL to use UTF-8 (it will be faster in this case). | 156 // be NULL to use UTF-8 (it will be faster in this case). |
143 // | 157 // |
144 // Returns true if a valid URL was produced, false if not. On failure, the | 158 // Returns true if a valid URL was produced, false if not. On failure, the |
145 // output and parsed structures will still be filled and will be consistent, | 159 // output and parsed structures will still be filled and will be consistent, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 Parsed* out_parsed); | 211 Parsed* out_parsed); |
198 URL_EXPORT bool ReplaceComponents( | 212 URL_EXPORT bool ReplaceComponents( |
199 const char* spec, | 213 const char* spec, |
200 int spec_len, | 214 int spec_len, |
201 const Parsed& parsed, | 215 const Parsed& parsed, |
202 const Replacements<base::char16>& replacements, | 216 const Replacements<base::char16>& replacements, |
203 CharsetConverter* charset_converter, | 217 CharsetConverter* charset_converter, |
204 CanonOutput* output, | 218 CanonOutput* output, |
205 Parsed* out_parsed); | 219 Parsed* out_parsed); |
206 | 220 |
207 // String helper functions ---------------------------------------------------- | 221 // String helper functions ----------------------------------------------------- |
208 | 222 |
209 // Unescapes the given string using URL escaping rules. | 223 // Unescapes the given string using URL escaping rules. |
210 URL_EXPORT void DecodeURLEscapeSequences(const char* input, | 224 URL_EXPORT void DecodeURLEscapeSequences(const char* input, |
211 int length, | 225 int length, |
212 CanonOutputW* output); | 226 CanonOutputW* output); |
213 | 227 |
214 // Escapes the given string as defined by the JS method encodeURIComponent. See | 228 // Escapes the given string as defined by the JS method encodeURIComponent. See |
215 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeUR
IComponent | 229 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeUR
IComponent |
216 URL_EXPORT void EncodeURIComponent(const char* input, | 230 URL_EXPORT void EncodeURIComponent(const char* input, |
217 int length, | 231 int length, |
218 CanonOutput* output); | 232 CanonOutput* output); |
219 | 233 |
220 } // namespace url | 234 } // namespace url |
221 | 235 |
222 #endif // URL_URL_UTIL_H_ | 236 #endif // URL_URL_UTIL_H_ |
OLD | NEW |