Don't preload rarely seen large images
[chromium-blink-merge.git] / components / dom_distiller / content / distillable_page_utils_android.cc
blobeac1f2473f6c0f605e19c137b29ee83a5a1d5788
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/dom_distiller/content/distillable_page_utils_android.h"
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "components/dom_distiller/content/distillable_page_utils.h"
10 #include "content/public/browser/web_contents.h"
11 #include "jni/DistillablePageUtils_jni.h"
13 using base::android::ScopedJavaGlobalRef;
15 namespace dom_distiller {
16 namespace android {
17 namespace {
18 void OnIsPageDistillableResult(
19 scoped_ptr<ScopedJavaGlobalRef<jobject>> callback_holder,
20 bool isDistillable) {
21 Java_DistillablePageUtils_callOnIsPageDistillableResult(
22 base::android::AttachCurrentThread(), callback_holder->obj(),
23 isDistillable);
25 } // namespace
27 static void IsPageDistillable(JNIEnv* env,
28 jclass jcaller,
29 jobject webContents,
30 jboolean is_mobile_optimized,
31 jobject callback) {
32 content::WebContents* web_contents(
33 content::WebContents::FromJavaWebContents(webContents));
34 scoped_ptr<ScopedJavaGlobalRef<jobject>> callback_holder(
35 new ScopedJavaGlobalRef<jobject>());
36 callback_holder->Reset(env, callback);
38 if (!web_contents) {
39 base::MessageLoop::current()->PostTask(
40 FROM_HERE, base::Bind(OnIsPageDistillableResult,
41 base::Passed(&callback_holder), false));
42 return;
44 IsDistillablePage(
45 web_contents, is_mobile_optimized,
46 base::Bind(OnIsPageDistillableResult, base::Passed(&callback_holder)));
49 bool RegisterDistillablePageUtils(JNIEnv* env) {
50 return RegisterNativesImpl(env);