Bug 1251184: [quicktime] P2. Use external plugin if available over native playback. r?cpearce draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 11 Mar 2016 22:42:02 +1100
changeset 339477 4a4c4fab81ba65722ae03f37a1199a249a677f58
parent 339476 b7459a5de4b2100b0296b395afc671d3d6cbe5d8
child 339481 8709b666c6b3eea5ca82a9218a67e52e527fb81a
push id12741
push userbmo:jyavenard@mozilla.com
push dateFri, 11 Mar 2016 11:42:24 +0000
reviewerscpearce
bugs1251184
milestone48.0a1
Bug 1251184: [quicktime] P2. Use external plugin if available over native playback. r?cpearce While almost identical to video/mp4, quicktime files often use codecs that we don't support: in particular MPEG4 part 2 and amr audio. If a plugin exists and is enabled, prefer it to handle those files. We only do so when opening the file directly. Media in <video> element will always play natively. MozReview-Commit-ID: 1yPpzfDaCfT
dom/media/DecoderTraits.cpp
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -50,16 +50,18 @@
 
 #include "WaveDecoder.h"
 #include "WaveDemuxer.h"
 #include "WaveReader.h"
 
 #include "ADTSDecoder.h"
 #include "ADTSDemuxer.h"
 
+#include "nsPluginHost.h"
+
 namespace mozilla
 {
 
 template <class String>
 static bool
 CodecListContains(char const *const * aCodecs, const String& aCodec)
 {
   for (int32_t i = 0; aCodecs[i]; ++i) {
@@ -349,16 +351,28 @@ bool DecoderTraits::ShouldHandleMediaTyp
   if (IsWaveType(nsDependentCString(aMIMEType))) {
     // We should not return true for Wave types, since there are some
     // Wave codecs actually in use in the wild that we don't support, and
     // we should allow those to be handled by plugins or helper apps.
     // Furthermore people can play Wave files on most platforms by other
     // means.
     return false;
   }
+
+  // If an external plugin which can handle quicktime video is available
+  // (and not disabled), prefer it over native playback as there several
+  // codecs found in the wild that we do not handle.
+  if (nsDependentCString(aMIMEType).EqualsASCII("video/quicktime")) {
+    RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
+    if (pluginHost &&
+        pluginHost->HavePluginForType(nsDependentCString(aMIMEType))) {
+      return false;
+    }
+  }
+
   return CanHandleMediaType(aMIMEType, false, EmptyString()) != CANPLAY_NO;
 }
 
 /* static */
 CanPlayStatus
 DecoderTraits::CanHandleCodecsType(const char* aMIMEType,
                                    const nsAString& aRequestedCodecs)
 {