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

Side by Side Diff: content/browser/media/session/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: addressed Mounir's comments 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_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_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
20 PepperWebContentsObserver::~PepperWebContentsObserver() = default;
21
22 void PepperWebContentsObserver::WebContentsDestroyed() {
23 for (auto& instance_player : players_map_) {
24 OnPepperStopsPlayback(instance_player.first);
25 }
26 }
27
28 bool PepperWebContentsObserver::OnMessageReceived(
29 const IPC::Message& msg, RenderFrameHost* render_frame_host) {
30 if (!base::FeatureList::IsEnabled(media::kFlashJoinsMediaSession))
31 return true;
32
33 bool handled = true;
34 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(PepperWebContentsObserver, msg,
35 render_frame_host)
36 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
37 OnPepperStartsPlayback)
38 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
39 OnPepperStopsPlayback)
40 IPC_MESSAGE_UNHANDLED(handled = false)
41 IPC_END_MESSAGE_MAP()
42
43 return handled;
44 }
45
46 void PepperWebContentsObserver::PepperInstanceCreated(int32_t pp_instance) {}
47
48 void PepperWebContentsObserver::PepperInstanceDeleted(int32_t pp_instance) {
49 OnPepperStopsPlayback(pp_instance);
50 }
51
52 void PepperWebContentsObserver::OnPepperStartsPlayback(int32_t pp_instance) {
53 if (players_map_.count(pp_instance))
54 return;
55
56 players_map_[pp_instance].reset(new PepperPlayerDelegate(this, pp_instance));
57 MediaSession::Get(web_contents())->AddPlayer(
58 players_map_[pp_instance].get(), 0, MediaSession::Type::Content);
59 }
60
61 void PepperWebContentsObserver::OnPepperStopsPlayback(int32_t pp_instance) {
62 DCHECK_EQ(players_map_.count(pp_instance), 1u);
63
64 // Only remove the player from MediaSession once the Pepper instance
65 // is deleted.
66 if (players_map_.count(pp_instance)) {
67 MediaSession::Get(web_contents())->RemovePlayer(
68 players_map_[pp_instance].get(), 0);
69 }
70
71 players_map_.erase(pp_instance);
jochen (gone - plz use gerrit) 2016/06/27 11:47:11 why is this not in the previous if?
Zhiqiang Zhang (Slow) 2016/06/28 18:53:24 Sorry, this is code in an old patch. Fixed.
72 }
73
74 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698