Bug 1271483 - p13. Rework formats list - r=cpearce
Renamed AppendToStringList to AppendToFormatsList, to distinguish from other
string-based lists.
Ensure that list items don't contain commas, as commas are used as separators,
and we don't want&need to introduce escaping.
Added FormatsListContains.
MozReview-Commit-ID: 8KpuhSjCW3d
--- a/dom/media/DecoderDoctorDiagnostics.cpp
+++ b/dom/media/DecoderDoctorDiagnostics.cpp
@@ -451,22 +451,41 @@ CheckSilverlight()
return plugin->IsEnabled() ? eSilverlightEnabled : eSilverlightDisabled;
}
}
}
return eNoSilverlight;
}
-static void AppendToStringList(nsAString& list, const nsAString& item)
+static nsString
+CleanItemForFormatsList(const nsAString& aItem)
{
- if (!list.IsEmpty()) {
- list += NS_LITERAL_STRING(", ");
+ nsString item(aItem);
+ // Remove commas from item, as commas are used to separate items. It's fine
+ // to have a one-way mapping, it's only used for comparisons and in
+ // console display (where formats shouldn't contain commas in the first place)
+ item.ReplaceChar(',', ' ');
+ item.CompressWhitespace();
+ return item;
+}
+
+static void
+AppendToFormatsList(nsAString& aList, const nsAString& aItem)
+{
+ if (!aList.IsEmpty()) {
+ aList += NS_LITERAL_STRING(", ");
}
- list += item;
+ aList += CleanItemForFormatsList(aItem);
+}
+
+static bool
+FormatsListContains(const nsAString& aList, const nsAString& aItem)
+{
+ return StringListContains(aList, CleanItemForFormatsList(aItem));
}
void
DecoderDoctorDocumentWatcher::SynthesizeAnalysis()
{
MOZ_ASSERT(NS_IsMainThread());
nsAutoString playableFormats;
@@ -482,42 +501,42 @@ DecoderDoctorDocumentWatcher::Synthesize
nsAutoString unsupportedKeySystems;
DecoderDoctorDiagnostics::KeySystemIssue lastKeySystemIssue =
DecoderDoctorDiagnostics::eUnset;
for (const auto& diag : mDiagnosticsSequence) {
switch (diag.mDecoderDoctorDiagnostics.Type()) {
case DecoderDoctorDiagnostics::eFormatSupportCheck:
if (diag.mDecoderDoctorDiagnostics.CanPlay()) {
- AppendToStringList(playableFormats,
- diag.mDecoderDoctorDiagnostics.Format());
+ AppendToFormatsList(playableFormats,
+ diag.mDecoderDoctorDiagnostics.Format());
} else {
- AppendToStringList(unplayableFormats,
- diag.mDecoderDoctorDiagnostics.Format());
+ AppendToFormatsList(unplayableFormats,
+ diag.mDecoderDoctorDiagnostics.Format());
#if defined(XP_WIN)
if (diag.mDecoderDoctorDiagnostics.DidWMFFailToLoad()) {
- AppendToStringList(formatsRequiringWMF,
- diag.mDecoderDoctorDiagnostics.Format());
+ AppendToFormatsList(formatsRequiringWMF,
+ diag.mDecoderDoctorDiagnostics.Format());
}
#endif
#if defined(MOZ_FFMPEG)
if (diag.mDecoderDoctorDiagnostics.DidFFmpegFailToLoad()) {
- AppendToStringList(formatsRequiringFFMpeg,
- diag.mDecoderDoctorDiagnostics.Format());
+ AppendToFormatsList(formatsRequiringFFMpeg,
+ diag.mDecoderDoctorDiagnostics.Format());
}
#endif
}
break;
case DecoderDoctorDiagnostics::eMediaKeySystemAccessRequest:
if (diag.mDecoderDoctorDiagnostics.IsKeySystemSupported()) {
- AppendToStringList(supportedKeySystems,
- diag.mDecoderDoctorDiagnostics.KeySystem());
+ AppendToFormatsList(supportedKeySystems,
+ diag.mDecoderDoctorDiagnostics.KeySystem());
} else {
- AppendToStringList(unsupportedKeySystems,
- diag.mDecoderDoctorDiagnostics.KeySystem());
+ AppendToFormatsList(unsupportedKeySystems,
+ diag.mDecoderDoctorDiagnostics.KeySystem());
DecoderDoctorDiagnostics::KeySystemIssue issue =
diag.mDecoderDoctorDiagnostics.GetKeySystemIssue();
if (issue != DecoderDoctorDiagnostics::eUnset) {
lastKeySystemIssue = issue;
}
}
break;
default: