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

Unified Diff: content/browser/media/session/media_session_android.cc

Issue 2439483003: Link MediaSessionTabHelper with native MediaSession [CL is going to be split] (Closed)
Patch Set: Don't review, this CL is getting huge and needs to be split 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/media/session/media_session_android.cc
diff --git a/content/browser/media/session/media_session_android.cc b/content/browser/media/session/media_session_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8d7e69bb55e1b3893bfe50bdef0998c033f6b6ba
--- /dev/null
+++ b/content/browser/media/session/media_session_android.cc
@@ -0,0 +1,100 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/media/session/media_session_android.h"
+
+#include <algorithm>
+#include "content/browser/web_contents/web_contents_android.h"
+#include "content/common/android/media_metadata_android.h"
+#include "jni/ChromeMediaSession_jni.h"
+
+namespace content {
+
+using base::android::JavaParamRef;
+
+MediaSessionAndroid::MediaSessionAndroid(MediaSession* session)
+ : MediaSessionObserver(session) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ DCHECK(env);
+ j_media_session_.Reset(
+ Java_ChromeMediaSession_create(env, reinterpret_cast<intptr_t>(this)));
+}
+
+MediaSessionAndroid::~MediaSessionAndroid() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ DCHECK(env);
+ Java_ChromeMediaSession_tearDown(env, j_media_session_);
+}
+
+// static
+bool MediaSessionAndroid::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+// static
+base::android::ScopedJavaLocalRef<jobject> GetMediaSessionFromWebContents(
+ JNIEnv* env,
+ const JavaParamRef<jclass>& clazz,
+ const JavaParamRef<jobject>& j_contents_android) {
+ WebContents* contents = WebContents::FromJavaWebContents(j_contents_android);
+ DCHECK(contents);
+ MediaSession* session = MediaSession::Get(contents);
+ return session->session_android()->GetJavaSession();
+}
+
+base::android::ScopedJavaLocalRef<jobject>
+MediaSessionAndroid::GetJavaSession() {
+ return base::android::ScopedJavaLocalRef<jobject>(j_media_session_);
+}
+
+void MediaSessionAndroid::MediaSessionDestroyed() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ DCHECK(env);
+ Java_ChromeMediaSession_mediaSessionDestroyed(env, j_media_session_);
+}
+
+void MediaSessionAndroid::MediaSessionStateChanged(bool is_controllable,
+ bool is_suspended) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ DCHECK(env);
+ Java_ChromeMediaSession_mediaSessionStateChanged(
+ env, j_media_session_, is_controllable, is_suspended);
+}
+
+void MediaSessionAndroid::MediaSessionMetadataChanged(
+ const base::Optional<MediaMetadata>& metadata) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ DCHECK(env);
+
+ // Avoid translating metadata through JNI if there is no Java observer.
+ if (!Java_ChromeMediaSession_hasObservers(env, j_media_session_))
+ return;
+
+ base::android::ScopedJavaLocalRef<jobject> j_metadata;
+ if (metadata.has_value()) {
+ j_metadata = MediaMetadataAndroid::CreateJavaObject(env, metadata.value());
+ }
+ Java_ChromeMediaSession_mediaSessionMetadataChanged(env, j_media_session_,
+ j_metadata);
+}
+
+void MediaSessionAndroid::Resume(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& j_obj) {
+ session()->Resume(MediaSession::SuspendType::UI);
+}
+
+void MediaSessionAndroid::Suspend(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& j_obj) {
+ session()->Suspend(MediaSession::SuspendType::UI);
+}
+
+void MediaSessionAndroid::Stop(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& j_obj) {
+ session()->Stop(MediaSession::SuspendType::UI);
+}
+
+} // namespace content
« no previous file with comments | « content/browser/media/session/media_session_android.h ('k') | content/browser/media/session/media_session_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698