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/dom_distiller_service_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "components/dom_distiller/core/distilled_page_prefs.h"
11 #include "components/dom_distiller/core/distilled_page_prefs_android.h"
12 #include "components/dom_distiller/core/dom_distiller_service.h"
13 #include "jni/DomDistillerService_jni.h"
15 using base::android::ConvertUTF8ToJavaString
;
16 using base::android::ScopedJavaLocalRef
;
18 namespace dom_distiller
{
21 DomDistillerServiceAndroid::DomDistillerServiceAndroid(
22 DomDistillerService
* service
)
24 JNIEnv
* env
= base::android::AttachCurrentThread();
25 base::android::ScopedJavaLocalRef
<jobject
> local_java_ref
=
26 Java_DomDistillerService_create(env
, reinterpret_cast<intptr_t>(this));
27 java_ref_
.Reset(env
, local_java_ref
.obj());
30 DomDistillerServiceAndroid::~DomDistillerServiceAndroid() {
33 bool DomDistillerServiceAndroid::HasEntry(JNIEnv
* env
,
36 const std::string entry_id
=
37 base::android::ConvertJavaStringToUTF8(env
, j_entry_id
);
38 return service_
->HasEntry(entry_id
);
41 ScopedJavaLocalRef
<jstring
> DomDistillerServiceAndroid::GetUrlForEntry(
45 const std::string entry_id
=
46 base::android::ConvertJavaStringToUTF8(env
, j_entry_id
);
47 return ConvertUTF8ToJavaString(env
, service_
->GetUrlForEntry(entry_id
));
50 jlong
DomDistillerServiceAndroid::GetDistilledPagePrefsPtr(JNIEnv
* env
,
52 return reinterpret_cast<intptr_t>(service_
->GetDistilledPagePrefs());
55 bool DomDistillerServiceAndroid::Register(JNIEnv
* env
) {
56 return RegisterNativesImpl(env
);
59 } // namespace android
60 } // namespace dom_distiller