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"
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"
16 namespace dom_distiller
{
22 ScopedJavaLocalRef
<jstring
> GetDistillerViewUrlFromUrl(JNIEnv
* env
,
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 ScopedJavaLocalRef
<jstring
>();
32 dom_distiller::url_utils::GetDistillerViewUrlFromUrl(scheme
, url
);
33 if (!view_url
.is_valid()) {
34 return ScopedJavaLocalRef
<jstring
>();
36 return base::android::ConvertUTF8ToJavaString(env
, view_url
.spec());
39 ScopedJavaLocalRef
<jstring
> GetOriginalUrlFromDistillerUrl(JNIEnv
* env
,
42 GURL
url(base::android::ConvertJavaStringToUTF8(env
, j_url
));
44 return ScopedJavaLocalRef
<jstring
>();
47 dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(url
);
48 if (!original_url
.is_valid())
49 return ScopedJavaLocalRef
<jstring
>();
51 return base::android::ConvertUTF8ToJavaString(env
, original_url
.spec());
54 jboolean
IsDistilledPage(JNIEnv
* env
, jclass clazz
, jstring j_url
) {
55 GURL
url(base::android::ConvertJavaStringToUTF8(env
, j_url
));
56 return dom_distiller::url_utils::IsDistilledPage(url
);
59 jboolean
IsUrlDistillable(JNIEnv
* env
, jclass clazz
, jstring j_url
) {
60 GURL
url(base::android::ConvertJavaStringToUTF8(env
, j_url
));
61 return dom_distiller::url_utils::IsUrlDistillable(url
);
64 ScopedJavaLocalRef
<jstring
> GetIsDistillableJs(JNIEnv
* env
, jclass clazz
) {
65 return base::android::ConvertUTF8ToJavaString(
66 env
, dom_distiller::url_utils::GetIsDistillableJs());
69 ScopedJavaLocalRef
<jstring
> GetValueForKeyInUrl(JNIEnv
* env
,
73 GURL
url(base::android::ConvertJavaStringToUTF8(env
, j_url
));
74 std::string key
= base::android::ConvertJavaStringToUTF8(env
, j_key
);
75 return base::android::ConvertUTF8ToJavaString(
76 env
, dom_distiller::url_utils::GetValueForKeyInUrl(url
, key
));
79 bool RegisterUrlUtils(JNIEnv
* env
) { return RegisterNativesImpl(env
); }
81 } // namespace android
83 } // namespace url_utils
85 } // namespace dom_distiller