summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorsunangel@chromium.org <sunangel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-17 10:57:09 +0000
committersunangel@chromium.org <sunangel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-17 10:57:09 +0000
commit9d0d78491d7037d5ac51d5fa7ac8f493307c5c1b (patch)
tree028077eaad03341a799e64441779e996a5c0aca4 /components
parent37216c6396f3dfc1cec887d7bab5088c1b9e705b (diff)
downloadchromium_src-9d0d78491d7037d5ac51d5fa7ac8f493307c5c1b.zip
chromium_src-9d0d78491d7037d5ac51d5fa7ac8f493307c5c1b.tar.gz
chromium_src-9d0d78491d7037d5ac51d5fa7ac8f493307c5c1b.tar.bz2
Java wrapper for DistilledPagePrefs.
Adds Java version of DomDistillerService and DistilledPagePrefs with support for setting and retrieving the current Theme. The DomDistillerService can be retrieved by using the DomDistillerServiceFactory, which maps a profile to an instance of the service. BUG=383630 Review URL: https://codereview.chromium.org/340403004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283742 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/dom_distiller.gypi20
-rw-r--r--components/dom_distiller/android/component_jni_registrar.cc7
-rw-r--r--components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java37
-rw-r--r--components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DomDistillerService.java38
-rw-r--r--components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/Theme.template37
-rw-r--r--components/dom_distiller/core/distilled_page_prefs.h7
-rw-r--r--components/dom_distiller/core/distilled_page_prefs_android.cc45
-rw-r--r--components/dom_distiller/core/distilled_page_prefs_android.h35
-rw-r--r--components/dom_distiller/core/dom_distiller_service_android.cc38
-rw-r--r--components/dom_distiller/core/dom_distiller_service_android.h41
-rw-r--r--components/dom_distiller/core/theme_list.h17
11 files changed, 317 insertions, 5 deletions
diff --git a/components/dom_distiller.gypi b/components/dom_distiller.gypi
index fc88cd2..b18bee7 100644
--- a/components/dom_distiller.gypi
+++ b/components/dom_distiller.gypi
@@ -62,6 +62,8 @@
'dom_distiller/core/distilled_content_store.h',
'dom_distiller/core/distilled_page_prefs.cc',
'dom_distiller/core/distilled_page_prefs.h',
+ 'dom_distiller/core/distilled_page_prefs_android.cc',
+ 'dom_distiller/core/distilled_page_prefs_android.h',
'dom_distiller/core/distiller.cc',
'dom_distiller/core/distiller.h',
'dom_distiller/core/distiller_page.cc',
@@ -75,12 +77,15 @@
'dom_distiller/core/dom_distiller_observer.h',
'dom_distiller/core/dom_distiller_service.cc',
'dom_distiller/core/dom_distiller_service.h',
+ 'dom_distiller/core/dom_distiller_service_android.cc',
+ 'dom_distiller/core/dom_distiller_service_android.h',
'dom_distiller/core/dom_distiller_store.cc',
'dom_distiller/core/dom_distiller_store.h',
'dom_distiller/core/feedback_reporter.cc',
'dom_distiller/core/feedback_reporter.h',
'dom_distiller/core/task_tracker.cc',
'dom_distiller/core/task_tracker.h',
+ 'dom_distiller/core/theme_list.h',
'dom_distiller/core/url_constants.cc',
'dom_distiller/core/url_constants.h',
'dom_distiller/core/url_utils_android.cc',
@@ -171,6 +176,7 @@
'target_name': 'dom_distiller_core_java',
'type': 'none',
'dependencies': [
+ 'dom_distiller_core_theme_java',
'../base/base.gyp:base',
],
'variables': {
@@ -182,6 +188,8 @@
'target_name': 'dom_distiller_core_jni_headers',
'type': 'none',
'sources': [
+ 'dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java',
+ 'dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DomDistillerService.java',
'dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DomDistillerUrlUtils.java',
],
'variables': {
@@ -189,6 +197,18 @@
},
'includes': [ '../build/jni_generator.gypi' ],
},
+ {
+ 'target_name': 'dom_distiller_core_theme_java',
+ 'type': 'none',
+ 'sources': [
+ 'dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/Theme.template',
+ ],
+ 'variables': {
+ 'package_name': 'org/chromium/components/dom_distiller/core',
+ 'template_deps': ['dom_distiller/core/theme_list.h'],
+ },
+ 'includes': [ '../build/android/java_cpp_template.gypi' ],
+ },
],
}],
],
diff --git a/components/dom_distiller/android/component_jni_registrar.cc b/components/dom_distiller/android/component_jni_registrar.cc
index a19e4d4..f631a2d 100644
--- a/components/dom_distiller/android/component_jni_registrar.cc
+++ b/components/dom_distiller/android/component_jni_registrar.cc
@@ -7,6 +7,8 @@
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "base/basictypes.h"
+#include "components/dom_distiller/core/distilled_page_prefs_android.h"
+#include "components/dom_distiller/core/dom_distiller_service_android.h"
#include "components/dom_distiller/core/url_utils_android.h"
namespace dom_distiller {
@@ -14,8 +16,11 @@ namespace dom_distiller {
namespace android {
static base::android::RegistrationMethod kDomDistillerRegisteredMethods[] = {
+ {"DistilledPagePrefs", DistilledPagePrefsAndroid::Register},
+ {"DomDistillerService", DomDistillerServiceAndroid::Register},
{"DomDistillerUrlUtils",
- dom_distiller::url_utils::android::RegisterUrlUtils}, };
+ dom_distiller::url_utils::android::RegisterUrlUtils},
+};
bool RegisterDomDistiller(JNIEnv* env) {
return base::android::RegisterNativeMethods(
diff --git a/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java
new file mode 100644
index 0000000..3ec91ba
--- /dev/null
+++ b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java
@@ -0,0 +1,37 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.components.dom_distiller.core;
+
+import org.chromium.base.JNINamespace;
+
+/**
+ * Wrapper for the dom_distiller::DistilledPagePrefs.
+ */
+@JNINamespace("dom_distiller::android")
+public final class DistilledPagePrefs {
+
+ private final long mDistilledPagePrefsAndroid;
+
+ DistilledPagePrefs(long distilledPagePrefsPtr) {
+ mDistilledPagePrefsAndroid = nativeInit(distilledPagePrefsPtr);
+ }
+
+ // TODO(sunangel): Add observer support from this Java class to native
+ // counterpart so UI can be updated across tabs.
+ public void setTheme(Theme theme) {
+ nativeSetTheme(mDistilledPagePrefsAndroid, theme.asNativeEnum());
+ }
+
+ public Theme getTheme() {
+ return Theme.getThemeForValue(
+ nativeGetTheme(mDistilledPagePrefsAndroid));
+ }
+
+ private native long nativeInit(long distilledPagePrefPtr);
+ private native void nativeSetTheme(long nativeDistilledPagePrefsAndroid,
+ int theme);
+ private native int nativeGetTheme(
+ long nativeDistilledPagePrefsAndroid);
+}
diff --git a/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DomDistillerService.java b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DomDistillerService.java
new file mode 100644
index 0000000..e5b5cb8
--- /dev/null
+++ b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DomDistillerService.java
@@ -0,0 +1,38 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.components.dom_distiller.core;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+import org.chromium.base.ThreadUtils;
+
+/**
+ * Wrapper for native dom_distiller::DomDistillerService.
+ */
+@JNINamespace("dom_distiller::android")
+public final class DomDistillerService {
+
+ private final long mDomDistillerServiceAndroid;
+ private final DistilledPagePrefs mDistilledPagePrefs;
+
+ private DomDistillerService(long nativeDomDistillerAndroidServicePtr) {
+ mDomDistillerServiceAndroid = nativeDomDistillerAndroidServicePtr;
+ mDistilledPagePrefs = new DistilledPagePrefs(
+ nativeGetDistilledPagePrefsPtr(mDomDistillerServiceAndroid));
+ }
+
+ public DistilledPagePrefs getDistilledPagePrefs() {
+ return mDistilledPagePrefs;
+ }
+
+ @CalledByNative
+ private static DomDistillerService create(long nativeDomDistillerServiceAndroid) {
+ ThreadUtils.assertOnUiThread();
+ return new DomDistillerService(nativeDomDistillerServiceAndroid);
+ }
+
+ private static native long nativeGetDistilledPagePrefsPtr(
+ long nativeDomDistillerServiceAndroid);
+}
diff --git a/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/Theme.template b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/Theme.template
new file mode 100644
index 0000000..c74c8a3
--- /dev/null
+++ b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/Theme.template
@@ -0,0 +1,37 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.components.dom_distiller.core;
+
+// An auto-generated enum for Distilled Page Theme preferences as used by
+// org.chromium.components.dom_distiller.core.DistilledPagePrefs and
+// the corresponding native class
+// dom_distiller::android::DistilledPagePrefsAndroid
+public enum Theme {
+
+#define DEFINE_THEME(name, value) name(value),
+#include "components/dom_distiller/core/theme_list.h"
+#undef DEFINE_THEME
+;
+
+private final int mValue;
+
+private Theme(int value) {
+ mValue = value;
+}
+
+int asNativeEnum() {
+ return mValue;
+}
+
+static Theme getThemeForValue(int value) {
+ for (Theme theme: Theme.values()) {
+ if (theme.mValue == value) {
+ return theme;
+ }
+ }
+ return null;
+}
+
+}
diff --git a/components/dom_distiller/core/distilled_page_prefs.h b/components/dom_distiller/core/distilled_page_prefs.h
index 9b93be5..7a40b27 100644
--- a/components/dom_distiller/core/distilled_page_prefs.h
+++ b/components/dom_distiller/core/distilled_page_prefs.h
@@ -22,10 +22,9 @@ class DistilledPagePrefs {
public:
// Possible themes for distilled page.
enum Theme {
- LIGHT,
- DARK,
- SEPIA,
- THEME_COUNT
+#define DEFINE_THEME(name, value) name = value,
+#include "components/dom_distiller/core/theme_list.h"
+#undef DEFINE_THEME
};
class Observer {
diff --git a/components/dom_distiller/core/distilled_page_prefs_android.cc b/components/dom_distiller/core/distilled_page_prefs_android.cc
new file mode 100644
index 0000000..a4edfbd
--- /dev/null
+++ b/components/dom_distiller/core/distilled_page_prefs_android.cc
@@ -0,0 +1,45 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/dom_distiller/core/distilled_page_prefs_android.h"
+
+#include "components/dom_distiller/core/distilled_page_prefs.h"
+#include "components/dom_distiller/core/dom_distiller_service.h"
+#include "jni/DistilledPagePrefs_jni.h"
+
+namespace dom_distiller {
+namespace android {
+
+DistilledPagePrefsAndroid::DistilledPagePrefsAndroid(
+ JNIEnv* env,
+ jobject obj,
+ DistilledPagePrefs* distillerPagePrefsPtr)
+ : distilled_page_prefs_(distillerPagePrefsPtr) {
+}
+
+DistilledPagePrefsAndroid::~DistilledPagePrefsAndroid() {
+}
+
+void DistilledPagePrefsAndroid::SetTheme(JNIEnv* env, jobject obj, jint theme) {
+ distilled_page_prefs_->SetTheme((DistilledPagePrefs::Theme)theme);
+}
+
+jint DistilledPagePrefsAndroid::GetTheme(JNIEnv* env, jobject obj) {
+ return (int)distilled_page_prefs_->GetTheme();
+}
+
+jlong Init(JNIEnv* env, jobject obj, jlong distilledPagePrefsPtr) {
+ DistilledPagePrefs* distilledPagePrefs =
+ reinterpret_cast<DistilledPagePrefs*>(distilledPagePrefsPtr);
+ DistilledPagePrefsAndroid* distilled_page_prefs_android =
+ new DistilledPagePrefsAndroid(env, obj, distilledPagePrefs);
+ return reinterpret_cast<intptr_t>(distilled_page_prefs_android);
+}
+
+bool DistilledPagePrefsAndroid::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace android
+} // namespace dom_distiller
diff --git a/components/dom_distiller/core/distilled_page_prefs_android.h b/components/dom_distiller/core/distilled_page_prefs_android.h
new file mode 100644
index 0000000..baf7398
--- /dev/null
+++ b/components/dom_distiller/core/distilled_page_prefs_android.h
@@ -0,0 +1,35 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_DOM_DISTILLER_CORE_DISTILLED_PAGE_PREFS_ANDROID_H_
+#define COMPONENTS_DOM_DISTILLER_CORE_DISTILLED_PAGE_PREFS_ANDROID_H_
+
+#include <jni.h>
+
+#include "base/android/scoped_java_ref.h"
+#include "components/dom_distiller/core/distilled_page_prefs.h"
+
+namespace dom_distiller {
+namespace android {
+
+class DistilledPagePrefsAndroid {
+ public:
+ DistilledPagePrefsAndroid(JNIEnv* env,
+ jobject obj,
+ DistilledPagePrefs* distillerPagePrefsPtr);
+ virtual ~DistilledPagePrefsAndroid();
+ static bool Register(JNIEnv* env);
+ void SetTheme(JNIEnv* env, jobject obj, jint theme);
+ jint GetTheme(JNIEnv* env, jobject obj);
+
+ private:
+ DistilledPagePrefs* distilled_page_prefs_;
+
+ DISALLOW_COPY_AND_ASSIGN(DistilledPagePrefsAndroid);
+};
+
+} // namespace android
+} // namespace dom_distiller
+
+#endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLED_PAGE_PREFS_ANDROID_H_
diff --git a/components/dom_distiller/core/dom_distiller_service_android.cc b/components/dom_distiller/core/dom_distiller_service_android.cc
new file mode 100644
index 0000000..5f65594
--- /dev/null
+++ b/components/dom_distiller/core/dom_distiller_service_android.cc
@@ -0,0 +1,38 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/dom_distiller/core/dom_distiller_service_android.h"
+
+#include "base/android/jni_android.h"
+#include "components/dom_distiller/core/distilled_page_prefs.h"
+#include "components/dom_distiller/core/distilled_page_prefs_android.h"
+#include "components/dom_distiller/core/dom_distiller_service.h"
+#include "jni/DomDistillerService_jni.h"
+
+namespace dom_distiller {
+namespace android {
+
+DomDistillerServiceAndroid::DomDistillerServiceAndroid(
+ DomDistillerService* service)
+ : service_(service) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ base::android::ScopedJavaLocalRef<jobject> local_java_ref =
+ Java_DomDistillerService_create(env, reinterpret_cast<intptr_t>(this));
+ java_ref_.Reset(env, local_java_ref.obj());
+}
+
+DomDistillerServiceAndroid::~DomDistillerServiceAndroid() {
+}
+
+jlong DomDistillerServiceAndroid::GetDistilledPagePrefsPtr(JNIEnv* env,
+ jobject obj) {
+ return reinterpret_cast<intptr_t>(service_->GetDistilledPagePrefs());
+}
+
+bool DomDistillerServiceAndroid::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace android
+} // namespace dom_distiller
diff --git a/components/dom_distiller/core/dom_distiller_service_android.h b/components/dom_distiller/core/dom_distiller_service_android.h
new file mode 100644
index 0000000..bf68947
--- /dev/null
+++ b/components/dom_distiller/core/dom_distiller_service_android.h
@@ -0,0 +1,41 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_ANDROID_H_
+#define COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_ANDROID_H_
+
+#include <jni.h>
+
+#include "base/android/scoped_java_ref.h"
+#include "components/dom_distiller/core/dom_distiller_service.h"
+
+namespace dom_distiller {
+namespace android {
+
+class DomDistillerServiceFactoryAndroid;
+
+// Native implementation of DomDistillerService,
+// provides access to Java DistilledPagePrefs.
+class DomDistillerServiceAndroid {
+ public:
+ DomDistillerServiceAndroid(DomDistillerService* service);
+ virtual ~DomDistillerServiceAndroid();
+ static bool Register(JNIEnv* env);
+ // Returns native pointer to native DistilledPagePrefs registered with
+ // DomDistillerService.
+ jlong GetDistilledPagePrefsPtr(JNIEnv* env, jobject obj);
+
+ private:
+ // Friend class so that DomDistillerServiceFactoryAndroid has access to
+ // private member object java_ref_.
+ friend class DomDistillerServiceFactoryAndroid;
+ // Points to a Java instance of DomDistillerService.
+ base::android::ScopedJavaGlobalRef<jobject> java_ref_;
+ DomDistillerService* service_;
+};
+
+} // namespace android
+} // namespace dom_distiller
+
+#endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_ANDROID_H
diff --git a/components/dom_distiller/core/theme_list.h b/components/dom_distiller/core/theme_list.h
new file mode 100644
index 0000000..44496a5
--- /dev/null
+++ b/components/dom_distiller/core/theme_list.h
@@ -0,0 +1,17 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file intentionally does not have header guards, it's included
+// inside a macro to generate enum values.
+
+#ifndef DEFINE_THEME
+#error "DEFINE_THEME should be defined before including this file"
+#endif
+
+// First argument represents the enum name, second argument represents enum
+// value. THEME_COUNT used only by native enum.
+DEFINE_THEME(LIGHT, 0)
+DEFINE_THEME(DARK, 1)
+DEFINE_THEME(SEPIA, 2)
+DEFINE_THEME(THEME_COUNT, 3)