Chromium Code Reviews| 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 "content/browser/android/web_contents_observer_proxy.h" | 5 #include "content/browser/android/web_contents_observer_proxy.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 Java_WebContentsObserverProxy_didFinishNavigation( | 86 Java_WebContentsObserverProxy_didFinishNavigation( |
| 87 env, obj.obj(), navigation_handle->IsInMainFrame(), | 87 env, obj.obj(), navigation_handle->IsInMainFrame(), |
| 88 navigation_handle->IsErrorPage(), navigation_handle->HasCommitted()); | 88 navigation_handle->IsErrorPage(), navigation_handle->HasCommitted()); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void WebContentsObserverProxy::DidStartLoading() { | 91 void WebContentsObserverProxy::DidStartLoading() { |
| 92 JNIEnv* env = AttachCurrentThread(); | 92 JNIEnv* env = AttachCurrentThread(); |
| 93 ScopedJavaLocalRef<jobject> obj(java_observer_); | 93 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 94 ScopedJavaLocalRef<jstring> jstring_url( | 94 ScopedJavaLocalRef<jstring> jstring_url( |
| 95 ConvertUTF8ToJavaString(env, web_contents()->GetVisibleURL().spec())); | 95 ConvertUTF8ToJavaString(env, web_contents()->GetVisibleURL().spec())); |
| 96 if (auto entry = web_contents()->GetController().GetPendingEntry()) { | |
|
boliu
2016/03/14 18:34:04
auto* ? Actually style guide doesn't really say an
mnaganov (inactive)
2016/03/14 20:10:57
I don't think it makes any difference here.
| |
| 97 base_url_of_last_started_data_url_ = entry->GetBaseURLForDataURL(); | |
| 98 } | |
| 96 Java_WebContentsObserverProxy_didStartLoading(env, obj.obj(), | 99 Java_WebContentsObserverProxy_didStartLoading(env, obj.obj(), |
| 97 jstring_url.obj()); | 100 jstring_url.obj()); |
| 98 } | 101 } |
| 99 | 102 |
| 100 void WebContentsObserverProxy::DidStopLoading() { | 103 void WebContentsObserverProxy::DidStopLoading() { |
| 101 JNIEnv* env = AttachCurrentThread(); | 104 JNIEnv* env = AttachCurrentThread(); |
| 102 ScopedJavaLocalRef<jobject> obj(java_observer_); | 105 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 103 std::string url_string = web_contents()->GetLastCommittedURL().spec(); | 106 std::string url_string = web_contents()->GetLastCommittedURL().spec(); |
| 104 SetToBaseURLForDataURLIfNeeded(&url_string); | 107 SetToBaseURLForDataURLIfNeeded(&url_string); |
| 108 base_url_of_last_started_data_url_ = GURL::EmptyGURL(); | |
| 105 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString( | 109 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString( |
| 106 env, url_string)); | 110 env, url_string)); |
| 107 Java_WebContentsObserverProxy_didStopLoading(env, obj.obj(), | 111 Java_WebContentsObserverProxy_didStopLoading(env, obj.obj(), |
| 108 jstring_url.obj()); | 112 jstring_url.obj()); |
| 109 } | 113 } |
| 110 | 114 |
| 111 void WebContentsObserverProxy::DidFailProvisionalLoad( | 115 void WebContentsObserverProxy::DidFailProvisionalLoad( |
| 112 RenderFrameHost* render_frame_host, | 116 RenderFrameHost* render_frame_host, |
| 113 const GURL& validated_url, | 117 const GURL& validated_url, |
| 114 int error_code, | 118 int error_code, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 env, obj.obj(), render_frame_host->GetRoutingID(), | 218 env, obj.obj(), render_frame_host->GetRoutingID(), |
| 215 !render_frame_host->GetParent(), jstring_url.obj(), transition_type); | 219 !render_frame_host->GetParent(), jstring_url.obj(), transition_type); |
| 216 } | 220 } |
| 217 | 221 |
| 218 void WebContentsObserverProxy::DidFinishLoad(RenderFrameHost* render_frame_host, | 222 void WebContentsObserverProxy::DidFinishLoad(RenderFrameHost* render_frame_host, |
| 219 const GURL& validated_url) { | 223 const GURL& validated_url) { |
| 220 JNIEnv* env = AttachCurrentThread(); | 224 JNIEnv* env = AttachCurrentThread(); |
| 221 ScopedJavaLocalRef<jobject> obj(java_observer_); | 225 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 222 | 226 |
| 223 std::string url_string = validated_url.spec(); | 227 std::string url_string = validated_url.spec(); |
| 224 SetToBaseURLForDataURLIfNeeded(&url_string); | 228 SetToBaseURLForDataURLIfNeeded(&url_string); |
|
boliu
2016/03/14 18:34:04
so iiuc DidFinishLoad is actually fired *between*
mnaganov (inactive)
2016/03/14 20:10:57
For a long time actually. See the description of h
boliu
2016/03/14 20:24:53
I mean that comment should live around where base_
mnaganov (inactive)
2016/03/14 20:28:51
Done.
| |
| 225 | 229 |
| 226 ScopedJavaLocalRef<jstring> jstring_url( | 230 ScopedJavaLocalRef<jstring> jstring_url( |
| 227 ConvertUTF8ToJavaString(env, url_string)); | 231 ConvertUTF8ToJavaString(env, url_string)); |
| 228 Java_WebContentsObserverProxy_didFinishLoad( | 232 Java_WebContentsObserverProxy_didFinishLoad( |
| 229 env, obj.obj(), render_frame_host->GetRoutingID(), jstring_url.obj(), | 233 env, obj.obj(), render_frame_host->GetRoutingID(), jstring_url.obj(), |
| 230 !render_frame_host->GetParent()); | 234 !render_frame_host->GetParent()); |
| 231 } | 235 } |
| 232 | 236 |
| 233 void WebContentsObserverProxy::DocumentLoadedInFrame( | 237 void WebContentsObserverProxy::DocumentLoadedInFrame( |
| 234 RenderFrameHost* render_frame_host) { | 238 RenderFrameHost* render_frame_host) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 | 314 |
| 311 Java_WebContentsObserverProxy_mediaSessionStateChanged( | 315 Java_WebContentsObserverProxy_mediaSessionStateChanged( |
| 312 env, obj.obj(), is_controllable, is_suspended); | 316 env, obj.obj(), is_controllable, is_suspended); |
| 313 } | 317 } |
| 314 | 318 |
| 315 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded( | 319 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded( |
| 316 std::string* url) { | 320 std::string* url) { |
| 317 NavigationEntry* entry = | 321 NavigationEntry* entry = |
| 318 web_contents()->GetController().GetLastCommittedEntry(); | 322 web_contents()->GetController().GetLastCommittedEntry(); |
| 319 // Note that GetBaseURLForDataURL is only used by the Android WebView. | 323 // Note that GetBaseURLForDataURL is only used by the Android WebView. |
| 320 if (entry && !entry->GetBaseURLForDataURL().is_empty()) | 324 if (entry && !entry->GetBaseURLForDataURL().is_empty()) { |
| 321 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); | 325 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); |
| 326 } else if (!base_url_of_last_started_data_url_.is_empty()) { | |
| 327 // NavigationController can lose the pending entry and recreate it without | |
| 328 // a base URL if there has been a loadUrl("javascript:...") after | |
| 329 // loadDataWithBaseUrl. | |
| 330 *url = base_url_of_last_started_data_url_.possibly_invalid_spec(); | |
| 331 } | |
| 322 } | 332 } |
| 323 | 333 |
| 324 bool RegisterWebContentsObserverProxy(JNIEnv* env) { | 334 bool RegisterWebContentsObserverProxy(JNIEnv* env) { |
| 325 return RegisterNativesImpl(env); | 335 return RegisterNativesImpl(env); |
| 326 } | 336 } |
| 327 } // namespace content | 337 } // namespace content |
| OLD | NEW |