| 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 ScopedJavaLocalRef<jobject> obj(java_observer_); | 303 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 304 ScopedJavaLocalRef<jstring> jstring_url( | 304 ScopedJavaLocalRef<jstring> jstring_url( |
| 305 ConvertUTF8ToJavaString(env, url.spec())); | 305 ConvertUTF8ToJavaString(env, url.spec())); |
| 306 | 306 |
| 307 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry( | 307 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry( |
| 308 env, obj.obj(), jstring_url.obj()); | 308 env, obj.obj(), jstring_url.obj()); |
| 309 } | 309 } |
| 310 | 310 |
| 311 void WebContentsObserverProxy::MediaSessionStateChanged( | 311 void WebContentsObserverProxy::MediaSessionStateChanged( |
| 312 bool is_controllable, | 312 bool is_controllable, |
| 313 bool is_suspended, | 313 bool is_suspended) { |
| 314 const MediaMetadata& metadata) { | 314 JNIEnv* env = AttachCurrentThread(); |
| 315 |
| 316 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 317 |
| 318 Java_WebContentsObserverProxy_mediaSessionStateChanged( |
| 319 env, obj.obj(), is_controllable, is_suspended); |
| 320 } |
| 321 |
| 322 void WebContentsObserverProxy::MediaMetadataChanged( |
| 323 const MediaMetadata &metadata) { |
| 315 JNIEnv* env = AttachCurrentThread(); | 324 JNIEnv* env = AttachCurrentThread(); |
| 316 | 325 |
| 317 ScopedJavaLocalRef<jobject> obj(java_observer_); | 326 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 318 ScopedJavaLocalRef<jobject> j_metadata = | 327 ScopedJavaLocalRef<jobject> j_metadata = |
| 319 MediaMetadataAndroid::CreateJavaObject(env, metadata); | 328 MediaMetadataAndroid::CreateJavaObject(env, metadata); |
| 320 | 329 |
| 321 Java_WebContentsObserverProxy_mediaSessionStateChanged( | 330 Java_WebContentsObserverProxy_mediaMetadataChanged( |
| 322 env, obj.obj(), is_controllable, is_suspended, j_metadata.obj()); | 331 env, obj.obj(), j_metadata.obj()); |
| 323 } | 332 } |
| 324 | 333 |
| 325 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded( | 334 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded( |
| 326 std::string* url) { | 335 std::string* url) { |
| 327 NavigationEntry* entry = | 336 NavigationEntry* entry = |
| 328 web_contents()->GetController().GetLastCommittedEntry(); | 337 web_contents()->GetController().GetLastCommittedEntry(); |
| 329 // Note that GetBaseURLForDataURL is only used by the Android WebView. | 338 // Note that GetBaseURLForDataURL is only used by the Android WebView. |
| 330 // FIXME: Should we only return valid specs and "about:blank" for invalid | 339 // FIXME: Should we only return valid specs and "about:blank" for invalid |
| 331 // ones? This may break apps. | 340 // ones? This may break apps. |
| 332 if (entry && !entry->GetBaseURLForDataURL().is_empty()) { | 341 if (entry && !entry->GetBaseURLForDataURL().is_empty()) { |
| 333 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); | 342 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); |
| 334 } else if (!base_url_of_last_started_data_url_.is_empty()) { | 343 } else if (!base_url_of_last_started_data_url_.is_empty()) { |
| 335 // NavigationController can lose the pending entry and recreate it without | 344 // NavigationController can lose the pending entry and recreate it without |
| 336 // a base URL if there has been a loadUrl("javascript:...") after | 345 // a base URL if there has been a loadUrl("javascript:...") after |
| 337 // loadDataWithBaseUrl. | 346 // loadDataWithBaseUrl. |
| 338 *url = base_url_of_last_started_data_url_.possibly_invalid_spec(); | 347 *url = base_url_of_last_started_data_url_.possibly_invalid_spec(); |
| 339 } | 348 } |
| 340 } | 349 } |
| 341 | 350 |
| 342 bool RegisterWebContentsObserverProxy(JNIEnv* env) { | 351 bool RegisterWebContentsObserverProxy(JNIEnv* env) { |
| 343 return RegisterNativesImpl(env); | 352 return RegisterNativesImpl(env); |
| 344 } | 353 } |
| 345 } // namespace content | 354 } // namespace content |
| OLD | NEW |