summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/android/shell/res/menu/main_menu.xml2
-rw-r--r--chrome/android/shell/res/values/strings.xml1
-rw-r--r--chrome/android/testshell/java/DEPS1
-rw-r--r--chrome/android/testshell/java/src/org/chromium/chrome/shell/ChromiumTestShellActivity.java11
-rw-r--r--chrome/android/testshell/java/src/org/chromium/chrome/shell/TestShellSwitches.java13
-rw-r--r--chrome/browser/android/chrome_jni_registrar.cc2
-rw-r--r--chrome/chrome_android.gypi5
-rw-r--r--components/dom_distiller.gypi37
-rw-r--r--components/dom_distiller/DEPS1
-rw-r--r--components/dom_distiller/android/component_jni_registrar.cc29
-rw-r--r--components/dom_distiller/android/component_jni_registrar.h21
-rw-r--r--components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DomDistillerUrlUtils.java30
-rw-r--r--components/dom_distiller/core/url_utils_android.cc43
-rw-r--r--components/dom_distiller/core/url_utils_android.h27
14 files changed, 221 insertions, 2 deletions
diff --git a/chrome/android/shell/res/menu/main_menu.xml b/chrome/android/shell/res/menu/main_menu.xml
index 4235001..09d2114 100644
--- a/chrome/android/shell/res/menu/main_menu.xml
+++ b/chrome/android/shell/res/menu/main_menu.xml
@@ -12,6 +12,8 @@
android:title="@string/signin_sign_in" />
<item android:id="@+id/print"
android:title="@string/print_menu" />
+ <item android:id="@+id/distill_page"
+ android:title="@string/distill_page_menu" />
</group>
<group android:id="@+id/PHONE_ICON_MENU_ITEMS"
diff --git a/chrome/android/shell/res/values/strings.xml b/chrome/android/shell/res/values/strings.xml
index 1081327..df212c1 100644
--- a/chrome/android/shell/res/values/strings.xml
+++ b/chrome/android/shell/res/values/strings.xml
@@ -15,5 +15,6 @@
<string name="signout_title">Do you want to sign out?</string>
<string name="signout_sign_out">Sign out</string>
<string name="signout_cancel">Cancel</string>
+ <string name="distill_page_menu">Distill page</string>
<string name="browser_process_initialization_failed">Initialization failed.</string>
</resources>
diff --git a/chrome/android/testshell/java/DEPS b/chrome/android/testshell/java/DEPS
index 0d019e1..fcb5e7b 100644
--- a/chrome/android/testshell/java/DEPS
+++ b/chrome/android/testshell/java/DEPS
@@ -1,3 +1,4 @@
include_rules = [
+ "+components/dom_distiller/android/java",
"+content/public/android/java",
]
diff --git a/chrome/android/testshell/java/src/org/chromium/chrome/shell/ChromiumTestShellActivity.java b/chrome/android/testshell/java/src/org/chromium/chrome/shell/ChromiumTestShellActivity.java
index f82d707..349afc1 100644
--- a/chrome/android/testshell/java/src/org/chromium/chrome/shell/ChromiumTestShellActivity.java
+++ b/chrome/android/testshell/java/src/org/chromium/chrome/shell/ChromiumTestShellActivity.java
@@ -28,6 +28,7 @@ import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate;
import org.chromium.chrome.browser.printing.PrintingControllerFactory;
import org.chromium.chrome.browser.printing.TabPrinter;
import org.chromium.chrome.shell.sync.SyncController;
+import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils;
import org.chromium.content.browser.ActivityContentVideoViewClient;
import org.chromium.content.browser.BrowserStartupController;
import org.chromium.content.browser.ContentView;
@@ -42,6 +43,7 @@ import org.chromium.ui.base.WindowAndroid;
*/
public class ChromiumTestShellActivity extends Activity implements AppMenuPropertiesDelegate {
private static final String TAG = "ChromiumTestShellActivity";
+ private static final String CHROME_DISTILLER_SCHEME = "chrome-distiller";
private WindowAndroid mWindow;
private TabManager mTabManager;
@@ -233,6 +235,12 @@ public class ChromiumTestShellActivity extends Activity implements AppMenuProper
mPrintingController.startPrint(new TabPrinter(getActiveTab()));
}
return true;
+ case R.id.distill_page:
+ TestShellTab activeTab = getActiveTab();
+ String viewUrl = DomDistillerUrlUtils.getDistillerViewUrlFromUrl(
+ CHROME_DISTILLER_SCHEME, getActiveTab().getUrl());
+ activeTab.loadUrlWithSanitization(viewUrl);
+ return true;
case R.id.back_menu_id:
if (getActiveTab().canGoBack()) getActiveTab().goBack();
return true;
@@ -283,6 +291,9 @@ public class ChromiumTestShellActivity extends Activity implements AppMenuProper
menu.findItem(R.id.print).setVisible(ApiCompatibilityUtils.isPrintingSupported());
+ menu.findItem(R.id.distill_page).setVisible(
+ CommandLine.getInstance().hasSwitch(TestShellSwitches.ENABLE_DOM_DISTILLER));
+
menu.setGroupVisible(R.id.MAIN_MENU, true);
}
diff --git a/chrome/android/testshell/java/src/org/chromium/chrome/shell/TestShellSwitches.java b/chrome/android/testshell/java/src/org/chromium/chrome/shell/TestShellSwitches.java
new file mode 100644
index 0000000..809661a
--- /dev/null
+++ b/chrome/android/testshell/java/src/org/chromium/chrome/shell/TestShellSwitches.java
@@ -0,0 +1,13 @@
+// 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.shell;
+
+/**
+ * Command line switches for the shell.
+ */
+public abstract class TestShellSwitches {
+ // Enable the DOM Distiller.
+ public static final String ENABLE_DOM_DISTILLER = "enable-dom-distiller";
+}
diff --git a/chrome/browser/android/chrome_jni_registrar.cc b/chrome/browser/android/chrome_jni_registrar.cc
index 446a99d..1c4b0b8 100644
--- a/chrome/browser/android/chrome_jni_registrar.cc
+++ b/chrome/browser/android/chrome_jni_registrar.cc
@@ -62,6 +62,7 @@
#include "chrome/browser/ui/android/toolbar/toolbar_model_android.h"
#include "chrome/browser/ui/android/website_settings_popup_android.h"
#include "components/autofill/core/browser/android/component_jni_registrar.h"
+#include "components/dom_distiller/android/component_jni_registrar.h"
#include "components/navigation_interception/component_jni_registrar.h"
#include "components/web_contents_delegate_android/component_jni_registrar.h"
@@ -76,6 +77,7 @@ namespace android {
static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
// Register JNI for components we depend on.
+ { "DomDistiller", dom_distiller::android::RegisterDomDistiller },
{ "NavigationInterception",
navigation_interception::RegisterNavigationInterceptionJni },
{ "WebContentsDelegateAndroid",
diff --git a/chrome/chrome_android.gypi b/chrome/chrome_android.gypi
index 8292d4b..4f1adde 100644
--- a/chrome/chrome_android.gypi
+++ b/chrome/chrome_android.gypi
@@ -49,10 +49,11 @@
'target_name': 'chromium_testshell',
'type': 'none',
'dependencies': [
- '../media/media.gyp:media_java',
- 'chrome.gyp:chrome_java',
+ 'chrome_java',
'chromium_testshell_paks',
'libchromiumtestshell',
+ '../components/components.gyp:dom_distiller_core_java',
+ '../media/media.gyp:media_java',
],
'variables': {
'apk_name': 'ChromiumTestShell',
diff --git a/components/dom_distiller.gypi b/components/dom_distiller.gypi
index 1ad3f07..4e8b6ed 100644
--- a/components/dom_distiller.gypi
+++ b/components/dom_distiller.gypi
@@ -48,6 +48,8 @@
'distilled_page_proto',
],
'sources': [
+ 'dom_distiller/android/component_jni_registrar.cc',
+ 'dom_distiller/android/component_jni_registrar.h',
'dom_distiller/core/article_entry.cc',
'dom_distiller/core/article_entry.h',
'dom_distiller/core/distiller.cc',
@@ -73,9 +75,18 @@
'dom_distiller/core/task_tracker.h',
'dom_distiller/core/url_constants.cc',
'dom_distiller/core/url_constants.h',
+ 'dom_distiller/core/url_utils_android.cc',
+ 'dom_distiller/core/url_utils_android.h',
'dom_distiller/core/url_utils.cc',
'dom_distiller/core/url_utils.h',
],
+ 'conditions': [
+ ['OS == "android"', {
+ 'dependencies': [
+ 'dom_distiller_core_jni_headers',
+ ],
+ }],
+ ],
},
{
'target_name': 'dom_distiller_test_support',
@@ -137,6 +148,32 @@
},
],
}],
+ ['OS=="android"', {
+ 'targets': [
+ {
+ 'target_name': 'dom_distiller_core_java',
+ 'type': 'none',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ ],
+ 'variables': {
+ 'java_in_dir': 'dom_distiller/android/java',
+ },
+ 'includes': [ '../build/java.gypi' ],
+ },
+ {
+ 'target_name': 'dom_distiller_core_jni_headers',
+ 'type': 'none',
+ 'sources': [
+ 'dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DomDistillerUrlUtils.java',
+ ],
+ 'variables': {
+ 'jni_gen_package': 'dom_distiller_core',
+ },
+ 'includes': [ '../build/jni_generator.gypi' ],
+ },
+ ],
+ }],
],
}],
],
diff --git a/components/dom_distiller/DEPS b/components/dom_distiller/DEPS
index cff0bf5..9a9f0f7 100644
--- a/components/dom_distiller/DEPS
+++ b/components/dom_distiller/DEPS
@@ -1,5 +1,6 @@
include_rules = [
"+grit", # For generated headers.
+ "+jni",
"+sync/api",
"+sync/protocol",
"+third_party/leveldatabase/src/include",
diff --git a/components/dom_distiller/android/component_jni_registrar.cc b/components/dom_distiller/android/component_jni_registrar.cc
new file mode 100644
index 0000000..a19e4d4
--- /dev/null
+++ b/components/dom_distiller/android/component_jni_registrar.cc
@@ -0,0 +1,29 @@
+// 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/android/component_jni_registrar.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_registrar.h"
+#include "base/basictypes.h"
+#include "components/dom_distiller/core/url_utils_android.h"
+
+namespace dom_distiller {
+
+namespace android {
+
+static base::android::RegistrationMethod kDomDistillerRegisteredMethods[] = {
+ {"DomDistillerUrlUtils",
+ dom_distiller::url_utils::android::RegisterUrlUtils}, };
+
+bool RegisterDomDistiller(JNIEnv* env) {
+ return base::android::RegisterNativeMethods(
+ env,
+ kDomDistillerRegisteredMethods,
+ arraysize(kDomDistillerRegisteredMethods));
+}
+
+} // namespace android
+
+} // namespace dom_distiller
diff --git a/components/dom_distiller/android/component_jni_registrar.h b/components/dom_distiller/android/component_jni_registrar.h
new file mode 100644
index 0000000..ace0035
--- /dev/null
+++ b/components/dom_distiller/android/component_jni_registrar.h
@@ -0,0 +1,21 @@
+// 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_ANDROID_COMPONENT_JNI_REGISTRAR_H
+#define COMPONENTS_DOM_DISTILLER_ANDROID_COMPONENT_JNI_REGISTRAR_H
+
+#include <jni.h>
+
+namespace dom_distiller {
+
+namespace android {
+
+// Register all JNI bindings necessary for the dom_distiller component.
+bool RegisterDomDistiller(JNIEnv* env);
+
+} // namespace android
+
+} // namespace dom_distiller
+
+#endif // COMPONENTS_DOM_DISTILLER_ANDROID_COMPONENT_JNI_REGISTRAR_H
diff --git a/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DomDistillerUrlUtils.java b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DomDistillerUrlUtils.java
new file mode 100644
index 0000000..598e299
--- /dev/null
+++ b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DomDistillerUrlUtils.java
@@ -0,0 +1,30 @@
+// 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::url_utils.
+ */
+@JNINamespace("dom_distiller::url_utils::android")
+public final class DomDistillerUrlUtils {
+
+ private DomDistillerUrlUtils() {
+ }
+
+ /**
+ * Returns the URL for viewing distilled content for a URL.
+ *
+ * @param scheme The scheme for the DOM Distiller source.
+ * @param url The URL to distill.
+ * @return the URL to load to get the distilled version of a page.
+ */
+ public static String getDistillerViewUrlFromUrl(String scheme, String url) {
+ return nativeGetDistillerViewUrlFromUrl(scheme, url);
+ }
+
+ private static native String nativeGetDistillerViewUrlFromUrl(String scheme, String url);
+}
diff --git a/components/dom_distiller/core/url_utils_android.cc b/components/dom_distiller/core/url_utils_android.cc
new file mode 100644
index 0000000..2f12d34
--- /dev/null
+++ b/components/dom_distiller/core/url_utils_android.cc
@@ -0,0 +1,43 @@
+// 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/url_utils_android.h"
+
+#include <string>
+
+#include "base/android/jni_string.h"
+#include "components/dom_distiller/core/url_utils.h"
+#include "jni/DomDistillerUrlUtils_jni.h"
+#include "url/gurl.h"
+
+namespace dom_distiller {
+
+namespace url_utils {
+
+namespace android {
+
+jstring GetDistillerViewUrlFromUrl(JNIEnv* env,
+ jclass clazz,
+ jstring j_scheme,
+ jstring j_url) {
+ std::string scheme(base::android::ConvertJavaStringToUTF8(env, j_scheme));
+ GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
+ if (!url.is_valid()) {
+ return NULL;
+ }
+ GURL view_url =
+ dom_distiller::url_utils::GetDistillerViewUrlFromUrl(scheme, url);
+ if (!view_url.is_valid()) {
+ return NULL;
+ }
+ return base::android::ConvertUTF8ToJavaString(env, view_url.spec()).Release();
+}
+
+bool RegisterUrlUtils(JNIEnv* env) { return RegisterNativesImpl(env); }
+
+} // namespace android
+
+} // namespace url_utils
+
+} // namespace dom_distiller
diff --git a/components/dom_distiller/core/url_utils_android.h b/components/dom_distiller/core/url_utils_android.h
new file mode 100644
index 0000000..46b3598
--- /dev/null
+++ b/components/dom_distiller/core/url_utils_android.h
@@ -0,0 +1,27 @@
+// 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_URL_UTILS_ANDROID_H
+#define COMPONENTS_DOM_DISTILLER_CORE_URL_UTILS_ANDROID_H
+
+#include <jni.h>
+
+#include <string>
+
+namespace dom_distiller {
+
+namespace url_utils {
+
+namespace android {
+
+// Register JNI methods
+bool RegisterUrlUtils(JNIEnv* env);
+
+} // namespace android
+
+} // namespace url_utils
+
+} // namespace dom_distiller
+
+#endif // COMPONENTS_DOM_DISTILLER_CORE_URL_UTILS_ANDROID_H