Use app list item shadow for app list folders.
[chromium-blink-merge.git] / chrome / browser / android / url_utilities.cc
blob495a0cd9a4f5d0b8a24de0796254c690dfd49ddd
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 "components/google/core/browser/google_util.h"
8 #include "components/url_fixer/url_fixer.h"
9 #include "jni/UrlUtilities_jni.h"
10 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
11 #include "url/gurl.h"
13 using base::android::ConvertJavaStringToUTF8;
15 namespace {
17 GURL ConvertJavaStringToGURL(JNIEnv*env, jstring url) {
18 return url ? GURL(ConvertJavaStringToUTF8(env, url)) : GURL();
21 net::registry_controlled_domains::PrivateRegistryFilter GetRegistryFilter(
22 jboolean include_private) {
23 return include_private
24 ? net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES
25 : net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES;
28 } // namespace
30 static jboolean SameDomainOrHost(JNIEnv* env,
31 jclass clazz,
32 jstring url_1_str,
33 jstring url_2_str,
34 jboolean include_private) {
35 GURL url_1 = ConvertJavaStringToGURL(env, url_1_str);
36 GURL url_2 = ConvertJavaStringToGURL(env, url_2_str);
38 net::registry_controlled_domains::PrivateRegistryFilter filter =
39 GetRegistryFilter(include_private);
41 return net::registry_controlled_domains::SameDomainOrHost(url_1,
42 url_2,
43 filter);
46 static jstring GetDomainAndRegistry(JNIEnv* env,
47 jclass clazz,
48 jstring url,
49 jboolean include_private) {
50 DCHECK(url);
51 GURL gurl = ConvertJavaStringToGURL(env, url);
52 if (gurl.is_empty())
53 return nullptr;
55 net::registry_controlled_domains::PrivateRegistryFilter filter =
56 GetRegistryFilter(include_private);
58 // OK to release, JNI binding.
59 return base::android::ConvertUTF8ToJavaString(
60 env, net::registry_controlled_domains::GetDomainAndRegistry(
61 gurl, filter)).Release();
64 static jboolean IsGoogleSearchUrl(JNIEnv* env, jclass clazz, jstring url) {
65 GURL gurl = ConvertJavaStringToGURL(env, url);
66 if (gurl.is_empty())
67 return false;
68 return google_util::IsGoogleSearchUrl(gurl);
71 static jboolean IsGoogleHomePageUrl(JNIEnv* env, jclass clazz, jstring url) {
72 GURL gurl = ConvertJavaStringToGURL(env, url);
73 if (gurl.is_empty())
74 return false;
75 return google_util::IsGoogleHomePageUrl(gurl);
78 static jstring FixupUrl(JNIEnv* env,
79 jclass clazz,
80 jstring url,
81 jstring optional_desired_tld) {
82 DCHECK(url);
83 GURL fixed_url = url_fixer::FixupURL(
84 base::android::ConvertJavaStringToUTF8(env, url),
85 optional_desired_tld
86 ? base::android::ConvertJavaStringToUTF8(env, optional_desired_tld)
87 : std::string());
89 return fixed_url.is_valid() ?
90 base::android::ConvertUTF8ToJavaString(env, fixed_url.spec()).Release() :
91 nullptr;
94 // Register native methods
95 bool RegisterUrlUtilities(JNIEnv* env) {
96 return RegisterNativesImpl(env);