| 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 "base/optional.h" |
| 12 #include "content/browser/renderer_host/render_widget_host_impl.h" | 13 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 13 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
| 14 #include "content/common/android/media_metadata_android.h" | 15 #include "content/common/android/media_metadata_android.h" |
| 15 #include "content/public/browser/navigation_details.h" | 16 #include "content/public/browser/navigation_details.h" |
| 16 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
| 17 #include "content/public/browser/navigation_handle.h" | 18 #include "content/public/browser/navigation_handle.h" |
| 19 #include "content/public/common/media_metadata.h" |
| 18 #include "jni/WebContentsObserverProxy_jni.h" | 20 #include "jni/WebContentsObserverProxy_jni.h" |
| 19 | 21 |
| 20 using base::android::AttachCurrentThread; | 22 using base::android::AttachCurrentThread; |
| 21 using base::android::JavaParamRef; | 23 using base::android::JavaParamRef; |
| 22 using base::android::ScopedJavaLocalRef; | 24 using base::android::ScopedJavaLocalRef; |
| 23 using base::android::ConvertUTF8ToJavaString; | 25 using base::android::ConvertUTF8ToJavaString; |
| 24 using base::android::ConvertUTF16ToJavaString; | 26 using base::android::ConvertUTF16ToJavaString; |
| 25 | 27 |
| 26 namespace content { | 28 namespace content { |
| 27 | 29 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 ScopedJavaLocalRef<jstring> jstring_url( | 302 ScopedJavaLocalRef<jstring> jstring_url( |
| 301 ConvertUTF8ToJavaString(env, url.spec())); | 303 ConvertUTF8ToJavaString(env, url.spec())); |
| 302 | 304 |
| 303 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry(env, obj, | 305 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry(env, obj, |
| 304 jstring_url); | 306 jstring_url); |
| 305 } | 307 } |
| 306 | 308 |
| 307 void WebContentsObserverProxy::MediaSessionStateChanged( | 309 void WebContentsObserverProxy::MediaSessionStateChanged( |
| 308 bool is_controllable, | 310 bool is_controllable, |
| 309 bool is_suspended, | 311 bool is_suspended, |
| 310 const MediaMetadata& metadata) { | 312 const base::Optional<MediaMetadata>& metadata) { |
| 311 JNIEnv* env = AttachCurrentThread(); | 313 JNIEnv* env = AttachCurrentThread(); |
| 312 | 314 |
| 313 ScopedJavaLocalRef<jobject> obj(java_observer_); | 315 ScopedJavaLocalRef<jobject> obj(java_observer_); |
| 314 ScopedJavaLocalRef<jobject> j_metadata = | 316 ScopedJavaLocalRef<jobject> j_metadata; |
| 315 MediaMetadataAndroid::CreateJavaObject(env, metadata); | 317 |
| 318 if (metadata.has_value()) |
| 319 j_metadata = MediaMetadataAndroid::CreateJavaObject(env, metadata.value()); |
| 316 | 320 |
| 317 Java_WebContentsObserverProxy_mediaSessionStateChanged( | 321 Java_WebContentsObserverProxy_mediaSessionStateChanged( |
| 318 env, obj, is_controllable, is_suspended, j_metadata); | 322 env, obj, is_controllable, is_suspended, j_metadata); |
| 319 } | 323 } |
| 320 | 324 |
| 321 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded( | 325 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded( |
| 322 std::string* url) { | 326 std::string* url) { |
| 323 NavigationEntry* entry = | 327 NavigationEntry* entry = |
| 324 web_contents()->GetController().GetLastCommittedEntry(); | 328 web_contents()->GetController().GetLastCommittedEntry(); |
| 325 // Note that GetBaseURLForDataURL is only used by the Android WebView. | 329 // Note that GetBaseURLForDataURL is only used by the Android WebView. |
| 326 // FIXME: Should we only return valid specs and "about:blank" for invalid | 330 // FIXME: Should we only return valid specs and "about:blank" for invalid |
| 327 // ones? This may break apps. | 331 // ones? This may break apps. |
| 328 if (entry && !entry->GetBaseURLForDataURL().is_empty()) { | 332 if (entry && !entry->GetBaseURLForDataURL().is_empty()) { |
| 329 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); | 333 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); |
| 330 } else if (!base_url_of_last_started_data_url_.is_empty()) { | 334 } else if (!base_url_of_last_started_data_url_.is_empty()) { |
| 331 // NavigationController can lose the pending entry and recreate it without | 335 // NavigationController can lose the pending entry and recreate it without |
| 332 // a base URL if there has been a loadUrl("javascript:...") after | 336 // a base URL if there has been a loadUrl("javascript:...") after |
| 333 // loadDataWithBaseUrl. | 337 // loadDataWithBaseUrl. |
| 334 *url = base_url_of_last_started_data_url_.possibly_invalid_spec(); | 338 *url = base_url_of_last_started_data_url_.possibly_invalid_spec(); |
| 335 } | 339 } |
| 336 } | 340 } |
| 337 | 341 |
| 338 bool RegisterWebContentsObserverProxy(JNIEnv* env) { | 342 bool RegisterWebContentsObserverProxy(JNIEnv* env) { |
| 339 return RegisterNativesImpl(env); | 343 return RegisterNativesImpl(env); |
| 340 } | 344 } |
| 341 } // namespace content | 345 } // namespace content |
| OLD | NEW |