| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 Java_WebContentsObserverAndroid_didStartLoading( | 83 Java_WebContentsObserverAndroid_didStartLoading( |
| 84 env, obj.obj(), jstring_url.obj()); | 84 env, obj.obj(), jstring_url.obj()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void WebContentsObserverAndroid::DidStopLoading( | 87 void WebContentsObserverAndroid::DidStopLoading( |
| 88 RenderViewHost* render_view_host) { | 88 RenderViewHost* render_view_host) { |
| 89 JNIEnv* env = AttachCurrentThread(); | 89 JNIEnv* env = AttachCurrentThread(); |
| 90 ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env)); | 90 ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env)); |
| 91 if (obj.is_null()) | 91 if (obj.is_null()) |
| 92 return; | 92 return; |
| 93 | 93 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString( |
| 94 std::string url_string; | 94 env, web_contents()->GetLastCommittedURL().spec())); |
| 95 NavigationEntry* entry = | |
| 96 web_contents()->GetController().GetLastCommittedEntry(); | |
| 97 // Not that GetBaseURLForDataURL is only used by the Android WebView | |
| 98 if (entry && !entry->GetBaseURLForDataURL().is_empty()) { | |
| 99 url_string = entry->GetBaseURLForDataURL().possibly_invalid_spec(); | |
| 100 } else { | |
| 101 url_string = web_contents()->GetLastCommittedURL().spec(); | |
| 102 } | |
| 103 | |
| 104 ScopedJavaLocalRef<jstring> jstring_url( | |
| 105 ConvertUTF8ToJavaString(env, url_string)); | |
| 106 Java_WebContentsObserverAndroid_didStopLoading( | 95 Java_WebContentsObserverAndroid_didStopLoading( |
| 107 env, obj.obj(), jstring_url.obj()); | 96 env, obj.obj(), jstring_url.obj()); |
| 108 } | 97 } |
| 109 | 98 |
| 110 void WebContentsObserverAndroid::DidFailProvisionalLoad( | 99 void WebContentsObserverAndroid::DidFailProvisionalLoad( |
| 111 int64 frame_id, | 100 int64 frame_id, |
| 112 const string16& frame_unique_name, | 101 const string16& frame_unique_name, |
| 113 bool is_main_frame, | 102 bool is_main_frame, |
| 114 const GURL& validated_url, | 103 const GURL& validated_url, |
| 115 int error_code, | 104 int error_code, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 193 |
| 205 void WebContentsObserverAndroid::DidFinishLoad( | 194 void WebContentsObserverAndroid::DidFinishLoad( |
| 206 int64 frame_id, | 195 int64 frame_id, |
| 207 const GURL& validated_url, | 196 const GURL& validated_url, |
| 208 bool is_main_frame, | 197 bool is_main_frame, |
| 209 RenderViewHost* render_view_host) { | 198 RenderViewHost* render_view_host) { |
| 210 JNIEnv* env = AttachCurrentThread(); | 199 JNIEnv* env = AttachCurrentThread(); |
| 211 ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env)); | 200 ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env)); |
| 212 if (obj.is_null()) | 201 if (obj.is_null()) |
| 213 return; | 202 return; |
| 203 |
| 204 std::string url_string = validated_url.spec(); |
| 205 NavigationEntry* entry = |
| 206 web_contents()->GetController().GetLastCommittedEntry(); |
| 207 // Note that GetBaseURLForDataURL is only used by the Android WebView. |
| 208 if (entry && !entry->GetBaseURLForDataURL().is_empty()) |
| 209 url_string = entry->GetBaseURLForDataURL().possibly_invalid_spec(); |
| 210 |
| 214 ScopedJavaLocalRef<jstring> jstring_url( | 211 ScopedJavaLocalRef<jstring> jstring_url( |
| 215 ConvertUTF8ToJavaString(env, validated_url.spec())); | 212 ConvertUTF8ToJavaString(env, url_string)); |
| 216 Java_WebContentsObserverAndroid_didFinishLoad( | 213 Java_WebContentsObserverAndroid_didFinishLoad( |
| 217 env, obj.obj(), frame_id, jstring_url.obj(), is_main_frame); | 214 env, obj.obj(), frame_id, jstring_url.obj(), is_main_frame); |
| 218 } | 215 } |
| 219 | 216 |
| 220 void WebContentsObserverAndroid::NavigationEntryCommitted( | 217 void WebContentsObserverAndroid::NavigationEntryCommitted( |
| 221 const LoadCommittedDetails& load_details) { | 218 const LoadCommittedDetails& load_details) { |
| 222 JNIEnv* env = AttachCurrentThread(); | 219 JNIEnv* env = AttachCurrentThread(); |
| 223 ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env)); | 220 ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env)); |
| 224 if (obj.is_null()) | 221 if (obj.is_null()) |
| 225 return; | 222 return; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 is_provisional_load, | 267 is_provisional_load, |
| 271 is_main_frame, | 268 is_main_frame, |
| 272 error_code, | 269 error_code, |
| 273 jstring_error_description.obj(), jstring_url.obj()); | 270 jstring_error_description.obj(), jstring_url.obj()); |
| 274 } | 271 } |
| 275 | 272 |
| 276 bool RegisterWebContentsObserverAndroid(JNIEnv* env) { | 273 bool RegisterWebContentsObserverAndroid(JNIEnv* env) { |
| 277 return RegisterNativesImpl(env); | 274 return RegisterNativesImpl(env); |
| 278 } | 275 } |
| 279 } // namespace content | 276 } // namespace content |
| OLD | NEW |