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