summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerServiceFactory.java40
-rw-r--r--chrome/android/javatests/DEPS1
-rw-r--r--chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java42
-rw-r--r--chrome/browser/android/chrome_jni_registrar.cc3
-rw-r--r--chrome/browser/dom_distiller/dom_distiller_service_factory_android.cc40
-rw-r--r--chrome/browser/dom_distiller/dom_distiller_service_factory_android.h24
-rw-r--r--chrome/chrome_browser.gypi3
-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
18 files changed, 470 insertions, 5 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerServiceFactory.java b/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerServiceFactory.java
new file mode 100644
index 0000000..b7f1dcb
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerServiceFactory.java
@@ -0,0 +1,40 @@
+// 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.chrome.browser.dom_distiller;
+
+import org.chromium.base.JNINamespace;
+import org.chromium.base.ThreadUtils;
+import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.components.dom_distiller.core.DomDistillerService;
+
+import java.util.HashMap;
+
+/**
+ * DomDistillerServiceFactory maps Profiles to instances of
+ * {@link DomDistillerService} instances. Each {@link Profile} will at most
+ * have one instance of this service. If the service does not already exist,
+ * it will be created on the first access.
+ */
+@JNINamespace("dom_distiller::android")
+public class DomDistillerServiceFactory {
+
+ private static final HashMap<Profile, DomDistillerService> sServiceMap =
+ new HashMap<Profile, DomDistillerService>();
+
+ /**
+ * Returns Java DomDistillerService for given Profile.
+ */
+ public static DomDistillerService getForProfile(Profile profile) {
+ ThreadUtils.assertOnUiThread();
+ DomDistillerService service = sServiceMap.get(profile);
+ if (service == null) {
+ service = (DomDistillerService) nativeGetForProfile(profile);
+ sServiceMap.put(profile, service);
+ }
+ return service;
+ }
+
+ private static native DomDistillerService nativeGetForProfile(Profile profile);
+}
diff --git a/chrome/android/javatests/DEPS b/chrome/android/javatests/DEPS
index 619b59b..c3c100b 100644
--- a/chrome/android/javatests/DEPS
+++ b/chrome/android/javatests/DEPS
@@ -1,4 +1,5 @@
include_rules = [
+ "+components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core",
"+content/public/android/java",
"+sync/android/java/src/org/chromium/sync/internal_api/pub",
"+sync/android/java/src/org/chromium/sync/notifier",
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java
new file mode 100644
index 0000000..60e87b1
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java
@@ -0,0 +1,42 @@
+// 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.chrome.browser.dom_distiller;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import android.test.UiThreadTest;
+
+import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.chrome.shell.ChromeShellTestBase;
+import org.chromium.components.dom_distiller.core.DistilledPagePrefs;
+import org.chromium.components.dom_distiller.core.DomDistillerService;
+import org.chromium.components.dom_distiller.core.Theme;
+
+/**
+ * Test class for {@link DistilledPagePrefs}.
+ */
+public class DistilledPagePrefsTest extends ChromeShellTestBase {
+
+ @SmallTest
+ @UiThreadTest
+ @Feature({"DomDistiller"})
+ public void testGetAndSetPrefs() throws InterruptedException {
+ startChromeBrowserProcessSync(getInstrumentation().getTargetContext());
+ DomDistillerService service = DomDistillerServiceFactory.
+ getForProfile(Profile.getLastUsedProfile());
+ assertNotNull(service);
+ DistilledPagePrefs distilledPagePrefs = service.getDistilledPagePrefs();
+ assertNotNull(distilledPagePrefs);
+ // Check default theme.
+ assertEquals(distilledPagePrefs.getTheme(), Theme.LIGHT);
+ // Check that theme can be correctly set.
+ distilledPagePrefs.setTheme(Theme.DARK);
+ assertEquals(Theme.DARK, distilledPagePrefs.getTheme());
+ distilledPagePrefs.setTheme(Theme.LIGHT);
+ assertEquals(Theme.LIGHT, distilledPagePrefs.getTheme());
+ distilledPagePrefs.setTheme(Theme.SEPIA);
+ assertEquals(Theme.SEPIA, distilledPagePrefs.getTheme());
+ }
+}
diff --git a/chrome/browser/android/chrome_jni_registrar.cc b/chrome/browser/android/chrome_jni_registrar.cc
index e410960..7835b03 100644
--- a/chrome/browser/android/chrome_jni_registrar.cc
+++ b/chrome/browser/android/chrome_jni_registrar.cc
@@ -38,6 +38,7 @@
#include "chrome/browser/android/url_utilities.h"
#include "chrome/browser/android/voice_search_tab_helper.h"
#include "chrome/browser/autofill/android/personal_data_manager_android.h"
+#include "chrome/browser/dom_distiller/dom_distiller_service_factory_android.h"
#include "chrome/browser/dom_distiller/tab_utils_android.h"
#include "chrome/browser/history/android/sqlite_cursor.h"
#include "chrome/browser/invalidation/invalidation_controller_android.h"
@@ -127,6 +128,8 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
{ "ContextMenuHelper", RegisterContextMenuHelper },
{ "DataReductionProxySettings", DataReductionProxySettingsAndroid::Register },
{ "DevToolsServer", RegisterDevToolsServer },
+ { "DomDistillerServiceFactory",
+ dom_distiller::android::DomDistillerServiceFactoryAndroid::Register},
{ "DomDistillerTabUtils", RegisterDomDistillerTabUtils },
{ "ExternalPrerenderRequestHandler",
prerender::ExternalPrerenderHandlerAndroid::
diff --git a/chrome/browser/dom_distiller/dom_distiller_service_factory_android.cc b/chrome/browser/dom_distiller/dom_distiller_service_factory_android.cc
new file mode 100644
index 0000000..892a441
--- /dev/null
+++ b/chrome/browser/dom_distiller/dom_distiller_service_factory_android.cc
@@ -0,0 +1,40 @@
+// 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 "chrome/browser/dom_distiller/dom_distiller_service_factory_android.h"
+
+#include "base/android/jni_android.h"
+#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_android.h"
+#include "components/dom_distiller/core/dom_distiller_service_android.h"
+#include "jni/DomDistillerServiceFactory_jni.h"
+
+using base::android::ScopedJavaLocalRef;
+
+namespace dom_distiller {
+namespace android {
+
+jobject DomDistillerServiceFactoryAndroid::GetForProfile(JNIEnv* env,
+ jclass clazz,
+ jobject j_profile) {
+ dom_distiller::DomDistillerService* service =
+ dom_distiller::DomDistillerServiceFactory::GetForBrowserContext(
+ ProfileAndroid::FromProfileAndroid(j_profile));
+ DomDistillerServiceAndroid* service_android =
+ new DomDistillerServiceAndroid(service);
+ return service_android->java_ref_.obj();
+}
+
+bool DomDistillerServiceFactoryAndroid::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+jobject GetForProfile(JNIEnv* env, jclass clazz, jobject j_profile) {
+ return DomDistillerServiceFactoryAndroid::GetForProfile(
+ env, clazz, j_profile);
+}
+
+} // namespace android
+} // namespace dom_distiller
diff --git a/chrome/browser/dom_distiller/dom_distiller_service_factory_android.h b/chrome/browser/dom_distiller/dom_distiller_service_factory_android.h
new file mode 100644
index 0000000..a44584c
--- /dev/null
+++ b/chrome/browser/dom_distiller/dom_distiller_service_factory_android.h
@@ -0,0 +1,24 @@
+// 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 CHROME_BROWSER_DOM_DISTILLER_DOM_DISTILLER_SERVICE_FACTORY_ANDROID_H_
+#define CHROME_BROWSER_DOM_DISTILLER_DOM_DISTILLER_SERVICE_FACTORY_ANDROID_H_
+
+#include <jni.h>
+
+namespace dom_distiller {
+namespace android {
+
+// This class should not be used except from the Java class
+// DomDistillerServiceFactory.
+class DomDistillerServiceFactoryAndroid {
+ public:
+ static jobject GetForProfile(JNIEnv* env, jclass clazz, jobject j_profile);
+ static bool Register(JNIEnv* env);
+};
+
+} // namespace android
+} // namespace dom_distiller
+
+#endif // CHROME_BROWSER_DOM_DISTILLER_DOM_DISTILLER_SERVICE_FACTORY_ANDROID_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index cf770ea..3479251 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -362,6 +362,8 @@
'browser/defaults.h',
'browser/dom_distiller/dom_distiller_service_factory.cc',
'browser/dom_distiller/dom_distiller_service_factory.h',
+ 'browser/dom_distiller/dom_distiller_service_factory_android.cc',
+ 'browser/dom_distiller/dom_distiller_service_factory_android.h',
'browser/dom_distiller/lazy_dom_distiller_service.cc',
'browser/dom_distiller/lazy_dom_distiller_service.h',
'browser/dom_distiller/tab_utils.cc',
@@ -2767,6 +2769,7 @@
'android/java/src/org/chromium/chrome/browser/DevToolsServer.java',
'android/java/src/org/chromium/chrome/browser/database/SQLiteCursor.java',
'android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerFeedbackReporter.java',
+ 'android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerServiceFactory.java',
'android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerTabUtils.java',
'android/java/src/org/chromium/chrome/browser/favicon/FaviconHelper.java',
'android/java/src/org/chromium/chrome/browser/ForeignSessionHelper.java',
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)