| 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 ++inner_path_end; | 448 ++inner_path_end; |
| 449 parsed->path.begin = inner_path_end; | 449 parsed->path.begin = inner_path_end; |
| 450 int new_inner_path_length = inner_path_end - inner_parsed.path.begin; | 450 int new_inner_path_length = inner_path_end - inner_parsed.path.begin; |
| 451 parsed->path.len = inner_parsed.path.len - new_inner_path_length; | 451 parsed->path.len = inner_parsed.path.len - new_inner_path_length; |
| 452 parsed->inner_parsed()->path.len = new_inner_path_length; | 452 parsed->inner_parsed()->path.len = new_inner_path_length; |
| 453 } | 453 } |
| 454 | 454 |
| 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 bool trim_tail) { |
| 459 // Get the non-path and non-scheme parts of the URL out of the way, we never | 460 // Get the non-path and non-scheme parts of the URL out of the way, we never |
| 460 // use them. | 461 // use them. |
| 461 parsed->username.reset(); | 462 parsed->username.reset(); |
| 462 parsed->password.reset(); | 463 parsed->password.reset(); |
| 463 parsed->host.reset(); | 464 parsed->host.reset(); |
| 464 parsed->port.reset(); | 465 parsed->port.reset(); |
| 466 parsed->path.reset(); |
| 465 parsed->query.reset(); | 467 parsed->query.reset(); |
| 466 parsed->ref.reset(); | 468 parsed->ref.reset(); |
| 467 | 469 |
| 468 // Strip leading & trailing spaces and control characters. | 470 // Strip leading & trailing spaces and control characters. |
| 469 int begin = 0; | 471 int begin = 0; |
| 470 TrimURL(spec, &begin, &spec_len); | 472 int dummy_spec_len = spec_len; |
| 473 TrimURL(spec, &begin, trim_tail ? &spec_len : &dummy_spec_len); |
| 471 | 474 |
| 472 // Handle empty specs or ones that contain only whitespace or control chars. | 475 // Handle empty specs or ones that contain only whitespace or control chars. |
| 473 if (begin == spec_len) { | 476 if (begin == spec_len) { |
| 474 parsed->scheme.reset(); | 477 parsed->scheme.reset(); |
| 475 parsed->path.reset(); | 478 parsed->path.reset(); |
| 476 return; | 479 return; |
| 477 } | 480 } |
| 478 | 481 |
| 479 // Extract the scheme, with the path being everything following. We also | 482 // Extract the scheme, with the path being everything following. We also |
| 480 // handle the case where there is no scheme. | 483 // handle the case where there is no scheme. |
| 481 if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) { | 484 if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) { |
| 482 // Offset the results since we gave ExtractScheme a substring. | 485 // Offset the results since we gave ExtractScheme a substring. |
| 483 parsed->scheme.begin += begin; | 486 parsed->scheme.begin += begin; |
| 487 begin = parsed->scheme.end() + 1; |
| 488 } else { |
| 489 parsed->scheme.reset(); |
| 490 } |
| 484 | 491 |
| 485 // For compatability with the standard URL parser, we treat no path as | 492 if (begin == spec_len) |
| 486 // -1, rather than having a length of 0 (we normally wouldn't care so | 493 return; |
| 487 // much for these non-standard URLs). | 494 DCHECK_LT(begin, spec_len); |
| 488 if (parsed->scheme.end() == spec_len - 1) | 495 |
| 489 parsed->path.reset(); | 496 ParsePath(spec, |
| 490 else | 497 MakeRange(begin, spec_len), |
| 491 parsed->path = MakeRange(parsed->scheme.end() + 1, spec_len); | 498 &parsed->path, |
| 492 } else { | 499 &parsed->query, |
| 493 // No scheme found, just path. | 500 &parsed->ref); |
| 494 parsed->scheme.reset(); | |
| 495 parsed->path = MakeRange(begin, spec_len); | |
| 496 } | |
| 497 } | 501 } |
| 498 | 502 |
| 499 template<typename CHAR> | 503 template<typename CHAR> |
| 500 void DoParseMailtoURL(const CHAR* spec, int spec_len, Parsed* parsed) { | 504 void DoParseMailtoURL(const CHAR* spec, int spec_len, Parsed* parsed) { |
| 501 DCHECK(spec_len >= 0); | 505 DCHECK(spec_len >= 0); |
| 502 | 506 |
| 503 // Get the non-path and non-scheme parts of the URL out of the way, we never | 507 // Get the non-path and non-scheme parts of the URL out of the way, we never |
| 504 // use them. | 508 // use them. |
| 505 parsed->username.reset(); | 509 parsed->username.reset(); |
| 506 parsed->password.reset(); | 510 parsed->password.reset(); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 return ref.begin; // Back over delimiter. | 789 return ref.begin; // Back over delimiter. |
| 786 | 790 |
| 787 // When there is a ref and we get here, the component we wanted was before | 791 // When there is a ref and we get here, the component we wanted was before |
| 788 // this and not found, so we always know the beginning of the ref is right. | 792 // this and not found, so we always know the beginning of the ref is right. |
| 789 return ref.begin - 1; // Don't want delimiter counted. | 793 return ref.begin - 1; // Don't want delimiter counted. |
| 790 } | 794 } |
| 791 | 795 |
| 792 return cur; | 796 return cur; |
| 793 } | 797 } |
| 794 | 798 |
| 799 Component Parsed::Content() const { |
| 800 const int begin = CountCharactersBefore(USERNAME, false); |
| 801 const int len = Length() - begin; |
| 802 // For compatability with the standard URL parser, we treat no content as |
| 803 // -1, rather than having a length of 0 (we normally wouldn't care so |
| 804 // much for these non-standard URLs). |
| 805 return len ? Component(begin, len) : Component(); |
| 806 } |
| 807 |
| 795 bool ExtractScheme(const char* url, int url_len, Component* scheme) { | 808 bool ExtractScheme(const char* url, int url_len, Component* scheme) { |
| 796 return DoExtractScheme(url, url_len, scheme); | 809 return DoExtractScheme(url, url_len, scheme); |
| 797 } | 810 } |
| 798 | 811 |
| 799 bool ExtractScheme(const base::char16* url, int url_len, Component* scheme) { | 812 bool ExtractScheme(const base::char16* url, int url_len, Component* scheme) { |
| 800 return DoExtractScheme(url, url_len, scheme); | 813 return DoExtractScheme(url, url_len, scheme); |
| 801 } | 814 } |
| 802 | 815 |
| 803 // This handles everything that may be an authority terminator, including | 816 // This handles everything that may be an authority terminator, including |
| 804 // backslash. For special backslash handling see DoParseAfterScheme. | 817 // backslash. For special backslash handling see DoParseAfterScheme. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 } | 872 } |
| 860 | 873 |
| 861 void ParseStandardURL(const char* url, int url_len, Parsed* parsed) { | 874 void ParseStandardURL(const char* url, int url_len, Parsed* parsed) { |
| 862 DoParseStandardURL(url, url_len, parsed); | 875 DoParseStandardURL(url, url_len, parsed); |
| 863 } | 876 } |
| 864 | 877 |
| 865 void ParseStandardURL(const base::char16* url, int url_len, Parsed* parsed) { | 878 void ParseStandardURL(const base::char16* url, int url_len, Parsed* parsed) { |
| 866 DoParseStandardURL(url, url_len, parsed); | 879 DoParseStandardURL(url, url_len, parsed); |
| 867 } | 880 } |
| 868 | 881 |
| 869 void ParsePathURL(const char* url, int url_len, Parsed* parsed) { | 882 void ParsePathURL(const char* url, int url_len, Parsed* parsed, |
| 870 DoParsePathURL(url, url_len, parsed); | 883 bool trim_tail) { |
| 884 DoParsePathURL(url, url_len, parsed, trim_tail); |
| 871 } | 885 } |
| 872 | 886 |
| 873 void ParsePathURL(const base::char16* url, int url_len, Parsed* parsed) { | 887 void ParsePathURL(const base::char16* url, int url_len, Parsed* parsed, |
| 874 DoParsePathURL(url, url_len, parsed); | 888 bool trim_tail) { |
| 889 DoParsePathURL(url, url_len, parsed, trim_tail); |
| 875 } | 890 } |
| 876 | 891 |
| 877 void ParseFileSystemURL(const char* url, int url_len, Parsed* parsed) { | 892 void ParseFileSystemURL(const char* url, int url_len, Parsed* parsed) { |
| 878 DoParseFileSystemURL(url, url_len, parsed); | 893 DoParseFileSystemURL(url, url_len, parsed); |
| 879 } | 894 } |
| 880 | 895 |
| 881 void ParseFileSystemURL(const base::char16* url, int url_len, Parsed* parsed) { | 896 void ParseFileSystemURL(const base::char16* url, int url_len, Parsed* parsed) { |
| 882 DoParseFileSystemURL(url, url_len, parsed); | 897 DoParseFileSystemURL(url, url_len, parsed); |
| 883 } | 898 } |
| 884 | 899 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 914 } | 929 } |
| 915 | 930 |
| 916 void ParseAfterScheme(const base::char16* spec, | 931 void ParseAfterScheme(const base::char16* spec, |
| 917 int spec_len, | 932 int spec_len, |
| 918 int after_scheme, | 933 int after_scheme, |
| 919 Parsed* parsed) { | 934 Parsed* parsed) { |
| 920 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); | 935 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); |
| 921 } | 936 } |
| 922 | 937 |
| 923 } // namespace url_parse | 938 } // namespace url_parse |
| OLD | NEW |