Bug 1271483 - p13. Rework formats list - r=cpearce, a=lizzard
authorGerald Squelart <gsquelart@mozilla.com>
Wed, 25 May 2016 03:24:14 +1000
changeset 339801 e40406f3f9e9b95044dac6db4ec0ffb8fa0febce
parent 339800 c99836f4707dcff72ac1f16bf99edcfb8fa61660
child 339802 32ffb9c06c7beb55af4b62d0b1613feefb717e3a
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, lizzard
bugs1271483
milestone49.0a2
Bug 1271483 - p13. Rework formats list - r=cpearce, a=lizzard 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
dom/media/DecoderDoctorDiagnostics.cpp
--- 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: