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