Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/url_formatter/url_formatter.h" | 5 #include "components/url_formatter/url_formatter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_offset_string_conversions.h" | 15 #include "base/strings/utf_offset_string_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/threading/thread_local_storage.h" | 17 #include "base/threading/thread_local_storage.h" |
| 18 #include "third_party/icu/source/common/unicode/schriter.h" | 18 #include "third_party/icu/source/common/unicode/schriter.h" |
| 19 #include "third_party/icu/source/common/unicode/uidna.h" | 19 #include "third_party/icu/source/common/unicode/uidna.h" |
| 20 #include "third_party/icu/source/common/unicode/uniset.h" | 20 #include "third_party/icu/source/common/unicode/uniset.h" |
| 21 #include "third_party/icu/source/common/unicode/uscript.h" | 21 #include "third_party/icu/source/common/unicode/uscript.h" |
| 22 #include "third_party/icu/source/common/unicode/uvernum.h" | 22 #include "third_party/icu/source/common/unicode/uvernum.h" |
| 23 #include "third_party/icu/source/i18n/unicode/regex.h" | 23 #include "third_party/icu/source/i18n/unicode/regex.h" |
| 24 #include "third_party/icu/source/i18n/unicode/uspoof.h" | 24 #include "third_party/icu/source/i18n/unicode/uspoof.h" |
| 25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 26 #include "url/third_party/mozilla/url_parse.h" | 26 #include "url/third_party/mozilla/url_parse.h" |
| 27 | 27 |
| 28 #if defined(OS_ANDROID) | |
| 29 #include "base/android/build_info.h" | |
| 30 #include "base/i18n/rtl.h" | |
| 31 #endif | |
| 32 | |
| 28 namespace url_formatter { | 33 namespace url_formatter { |
| 29 | 34 |
| 30 namespace { | 35 namespace { |
| 31 | 36 |
| 32 base::string16 IDNToUnicodeWithAdjustments( | 37 base::string16 IDNToUnicodeWithAdjustments( |
| 33 base::StringPiece host, | 38 base::StringPiece host, |
| 34 base::OffsetAdjuster::Adjustments* adjustments); | 39 base::OffsetAdjuster::Adjustments* adjustments); |
| 35 bool IDNToUnicodeOneComponent(const base::char16* comp, | 40 bool IDNToUnicodeOneComponent(const base::char16* comp, |
| 36 size_t comp_len, | 41 size_t comp_len, |
| 37 bool is_tld_ascii, | 42 bool is_tld_ascii, |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 if (prefix_end) | 823 if (prefix_end) |
| 819 *prefix_end -= kHTTPSize; | 824 *prefix_end -= kHTTPSize; |
| 820 | 825 |
| 821 // Adjust new_parsed. | 826 // Adjust new_parsed. |
| 822 DCHECK(new_parsed->scheme.is_valid()); | 827 DCHECK(new_parsed->scheme.is_valid()); |
| 823 int delta = -(new_parsed->scheme.len + 3); // +3 for ://. | 828 int delta = -(new_parsed->scheme.len + 3); // +3 for ://. |
| 824 new_parsed->scheme.reset(); | 829 new_parsed->scheme.reset(); |
| 825 AdjustAllComponentsButScheme(delta, new_parsed); | 830 AdjustAllComponentsButScheme(delta, new_parsed); |
| 826 } | 831 } |
| 827 | 832 |
| 833 #if defined(OS_ANDROID) | |
| 834 // Android versions 4.2 and before have broken RTL support. | |
| 835 if (base::android::BuildInfo::GetInstance()->sdk_int() <= | |
| 836 base::android::SDK_VERSION_JELLY_BEAN_MR1) { | |
| 837 url_string = base::i18n::GetDisplayStringInLTRDirectionality(url_string); | |
|
tommycli
2017/04/25 00:06:21
Hey, I'm not sure this is the correct thing to do.
Matt Giuca
2017/04/26 00:01:05
It's probably the case that they are all three byt
Matt Giuca
2017/04/26 05:57:09
After we had a chat:
It looks like this *is* the
tommycli
2017/04/27 01:36:33
You're right, this does mess up the copy and paste
| |
| 838 } | |
| 839 #endif | |
| 840 | |
| 828 return url_string; | 841 return url_string; |
| 829 } | 842 } |
| 830 | 843 |
| 831 bool CanStripTrailingSlash(const GURL& url) { | 844 bool CanStripTrailingSlash(const GURL& url) { |
| 832 // Omit the path only for standard, non-file URLs with nothing but "/" after | 845 // Omit the path only for standard, non-file URLs with nothing but "/" after |
| 833 // the hostname. | 846 // the hostname. |
| 834 return url.IsStandard() && !url.SchemeIsFile() && !url.SchemeIsFileSystem() && | 847 return url.IsStandard() && !url.SchemeIsFile() && !url.SchemeIsFileSystem() && |
| 835 !url.has_query() && !url.has_ref() && url.path_piece() == "/"; | 848 !url.has_query() && !url.has_ref() && url.path_piece() == "/"; |
| 836 } | 849 } |
| 837 | 850 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 850 return base::StartsWith(text, www, base::CompareCase::SENSITIVE) | 863 return base::StartsWith(text, www, base::CompareCase::SENSITIVE) |
| 851 ? text.substr(www.length()) : text; | 864 ? text.substr(www.length()) : text; |
| 852 } | 865 } |
| 853 | 866 |
| 854 base::string16 StripWWWFromHost(const GURL& url) { | 867 base::string16 StripWWWFromHost(const GURL& url) { |
| 855 DCHECK(url.is_valid()); | 868 DCHECK(url.is_valid()); |
| 856 return StripWWW(base::ASCIIToUTF16(url.host_piece())); | 869 return StripWWW(base::ASCIIToUTF16(url.host_piece())); |
| 857 } | 870 } |
| 858 | 871 |
| 859 } // namespace url_formatter | 872 } // namespace url_formatter |
| OLD | NEW |