diff options
author | cjhopman <cjhopman@chromium.org> | 2015-04-10 18:19:53 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-11 01:21:00 +0000 |
commit | 066f2b8678771a00db9402c0774e4b942001220c (patch) | |
tree | 3ee37e63f0df1cd8f54a731435a2e79fde554526 /components | |
parent | f42e70932de69422378f3fef25df8afc4f2bb8e1 (diff) | |
download | chromium_src-066f2b8678771a00db9402c0774e4b942001220c.zip chromium_src-066f2b8678771a00db9402c0774e4b942001220c.tar.gz chromium_src-066f2b8678771a00db9402c0774e4b942001220c.tar.bz2 |
Add Java interface to IsDistillablePage
BUG=471439
Review URL: https://codereview.chromium.org/1049873004
Cr-Commit-Position: refs/heads/master@{#324740}
Diffstat (limited to 'components')
9 files changed, 178 insertions, 3 deletions
diff --git a/components/dom_distiller.gypi b/components/dom_distiller.gypi index 1a31ac2..69a1a4d 100644 --- a/components/dom_distiller.gypi +++ b/components/dom_distiller.gypi @@ -182,6 +182,8 @@ 'sources': [ 'dom_distiller/content/distillable_page_utils.cc', 'dom_distiller/content/distillable_page_utils.h', + 'dom_distiller/content/distillable_page_utils_android.cc', + 'dom_distiller/content/distillable_page_utils_android.h', 'dom_distiller/content/distiller_page_web_contents.cc', 'dom_distiller/content/distiller_page_web_contents.h', 'dom_distiller/content/dom_distiller_viewer_source.cc', @@ -189,6 +191,14 @@ 'dom_distiller/content/web_contents_main_frame_observer.cc', 'dom_distiller/content/web_contents_main_frame_observer.h', ], + 'conditions': [ + ['OS == "android"', { + 'dependencies': [ + 'dom_distiller_content_jni_headers', + 'dom_distiller_core_jni_headers', + ], + }], + ], }, ], }], @@ -217,13 +227,22 @@ ['OS=="android"', { 'targets': [ { - # GN: //components/dom_distiller/android:dom_distiller_core_java + # TODO(cjhopman): remove this when it is rolled downstream. 'target_name': 'dom_distiller_core_java', 'type': 'none', 'dependencies': [ + 'dom_distiller_java', + ], + }, + { + # GN: //components/dom_distiller/android:dom_distiller_java + 'target_name': 'dom_distiller_java', + 'type': 'none', + 'dependencies': [ 'dom_distiller_core_font_family_java', 'dom_distiller_core_theme_java', '../base/base.gyp:base', + '../content/content.gyp:content_java', ], 'variables': { 'java_in_dir': 'dom_distiller/android/java', @@ -244,6 +263,18 @@ 'includes': [ '../build/android/java_cpp_template.gypi' ], }, { + # GN: //components/dom_distiller/content:jni_headers + 'target_name': 'dom_distiller_content_jni_headers', + 'type': 'none', + 'sources': [ + 'dom_distiller/android/java/src/org/chromium/components/dom_distiller/content/DistillablePageUtils.java', + ], + 'variables': { + 'jni_gen_package': 'dom_distiller_content', + }, + 'includes': [ '../build/jni_generator.gypi' ], + }, + { # GN: //components/dom_distiller/core:jni_headers 'target_name': 'dom_distiller_core_jni_headers', 'type': 'none', diff --git a/components/dom_distiller/android/BUILD.gn b/components/dom_distiller/android/BUILD.gn index 3bda4e9..2cc4dc7 100644 --- a/components/dom_distiller/android/BUILD.gn +++ b/components/dom_distiller/android/BUILD.gn @@ -4,18 +4,29 @@ import("//build/config/android/rules.gni") -# GYP: //components/dom_distiller.gypi:dom_distiller_core_java android_library("dom_distiller_core_java") { deps = [ "//base:base_java", ] + java_files = [ + "java/src/org/chromium/components/dom_distiller/core/DomDistillerService.java", + "java/src/org/chromium/components/dom_distiller/core/DomDistillerUrlUtils.java", + "java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java", + ] srcjar_deps = [ ":dom_distiller_core_font_family_javagen", ":dom_distiller_core_theme_javagen", ] +} - DEPRECATED_java_in_dir = "java/src" +# GYP: //components/dom_distiller.gypi:dom_distiller_java +android_library("dom_distiller_content_java") { + deps = [ + ":dom_distiller_core_java", + "//content/public/android:content_java", + ] + java_files = [ "java/src/org/chromium/components/dom_distiller/content/DistillablePageUtils.java" ] } # GYP: //components/dom_distiller.gypi:dom_distiller_core_font_family_java diff --git a/components/dom_distiller/android/DEPS b/components/dom_distiller/android/DEPS new file mode 100644 index 0000000..54004a2 --- /dev/null +++ b/components/dom_distiller/android/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+components/dom_distiller", +] diff --git a/components/dom_distiller/android/component_jni_registrar.cc b/components/dom_distiller/android/component_jni_registrar.cc index f631a2d..2ea4b57 100644 --- a/components/dom_distiller/android/component_jni_registrar.cc +++ b/components/dom_distiller/android/component_jni_registrar.cc @@ -7,6 +7,7 @@ #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" #include "base/basictypes.h" +#include "components/dom_distiller/content/distillable_page_utils_android.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" @@ -20,6 +21,8 @@ static base::android::RegistrationMethod kDomDistillerRegisteredMethods[] = { {"DomDistillerService", DomDistillerServiceAndroid::Register}, {"DomDistillerUrlUtils", dom_distiller::url_utils::android::RegisterUrlUtils}, + {"DistillablePageUtils", + dom_distiller::android::RegisterDistillablePageUtils}, }; bool RegisterDomDistiller(JNIEnv* env) { diff --git a/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/content/DEPS b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/content/DEPS new file mode 100644 index 0000000..0d019e1 --- /dev/null +++ b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/content/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+content/public/android/java", +] diff --git a/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/content/DistillablePageUtils.java b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/content/DistillablePageUtils.java new file mode 100644 index 0000000..03e2a15 --- /dev/null +++ b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/content/DistillablePageUtils.java @@ -0,0 +1,37 @@ +// Copyright 2015 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.content; + +import org.chromium.base.CalledByNative; +import org.chromium.base.JNINamespace; +import org.chromium.content_public.browser.WebContents; + +/** + * Provides access to the native dom_distiller::IsPageDistillable function. + */ +@JNINamespace("dom_distiller::android") +public final class DistillablePageUtils { + /** + * Callback for handling the result of isPageDistillable. + */ + public static interface PageDistillableCallback { + public void onIsPageDistillableResult(boolean isDistillable); + } + + public static void isPageDistillable( + WebContents webContents, PageDistillableCallback callback) { + nativeIsPageDistillable(webContents, callback); + } + + @CalledByNative + private static void callOnIsPageDistillableResult( + PageDistillableCallback callback, boolean isDistillable) { + callback.onIsPageDistillableResult(isDistillable); + } + + private static native void nativeIsPageDistillable( + WebContents webContents, PageDistillableCallback callback); +} + diff --git a/components/dom_distiller/content/BUILD.gn b/components/dom_distiller/content/BUILD.gn index 61dd8e6..df9b5c0 100644 --- a/components/dom_distiller/content/BUILD.gn +++ b/components/dom_distiller/content/BUILD.gn @@ -30,5 +30,24 @@ if (!is_ios) { "//ui/gfx", "//url", ] + + if (is_android) { + sources += [ + "distillable_page_utils_android.cc", + "distillable_page_utils_android.h", + ] + deps += [ ":jni_headers" ] + } + } + + if (is_android) { + import("//build/config/android/rules.gni") + + generate_jni("jni_headers") { + sources = [ + "../android/java/src/org/chromium/components/dom_distiller/content/DistillablePageUtils.java", + ] + jni_package = "dom_distiller_content" + } } } diff --git a/components/dom_distiller/content/distillable_page_utils_android.cc b/components/dom_distiller/content/distillable_page_utils_android.cc new file mode 100644 index 0000000..6250398 --- /dev/null +++ b/components/dom_distiller/content/distillable_page_utils_android.cc @@ -0,0 +1,52 @@ +// Copyright 2015 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/content/distillable_page_utils_android.h" + +#include "base/bind.h" +#include "base/message_loop/message_loop.h" +#include "components/dom_distiller/content/distillable_page_utils.h" +#include "content/public/browser/web_contents.h" +#include "jni/DistillablePageUtils_jni.h" + +using base::android::ScopedJavaGlobalRef; + +namespace dom_distiller { +namespace android { +namespace { +void OnIsPageDistillableResult( + scoped_ptr<ScopedJavaGlobalRef<jobject>> callback_holder, + bool isDistillable) { + Java_DistillablePageUtils_callOnIsPageDistillableResult( + base::android::AttachCurrentThread(), callback_holder->obj(), + isDistillable); +} +} // namespace + +static void IsPageDistillable(JNIEnv* env, + jclass jcaller, + jobject webContents, + jobject callback) { + content::WebContents* web_contents( + content::WebContents::FromJavaWebContents(webContents)); + scoped_ptr<ScopedJavaGlobalRef<jobject>> callback_holder( + new ScopedJavaGlobalRef<jobject>()); + callback_holder->Reset(env, callback); + + if (!web_contents) { + base::MessageLoop::current()->PostTask( + FROM_HERE, base::Bind(OnIsPageDistillableResult, + base::Passed(&callback_holder), false)); + return; + } + IsDistillablePage(web_contents, base::Bind(OnIsPageDistillableResult, + base::Passed(&callback_holder))); +} + +bool RegisterDistillablePageUtils(JNIEnv* env) { + return RegisterNativesImpl(env); +} + +} +} diff --git a/components/dom_distiller/content/distillable_page_utils_android.h b/components/dom_distiller/content/distillable_page_utils_android.h new file mode 100644 index 0000000..ea75799 --- /dev/null +++ b/components/dom_distiller/content/distillable_page_utils_android.h @@ -0,0 +1,16 @@ +// Copyright 2015 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_CONTENT_DISTILLABLE_PAGE_UTILS_ANDROID_H_ +#define COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLABLE_PAGE_UTILS_ANDROID_H_ + +#include <jni.h> + +namespace dom_distiller { +namespace android { +bool RegisterDistillablePageUtils(JNIEnv* env); +} +} + +#endif // COMPONENTS_DOM_DISTILLER_CONTENT_DISTILLABLE_PAGE_UTILS_ANDROID_H_ |