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_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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 // Returns true if the given scheme identified by |scheme| within |spec| is in | 125 // Returns true if the given scheme identified by |scheme| within |spec| is in |
| 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); |
| 135 // Domains --------------------------------------------------------------------- | |
|
engedy
2016/08/30 17:13:13
nit: Blank line before.
pkalinnikov
2016/08/31 08:43:10
Done.
| |
| 134 | 136 |
| 135 // URL library wrappers ------------------------------------------------------- | 137 // Returns true if the |canonicalized_host| matches or is in the same domain as |
| 138 // the given |lower_ascii_domain| string. For example, if the canonicalized | |
| 139 // hostname is "www.google.com", this will return true for "com", "google.com", | |
| 140 // and "www.google.com" domains. | |
| 141 // | |
| 142 // If either of the input StringPieces is empty, the return value is false. The | |
| 143 // input domain should be a lower-case ASCII string in order to match the | |
| 144 // canonicalized host. | |
| 145 URL_EXPORT bool DomainIs(base::StringPiece canonicalized_host, | |
| 146 base::StringPiece lower_ascii_domain); | |
| 147 | |
| 148 // URL library wrappers -------------------------------------------------------- | |
| 136 | 149 |
| 137 // Parses the given spec according to the extracted scheme type. Normal users | 150 // 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 | 151 // 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. | 152 // critical and you don't want to do the heap allocation for the std::string. |
| 140 // | 153 // |
| 141 // As with the Canonicalize* functions, the charset converter can | 154 // As with the Canonicalize* functions, the charset converter can |
| 142 // be NULL to use UTF-8 (it will be faster in this case). | 155 // be NULL to use UTF-8 (it will be faster in this case). |
| 143 // | 156 // |
| 144 // Returns true if a valid URL was produced, false if not. On failure, the | 157 // 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, | 158 // 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); | 210 Parsed* out_parsed); |
| 198 URL_EXPORT bool ReplaceComponents( | 211 URL_EXPORT bool ReplaceComponents( |
| 199 const char* spec, | 212 const char* spec, |
| 200 int spec_len, | 213 int spec_len, |
| 201 const Parsed& parsed, | 214 const Parsed& parsed, |
| 202 const Replacements<base::char16>& replacements, | 215 const Replacements<base::char16>& replacements, |
| 203 CharsetConverter* charset_converter, | 216 CharsetConverter* charset_converter, |
| 204 CanonOutput* output, | 217 CanonOutput* output, |
| 205 Parsed* out_parsed); | 218 Parsed* out_parsed); |
| 206 | 219 |
| 207 // String helper functions ---------------------------------------------------- | 220 // String helper functions ----------------------------------------------------- |
| 208 | 221 |
| 209 // Unescapes the given string using URL escaping rules. | 222 // Unescapes the given string using URL escaping rules. |
| 210 URL_EXPORT void DecodeURLEscapeSequences(const char* input, | 223 URL_EXPORT void DecodeURLEscapeSequences(const char* input, |
| 211 int length, | 224 int length, |
| 212 CanonOutputW* output); | 225 CanonOutputW* output); |
| 213 | 226 |
| 214 // Escapes the given string as defined by the JS method encodeURIComponent. See | 227 // Escapes the given string as defined by the JS method encodeURIComponent. See |
| 215 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeUR IComponent | 228 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeUR IComponent |
| 216 URL_EXPORT void EncodeURIComponent(const char* input, | 229 URL_EXPORT void EncodeURIComponent(const char* input, |
| 217 int length, | 230 int length, |
| 218 CanonOutput* output); | 231 CanonOutput* output); |
| 219 | 232 |
| 220 } // namespace url | 233 } // namespace url |
| 221 | 234 |
| 222 #endif // URL_URL_UTIL_H_ | 235 #endif // URL_URL_UTIL_H_ |
| OLD | NEW |