1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/PlayPromise.h"
8 #include "mozilla/Logging.h"
9 #include "mozilla/Telemetry.h"
11 extern mozilla::LazyLogModule gMediaElementLog
;
13 #define PLAY_PROMISE_LOG(msg, ...) \
14 MOZ_LOG(gMediaElementLog, LogLevel::Debug, (msg, ##__VA_ARGS__))
16 namespace mozilla::dom
{
18 PlayPromise::PlayPromise(nsIGlobalObject
* aGlobal
) : Promise(aGlobal
) {}
20 PlayPromise::~PlayPromise() {
21 if (!mFulfilled
&& PromiseObj()) {
22 MaybeReject(NS_ERROR_DOM_ABORT_ERR
);
27 already_AddRefed
<PlayPromise
> PlayPromise::Create(nsIGlobalObject
* aGlobal
,
29 RefPtr
<PlayPromise
> promise
= new PlayPromise(aGlobal
);
30 promise
->CreateWrapper(aRv
);
31 return aRv
.Failed() ? nullptr : promise
.forget();
35 void PlayPromise::ResolvePromisesWithUndefined(
36 const PlayPromiseArr
& aPromises
) {
37 for (const auto& promise
: aPromises
) {
38 promise
->MaybeResolveWithUndefined();
43 void PlayPromise::RejectPromises(const PlayPromiseArr
& aPromises
,
45 for (const auto& promise
: aPromises
) {
46 promise
->MaybeReject(aError
);
50 void PlayPromise::MaybeResolveWithUndefined() {
55 PLAY_PROMISE_LOG("PlayPromise %p resolved with undefined", this);
56 Promise::MaybeResolveWithUndefined();
59 static const char* ToPlayResultStr(nsresult aReason
) {
61 case NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR
:
62 return "NotAllowedErr";
63 case NS_ERROR_DOM_MEDIA_NOT_SUPPORTED_ERR
:
64 return "SrcNotSupportedErr";
65 case NS_ERROR_DOM_MEDIA_ABORT_ERR
:
66 return "PauseAbortErr";
67 case NS_ERROR_DOM_ABORT_ERR
:
74 void PlayPromise::MaybeReject(nsresult aReason
) {
79 PLAY_PROMISE_LOG("PlayPromise %p rejected with 0x%x (%s)", this,
80 static_cast<uint32_t>(aReason
), ToPlayResultStr(aReason
));
81 Promise::MaybeReject(aReason
);
84 } // namespace mozilla::dom