Commit ad35a60c authored by nyquist@chromium.org's avatar nyquist@chromium.org

Add UI hook for distilling web pages for test shell (relanding)

This adds the Java hooks needed and a menu option to distill the current
web page in the test shell.

Original CL: https://codereview.chromium.org/185113002/

BUG=319881

Review URL: https://codereview.chromium.org/183893029

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255369 0039d316-1c4b-4281-b951-d872f2087c98
parent 409ab6d5
include_rules = [
"+chrome/app",
"+chrome/browser",
"+components/dom_distiller/android/java",
"+content/public/android",
"+content/public/browser",
"+content/public/browser/android",
......
......@@ -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 ChromeShellActivity extends Activity implements AppMenuPropertiesDelegate {
private static final String TAG = "ChromeShellActivity";
private static final String CHROME_DISTILLER_SCHEME = "chrome-distiller";
private WindowAndroid mWindow;
private TabManager mTabManager;
......@@ -233,6 +235,12 @@ public class ChromeShellActivity extends Activity implements AppMenuPropertiesDe
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 ChromeShellActivity extends Activity implements AppMenuPropertiesDe
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);
}
......
// 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";
}
......@@ -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"
......
......@@ -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>
......@@ -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",
......
......@@ -995,6 +995,7 @@
'toolbar_model_security_levels_java',
'../base/base.gyp:base',
'../components/components.gyp:autofill_java',
'../components/components.gyp:dom_distiller_core_java',
'../components/components.gyp:navigation_interception_java',
'../components/components.gyp:sessions',
'../components/components.gyp:web_contents_delegate_android_java',
......
......@@ -49,10 +49,10 @@
'target_name': 'chromium_testshell',
'type': 'none',
'dependencies': [
'../media/media.gyp:media_java',
'chrome.gyp:chrome_java',
'chrome_java',
'chromium_testshell_paks',
'libchromiumtestshell',
'../media/media.gyp:media_java',
],
'variables': {
'apk_name': 'ChromiumTestShell',
......
......@@ -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' ],
},
],
}],
],
}],
],
......
include_rules = [
"+grit", # For generated headers.
"+jni",
"+sync/api",
"+sync/protocol",
"+third_party/leveldatabase/src/include",
......
// 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
// 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
// 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);
}
// 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
// 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment