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