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

Side by Side Diff: content/browser/media/session/pepper/pepper_web_contents_observer.cc

Issue 2060933002: Let Flash join and be controlled by media session (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pepper_to_contents
Patch Set: modified when to add/remove player to/from MediaSession Created 4 years, 6 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
(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/pepper/pepper_web_contents_observer.h"
6
7 #include "base/feature_list.h"
8 #include "base/logging.h"
9 #include "content/browser/media/session/media_session.h"
10 #include "content/browser/media/session/pepper/pepper_player_delegate.h"
11 #include "content/common/frame_messages.h"
12 #include "ipc/ipc_message_macros.h"
13 #include "media/base/media_switches.h"
14
15 namespace content {
16
17 PepperWebContentsObserver::PepperWebContentsObserver(WebContents *web_contents)
18 : WebContentsObserver(web_contents),
19 media_session_(MediaSession::Get(web_contents)) {}
20
21 PepperWebContentsObserver::~PepperWebContentsObserver() = default;
22
23 void PepperWebContentsObserver::WebContentsDestroyed() {
24 for (auto& instance_player : players_map_) {
25 OnPepperStopsPlayback(instance_player.first);
26 }
27 }
28
29 void PepperWebContentsObserver::PepperInstanceCreated(int32_t pp_instance) {
30 DCHECK_EQ(players_map_.count(pp_instance), 0u);
31 players_map_[pp_instance].reset(new PepperPlayerDelegate(this, pp_instance));
32 }
33
34 void PepperWebContentsObserver::PepperInstanceDeleted(int32_t pp_instance) {
35 DCHECK_EQ(players_map_.count(pp_instance), 1u);
36
37 // Only remove the player from MediaSession once the Pepper instance
38 // is deleted.
39 if (active_players_.count(pp_instance))
40 media_session_->RemovePlayer(players_map_[pp_instance].get(), 0);
41
42 players_map_.erase(pp_instance);
43 active_players_.erase(pp_instance);
44 }
45
46 bool PepperWebContentsObserver::OnMessageReceived(
47 const IPC::Message& msg, RenderFrameHost* render_frame_host) {
48 if (!base::FeatureList::IsEnabled(media::kFlashJoinsMediaSession))
49 return true;
50
51 bool handled = true;
52 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(PepperWebContentsObserver, msg,
53 render_frame_host)
54 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
55 OnPepperStartsPlayback)
56 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
57 OnPepperStopsPlayback)
58 IPC_MESSAGE_UNHANDLED(handled = false)
59 IPC_END_MESSAGE_MAP()
60
61 return handled;
62 }
63
64 void PepperWebContentsObserver::OnPepperStartsPlayback(int32_t pp_instance) {
65 DCHECK_EQ(players_map_.count(pp_instance), 1u);
66
67 if (active_players_.count(pp_instance))
68 // Only add the player into MediaSession on the first time it
69 // starts playback.
70 return;
71
72 media_session_->AddPlayer(players_map_[pp_instance].get(), 0,
73 MediaSession::Type::Content);
74 active_players_.insert(pp_instance);
75 }
76
77 void PepperWebContentsObserver::OnPepperStopsPlayback(int32_t pp_instance) {
78 }
mlamouri (slow - plz ping) 2016/06/24 15:33:32 Why do you do nothing here? Actually, why does cre
Zhiqiang Zhang (Slow) 2016/06/24 17:43:21 I was thinking letting one flash join MediaSession
79
80 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698