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

Unified Diff: content/browser/media/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: added TODO 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/media/pepper/pepper_web_contents_observer.cc
diff --git a/content/browser/media/pepper/pepper_web_contents_observer.cc b/content/browser/media/pepper/pepper_web_contents_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..38d0fc495586509744192d10f84febc46220bf19
--- /dev/null
+++ b/content/browser/media/pepper/pepper_web_contents_observer.cc
@@ -0,0 +1,74 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/media/pepper/pepper_web_contents_observer.h"
+
+#include "base/feature_list.h"
+#include "base/logging.h"
+#include "content/browser/media/pepper/pepper_player_delegate.h"
+#include "content/browser/media/session/media_session.h"
+#include "content/common/frame_messages.h"
+#include "ipc/ipc_message_macros.h"
+#include "media/base/media_switches.h"
+
+namespace content {
+
+PepperWebContentsObserver::PepperWebContentsObserver(WebContents *web_contents)
+ : WebContentsObserver(web_contents),
+ media_session_(MediaSession::Get(web_contents)) {}
+
+PepperWebContentsObserver::~PepperWebContentsObserver() {
+}
mlamouri (slow - plz ping) 2016/06/23 13:23:20 `= default;` instead of `{}`.
Zhiqiang Zhang (Slow) 2016/06/24 17:43:20 Done.
+
+void PepperWebContentsObserver::WebContentsDestroyed() {
+ for (auto& instance_player : players_map_) {
+ OnPepperStopsPlayback(instance_player.first);
+ }
+}
+
+void PepperWebContentsObserver::PepperInstanceCreated(int32_t pp_instance) {
+ DCHECK_EQ(players_map_.count(pp_instance), 0u);
+ players_map_[pp_instance].reset(new PepperPlayerDelegate(this, pp_instance));
+}
+
+void PepperWebContentsObserver::PepperInstanceDeleted(int32_t pp_instance) {
+ DCHECK_EQ(players_map_.count(pp_instance), 1u);
+ OnPepperStopsPlayback(pp_instance);
+ players_map_.erase(pp_instance);
+}
+
+bool PepperWebContentsObserver::OnMessageReceived(
+ const IPC::Message& msg, RenderFrameHost* render_frame_host) {
+ if (!base::FeatureList::IsEnabled(media::kFlashJoinsMediaSession))
+ return true;
+ bool handled = true;
mlamouri (slow - plz ping) 2016/06/23 13:23:20 style: add an empty line :)
Zhiqiang Zhang (Slow) 2016/06/24 17:43:20 Done.
+ IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(PepperWebContentsObserver, msg,
+ render_frame_host)
+ IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
+ OnPepperStartsPlayback)
+ IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
+ OnPepperStopsPlayback)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
mlamouri (slow - plz ping) 2016/06/23 13:23:20 ... here too :)
Zhiqiang Zhang (Slow) 2016/06/24 17:43:20 Done.
+}
+
+void PepperWebContentsObserver::OnPepperStartsPlayback(int32_t pp_instance) {
+ // TODO(zqzhang): a pepper instance can start playback multiple times. Since
+ // we cannot trully control pepper playback, it may starts to play at any time
+ // interrupting other players. Working on a variation such that pepper only
+ // gains audio focus at the first time it starts playback, duck it whenever
+ // another player starts playback, and unduck pepper when no other players are
+ // playing.
+ DCHECK_EQ(players_map_.count(pp_instance), 1u);
+ media_session_->AddPlayer(players_map_[pp_instance].get(), 0,
+ MediaSession::Type::Content);
+ players_map_[pp_instance]->OnSetVolume(0, 1.0f);
+}
+
+void PepperWebContentsObserver::OnPepperStopsPlayback(int32_t pp_instance) {
+ if (!players_map_.count(pp_instance)) return;
mlamouri (slow - plz ping) 2016/06/23 13:23:20 style: return needs to go on a new line.
Zhiqiang Zhang (Slow) 2016/06/24 17:43:20 Done.
+ media_session_->RemovePlayer(players_map_[pp_instance].get(), 0);
+}
+}
mlamouri (slow - plz ping) 2016/06/23 13:23:20 style: add empty line above and " // namespace co
Zhiqiang Zhang (Slow) 2016/06/24 17:43:20 Done.

Powered by Google App Engine
This is Rietveld 408576698