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

Side by Side Diff: content/browser/media/media_web_contents_observer.cc

Issue 1570043002: Implement MediaSession on top of the WebMediaPlayerDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_session
Patch Set: Created 4 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/media/media_web_contents_observer.h" 5 #include "content/browser/media/media_web_contents_observer.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/browser/power_save_blocker_impl.h" 9 #include "content/browser/power_save_blocker_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h" 10 #include "content/browser/web_contents/web_contents_impl.h"
(...skipping 23 matching lines...) Expand all
34 } 34 }
35 } 35 }
36 36
37 bool MediaWebContentsObserver::OnMessageReceived( 37 bool MediaWebContentsObserver::OnMessageReceived(
38 const IPC::Message& msg, 38 const IPC::Message& msg,
39 RenderFrameHost* render_frame_host) { 39 RenderFrameHost* render_frame_host) {
40 bool handled = true; 40 bool handled = true;
41 // TODO(dalecurtis): These should no longer be FrameHostMsg. 41 // TODO(dalecurtis): These should no longer be FrameHostMsg.
42 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(MediaWebContentsObserver, msg, 42 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(MediaWebContentsObserver, msg,
43 render_frame_host) 43 render_frame_host)
44 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaDestroyedNotification,
45 OnMediaDestroyedNotification)
44 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification, 46 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
45 OnMediaPlayingNotification) 47 OnMediaPlayingNotification)
46 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification, 48 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
47 OnMediaPausedNotification) 49 OnMediaPausedNotification)
48 IPC_MESSAGE_UNHANDLED(handled = false) 50 IPC_MESSAGE_UNHANDLED(handled = false)
49 IPC_END_MESSAGE_MAP() 51 IPC_END_MESSAGE_MAP()
50 return handled; 52 return handled;
51 } 53 }
52 54
55 void MediaWebContentsObserver::OnMediaDestroyedNotification(
56 RenderFrameHost* render_frame_host,
57 int64_t player_cookie) {
58 OnMediaPausedNotification(render_frame_host, player_cookie, true);
59 }
60
53 void MediaWebContentsObserver::OnMediaPlayingNotification( 61 void MediaWebContentsObserver::OnMediaPlayingNotification(
54 RenderFrameHost* render_frame_host, 62 RenderFrameHost* render_frame_host,
55 int64_t player_cookie, 63 int64_t player_cookie,
56 bool has_video, 64 bool has_video,
57 bool has_audio, 65 bool has_audio,
58 bool is_remote) { 66 bool is_remote,
67 base::TimeDelta duration) {
59 // Ignore the videos playing remotely and don't hold the wake lock for the 68 // Ignore the videos playing remotely and don't hold the wake lock for the
60 // screen. TODO(dalecurtis): Is this correct? It means observers will not 69 // screen. TODO(dalecurtis): Is this correct? It means observers will not
61 // receive play and pause messages. 70 // receive play and pause messages.
62 if (is_remote) 71 if (is_remote)
63 return; 72 return;
64 73
65 const MediaPlayerId id(render_frame_host, player_cookie); 74 const MediaPlayerId id(render_frame_host, player_cookie);
66 if (has_audio) { 75 if (has_audio) {
67 AddMediaPlayerEntry(id, &active_audio_players_); 76 AddMediaPlayerEntry(id, &active_audio_players_);
68 77
(...skipping 15 matching lines...) Expand all
84 } 93 }
85 } 94 }
86 95
87 // Notify observers of the new player. 96 // Notify observers of the new player.
88 DCHECK(has_audio || has_video); 97 DCHECK(has_audio || has_video);
89 static_cast<WebContentsImpl*>(web_contents())->MediaStartedPlaying(id); 98 static_cast<WebContentsImpl*>(web_contents())->MediaStartedPlaying(id);
90 } 99 }
91 100
92 void MediaWebContentsObserver::OnMediaPausedNotification( 101 void MediaWebContentsObserver::OnMediaPausedNotification(
93 RenderFrameHost* render_frame_host, 102 RenderFrameHost* render_frame_host,
94 int64_t player_cookie) { 103 int64_t player_cookie,
104 bool reached_end_of_stream) {
95 const MediaPlayerId id(render_frame_host, player_cookie); 105 const MediaPlayerId id(render_frame_host, player_cookie);
96 const bool removed_audio = RemoveMediaPlayerEntry(id, &active_audio_players_); 106 const bool removed_audio = RemoveMediaPlayerEntry(id, &active_audio_players_);
97 const bool removed_video = RemoveMediaPlayerEntry(id, &active_video_players_); 107 const bool removed_video = RemoveMediaPlayerEntry(id, &active_video_players_);
98 MaybeReleasePowerSaveBlockers(); 108 MaybeReleasePowerSaveBlockers();
99 109
100 if (removed_audio || removed_video) { 110 if (removed_audio || removed_video) {
101 // Notify observers the player has been "paused". 111 // Notify observers the player has been "paused".
102 static_cast<WebContentsImpl*>(web_contents())->MediaStoppedPlaying(id); 112 static_cast<WebContentsImpl*>(web_contents())->MediaStoppedPlaying(id);
103 } 113 }
104 } 114 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 if (it == player_map->end()) 213 if (it == player_map->end())
204 return; 214 return;
205 215
206 for (int64_t player_cookie : it->second) 216 for (int64_t player_cookie : it->second)
207 removed_players->insert(MediaPlayerId(render_frame_host, player_cookie)); 217 removed_players->insert(MediaPlayerId(render_frame_host, player_cookie));
208 218
209 player_map->erase(it); 219 player_map->erase(it);
210 } 220 }
211 221
212 } // namespace content 222 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698