mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 01:35:35 +00:00
Bug 1609861 part 5. Stop using NS_ERROR_DOM_TYPE_ERR in IsTypeSupported. r=jya
Differential Revision: https://phabricator.services.mozilla.com/D60223 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
5740554e85
commit
fb61b9fd86
@ -411,12 +411,14 @@ static bool CanDecryptAndDecode(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (aContainerSupport.Decrypts(codec) &&
|
||||
NS_SUCCEEDED(
|
||||
MediaSource::IsTypeSupported(aContentType, aDiagnostics))) {
|
||||
// GMP can decrypt and is allowed to return compressed samples to
|
||||
// Gecko to decode, and Gecko has a decoder.
|
||||
continue;
|
||||
if (aContainerSupport.Decrypts(codec)) {
|
||||
IgnoredErrorResult rv;
|
||||
MediaSource::IsTypeSupported(aContentType, aDiagnostics, rv);
|
||||
if (!rv.Failed()) {
|
||||
// GMP can decrypt and is allowed to return compressed samples to
|
||||
// Gecko to decode, and Gecko has a decoder.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Neither the GMP nor Gecko can both decrypt and decode. We don't
|
||||
|
@ -534,8 +534,11 @@ Maybe<MediaContainerType> MediaCapabilities::CheckAudioConfiguration(
|
||||
}
|
||||
|
||||
bool MediaCapabilities::CheckTypeForMediaSource(const nsAString& aType) {
|
||||
return NS_SUCCEEDED(MediaSource::IsTypeSupported(
|
||||
aType, nullptr /* DecoderDoctorDiagnostics */));
|
||||
IgnoredErrorResult rv;
|
||||
MediaSource::IsTypeSupported(aType, nullptr /* DecoderDoctorDiagnostics */,
|
||||
rv);
|
||||
|
||||
return !rv.Failed();
|
||||
}
|
||||
|
||||
bool MediaCapabilities::CheckTypeForFile(const nsAString& aType) {
|
||||
|
@ -88,20 +88,23 @@ static bool IsWebMForced(DecoderDoctorDiagnostics* aDiagnostics) {
|
||||
namespace dom {
|
||||
|
||||
/* static */
|
||||
nsresult MediaSource::IsTypeSupported(const nsAString& aType,
|
||||
DecoderDoctorDiagnostics* aDiagnostics) {
|
||||
void MediaSource::IsTypeSupported(const nsAString& aType,
|
||||
DecoderDoctorDiagnostics* aDiagnostics,
|
||||
ErrorResult& aRv) {
|
||||
if (aType.IsEmpty()) {
|
||||
return NS_ERROR_DOM_TYPE_ERR;
|
||||
return aRv.ThrowTypeError(u"Empty type");
|
||||
}
|
||||
|
||||
Maybe<MediaContainerType> containerType = MakeMediaContainerType(aType);
|
||||
if (!containerType) {
|
||||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
|
||||
"Unknown type");
|
||||
}
|
||||
|
||||
if (DecoderTraits::CanHandleContainerType(*containerType, aDiagnostics) ==
|
||||
CANPLAY_NO) {
|
||||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
|
||||
"Can't play type");
|
||||
}
|
||||
|
||||
// Now we know that this media type could be played.
|
||||
@ -110,9 +113,12 @@ nsresult MediaSource::IsTypeSupported(const nsAString& aType,
|
||||
if (mimeType == MEDIAMIMETYPE("video/mp4") ||
|
||||
mimeType == MEDIAMIMETYPE("audio/mp4")) {
|
||||
if (!StaticPrefs::media_mediasource_mp4_enabled()) {
|
||||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
// Don't leak information about the fact that it's pref-disabled; just act
|
||||
// like we can't play it. Or should this throw "Unknown type"?
|
||||
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
|
||||
"Can't play type");
|
||||
}
|
||||
return NS_OK;
|
||||
return;
|
||||
}
|
||||
if (mimeType == MEDIAMIMETYPE("video/webm")) {
|
||||
if (!(StaticPrefs::media_mediasource_webm_enabled() ||
|
||||
@ -125,19 +131,26 @@ nsresult MediaSource::IsTypeSupported(const nsAString& aType,
|
||||
containerType->ExtendedType().Codecs().AsString())) ||
|
||||
#endif
|
||||
IsWebMForced(aDiagnostics))) {
|
||||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
// Don't leak information about the fact that it's pref-disabled; just act
|
||||
// like we can't play it. Or should this throw "Unknown type"?
|
||||
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
|
||||
"Can't play type");
|
||||
}
|
||||
return NS_OK;
|
||||
return;
|
||||
}
|
||||
if (mimeType == MEDIAMIMETYPE("audio/webm")) {
|
||||
if (!(StaticPrefs::media_mediasource_webm_enabled() ||
|
||||
StaticPrefs::media_mediasource_webm_audio_enabled())) {
|
||||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
// Don't leak information about the fact that it's pref-disabled; just act
|
||||
// like we can't play it. Or should this throw "Unknown type"?
|
||||
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
|
||||
"Can't play type");
|
||||
}
|
||||
return NS_OK;
|
||||
return;
|
||||
}
|
||||
|
||||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
|
||||
"Type not supported in MediaSource");
|
||||
}
|
||||
|
||||
/* static */
|
||||
@ -215,14 +228,14 @@ already_AddRefed<SourceBuffer> MediaSource::AddSourceBuffer(
|
||||
const nsAString& aType, ErrorResult& aRv) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
DecoderDoctorDiagnostics diagnostics;
|
||||
nsresult rv = IsTypeSupported(aType, &diagnostics);
|
||||
IsTypeSupported(aType, &diagnostics, aRv);
|
||||
bool supported = !aRv.Failed();
|
||||
diagnostics.StoreFormatDiagnostics(
|
||||
GetOwner() ? GetOwner()->GetExtantDoc() : nullptr, aType,
|
||||
NS_SUCCEEDED(rv), __func__);
|
||||
GetOwner() ? GetOwner()->GetExtantDoc() : nullptr, aType, supported,
|
||||
__func__);
|
||||
MSE_API("AddSourceBuffer(aType=%s)%s", NS_ConvertUTF16toUTF8(aType).get(),
|
||||
rv == NS_OK ? "" : " [not supported]");
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
supported ? "" : " [not supported]");
|
||||
if (!supported) {
|
||||
return nullptr;
|
||||
}
|
||||
if (mSourceBuffers->Length() >= MAX_SOURCE_BUFFERS) {
|
||||
@ -365,16 +378,18 @@ bool MediaSource::IsTypeSupported(const GlobalObject& aOwner,
|
||||
const nsAString& aType) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
DecoderDoctorDiagnostics diagnostics;
|
||||
nsresult rv = IsTypeSupported(aType, &diagnostics);
|
||||
IgnoredErrorResult rv;
|
||||
IsTypeSupported(aType, &diagnostics, rv);
|
||||
bool supported = !rv.Failed();
|
||||
nsCOMPtr<nsPIDOMWindowInner> window =
|
||||
do_QueryInterface(aOwner.GetAsSupports());
|
||||
diagnostics.StoreFormatDiagnostics(window ? window->GetExtantDoc() : nullptr,
|
||||
aType, NS_SUCCEEDED(rv), __func__);
|
||||
aType, supported, __func__);
|
||||
MOZ_LOG(GetMediaSourceAPILog(), mozilla::LogLevel::Debug,
|
||||
("MediaSource::%s: IsTypeSupported(aType=%s) %s", __func__,
|
||||
NS_ConvertUTF16toUTF8(aType).get(),
|
||||
rv == NS_OK ? "OK" : "[not supported]"));
|
||||
return NS_SUCCEEDED(rv);
|
||||
supported ? "OK" : "[not supported]"));
|
||||
return supported;
|
||||
}
|
||||
|
||||
void MediaSource::SetLiveSeekableRange(double aStart, double aEnd,
|
||||
|
@ -80,8 +80,10 @@ class MediaSource final : public DOMEventTargetHelper,
|
||||
void ClearLiveSeekableRange(ErrorResult& aRv);
|
||||
|
||||
static bool IsTypeSupported(const GlobalObject&, const nsAString& aType);
|
||||
static nsresult IsTypeSupported(const nsAString& aType,
|
||||
DecoderDoctorDiagnostics* aDiagnostics);
|
||||
// Throws on aRv if not supported.
|
||||
static void IsTypeSupported(const nsAString& aType,
|
||||
DecoderDoctorDiagnostics* aDiagnostics,
|
||||
ErrorResult& aRv);
|
||||
|
||||
IMPL_EVENT_HANDLER(sourceopen);
|
||||
IMPL_EVENT_HANDLER(sourceended);
|
||||
|
@ -364,16 +364,17 @@ void SourceBuffer::ChangeType(const nsAString& aType, ErrorResult& aRv) {
|
||||
// the parent media source , then throw a NotSupportedError exception and
|
||||
// abort these steps.
|
||||
DecoderDoctorDiagnostics diagnostics;
|
||||
nsresult rv = MediaSource::IsTypeSupported(aType, &diagnostics);
|
||||
MediaSource::IsTypeSupported(aType, &diagnostics, aRv);
|
||||
bool supported = !aRv.Failed();
|
||||
diagnostics.StoreFormatDiagnostics(
|
||||
mMediaSource->GetOwner() ? mMediaSource->GetOwner()->GetExtantDoc()
|
||||
: nullptr,
|
||||
aType, NS_SUCCEEDED(rv), __func__);
|
||||
aType, supported, __func__);
|
||||
MSE_API("ChangeType(aType=%s)%s", NS_ConvertUTF16toUTF8(aType).get(),
|
||||
rv == NS_OK ? "" : " [not supported]");
|
||||
if (NS_FAILED(rv)) {
|
||||
DDLOG(DDLogCategory::API, "ChangeType", rv);
|
||||
aRv.Throw(rv);
|
||||
supported ? "" : " [not supported]");
|
||||
if (!supported) {
|
||||
DDLOG(DDLogCategory::API, "ChangeType",
|
||||
static_cast<nsresult>(aRv.ErrorCodeAsInt()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
mediasource_test(function(test, mediaElement, mediaSource)
|
||||
{
|
||||
assert_throws({name: "TypeError"},
|
||||
assert_throws_js(TypeError,
|
||||
function() { mediaSource.addSourceBuffer(""); },
|
||||
"addSourceBuffer() threw an exception when passed an empty string.");
|
||||
test.done();
|
||||
|
Loading…
Reference in New Issue
Block a user