| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 185 } |
| 186 | 186 |
| 187 template <typename CHAR> | 187 template <typename CHAR> |
| 188 bool DoCanonicalize(const CHAR* spec, | 188 bool DoCanonicalize(const CHAR* spec, |
| 189 int spec_len, | 189 int spec_len, |
| 190 bool trim_path_end, | 190 bool trim_path_end, |
| 191 WhitespaceRemovalPolicy whitespace_policy, | 191 WhitespaceRemovalPolicy whitespace_policy, |
| 192 CharsetConverter* charset_converter, | 192 CharsetConverter* charset_converter, |
| 193 CanonOutput* output, | 193 CanonOutput* output, |
| 194 Parsed* output_parsed) { | 194 Parsed* output_parsed) { |
| 195 // Reserve enough room in the output for the input, plus some extra so that | 195 output->ReserveSizeIfNeeded(spec_len); |
| 196 // we have room if we have to escape a few things without reallocating. | |
| 197 output->ReserveSizeIfNeeded(spec_len + 8); | |
| 198 | 196 |
| 199 // Remove any whitespace from the middle of the relative URL if necessary. | 197 // Remove any whitespace from the middle of the relative URL if necessary. |
| 200 // Possibly this will result in copying to the new buffer. | 198 // Possibly this will result in copying to the new buffer. |
| 201 RawCanonOutputT<CHAR> whitespace_buffer; | 199 RawCanonOutputT<CHAR> whitespace_buffer; |
| 202 if (whitespace_policy == REMOVE_WHITESPACE) | 200 if (whitespace_policy == REMOVE_WHITESPACE) |
| 203 spec = RemoveURLWhitespace(spec, spec_len, &whitespace_buffer, &spec_len); | 201 spec = RemoveURLWhitespace(spec, spec_len, &whitespace_buffer, &spec_len); |
| 204 | 202 |
| 205 Parsed parsed_input; | 203 Parsed parsed_input; |
| 206 #ifdef WIN32 | 204 #ifdef WIN32 |
| 207 // For Windows, we allow things that look like absolute Windows paths to be | 205 // For Windows, we allow things that look like absolute Windows paths to be |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 replacements_no_scheme.SetScheme(NULL, Component()); | 405 replacements_no_scheme.SetScheme(NULL, Component()); |
| 408 return DoReplaceComponents(recanonicalized.data(), recanonicalized.length(), | 406 return DoReplaceComponents(recanonicalized.data(), recanonicalized.length(), |
| 409 recanonicalized_parsed, replacements_no_scheme, | 407 recanonicalized_parsed, replacements_no_scheme, |
| 410 charset_converter, output, out_parsed); | 408 charset_converter, output, out_parsed); |
| 411 } | 409 } |
| 412 | 410 |
| 413 // TODO(csharrison): We could be smarter about size to reserve if this is done | 411 // TODO(csharrison): We could be smarter about size to reserve if this is done |
| 414 // in callers below, and the code checks to see which components are being | 412 // in callers below, and the code checks to see which components are being |
| 415 // replaced, and with what length. If this ends up being a hot spot it should | 413 // replaced, and with what length. If this ends up being a hot spot it should |
| 416 // be changed. | 414 // be changed. |
| 417 output->ReserveSizeIfNeeded(spec_len + 8); | 415 output->ReserveSizeIfNeeded(spec_len); |
| 418 | 416 |
| 419 // If we get here, then we know the scheme doesn't need to be replaced, so can | 417 // If we get here, then we know the scheme doesn't need to be replaced, so can |
| 420 // just key off the scheme in the spec to know how to do the replacements. | 418 // just key off the scheme in the spec to know how to do the replacements. |
| 421 if (DoCompareSchemeComponent(spec, parsed.scheme, url::kFileScheme)) { | 419 if (DoCompareSchemeComponent(spec, parsed.scheme, url::kFileScheme)) { |
| 422 return ReplaceFileURL(spec, parsed, replacements, charset_converter, output, | 420 return ReplaceFileURL(spec, parsed, replacements, charset_converter, output, |
| 423 out_parsed); | 421 out_parsed); |
| 424 } | 422 } |
| 425 if (DoCompareSchemeComponent(spec, parsed.scheme, url::kFileSystemScheme)) { | 423 if (DoCompareSchemeComponent(spec, parsed.scheme, url::kFileSystemScheme)) { |
| 426 return ReplaceFileSystemURL(spec, parsed, replacements, charset_converter, | 424 return ReplaceFileSystemURL(spec, parsed, replacements, charset_converter, |
| 427 output, out_parsed); | 425 output, out_parsed); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 return DoCompareSchemeComponent(spec, component, compare_to); | 791 return DoCompareSchemeComponent(spec, component, compare_to); |
| 794 } | 792 } |
| 795 | 793 |
| 796 bool CompareSchemeComponent(const base::char16* spec, | 794 bool CompareSchemeComponent(const base::char16* spec, |
| 797 const Component& component, | 795 const Component& component, |
| 798 const char* compare_to) { | 796 const char* compare_to) { |
| 799 return DoCompareSchemeComponent(spec, component, compare_to); | 797 return DoCompareSchemeComponent(spec, component, compare_to); |
| 800 } | 798 } |
| 801 | 799 |
| 802 } // namespace url | 800 } // namespace url |
| OLD | NEW |