OLD | NEW |
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 "content/browser/android/web_contents_observer_android.h" | 5 #include "content/browser/android/web_contents_observer_android.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include <jni.h> | 9 #include <jni.h> |
10 | 10 |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
13 #include "base/android/scoped_java_ref.h" | 13 #include "base/android/scoped_java_ref.h" |
14 #include "content/browser/android/content_view_core_impl.h" | |
15 #include "content/browser/renderer_host/render_widget_host_impl.h" | 14 #include "content/browser/renderer_host/render_widget_host_impl.h" |
16 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
17 #include "content/public/browser/navigation_details.h" | 16 #include "content/public/browser/navigation_details.h" |
18 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
19 #include "jni/WebContentsObserverAndroid_jni.h" | 18 #include "jni/WebContentsObserverAndroid_jni.h" |
20 | 19 |
21 using base::android::AttachCurrentThread; | 20 using base::android::AttachCurrentThread; |
22 using base::android::ScopedJavaLocalRef; | 21 using base::android::ScopedJavaLocalRef; |
23 using base::android::ConvertUTF8ToJavaString; | 22 using base::android::ConvertUTF8ToJavaString; |
24 using base::android::ConvertUTF16ToJavaString; | 23 using base::android::ConvertUTF16ToJavaString; |
25 | 24 |
26 namespace content { | 25 namespace content { |
27 | 26 |
28 WebContentsObserverAndroid::WebContentsObserverAndroid( | 27 WebContentsObserverAndroid::WebContentsObserverAndroid( |
29 JNIEnv* env, | 28 JNIEnv* env, |
30 jobject obj, | 29 jobject obj, |
31 WebContents* web_contents) | 30 WebContents* web_contents) |
32 : WebContentsObserver(web_contents), | 31 : WebContentsObserver(web_contents), |
33 weak_java_observer_(env, obj){ | 32 weak_java_observer_(env, obj){ |
34 } | 33 } |
35 | 34 |
36 WebContentsObserverAndroid::~WebContentsObserverAndroid() { | 35 WebContentsObserverAndroid::~WebContentsObserverAndroid() { |
37 } | 36 } |
38 | 37 |
39 jlong Init(JNIEnv* env, jobject obj, jlong native_content_view_core) { | 38 jlong Init(JNIEnv* env, jobject obj, jobject java_web_contents) { |
40 ContentViewCore* content_view_core = | 39 content::WebContents* web_contents = |
41 reinterpret_cast<ContentViewCore*>(native_content_view_core); | 40 content::WebContents::FromJavaWebContents(java_web_contents); |
| 41 CHECK(web_contents); |
| 42 |
42 WebContentsObserverAndroid* native_observer = new WebContentsObserverAndroid( | 43 WebContentsObserverAndroid* native_observer = new WebContentsObserverAndroid( |
43 env, obj, content_view_core->GetWebContents()); | 44 env, obj, web_contents); |
44 return reinterpret_cast<intptr_t>(native_observer); | 45 return reinterpret_cast<intptr_t>(native_observer); |
45 } | 46 } |
46 | 47 |
47 void WebContentsObserverAndroid::Destroy(JNIEnv* env, jobject obj) { | 48 void WebContentsObserverAndroid::Destroy(JNIEnv* env, jobject obj) { |
48 delete this; | 49 delete this; |
49 } | 50 } |
50 | 51 |
51 void WebContentsObserverAndroid::WebContentsDestroyed() { | 52 void WebContentsObserverAndroid::WebContentsDestroyed() { |
52 JNIEnv* env = AttachCurrentThread(); | 53 JNIEnv* env = AttachCurrentThread(); |
53 ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env)); | 54 ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env)); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 if (obj.is_null()) | 293 if (obj.is_null()) |
293 return; | 294 return; |
294 Java_WebContentsObserverAndroid_didFirstVisuallyNonEmptyPaint( | 295 Java_WebContentsObserverAndroid_didFirstVisuallyNonEmptyPaint( |
295 env, obj.obj()); | 296 env, obj.obj()); |
296 } | 297 } |
297 | 298 |
298 bool RegisterWebContentsObserverAndroid(JNIEnv* env) { | 299 bool RegisterWebContentsObserverAndroid(JNIEnv* env) { |
299 return RegisterNativesImpl(env); | 300 return RegisterNativesImpl(env); |
300 } | 301 } |
301 } // namespace content | 302 } // namespace content |
OLD | NEW |