diff options
author | mlamouri <mlamouri@chromium.org> | 2015-08-17 08:51:01 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-17 15:51:36 +0000 |
commit | 4c4fbedc4d4c613bcc456efe4e4a2477abe0e4d3 (patch) | |
tree | c98ec21a81fbaaf8f673cf5fffa0d07528b5eb7b /content | |
parent | 58a2915b955ac366f988c0f3582fa8506698f900 (diff) | |
download | chromium_src-4c4fbedc4d4c613bcc456efe4e4a2477abe0e4d3.zip chromium_src-4c4fbedc4d4c613bcc456efe4e4a2477abe0e4d3.tar.gz chromium_src-4c4fbedc4d4c613bcc456efe4e4a2477abe0e4d3.tar.bz2 |
Android Media Notification: stop the MediaSession when dismissed.
The current behaviour is to simply dismiss the notification but the
WebContents and content::MediaSession will consider the session still
running while the user's intent was to actually stop it. As a result,
the WebContents will still receive notification about the session
changes, for example, when Chrome will lose/re-gain audio focus. These
notifications will re-introduce the Notification (in a paused state).
BUG=515129
Review URL: https://codereview.chromium.org/1294863002
Cr-Commit-Position: refs/heads/master@{#343688}
Diffstat (limited to 'content')
9 files changed, 37 insertions, 0 deletions
diff --git a/content/browser/media/android/media_session.cc b/content/browser/media/android/media_session.cc index a8b64ef..37a6995 100644 --- a/content/browser/media/android/media_session.cc +++ b/content/browser/media/android/media_session.cc @@ -145,6 +145,17 @@ void MediaSession::Suspend() { OnSuspendInternal(SuspendType::UI); } +void MediaSession::Stop() { + DCHECK(audio_focus_state_ != State::INACTIVE); + + if (audio_focus_state_ != State::SUSPENDED) + OnSuspendInternal(SuspendType::UI); + + DCHECK(audio_focus_state_ == State::SUSPENDED); + players_.clear(); + AbandonSystemAudioFocusIfNeeded(); +} + bool MediaSession::IsSuspended() const { // TODO(mlamouri): should be == State::SUSPENDED. return audio_focus_state_ != State::ACTIVE; diff --git a/content/browser/media/android/media_session.h b/content/browser/media/android/media_session.h index 3cd5dff..b7a6f8a 100644 --- a/content/browser/media/android/media_session.h +++ b/content/browser/media/android/media_session.h @@ -75,6 +75,9 @@ class CONTENT_EXPORT MediaSession // is not controllable. void Suspend(); + // Called when the user requests stopping the session. + void Stop(); + // Returns if the session can be controlled by Resume() and Suspend calls // above. bool IsControllable() const; diff --git a/content/browser/web_contents/web_contents_android.cc b/content/browser/web_contents/web_contents_android.cc index 647accd..76d2d39 100644 --- a/content/browser/web_contents/web_contents_android.cc +++ b/content/browser/web_contents/web_contents_android.cc @@ -537,6 +537,10 @@ void WebContentsAndroid::SuspendMediaSession(JNIEnv* env, jobject obj) { web_contents_->SuspendMediaSession(); } +void WebContentsAndroid::StopMediaSession(JNIEnv* env, jobject obj) { + web_contents_->StopMediaSession(); +} + ScopedJavaLocalRef<jstring> WebContentsAndroid::GetEncoding( JNIEnv* env, jobject obj) const { return base::android::ConvertUTF8ToJavaString(env, diff --git a/content/browser/web_contents/web_contents_android.h b/content/browser/web_contents/web_contents_android.h index a17fc3e..5088d97 100644 --- a/content/browser/web_contents/web_contents_android.h +++ b/content/browser/web_contents/web_contents_android.h @@ -114,6 +114,7 @@ class CONTENT_EXPORT WebContentsAndroid void ResumeMediaSession(JNIEnv* env, jobject obj); void SuspendMediaSession(JNIEnv* env, jobject obj); + void StopMediaSession(JNIEnv* env, jobject obj); base::android::ScopedJavaLocalRef<jstring> GetEncoding(JNIEnv* env, jobject obj) const; diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 1b066ba..fb770ca 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -3407,6 +3407,10 @@ void WebContentsImpl::SuspendMediaSession() { MediaSession::Get(this)->Suspend(); } +void WebContentsImpl::StopMediaSession() { + MediaSession::Get(this)->Stop(); +} + #endif // defined(OS_ANDROID) void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() { diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 180f4d6..95eb49a 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -366,6 +366,7 @@ class CONTENT_EXPORT WebContentsImpl void OnMediaSessionStateChanged(); void ResumeMediaSession() override; void SuspendMediaSession() override; + void StopMediaSession() override; base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() override; virtual WebContentsAndroid* GetWebContentsAndroid(); diff --git a/content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java b/content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java index 5584b3e..1f60a54 100644 --- a/content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java +++ b/content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java @@ -350,6 +350,11 @@ import java.util.UUID; } @Override + public void stopMediaSession() { + nativeStopMediaSession(mNativeWebContentsAndroid); + } + + @Override public String getEncoding() { return nativeGetEncoding(mNativeWebContentsAndroid); } @@ -449,5 +454,6 @@ import java.util.UUID; AccessibilitySnapshotCallback callback, float offsetY, float scrollX); private native void nativeResumeMediaSession(long nativeWebContentsAndroid); private native void nativeSuspendMediaSession(long nativeWebContentsAndroid); + private native void nativeStopMediaSession(long nativeWebContentsAndroid); private native String nativeGetEncoding(long nativeWebContentsAndroid); } diff --git a/content/public/android/java/src/org/chromium/content_public/browser/WebContents.java b/content/public/android/java/src/org/chromium/content_public/browser/WebContents.java index e916f82..99a5cb9 100644 --- a/content/public/android/java/src/org/chromium/content_public/browser/WebContents.java +++ b/content/public/android/java/src/org/chromium/content_public/browser/WebContents.java @@ -291,6 +291,11 @@ public interface WebContents extends Parcelable { void suspendMediaSession(); /** + * Stops the current media session. + */ + void stopMediaSession(); + + /** * Add an observer to the WebContents * * @param observer The observer to add. diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index 4ed6a40..803b816 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -672,6 +672,8 @@ class WebContents : public PageNavigator, virtual void ResumeMediaSession() = 0; // Requests to suspend the current media session. virtual void SuspendMediaSession() = 0; + // Requests to stop the current media session. + virtual void StopMediaSession() = 0; CONTENT_EXPORT static WebContents* FromJavaWebContents( jobject jweb_contents_android); |