Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 } | 569 } |
| 570 | 570 |
| 571 } // namespace | 571 } // namespace |
| 572 | 572 |
| 573 const FormatUrlType kFormatUrlOmitNothing = 0; | 573 const FormatUrlType kFormatUrlOmitNothing = 0; |
| 574 const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0; | 574 const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0; |
| 575 const FormatUrlType kFormatUrlOmitHTTP = 1 << 1; | 575 const FormatUrlType kFormatUrlOmitHTTP = 1 << 1; |
| 576 const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2; | 576 const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2; |
| 577 const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword | | 577 const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword | |
| 578 kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname; | 578 kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname; |
| 579 const FormatUrlType kFormatUrlOmitDefaultPort = 1 << 3; | |
| 579 | 580 |
| 580 base::string16 IDNToUnicode(const std::string& host, | 581 base::string16 IDNToUnicode(const std::string& host, |
| 581 const std::string& languages) { | 582 const std::string& languages) { |
| 582 return IDNToUnicodeWithAdjustments(host, languages, NULL); | 583 return IDNToUnicodeWithAdjustments(host, languages, NULL); |
| 583 } | 584 } |
| 584 | 585 |
| 585 std::string GetDirectoryListingEntry(const base::string16& name, | 586 std::string GetDirectoryListingEntry(const base::string16& name, |
| 586 const std::string& raw_bytes, | 587 const std::string& raw_bytes, |
| 587 bool is_dir, | 588 bool is_dir, |
| 588 int64 size, | 589 int64 size, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 if (parsed.username.is_valid() || parsed.password.is_valid()) | 743 if (parsed.username.is_valid() || parsed.password.is_valid()) |
| 743 url_string.push_back('@'); | 744 url_string.push_back('@'); |
| 744 } | 745 } |
| 745 if (prefix_end) | 746 if (prefix_end) |
| 746 *prefix_end = static_cast<size_t>(url_string.length()); | 747 *prefix_end = static_cast<size_t>(url_string.length()); |
| 747 | 748 |
| 748 // Host. | 749 // Host. |
| 749 AppendFormattedComponent(spec, parsed.host, HostComponentTransform(languages), | 750 AppendFormattedComponent(spec, parsed.host, HostComponentTransform(languages), |
| 750 &url_string, &new_parsed->host, adjustments); | 751 &url_string, &new_parsed->host, adjustments); |
| 751 | 752 |
| 752 // Port. | 753 // Port. Can omit port if it matches the default port for the scheme. |
| 753 if (parsed.port.is_nonempty()) { | 754 bool port_needs_reset = !parsed.port.is_nonempty(); |
| 755 if (!port_needs_reset && format_types & kFormatUrlOmitDefaultPort) { | |
|
Ryan Sleevi
2014/08/25 04:16:37
Put this bitmask in ()
(format_type & kFormatUrlO
| |
| 756 int port = url::ParsePort(spec.data(), parsed.port); | |
| 757 // Intentionally keep the port if there is a parsing error. | |
| 758 port_needs_reset = | |
| 759 (port == url::PORT_UNSPECIFIED) || | |
| 760 (port == url::DefaultPortForScheme(spec.data() + parsed.scheme.begin, | |
| 761 parsed.scheme.len)); | |
| 762 if (port_needs_reset) { | |
| 763 adjustments->push_back(base::OffsetAdjuster::Adjustment( | |
| 764 parsed.port.begin, parsed.port.len, 0)); | |
| 765 } | |
| 766 } | |
| 767 | |
| 768 if (!port_needs_reset) { | |
| 754 url_string.push_back(':'); | 769 url_string.push_back(':'); |
| 755 new_parsed->port.begin = url_string.length(); | 770 new_parsed->port.begin = url_string.length(); |
| 756 url_string.insert(url_string.end(), | 771 url_string.insert(url_string.end(), |
| 757 spec.begin() + parsed.port.begin, | 772 spec.begin() + parsed.port.begin, |
| 758 spec.begin() + parsed.port.end()); | 773 spec.begin() + parsed.port.end()); |
| 759 new_parsed->port.len = url_string.length() - new_parsed->port.begin; | 774 new_parsed->port.len = url_string.length() - new_parsed->port.begin; |
| 760 } else { | 775 } else { |
| 761 new_parsed->port.reset(); | 776 new_parsed->port.reset(); |
| 762 } | 777 } |
| 763 | 778 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 if (offset_for_adjustment) | 836 if (offset_for_adjustment) |
| 822 offsets.push_back(*offset_for_adjustment); | 837 offsets.push_back(*offset_for_adjustment); |
| 823 base::string16 result = FormatUrlWithOffsets(url, languages, format_types, | 838 base::string16 result = FormatUrlWithOffsets(url, languages, format_types, |
| 824 unescape_rules, new_parsed, prefix_end, &offsets); | 839 unescape_rules, new_parsed, prefix_end, &offsets); |
| 825 if (offset_for_adjustment) | 840 if (offset_for_adjustment) |
| 826 *offset_for_adjustment = offsets[0]; | 841 *offset_for_adjustment = offsets[0]; |
| 827 return result; | 842 return result; |
| 828 } | 843 } |
| 829 | 844 |
| 830 } // namespace net | 845 } // namespace net |
| OLD | NEW |