Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: content/browser/android/web_contents_observer_proxy.cc

Issue 2439483003: Link MediaSessionTabHelper with native MediaSession [CL is going to be split] (Closed)
Patch Set: addressed nits Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 ReloadType reload_type) { 297 ReloadType reload_type) {
300 JNIEnv* env = AttachCurrentThread(); 298 JNIEnv* env = AttachCurrentThread();
301 ScopedJavaLocalRef<jobject> obj(java_observer_); 299 ScopedJavaLocalRef<jobject> obj(java_observer_);
302 ScopedJavaLocalRef<jstring> jstring_url( 300 ScopedJavaLocalRef<jstring> jstring_url(
303 ConvertUTF8ToJavaString(env, url.spec())); 301 ConvertUTF8ToJavaString(env, url.spec()));
304 302
305 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry(env, obj, 303 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry(env, obj,
306 jstring_url); 304 jstring_url);
307 } 305 }
308 306
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( 307 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded(
334 std::string* url) { 308 std::string* url) {
335 NavigationEntry* entry = 309 NavigationEntry* entry =
336 web_contents()->GetController().GetLastCommittedEntry(); 310 web_contents()->GetController().GetLastCommittedEntry();
337 // Note that GetBaseURLForDataURL is only used by the Android WebView. 311 // Note that GetBaseURLForDataURL is only used by the Android WebView.
338 // FIXME: Should we only return valid specs and "about:blank" for invalid 312 // FIXME: Should we only return valid specs and "about:blank" for invalid
339 // ones? This may break apps. 313 // ones? This may break apps.
340 if (entry && !entry->GetBaseURLForDataURL().is_empty()) { 314 if (entry && !entry->GetBaseURLForDataURL().is_empty()) {
341 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); 315 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec();
342 } else if (!base_url_of_last_started_data_url_.is_empty()) { 316 } else if (!base_url_of_last_started_data_url_.is_empty()) {
343 // NavigationController can lose the pending entry and recreate it without 317 // NavigationController can lose the pending entry and recreate it without
344 // a base URL if there has been a loadUrl("javascript:...") after 318 // a base URL if there has been a loadUrl("javascript:...") after
345 // loadDataWithBaseUrl. 319 // loadDataWithBaseUrl.
346 *url = base_url_of_last_started_data_url_.possibly_invalid_spec(); 320 *url = base_url_of_last_started_data_url_.possibly_invalid_spec();
347 } 321 }
348 } 322 }
349 323
350 bool RegisterWebContentsObserverProxy(JNIEnv* env) { 324 bool RegisterWebContentsObserverProxy(JNIEnv* env) {
351 return RegisterNativesImpl(env); 325 return RegisterNativesImpl(env);
352 } 326 }
353 } // namespace content 327 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698