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

Side by Side Diff: android_webview/native/aw_contents.cc

Issue 10890024: Implement DocuementHasImages (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "android_webview/native/aw_contents.h" 5 #include "android_webview/native/aw_contents.h"
6 6
7 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h"
7 #include "android_webview/native/aw_browser_dependency_factory.h" 8 #include "android_webview/native/aw_browser_dependency_factory.h"
8 #include "android_webview/native/aw_contents_container.h" 9 #include "android_webview/native/aw_contents_container.h"
9 #include "android_webview/native/aw_web_contents_delegate.h" 10 #include "android_webview/native/aw_web_contents_delegate.h"
10 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
11 #include "base/android/jni_string.h" 12 #include "base/android/jni_string.h"
13 #include "base/bind.h"
14 #include "base/callback.h"
12 #include "content/public/browser/android/content_view_core.h" 15 #include "content/public/browser/android/content_view_core.h"
13 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
14 #include "jni/AwContents_jni.h" 17 #include "jni/AwContents_jni.h"
15 18
16 using base::android::AttachCurrentThread; 19 using base::android::AttachCurrentThread;
17 using base::android::ConvertUTF16ToJavaString; 20 using base::android::ConvertUTF16ToJavaString;
21 using base::android::ScopedJavaGlobalRef;
22 using base::android::ScopedJavaLocalRef;
18 using content::ContentViewCore; 23 using content::ContentViewCore;
19 using content::WebContents; 24 using content::WebContents;
20 25
21 namespace android_webview { 26 namespace android_webview {
22 27
28 namespace {
29
30 // |message| is passed as base::Owned, so it will automatically be deleted
31 // when the callback goes out of scope.
32 void DocumentHasImagesCallback(ScopedJavaGlobalRef<jobject>* message,
33 bool has_images) {
34 Java_AwContents_onDocumentHasImagesResponse(AttachCurrentThread(),
35 has_images,
36 message->obj());
37 }
38
39 } // namespace
40
23 AwContents::AwContents(JNIEnv* env, 41 AwContents::AwContents(JNIEnv* env,
24 jobject obj, 42 jobject obj,
25 jobject web_contents_delegate, 43 jobject web_contents_delegate,
26 bool private_browsing) 44 bool private_browsing)
27 : java_ref_(env, obj), 45 : java_ref_(env, obj),
28 web_contents_delegate_( 46 web_contents_delegate_(
29 new AwWebContentsDelegate(env, web_contents_delegate)) { 47 new AwWebContentsDelegate(env, web_contents_delegate)) {
30 android_webview::AwBrowserDependencyFactory* dependency_factory = 48 android_webview::AwBrowserDependencyFactory* dependency_factory =
31 android_webview::AwBrowserDependencyFactory::GetInstance(); 49 android_webview::AwBrowserDependencyFactory::GetInstance();
32 content::WebContents* web_contents = 50 content::WebContents* web_contents =
33 dependency_factory->CreateWebContents(private_browsing); 51 dependency_factory->CreateWebContents(private_browsing);
34 contents_container_.reset(dependency_factory->CreateContentsContainer( 52 contents_container_.reset(dependency_factory->CreateContentsContainer(
35 web_contents)); 53 web_contents));
36 web_contents->SetDelegate(web_contents_delegate_.get()); 54 web_contents->SetDelegate(web_contents_delegate_.get());
37 web_contents_delegate_->SetJavaScriptDialogCreator( 55 web_contents_delegate_->SetJavaScriptDialogCreator(
38 dependency_factory->GetJavaScriptDialogCreator()); 56 dependency_factory->GetJavaScriptDialogCreator());
57 render_view_host_ext_.reset(new AwRenderViewHostExt(web_contents));
39 } 58 }
40 59
41 AwContents::~AwContents() { 60 AwContents::~AwContents() {
42 } 61 }
43 62
44 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { 63 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) {
45 return reinterpret_cast<jint>(contents_container_->GetWebContents()); 64 return reinterpret_cast<jint>(contents_container_->GetWebContents());
46 } 65 }
47 66
48 void AwContents::Destroy(JNIEnv* env, jobject obj) { 67 void AwContents::Destroy(JNIEnv* env, jobject obj) {
49 delete this; 68 delete this;
50 } 69 }
51 70
71 void AwContents::DocumentHasImages(JNIEnv* env, jobject obj, jobject message) {
72 render_view_host_ext_->DocumentHasImages(
73 base::Bind(&DocumentHasImagesCallback,
74 base::Owned(new ScopedJavaGlobalRef<jobject>(
75 ScopedJavaLocalRef<jobject>(env, message)))));
76 }
77
52 static jint Init(JNIEnv* env, 78 static jint Init(JNIEnv* env,
53 jobject obj, 79 jobject obj,
54 jobject web_contents_delegate, 80 jobject web_contents_delegate,
55 jboolean private_browsing) { 81 jboolean private_browsing) {
56 AwContents* tab = new AwContents(env, obj, web_contents_delegate, 82 AwContents* tab = new AwContents(env, obj, web_contents_delegate,
57 private_browsing); 83 private_browsing);
58 return reinterpret_cast<jint>(tab); 84 return reinterpret_cast<jint>(tab);
59 } 85 }
60 86
61 bool RegisterAwContents(JNIEnv* env) { 87 bool RegisterAwContents(JNIEnv* env) {
62 return RegisterNativesImpl(env) >= 0; 88 return RegisterNativesImpl(env) >= 0;
63 } 89 }
64 90
65 91
66 } // namespace android_webview 92 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698