Bug 1816170 - Disable perftest-on-autoland cron. r=aglavic
[gecko.git] / dom / html / PlayPromise.cpp
blobee33b3ad6854392f91f66b7b0fcc4d449e809f7b
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);
26 /* static */
27 already_AddRefed<PlayPromise> PlayPromise::Create(nsIGlobalObject* aGlobal,
28 ErrorResult& aRv) {
29 RefPtr<PlayPromise> promise = new PlayPromise(aGlobal);
30 promise->CreateWrapper(aRv);
31 return aRv.Failed() ? nullptr : promise.forget();
34 /* static */
35 void PlayPromise::ResolvePromisesWithUndefined(
36 const PlayPromiseArr& aPromises) {
37 for (const auto& promise : aPromises) {
38 promise->MaybeResolveWithUndefined();
42 /* static */
43 void PlayPromise::RejectPromises(const PlayPromiseArr& aPromises,
44 nsresult aError) {
45 for (const auto& promise : aPromises) {
46 promise->MaybeReject(aError);
50 void PlayPromise::MaybeResolveWithUndefined() {
51 if (mFulfilled) {
52 return;
54 mFulfilled = true;
55 PLAY_PROMISE_LOG("PlayPromise %p resolved with undefined", this);
56 Promise::MaybeResolveWithUndefined();
59 static const char* ToPlayResultStr(nsresult aReason) {
60 switch (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:
68 return "AbortErr";
69 default:
70 return "UnknownErr";
74 void PlayPromise::MaybeReject(nsresult aReason) {
75 if (mFulfilled) {
76 return;
78 mFulfilled = true;
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