Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Side by Side Diff: url/url_util.cc

Issue 23835019: Support URL fragment resolution againt non-hierarchical schemes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: brettw2 Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « url/url_util.h ('k') | url/url_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 *found_scheme = url_parse::Component(); 114 *found_scheme = url_parse::Component();
115 return false; 115 return false;
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 bool trim_path_end,
124 url_canon::CharsetConverter* charset_converter, 125 url_canon::CharsetConverter* charset_converter,
125 url_canon::CanonOutput* output, 126 url_canon::CanonOutput* output,
126 url_parse::Parsed* output_parsed) { 127 url_parse::Parsed* output_parsed) {
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
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, trim_path_end, &parsed_input);
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 ParseStandardURL(base_spec, base_spec_len, &base_parsed_authority); 246 ParseStandardURL(base_spec, base_spec_len, &base_parsed_authority);
246 if (base_parsed_authority.host.is_nonempty()) { 247 if (base_parsed_authority.host.is_nonempty()) {
247 bool did_resolve_succeed = 248 bool did_resolve_succeed =
248 url_canon::ResolveRelativeURL(base_spec, base_parsed_authority, 249 url_canon::ResolveRelativeURL(base_spec, base_parsed_authority,
249 false, relative, 250 false, relative,
250 relative_component, charset_converter, 251 relative_component, charset_converter,
251 output, output_parsed); 252 output, output_parsed);
252 // The output_parsed is incorrect at this point (because it was built 253 // The output_parsed is incorrect at this point (because it was built
253 // based on base_parsed_authority instead of base_parsed) and needs to be 254 // based on base_parsed_authority instead of base_parsed) and needs to be
254 // re-created. 255 // re-created.
255 ParsePathURL(output->data(), output->length(), output_parsed); 256 ParsePathURL(output->data(), output->length(), true,
257 output_parsed);
256 return did_resolve_succeed; 258 return did_resolve_succeed;
257 } 259 }
258 } else if (is_relative) { 260 } else if (is_relative) {
259 // Relative, resolve and canonicalize. 261 // Relative, resolve and canonicalize.
260 bool file_base_scheme = base_parsed.scheme.is_nonempty() && 262 bool file_base_scheme = base_parsed.scheme.is_nonempty() &&
261 DoCompareSchemeComponent(base_spec, base_parsed.scheme, kFileScheme); 263 DoCompareSchemeComponent(base_spec, base_parsed.scheme, kFileScheme);
262 return url_canon::ResolveRelativeURL(base_spec, base_parsed, 264 return url_canon::ResolveRelativeURL(base_spec, base_parsed,
263 file_base_scheme, relative, 265 file_base_scheme, relative,
264 relative_component, charset_converter, 266 relative_component, charset_converter,
265 output, output_parsed); 267 output, output_parsed);
266 } 268 }
267 269
268 // Not relative, canonicalize the input. 270 // Not relative, canonicalize the input.
269 return DoCanonicalize(relative, relative_length, charset_converter, 271 return DoCanonicalize(relative, relative_length, true, charset_converter,
270 output, output_parsed); 272 output, output_parsed);
271 } 273 }
272 274
273 template<typename CHAR> 275 template<typename CHAR>
274 bool DoReplaceComponents(const char* spec, 276 bool DoReplaceComponents(const char* spec,
275 int spec_len, 277 int spec_len,
276 const url_parse::Parsed& parsed, 278 const url_parse::Parsed& parsed,
277 const url_canon::Replacements<CHAR>& replacements, 279 const url_canon::Replacements<CHAR>& replacements,
278 url_canon::CharsetConverter* charset_converter, 280 url_canon::CharsetConverter* charset_converter,
279 url_canon::CanonOutput* output, 281 url_canon::CanonOutput* output,
(...skipping 27 matching lines...) Expand all
307 : 1; 309 : 1;
308 if (spec_len - spec_after_colon > 0) { 310 if (spec_len - spec_after_colon > 0) {
309 scheme_replaced.Append(&spec[spec_after_colon], 311 scheme_replaced.Append(&spec[spec_after_colon],
310 spec_len - spec_after_colon); 312 spec_len - spec_after_colon);
311 } 313 }
312 314
313 // We now need to completely re-parse the resulting string since its meaning 315 // We now need to completely re-parse the resulting string since its meaning
314 // may have changed with the different scheme. 316 // may have changed with the different scheme.
315 url_canon::RawCanonOutput<128> recanonicalized; 317 url_canon::RawCanonOutput<128> recanonicalized;
316 url_parse::Parsed recanonicalized_parsed; 318 url_parse::Parsed recanonicalized_parsed;
317 DoCanonicalize(scheme_replaced.data(), scheme_replaced.length(), 319 DoCanonicalize(scheme_replaced.data(), scheme_replaced.length(), true,
318 charset_converter, 320 charset_converter,
319 &recanonicalized, &recanonicalized_parsed); 321 &recanonicalized, &recanonicalized_parsed);
320 322
321 // Recurse using the version with the scheme already replaced. This will now 323 // Recurse using the version with the scheme already replaced. This will now
322 // use the replacement rules for the new scheme. 324 // use the replacement rules for the new scheme.
323 // 325 //
324 // Warning: this code assumes that ReplaceComponents will re-check all 326 // Warning: this code assumes that ReplaceComponents will re-check all
325 // components for validity. This is because we can't fail if DoCanonicalize 327 // components for validity. This is because we can't fail if DoCanonicalize
326 // failed above since theoretically the thing making it fail could be 328 // failed above since theoretically the thing making it fail could be
327 // getting replaced here. If ReplaceComponents didn't re-check everything, 329 // getting replaced here. If ReplaceComponents didn't re-check everything,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 424
423 bool FindAndCompareScheme(const base::char16* str, 425 bool FindAndCompareScheme(const base::char16* str,
424 int str_len, 426 int str_len,
425 const char* compare, 427 const char* compare,
426 url_parse::Component* found_scheme) { 428 url_parse::Component* found_scheme) {
427 return DoFindAndCompareScheme(str, str_len, compare, found_scheme); 429 return DoFindAndCompareScheme(str, str_len, compare, found_scheme);
428 } 430 }
429 431
430 bool Canonicalize(const char* spec, 432 bool Canonicalize(const char* spec,
431 int spec_len, 433 int spec_len,
434 bool trim_path_end,
432 url_canon::CharsetConverter* charset_converter, 435 url_canon::CharsetConverter* charset_converter,
433 url_canon::CanonOutput* output, 436 url_canon::CanonOutput* output,
434 url_parse::Parsed* output_parsed) { 437 url_parse::Parsed* output_parsed) {
435 return DoCanonicalize(spec, spec_len, charset_converter, 438 return DoCanonicalize(spec, spec_len, trim_path_end, charset_converter,
436 output, output_parsed); 439 output, output_parsed);
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,
444 bool trim_path_end,
441 url_canon::CharsetConverter* charset_converter, 445 url_canon::CharsetConverter* charset_converter,
442 url_canon::CanonOutput* output, 446 url_canon::CanonOutput* output,
443 url_parse::Parsed* output_parsed) { 447 url_parse::Parsed* output_parsed) {
444 return DoCanonicalize(spec, spec_len, charset_converter, 448 return DoCanonicalize(spec, spec_len, trim_path_end, charset_converter,
445 output, output_parsed); 449 output, output_parsed);
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,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « url/url_util.h ('k') | url/url_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698