Bug 1144204. Stop returning things for non-plug-in MIME types from the navigator.mimeTypes getter. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 21 Mar 2016 11:01:49 -0400
changeset 289720 960029b66e4c3f02862d00d080a399cf15d00438
parent 289719 3cdd3f35f65e7bc85fa2719504d55d0e3900734b
child 289721 72a2ec038f5366bf1af0ed4426a76851aa2d6aac
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1144204
milestone48.0a1
Bug 1144204. Stop returning things for non-plug-in MIME types from the navigator.mimeTypes getter. r=smaug
dom/base/nsMimeTypeArray.cpp
dom/base/nsMimeTypeArray.h
--- a/dom/base/nsMimeTypeArray.cpp
+++ b/dom/base/nsMimeTypeArray.cpp
@@ -114,60 +114,17 @@ nsMimeTypeArray::NamedGetter(const nsASt
   ToLowerCase(lowerName);
 
   nsMimeType* mimeType = FindMimeType(mMimeTypes, lowerName);
   if (mimeType) {
     aFound = true;
     return mimeType;
   }
 
-  // Now let's check with the MIME service.
-  nsCOMPtr<nsIMIMEService> mimeSrv = do_GetService("@mozilla.org/mime;1");
-  if (!mimeSrv) {
-    return nullptr;
-  }
-
-  nsCOMPtr<nsIMIMEInfo> mimeInfo;
-  mimeSrv->GetFromTypeAndExtension(NS_ConvertUTF16toUTF8(lowerName),
-                                   EmptyCString(), getter_AddRefs(mimeInfo));
-  if (!mimeInfo) {
-    return nullptr;
-  }
-
-  // Now we check whether we can really claim to support this type
-  nsHandlerInfoAction action = nsIHandlerInfo::saveToDisk;
-  mimeInfo->GetPreferredAction(&action);
-  if (action != nsIMIMEInfo::handleInternally) {
-    bool hasHelper = false;
-    mimeInfo->GetHasDefaultHandler(&hasHelper);
-
-    if (!hasHelper) {
-      nsCOMPtr<nsIHandlerApp> helper;
-      mimeInfo->GetPreferredApplicationHandler(getter_AddRefs(helper));
-
-      if (!helper) {
-        // mime info from the OS may not have a PreferredApplicationHandler
-        // so just check for an empty default description
-        nsAutoString defaultDescription;
-        mimeInfo->GetDefaultDescription(defaultDescription);
-
-        if (defaultDescription.IsEmpty()) {
-          // no support; just leave
-          return nullptr;
-        }
-      }
-    }
-  }
-
-  // If we got here, we support this type!  Say so.
-  aFound = true;
-
-  nsMimeType *mt = new nsMimeType(mWindow, lowerName);
-  mMimeTypes.AppendElement(mt);
-  return mt;
+  return nullptr;
 }
 
 bool
 nsMimeTypeArray::NameIsEnumerable(const nsAString& aName)
 {
   return true;
 }
 
@@ -223,23 +180,17 @@ nsMimeType::nsMimeType(nsPIDOMWindowInne
                        const nsAString& aDescription,
                        const nsAString& aExtension)
   : mWindow(aWindow),
     mPluginElement(aPluginElement),
     mType(aType),
     mDescription(aDescription),
     mExtension(aExtension)
 {
-}
-
-nsMimeType::nsMimeType(nsPIDOMWindowInner* aWindow, const nsAString& aType)
-  : mWindow(aWindow),
-    mPluginElement(nullptr),
-    mType(aType)
-{
+  MOZ_ASSERT(aPluginElement);
 }
 
 nsMimeType::~nsMimeType()
 {
 }
 
 nsPIDOMWindowInner*
 nsMimeType::GetParentObject() const
@@ -258,16 +209,18 @@ void
 nsMimeType::GetDescription(nsString& aRetval) const
 {
   aRetval = mDescription;
 }
 
 nsPluginElement*
 nsMimeType::GetEnabledPlugin() const
 {
+  // mPluginElement might be null if we got unlinked but are still somehow being
+  // called into.
   if (!mPluginElement || !mPluginElement->PluginTag()->IsEnabled()) {
     return nullptr;
   }
   return mPluginElement;
 }
 
 void
 nsMimeType::GetSuffixes(nsString& aRetval) const
--- a/dom/base/nsMimeTypeArray.h
+++ b/dom/base/nsMimeTypeArray.h
@@ -58,17 +58,16 @@ public:
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsMimeType)
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(nsMimeType)
 
   nsMimeType(nsPIDOMWindowInner* aWindow,
              nsPluginElement* aPluginElement,
              const nsAString& aType,
              const nsAString& aDescription,
              const nsAString& aExtension);
-  nsMimeType(nsPIDOMWindowInner* aWindow, const nsAString& aMimeType);
   nsPIDOMWindowInner* GetParentObject() const;
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   const nsString& Type() const
   {
     return mType;
   }
 
@@ -78,19 +77,18 @@ public:
   void GetSuffixes(nsString& retval) const;
   void GetType(nsString& retval) const;
 
 protected:
   virtual ~nsMimeType();
 
   nsCOMPtr<nsPIDOMWindowInner> mWindow;
 
-  // Strong reference to the active plugin, if any. Note that this
-  // creates an explicit reference cycle through the plugin element's
-  // mimetype array. We rely on the cycle collector to break this
-  // cycle.
+  // Strong reference to the active plugin. Note that this creates an explicit
+  // reference cycle through the plugin element's mimetype array. We rely on the
+  // cycle collector to break this cycle.
   RefPtr<nsPluginElement> mPluginElement;
   nsString mType;
   nsString mDescription;
   nsString mExtension;
 };
 
 #endif /* nsMimeTypeArray_h___ */