Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/dom_distiller/core/dom_distiller_service_android.h" | 5 #include "components/dom_distiller/core/dom_distiller_service_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | |
| 9 #include "base/android/scoped_java_ref.h" | |
| 8 #include "components/dom_distiller/core/distilled_page_prefs.h" | 10 #include "components/dom_distiller/core/distilled_page_prefs.h" |
| 9 #include "components/dom_distiller/core/distilled_page_prefs_android.h" | 11 #include "components/dom_distiller/core/distilled_page_prefs_android.h" |
| 10 #include "components/dom_distiller/core/dom_distiller_service.h" | 12 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 11 #include "jni/DomDistillerService_jni.h" | 13 #include "jni/DomDistillerService_jni.h" |
| 12 | 14 |
| 15 using base::android::ConvertUTF8ToJavaString; | |
| 16 using base::android::ScopedJavaLocalRef; | |
| 17 | |
| 13 namespace dom_distiller { | 18 namespace dom_distiller { |
| 14 namespace android { | 19 namespace android { |
| 15 | 20 |
| 16 DomDistillerServiceAndroid::DomDistillerServiceAndroid( | 21 DomDistillerServiceAndroid::DomDistillerServiceAndroid( |
| 17 DomDistillerService* service) | 22 DomDistillerService* service) |
| 18 : service_(service) { | 23 : service_(service) { |
| 19 JNIEnv* env = base::android::AttachCurrentThread(); | 24 JNIEnv* env = base::android::AttachCurrentThread(); |
| 20 base::android::ScopedJavaLocalRef<jobject> local_java_ref = | 25 base::android::ScopedJavaLocalRef<jobject> local_java_ref = |
| 21 Java_DomDistillerService_create(env, reinterpret_cast<intptr_t>(this)); | 26 Java_DomDistillerService_create(env, reinterpret_cast<intptr_t>(this)); |
| 22 java_ref_.Reset(env, local_java_ref.obj()); | 27 java_ref_.Reset(env, local_java_ref.obj()); |
| 23 } | 28 } |
| 24 | 29 |
| 25 DomDistillerServiceAndroid::~DomDistillerServiceAndroid() { | 30 DomDistillerServiceAndroid::~DomDistillerServiceAndroid() { |
| 26 } | 31 } |
| 27 | 32 |
| 33 bool DomDistillerServiceAndroid::HasEntry(JNIEnv* env, | |
| 34 jobject obj, | |
| 35 jstring j_entry_id) { | |
| 36 std::string entry_id = | |
|
robliao
2014/08/13 23:43:15
const std::string
sunangel
2014/08/13 23:47:15
Done.
| |
| 37 base::android::ConvertJavaStringToUTF8(env, j_entry_id); | |
| 38 return service_->HasEntry(entry_id); | |
| 39 } | |
| 40 | |
| 41 ScopedJavaLocalRef<jstring> DomDistillerServiceAndroid::GetUrlForEntry( | |
| 42 JNIEnv* env, | |
| 43 jobject obj, | |
| 44 jstring j_entry_id) { | |
| 45 const std::string entry_id = | |
| 46 base::android::ConvertJavaStringToUTF8(env, j_entry_id); | |
| 47 return ConvertUTF8ToJavaString(env, service_->GetUrlForEntry(entry_id)); | |
| 48 } | |
| 49 | |
| 28 jlong DomDistillerServiceAndroid::GetDistilledPagePrefsPtr(JNIEnv* env, | 50 jlong DomDistillerServiceAndroid::GetDistilledPagePrefsPtr(JNIEnv* env, |
| 29 jobject obj) { | 51 jobject obj) { |
| 30 return reinterpret_cast<intptr_t>(service_->GetDistilledPagePrefs()); | 52 return reinterpret_cast<intptr_t>(service_->GetDistilledPagePrefs()); |
| 31 } | 53 } |
| 32 | 54 |
| 33 bool DomDistillerServiceAndroid::Register(JNIEnv* env) { | 55 bool DomDistillerServiceAndroid::Register(JNIEnv* env) { |
| 34 return RegisterNativesImpl(env); | 56 return RegisterNativesImpl(env); |
| 35 } | 57 } |
| 36 | 58 |
| 37 } // namespace android | 59 } // namespace android |
| 38 } // namespace dom_distiller | 60 } // namespace dom_distiller |
| OLD | NEW |