| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 void WebContentsObserverProxy::Destroy(JNIEnv* env, | 54 void WebContentsObserverProxy::Destroy(JNIEnv* env, |
| 55 const JavaParamRef<jobject>& obj) { | 55 const JavaParamRef<jobject>& obj) { |
| 56 delete this; | 56 delete this; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void WebContentsObserverProxy::WebContentsDestroyed() { | 59 void WebContentsObserverProxy::WebContentsDestroyed() { |
| 60 JNIEnv* env = AttachCurrentThread(); | 60 JNIEnv* env = AttachCurrentThread(); |
| 61 ScopedJavaLocalRef<jobject> obj(java_observer_); | 61 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 62 // The java side will destroy |this| | 62 // The java side will destroy |this| |
| 63 Java_WebContentsObserverProxy_destroy(env, obj.obj()); | 63 Java_WebContentsObserverProxy_destroy(env, obj); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void WebContentsObserverProxy::RenderViewReady() { | 66 void WebContentsObserverProxy::RenderViewReady() { |
| 67 JNIEnv* env = AttachCurrentThread(); | 67 JNIEnv* env = AttachCurrentThread(); |
| 68 ScopedJavaLocalRef<jobject> obj(java_observer_); | 68 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 69 Java_WebContentsObserverProxy_renderViewReady(env, obj.obj()); | 69 Java_WebContentsObserverProxy_renderViewReady(env, obj); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void WebContentsObserverProxy::RenderProcessGone( | 72 void WebContentsObserverProxy::RenderProcessGone( |
| 73 base::TerminationStatus termination_status) { | 73 base::TerminationStatus termination_status) { |
| 74 JNIEnv* env = AttachCurrentThread(); | 74 JNIEnv* env = AttachCurrentThread(); |
| 75 ScopedJavaLocalRef<jobject> obj(java_observer_); | 75 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 76 jboolean was_oom_protected = | 76 jboolean was_oom_protected = |
| 77 termination_status == base::TERMINATION_STATUS_OOM_PROTECTED; | 77 termination_status == base::TERMINATION_STATUS_OOM_PROTECTED; |
| 78 Java_WebContentsObserverProxy_renderProcessGone(env, obj.obj(), | 78 Java_WebContentsObserverProxy_renderProcessGone(env, obj, was_oom_protected); |
| 79 was_oom_protected); | |
| 80 } | 79 } |
| 81 | 80 |
| 82 void WebContentsObserverProxy::DidFinishNavigation( | 81 void WebContentsObserverProxy::DidFinishNavigation( |
| 83 NavigationHandle* navigation_handle) { | 82 NavigationHandle* navigation_handle) { |
| 84 JNIEnv* env = AttachCurrentThread(); | 83 JNIEnv* env = AttachCurrentThread(); |
| 85 ScopedJavaLocalRef<jobject> obj(java_observer_); | 84 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 86 ScopedJavaLocalRef<jstring> jstring_url( | 85 ScopedJavaLocalRef<jstring> jstring_url( |
| 87 ConvertUTF8ToJavaString(env, web_contents()->GetVisibleURL().spec())); | 86 ConvertUTF8ToJavaString(env, web_contents()->GetVisibleURL().spec())); |
| 88 Java_WebContentsObserverProxy_didFinishNavigation( | 87 Java_WebContentsObserverProxy_didFinishNavigation( |
| 89 env, obj.obj(), navigation_handle->IsInMainFrame(), | 88 env, obj, navigation_handle->IsInMainFrame(), |
| 90 navigation_handle->IsErrorPage(), navigation_handle->HasCommitted()); | 89 navigation_handle->IsErrorPage(), navigation_handle->HasCommitted()); |
| 91 } | 90 } |
| 92 | 91 |
| 93 void WebContentsObserverProxy::DidStartLoading() { | 92 void WebContentsObserverProxy::DidStartLoading() { |
| 94 JNIEnv* env = AttachCurrentThread(); | 93 JNIEnv* env = AttachCurrentThread(); |
| 95 ScopedJavaLocalRef<jobject> obj(java_observer_); | 94 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 96 ScopedJavaLocalRef<jstring> jstring_url( | 95 ScopedJavaLocalRef<jstring> jstring_url( |
| 97 ConvertUTF8ToJavaString(env, web_contents()->GetVisibleURL().spec())); | 96 ConvertUTF8ToJavaString(env, web_contents()->GetVisibleURL().spec())); |
| 98 if (auto* entry = web_contents()->GetController().GetPendingEntry()) { | 97 if (auto* entry = web_contents()->GetController().GetPendingEntry()) { |
| 99 base_url_of_last_started_data_url_ = entry->GetBaseURLForDataURL(); | 98 base_url_of_last_started_data_url_ = entry->GetBaseURLForDataURL(); |
| 100 } | 99 } |
| 101 Java_WebContentsObserverProxy_didStartLoading(env, obj.obj(), | 100 Java_WebContentsObserverProxy_didStartLoading(env, obj, jstring_url); |
| 102 jstring_url.obj()); | |
| 103 } | 101 } |
| 104 | 102 |
| 105 void WebContentsObserverProxy::DidStopLoading() { | 103 void WebContentsObserverProxy::DidStopLoading() { |
| 106 JNIEnv* env = AttachCurrentThread(); | 104 JNIEnv* env = AttachCurrentThread(); |
| 107 ScopedJavaLocalRef<jobject> obj(java_observer_); | 105 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 108 std::string url_string = web_contents()->GetLastCommittedURL().spec(); | 106 std::string url_string = web_contents()->GetLastCommittedURL().spec(); |
| 109 SetToBaseURLForDataURLIfNeeded(&url_string); | 107 SetToBaseURLForDataURLIfNeeded(&url_string); |
| 110 // DidStopLoading is the last event we should get. | 108 // DidStopLoading is the last event we should get. |
| 111 base_url_of_last_started_data_url_ = GURL::EmptyGURL(); | 109 base_url_of_last_started_data_url_ = GURL::EmptyGURL(); |
| 112 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString( | 110 ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString( |
| 113 env, url_string)); | 111 env, url_string)); |
| 114 Java_WebContentsObserverProxy_didStopLoading(env, obj.obj(), | 112 Java_WebContentsObserverProxy_didStopLoading(env, obj, jstring_url); |
| 115 jstring_url.obj()); | |
| 116 } | 113 } |
| 117 | 114 |
| 118 void WebContentsObserverProxy::DidFailProvisionalLoad( | 115 void WebContentsObserverProxy::DidFailProvisionalLoad( |
| 119 RenderFrameHost* render_frame_host, | 116 RenderFrameHost* render_frame_host, |
| 120 const GURL& validated_url, | 117 const GURL& validated_url, |
| 121 int error_code, | 118 int error_code, |
| 122 const base::string16& error_description, | 119 const base::string16& error_description, |
| 123 bool was_ignored_by_handler) { | 120 bool was_ignored_by_handler) { |
| 124 DidFailLoadInternal(true, !render_frame_host->GetParent(), error_code, | 121 DidFailLoadInternal(true, !render_frame_host->GetParent(), error_code, |
| 125 error_description, validated_url, was_ignored_by_handler); | 122 error_description, validated_url, was_ignored_by_handler); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 153 details.previous_url.ReplaceComponents(replacements); | 150 details.previous_url.ReplaceComponents(replacements); |
| 154 | 151 |
| 155 // is_fragment_navigation is indicative of the intent of this variable. | 152 // is_fragment_navigation is indicative of the intent of this variable. |
| 156 // However, there isn't sufficient information here to determine whether this | 153 // However, there isn't sufficient information here to determine whether this |
| 157 // is actually a fragment navigation, or a history API navigation to a URL | 154 // is actually a fragment navigation, or a history API navigation to a URL |
| 158 // that would also be valid for a fragment navigation. | 155 // that would also be valid for a fragment navigation. |
| 159 bool is_fragment_navigation = | 156 bool is_fragment_navigation = |
| 160 urls_same_ignoring_fragment && details.is_in_page; | 157 urls_same_ignoring_fragment && details.is_in_page; |
| 161 | 158 |
| 162 Java_WebContentsObserverProxy_didNavigateMainFrame( | 159 Java_WebContentsObserverProxy_didNavigateMainFrame( |
| 163 env, obj.obj(), jstring_url.obj(), jstring_base_url.obj(), | 160 env, obj, jstring_url, jstring_base_url, |
| 164 details.is_navigation_to_different_page(), is_fragment_navigation, | 161 details.is_navigation_to_different_page(), is_fragment_navigation, |
| 165 details.http_status_code); | 162 details.http_status_code); |
| 166 } | 163 } |
| 167 | 164 |
| 168 void WebContentsObserverProxy::DidNavigateAnyFrame( | 165 void WebContentsObserverProxy::DidNavigateAnyFrame( |
| 169 RenderFrameHost* render_frame_host, | 166 RenderFrameHost* render_frame_host, |
| 170 const LoadCommittedDetails& details, | 167 const LoadCommittedDetails& details, |
| 171 const FrameNavigateParams& params) { | 168 const FrameNavigateParams& params) { |
| 172 JNIEnv* env = AttachCurrentThread(); | 169 JNIEnv* env = AttachCurrentThread(); |
| 173 ScopedJavaLocalRef<jobject> obj(java_observer_); | 170 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 174 ScopedJavaLocalRef<jstring> jstring_url( | 171 ScopedJavaLocalRef<jstring> jstring_url( |
| 175 ConvertUTF8ToJavaString(env, params.url.spec())); | 172 ConvertUTF8ToJavaString(env, params.url.spec())); |
| 176 ScopedJavaLocalRef<jstring> jstring_base_url( | 173 ScopedJavaLocalRef<jstring> jstring_base_url( |
| 177 ConvertUTF8ToJavaString(env, params.base_url.spec())); | 174 ConvertUTF8ToJavaString(env, params.base_url.spec())); |
| 178 jboolean jboolean_is_reload = ui::PageTransitionCoreTypeIs( | 175 jboolean jboolean_is_reload = ui::PageTransitionCoreTypeIs( |
| 179 params.transition, ui::PAGE_TRANSITION_RELOAD); | 176 params.transition, ui::PAGE_TRANSITION_RELOAD); |
| 180 | 177 |
| 181 Java_WebContentsObserverProxy_didNavigateAnyFrame( | 178 Java_WebContentsObserverProxy_didNavigateAnyFrame( |
| 182 env, obj.obj(), jstring_url.obj(), jstring_base_url.obj(), | 179 env, obj, jstring_url, jstring_base_url, jboolean_is_reload); |
| 183 jboolean_is_reload); | |
| 184 } | 180 } |
| 185 | 181 |
| 186 void WebContentsObserverProxy::DocumentAvailableInMainFrame() { | 182 void WebContentsObserverProxy::DocumentAvailableInMainFrame() { |
| 187 JNIEnv* env = AttachCurrentThread(); | 183 JNIEnv* env = AttachCurrentThread(); |
| 188 ScopedJavaLocalRef<jobject> obj(java_observer_); | 184 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 189 Java_WebContentsObserverProxy_documentAvailableInMainFrame(env, obj.obj()); | 185 Java_WebContentsObserverProxy_documentAvailableInMainFrame(env, obj); |
| 190 } | 186 } |
| 191 | 187 |
| 192 void WebContentsObserverProxy::DidStartProvisionalLoadForFrame( | 188 void WebContentsObserverProxy::DidStartProvisionalLoadForFrame( |
| 193 RenderFrameHost* render_frame_host, | 189 RenderFrameHost* render_frame_host, |
| 194 const GURL& validated_url, | 190 const GURL& validated_url, |
| 195 bool is_error_page, | 191 bool is_error_page, |
| 196 bool is_iframe_srcdoc) { | 192 bool is_iframe_srcdoc) { |
| 197 JNIEnv* env = AttachCurrentThread(); | 193 JNIEnv* env = AttachCurrentThread(); |
| 198 ScopedJavaLocalRef<jobject> obj(java_observer_); | 194 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 199 ScopedJavaLocalRef<jstring> jstring_url( | 195 ScopedJavaLocalRef<jstring> jstring_url( |
| 200 ConvertUTF8ToJavaString(env, validated_url.spec())); | 196 ConvertUTF8ToJavaString(env, validated_url.spec())); |
| 201 // TODO(dcheng): Does Java really need the parent frame ID? It doesn't appear | 197 // TODO(dcheng): Does Java really need the parent frame ID? It doesn't appear |
| 202 // to be used at all, and it just adds complexity here. | 198 // to be used at all, and it just adds complexity here. |
| 203 Java_WebContentsObserverProxy_didStartProvisionalLoadForFrame( | 199 Java_WebContentsObserverProxy_didStartProvisionalLoadForFrame( |
| 204 env, obj.obj(), render_frame_host->GetRoutingID(), | 200 env, obj, render_frame_host->GetRoutingID(), |
| 205 render_frame_host->GetParent() | 201 render_frame_host->GetParent() |
| 206 ? render_frame_host->GetParent()->GetRoutingID() | 202 ? render_frame_host->GetParent()->GetRoutingID() |
| 207 : -1, | 203 : -1, |
| 208 !render_frame_host->GetParent(), jstring_url.obj(), is_error_page, | 204 !render_frame_host->GetParent(), jstring_url, is_error_page, |
| 209 is_iframe_srcdoc); | 205 is_iframe_srcdoc); |
| 210 } | 206 } |
| 211 | 207 |
| 212 void WebContentsObserverProxy::DidCommitProvisionalLoadForFrame( | 208 void WebContentsObserverProxy::DidCommitProvisionalLoadForFrame( |
| 213 RenderFrameHost* render_frame_host, | 209 RenderFrameHost* render_frame_host, |
| 214 const GURL& url, | 210 const GURL& url, |
| 215 ui::PageTransition transition_type) { | 211 ui::PageTransition transition_type) { |
| 216 JNIEnv* env = AttachCurrentThread(); | 212 JNIEnv* env = AttachCurrentThread(); |
| 217 ScopedJavaLocalRef<jobject> obj(java_observer_); | 213 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 218 ScopedJavaLocalRef<jstring> jstring_url( | 214 ScopedJavaLocalRef<jstring> jstring_url( |
| 219 ConvertUTF8ToJavaString(env, url.spec())); | 215 ConvertUTF8ToJavaString(env, url.spec())); |
| 220 Java_WebContentsObserverProxy_didCommitProvisionalLoadForFrame( | 216 Java_WebContentsObserverProxy_didCommitProvisionalLoadForFrame( |
| 221 env, obj.obj(), render_frame_host->GetRoutingID(), | 217 env, obj, render_frame_host->GetRoutingID(), |
| 222 !render_frame_host->GetParent(), jstring_url.obj(), transition_type); | 218 !render_frame_host->GetParent(), jstring_url, transition_type); |
| 223 } | 219 } |
| 224 | 220 |
| 225 void WebContentsObserverProxy::DidFinishLoad(RenderFrameHost* render_frame_host, | 221 void WebContentsObserverProxy::DidFinishLoad(RenderFrameHost* render_frame_host, |
| 226 const GURL& validated_url) { | 222 const GURL& validated_url) { |
| 227 JNIEnv* env = AttachCurrentThread(); | 223 JNIEnv* env = AttachCurrentThread(); |
| 228 ScopedJavaLocalRef<jobject> obj(java_observer_); | 224 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 229 | 225 |
| 230 std::string url_string = validated_url.spec(); | 226 std::string url_string = validated_url.spec(); |
| 231 SetToBaseURLForDataURLIfNeeded(&url_string); | 227 SetToBaseURLForDataURLIfNeeded(&url_string); |
| 232 | 228 |
| 233 ScopedJavaLocalRef<jstring> jstring_url( | 229 ScopedJavaLocalRef<jstring> jstring_url( |
| 234 ConvertUTF8ToJavaString(env, url_string)); | 230 ConvertUTF8ToJavaString(env, url_string)); |
| 235 Java_WebContentsObserverProxy_didFinishLoad( | 231 Java_WebContentsObserverProxy_didFinishLoad( |
| 236 env, obj.obj(), render_frame_host->GetRoutingID(), jstring_url.obj(), | 232 env, obj, render_frame_host->GetRoutingID(), jstring_url, |
| 237 !render_frame_host->GetParent()); | 233 !render_frame_host->GetParent()); |
| 238 } | 234 } |
| 239 | 235 |
| 240 void WebContentsObserverProxy::DocumentLoadedInFrame( | 236 void WebContentsObserverProxy::DocumentLoadedInFrame( |
| 241 RenderFrameHost* render_frame_host) { | 237 RenderFrameHost* render_frame_host) { |
| 242 JNIEnv* env = AttachCurrentThread(); | 238 JNIEnv* env = AttachCurrentThread(); |
| 243 ScopedJavaLocalRef<jobject> obj(java_observer_); | 239 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 244 Java_WebContentsObserverProxy_documentLoadedInFrame( | 240 Java_WebContentsObserverProxy_documentLoadedInFrame( |
| 245 env, obj.obj(), render_frame_host->GetRoutingID(), | 241 env, obj, render_frame_host->GetRoutingID(), |
| 246 !render_frame_host->GetParent()); | 242 !render_frame_host->GetParent()); |
| 247 } | 243 } |
| 248 | 244 |
| 249 void WebContentsObserverProxy::NavigationEntryCommitted( | 245 void WebContentsObserverProxy::NavigationEntryCommitted( |
| 250 const LoadCommittedDetails& load_details) { | 246 const LoadCommittedDetails& load_details) { |
| 251 JNIEnv* env = AttachCurrentThread(); | 247 JNIEnv* env = AttachCurrentThread(); |
| 252 ScopedJavaLocalRef<jobject> obj(java_observer_); | 248 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 253 Java_WebContentsObserverProxy_navigationEntryCommitted(env, obj.obj()); | 249 Java_WebContentsObserverProxy_navigationEntryCommitted(env, obj); |
| 254 } | 250 } |
| 255 | 251 |
| 256 void WebContentsObserverProxy::DidAttachInterstitialPage() { | 252 void WebContentsObserverProxy::DidAttachInterstitialPage() { |
| 257 JNIEnv* env = AttachCurrentThread(); | 253 JNIEnv* env = AttachCurrentThread(); |
| 258 ScopedJavaLocalRef<jobject> obj(java_observer_); | 254 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 259 Java_WebContentsObserverProxy_didAttachInterstitialPage(env, obj.obj()); | 255 Java_WebContentsObserverProxy_didAttachInterstitialPage(env, obj); |
| 260 } | 256 } |
| 261 | 257 |
| 262 void WebContentsObserverProxy::DidDetachInterstitialPage() { | 258 void WebContentsObserverProxy::DidDetachInterstitialPage() { |
| 263 JNIEnv* env = AttachCurrentThread(); | 259 JNIEnv* env = AttachCurrentThread(); |
| 264 ScopedJavaLocalRef<jobject> obj(java_observer_); | 260 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 265 Java_WebContentsObserverProxy_didDetachInterstitialPage(env, obj.obj()); | 261 Java_WebContentsObserverProxy_didDetachInterstitialPage(env, obj); |
| 266 } | 262 } |
| 267 | 263 |
| 268 void WebContentsObserverProxy::DidChangeThemeColor(SkColor color) { | 264 void WebContentsObserverProxy::DidChangeThemeColor(SkColor color) { |
| 269 JNIEnv* env = AttachCurrentThread(); | 265 JNIEnv* env = AttachCurrentThread(); |
| 270 ScopedJavaLocalRef<jobject> obj(java_observer_); | 266 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 271 Java_WebContentsObserverProxy_didChangeThemeColor(env, obj.obj(), color); | 267 Java_WebContentsObserverProxy_didChangeThemeColor(env, obj, color); |
| 272 } | 268 } |
| 273 | 269 |
| 274 void WebContentsObserverProxy::DidFailLoadInternal( | 270 void WebContentsObserverProxy::DidFailLoadInternal( |
| 275 bool is_provisional_load, | 271 bool is_provisional_load, |
| 276 bool is_main_frame, | 272 bool is_main_frame, |
| 277 int error_code, | 273 int error_code, |
| 278 const base::string16& description, | 274 const base::string16& description, |
| 279 const GURL& url, | 275 const GURL& url, |
| 280 bool was_ignored_by_handler) { | 276 bool was_ignored_by_handler) { |
| 281 JNIEnv* env = AttachCurrentThread(); | 277 JNIEnv* env = AttachCurrentThread(); |
| 282 ScopedJavaLocalRef<jobject> obj(java_observer_); | 278 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 283 ScopedJavaLocalRef<jstring> jstring_error_description( | 279 ScopedJavaLocalRef<jstring> jstring_error_description( |
| 284 ConvertUTF16ToJavaString(env, description)); | 280 ConvertUTF16ToJavaString(env, description)); |
| 285 ScopedJavaLocalRef<jstring> jstring_url( | 281 ScopedJavaLocalRef<jstring> jstring_url( |
| 286 ConvertUTF8ToJavaString(env, url.spec())); | 282 ConvertUTF8ToJavaString(env, url.spec())); |
| 287 | 283 |
| 288 Java_WebContentsObserverProxy_didFailLoad( | 284 Java_WebContentsObserverProxy_didFailLoad( |
| 289 env, obj.obj(), is_provisional_load, is_main_frame, error_code, | 285 env, obj, is_provisional_load, is_main_frame, error_code, |
| 290 jstring_error_description.obj(), jstring_url.obj(), | 286 jstring_error_description, jstring_url, was_ignored_by_handler); |
| 291 was_ignored_by_handler); | |
| 292 } | 287 } |
| 293 | 288 |
| 294 void WebContentsObserverProxy::DidFirstVisuallyNonEmptyPaint() { | 289 void WebContentsObserverProxy::DidFirstVisuallyNonEmptyPaint() { |
| 295 JNIEnv* env = AttachCurrentThread(); | 290 JNIEnv* env = AttachCurrentThread(); |
| 296 ScopedJavaLocalRef<jobject> obj(java_observer_); | 291 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 297 Java_WebContentsObserverProxy_didFirstVisuallyNonEmptyPaint(env, obj.obj()); | 292 Java_WebContentsObserverProxy_didFirstVisuallyNonEmptyPaint(env, obj); |
| 298 } | 293 } |
| 299 | 294 |
| 300 void WebContentsObserverProxy::DidStartNavigationToPendingEntry( | 295 void WebContentsObserverProxy::DidStartNavigationToPendingEntry( |
| 301 const GURL& url, | 296 const GURL& url, |
| 302 NavigationController::ReloadType reload_type) { | 297 NavigationController::ReloadType reload_type) { |
| 303 JNIEnv* env = AttachCurrentThread(); | 298 JNIEnv* env = AttachCurrentThread(); |
| 304 ScopedJavaLocalRef<jobject> obj(java_observer_); | 299 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 305 ScopedJavaLocalRef<jstring> jstring_url( | 300 ScopedJavaLocalRef<jstring> jstring_url( |
| 306 ConvertUTF8ToJavaString(env, url.spec())); | 301 ConvertUTF8ToJavaString(env, url.spec())); |
| 307 | 302 |
| 308 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry( | 303 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry(env, obj, |
| 309 env, obj.obj(), jstring_url.obj()); | 304 jstring_url); |
| 310 } | 305 } |
| 311 | 306 |
| 312 void WebContentsObserverProxy::MediaSessionStateChanged( | 307 void WebContentsObserverProxy::MediaSessionStateChanged( |
| 313 bool is_controllable, | 308 bool is_controllable, |
| 314 bool is_suspended, | 309 bool is_suspended, |
| 315 const MediaMetadata& metadata) { | 310 const MediaMetadata& metadata) { |
| 316 JNIEnv* env = AttachCurrentThread(); | 311 JNIEnv* env = AttachCurrentThread(); |
| 317 | 312 |
| 318 ScopedJavaLocalRef<jobject> obj(java_observer_); | 313 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 319 ScopedJavaLocalRef<jobject> j_metadata = | 314 ScopedJavaLocalRef<jobject> j_metadata = |
| 320 MediaMetadataAndroid::CreateJavaObject(env, metadata); | 315 MediaMetadataAndroid::CreateJavaObject(env, metadata); |
| 321 | 316 |
| 322 Java_WebContentsObserverProxy_mediaSessionStateChanged( | 317 Java_WebContentsObserverProxy_mediaSessionStateChanged( |
| 323 env, obj.obj(), is_controllable, is_suspended, j_metadata.obj()); | 318 env, obj, is_controllable, is_suspended, j_metadata); |
| 324 } | 319 } |
| 325 | 320 |
| 326 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded( | 321 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded( |
| 327 std::string* url) { | 322 std::string* url) { |
| 328 NavigationEntry* entry = | 323 NavigationEntry* entry = |
| 329 web_contents()->GetController().GetLastCommittedEntry(); | 324 web_contents()->GetController().GetLastCommittedEntry(); |
| 330 // Note that GetBaseURLForDataURL is only used by the Android WebView. | 325 // Note that GetBaseURLForDataURL is only used by the Android WebView. |
| 331 // FIXME: Should we only return valid specs and "about:blank" for invalid | 326 // FIXME: Should we only return valid specs and "about:blank" for invalid |
| 332 // ones? This may break apps. | 327 // ones? This may break apps. |
| 333 if (entry && !entry->GetBaseURLForDataURL().is_empty()) { | 328 if (entry && !entry->GetBaseURLForDataURL().is_empty()) { |
| 334 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); | 329 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); |
| 335 } else if (!base_url_of_last_started_data_url_.is_empty()) { | 330 } else if (!base_url_of_last_started_data_url_.is_empty()) { |
| 336 // NavigationController can lose the pending entry and recreate it without | 331 // NavigationController can lose the pending entry and recreate it without |
| 337 // a base URL if there has been a loadUrl("javascript:...") after | 332 // a base URL if there has been a loadUrl("javascript:...") after |
| 338 // loadDataWithBaseUrl. | 333 // loadDataWithBaseUrl. |
| 339 *url = base_url_of_last_started_data_url_.possibly_invalid_spec(); | 334 *url = base_url_of_last_started_data_url_.possibly_invalid_spec(); |
| 340 } | 335 } |
| 341 } | 336 } |
| 342 | 337 |
| 343 bool RegisterWebContentsObserverProxy(JNIEnv* env) { | 338 bool RegisterWebContentsObserverProxy(JNIEnv* env) { |
| 344 return RegisterNativesImpl(env); | 339 return RegisterNativesImpl(env); |
| 345 } | 340 } |
| 346 } // namespace content | 341 } // namespace content |
| OLD | NEW |