Bug 848994 - p7. Filter front-end notifications - r?cpearce draft
authorGerald Squelart <gsquelart@mozilla.com>
Fri, 22 Apr 2016 11:48:28 +1000
changeset 355188 75915add0bc9cbac0e3ba535c4f3d68bc57e74ef
parent 355187 a0204911f2a644bfa0036f145b26fab4a5220d81
child 519134 e4fd597386f383d9946ed37bc0870825a0601a5b
push id16221
push usergsquelart@mozilla.com
push dateFri, 22 Apr 2016 01:56:41 +0000
reviewerscpearce
bugs848994
milestone48.0a1
Bug 848994 - p7. Filter front-end notifications - r?cpearce Pref "media.decoder-doctor.notifications-allowed" defines which notifications may be forwarded to the front-end (based on the web-console message ID for that situation). This allows fine-grained filtering. The current default is to only notify the user about Widevine requests when WMF and Silverlight are missing (because Widevine does not include an AAC decoder). MozReview-Commit-ID: KPFH5XjuwnZ
dom/media/DecoderDoctorDiagnostics.cpp
modules/libpref/init/all.js
--- a/dom/media/DecoderDoctorDiagnostics.cpp
+++ b/dom/media/DecoderDoctorDiagnostics.cpp
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DecoderDoctorDiagnostics.h"
 
 #include "mozilla/dom/DecoderDoctorNotificationBinding.h"
 #include "mozilla/Logging.h"
+#include "mozilla/Preferences.h"
 #include "nsGkAtoms.h"
 #include "nsIDocument.h"
 #include "nsIObserverService.h"
 #include "nsITimer.h"
 #include "nsIWeakReference.h"
 #include "nsPluginHost.h"
 
 static mozilla::LazyLogModule sDecoderDoctorLog("DecoderDoctor");
@@ -282,19 +283,41 @@ DecoderDoctorDocumentWatcher::ReportAnal
   nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
                                   NS_LITERAL_CSTRING("Media"),
                                   mDocument,
                                   nsContentUtils::eDOM_PROPERTIES,
                                   aReportStringId,
                                   aParams.IsEmpty() ? nullptr : params,
                                   aParams.IsEmpty() ? 0 : 1);
 
-  // For now, disable all front-end notifications by default.
-  // TODO: Future bugs will use finer-grained filtering instead.
-  if (Preferences::GetBool("media.decoderdoctor.enable-notification-bar", false)) {
+  // "media.decoder-doctor.notifications-allowed" controls which notifications
+  // 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) {
     DispatchNotification(
       mDocument->GetInnerWindow(), aNotificationType, aParams);
   }
 }
 
 enum SilverlightPresence {
   eNoSilverlight,
   eSilverlightDisabled,
@@ -435,17 +458,17 @@ DecoderDoctorDocumentWatcher::Synthesize
             this, mDocument, NS_ConvertUTF16toUTF8(unplayableFormats).get());
     ReportAnalysis(dom::DecoderDoctorNotificationType::Cannot_play,
                    "MediaCannotPlayNoDecoders", unplayableFormats);
     return;
   }
   if (!unplayableFormats.IsEmpty()) {
     DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Can play media, but no decoders for some requested formats: %s",
             this, mDocument, NS_ConvertUTF16toUTF8(unplayableFormats).get());
-    if (Preferences::GetBool("media.decoderdoctor.verbose", false)) {
+    if (Preferences::GetBool("media.decoder-doctor.verbose", false)) {
       ReportAnalysis(
         dom::DecoderDoctorNotificationType::Can_play_but_some_missing_decoders,
         "MediaNoDecoders", unplayableFormats);
     }
     return;
   }
   DD_DEBUG("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Can play media, decoders available for all requested formats",
            this, mDocument);
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -346,16 +346,23 @@ pref("media.webm.intel_decoder.enabled",
 
 #ifdef MOZ_APPLEMEDIA
 #ifdef MOZ_WIDGET_UIKIT
 pref("media.mp3.enabled", true);
 #endif
 pref("media.apple.mp3.enabled", true);
 pref("media.apple.mp4.enabled", true);
 #endif
+
+// Filter what triggers user notifications.
+// See DecoderDoctorDocumentWatcher::ReportAnalysis for details.
+pref("media.decoder-doctor.notifications-allowed", "MediaWidevineNoWMFNoSilverlight");
+// Whether we report partial failures.
+pref("media.decoder-doctor.verbose", false);
+
 #ifdef MOZ_WEBRTC
 pref("media.navigator.enabled", true);
 pref("media.navigator.video.enabled", true);
 pref("media.navigator.load_adapt", true);
 pref("media.navigator.load_adapt.measure_interval",1000);
 pref("media.navigator.load_adapt.avg_seconds",3);
 pref("media.navigator.load_adapt.high_load","0.90");
 pref("media.navigator.load_adapt.low_load","0.40");