Bug 1351490 - Only run plugin finding on flash mime types/extensions; r?bsmedberg draft
authorKyle Machulis <kyle@nonpolynomial.com>
Tue, 28 Mar 2017 15:51:16 -0700
changeset 554554 85de901fd86d19ac00f2a8a3ba3f4b3fc7415e29
parent 554553 a2cb4183bf3cb88834fd83dc9d314414025fa013
child 622380 67905563b1133d5709a9aa93484e80583bcb10ff
push id51981
push userbmo:kyle@nonpolynomial.com
push dateFri, 31 Mar 2017 22:02:02 +0000
reviewersbsmedberg
bugs1351490
milestone55.0a1
Bug 1351490 - Only run plugin finding on flash mime types/extensions; r?bsmedberg Now that we only support the flash plugin, we should only run plugin finding if the flash mime type is requested. MozReview-Commit-ID: CrHkTe2aEyz
docshell/base/nsWebNavigationInfo.cpp
dom/plugins/base/nsPluginHost.cpp
dom/plugins/base/nsPluginHost.h
--- a/docshell/base/nsWebNavigationInfo.cpp
+++ b/docshell/base/nsWebNavigationInfo.cpp
@@ -7,23 +7,20 @@
 #include "nsWebNavigationInfo.h"
 #include "nsIWebNavigation.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIDocumentLoaderFactory.h"
 #include "nsIPluginHost.h"
 #include "nsIDocShell.h"
 #include "nsContentUtils.h"
 #include "imgLoader.h"
+#include "nsPluginHost.h"
 
 NS_IMPL_ISUPPORTS(nsWebNavigationInfo, nsIWebNavigationInfo)
 
-#define CONTENT_DLF_CONTRACT "@mozilla.org/content/document-loader-factory;1"
-#define PLUGIN_DLF_CONTRACT \
-  "@mozilla.org/content/plugin/document-loader-factory;1"
-
 nsresult
 nsWebNavigationInfo::Init()
 {
   nsresult rv;
   mCategoryManager = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
@@ -54,16 +51,22 @@ nsWebNavigationInfo::IsTypeSupported(con
   const nsCString& flatType = PromiseFlatCString(aType);
   nsresult rv = IsTypeSupportedInternal(flatType, aIsTypeSupported);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (*aIsTypeSupported) {
     return rv;
   }
 
+  // As of FF 52, we only support flash and test plugins, so if the mime types
+  // don't match for that, exit before we start loading plugins.
+  if (!nsPluginHost::CanUsePluginForMIMEType(aType)) {
+    return NS_OK;
+  }
+
   // If this request is for a docShell that isn't going to allow plugins,
   // there's no need to try and find a plugin to handle it.
   nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aWebNav));
   bool allowed;
   if (docShell &&
       NS_SUCCEEDED(docShell->GetAllowPlugins(&allowed)) && !allowed) {
     return NS_OK;
   }
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -1030,16 +1030,22 @@ nsPluginHost::GetPermissionStringForTag(
   return NS_OK;
 }
 
 bool
 nsPluginHost::HavePluginForExtension(const nsACString & aExtension,
                                      /* out */ nsACString & aMimeType,
                                      PluginFilter aFilter)
 {
+  // As of FF 52, we only support flash and test plugins, so if the extension types
+  // don't match for that, exit before we start loading plugins.
+  if (!aExtension.LowerCaseEqualsLiteral("swf")) {
+    return false;
+  }
+
   bool checkEnabled = aFilter & eExcludeDisabled;
   bool allowFake = !(aFilter & eExcludeFake);
   return FindNativePluginForExtension(aExtension, aMimeType, checkEnabled) ||
     (allowFake &&
      FindFakePluginForExtension(aExtension, aMimeType, checkEnabled));
 }
 
 void
@@ -1171,16 +1177,22 @@ nsPluginHost::FindFakePluginForType(cons
 nsPluginTag*
 nsPluginHost::FindNativePluginForType(const nsACString & aMimeType,
                                       bool aCheckEnabled)
 {
   if (aMimeType.IsEmpty()) {
     return nullptr;
   }
 
+  // As of FF 52, we only support flash and test plugins, so if the mime types
+  // don't match for that, exit before we start loading plugins.
+  if (!nsPluginHost::CanUsePluginForMIMEType(aMimeType)) {
+    return nullptr;
+  }
+
   LoadPlugins();
 
   InfallibleTArray<nsPluginTag*> matchingPlugins;
 
   nsPluginTag *plugin = mPlugins;
   while (plugin) {
     if ((!aCheckEnabled || plugin->IsActive()) &&
         plugin->HasMimeType(aMimeType)) {
@@ -3955,16 +3967,35 @@ nsPluginHost::DestroyRunningInstances(ns
       // Notify owning content that we destroyed its plugin out from under it
       if (objectContent) {
         objectContent->PluginDestroyed();
       }
     }
   }
 }
 
+/* static */
+bool
+nsPluginHost::CanUsePluginForMIMEType(const nsACString& aMIMEType)
+{
+  // We only support flash as a plugin, so if the mime types don't match for
+  // those, exit before we start loading plugins.
+  //
+  // XXX: Remove test/java cases when bug 1351885 lands.
+  if (nsPluginHost::GetSpecialType(aMIMEType) == nsPluginHost::eSpecialType_Flash ||
+      aMIMEType.LowerCaseEqualsLiteral("application/x-test") ||
+      aMIMEType.LowerCaseEqualsLiteral("application/x-second-test") ||
+      aMIMEType.LowerCaseEqualsLiteral("application/x-third-test") ||
+      aMIMEType.LowerCaseEqualsLiteral("application/x-java-test")) {
+    return true;
+  }
+
+  return false;
+}
+
 // Runnable that does an async destroy of a plugin.
 
 class nsPluginDestroyRunnable : public Runnable,
                                 public PRCList
 {
 public:
   explicit nsPluginDestroyRunnable(nsNPAPIPluginInstance *aInstance)
     : Runnable("nsPluginDestroyRunnable"),
--- a/dom/plugins/base/nsPluginHost.h
+++ b/dom/plugins/base/nsPluginHost.h
@@ -185,16 +185,23 @@ public:
   // Always returns true if plugin.allowed_types is not set
   static bool IsTypeWhitelisted(const char *aType);
 
   // Helper that checks if a plugin of a given MIME type can be loaded by the
   // parent process. It checks the plugin.load_in_parent_process.<mime> pref.
   // Always returns false if plugin.load_in_parent_process.<mime> is not set.
   static bool ShouldLoadTypeInParent(const nsACString& aMimeType);
 
+  /**
+   * Returns true if a plugin can be used to load the requested MIME type. Used
+   * for short circuiting before sending things to plugin code.
+   */
+  static bool
+  CanUsePluginForMIMEType(const nsACString& aMIMEType);
+
   // checks whether aType is a type we recognize for potential special handling
   enum SpecialType {
     eSpecialType_None,
     // Needed to whitelist for async init support
     eSpecialType_Test,
     // Informs some decisions about OOP and quirks
     eSpecialType_Flash,
     // Binds to the <applet> tag, has various special