Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: components/dom_distiller/content/browser/distillable_page_utils_android.cc

Issue 1248643004: Test distillability without JavaScript (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@early
Patch Set: draft (WIP) Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/dom_distiller/content/browser/distillable_page_utils_androi d.h" 5 #include "components/dom_distiller/content/browser/distillable_page_utils_androi d.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "components/dom_distiller/content/browser/distillability_driver.h"
9 #include "components/dom_distiller/content/browser/distillable_page_utils.h" 11 #include "components/dom_distiller/content/browser/distillable_page_utils.h"
10 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
11 #include "jni/DistillablePageUtils_jni.h" 13 #include "jni/DistillablePageUtils_jni.h"
12 14
13 using base::android::ScopedJavaGlobalRef; 15 using base::android::ScopedJavaGlobalRef;
14 16
15 namespace dom_distiller { 17 namespace dom_distiller {
16 namespace android { 18 namespace android {
17 namespace { 19 namespace {
18 void OnIsPageDistillableResult( 20 void OnIsPageDistillableResult(
19 scoped_ptr<ScopedJavaGlobalRef<jobject>> callback_holder, 21 ScopedJavaGlobalRef<jobject>* callback_holder,
20 bool isDistillable) { 22 bool isDistillable, bool isLast) {
23 LOG(ERROR) << "ReaderMode OnIsPageDistillableResult";
21 Java_DistillablePageUtils_callOnIsPageDistillableResult( 24 Java_DistillablePageUtils_callOnIsPageDistillableResult(
22 base::android::AttachCurrentThread(), callback_holder->obj(), 25 base::android::AttachCurrentThread(), callback_holder->obj(),
23 isDistillable); 26 isDistillable, isLast);
24 } 27 }
25 } // namespace 28 } // namespace
26 29
27 static void IsPageDistillable(JNIEnv* env, 30 static void SetCallback(JNIEnv* env,
28 const JavaParamRef<jclass>& jcaller, 31 const JavaParamRef<jclass>& jcaller,
29 const JavaParamRef<jobject>& webContents, 32 const JavaParamRef<jobject>& webContents,
30 jboolean is_mobile_optimized,
31 const JavaParamRef<jobject>& callback) { 33 const JavaParamRef<jobject>& callback) {
32 content::WebContents* web_contents( 34 content::WebContents* web_contents(
33 content::WebContents::FromJavaWebContents(webContents)); 35 content::WebContents::FromJavaWebContents(webContents));
34 scoped_ptr<ScopedJavaGlobalRef<jobject>> callback_holder( 36 if (!web_contents) {
37 return;
38 }
39 LOG(ERROR) << "ReaderMode SetCallback";
40
41 // FIXME(wychen): check memory management
42 ScopedJavaGlobalRef<jobject>* callback_holder(
35 new ScopedJavaGlobalRef<jobject>()); 43 new ScopedJavaGlobalRef<jobject>());
36 callback_holder->Reset(env, callback); 44 callback_holder->Reset(env, callback);
37 45
38 if (!web_contents) { 46 base::Callback<void(bool, bool)> cb =
39 base::MessageLoop::current()->PostTask( 47 base::Bind(OnIsPageDistillableResult, base::Owned(callback_holder));
40 FROM_HERE, base::Bind(OnIsPageDistillableResult, 48 setCallback(web_contents, cb);
41 base::Passed(&callback_holder), false));
42 return;
43 }
44 IsDistillablePage(
45 web_contents, is_mobile_optimized,
46 base::Bind(OnIsPageDistillableResult, base::Passed(&callback_holder)));
47 } 49 }
48 50
49 bool RegisterDistillablePageUtils(JNIEnv* env) { 51 bool RegisterDistillablePageUtils(JNIEnv* env) {
50 return RegisterNativesImpl(env); 52 return RegisterNativesImpl(env);
51 } 53 }
52 54
53 } 55 }
54 } 56 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698