diff options
author | mlamouri <mlamouri@chromium.org> | 2016-03-11 20:47:52 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-12 04:49:21 +0000 |
commit | 91873409e26ae1547dcd759735348884823f66ad (patch) | |
tree | 516c4b5b460dae44df1bd75bc0cf720509684111 /content/browser/media/media_web_contents_observer.cc | |
parent | 6b5a389af3231391673ca3654034571a17a53034 (diff) | |
download | chromium_src-91873409e26ae1547dcd759735348884823f66ad.zip chromium_src-91873409e26ae1547dcd759735348884823f66ad.tar.gz chromium_src-91873409e26ae1547dcd759735348884823f66ad.tar.bz2 |
Make MediaSession a runtime-enabled feature on Desktop.
At the moment, it's only compiled on Android, this CL compiles it on all platforms
but it's only enabled by default on Android. Other platforms have to pass
--enable-default-media-session flag to the command line.
This CL move all the media session related files from content/browser/media/android/
to content/browser/media/session/ and tear down the Android specific code from
MediaSession into a delegate. The Desktop delegate simply pauses other tabs when a
media session gets activated in a tab.
It is also moving the MediaSessionController handling to a separate class so it
can move from MediaWebContentsObserverAndroid to MediaWebContentsObserver easily.
BUG=587471
Review URL: https://codereview.chromium.org/1698933004
Cr-Commit-Position: refs/heads/master@{#380850}
Diffstat (limited to 'content/browser/media/media_web_contents_observer.cc')
-rw-r--r-- | content/browser/media/media_web_contents_observer.cc | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/content/browser/media/media_web_contents_observer.cc b/content/browser/media/media_web_contents_observer.cc index 1123974..654f99c 100644 --- a/content/browser/media/media_web_contents_observer.cc +++ b/content/browser/media/media_web_contents_observer.cc @@ -26,7 +26,8 @@ static base::LazyInstance<AudibleMetrics>::Leaky g_audible_metrics = } // anonymous namespace MediaWebContentsObserver::MediaWebContentsObserver(WebContents* web_contents) - : WebContentsObserver(web_contents) {} + : WebContentsObserver(web_contents), + session_controllers_manager_(this) {} MediaWebContentsObserver::~MediaWebContentsObserver() {} @@ -37,6 +38,7 @@ void MediaWebContentsObserver::WebContentsDestroyed() { void MediaWebContentsObserver::RenderFrameDeleted( RenderFrameHost* render_frame_host) { ClearPowerSaveBlockers(render_frame_host); + session_controllers_manager_.RenderFrameDeleted(render_frame_host); } void MediaWebContentsObserver::MaybeUpdateAudibleState() { @@ -93,19 +95,26 @@ void MediaWebContentsObserver::OnMediaDestroyed( OnMediaPaused(render_frame_host, delegate_id, true); } - void MediaWebContentsObserver::OnMediaPaused(RenderFrameHost* render_frame_host, int delegate_id, bool reached_end_of_stream) { - const MediaPlayerId id(render_frame_host, delegate_id); - const bool removed_audio = RemoveMediaPlayerEntry(id, &active_audio_players_); - const bool removed_video = RemoveMediaPlayerEntry(id, &active_video_players_); + const MediaPlayerId player_id(render_frame_host, delegate_id); + const bool removed_audio = + RemoveMediaPlayerEntry(player_id, &active_audio_players_); + const bool removed_video = + RemoveMediaPlayerEntry(player_id, &active_video_players_); MaybeReleasePowerSaveBlockers(); if (removed_audio || removed_video) { // Notify observers the player has been "paused". - static_cast<WebContentsImpl*>(web_contents())->MediaStoppedPlaying(id); + static_cast<WebContentsImpl*>(web_contents()) + ->MediaStoppedPlaying(player_id); } + + if (reached_end_of_stream) + session_controllers_manager_.OnEnd(player_id); + else + session_controllers_manager_.OnPause(player_id); } void MediaWebContentsObserver::OnMediaPlaying( @@ -143,6 +152,11 @@ void MediaWebContentsObserver::OnMediaPlaying( } } + if (!session_controllers_manager_.RequestPlay( + id, has_audio, is_remote, duration)) { + return; + } + // Notify observers of the new player. DCHECK(has_audio || has_video); static_cast<WebContentsImpl*>(web_contents())->MediaStartedPlaying(id); |