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 "url/url_canon.h" | 11 #include "url/url_canon.h" |
12 #include "url/url_constants.h" | 12 #include "url/url_constants.h" |
13 #include "url/url_export.h" | 13 #include "url/url_export.h" |
14 #include "url/url_parse.h" | 14 #include "url/url_parse.h" |
15 | 15 |
16 namespace url { | 16 namespace url { |
17 | 17 |
18 // Init ------------------------------------------------------------------------ | 18 // Init ------------------------------------------------------------------------ |
19 | 19 |
20 // Initialization is NOT required, it will be implicitly initialized when first | 20 // Initialization is NOT required, it will be implicitly initialized when first |
21 // used. However, this implicit initialization is NOT threadsafe. If you are | 21 // 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 | 22 // using this library in a threaded environment and don't have a consistent |
23 // "first call" (an example might be calling "AddStandardScheme" with your | 23 // "first call" (an example might be calling AddStandardScheme with your special |
24 // special application-specific schemes) then you will want to call initialize | 24 // application-specific schemes) then you will want to call initialize before |
25 // before spawning any threads. | 25 // spawning any threads. |
26 // | 26 // |
27 // It is OK to call this function more than once, subsequent calls will simply | 27 // It is OK to call this function more than once, subsequent calls will be |
28 // "noop", unless Shutdown() was called in the mean time. This will also be a | 28 // no-ops, unless Shutdown was called in the mean time. This will also be a |
29 // "noop" if other calls to the library have forced an initialization | 29 // no-op if other calls to the library have forced an initialization beforehand. |
30 // beforehand. | |
31 URL_EXPORT void Initialize(); | 30 URL_EXPORT void Initialize(); |
32 | 31 |
33 // 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 |
34 // 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 |
35 // 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 |
36 // library. | 35 // library. |
37 URL_EXPORT void Shutdown(); | 36 URL_EXPORT void Shutdown(); |
38 | 37 |
39 // Schemes -------------------------------------------------------------------- | 38 // Schemes -------------------------------------------------------------------- |
40 | 39 |
41 // Adds an application-defined scheme to the internal list of "standard" URL | 40 // Adds an application-defined scheme to the internal list of "standard-format" |
42 // schemes. This function is not threadsafe and can not be called concurrently | 41 // URL schemes. A standard-format scheme adheres to what RFC 3986 calls "generic |
43 // with any other url_util function. It will assert if the list of standard | 42 // URI syntax" (https://tools.ietf.org/html/rfc3986#section-3). |
44 // schemes has been locked (see LockStandardSchemes). | 43 // |
| 44 // 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 |
| 46 // been locked (see LockStandardSchemes). |
45 URL_EXPORT void AddStandardScheme(const char* new_scheme); | 47 URL_EXPORT void AddStandardScheme(const char* new_scheme); |
46 | 48 |
47 // Sets a flag to prevent future calls to AddStandardScheme from succeeding. | 49 // Sets a flag to prevent future calls to AddStandardScheme from succeeding. |
48 // | 50 // |
49 // This is designed to help prevent errors for multithreaded applications. | 51 // This is designed to help prevent errors for multithreaded applications. |
50 // 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 |
51 // the beginning of program initialization, and then LockStandardSchemes. This | 53 // the beginning of program initialization, and then LockStandardSchemes. This |
52 // prevents future callers from mistakenly calling AddStandardScheme when the | 54 // prevents future callers from mistakenly calling AddStandardScheme when the |
53 // program is running with multiple threads, where such usage would be | 55 // program is running with multiple threads, where such usage would be |
54 // dangerous. | 56 // dangerous. |
(...skipping 23 matching lines...) Expand all Loading... |
78 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), | 80 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), |
79 compare, found_scheme); | 81 compare, found_scheme); |
80 } | 82 } |
81 inline bool FindAndCompareScheme(const base::string16& str, | 83 inline bool FindAndCompareScheme(const base::string16& str, |
82 const char* compare, | 84 const char* compare, |
83 Component* found_scheme) { | 85 Component* found_scheme) { |
84 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), | 86 return FindAndCompareScheme(str.data(), static_cast<int>(str.size()), |
85 compare, found_scheme); | 87 compare, found_scheme); |
86 } | 88 } |
87 | 89 |
88 // Returns true if the given string represents a standard URL. This means that | 90 // Returns true if the given string represents a URL whose scheme is in the list |
89 // either the scheme is in the list of known standard schemes. | 91 // of known standard-format schemes (see AddStandardScheme). |
90 URL_EXPORT bool IsStandard(const char* spec, const Component& scheme); | 92 URL_EXPORT bool IsStandard(const char* spec, const Component& scheme); |
91 URL_EXPORT bool IsStandard(const base::char16* spec, const Component& scheme); | 93 URL_EXPORT bool IsStandard(const base::char16* spec, const Component& scheme); |
92 | 94 |
93 // TODO(brettw) remove this. This is a temporary compatibility hack to avoid | |
94 // breaking the WebKit build when this version is synced via Chrome. | |
95 inline bool IsStandard(const char* spec, | |
96 int spec_len, | |
97 const Component& scheme) { | |
98 return IsStandard(spec, scheme); | |
99 } | |
100 | |
101 // URL library wrappers ------------------------------------------------------- | 95 // URL library wrappers ------------------------------------------------------- |
102 | 96 |
103 // 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 |
104 // 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 |
105 // 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. |
106 // | 100 // |
107 // As with the Canonicalize* functions, the charset converter can | 101 // As with the Canonicalize* functions, the charset converter can |
108 // 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). |
109 // | 103 // |
110 // 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 190 |
197 // Escapes the given string as defined by the JS method encodeURIComponent. See | 191 // Escapes the given string as defined by the JS method encodeURIComponent. See |
198 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeUR
IComponent | 192 // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeUR
IComponent |
199 URL_EXPORT void EncodeURIComponent(const char* input, | 193 URL_EXPORT void EncodeURIComponent(const char* input, |
200 int length, | 194 int length, |
201 CanonOutput* output); | 195 CanonOutput* output); |
202 | 196 |
203 } // namespace url | 197 } // namespace url |
204 | 198 |
205 #endif // URL_URL_UTIL_H_ | 199 #endif // URL_URL_UTIL_H_ |
OLD | NEW |