mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 859824 - MediaElement creates a WakeLock when playing audio. r=jlebar
This commit is contained in:
parent
15a1dca0e3
commit
61eecbe753
@ -518,14 +518,25 @@ protected:
|
||||
|
||||
class WakeLockBoolWrapper {
|
||||
public:
|
||||
WakeLockBoolWrapper(bool val = false) : mValue(val), mOuter(nullptr), mWakeLock(nullptr) {}
|
||||
void SetOuter(HTMLMediaElement* outer) { mOuter = outer; }
|
||||
operator bool() const { return mValue; }
|
||||
WakeLockBoolWrapper(bool val = false)
|
||||
: mValue(val), mCanPlay(true), mOuter(nullptr) {}
|
||||
|
||||
void SetOuter(nsHTMLMediaElement* outer) { mOuter = outer; }
|
||||
void SetCanPlay(bool aCanPlay);
|
||||
|
||||
operator bool() { return mValue; }
|
||||
|
||||
WakeLockBoolWrapper& operator=(bool val);
|
||||
|
||||
bool operator !() const { return !mValue; }
|
||||
|
||||
private:
|
||||
void UpdateWakeLock();
|
||||
|
||||
bool mValue;
|
||||
HTMLMediaElement* mOuter;
|
||||
bool mCanPlay;
|
||||
nsHTMLMediaElement* mOuter;
|
||||
|
||||
nsCOMPtr<nsIDOMMozWakeLock> mWakeLock;
|
||||
};
|
||||
|
||||
|
@ -2088,21 +2088,47 @@ NS_IMETHODIMP HTMLMediaElement::Play()
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
HTMLMediaElement::WakeLockBoolWrapper& HTMLMediaElement::WakeLockBoolWrapper::operator=(bool val) {
|
||||
if (mValue == val)
|
||||
nsHTMLMediaElement::WakeLockBoolWrapper&
|
||||
nsHTMLMediaElement::WakeLockBoolWrapper::operator=(bool val) {
|
||||
if (mValue == val) {
|
||||
return *this;
|
||||
if (!mWakeLock && !val && mOuter) {
|
||||
}
|
||||
|
||||
mValue = val;
|
||||
UpdateWakeLock();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLMediaElement::WakeLockBoolWrapper::SetCanPlay(bool aCanPlay)
|
||||
{
|
||||
mCanPlay = aCanPlay;
|
||||
UpdateWakeLock();
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLMediaElement::WakeLockBoolWrapper::UpdateWakeLock()
|
||||
{
|
||||
if (!mOuter) {
|
||||
return;
|
||||
|
||||
}
|
||||
bool playing = (!mValue && mCanPlay);
|
||||
|
||||
if (playing) {
|
||||
nsCOMPtr<nsIPowerManagerService> pmService =
|
||||
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(pmService, *this);
|
||||
NS_ENSURE_TRUE_VOID(pmService);
|
||||
|
||||
pmService->NewWakeLock(NS_LITERAL_STRING("Playing_media"), mOuter->OwnerDoc()->GetWindow(), getter_AddRefs(mWakeLock));
|
||||
} else if (mWakeLock && val) {
|
||||
mWakeLock->Unlock();
|
||||
if (!mWakeLock) {
|
||||
pmService->NewWakeLock(NS_LITERAL_STRING("cpu"),
|
||||
mOuter->OwnerDoc()->GetWindow(),
|
||||
getter_AddRefs(mWakeLock));
|
||||
}
|
||||
} else if (mWakeLock) {
|
||||
// Wakelock 'unlocks' itself in its destructor.
|
||||
mWakeLock = nullptr;
|
||||
}
|
||||
mValue = val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool HTMLMediaElement::ParseAttribute(int32_t aNamespaceID,
|
||||
@ -3715,6 +3741,7 @@ void HTMLMediaElement::UpdateAudioChannelPlayingState()
|
||||
if (mPlayingThroughTheAudioChannel) {
|
||||
bool canPlay;
|
||||
mAudioChannelAgent->StartPlaying(&canPlay);
|
||||
mPaused.SetCanPlay(canPlay);
|
||||
} else {
|
||||
mAudioChannelAgent->StopPlaying();
|
||||
mAudioChannelAgent = nullptr;
|
||||
@ -3728,6 +3755,7 @@ NS_IMETHODIMP HTMLMediaElement::CanPlayChanged(bool canPlay)
|
||||
NS_ENSURE_TRUE(nsContentUtils::IsCallerChrome(), NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
UpdateChannelMuteState(canPlay);
|
||||
mPaused.SetCanPlay(canPlay);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user