tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 57eb0ea52fe08d13c0b99e97a236da440f9da056
parent 596b5c2cfe64d63c2ac5e62b0ddf2ec94ce8acb8
Author: az <azebrowski@mozilla.com>
Date:   Mon,  1 Dec 2025 17:07:05 +0000

Bug 1993541 - Part 4: Use MediaCapabilitiesValidation to check DecodingInfo. r=pehrsons,media-playback-reviewers,padenot

Differential Revision: https://phabricator.services.mozilla.com/D263719

Diffstat:
Mdom/media/mediacapabilities/MediaCapabilities.cpp | 36++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/dom/media/mediacapabilities/MediaCapabilities.cpp b/dom/media/mediacapabilities/MediaCapabilities.cpp @@ -13,6 +13,7 @@ #include "AllocationPolicy.h" #include "DecoderTraits.h" #include "MP4Decoder.h" +#include "MediaCapabilitiesValidation.h" #include "MediaInfo.h" #include "MediaRecorder.h" #include "PDMFactory.h" @@ -42,6 +43,7 @@ mozilla::LazyLogModule sMediaCapabilitiesLog("MediaCapabilities"); DDMOZ_LOG(sMediaCapabilitiesLog, LogLevel::Debug, msg, ##__VA_ARGS__) namespace mozilla::dom { +using mediacaps::IsValidMediaDecodingConfiguration; static bool MediaCapabilitiesKeySystemConfigurationToMediaKeySystemConfiguration( @@ -184,6 +186,7 @@ MediaCapabilities::MediaCapabilities(nsIGlobalObject* aParent) : mParent(aParent) {} // https://w3c.github.io/media-capabilities/#dom-mediacapabilities-decodinginfo +// Section 2.5.2 DecodingInfo() Method already_AddRefed<Promise> MediaCapabilities::DecodingInfo( const MediaDecodingConfiguration& aConfiguration, ErrorResult& aRv) { RefPtr<Promise> promise = Promise::Create(mParent, aRv); @@ -191,29 +194,28 @@ already_AddRefed<Promise> MediaCapabilities::DecodingInfo( return nullptr; } - // If configuration is not a valid MediaConfiguration, return a Promise - // rejected with a TypeError. - if (!aConfiguration.mVideo.WasPassed() && - !aConfiguration.mAudio.WasPassed()) { - promise->MaybeRejectWithTypeError( - "'audio' or 'video' member of argument of " - "MediaCapabilities.decodingInfo"); + // Step 1: If configuration is not a valid MediaDecodingConfiguration, + // return a Promise rejected with a newly created TypeError. + if (auto configCheck = IsValidMediaDecodingConfiguration(aConfiguration); + configCheck.isErr()) { + RejectWithValidationResult(promise, configCheck.unwrapErr()); return promise.forget(); } - // If configuration.keySystemConfiguration exists, run the following substeps: + // Step 2: If configuration.keySystemConfiguration exists, + // run the following substeps: if (aConfiguration.mKeySystemConfiguration.WasPassed()) { - // If the global object is of type WorkerGlobalScope, return a Promise - // rejected with a newly created DOMException whose name is - // InvalidStateError. + // Step 2.1: If the global object is of type WorkerGlobalScope, + // return a Promise rejected with a newly created DOMException + // whose name is InvalidStateError. if (IsWorkerGlobal(mParent->GetGlobalJSObject())) { promise->MaybeRejectWithInvalidStateError( "key system configuration is not allowed in the worker scope"); return promise.forget(); } - // If the global object’s relevant settings object is a non-secure context, - // return a Promise rejected with a newly created DOMException whose name is - // SecurityError. + // Step 2.2 If the global object’s relevant settings object is a + // non-secure context, return a Promise rejected with a newly + // created DOMException whose name is SecurityError. if (auto* window = mParent->GetAsInnerWindow(); window && !window->IsSecureContext()) { promise->MaybeRejectWithSecurityError( @@ -222,8 +224,9 @@ already_AddRefed<Promise> MediaCapabilities::DecodingInfo( } } - // In parallel, run the Create a MediaCapabilitiesDecodingInfo algorithm with - // configuration and resolve p with its result. + // Step 3: Let p be a new Promise (already have it!) + // Step 4: In parallel, run the Create a MediaCapabilitiesDecodingInfo + // algorithm with configuration and resolve p with its result. CreateMediaCapabilitiesDecodingInfo(aConfiguration, aRv, promise); return promise.forget(); } @@ -788,3 +791,4 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaCapabilities) NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MediaCapabilities, mParent) } // namespace mozilla::dom +#undef LOG