| OLD | NEW |
| 1 /* Based on nsURLParsers.cc from Mozilla | 1 /* Based on nsURLParsers.cc from Mozilla |
| 2 * ------------------------------------- | 2 * ------------------------------------- |
| 3 * The contents of this file are subject to the Mozilla Public License Version | 3 * The contents of this file are subject to the Mozilla Public License Version |
| 4 * 1.1 (the "License"); you may not use this file except in compliance with | 4 * 1.1 (the "License"); you may not use this file except in compliance with |
| 5 * the License. You may obtain a copy of the License at | 5 * the License. You may obtain a copy of the License at |
| 6 * http://www.mozilla.org/MPL/ | 6 * http://www.mozilla.org/MPL/ |
| 7 * | 7 * |
| 8 * Software distributed under the License is distributed on an "AS IS" basis, | 8 * Software distributed under the License is distributed on an "AS IS" basis, |
| 9 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 9 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 10 * for the specific language governing rights and limitations under the | 10 * for the specific language governing rights and limitations under the |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 // Initializes a path URL which is merely a scheme followed by a path. Examples | 455 // Initializes a path URL which is merely a scheme followed by a path. Examples |
| 456 // include "about:foo" and "javascript:alert('bar');" | 456 // include "about:foo" and "javascript:alert('bar');" |
| 457 template<typename CHAR> | 457 template<typename CHAR> |
| 458 void DoParsePathURL(const CHAR* spec, int spec_len, Parsed* parsed) { | 458 void DoParsePathURL(const CHAR* spec, int spec_len, Parsed* parsed) { |
| 459 // Get the non-path and non-scheme parts of the URL out of the way, we never | 459 // Get the non-path and non-scheme parts of the URL out of the way, we never |
| 460 // use them. | 460 // use them. |
| 461 parsed->username.reset(); | 461 parsed->username.reset(); |
| 462 parsed->password.reset(); | 462 parsed->password.reset(); |
| 463 parsed->host.reset(); | 463 parsed->host.reset(); |
| 464 parsed->port.reset(); | 464 parsed->port.reset(); |
| 465 parsed->path.reset(); |
| 465 parsed->query.reset(); | 466 parsed->query.reset(); |
| 466 parsed->ref.reset(); | 467 parsed->ref.reset(); |
| 467 | 468 |
| 468 // Strip leading & trailing spaces and control characters. | 469 // Strip leading & trailing spaces and control characters. |
| 469 int begin = 0; | 470 int begin = 0; |
| 470 TrimURL(spec, &begin, &spec_len); | 471 TrimURL(spec, &begin, &spec_len); |
| 471 | 472 |
| 472 // Handle empty specs or ones that contain only whitespace or control chars. | 473 // Handle empty specs or ones that contain only whitespace or control chars. |
| 473 if (begin == spec_len) { | 474 if (begin == spec_len) { |
| 474 parsed->scheme.reset(); | 475 parsed->scheme.reset(); |
| 475 parsed->path.reset(); | 476 parsed->path.reset(); |
| 476 return; | 477 return; |
| 477 } | 478 } |
| 478 | 479 |
| 479 // Extract the scheme, with the path being everything following. We also | 480 // Extract the scheme, with the path being everything following. We also |
| 480 // handle the case where there is no scheme. | 481 // handle the case where there is no scheme. |
| 481 if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) { | 482 if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) { |
| 482 // Offset the results since we gave ExtractScheme a substring. | 483 // Offset the results since we gave ExtractScheme a substring. |
| 483 parsed->scheme.begin += begin; | 484 parsed->scheme.begin += begin; |
| 485 begin = parsed->scheme.end() + 1; |
| 486 } else { |
| 487 parsed->scheme.reset(); |
| 488 } |
| 484 | 489 |
| 485 // For compatability with the standard URL parser, we treat no path as | 490 if (begin == spec_len) |
| 486 // -1, rather than having a length of 0 (we normally wouldn't care so | 491 return; |
| 487 // much for these non-standard URLs). | 492 DCHECK_LT(begin, spec_len); |
| 488 if (parsed->scheme.end() == spec_len - 1) | 493 |
| 489 parsed->path.reset(); | 494 ParsePath(spec, |
| 490 else | 495 MakeRange(begin, spec_len), |
| 491 parsed->path = MakeRange(parsed->scheme.end() + 1, spec_len); | 496 &parsed->path, |
| 492 } else { | 497 &parsed->query, |
| 493 // No scheme found, just path. | 498 &parsed->ref); |
| 494 parsed->scheme.reset(); | |
| 495 parsed->path = MakeRange(begin, spec_len); | |
| 496 } | |
| 497 } | 499 } |
| 498 | 500 |
| 499 template<typename CHAR> | 501 template<typename CHAR> |
| 500 void DoParseMailtoURL(const CHAR* spec, int spec_len, Parsed* parsed) { | 502 void DoParseMailtoURL(const CHAR* spec, int spec_len, Parsed* parsed) { |
| 501 DCHECK(spec_len >= 0); | 503 DCHECK(spec_len >= 0); |
| 502 | 504 |
| 503 // Get the non-path and non-scheme parts of the URL out of the way, we never | 505 // Get the non-path and non-scheme parts of the URL out of the way, we never |
| 504 // use them. | 506 // use them. |
| 505 parsed->username.reset(); | 507 parsed->username.reset(); |
| 506 parsed->password.reset(); | 508 parsed->password.reset(); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 } | 925 } |
| 924 | 926 |
| 925 void ParseAfterScheme(const base::char16* spec, | 927 void ParseAfterScheme(const base::char16* spec, |
| 926 int spec_len, | 928 int spec_len, |
| 927 int after_scheme, | 929 int after_scheme, |
| 928 Parsed* parsed) { | 930 Parsed* parsed) { |
| 929 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); | 931 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); |
| 930 } | 932 } |
| 931 | 933 |
| 932 } // namespace url_parse | 934 } // namespace url_parse |
| OLD | NEW |