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
This commit is contained in:
Alastor Wu
2016-10-27 09:59:55 +08:00
parent ec53186ff4
commit 47b76aa673
2 changed files with 38 additions and 0 deletions

View File

@@ -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<nsIObserverService> observerService =
services::GetObserverService();
if (NS_WARN_IF(!observerService)) {
return;
}
nsCOMPtr<nsISupportsPRUint64> 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
{