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" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 116 } |
117 if (found_scheme) | 117 if (found_scheme) |
118 *found_scheme = our_scheme; | 118 *found_scheme = our_scheme; |
119 return DoCompareSchemeComponent(spec, our_scheme, compare); | 119 return DoCompareSchemeComponent(spec, our_scheme, compare); |
120 } | 120 } |
121 | 121 |
122 template<typename CHAR> | 122 template<typename CHAR> |
123 bool DoCanonicalize(const CHAR* in_spec, int in_spec_len, | 123 bool DoCanonicalize(const CHAR* in_spec, int in_spec_len, |
124 url_canon::CharsetConverter* charset_converter, | 124 url_canon::CharsetConverter* charset_converter, |
125 url_canon::CanonOutput* output, | 125 url_canon::CanonOutput* output, |
126 url_parse::Parsed* output_parsed) { | 126 url_parse::Parsed* output_parsed, |
| 127 bool trim_tail = true) { |
127 // Remove any whitespace from the middle of the relative URL, possibly | 128 // Remove any whitespace from the middle of the relative URL, possibly |
128 // copying to the new buffer. | 129 // copying to the new buffer. |
129 url_canon::RawCanonOutputT<CHAR> whitespace_buffer; | 130 url_canon::RawCanonOutputT<CHAR> whitespace_buffer; |
130 int spec_len; | 131 int spec_len; |
131 const CHAR* spec = RemoveURLWhitespace(in_spec, in_spec_len, | 132 const CHAR* spec = RemoveURLWhitespace(in_spec, in_spec_len, |
132 &whitespace_buffer, &spec_len); | 133 &whitespace_buffer, &spec_len); |
133 | 134 |
134 url_parse::Parsed parsed_input; | 135 url_parse::Parsed parsed_input; |
135 #ifdef WIN32 | 136 #ifdef WIN32 |
136 // For Windows, we allow things that look like absolute Windows paths to be | 137 // For Windows, we allow things that look like absolute Windows paths to be |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 output, output_parsed); | 182 output, output_parsed); |
182 | 183 |
183 } else if (DoCompareSchemeComponent(spec, scheme, kMailtoScheme)) { | 184 } else if (DoCompareSchemeComponent(spec, scheme, kMailtoScheme)) { |
184 // Mailto are treated like a standard url with only a scheme, path, query | 185 // Mailto are treated like a standard url with only a scheme, path, query |
185 url_parse::ParseMailtoURL(spec, spec_len, &parsed_input); | 186 url_parse::ParseMailtoURL(spec, spec_len, &parsed_input); |
186 success = url_canon::CanonicalizeMailtoURL(spec, spec_len, parsed_input, | 187 success = url_canon::CanonicalizeMailtoURL(spec, spec_len, parsed_input, |
187 output, output_parsed); | 188 output, output_parsed); |
188 | 189 |
189 } else { | 190 } else { |
190 // "Weird" URLs like data: and javascript: | 191 // "Weird" URLs like data: and javascript: |
191 url_parse::ParsePathURL(spec, spec_len, &parsed_input); | 192 url_parse::ParsePathURL(spec, spec_len, &parsed_input, trim_tail); |
192 success = url_canon::CanonicalizePathURL(spec, spec_len, parsed_input, | 193 success = url_canon::CanonicalizePathURL(spec, spec_len, parsed_input, |
193 output, output_parsed); | 194 output, output_parsed); |
194 } | 195 } |
195 return success; | 196 return success; |
196 } | 197 } |
197 | 198 |
198 template<typename CHAR> | 199 template<typename CHAR> |
199 bool DoResolveRelative(const char* base_spec, | 200 bool DoResolveRelative(const char* base_spec, |
200 int base_spec_len, | 201 int base_spec_len, |
201 const url_parse::Parsed& base_parsed, | 202 const url_parse::Parsed& base_parsed, |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 int str_len, | 425 int str_len, |
425 const char* compare, | 426 const char* compare, |
426 url_parse::Component* found_scheme) { | 427 url_parse::Component* found_scheme) { |
427 return DoFindAndCompareScheme(str, str_len, compare, found_scheme); | 428 return DoFindAndCompareScheme(str, str_len, compare, found_scheme); |
428 } | 429 } |
429 | 430 |
430 bool Canonicalize(const char* spec, | 431 bool Canonicalize(const char* spec, |
431 int spec_len, | 432 int spec_len, |
432 url_canon::CharsetConverter* charset_converter, | 433 url_canon::CharsetConverter* charset_converter, |
433 url_canon::CanonOutput* output, | 434 url_canon::CanonOutput* output, |
434 url_parse::Parsed* output_parsed) { | 435 url_parse::Parsed* output_parsed, |
| 436 bool trim_tail) { |
435 return DoCanonicalize(spec, spec_len, charset_converter, | 437 return DoCanonicalize(spec, spec_len, charset_converter, |
436 output, output_parsed); | 438 output, output_parsed, |
| 439 trim_tail); |
437 } | 440 } |
438 | 441 |
439 bool Canonicalize(const base::char16* spec, | 442 bool Canonicalize(const base::char16* spec, |
440 int spec_len, | 443 int spec_len, |
441 url_canon::CharsetConverter* charset_converter, | 444 url_canon::CharsetConverter* charset_converter, |
442 url_canon::CanonOutput* output, | 445 url_canon::CanonOutput* output, |
443 url_parse::Parsed* output_parsed) { | 446 url_parse::Parsed* output_parsed, |
| 447 bool trim_tail) { |
444 return DoCanonicalize(spec, spec_len, charset_converter, | 448 return DoCanonicalize(spec, spec_len, charset_converter, |
445 output, output_parsed); | 449 output, output_parsed, trim_tail); |
446 } | 450 } |
447 | 451 |
448 bool ResolveRelative(const char* base_spec, | 452 bool ResolveRelative(const char* base_spec, |
449 int base_spec_len, | 453 int base_spec_len, |
450 const url_parse::Parsed& base_parsed, | 454 const url_parse::Parsed& base_parsed, |
451 const char* relative, | 455 const char* relative, |
452 int relative_length, | 456 int relative_length, |
453 url_canon::CharsetConverter* charset_converter, | 457 url_canon::CharsetConverter* charset_converter, |
454 url_canon::CanonOutput* output, | 458 url_canon::CanonOutput* output, |
455 url_parse::Parsed* output_parsed) { | 459 url_parse::Parsed* output_parsed) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 return DoCompareSchemeComponent(spec, component, compare_to); | 589 return DoCompareSchemeComponent(spec, component, compare_to); |
586 } | 590 } |
587 | 591 |
588 bool CompareSchemeComponent(const base::char16* spec, | 592 bool CompareSchemeComponent(const base::char16* spec, |
589 const url_parse::Component& component, | 593 const url_parse::Component& component, |
590 const char* compare_to) { | 594 const char* compare_to) { |
591 return DoCompareSchemeComponent(spec, component, compare_to); | 595 return DoCompareSchemeComponent(spec, component, compare_to); |
592 } | 596 } |
593 | 597 |
594 } // namespace url_util | 598 } // namespace url_util |
OLD | NEW |