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

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

Issue 1806853005: Store and use last base URL between DidStart / DidStopLoading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2623
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 termination_status == base::TERMINATION_STATUS_OOM_PROTECTED; 74 termination_status == base::TERMINATION_STATUS_OOM_PROTECTED;
75 Java_WebContentsObserverProxy_renderProcessGone(env, obj.obj(), 75 Java_WebContentsObserverProxy_renderProcessGone(env, obj.obj(),
76 was_oom_protected); 76 was_oom_protected);
77 } 77 }
78 78
79 void WebContentsObserverProxy::DidStartLoading() { 79 void WebContentsObserverProxy::DidStartLoading() {
80 JNIEnv* env = AttachCurrentThread(); 80 JNIEnv* env = AttachCurrentThread();
81 ScopedJavaLocalRef<jobject> obj(java_observer_); 81 ScopedJavaLocalRef<jobject> obj(java_observer_);
82 ScopedJavaLocalRef<jstring> jstring_url( 82 ScopedJavaLocalRef<jstring> jstring_url(
83 ConvertUTF8ToJavaString(env, web_contents()->GetVisibleURL().spec())); 83 ConvertUTF8ToJavaString(env, web_contents()->GetVisibleURL().spec()));
84 if (auto entry = web_contents()->GetController().GetPendingEntry()) {
85 base_url_of_last_started_data_url_ = entry->GetBaseURLForDataURL();
86 }
84 Java_WebContentsObserverProxy_didStartLoading(env, obj.obj(), 87 Java_WebContentsObserverProxy_didStartLoading(env, obj.obj(),
85 jstring_url.obj()); 88 jstring_url.obj());
86 } 89 }
87 90
88 void WebContentsObserverProxy::DidStopLoading() { 91 void WebContentsObserverProxy::DidStopLoading() {
89 JNIEnv* env = AttachCurrentThread(); 92 JNIEnv* env = AttachCurrentThread();
90 ScopedJavaLocalRef<jobject> obj(java_observer_); 93 ScopedJavaLocalRef<jobject> obj(java_observer_);
91 std::string url_string = web_contents()->GetLastCommittedURL().spec(); 94 std::string url_string = web_contents()->GetLastCommittedURL().spec();
92 SetToBaseURLForDataURLIfNeeded(&url_string); 95 SetToBaseURLForDataURLIfNeeded(&url_string);
96 // DidStopLoading is the last event we should get.
97 base_url_of_last_started_data_url_ = GURL::EmptyGURL();
93 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString( 98 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString(
94 env, url_string)); 99 env, url_string));
95 Java_WebContentsObserverProxy_didStopLoading(env, obj.obj(), 100 Java_WebContentsObserverProxy_didStopLoading(env, obj.obj(),
96 jstring_url.obj()); 101 jstring_url.obj());
97 } 102 }
98 103
99 void WebContentsObserverProxy::DidFailProvisionalLoad( 104 void WebContentsObserverProxy::DidFailProvisionalLoad(
100 RenderFrameHost* render_frame_host, 105 RenderFrameHost* render_frame_host,
101 const GURL& validated_url, 106 const GURL& validated_url,
102 int error_code, 107 int error_code,
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 302
298 Java_WebContentsObserverProxy_mediaSessionStateChanged( 303 Java_WebContentsObserverProxy_mediaSessionStateChanged(
299 env, obj.obj(), is_controllable, is_suspended); 304 env, obj.obj(), is_controllable, is_suspended);
300 } 305 }
301 306
302 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded( 307 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded(
303 std::string* url) { 308 std::string* url) {
304 NavigationEntry* entry = 309 NavigationEntry* entry =
305 web_contents()->GetController().GetLastCommittedEntry(); 310 web_contents()->GetController().GetLastCommittedEntry();
306 // Note that GetBaseURLForDataURL is only used by the Android WebView. 311 // Note that GetBaseURLForDataURL is only used by the Android WebView.
307 if (entry && !entry->GetBaseURLForDataURL().is_empty()) 312 // FIXME: Should we only return valid specs and "about:blank" for invalid
313 // ones? This may break apps.
314 if (entry && !entry->GetBaseURLForDataURL().is_empty()) {
308 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); 315 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec();
316 } else if (!base_url_of_last_started_data_url_.is_empty()) {
317 // NavigationController can lose the pending entry and recreate it without
318 // a base URL if there has been a loadUrl("javascript:...") after
319 // loadDataWithBaseUrl.
320 *url = base_url_of_last_started_data_url_.possibly_invalid_spec();
321 }
309 } 322 }
310 323
311 bool RegisterWebContentsObserverProxy(JNIEnv* env) { 324 bool RegisterWebContentsObserverProxy(JNIEnv* env) {
312 return RegisterNativesImpl(env); 325 return RegisterNativesImpl(env);
313 } 326 }
314 } // namespace content 327 } // 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