From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/eme/DetailedPromise.h | 104 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 dom/media/eme/DetailedPromise.h (limited to 'dom/media/eme/DetailedPromise.h') diff --git a/dom/media/eme/DetailedPromise.h b/dom/media/eme/DetailedPromise.h new file mode 100644 index 0000000000..02c774755f --- /dev/null +++ b/dom/media/eme/DetailedPromise.h @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef __DetailedPromise_h__ +#define __DetailedPromise_h__ + +#include "mozilla/dom/Promise.h" +#include "mozilla/Telemetry.h" +#include "EMEUtils.h" + +namespace mozilla::dom { + +/* + * This is pretty horrible; bug 1160445. + * Extend Promise to add custom DOMException messages on rejection. + * Get rid of this once we've ironed out EME errors in the wild. + */ +class DetailedPromise : public Promise { + public: + static already_AddRefed Create(nsIGlobalObject* aGlobal, + ErrorResult& aRv, + const nsACString& aName); + + template + void MaybeResolve(T&& aArg) { + EME_LOG("%s promise resolved", mName.get()); + MaybeReportTelemetry(eStatus::kSucceeded); + Promise::MaybeResolve(std::forward(aArg)); + } + + void MaybeReject(nsresult aArg) = delete; + void MaybeReject(nsresult aArg, const nsACString& aReason); + + void MaybeReject(ErrorResult&& aArg) = delete; + void MaybeReject(ErrorResult&& aArg, const nsACString& aReason); + + // Facilities for rejecting with various spec-defined exception values. +#define DOMEXCEPTION(name, err) \ + inline void MaybeRejectWith##name(const nsACString& aMessage) { \ + LogRejectionReason(static_cast(err), aMessage); \ + Promise::MaybeRejectWith##name(aMessage); \ + } \ + template \ + void MaybeRejectWith##name(const char(&aMessage)[N]) { \ + MaybeRejectWith##name(nsLiteralCString(aMessage)); \ + } + +#include "mozilla/dom/DOMExceptionNames.h" + +#undef DOMEXCEPTION + + template + void MaybeRejectWithTypeError(Ts&&... aMessageArgs) = delete; + + inline void MaybeRejectWithTypeError(const nsACString& aMessage) { + ErrorResult res; + res.ThrowTypeError(aMessage); + MaybeReject(std::move(res), aMessage); + } + + template + void MaybeRejectWithTypeError(const char (&aMessage)[N]) { + MaybeRejectWithTypeError(nsLiteralCString(aMessage)); + } + + template + void MaybeRejectWithRangeError(Ts&&... aMessageArgs) = delete; + + inline void MaybeRejectWithRangeError(const nsACString& aMessage) { + ErrorResult res; + res.ThrowRangeError(aMessage); + MaybeReject(std::move(res), aMessage); + } + + template + void MaybeRejectWithRangeError(const char (&aMessage)[N]) { + MaybeRejectWithRangeError(nsLiteralCString(aMessage)); + } + + private: + explicit DetailedPromise(nsIGlobalObject* aGlobal, const nsACString& aName); + + explicit DetailedPromise(nsIGlobalObject* aGlobal, const nsACString& aName, + Telemetry::HistogramID aSuccessLatencyProbe, + Telemetry::HistogramID aFailureLatencyProbe); + virtual ~DetailedPromise(); + + enum eStatus { kSucceeded, kFailed }; + void MaybeReportTelemetry(eStatus aStatus); + void LogRejectionReason(uint32_t aErrorCode, const nsACString& aReason); + + nsCString mName; + bool mResponded; + TimeStamp mStartTime; + Optional mSuccessLatencyProbe; + Optional mFailureLatencyProbe; +}; + +} // namespace mozilla::dom + +#endif // __DetailedPromise_h__ -- cgit v1.2.3