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

Side by Side Diff: content/browser/android/web_contents_observer_proxy.cc

Issue 1799973002: Store and use last base URL between DidStart / DidStopLoading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 9 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
« no previous file with comments | « content/browser/android/web_contents_observer_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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()) {
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 // DidStopLoading is the last event we should get.
109 base_url_of_last_started_data_url_ = GURL::EmptyGURL();
105 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString( 110 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString(
106 env, url_string)); 111 env, url_string));
107 Java_WebContentsObserverProxy_didStopLoading(env, obj.obj(), 112 Java_WebContentsObserverProxy_didStopLoading(env, obj.obj(),
108 jstring_url.obj()); 113 jstring_url.obj());
109 } 114 }
110 115
111 void WebContentsObserverProxy::DidFailProvisionalLoad( 116 void WebContentsObserverProxy::DidFailProvisionalLoad(
112 RenderFrameHost* render_frame_host, 117 RenderFrameHost* render_frame_host,
113 const GURL& validated_url, 118 const GURL& validated_url,
114 int error_code, 119 int error_code,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 315
311 Java_WebContentsObserverProxy_mediaSessionStateChanged( 316 Java_WebContentsObserverProxy_mediaSessionStateChanged(
312 env, obj.obj(), is_controllable, is_suspended); 317 env, obj.obj(), is_controllable, is_suspended);
313 } 318 }
314 319
315 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded( 320 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded(
316 std::string* url) { 321 std::string* url) {
317 NavigationEntry* entry = 322 NavigationEntry* entry =
318 web_contents()->GetController().GetLastCommittedEntry(); 323 web_contents()->GetController().GetLastCommittedEntry();
319 // Note that GetBaseURLForDataURL is only used by the Android WebView. 324 // Note that GetBaseURLForDataURL is only used by the Android WebView.
320 if (entry && !entry->GetBaseURLForDataURL().is_empty()) 325 // FIXME: Should we only return valid specs and "about:blank" for invalid
326 // ones? This may break apps.
327 if (entry && !entry->GetBaseURLForDataURL().is_empty()) {
321 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); 328 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec();
329 } else if (!base_url_of_last_started_data_url_.is_empty()) {
330 // NavigationController can lose the pending entry and recreate it without
331 // a base URL if there has been a loadUrl("javascript:...") after
332 // loadDataWithBaseUrl.
333 *url = base_url_of_last_started_data_url_.possibly_invalid_spec();
334 }
322 } 335 }
323 336
324 bool RegisterWebContentsObserverProxy(JNIEnv* env) { 337 bool RegisterWebContentsObserverProxy(JNIEnv* env) {
325 return RegisterNativesImpl(env); 338 return RegisterNativesImpl(env);
326 } 339 }
327 } // namespace content 340 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/web_contents_observer_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698