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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 | 790 |
791 // If we need to strip out http do it after the fact. | 791 // If we need to strip out http do it after the fact. |
792 if (omit_http && StartsWith(url_string, base::ASCIIToUTF16(kHTTP), true)) { | 792 if (omit_http && StartsWith(url_string, base::ASCIIToUTF16(kHTTP), true)) { |
793 const size_t kHTTPSize = arraysize(kHTTP) - 1; | 793 const size_t kHTTPSize = arraysize(kHTTP) - 1; |
794 url_string = url_string.substr(kHTTPSize); | 794 url_string = url_string.substr(kHTTPSize); |
795 // Because offsets in the |adjustments| are already calculated with respect | 795 // Because offsets in the |adjustments| are already calculated with respect |
796 // to the string with the http:// prefix in it, those offsets remain correct | 796 // to the string with the http:// prefix in it, those offsets remain correct |
797 // after stripping the prefix. The only thing necessary is to add an | 797 // after stripping the prefix. The only thing necessary is to add an |
798 // adjustment to reflect the stripped prefix. | 798 // adjustment to reflect the stripped prefix. |
799 adjustments->insert(adjustments->begin(), | 799 adjustments->insert(adjustments->begin(), |
800 base::OffsetAdjuster::Adjustment(0, kHTTPSize, 0)); | 800 base::OffsetAdjuster::Adjustment(0, kHTTPSize, 0)); |
801 | 801 |
802 if (prefix_end) | 802 if (prefix_end) |
803 *prefix_end -= kHTTPSize; | 803 *prefix_end -= kHTTPSize; |
804 | 804 |
805 // Adjust new_parsed. | 805 // Adjust new_parsed. |
806 DCHECK(new_parsed->scheme.is_valid()); | 806 DCHECK(new_parsed->scheme.is_valid()); |
807 int delta = -(new_parsed->scheme.len + 3); // +3 for ://. | 807 int delta = -(new_parsed->scheme.len + 3); // +3 for ://. |
808 new_parsed->scheme.reset(); | 808 new_parsed->scheme.reset(); |
809 AdjustAllComponentsButScheme(delta, new_parsed); | 809 AdjustAllComponentsButScheme(delta, new_parsed); |
810 } | 810 } |
(...skipping 11 matching lines...) Expand all Loading... |
822 Offsets offsets; | 822 Offsets offsets; |
823 if (offset_for_adjustment) | 823 if (offset_for_adjustment) |
824 offsets.push_back(*offset_for_adjustment); | 824 offsets.push_back(*offset_for_adjustment); |
825 base::string16 result = FormatUrlWithOffsets(url, languages, format_types, | 825 base::string16 result = FormatUrlWithOffsets(url, languages, format_types, |
826 unescape_rules, new_parsed, prefix_end, &offsets); | 826 unescape_rules, new_parsed, prefix_end, &offsets); |
827 if (offset_for_adjustment) | 827 if (offset_for_adjustment) |
828 *offset_for_adjustment = offsets[0]; | 828 *offset_for_adjustment = offsets[0]; |
829 return result; | 829 return result; |
830 } | 830 } |
831 | 831 |
832 base::string16 FormatOriginForDisplay(const GURL& url, | |
833 const std::string& languages, | |
834 bool omit_scheme) { | |
835 if (!url.IsStandard()) | |
836 return FormatUrl(url, languages); | |
837 | |
838 if (url.SchemeIsFile()) { | |
839 // TODO(palmer): Determine whether to encode this policy in GURL::GetOrigin. | |
840 return (omit_scheme ? base::ASCIIToUTF16("") | |
841 : base::ASCIIToUTF16("file://")) + | |
842 base::UTF8ToUTF16(url.path()); | |
843 } | |
844 | |
845 if (url.SchemeIsFileSystem()) { | |
846 // TODO(palmer): Determine whether to encode this policy in GURL::GetOrigin. | |
847 const GURL inner_url(url.spec().substr(strlen("filesystem:"))); | |
848 return base::ASCIIToUTF16("filesystem:") + | |
849 FormatOriginForDisplay(inner_url, languages, omit_scheme); | |
850 } | |
851 | |
852 const GURL origin = url.GetOrigin(); | |
853 const std::string& scheme = origin.scheme(); | |
854 const std::string& host = origin.host(); | |
855 if (scheme.empty() || host.empty()) | |
856 return FormatUrl(url, languages); | |
857 | |
858 base::string16 result; | |
859 | |
860 if (!omit_scheme) | |
861 result = base::UTF8ToUTF16(scheme) + base::ASCIIToUTF16("://"); | |
862 | |
863 result += base::UTF8ToUTF16(host); | |
864 | |
865 const int port = origin.IntPort(); | |
866 const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(), | |
867 origin.scheme().length()); | |
868 if (origin.port().length() > 0 && port != 0 && port != default_port) | |
869 result += base::ASCIIToUTF16(":") + base::UTF8ToUTF16(origin.port()); | |
870 | |
871 return result; | |
872 } | |
873 | |
874 } // namespace net | 832 } // namespace net |
OLD | NEW |