From 4bde50109e74b276d9adca60028df8004b2bb29b Mon Sep 17 00:00:00 2001 From: alwu Date: Fri, 3 Jan 2020 01:27:24 +0000 Subject: [PATCH] Bug 1571493 - part5 : use 'MediaControlKeysEventHandler' to deliver control keys event. r=chunmin Use `MediaControlKeysEventHandler` to handle the control keys event, which can always find corresponding controlled media if there are some. Differential Revision: https://phabricator.services.mozilla.com/D57575 --HG-- extra : moz-landing-system : lando --- dom/media/mediacontrol/PlaybackController.cpp | 30 ++++++++++--------- dom/media/mediacontrol/PlaybackController.h | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/dom/media/mediacontrol/PlaybackController.cpp b/dom/media/mediacontrol/PlaybackController.cpp index ec59ebc4f07a..074d93546b7f 100644 --- a/dom/media/mediacontrol/PlaybackController.cpp +++ b/dom/media/mediacontrol/PlaybackController.cpp @@ -18,11 +18,7 @@ namespace dom { PlaybackController::PlaybackController(BrowsingContext* aContext) { MOZ_ASSERT(aContext); - // TODO : Because of bug 1593826, now we can't ganrantee that we always have - // the outer window. In the ideal situation, we should always provide a - // correct browsing context which has an outer window, this would be fixed in - // bug 1593826. - mWindow = aContext->GetDOMWindow(); + mBC = aContext; } void PlaybackController::Play() { @@ -40,18 +36,22 @@ void PlaybackController::Play() { */ // Our default behavior is to play all media elements within this window and // its children. - if (mWindow) { - LOG("Handle 'play' in default behavior"); - mWindow->SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED); + LOG("Handle 'play' in default behavior"); + RefPtr receiver = + ContentControlKeyEventReceiver::Get(mBC); + if (receiver) { + receiver->OnKeyPressed(MediaControlKeysEvent::ePlay); } }; void PlaybackController::Pause() { // TODO : same as Play(), we would provide default action handling if current // media session doesn't have an action handler. - if (mWindow) { - LOG("Handle 'pause' in default behavior"); - mWindow->SetMediaSuspend(nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE); + LOG("Handle 'pause' in default behavior"); + RefPtr receiver = + ContentControlKeyEventReceiver::Get(mBC); + if (receiver) { + receiver->OnKeyPressed(MediaControlKeysEvent::ePause); } } @@ -83,9 +83,11 @@ void PlaybackController::SkipAd() { void PlaybackController::Stop() { // TODO : same as Play(), we would provide default action handling if current // media session doesn't have an action handler. - if (mWindow) { - LOG("Handle 'stop' in default behavior"); - mWindow->SetMediaSuspend(nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE); + LOG("Handle 'stop' in default behavior"); + RefPtr receiver = + ContentControlKeyEventReceiver::Get(mBC); + if (receiver) { + receiver->OnKeyPressed(MediaControlKeysEvent::eStop); } } diff --git a/dom/media/mediacontrol/PlaybackController.h b/dom/media/mediacontrol/PlaybackController.h index ba7e1a16a098..93a4dcac2fe4 100644 --- a/dom/media/mediacontrol/PlaybackController.h +++ b/dom/media/mediacontrol/PlaybackController.h @@ -47,7 +47,7 @@ class MOZ_STACK_CLASS PlaybackController { void SeekTo(); private: - RefPtr mWindow; + RefPtr mBC; }; class MediaActionHandler {