Bug 1271483 - p13. Rework formats list - r=cpearce draft
authorGerald Squelart <gsquelart@mozilla.com>
Wed, 25 May 2016 03:24:14 +1000
changeset 380486 43024a985814d5fc7c08bd2561b0ee16352fc604
parent 380485 94381bb362bb4750b33519302de5d6062b782445
child 380487 64ced9bb675e97ff076a277709bdca5ca7aff4d9
push id21230
push usergsquelart@mozilla.com
push dateWed, 22 Jun 2016 01:46:41 +0000
reviewerscpearce
bugs1271483
milestone50.0a1
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
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: