OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "components/google/core/browser/google_util.h" | 9 #include "components/google/core/browser/google_util.h" |
10 #include "jni/UrlUtilities_jni.h" | 10 #include "jni/UrlUtilities_jni.h" |
11 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 11 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 | 13 |
14 using base::android::ConvertJavaStringToUTF8; | 14 using base::android::ConvertJavaStringToUTF8; |
15 using base::android::JavaParamRef; | 15 using base::android::JavaParamRef; |
16 using base::android::ScopedJavaLocalRef; | 16 using base::android::ScopedJavaLocalRef; |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 static const char* const g_supported_schemes[] = { "about", "data", "file", | 20 static const char* const g_supported_schemes[] = { "about", "data", "file", |
21 "http", "https", "inline", "javascript", nullptr }; | 21 "http", "https", "inline", "javascript", nullptr }; |
22 | 22 |
23 static const char* const g_downloadable_schemes[] = { | 23 static const char* const g_downloadable_schemes[] = { |
24 "data", "blob", "file", "filesystem", "http", "https", nullptr }; | 24 "data", "blob", "file", "filesystem", "http", "https", nullptr }; |
25 | 25 |
26 static const char* const g_fallback_valid_schemes[] = { | 26 static const char* const g_fallback_valid_schemes[] = { |
27 "http", "https", nullptr }; | 27 "http", "https", nullptr }; |
28 | 28 |
29 // TODO(mariakhomenko): figure out how to keep this list updated. | |
battre (please use the other)
2016/11/11 22:54:10
IsCanonicalHostGoogleHostname in components/google
| |
30 static const char* const g_google_tld_list[] = {"ac", "ad", "ae", "af", "ag", | |
31 "al", "am", "as", "at", "aw", "az", "ba", "be", "bf", "bg", "bi", "biz", | |
32 "bj", "bm", "bn", "bo", "bs", "bt", "by", "bz", "ca", "cat", "cc", "cd", | |
33 "cf", "cg", "ch", "ci", "cl", "cm", "cn", "co", "co.ao", "co.at", "co.ba", | |
34 "co.bi", "co.bw", "co.ci", "co.ck", "co.cr", "co.gg", "co.gl", "co.gy", | |
35 "co.hu", "co.id", "co.il", "co.im", "co.in", "co.it", "co.je", "co.jp", | |
36 "co.ke", "co.kr", "co.ls", "co.ma", "co.mu", "co.mw", "co.mz", "co.nz", | |
37 "co.pn", "co.rs", "co.th", "co.tt", "co.tz", "co.ua", "co.ug", "co.uk", | |
38 "co.uz", "co.ve", "co.vi", "co.za", "co.zm", "co.zw", "com", "com.af", | |
39 "com.ag", "com.ai", "com.ar", "com.au", "com.az", "com.bd", "com.bh", | |
40 "com.bi", "com.bn", "com.bo", "com.br", "com.bs", "com.by", "com.bz", | |
41 "com.cn", "com.co", "com.cu", "com.cy", "com.do", "com.dz", "com.ec", | |
42 "com.eg", "com.er", "com.et", "com.fj", "com.ge", "com.gh", "com.gi", | |
43 "com.gl", "com.gp", "com.gr", "com.gt", "com.gy", "com.hk", "com.hn", | |
44 "com.hr", "com.ht", "com.iq", "com.jm", "com.jo", "com.kg", "com.kh", | |
45 "com.ki", "com.kw", "com.kz", "com.lb", "com.lc", "com.lk", "com.lv", | |
46 "com.ly", "com.mk", "com.mm", "com.mt", "com.mu", "com.mw", "com.mx", | |
47 "com.my", "com.na", "com.nc", "com.nf", "com.ng", "com.ni", "com.np", | |
48 "com.nr", "com.om", "com.pa", "com.pe", "com.pg", "com.ph", "com.pk", | |
49 "com.pl", "com.pr", "com.ps", "com.pt", "com.py", "com.qa", "com.ru", | |
50 "com.sa", "com.sb", "com.sc", "com.sg", "com.sl", "com.sv", "com.tj", | |
51 "com.tm", "com.tn", "com.tr", "com.tt", "com.tw", "com.ua", "com.uy", | |
52 "com.uz", "com.vc", "com.ve", "com.vi", "com.vn", "com.ws", "cv", "cx", | |
53 "cz", "de", "dj", "dk", "dm", "do", "dz", "ec", "ee", "es", "eu", "fi", | |
54 "fm", "fr", "ga", "gd", "ge", "gf", "gg", "gl", "gm", "gp", "gr", "gw", | |
55 "gy", "hk", "hn", "hr", "ht", "hu", "ie", "im", "in", "info", "in.rs", "io", | |
56 "iq", "is", "it", "it.ao", "je", "jo", "jobs", "jp", "kg", "ki", "kids.us", | |
57 "km", "kn", "kr", "kz", "la", "li", "lk", "lt", "lu", "lv", "ma", "md", | |
58 "me", "mg", "mh", "mk", "ml", "mn", "mobi", "mr", "ms", "mu", "mv", "mw", | |
59 "mx", "name", "ne", "ne.jp", "net", "net.in", "net.nz", "nf", "ng", "nl", | |
60 "no", "nom.es", "nr", "nu", "off.ai", "org", "org.af", "org.es", "org.in", | |
61 "org.nz", "org.uk", "pf", "ph", "pk", "pl", "pn", "pr", "pro", "ps", "pt", | |
62 "qa", "re", "ro", "rs", "ru", "rw", "sc", "se", "sg", "sh", "si", "sk", | |
63 "sl", "sm", "sn", "so", "sr", "st", "sz", "td", "tel", "tg", "tk", "tl", | |
64 "tm", "tn", "to", "tt", "tv", "tw", "ua", "ug", "us", "uz", "vc", "vg", | |
65 "vn", "vu", "ws", "yt"}; | |
66 | |
29 GURL ConvertJavaStringToGURL(JNIEnv* env, jstring url) { | 67 GURL ConvertJavaStringToGURL(JNIEnv* env, jstring url) { |
30 return url ? GURL(ConvertJavaStringToUTF8(env, url)) : GURL(); | 68 return url ? GURL(ConvertJavaStringToUTF8(env, url)) : GURL(); |
31 } | 69 } |
32 | 70 |
33 bool CheckSchemeBelongsToList( | 71 bool CheckSchemeBelongsToList( |
34 JNIEnv* env, | 72 JNIEnv* env, |
35 const JavaParamRef<jstring>& url, | 73 const JavaParamRef<jstring>& url, |
36 const char* const* scheme_list) { | 74 const char* const* scheme_list) { |
37 GURL gurl = ConvertJavaStringToGURL(env, url); | 75 GURL gurl = ConvertJavaStringToGURL(env, url); |
38 if (gurl.is_valid()) { | 76 if (gurl.is_valid()) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 env, | 134 env, |
97 net::registry_controlled_domains::GetDomainAndRegistry(gurl, filter)); | 135 net::registry_controlled_domains::GetDomainAndRegistry(gurl, filter)); |
98 } | 136 } |
99 | 137 |
100 static jboolean IsGoogleSearchUrl(JNIEnv* env, | 138 static jboolean IsGoogleSearchUrl(JNIEnv* env, |
101 const JavaParamRef<jclass>& clazz, | 139 const JavaParamRef<jclass>& clazz, |
102 const JavaParamRef<jstring>& url) { | 140 const JavaParamRef<jstring>& url) { |
103 GURL gurl = ConvertJavaStringToGURL(env, url); | 141 GURL gurl = ConvertJavaStringToGURL(env, url); |
104 if (gurl.is_empty()) | 142 if (gurl.is_empty()) |
105 return false; | 143 return false; |
106 return google_util::IsGoogleSearchUrl(gurl); | 144 bool is_search = google_util::IsGoogleSearchUrl(gurl); |
battre (please use the other)
2016/11/11 22:54:10
Wouldn't it make sense to move the logic into this
| |
145 if (!is_search) | |
146 return is_search; | |
147 | |
148 size_t length = net::registry_controlled_domains::GetRegistryLength( | |
149 gurl, | |
150 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | |
151 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | |
152 if ((length == 0) || (length == std::string::npos)) | |
153 return false; | |
154 | |
155 std::string tld(gurl.host().substr(gurl.host().length() - length, | |
156 std::string::npos)); | |
157 // TODO(mariakhomenko): binary search instead? | |
158 for (size_t i = 0; g_google_tld_list[i]; i++) { | |
159 if (g_google_tld_list[i] == tld) { | |
160 return true; | |
161 } | |
162 } | |
163 return false; | |
107 } | 164 } |
108 | 165 |
109 static jboolean IsGoogleHomePageUrl(JNIEnv* env, | 166 static jboolean IsGoogleHomePageUrl(JNIEnv* env, |
110 const JavaParamRef<jclass>& clazz, | 167 const JavaParamRef<jclass>& clazz, |
111 const JavaParamRef<jstring>& url) { | 168 const JavaParamRef<jstring>& url) { |
112 GURL gurl = ConvertJavaStringToGURL(env, url); | 169 GURL gurl = ConvertJavaStringToGURL(env, url); |
113 if (gurl.is_empty()) | 170 if (gurl.is_empty()) |
114 return false; | 171 return false; |
115 return google_util::IsGoogleHomePageUrl(gurl); | 172 return google_util::IsGoogleHomePageUrl(gurl); |
116 } | 173 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 const JavaParamRef<jclass>& clazz, | 219 const JavaParamRef<jclass>& clazz, |
163 const JavaParamRef<jstring>& url) { | 220 const JavaParamRef<jstring>& url) { |
164 return CheckSchemeBelongsToList(env, url, g_downloadable_schemes); | 221 return CheckSchemeBelongsToList(env, url, g_downloadable_schemes); |
165 } | 222 } |
166 | 223 |
167 | 224 |
168 // Register native methods | 225 // Register native methods |
169 bool RegisterUrlUtilities(JNIEnv* env) { | 226 bool RegisterUrlUtilities(JNIEnv* env) { |
170 return RegisterNativesImpl(env); | 227 return RegisterNativesImpl(env); |
171 } | 228 } |
OLD | NEW |