| 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" |
| 11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "content/browser/renderer_host/render_widget_host_impl.h" | 12 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 13 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
| 14 #include "content/common/android/media_metadata_proxy.h" |
| 14 #include "content/public/browser/navigation_details.h" | 15 #include "content/public/browser/navigation_details.h" |
| 15 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
| 16 #include "content/public/browser/navigation_handle.h" | 17 #include "content/public/browser/navigation_handle.h" |
| 17 #include "jni/WebContentsObserverProxy_jni.h" | 18 #include "jni/WebContentsObserverProxy_jni.h" |
| 18 | 19 |
| 19 using base::android::AttachCurrentThread; | 20 using base::android::AttachCurrentThread; |
| 20 using base::android::ScopedJavaLocalRef; | 21 using base::android::ScopedJavaLocalRef; |
| 21 using base::android::ConvertUTF8ToJavaString; | 22 using base::android::ConvertUTF8ToJavaString; |
| 22 using base::android::ConvertUTF16ToJavaString; | 23 using base::android::ConvertUTF16ToJavaString; |
| 23 | 24 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 NavigationController::ReloadType reload_type) { | 296 NavigationController::ReloadType reload_type) { |
| 296 JNIEnv* env = AttachCurrentThread(); | 297 JNIEnv* env = AttachCurrentThread(); |
| 297 ScopedJavaLocalRef<jobject> obj(java_observer_); | 298 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 298 ScopedJavaLocalRef<jstring> jstring_url( | 299 ScopedJavaLocalRef<jstring> jstring_url( |
| 299 ConvertUTF8ToJavaString(env, url.spec())); | 300 ConvertUTF8ToJavaString(env, url.spec())); |
| 300 | 301 |
| 301 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry( | 302 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry( |
| 302 env, obj.obj(), jstring_url.obj()); | 303 env, obj.obj(), jstring_url.obj()); |
| 303 } | 304 } |
| 304 | 305 |
| 305 void WebContentsObserverProxy::MediaSessionStateChanged(bool is_controllable, | 306 void WebContentsObserverProxy::MediaSessionStateChanged( |
| 306 bool is_suspended) { | 307 bool is_controllable, |
| 308 bool is_suspended, |
| 309 const MediaMetadata& metadata) { |
| 307 JNIEnv* env = AttachCurrentThread(); | 310 JNIEnv* env = AttachCurrentThread(); |
| 308 | 311 |
| 309 ScopedJavaLocalRef<jobject> obj(java_observer_); | 312 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 313 ScopedJavaLocalRef<jobject> j_metadata = |
| 314 MediaMetadataProxy::GetJavaObject(env, metadata); |
| 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, j_metadata.obj()); |
| 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 if (entry && !entry->GetBaseURLForDataURL().is_empty()) |
| 321 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); | 326 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); |
| 322 } | 327 } |
| 323 | 328 |
| 324 bool RegisterWebContentsObserverProxy(JNIEnv* env) { | 329 bool RegisterWebContentsObserverProxy(JNIEnv* env) { |
| 325 return RegisterNativesImpl(env); | 330 return RegisterNativesImpl(env); |
| 326 } | 331 } |
| 327 } // namespace content | 332 } // namespace content |
| OLD | NEW |