Bug 1271483 - p12. Use StringListContains to filter notifications - r=cpearce draft
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 26 May 2016 17:01:52 +1000
changeset 380485 94381bb362bb4750b33519302de5d6062b782445
parent 380484 af745ceacd4b194698b719ebe3f7b4ee07786565
child 380486 43024a985814d5fc7c08bd2561b0ee16352fc604
push id21230
push usergsquelart@mozilla.com
push dateWed, 22 Jun 2016 01:46:41 +0000
reviewerscpearce
bugs1271483
milestone50.0a1
Bug 1271483 - p12. Use StringListContains to filter notifications - r=cpearce Using string-list iterator instead of bespoke code, to go through the decoder doctor notifications-allowed pref. MozReview-Commit-ID: 8sxopvlRrz7
dom/media/DecoderDoctorDiagnostics.cpp
--- a/dom/media/DecoderDoctorDiagnostics.cpp
+++ b/dom/media/DecoderDoctorDiagnostics.cpp
@@ -416,32 +416,18 @@ DecoderDoctorDocumentWatcher::ReportAnal
   // may be dispatched to the front-end. It either contains:
   // - '*' -> Allow everything.
   // - Comma-separater list of ids -> Allow if aReportStringId (from
   //                                  dom.properties) is one of them.
   // - Nothing (missing or empty) -> Disable everything.
   nsAdoptingCString filter =
     Preferences::GetCString("media.decoder-doctor.notifications-allowed");
   filter.StripWhitespace();
-  bool allowed = false;
-  if (!filter || filter.IsEmpty()) {
-    // Allow nothing.
-  } else if (filter.EqualsLiteral("*")) {
-    allowed = true;
-  } else for (uint32_t start = 0; start < filter.Length(); ) {
-    int32_t comma = filter.FindChar(',', start);
-    uint32_t end = (comma >= 0) ? uint32_t(comma) : filter.Length();
-    if (strncmp(aReportStringId, filter.Data() + start, end - start) == 0) {
-      allowed = true;
-      break;
-    }
-    // Skip comma. End of line will be caught in for 'while' clause.
-    start = end + 1;
-  }
-  if (allowed) {
+  if (filter.EqualsLiteral("*")
+      || StringListContains(filter, aReportStringId)) {
     DispatchNotification(
       mDocument->GetInnerWindow(),
       aNotificationType, aIsSolved, aReportStringId, aParams);
   }
 }
 
 enum SilverlightPresence {
   eNoSilverlight,