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