Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / dom_distiller / core / url_utils_android.cc
blobd700ff64a3e46a1e14c84de3632db7c004205669
1 // Copyright 2014 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 "components/dom_distiller/core/url_utils_android.h"
7 #include <string>
9 #include "base/android/jni_string.h"
10 #include "components/dom_distiller/core/url_constants.h"
11 #include "components/dom_distiller/core/url_utils.h"
12 #include "jni/DomDistillerUrlUtils_jni.h"
13 #include "net/base/url_util.h"
14 #include "url/gurl.h"
16 namespace dom_distiller {
18 namespace url_utils {
20 namespace android {
22 jstring GetDistillerViewUrlFromUrl(JNIEnv* env,
23 jclass clazz,
24 jstring j_scheme,
25 jstring j_url) {
26 std::string scheme(base::android::ConvertJavaStringToUTF8(env, j_scheme));
27 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
28 if (!url.is_valid()) {
29 return NULL;
31 GURL view_url =
32 dom_distiller::url_utils::GetDistillerViewUrlFromUrl(scheme, url);
33 if (!view_url.is_valid()) {
34 return NULL;
36 return base::android::ConvertUTF8ToJavaString(env, view_url.spec()).Release();
39 jstring GetOriginalUrlFromDistillerUrl(JNIEnv* env,
40 jclass clazz,
41 jstring j_url) {
42 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
43 if (!url.is_valid())
44 return NULL;
46 std::string original_url_str;
47 net::GetValueForKeyInQuery(url, kUrlKey, &original_url_str);
48 GURL original_url(original_url_str);
49 if (!original_url.is_valid())
50 return NULL;
52 return base::android::ConvertUTF8ToJavaString(env, original_url.spec())
53 .Release();
56 jboolean IsDistilledPage(JNIEnv* env, jclass clazz, jstring j_url) {
57 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
58 return dom_distiller::url_utils::IsDistilledPage(url);
61 jboolean IsUrlDistillable(JNIEnv* env, jclass clazz, jstring j_url) {
62 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
63 return dom_distiller::url_utils::IsUrlDistillable(url);
66 jstring GetIsDistillableJs(JNIEnv* env, jclass clazz) {
67 return base::android::ConvertUTF8ToJavaString(
68 env, dom_distiller::url_utils::GetIsDistillableJs()).Release();
71 jstring GetValueForKeyInUrl(JNIEnv* env,
72 jclass clazz,
73 jstring j_url,
74 jstring j_key) {
75 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
76 std::string key = base::android::ConvertJavaStringToUTF8(env, j_key);
77 return base::android::
78 ConvertUTF8ToJavaString(
79 env, dom_distiller::url_utils::GetValueForKeyInUrl(url, key))
80 .Release();
83 bool RegisterUrlUtils(JNIEnv* env) { return RegisterNativesImpl(env); }
85 } // namespace android
87 } // namespace url_utils
89 } // namespace dom_distiller