This source file includes following definitions.
- GetRegistryFilter
- SameDomainOrHost
- GetDomainAndRegistry
- IsGoogleSearchUrl
- IsGoogleHomePageUrl
- FixupUrl
- RegisterUrlUtilities
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/common/net/url_fixer_upper.h"
#include "jni/UrlUtilities_jni.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "url/gurl.h"
using base::android::ConvertJavaStringToUTF8;
namespace {
net::registry_controlled_domains::PrivateRegistryFilter GetRegistryFilter(
jboolean include_private) {
return include_private
? net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES
: net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES;
}
}
static jboolean SameDomainOrHost(JNIEnv* env,
jclass clazz,
jstring url_1_str,
jstring url_2_str,
jboolean include_private) {
GURL url_1(ConvertJavaStringToUTF8(env, url_1_str));
GURL url_2(ConvertJavaStringToUTF8(env, url_2_str));
net::registry_controlled_domains::PrivateRegistryFilter filter =
GetRegistryFilter(include_private);
return net::registry_controlled_domains::SameDomainOrHost(url_1,
url_2,
filter);
}
static jstring GetDomainAndRegistry(JNIEnv* env,
jclass clazz,
jstring url,
jboolean include_private) {
GURL gurl = GURL(ConvertJavaStringToUTF8(env, url));
if (gurl.is_empty())
return NULL;
net::registry_controlled_domains::PrivateRegistryFilter filter =
GetRegistryFilter(include_private);
return base::android::ConvertUTF8ToJavaString(
env, net::registry_controlled_domains::GetDomainAndRegistry(
gurl, filter)).Release();
}
static jboolean IsGoogleSearchUrl(JNIEnv* env, jclass clazz, jstring url) {
GURL gurl = GURL(ConvertJavaStringToUTF8(env, url));
if (gurl.is_empty())
return false;
return google_util::IsGoogleSearchUrl(gurl);
}
static jboolean IsGoogleHomePageUrl(JNIEnv* env, jclass clazz, jstring url) {
GURL gurl = GURL(ConvertJavaStringToUTF8(env, url));
if (gurl.is_empty())
return false;
return google_util::IsGoogleHomePageUrl(gurl);
}
static jstring FixupUrl(JNIEnv* env,
jclass clazz,
jstring url,
jstring desired_tld) {
GURL fixed_url = URLFixerUpper::FixupURL(
base::android::ConvertJavaStringToUTF8(env, url),
base::android::ConvertJavaStringToUTF8(env, desired_tld));
return fixed_url.is_valid() ?
base::android::ConvertUTF8ToJavaString(env, fixed_url.spec()).Release() :
NULL;
}
bool RegisterUrlUtilities(JNIEnv* env) {
return RegisterNativesImpl(env);
}