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
3 // found in the LICENSE file.
5 #include "base/android/jni_android.h"
6 #include "base/android/jni_string.h"
7 #include "chrome/browser/google/google_util.h"
8 #include "chrome/common/net/url_fixer_upper.h"
9 #include "jni/UrlUtilities_jni.h"
10 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
13 using base::android::ConvertJavaStringToUTF8
;
17 net::registry_controlled_domains::PrivateRegistryFilter
GetRegistryFilter(
18 jboolean include_private
) {
19 return include_private
20 ? net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES
21 : net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES
;
26 static jboolean
SameDomainOrHost(JNIEnv
* env
,
30 jboolean include_private
) {
31 GURL
url_1(ConvertJavaStringToUTF8(env
, url_1_str
));
32 GURL
url_2(ConvertJavaStringToUTF8(env
, url_2_str
));
34 net::registry_controlled_domains::PrivateRegistryFilter filter
=
35 GetRegistryFilter(include_private
);
37 return net::registry_controlled_domains::SameDomainOrHost(url_1
,
42 static jstring
GetDomainAndRegistry(JNIEnv
* env
,
45 jboolean include_private
) {
46 GURL gurl
= GURL(ConvertJavaStringToUTF8(env
, url
));
50 net::registry_controlled_domains::PrivateRegistryFilter filter
=
51 GetRegistryFilter(include_private
);
53 // OK to release, JNI binding.
54 return base::android::ConvertUTF8ToJavaString(
55 env
, net::registry_controlled_domains::GetDomainAndRegistry(
56 gurl
, filter
)).Release();
59 static jboolean
IsGoogleSearchUrl(JNIEnv
* env
, jclass clazz
, jstring url
) {
60 GURL gurl
= GURL(ConvertJavaStringToUTF8(env
, url
));
63 return google_util::IsGoogleSearchUrl(gurl
);
66 static jboolean
IsGoogleHomePageUrl(JNIEnv
* env
, jclass clazz
, jstring url
) {
67 GURL gurl
= GURL(ConvertJavaStringToUTF8(env
, url
));
70 return google_util::IsGoogleHomePageUrl(gurl
);
73 static jstring
FixupUrl(JNIEnv
* env
,
76 jstring desired_tld
) {
77 GURL fixed_url
= URLFixerUpper::FixupURL(
78 base::android::ConvertJavaStringToUTF8(env
, url
),
79 base::android::ConvertJavaStringToUTF8(env
, desired_tld
));
82 return fixed_url
.is_valid() ?
83 base::android::ConvertUTF8ToJavaString(env
, fixed_url
.spec()).Release() :
87 // Register native methods
88 bool RegisterUrlUtilities(JNIEnv
* env
) {
89 return RegisterNativesImpl(env
);