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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 JNIEnv* env, | 28 JNIEnv* env, |
29 jobject obj, | 29 jobject obj, |
30 WebContents* web_contents) | 30 WebContents* web_contents) |
31 : WebContentsObserver(web_contents), | 31 : WebContentsObserver(web_contents), |
32 weak_java_observer_(env, obj){ | 32 weak_java_observer_(env, obj){ |
33 } | 33 } |
34 | 34 |
35 WebContentsObserverAndroid::~WebContentsObserverAndroid() { | 35 WebContentsObserverAndroid::~WebContentsObserverAndroid() { |
36 } | 36 } |
37 | 37 |
38 jint Init(JNIEnv* env, jobject obj, jint native_content_view_core) { | 38 jint Init(JNIEnv* env, jobject obj, jint native_web_contents) { |
39 ContentViewCore* content_view_core = | 39 WebContents* web_contents = |
40 reinterpret_cast<ContentViewCore*>(native_content_view_core); | 40 reinterpret_cast<WebContents*>(native_web_contents); |
41 WebContentsObserverAndroid* native_observer = new WebContentsObserverAndroid( | 41 WebContentsObserverAndroid* native_observer = new WebContentsObserverAndroid( |
42 env, obj, content_view_core->GetWebContents()); | 42 env, obj, web_contents); |
43 return reinterpret_cast<jint>(native_observer); | 43 return reinterpret_cast<jint>(native_observer); |
44 } | 44 } |
45 | 45 |
46 void WebContentsObserverAndroid::Destroy(JNIEnv* env, jobject obj) { | 46 void WebContentsObserverAndroid::Destroy(JNIEnv* env, jobject obj) { |
47 delete this; | 47 delete this; |
48 } | 48 } |
49 | 49 |
50 void WebContentsObserverAndroid::WebContentsDestroyed( | 50 void WebContentsObserverAndroid::WebContentsDestroyed( |
51 WebContents* web_contents) { | 51 WebContents* web_contents) { |
52 JNIEnv* env = AttachCurrentThread(); | 52 JNIEnv* env = AttachCurrentThread(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 int64 frame_id, | 98 int64 frame_id, |
99 const GURL& validated_url, | 99 const GURL& validated_url, |
100 bool is_main_frame, | 100 bool is_main_frame, |
101 int error_code, | 101 int error_code, |
102 const string16& error_description, | 102 const string16& error_description, |
103 RenderViewHost* render_view_host) { | 103 RenderViewHost* render_view_host) { |
104 DidFailLoadInternal( | 104 DidFailLoadInternal( |
105 false, is_main_frame, error_code, error_description, validated_url); | 105 false, is_main_frame, error_code, error_description, validated_url); |
106 } | 106 } |
107 | 107 |
108 void WebContentsObserverAndroid::DidNavigateMainFrame( | |
109 const LoadCommittedDetails& details, | |
110 const FrameNavigateParams& params) { | |
111 JNIEnv* env = AttachCurrentThread(); | |
112 ScopedJavaLocalRef<jobject> obj = weak_java_observer_.get(env); | |
113 if (obj.is_null()) | |
114 return; | |
115 ScopedJavaLocalRef<jstring> jstring_url = | |
116 ConvertUTF8ToJavaString(env, params.url.spec()); | |
117 ScopedJavaLocalRef<jstring> jstring_base_url = | |
118 ConvertUTF8ToJavaString(env, params.base_url.spec()); | |
119 Java_WebContentsObserverAndroid_didNavigateMainFrame( | |
120 env, obj.obj(), jstring_url.obj(), jstring_base_url.obj()); | |
121 } | |
122 | |
123 void WebContentsObserverAndroid::DidFailLoadInternal( | 108 void WebContentsObserverAndroid::DidFailLoadInternal( |
124 bool is_provisional_load, | 109 bool is_provisional_load, |
125 bool is_main_frame, | 110 bool is_main_frame, |
126 int error_code, | 111 int error_code, |
127 const string16& description, | 112 const string16& description, |
128 const GURL& url) { | 113 const GURL& url) { |
129 JNIEnv* env = AttachCurrentThread(); | 114 JNIEnv* env = AttachCurrentThread(); |
130 ScopedJavaLocalRef<jobject> obj = weak_java_observer_.get(env); | 115 ScopedJavaLocalRef<jobject> obj = weak_java_observer_.get(env); |
131 if (obj.is_null()) | 116 if (obj.is_null()) |
132 return; | 117 return; |
(...skipping 11 matching lines...) Expand all Loading... |
144 } | 129 } |
145 | 130 |
146 bool RegisterWebContentsObserverAndroid(JNIEnv* env) { | 131 bool RegisterWebContentsObserverAndroid(JNIEnv* env) { |
147 if (!HasClass(env, kWebContentsObserverAndroidClassPath)) { | 132 if (!HasClass(env, kWebContentsObserverAndroidClassPath)) { |
148 DLOG(ERROR) << "Unable to find class WebContentsObserverAndroid!"; | 133 DLOG(ERROR) << "Unable to find class WebContentsObserverAndroid!"; |
149 return false; | 134 return false; |
150 } | 135 } |
151 return RegisterNativesImpl(env); | 136 return RegisterNativesImpl(env); |
152 } | 137 } |
153 } // namespace content | 138 } // namespace content |
OLD | NEW |