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

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

Issue 1458703003: Media Session API: use MediaMetadata in the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_session_browser_side
Patch Set: nits Created 4 years, 9 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 "content/browser/renderer_host/render_widget_host_impl.h" 12 #include "content/browser/renderer_host/render_widget_host_impl.h"
13 #include "content/browser/web_contents/web_contents_impl.h" 13 #include "content/browser/web_contents/web_contents_impl.h"
14 #include "content/common/android/media_metadata_android.h"
14 #include "content/public/browser/navigation_details.h" 15 #include "content/public/browser/navigation_details.h"
15 #include "content/public/browser/navigation_entry.h" 16 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/navigation_handle.h" 17 #include "content/public/browser/navigation_handle.h"
17 #include "jni/WebContentsObserverProxy_jni.h" 18 #include "jni/WebContentsObserverProxy_jni.h"
18 19
19 using base::android::AttachCurrentThread; 20 using base::android::AttachCurrentThread;
20 using base::android::ScopedJavaLocalRef; 21 using base::android::ScopedJavaLocalRef;
21 using base::android::ConvertUTF8ToJavaString; 22 using base::android::ConvertUTF8ToJavaString;
22 using base::android::ConvertUTF16ToJavaString; 23 using base::android::ConvertUTF16ToJavaString;
23 24
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 NavigationController::ReloadType reload_type) { 301 NavigationController::ReloadType reload_type) {
301 JNIEnv* env = AttachCurrentThread(); 302 JNIEnv* env = AttachCurrentThread();
302 ScopedJavaLocalRef<jobject> obj(java_observer_); 303 ScopedJavaLocalRef<jobject> obj(java_observer_);
303 ScopedJavaLocalRef<jstring> jstring_url( 304 ScopedJavaLocalRef<jstring> jstring_url(
304 ConvertUTF8ToJavaString(env, url.spec())); 305 ConvertUTF8ToJavaString(env, url.spec()));
305 306
306 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry( 307 Java_WebContentsObserverProxy_didStartNavigationToPendingEntry(
307 env, obj.obj(), jstring_url.obj()); 308 env, obj.obj(), jstring_url.obj());
308 } 309 }
309 310
310 void WebContentsObserverProxy::MediaSessionStateChanged(bool is_controllable, 311 void WebContentsObserverProxy::MediaSessionStateChanged(
311 bool is_suspended) { 312 bool is_controllable,
313 bool is_suspended,
314 const MediaMetadata& metadata) {
312 JNIEnv* env = AttachCurrentThread(); 315 JNIEnv* env = AttachCurrentThread();
313 316
314 ScopedJavaLocalRef<jobject> obj(java_observer_); 317 ScopedJavaLocalRef<jobject> obj(java_observer_);
318 ScopedJavaLocalRef<jobject> j_metadata =
319 MediaMetadataAndroid::CreateJavaObject(env, metadata);
315 320
316 Java_WebContentsObserverProxy_mediaSessionStateChanged( 321 Java_WebContentsObserverProxy_mediaSessionStateChanged(
317 env, obj.obj(), is_controllable, is_suspended); 322 env, obj.obj(), is_controllable, is_suspended, j_metadata.obj());
318 } 323 }
319 324
320 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded( 325 void WebContentsObserverProxy::SetToBaseURLForDataURLIfNeeded(
321 std::string* url) { 326 std::string* url) {
322 NavigationEntry* entry = 327 NavigationEntry* entry =
323 web_contents()->GetController().GetLastCommittedEntry(); 328 web_contents()->GetController().GetLastCommittedEntry();
324 // Note that GetBaseURLForDataURL is only used by the Android WebView. 329 // Note that GetBaseURLForDataURL is only used by the Android WebView.
325 // 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
326 // ones? This may break apps. 331 // ones? This may break apps.
327 if (entry && !entry->GetBaseURLForDataURL().is_empty()) { 332 if (entry && !entry->GetBaseURLForDataURL().is_empty()) {
328 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec(); 333 *url = entry->GetBaseURLForDataURL().possibly_invalid_spec();
329 } else if (!base_url_of_last_started_data_url_.is_empty()) { 334 } else if (!base_url_of_last_started_data_url_.is_empty()) {
330 // NavigationController can lose the pending entry and recreate it without 335 // NavigationController can lose the pending entry and recreate it without
331 // a base URL if there has been a loadUrl("javascript:...") after 336 // a base URL if there has been a loadUrl("javascript:...") after
332 // loadDataWithBaseUrl. 337 // loadDataWithBaseUrl.
333 *url = base_url_of_last_started_data_url_.possibly_invalid_spec(); 338 *url = base_url_of_last_started_data_url_.possibly_invalid_spec();
334 } 339 }
335 } 340 }
336 341
337 bool RegisterWebContentsObserverProxy(JNIEnv* env) { 342 bool RegisterWebContentsObserverProxy(JNIEnv* env) {
338 return RegisterNativesImpl(env); 343 return RegisterNativesImpl(env);
339 } 344 }
340 } // namespace content 345 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/web_contents_observer_proxy.h ('k') | content/browser/media/session/media_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698