Bug 1271483 - p13. Rework formats list - r=cpearce
authorGerald Squelart <gsquelart@mozilla.com>
Wed, 25 May 2016 03:24:14 +1000
changeset 302284 2bc76d3f7827576cd8d24e0dee225fc0d61dd2f4
parent 302283 bbfd03f4dd55e48e79da005863abc9d1ded85dc5
child 302285 d780f0ca52436491f471b24bb99a22222aa9c870
push id78676
push usergsquelart@mozilla.com
push dateWed, 22 Jun 2016 03:54:32 +0000
treeherdermozilla-inbound@da005aa1d83c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1271483
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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: