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/distilled_page_prefs_android.h"
7 #include "components/dom_distiller/core/distilled_page_prefs.h"
8 #include "components/dom_distiller/core/dom_distiller_service.h"
9 #include "jni/DistilledPagePrefs_jni.h"
11 namespace dom_distiller
{
15 DistilledPagePrefsAndroid::DistilledPagePrefsAndroid(
18 DistilledPagePrefs
* distilled_page_prefs_ptr
)
19 : distilled_page_prefs_(distilled_page_prefs_ptr
) {
22 DistilledPagePrefsAndroid::~DistilledPagePrefsAndroid() {
25 void DistilledPagePrefsAndroid::SetFontFamily(JNIEnv
* env
,
28 distilled_page_prefs_
->SetFontFamily(
29 static_cast<DistilledPagePrefs::FontFamily
>(font_family
));
32 jint
DistilledPagePrefsAndroid::GetFontFamily(JNIEnv
* env
, jobject obj
) {
33 return (int) distilled_page_prefs_
->GetFontFamily();
36 void DistilledPagePrefsAndroid::SetTheme(JNIEnv
* env
, jobject obj
, jint theme
) {
37 distilled_page_prefs_
->SetTheme(
38 static_cast<DistilledPagePrefs::Theme
>(theme
));
41 jint
DistilledPagePrefsAndroid::GetTheme(JNIEnv
* env
, jobject obj
) {
42 return (int) distilled_page_prefs_
->GetTheme();
45 jlong
Init(JNIEnv
* env
,
46 const JavaParamRef
<jobject
>& obj
,
47 jlong distilled_page_prefs_ptr
) {
48 DistilledPagePrefs
* distilled_page_prefs
=
49 reinterpret_cast<DistilledPagePrefs
*>(distilled_page_prefs_ptr
);
50 DistilledPagePrefsAndroid
* distilled_page_prefs_android
=
51 new DistilledPagePrefsAndroid(env
, obj
, distilled_page_prefs
);
52 return reinterpret_cast<intptr_t>(distilled_page_prefs_android
);
55 bool DistilledPagePrefsAndroid::Register(JNIEnv
* env
) {
56 return RegisterNativesImpl(env
);
59 void DistilledPagePrefsAndroid::AddObserver(JNIEnv
* env
,
62 DistilledPagePrefsObserverAndroid
* distilled_page_prefs_observer_wrapper
=
63 reinterpret_cast<DistilledPagePrefsObserverAndroid
*>(observer_ptr
);
64 distilled_page_prefs_
->AddObserver(distilled_page_prefs_observer_wrapper
);
67 void DistilledPagePrefsAndroid::RemoveObserver(JNIEnv
* env
,
70 DistilledPagePrefsObserverAndroid
* distilled_page_prefs_observer_wrapper
=
71 reinterpret_cast<DistilledPagePrefsObserverAndroid
*>(observer_ptr
);
72 distilled_page_prefs_
->RemoveObserver(distilled_page_prefs_observer_wrapper
);
75 DistilledPagePrefsObserverAndroid::DistilledPagePrefsObserverAndroid(
78 java_ref_
.Reset(env
, obj
);
81 DistilledPagePrefsObserverAndroid::~DistilledPagePrefsObserverAndroid() {}
83 void DistilledPagePrefsObserverAndroid::DestroyObserverAndroid(JNIEnv
* env
,
88 void DistilledPagePrefsObserverAndroid::OnChangeFontFamily(
89 DistilledPagePrefs::FontFamily new_font_family
) {
90 JNIEnv
* env
= base::android::AttachCurrentThread();
91 Java_DistilledPagePrefsObserverWrapper_onChangeFontFamily(
92 env
, java_ref_
.obj(), (int)new_font_family
);
95 void DistilledPagePrefsObserverAndroid::OnChangeTheme(
96 DistilledPagePrefs::Theme new_theme
) {
97 JNIEnv
* env
= base::android::AttachCurrentThread();
98 Java_DistilledPagePrefsObserverWrapper_onChangeTheme(
99 env
, java_ref_
.obj(), (int)new_theme
);
102 jlong
InitObserverAndroid(JNIEnv
* env
, const JavaParamRef
<jobject
>& obj
) {
103 DistilledPagePrefsObserverAndroid
* observer_android
=
104 new DistilledPagePrefsObserverAndroid(env
, obj
);
105 return reinterpret_cast<intptr_t>(observer_android
);
108 } // namespace android
110 } // namespace dom_distiller