Bug 1192450 - Remove PlayPreview registration from Shumway. r=jet
authorYury Delendik <ydelendik@mozilla.com>
Tue, 18 Aug 2015 11:24:16 -0500
changeset 291096 89776b90cb3b44760ea8f5601d29839b9a8bda7c
parent 291095 34cb31a628833e4b5d2273f545f8b0bbb0acf7c5
child 291097 5fb2d9aa3f3b8a1f474589145db1c91eebf0cf76
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjet
bugs1192450
milestone43.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 1192450 - Remove PlayPreview registration from Shumway. r=jet
browser/app/profile/firefox.js
browser/extensions/shumway/content/ShumwayBootstrapUtils.jsm
browser/extensions/shumway/content/ShumwayStreamConverter.jsm
docshell/base/nsWebNavigationInfo.cpp
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/base/nsObjectLoadingContent.cpp
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1684,23 +1684,17 @@ pref("pdfjs.disabled", false);
 pref("pdfjs.firstRun", true);
 // The values of preferredAction and alwaysAskBeforeHandling before pdf.js
 // became the default.
 pref("pdfjs.previousHandler.preferredAction", 0);
 pref("pdfjs.previousHandler.alwaysAskBeforeHandling", false);
 
 // Shumway is only bundled in Nightly.
 #ifdef NIGHTLY_BUILD
-// By default, Shumway (SWF player) is only enabled for whitelisted SWFs on Windows + OS X.
-#ifdef UNIX_BUT_NOT_MAC
 pref("shumway.disabled", true);
-#else
-pref("shumway.disabled", false);
-pref("shumway.swf.whitelist", "http://www.areweflashyet.com/*.swf");
-#endif
 #endif
 
 // The maximum amount of decoded image data we'll willingly keep around (we
 // might keep around more than this, but we'll try to get down to this value).
 // (This is intentionally on the high side; see bug 746055.)
 pref("image.mem.max_decoded_image_kb", 256000);
 
 pref("loop.enabled", true);
--- a/browser/extensions/shumway/content/ShumwayBootstrapUtils.jsm
+++ b/browser/extensions/shumway/content/ShumwayBootstrapUtils.jsm
@@ -64,21 +64,30 @@ Factory.prototype = {
     this._classID = proto.classID;
 
     var factory = XPCOMUtils._getFactory(targetConstructor);
     this._factory = factory;
 
     var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
     registrar.registerFactory(proto.classID, proto.classDescription,
       proto.contractID, factory);
+
+    if (proto.classID2) {
+      this._classID2 = proto.classID2;
+      registrar.registerFactory(proto.classID2, proto.classDescription,
+                                proto.contractID2, factory);
+    }
   },
 
   unregister: function unregister() {
     var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
     registrar.unregisterFactory(this._classID, this._factory);
+    if (this._classID2) {
+      registrar.unregisterFactory(this._classID2, this._factory);
+    }
   }
 };
 
 function allowedPlatformForMedia() {
   var oscpu = Cc["@mozilla.org/network/protocol;1?name=http"]
                 .getService(Ci.nsIHttpProtocolHandler).oscpu;
   if (oscpu.indexOf('Windows NT') === 0) {
     return oscpu.indexOf('Windows NT 5') < 0; // excluding Windows XP
@@ -123,52 +132,27 @@ var ShumwayBootstrapUtils = {
       };
       Ph.registerFakePlugin(initPluginDict);
     } else {
       Cu.import('resource://shumway/ShumwayStreamConverter.jsm');
 
       let converterFactory = new Factory();
       converterFactory.register(ShumwayStreamConverter);
       this.converterFactory = converterFactory;
-      let overlayConverterFactory = new Factory();
-      overlayConverterFactory.register(ShumwayStreamOverlayConverter);
-      this.overlayConverterFactory = overlayConverterFactory;
-
-      let registerOverlayPreview = 'registerPlayPreviewMimeType' in Ph;
-      if (registerOverlayPreview) {
-        var ignoreCTP = getBoolPref(PREF_IGNORE_CTP, true);
-        var whitelist = getStringPref(PREF_WHITELIST);
-        // Some platforms cannot support video playback, and our whitelist targets
-        // only video players atm. We need to disable Shumway for those platforms.
-        if (whitelist && !Services.prefs.prefHasUserValue(PREF_WHITELIST) && !allowedPlatformForMedia()) {
-          log('Default SWF whitelist is used on an unsupported platform -- ' +
-          'using demo whitelist.');
-          whitelist = 'http://www.areweflashyet.com/*.swf';
-        }
-        Ph.registerPlayPreviewMimeType(SWF_CONTENT_TYPE, ignoreCTP,
-          undefined, whitelist);
-      }
-      this.registerOverlayPreview = registerOverlayPreview;
     }
   },
 
   unregister: function () {
     if (!this.isRegistered) {
       return;
     }
 
     this.isRegistered = false;
 
     // Remove the contract/component.
     if (this.isJSPluginsSupported) {
       Ph.unregisterFakePlugin(PLUGIN_HANLDER_URI);
     } else {
       this.converterFactory.unregister();
       this.converterFactory = null;
-      this.overlayConverterFactory.unregister();
-      this.overlayConverterFactory = null;
-
-      if (this.registerOverlayPreview) {
-        Ph.unregisterPlayPreviewMimeType(SWF_CONTENT_TYPE);
-      }
     }
   }
 };
