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