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 #include "url/url_util.h" | 5 #include "url/url_util.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "url/url_canon_internal.h" | 11 #include "url/url_canon_internal.h" |
12 #include "url/url_file.h" | 12 #include "url/url_file.h" |
13 #include "url/url_util_internal.h" | 13 #include "url/url_util_internal.h" |
14 | 14 |
15 namespace url { | 15 namespace url { |
16 | 16 |
17 const char kFileScheme[] = "file"; | |
18 const char kFileSystemScheme[] = "filesystem"; | |
19 const char kMailtoScheme[] = "mailto"; | |
20 | |
21 namespace { | 17 namespace { |
22 | 18 |
23 // ASCII-specific tolower. The standard library's tolower is locale sensitive, | 19 // ASCII-specific tolower. The standard library's tolower is locale sensitive, |
24 // so we don't want to use it here. | 20 // so we don't want to use it here. |
25 template<class Char> | 21 template<class Char> |
26 inline Char ToLowerASCII(Char c) { | 22 inline Char ToLowerASCII(Char c) { |
27 return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c; | 23 return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c; |
28 } | 24 } |
29 | 25 |
30 // Backend for LowerCaseEqualsASCII. | 26 // Backend for LowerCaseEqualsASCII. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 150 } |
155 #endif | 151 #endif |
156 | 152 |
157 Component scheme; | 153 Component scheme; |
158 if (!ExtractScheme(spec, spec_len, &scheme)) | 154 if (!ExtractScheme(spec, spec_len, &scheme)) |
159 return false; | 155 return false; |
160 | 156 |
161 // This is the parsed version of the input URL, we have to canonicalize it | 157 // This is the parsed version of the input URL, we have to canonicalize it |
162 // before storing it in our object. | 158 // before storing it in our object. |
163 bool success; | 159 bool success; |
164 if (DoCompareSchemeComponent(spec, scheme, kFileScheme)) { | 160 if (DoCompareSchemeComponent(spec, scheme, url::kFileScheme)) { |
165 // File URLs are special. | 161 // File URLs are special. |
166 ParseFileURL(spec, spec_len, &parsed_input); | 162 ParseFileURL(spec, spec_len, &parsed_input); |
167 success = CanonicalizeFileURL(spec, spec_len, parsed_input, | 163 success = CanonicalizeFileURL(spec, spec_len, parsed_input, |
168 charset_converter, output, output_parsed); | 164 charset_converter, output, output_parsed); |
169 } else if (DoCompareSchemeComponent(spec, scheme, kFileSystemScheme)) { | 165 } else if (DoCompareSchemeComponent(spec, scheme, url::kFileSystemScheme)) { |
170 // Filesystem URLs are special. | 166 // Filesystem URLs are special. |
171 ParseFileSystemURL(spec, spec_len, &parsed_input); | 167 ParseFileSystemURL(spec, spec_len, &parsed_input); |
172 success = CanonicalizeFileSystemURL(spec, spec_len, parsed_input, | 168 success = CanonicalizeFileSystemURL(spec, spec_len, parsed_input, |
173 charset_converter, output, | 169 charset_converter, output, |
174 output_parsed); | 170 output_parsed); |
175 | 171 |
176 } else if (DoIsStandard(spec, scheme)) { | 172 } else if (DoIsStandard(spec, scheme)) { |
177 // All "normal" URLs. | 173 // All "normal" URLs. |
178 ParseStandardURL(spec, spec_len, &parsed_input); | 174 ParseStandardURL(spec, spec_len, &parsed_input); |
179 success = CanonicalizeStandardURL(spec, spec_len, parsed_input, | 175 success = CanonicalizeStandardURL(spec, spec_len, parsed_input, |
180 charset_converter, output, output_parsed); | 176 charset_converter, output, output_parsed); |
181 | 177 |
182 } else if (DoCompareSchemeComponent(spec, scheme, kMailtoScheme)) { | 178 } else if (DoCompareSchemeComponent(spec, scheme, url::kMailToScheme)) { |
183 // Mailto are treated like a standard url with only a scheme, path, query | 179 // Mailto are treated like a standard url with only a scheme, path, query |
184 ParseMailtoURL(spec, spec_len, &parsed_input); | 180 ParseMailtoURL(spec, spec_len, &parsed_input); |
185 success = CanonicalizeMailtoURL(spec, spec_len, parsed_input, output, | 181 success = CanonicalizeMailtoURL(spec, spec_len, parsed_input, output, |
186 output_parsed); | 182 output_parsed); |
187 | 183 |
188 } else { | 184 } else { |
189 // "Weird" URLs like data: and javascript: | 185 // "Weird" URLs like data: and javascript: |
190 ParsePathURL(spec, spec_len, trim_path_end, &parsed_input); | 186 ParsePathURL(spec, spec_len, trim_path_end, &parsed_input); |
191 success = CanonicalizePathURL(spec, spec_len, parsed_input, output, | 187 success = CanonicalizePathURL(spec, spec_len, parsed_input, output, |
192 output_parsed); | 188 output_parsed); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 // ref). | 324 // ref). |
329 Replacements<CHAR> replacements_no_scheme = replacements; | 325 Replacements<CHAR> replacements_no_scheme = replacements; |
330 replacements_no_scheme.SetScheme(NULL, Component()); | 326 replacements_no_scheme.SetScheme(NULL, Component()); |
331 return DoReplaceComponents(recanonicalized.data(), recanonicalized.length(), | 327 return DoReplaceComponents(recanonicalized.data(), recanonicalized.length(), |
332 recanonicalized_parsed, replacements_no_scheme, | 328 recanonicalized_parsed, replacements_no_scheme, |
333 charset_converter, output, out_parsed); | 329 charset_converter, output, out_parsed); |
334 } | 330 } |
335 | 331 |
336 // If we get here, then we know the scheme doesn't need to be replaced, so can | 332 // If we get here, then we know the scheme doesn't need to be replaced, so can |
337 // just key off the scheme in the spec to know how to do the replacements. | 333 // just key off the scheme in the spec to know how to do the replacements. |
338 if (DoCompareSchemeComponent(spec, parsed.scheme, kFileScheme)) { | 334 if (DoCompareSchemeComponent(spec, parsed.scheme, url::kFileScheme)) { |
339 return ReplaceFileURL(spec, parsed, replacements, charset_converter, output, | 335 return ReplaceFileURL(spec, parsed, replacements, charset_converter, output, |
340 out_parsed); | 336 out_parsed); |
341 } | 337 } |
342 if (DoCompareSchemeComponent(spec, parsed.scheme, kFileSystemScheme)) { | 338 if (DoCompareSchemeComponent(spec, parsed.scheme, url::kFileSystemScheme)) { |
343 return ReplaceFileSystemURL(spec, parsed, replacements, charset_converter, | 339 return ReplaceFileSystemURL(spec, parsed, replacements, charset_converter, |
344 output, out_parsed); | 340 output, out_parsed); |
345 } | 341 } |
346 if (DoIsStandard(spec, parsed.scheme)) { | 342 if (DoIsStandard(spec, parsed.scheme)) { |
347 return ReplaceStandardURL(spec, parsed, replacements, charset_converter, | 343 return ReplaceStandardURL(spec, parsed, replacements, charset_converter, |
348 output, out_parsed); | 344 output, out_parsed); |
349 } | 345 } |
350 if (DoCompareSchemeComponent(spec, parsed.scheme, kMailtoScheme)) { | 346 if (DoCompareSchemeComponent(spec, parsed.scheme, url::kMailToScheme)) { |
351 return ReplaceMailtoURL(spec, parsed, replacements, output, out_parsed); | 347 return ReplaceMailtoURL(spec, parsed, replacements, output, out_parsed); |
352 } | 348 } |
353 | 349 |
354 // Default is a path URL. | 350 // Default is a path URL. |
355 return ReplacePathURL(spec, parsed, replacements, output, out_parsed); | 351 return ReplacePathURL(spec, parsed, replacements, output, out_parsed); |
356 } | 352 } |
357 | 353 |
358 } // namespace | 354 } // namespace |
359 | 355 |
360 void Initialize() { | 356 void Initialize() { |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 return DoCompareSchemeComponent(spec, component, compare_to); | 574 return DoCompareSchemeComponent(spec, component, compare_to); |
579 } | 575 } |
580 | 576 |
581 bool CompareSchemeComponent(const base::char16* spec, | 577 bool CompareSchemeComponent(const base::char16* spec, |
582 const Component& component, | 578 const Component& component, |
583 const char* compare_to) { | 579 const char* compare_to) { |
584 return DoCompareSchemeComponent(spec, component, compare_to); | 580 return DoCompareSchemeComponent(spec, component, compare_to); |
585 } | 581 } |
586 | 582 |
587 } // namespace url | 583 } // namespace url |
OLD | NEW |