Bug 712134 - Log media load algorithm failures to web console. r=roc

This commit is contained in:
Chris Pearce 2011-12-22 12:33:39 +13:00
parent d69fab6ea6
commit c998f71a55
3 changed files with 72 additions and 0 deletions

View File

@ -355,6 +355,16 @@ public:
protected:
class MediaLoadListener;
/**
* Logs a warning message to the web console to report various failures.
* aMsg is the localized message identifier, aParams is the parameters to
* be substituted into the localized message, and aParamCount is the number
* of parameters in aParams.
*/
void ReportLoadError(const char* aMsg,
const PRUnichar** aParams = nsnull,
PRUint32 aParamCount = 0);
/**
* Changes mHasPlayedOrSeeked to aValue. If mHasPlayedOrSeeked changes
* we'll force a reflow so that the video frame gets reflowed to reflect

View File

@ -90,6 +90,8 @@
#include "nsIDOMNotifyAudioAvailableEvent.h"
#include "nsMediaFragmentURIParser.h"
#include "nsURIHashKey.h"
#include "nsContentUtils.h"
#include "nsIScriptError.h"
#ifdef MOZ_OGG
#include "nsOggDecoder.h"
@ -282,6 +284,20 @@ nsHTMLMediaElement::MediaLoadListener::Observe(nsISupports* aSubject,
return NS_OK;
}
void nsHTMLMediaElement::ReportLoadError(const char* aMsg,
const PRUnichar** aParams,
PRUint32 aParamCount)
{
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
"Media",
OwnerDoc(),
nsContentUtils::eDOM_PROPERTIES,
aMsg,
aParams,
aParamCount);
}
NS_IMETHODIMP nsHTMLMediaElement::MediaLoadListener::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
{
nsContentUtils::UnregisterShutdownObserver(this);
@ -308,6 +324,21 @@ NS_IMETHODIMP nsHTMLMediaElement::MediaLoadListener::OnStartRequest(nsIRequest*
return status;
}
nsCOMPtr<nsIHttpChannel> hc = do_QueryInterface(aRequest);
bool succeeded;
if (hc && NS_SUCCEEDED(hc->GetRequestSucceeded(&succeeded)) && !succeeded) {
element->NotifyLoadError();
PRUint32 responseStatus = 0;
hc->GetResponseStatus(&responseStatus);
nsAutoString code;
code.AppendInt(responseStatus);
nsAutoString src;
element->GetCurrentSrc(src);
const PRUnichar* params[] = { code.get(), src.get() };
element->ReportLoadError("MediaLoadHttpError", params, ArrayLength(params));
return NS_BINDING_ABORTED;
}
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
if (channel &&
element &&
@ -664,6 +695,9 @@ void nsHTMLMediaElement::SelectResource()
mIsRunningSelectResource = false;
return;
}
} else {
const PRUnichar* params[] = { src.get() };
ReportLoadError("MediaLoadInvalidURI", params, ArrayLength(params));
}
NoSupportedMediaSourceError();
} else {
@ -722,12 +756,14 @@ void nsHTMLMediaElement::LoadFromSourceChildren()
mLoadWaitStatus = WAITING_FOR_SOURCE;
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_NO_SOURCE;
ChangeDelayLoadStatus(false);
ReportLoadError("MediaLoadExhaustedCandidates");
return;
}
// Must have src attribute.
nsAutoString src;
if (!child->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
ReportLoadError("MediaLoadSourceMissingSrc");
DispatchAsyncSourceError(child);
continue;
}
@ -737,6 +773,8 @@ void nsHTMLMediaElement::LoadFromSourceChildren()
if (child->GetAttr(kNameSpaceID_None, nsGkAtoms::type, type) &&
GetCanPlay(type) == CANPLAY_NO) {
DispatchAsyncSourceError(child);
const PRUnichar* params[] = { type.get(), src.get() };
ReportLoadError("MediaLoadUnsupportedType", params, ArrayLength(params));
continue;
}
LOG(PR_LOG_DEBUG, ("%p Trying load from <source>=%s type=%s", this,
@ -746,6 +784,8 @@ void nsHTMLMediaElement::LoadFromSourceChildren()
NewURIFromString(src, getter_AddRefs(uri));
if (!uri) {
DispatchAsyncSourceError(child);
const PRUnichar* params[] = { src.get() };
ReportLoadError("MediaLoadInvalidURI", params, ArrayLength(params));
continue;
}
@ -1951,6 +1991,11 @@ nsresult nsHTMLMediaElement::InitializeDecoderForChannel(nsIChannel *aChannel,
nsRefPtr<nsMediaDecoder> decoder = CreateDecoder(mimeType);
if (!decoder) {
nsAutoString src;
GetCurrentSrc(src);
NS_ConvertUTF8toUTF16 mimeUTF16(mimeType);
const PRUnichar* params[] = { mimeUTF16.get(), src.get() };
ReportLoadError("MediaLoadUnsupportedMimeType", params, ArrayLength(params));
return NS_ERROR_FAILURE;
}
@ -2120,6 +2165,11 @@ void nsHTMLMediaElement::NetworkError()
void nsHTMLMediaElement::DecodeError()
{
nsAutoString src;
GetCurrentSrc(src);
const PRUnichar* params[] = { src.get() };
ReportLoadError("MediaLoadDecodeError", params, ArrayLength(params));
if (mDecoder) {
RemoveMediaElementFromURITable();
mDecoder->Shutdown();

View File

@ -136,3 +136,15 @@ InvalidRedirectChannelWarning=Unable to redirect to %S because the channel doesn
ResponseTypeSyncXHRWarning=Use of XMLHttpRequest's responseType attribute is no longer supported in the synchronous mode in window context.
WithCredentialsSyncXHRWarning=Use of XMLHttpRequest's withCredentials attribute is no longer supported in the synchronous mode in window context.
JSONCharsetWarning=An attempt was made to declare a non-UTF-8 encoding for JSON retrieved using XMLHttpRequest. Only UTF-8 is supported for decoding JSON.
MediaLoadExhaustedCandidates=All candidate resources failed to load. Media load paused.
MediaLoadSourceMissingSrc=<source> element has no "src" attribute. Media resource load failed.
# LOCALIZATION NOTE: %1$S is the Http error code the server returned (e.g. 404, 500, etc), %2$S is the URL of the media resource which failed to load.
MediaLoadHttpError=HTTP load failed with status %1$S. Load of media resource %2$S failed.
# LOCALIZATION NOTE: %S is the URL of the media resource which failed to load.
MediaLoadInvalidURI=Invalid URI. Load of media resource %S failed.
# LOCALIZATION NOTE: %1$S is the media resource's format/codec type (basically equivalent to the file type, e.g. MP4,AVI,WMV,MOV etc), %2$S is the URL of the media resource which failed to load.
MediaLoadUnsupportedType=Specified "type" of "%1$S" is not supported. Load of media resource %2$S failed.
# LOCALIZATION NOTE: %1$S is the MIME type HTTP header being sent by the web server, %2$S is the URL of the media resource which failed to load.
MediaLoadUnsupportedMimeType=HTTP "Content-Type" of "%1$S" is not supported. Load of media resource %2$S failed.
# LOCALIZATION NOTE: %S is the URL of the media resource which failed to load because of error in decoding.
MediaLoadDecodeError=Media resource %S could not be decoded.