| 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 "base/android/jni_android.h" | 5 #include "base/android/jni_android.h" |
| 6 #include "base/android/jni_string.h" | 6 #include "base/android/jni_string.h" |
| 7 #include "components/google/core/browser/google_util.h" | 7 #include "components/google/core/browser/google_util.h" |
| 8 #include "components/url_formatter/url_fixer.h" | 8 #include "components/url_formatter/url_fixer.h" |
| 9 #include "jni/UrlUtilities_jni.h" | 9 #include "jni/UrlUtilities_jni.h" |
| 10 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 10 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 GURL url_2 = ConvertJavaStringToGURL(env, url_2_str); | 36 GURL url_2 = ConvertJavaStringToGURL(env, url_2_str); |
| 37 | 37 |
| 38 net::registry_controlled_domains::PrivateRegistryFilter filter = | 38 net::registry_controlled_domains::PrivateRegistryFilter filter = |
| 39 GetRegistryFilter(include_private); | 39 GetRegistryFilter(include_private); |
| 40 | 40 |
| 41 return net::registry_controlled_domains::SameDomainOrHost(url_1, | 41 return net::registry_controlled_domains::SameDomainOrHost(url_1, |
| 42 url_2, | 42 url_2, |
| 43 filter); | 43 filter); |
| 44 } | 44 } |
| 45 | 45 |
| 46 static ScopedJavaLocalRef<jstring> GetDomainAndRegistry( | 46 static jstring GetDomainAndRegistry(JNIEnv* env, |
| 47 JNIEnv* env, | 47 jclass clazz, |
| 48 jclass clazz, | 48 jstring url, |
| 49 jstring url, | 49 jboolean include_private) { |
| 50 jboolean include_private) { | |
| 51 DCHECK(url); | 50 DCHECK(url); |
| 52 GURL gurl = ConvertJavaStringToGURL(env, url); | 51 GURL gurl = ConvertJavaStringToGURL(env, url); |
| 53 if (gurl.is_empty()) | 52 if (gurl.is_empty()) |
| 54 return ScopedJavaLocalRef<jstring>(); | 53 return nullptr; |
| 55 | 54 |
| 56 net::registry_controlled_domains::PrivateRegistryFilter filter = | 55 net::registry_controlled_domains::PrivateRegistryFilter filter = |
| 57 GetRegistryFilter(include_private); | 56 GetRegistryFilter(include_private); |
| 58 | 57 |
| 58 // OK to release, JNI binding. |
| 59 return base::android::ConvertUTF8ToJavaString( | 59 return base::android::ConvertUTF8ToJavaString( |
| 60 env, | 60 env, net::registry_controlled_domains::GetDomainAndRegistry( |
| 61 net::registry_controlled_domains::GetDomainAndRegistry(gurl, filter)); | 61 gurl, filter)).Release(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 static jboolean IsGoogleSearchUrl(JNIEnv* env, jclass clazz, jstring url) { | 64 static jboolean IsGoogleSearchUrl(JNIEnv* env, jclass clazz, jstring url) { |
| 65 GURL gurl = ConvertJavaStringToGURL(env, url); | 65 GURL gurl = ConvertJavaStringToGURL(env, url); |
| 66 if (gurl.is_empty()) | 66 if (gurl.is_empty()) |
| 67 return false; | 67 return false; |
| 68 return google_util::IsGoogleSearchUrl(gurl); | 68 return google_util::IsGoogleSearchUrl(gurl); |
| 69 } | 69 } |
| 70 | 70 |
| 71 static jboolean IsGoogleHomePageUrl(JNIEnv* env, jclass clazz, jstring url) { | 71 static jboolean IsGoogleHomePageUrl(JNIEnv* env, jclass clazz, jstring url) { |
| 72 GURL gurl = ConvertJavaStringToGURL(env, url); | 72 GURL gurl = ConvertJavaStringToGURL(env, url); |
| 73 if (gurl.is_empty()) | 73 if (gurl.is_empty()) |
| 74 return false; | 74 return false; |
| 75 return google_util::IsGoogleHomePageUrl(gurl); | 75 return google_util::IsGoogleHomePageUrl(gurl); |
| 76 } | 76 } |
| 77 | 77 |
| 78 static ScopedJavaLocalRef<jstring> FixupUrl(JNIEnv* env, | 78 static jstring FixupUrl(JNIEnv* env, |
| 79 jclass clazz, | 79 jclass clazz, |
| 80 jstring url, | 80 jstring url, |
| 81 jstring optional_desired_tld) { | 81 jstring optional_desired_tld) { |
| 82 DCHECK(url); | 82 DCHECK(url); |
| 83 GURL fixed_url = url_formatter::FixupURL( | 83 GURL fixed_url = url_formatter::FixupURL( |
| 84 base::android::ConvertJavaStringToUTF8(env, url), | 84 base::android::ConvertJavaStringToUTF8(env, url), |
| 85 optional_desired_tld | 85 optional_desired_tld |
| 86 ? base::android::ConvertJavaStringToUTF8(env, optional_desired_tld) | 86 ? base::android::ConvertJavaStringToUTF8(env, optional_desired_tld) |
| 87 : std::string()); | 87 : std::string()); |
| 88 | 88 |
| 89 return fixed_url.is_valid() | 89 return fixed_url.is_valid() ? |
| 90 ? base::android::ConvertUTF8ToJavaString(env, fixed_url.spec()) | 90 base::android::ConvertUTF8ToJavaString(env, fixed_url.spec()).Release() : |
| 91 : ScopedJavaLocalRef<jstring>(); | 91 nullptr; |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Register native methods | 94 // Register native methods |
| 95 bool RegisterUrlUtilities(JNIEnv* env) { | 95 bool RegisterUrlUtilities(JNIEnv* env) { |
| 96 return RegisterNativesImpl(env); | 96 return RegisterNativesImpl(env); |
| 97 } | 97 } |
| OLD | NEW |