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

Side by Side 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, 1 month 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/media/session/media_session_android.h"
6
7 #include <algorithm>
8 #include "content/browser/web_contents/web_contents_android.h"
9 #include "content/common/android/media_metadata_android.h"
10 #include "jni/ChromeMediaSession_jni.h"
11
12 namespace content {
13
14 using base::android::JavaParamRef;
15
16 MediaSessionAndroid::MediaSessionAndroid(MediaSession* session)
17 : MediaSessionObserver(session) {
18 JNIEnv* env = base::android::AttachCurrentThread();
19 DCHECK(env);
20 j_media_session_.Reset(
21 Java_ChromeMediaSession_create(env, reinterpret_cast<intptr_t>(this)));
22 }
23
24 MediaSessionAndroid::~MediaSessionAndroid() {
25 JNIEnv* env = base::android::AttachCurrentThread();
26 DCHECK(env);
27 Java_ChromeMediaSession_tearDown(env, j_media_session_);
28 }
29
30 // static
31 bool MediaSessionAndroid::Register(JNIEnv* env) {
32 return RegisterNativesImpl(env);
33 }
34
35 // static
36 base::android::ScopedJavaLocalRef<jobject> GetMediaSessionFromWebContents(
37 JNIEnv* env,
38 const JavaParamRef<jclass>& clazz,
39 const JavaParamRef<jobject>& j_contents_android) {
40 WebContents* contents = WebContents::FromJavaWebContents(j_contents_android);
41 DCHECK(contents);
42 MediaSession* session = MediaSession::Get(contents);
43 return session->session_android()->GetJavaSession();
44 }
45
46 base::android::ScopedJavaLocalRef<jobject>
47 MediaSessionAndroid::GetJavaSession() {
48 return base::android::ScopedJavaLocalRef<jobject>(j_media_session_);
49 }
50
51 void MediaSessionAndroid::MediaSessionDestroyed() {
52 JNIEnv* env = base::android::AttachCurrentThread();
53 DCHECK(env);
54 Java_ChromeMediaSession_mediaSessionDestroyed(env, j_media_session_);
55 }
56
57 void MediaSessionAndroid::MediaSessionStateChanged(bool is_controllable,
58 bool is_suspended) {
59 JNIEnv* env = base::android::AttachCurrentThread();
60 DCHECK(env);
61 Java_ChromeMediaSession_mediaSessionStateChanged(
62 env, j_media_session_, is_controllable, is_suspended);
63 }
64
65 void MediaSessionAndroid::MediaSessionMetadataChanged(
66 const base::Optional<MediaMetadata>& metadata) {
67 JNIEnv* env = base::android::AttachCurrentThread();
68 DCHECK(env);
69
70 // Avoid translating metadata through JNI if there is no Java observer.
71 if (!Java_ChromeMediaSession_hasObservers(env, j_media_session_))
72 return;
73
74 base::android::ScopedJavaLocalRef<jobject> j_metadata;
75 if (metadata.has_value()) {
76 j_metadata = MediaMetadataAndroid::CreateJavaObject(env, metadata.value());
77 }
78 Java_ChromeMediaSession_mediaSessionMetadataChanged(env, j_media_session_,
79 j_metadata);
80 }
81
82 void MediaSessionAndroid::Resume(
83 JNIEnv* env,
84 const base::android::JavaParamRef<jobject>& j_obj) {
85 session()->Resume(MediaSession::SuspendType::UI);
86 }
87
88 void MediaSessionAndroid::Suspend(
89 JNIEnv* env,
90 const base::android::JavaParamRef<jobject>& j_obj) {
91 session()->Suspend(MediaSession::SuspendType::UI);
92 }
93
94 void MediaSessionAndroid::Stop(
95 JNIEnv* env,
96 const base::android::JavaParamRef<jobject>& j_obj) {
97 session()->Stop(MediaSession::SuspendType::UI);
98 }
99
100 } // namespace content
OLDNEW
« 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