| OLD | NEW |
| 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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "components/dom_distiller/content/browser/distillability_driver.h" |
| 9 #include "components/dom_distiller/content/browser/distillable_page_utils.h" | 10 #include "components/dom_distiller/content/browser/distillable_page_utils.h" |
| 10 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 11 #include "jni/DistillablePageUtils_jni.h" | 12 #include "jni/DistillablePageUtils_jni.h" |
| 12 | 13 |
| 13 using base::android::ScopedJavaGlobalRef; | 14 using base::android::ScopedJavaGlobalRef; |
| 14 | 15 |
| 15 namespace dom_distiller { | 16 namespace dom_distiller { |
| 16 namespace android { | 17 namespace android { |
| 17 namespace { | 18 namespace { |
| 18 void OnIsPageDistillableResult( | 19 void OnIsPageDistillableResult( |
| 19 scoped_ptr<ScopedJavaGlobalRef<jobject>> callback_holder, | 20 ScopedJavaGlobalRef<jobject>* callback_holder, |
| 20 bool isDistillable) { | 21 bool isDistillable, bool isLast) { |
| 21 Java_DistillablePageUtils_callOnIsPageDistillableResult( | 22 Java_DistillablePageUtils_callOnIsPageDistillableResult( |
| 22 base::android::AttachCurrentThread(), callback_holder->obj(), | 23 base::android::AttachCurrentThread(), callback_holder->obj(), |
| 23 isDistillable); | 24 isDistillable, isLast); |
| 24 } | 25 } |
| 25 } // namespace | 26 } // namespace |
| 26 | 27 |
| 27 static void IsPageDistillable(JNIEnv* env, | 28 static void SetCallback(JNIEnv* env, |
| 28 const JavaParamRef<jclass>& jcaller, | 29 const JavaParamRef<jclass>& jcaller, |
| 29 const JavaParamRef<jobject>& webContents, | 30 const JavaParamRef<jobject>& webContents, |
| 30 jboolean is_mobile_optimized, | |
| 31 const JavaParamRef<jobject>& callback) { | 31 const JavaParamRef<jobject>& callback) { |
| 32 content::WebContents* web_contents( | 32 content::WebContents* web_contents( |
| 33 content::WebContents::FromJavaWebContents(webContents)); | 33 content::WebContents::FromJavaWebContents(webContents)); |
| 34 scoped_ptr<ScopedJavaGlobalRef<jobject>> callback_holder( | 34 if (!web_contents) { |
| 35 return; |
| 36 } |
| 37 |
| 38 // FIXME(wychen): check memory management |
| 39 ScopedJavaGlobalRef<jobject>* callback_holder( |
| 35 new ScopedJavaGlobalRef<jobject>()); | 40 new ScopedJavaGlobalRef<jobject>()); |
| 36 callback_holder->Reset(env, callback); | 41 callback_holder->Reset(env, callback); |
| 37 | 42 |
| 38 if (!web_contents) { | 43 base::Callback<void(bool, bool)> cb = |
| 39 base::MessageLoop::current()->PostTask( | 44 base::Bind(OnIsPageDistillableResult, base::Owned(callback_holder)); |
| 40 FROM_HERE, base::Bind(OnIsPageDistillableResult, | 45 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 } | 46 } |
| 48 | 47 |
| 49 bool RegisterDistillablePageUtils(JNIEnv* env) { | 48 bool RegisterDistillablePageUtils(JNIEnv* env) { |
| 50 return RegisterNativesImpl(env); | 49 return RegisterNativesImpl(env); |
| 51 } | 50 } |
| 52 | 51 |
| 53 } | 52 } |
| 54 } | 53 } |
| OLD | NEW |