Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / android / url_utilities.cc
blob51a67db01ce82397479f131b51b85273141a7e05
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"
11 #include "url/gurl.h"
13 using base::android::ConvertJavaStringToUTF8;
15 namespace {
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,
27 jclass clazz,
28 jstring url_1_str,
29 jstring url_2_str,
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,
38 url_2,
39 filter);
42 static jstring GetDomainAndRegistry(JNIEnv* env,
43 jclass clazz,
44 jstring url,
45 jboolean include_private) {
46 GURL gurl = GURL(ConvertJavaStringToUTF8(env, url));
47 if (gurl.is_empty())
48 return NULL;
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));
61 if (gurl.is_empty())
62 return false;
63 return google_util::IsGoogleSearchUrl(gurl);
66 static jboolean IsGoogleHomePageUrl(JNIEnv* env, jclass clazz, jstring url) {
67 GURL gurl = GURL(ConvertJavaStringToUTF8(env, url));
68 if (gurl.is_empty())
69 return false;
70 return google_util::IsGoogleHomePageUrl(gurl);
73 static jstring FixupUrl(JNIEnv* env,
74 jclass clazz,
75 jstring url,
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() :
84 NULL;
87 // Register native methods
88 bool RegisterUrlUtilities(JNIEnv* env) {
89 return RegisterNativesImpl(env);