--- a/browser/extensions/shumway/content/ShumwayStreamConverter.jsm
+++ b/browser/extensions/shumway/content/ShumwayStreamConverter.jsm
@@ -398,17 +398,20 @@ function copyProperties(obj, template) {
   }
 }
 
 function ShumwayStreamConverter() {}
 ShumwayStreamConverter.prototype = new ShumwayStreamConverterBase();
 copyProperties(ShumwayStreamConverter.prototype, {
   classID: Components.ID('{4c6030f7-e20a-264f-5b0e-ada3a9e97384}'),
   classDescription: 'Shumway Content Converter Component',
-  contractID: '@mozilla.org/streamconv;1?from=application/x-shockwave-flash&to=*/*'
+  contractID: '@mozilla.org/streamconv;1?from=application/x-shockwave-flash&to=*/*',
+
+  classID2: Components.ID('{4c6030f8-e20a-264f-5b0e-ada3a9e97384}'),
+  contractID2: '@mozilla.org/streamconv;1?from=application/x-shockwave-flash&to=text/html'
 });
 
 function ShumwayStreamOverlayConverter() {}
 ShumwayStreamOverlayConverter.prototype = new ShumwayStreamConverterBase();
 copyProperties(ShumwayStreamOverlayConverter.prototype, {
   classID: Components.ID('{4c6030f7-e20a-264f-5f9b-ada3a9e97384}'),
   classDescription: 'Shumway PlayPreview Component',
   contractID: '@mozilla.org/streamconv;1?from=application/x-moz-playpreview&to=*/*'
--- a/docshell/base/nsWebNavigationInfo.cpp
+++ b/docshell/base/nsWebNavigationInfo.cpp
@@ -46,16 +46,23 @@ nsWebNavigationInfo::IsTypeSupported(con
 
   // We want to claim that the type for PDF documents is unsupported,
   // so that the internal PDF viewer's stream converted will get used.
   if (aType.LowerCaseEqualsLiteral("application/pdf") &&
       nsContentUtils::IsPDFJSEnabled()) {
     return NS_OK;
   }
 
+  // We want to claim that the type for SWF movies is unsupported,
+  // so that the internal SWF player's stream converter will get used.
+  if (aType.LowerCaseEqualsLiteral("application/x-shockwave-flash") &&
+      nsContentUtils::IsSWFPlayerEnabled()) {
+    return NS_OK;
+  }
+
   const nsCString& flatType = PromiseFlatCString(aType);
   nsresult rv = IsTypeSupportedInternal(flatType, aIsTypeSupported);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (*aIsTypeSupported) {
     return rv;
   }
 
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -6573,16 +6573,30 @@ nsContentUtils::IsPDFJSEnabled()
    nsresult rv = NS_ERROR_FAILURE;
    bool canConvert = false;
    if (convServ) {
      rv = convServ->CanConvert("application/pdf", "text/html", &canConvert);
    }
    return NS_SUCCEEDED(rv) && canConvert;
 }
 
+bool
+nsContentUtils::IsSWFPlayerEnabled()
+{
+   nsCOMPtr<nsIStreamConverterService> convServ =
+     do_GetService("@mozilla.org/streamConverters;1");
+   nsresult rv = NS_ERROR_FAILURE;
+   bool canConvert = false;
+   if (convServ) {
+     rv = convServ->CanConvert("application/x-shockwave-flash",
+                               "text/html", &canConvert);
+   }
+   return NS_SUCCEEDED(rv) && canConvert;
+}
+
 already_AddRefed<nsIDocumentLoaderFactory>
 nsContentUtils::FindInternalContentViewer(const nsACString& aType,
                                           ContentViewerType* aLoaderType)
 {
   if (aLoaderType) {
     *aLoaderType = TYPE_UNSUPPORTED;
   }
 
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2102,16 +2102,21 @@ public:
    */
   static void XPCOMShutdown();
 
   /**
    * Checks if internal PDF viewer is enabled.
    */
   static bool IsPDFJSEnabled();
 
+  /**
+   * Checks if internal SWF player is enabled.
+   */
+  static bool IsSWFPlayerEnabled();
+
   enum ContentViewerType
   {
       TYPE_UNSUPPORTED,
       TYPE_CONTENT,
       TYPE_PLUGIN,
       TYPE_UNKNOWN
   };
 
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -553,16 +553,21 @@ IsPluginEnabledByExtension(nsIURI* uri, 
     return false;
   }
 
   // Disables any native PDF plugins, when internal PDF viewer is enabled.
   if (ext.EqualsIgnoreCase("pdf") && nsContentUtils::IsPDFJSEnabled()) {
     return false;
   }
 
+  // Disables any native SWF plugins, when internal SWF player is enabled.
+  if (ext.EqualsIgnoreCase("swf") && nsContentUtils::IsSWFPlayerEnabled()) {
+    return false;
+  }
+
   nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
 
   if (!pluginHost) {
     NS_NOTREACHED("No pluginhost");
     return false;
   }
 
   return pluginHost->HavePluginForExtension(ext, mimeType);
@@ -2684,16 +2689,23 @@ nsObjectLoadingContent::GetTypeOfContent
 
   // Faking support of the PDF content as a document for EMBED tags
   // when internal PDF viewer is enabled.
   if (aMIMEType.LowerCaseEqualsLiteral("application/pdf") &&
       nsContentUtils::IsPDFJSEnabled()) {
     return eType_Document;
   }
 
+  // Faking support of the SWF content as a document for EMBED tags
+  // when internal SWF player is enabled.
+  if (aMIMEType.LowerCaseEqualsLiteral("application/x-shockwave-flash") &&
+      nsContentUtils::IsSWFPlayerEnabled()) {
+    return eType_Document;
+  }
+
   // SVGs load as documents, but are their own capability
   bool isSVG = aMIMEType.LowerCaseEqualsLiteral("image/svg+xml");
   Capabilities supportType = isSVG ? eSupportSVG : eSupportDocuments;
   if ((caps & supportType) && IsSupportedDocument(aMIMEType)) {
     return eType_Document;
   }
 
   nsRefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();