From 10ed91bc28dd59fd4c9989121b8e4ca7c23cc0b2 Mon Sep 17 00:00:00 2001 From: Alastor Wu Date: Thu, 27 Oct 2016 09:59:55 +0800 Subject: [PATCH] Bug 1302453 - part1 : send new gecko event when media is resumed. r=baku We uses "media-playback" event to notify fennec media control about media start and end. However, if we resume media which was paused by media control, it won't send any notification to JAVA side so that the MediaControlService can't change the correct playing icon. Therefore, we create new event to inform this situation. MozReview-Commit-ID: zScaHxvHXM --HG-- extra : rebase_source : e1434840de36d8621a58fc7406b0f42673a2f3db --- dom/html/HTMLMediaElement.cpp | 34 ++++++++++++++++++++++++++++++++++ dom/html/HTMLMediaElement.h | 4 ++++ 2 files changed, 38 insertions(+) diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index d615dfe731c8..3270e96eb8c3 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -37,6 +37,8 @@ #include "nsContentUtils.h" #include "nsIRequest.h" #include "nsQueryObject.h" +#include "nsIObserverService.h" +#include "nsISupportsPrimitives.h" #include "nsIScriptSecurityManager.h" #include "nsIXPConnect.h" @@ -5945,6 +5947,7 @@ HTMLMediaElement::SetAudioChannelSuspended(SuspendTypes aSuspend) return; } + MaybeNotifyMediaResumed(aSuspend); mAudioChannelSuspended = aSuspend; MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug, ("HTMLMediaElement, SetAudioChannelSuspended, this = %p, " @@ -6427,6 +6430,37 @@ HTMLMediaElement::IsAudible() const return true; } +void +HTMLMediaElement::MaybeNotifyMediaResumed(SuspendTypes aSuspend) +{ + // In fennec, we should send the notification when media is resumed from the + // pause-disposable which was called by media control. + if (mAudioChannelSuspended != nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE && + aSuspend != nsISuspendedTypes::NONE_SUSPENDED) { + return; + } + + uint64_t windowID = mAudioChannelAgent->WindowID(); + NS_DispatchToMainThread(NS_NewRunnableFunction([windowID]() -> void { + nsCOMPtr observerService = + services::GetObserverService(); + if (NS_WARN_IF(!observerService)) { + return; + } + + nsCOMPtr wrapper = + do_CreateInstance(NS_SUPPORTS_PRUINT64_CONTRACTID); + if (NS_WARN_IF(!wrapper)) { + return; + } + + wrapper->SetData(windowID); + observerService->NotifyObservers(wrapper, + "media-playback-resumed", + u"active"); + })); +} + bool HTMLMediaElement::HaveFailedWithSourceNotSupportedError() const { diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h index e337d4ec9f51..14ea5ddee2a7 100644 --- a/dom/html/HTMLMediaElement.h +++ b/dom/html/HTMLMediaElement.h @@ -1268,6 +1268,10 @@ protected: void OpenUnsupportedMediaWithExtenalAppIfNeeded(); + // It's used for fennec only, send the notification when the user resumes the + // media which was paused by media control. + void MaybeNotifyMediaResumed(SuspendTypes aSuspend); + class nsAsyncEventRunner; using nsGenericHTMLElement::DispatchEvent; // For nsAsyncEventRunner.