| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 URL_EXPORT void Initialize(); | 30 URL_EXPORT void Initialize(); |
| 31 | 31 |
| 32 // Cleanup is not required, except some strings may leak. For most user | 32 // 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 | 33 // 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 | 34 // loaded and unloaded, you'll want to unload to properly clean up your |
| 35 // library. | 35 // library. |
| 36 URL_EXPORT void Shutdown(); | 36 URL_EXPORT void Shutdown(); |
| 37 | 37 |
| 38 // Schemes -------------------------------------------------------------------- | 38 // Schemes -------------------------------------------------------------------- |
| 39 | 39 |
| 40 // Types of a scheme representing the requirements on the data represented by | |
| 41 // the authority component of a URL with the scheme. | |
| 42 enum URL_EXPORT SchemeType { | |
| 43 // 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 SCHEME_WITH_PORT, | |
| 46 // The authority component of a URL with the scheme, if any, doesn't have a | |
| 47 // port. | |
| 48 SCHEME_WITHOUT_PORT, | |
| 49 // A URL with the scheme doesn't have the authority component. | |
| 50 SCHEME_WITHOUT_AUTHORITY, | |
| 51 }; | |
| 52 | |
| 53 // A pair for representing a standard scheme name and the SchemeType for it. | |
| 54 struct URL_EXPORT SchemeWithType { | |
| 55 const char* scheme; | |
| 56 SchemeType type; | |
| 57 }; | |
| 58 | |
| 59 // Adds an application-defined scheme to the internal list of "standard-format" | 40 // Adds an application-defined scheme to the internal list of "standard-format" |
| 60 // URL schemes. A standard-format scheme adheres to what RFC 3986 calls "generic | 41 // URL schemes. A standard-format scheme adheres to what RFC 3986 calls "generic |
| 61 // URI syntax" (https://tools.ietf.org/html/rfc3986#section-3). | 42 // URI syntax" (https://tools.ietf.org/html/rfc3986#section-3). |
| 62 // | 43 // |
| 63 // This function is not threadsafe and can not be called concurrently with any | 44 // This function is not threadsafe and can not be called concurrently with any |
| 64 // other url_util function. It will assert if the list of standard schemes has | 45 // other url_util function. It will assert if the list of standard schemes has |
| 65 // been locked (see LockStandardSchemes). | 46 // been locked (see LockStandardSchemes). |
| 66 URL_EXPORT void AddStandardScheme(const char* new_scheme, | 47 URL_EXPORT void AddStandardScheme(const char* new_scheme); |
| 67 SchemeType scheme_type); | |
| 68 | 48 |
| 69 // Sets a flag to prevent future calls to AddStandardScheme from succeeding. | 49 // Sets a flag to prevent future calls to AddStandardScheme from succeeding. |
| 70 // | 50 // |
| 71 // This is designed to help prevent errors for multithreaded applications. | 51 // This is designed to help prevent errors for multithreaded applications. |
| 72 // Normal usage would be to call AddStandardScheme for your custom schemes at | 52 // Normal usage would be to call AddStandardScheme for your custom schemes at |
| 73 // the beginning of program initialization, and then LockStandardSchemes. This | 53 // the beginning of program initialization, and then LockStandardSchemes. This |
| 74 // prevents future callers from mistakenly calling AddStandardScheme when the | 54 // prevents future callers from mistakenly calling AddStandardScheme when the |
| 75 // program is running with multiple threads, where such usage would be | 55 // program is running with multiple threads, where such usage would be |
| 76 // dangerous. | 56 // dangerous. |
| 77 // | 57 // |
| (...skipping 22 matching lines...) Expand all Loading... |
| 100 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), | 80 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), |
| 101 compare, found_scheme); | 81 compare, found_scheme); |
| 102 } | 82 } |
| 103 inline bool FindAndCompareScheme(const base::string16& str, | 83 inline bool FindAndCompareScheme(const base::string16& str, |
| 104 const char* compare, | 84 const char* compare, |
| 105 Component* found_scheme) { | 85 Component* found_scheme) { |
| 106 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), | 86 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), |
| 107 compare, found_scheme); | 87 compare, found_scheme); |
| 108 } | 88 } |
| 109 | 89 |
| 110 // Returns true if the given scheme identified by |scheme| within |spec| is in | 90 // Returns true if the given string represents a URL whose scheme is in the list |
| 111 // the list of known standard-format schemes (see AddStandardScheme). | 91 // of known standard-format schemes (see AddStandardScheme). |
| 112 URL_EXPORT bool IsStandard(const char* spec, const Component& scheme); | 92 URL_EXPORT bool IsStandard(const char* spec, const Component& scheme); |
| 113 URL_EXPORT bool IsStandard(const base::char16* spec, const Component& scheme); | 93 URL_EXPORT bool IsStandard(const base::char16* spec, const Component& scheme); |
| 114 | 94 |
| 115 // Returns true and sets |type| to the SchemeType of the given scheme | |
| 116 // identified by |scheme| within |spec| if the scheme is in the list of known | |
| 117 // standard-format schemes (see AddStandardScheme). | |
| 118 URL_EXPORT bool GetStandardSchemeType(const char* spec, | |
| 119 const Component& scheme, | |
| 120 SchemeType* type); | |
| 121 | |
| 122 // URL library wrappers ------------------------------------------------------- | 95 // URL library wrappers ------------------------------------------------------- |
| 123 | 96 |
| 124 // Parses the given spec according to the extracted scheme type. Normal users | 97 // Parses the given spec according to the extracted scheme type. Normal users |
| 125 // should use the URL object, although this may be useful if performance is | 98 // should use the URL object, although this may be useful if performance is |
| 126 // critical and you don't want to do the heap allocation for the std::string. | 99 // critical and you don't want to do the heap allocation for the std::string. |
| 127 // | 100 // |
| 128 // As with the Canonicalize* functions, the charset converter can | 101 // As with the Canonicalize* functions, the charset converter can |
| 129 // be NULL to use UTF-8 (it will be faster in this case). | 102 // be NULL to use UTF-8 (it will be faster in this case). |
| 130 // | 103 // |
| 131 // Returns true if a valid URL was produced, false if not. On failure, the | 104 // Returns true if a valid URL was produced, false if not. On failure, the |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 173 |
| 201 // Escapes the given string as defined by the JS method encodeURIComponent. See | 174 // Escapes the given string as defined by the JS method encodeURIComponent. See |
| 202 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeUR
IComponent | 175 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeUR
IComponent |
| 203 URL_EXPORT void EncodeURIComponent(const char* input, | 176 URL_EXPORT void EncodeURIComponent(const char* input, |
| 204 int length, | 177 int length, |
| 205 CanonOutput* output); | 178 CanonOutput* output); |
| 206 | 179 |
| 207 } // namespace url | 180 } // namespace url |
| 208 | 181 |
| 209 #endif // URL_URL_UTIL_H_ | 182 #endif // URL_URL_UTIL_H_ |
| OLD | NEW |