Bug 1343442 - Analyze eDecodeError/Warning issues - r=jya

MozReview-Commit-ID: 97AhQz2Hgmi

--HG--
extra : rebase_source : 66ccff1a9aeb7cdbc49e57a116ef449017b31c04
This commit is contained in:
Gerald Squelart 2017-03-24 17:09:41 +11:00
parent 4933532b48
commit c5578cbb63

View File

@ -245,7 +245,10 @@ enum class ReportParam : uint8_t
// Keep this zero! (For implicit zero-inits when used in definitions below.)
None = 0,
Formats
Formats,
DecodeIssue,
DocURL,
ResourceURL
};
struct NotificationAndReportStringId
@ -280,6 +283,14 @@ static const NotificationAndReportStringId sCannotInitializePulseAudio =
static const NotificationAndReportStringId sUnsupportedLibavcodec =
{ dom::DecoderDoctorNotificationType::Unsupported_libavcodec,
"MediaUnsupportedLibavcodec", { ReportParam::None } };
static const NotificationAndReportStringId sMediaDecodeError =
{ dom::DecoderDoctorNotificationType::Decode_error,
"MediaDecodeError",
{ ReportParam::ResourceURL, ReportParam::DecodeIssue } };
static const NotificationAndReportStringId sMediaDecodeWarning =
{ dom::DecoderDoctorNotificationType::Decode_warning,
"MediaDecodeWarning",
{ ReportParam::ResourceURL, ReportParam::DecodeIssue } };
static const NotificationAndReportStringId *const
sAllNotificationsAndReportStringIds[] =
@ -291,13 +302,18 @@ sAllNotificationsAndReportStringIds[] =
&sMediaNoDecoders,
&sCannotInitializePulseAudio,
&sUnsupportedLibavcodec,
&sMediaDecodeError,
&sMediaDecodeWarning
};
static void
DispatchNotification(nsISupports* aSubject,
const NotificationAndReportStringId& aNotification,
bool aIsSolved,
const nsAString& aFormats)
const nsAString& aFormats,
const nsAString& aDecodeIssue,
const nsACString& aDocURL,
const nsAString& aResourceURL)
{
if (!aSubject) {
return;
@ -310,6 +326,15 @@ DispatchNotification(nsISupports* aSubject,
if (!aFormats.IsEmpty()) {
data.mFormats.Construct(aFormats);
}
if (!aDecodeIssue.IsEmpty()) {
data.mDecodeIssue.Construct(aDecodeIssue);
}
if (!aDocURL.IsEmpty()) {
data.mDocURL.Construct(NS_ConvertUTF8toUTF16(aDocURL));
}
if (!aResourceURL.IsEmpty()) {
data.mResourceURL.Construct(aResourceURL);
}
nsAutoString json;
data.ToJSON(json);
if (json.IsEmpty()) {
@ -334,11 +359,16 @@ ReportToConsole(nsIDocument* aDocument,
MOZ_ASSERT(aDocument);
DD_DEBUG("DecoderDoctorDiagnostics.cpp:ReportToConsole(doc=%p) ReportToConsole"
" - aMsg='%s' params={%s}",
" - aMsg='%s' params={%s%s%s%s}",
aDocument, aConsoleStringId,
aParams.IsEmpty()
? "<no params>"
: NS_ConvertUTF16toUTF8(aParams[0]).get());
: NS_ConvertUTF16toUTF8(aParams[0]).get(),
(aParams.Length() < 1 || !aParams[1]) ? "" : ", ",
(aParams.Length() < 1 || !aParams[1])
? ""
: NS_ConvertUTF16toUTF8(aParams[1]).get(),
aParams.Length() < 2 ? "" : ", ...");
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("Media"),
aDocument,
@ -354,7 +384,10 @@ static void
ReportAnalysis(nsIDocument* aDocument,
const NotificationAndReportStringId& aNotification,
bool aIsSolved,
const nsAString& aFormats = NS_LITERAL_STRING(""))
const nsAString& aFormats = NS_LITERAL_STRING(""),
const nsAString& aDecodeIssue = NS_LITERAL_STRING(""),
const nsACString& aDocURL = NS_LITERAL_CSTRING(""),
const nsAString& aResourceURL = NS_LITERAL_STRING(""))
{
MOZ_ASSERT(NS_IsMainThread());
@ -375,6 +408,15 @@ ReportAnalysis(nsIDocument* aDocument,
case ReportParam::Formats:
params.AppendElement(aFormats.Data());
break;
case ReportParam::DecodeIssue:
params.AppendElement(aDecodeIssue.Data());
break;
case ReportParam::DocURL:
params.AppendElement(NS_ConvertUTF8toUTF16(aDocURL).Data());
break;
case ReportParam::ResourceURL:
params.AppendElement(aResourceURL.Data());
break;
default:
MOZ_ASSERT_UNREACHABLE("Bad notification parameter choice");
break;
@ -395,7 +437,11 @@ ReportAnalysis(nsIDocument* aDocument,
if (filter.EqualsLiteral("*")
|| StringListContains(filter, aNotification.mReportStringId)) {
DispatchNotification(
aDocument->GetInnerWindow(), aNotification, aIsSolved, aFormats);
aDocument->GetInnerWindow(), aNotification, aIsSolved,
aFormats,
aDecodeIssue,
aDocURL,
aResourceURL);
}
}
@ -426,6 +472,21 @@ FormatsListContains(const nsAString& aList, const nsAString& aItem)
return StringListContains(aList, CleanItemForFormatsList(aItem));
}
// Create a webcompat-friendly description of a MediaResult.
static nsString
MediaResultDescription(const MediaResult& aResult, bool aIsError)
{
nsCString name;
GetErrorName(aResult.Code(), static_cast<nsACString&>(name));
return NS_ConvertUTF8toUTF16(
nsPrintfCString(
"%s Code: %s (0x%08" PRIx32 ")%s%s",
aIsError ? "Error" : "Warning", name.get(),
static_cast<uint32_t>(aResult.Code()),
aResult.Message().IsEmpty() ? "" : "\nDetails: ",
aResult.Message().get()));
}
void
DecoderDoctorDocumentWatcher::SynthesizeAnalysis()
{
@ -444,6 +505,12 @@ DecoderDoctorDocumentWatcher::SynthesizeAnalysis()
nsAutoString unsupportedKeySystems;
DecoderDoctorDiagnostics::KeySystemIssue lastKeySystemIssue =
DecoderDoctorDiagnostics::eUnset;
// Only deal with one decode error per document (the first one found).
const MediaResult* firstDecodeError = nullptr;
const nsString* firstDecodeErrorMediaSrc = nullptr;
// Only deal with one decode warning per document (the first one found).
const MediaResult* firstDecodeWarning = nullptr;
const nsString* firstDecodeWarningMediaSrc = nullptr;
for (const auto& diag : mDiagnosticsSequence) {
switch (diag.mDecoderDoctorDiagnostics.Type()) {
@ -486,10 +553,18 @@ DecoderDoctorDocumentWatcher::SynthesizeAnalysis()
MOZ_ASSERT_UNREACHABLE("Events shouldn't be stored for processing.");
break;
case DecoderDoctorDiagnostics::eDecodeError:
// TODO
if (!firstDecodeError) {
firstDecodeError = &diag.mDecoderDoctorDiagnostics.DecodeIssue();
firstDecodeErrorMediaSrc =
&diag.mDecoderDoctorDiagnostics.DecodeIssueMediaSrc();
}
break;
case DecoderDoctorDiagnostics::eDecodeWarning:
// TODO
if (!firstDecodeWarning) {
firstDecodeWarning = &diag.mDecoderDoctorDiagnostics.DecodeIssue();
firstDecodeWarningMediaSrc =
&diag.mDecoderDoctorDiagnostics.DecodeIssueMediaSrc();
}
break;
default:
MOZ_ASSERT_UNREACHABLE("Unhandled DecoderDoctorDiagnostics type");
@ -624,6 +699,29 @@ DecoderDoctorDocumentWatcher::SynthesizeAnalysis()
}
return;
}
if (firstDecodeError) {
DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Decode error: %s",
this, mDocument, firstDecodeError->Description().get());
ReportAnalysis(mDocument, sMediaDecodeError, false,
NS_LITERAL_STRING(""),
MediaResultDescription(*firstDecodeError, true),
mDocument->GetDocumentURI()->GetSpecOrDefault(),
*firstDecodeErrorMediaSrc);
return;
}
if (firstDecodeWarning) {
DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Decode warning: %s",
this, mDocument, firstDecodeWarning->Description().get());
ReportAnalysis(mDocument, sMediaDecodeWarning, false,
NS_LITERAL_STRING(""),
MediaResultDescription(*firstDecodeWarning, false),
mDocument->GetDocumentURI()->GetSpecOrDefault(),
*firstDecodeWarningMediaSrc);
return;
}
DD_DEBUG("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Can play media, decoders available for all requested formats",
this, mDocument);
}