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