Bug 855613. Stop exposing nsIDOMMimeType in nsIPluginTag. r=joshmoz@gmail.com
authorJohnny Stenback <jst@mozilla.com>
Wed, 27 Mar 2013 22:19:41 -0700
changeset 133651 ec45e0246b831ea03cc5ba1ab2ddd5bbe6880a0b
parent 133650 cd7ca5763eac533de86f4edd8b8f861ae237fb74
child 133652 9bcaba8046eeab95bd4552a2f68767b4f524a22e
push id28852
push userjst@mozilla.com
push dateSat, 01 Jun 2013 06:41:08 +0000
treeherdermozilla-inbound@ec45e0246b83 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoshmoz
bugs855613
milestone24.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 855613. Stop exposing nsIDOMMimeType in nsIPluginTag. r=joshmoz@gmail.com
browser/base/content/pageinfo/permissions.js
dom/plugins/base/nsIPluginTag.idl
dom/plugins/base/nsPluginTags.cpp
dom/plugins/test/mochitest/test_refresh_navigator_plugins.html
toolkit/mozapps/extensions/PluginProvider.jsm
--- a/browser/base/content/pageinfo/permissions.js
+++ b/browser/base/content/pageinfo/permissions.js
@@ -297,29 +297,29 @@ function clearPluginPermissionTemplate()
 }
 
 function initPluginsRow() {
   let pluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
   let tags = pluginHost.getPluginTags().filter(function(aTag) {
     let mimeTypes = aTag.getMimeTypes();
     if (mimeTypes.length < 1)
       return false;
-    let mimeType = mimeTypes[0].type;
+    let mimeType = mimeTypes[0];
     return (!aTag.disabled && pluginHost.isPluginClickToPlayForType(mimeType));
   });
 
   tags.sort(function(tagA, tagB) {
     let nameA = makeNicePluginName(tagA.name);
     let nameB = makeNicePluginName(tagB.name);
     return nameA < nameB ? -1 : (nameA == nameB ? 0 : 1);
   });
 
   let permissionEntries = [];
   for (let plugin of tags) {
-    let mimeType = plugin.getMimeTypes()[0].type;
+    let mimeType = plugin.getMimeTypes()[0];
     let permString = pluginHost.getPermissionStringForType(mimeType);
     let pluginName = makeNicePluginName(plugin.name)
     let permEntry = fillInPluginPermissionTemplate(pluginName, permString);
     permissionEntries.push(permEntry);
   }
 
   let permPluginsRow = document.getElementById("permPluginsRow");
   clearPluginPermissionTemplate();
--- a/dom/plugins/base/nsIPluginTag.idl
+++ b/dom/plugins/base/nsIPluginTag.idl
@@ -1,30 +1,35 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 "nsISupports.idl"
-interface nsIDOMMimeType;
 
-[scriptable, uuid(87b4fcfc-417b-47f6-9c79-dfeb5e5a4840)]
+[scriptable, uuid(00ea1f72-a57a-49bb-ac57-478902d9228b)]
 interface nsIPluginTag : nsISupports
 {
   // enabledState is stored as one of the following as an integer in prefs,
   // so if new states are added, they must not renumber the existing states.
   const unsigned long STATE_DISABLED = 0;
   const unsigned long STATE_CLICKTOPLAY = 1;
   const unsigned long STATE_ENABLED = 2;
 
   readonly attribute AUTF8String description;
   readonly attribute AUTF8String filename;
   readonly attribute AUTF8String fullpath;
   readonly attribute AUTF8String version;
   readonly attribute AUTF8String name;
-           attribute boolean  blocklisted;
-  readonly attribute boolean  disabled;
-  readonly attribute boolean  clicktoplay;
+           attribute boolean blocklisted;
+  readonly attribute boolean disabled;
+  readonly attribute boolean clicktoplay;
            attribute unsigned long enabledState;
 
   void getMimeTypes([optional] out unsigned long aCount,
-                    [retval, array, size_is(aCount)] out nsIDOMMimeType aResults);
+                    [retval, array, size_is(aCount)] out wstring aResults);
+  void getMimeDescriptions([optional] out unsigned long aCount,
+                           [retval, array, size_is(aCount)]
+                           out wstring aResults);
+  void getExtensions([optional] out unsigned long aCount,
+                     [retval, array, size_is(aCount)]
+                     out wstring aResults);
 };
--- a/dom/plugins/base/nsPluginTags.cpp
+++ b/dom/plugins/base/nsPluginTags.cpp
@@ -69,43 +69,43 @@ GetBlocklistedPrefNameForPlugin(nsPlugin
   return MakePrefNameForPlugin("blocklisted", aTag);
 }
 
 NS_IMPL_ISUPPORTS1(DOMMimeTypeImpl, nsIDOMMimeType)
 
 /* nsPluginTag */
 
 nsPluginTag::nsPluginTag(nsPluginTag* aPluginTag)
-: mName(aPluginTag->mName),
-mDescription(aPluginTag->mDescription),
-mMimeTypes(aPluginTag->mMimeTypes),
-mMimeDescriptions(aPluginTag->mMimeDescriptions),
-mExtensions(aPluginTag->mExtensions),
-mLibrary(nullptr),
-mIsJavaPlugin(aPluginTag->mIsJavaPlugin),
-mIsFlashPlugin(aPluginTag->mIsFlashPlugin),
-mFileName(aPluginTag->mFileName),
-mFullPath(aPluginTag->mFullPath),
-mVersion(aPluginTag->mVersion),
-mLastModifiedTime(0),
-mNiceFileName()
+  : mName(aPluginTag->mName),
+    mDescription(aPluginTag->mDescription),
+    mMimeTypes(aPluginTag->mMimeTypes),
+    mMimeDescriptions(aPluginTag->mMimeDescriptions),
+    mExtensions(aPluginTag->mExtensions),
+    mLibrary(nullptr),
+    mIsJavaPlugin(aPluginTag->mIsJavaPlugin),
+    mIsFlashPlugin(aPluginTag->mIsFlashPlugin),
+    mFileName(aPluginTag->mFileName),
+    mFullPath(aPluginTag->mFullPath),
+    mVersion(aPluginTag->mVersion),
+    mLastModifiedTime(0),
+    mNiceFileName()
 {
 }
 
 nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo)
-: mName(aPluginInfo->fName),
-mDescription(aPluginInfo->fDescription),
-mLibrary(nullptr),
-mIsJavaPlugin(false),
-mIsFlashPlugin(false),
-mFileName(aPluginInfo->fFileName),
-mFullPath(aPluginInfo->fFullPath),
-mVersion(aPluginInfo->fVersion),
-mLastModifiedTime(0),
-mNiceFileName()
+  : mName(aPluginInfo->fName),
+    mDescription(aPluginInfo->fDescription),
+    mLibrary(nullptr),
+    mIsJavaPlugin(false),
+    mIsFlashPlugin(false),
+    mFileName(aPluginInfo->fFileName),
+    mFullPath(aPluginInfo->fFullPath),
+    mVersion(aPluginInfo->fVersion),
+    mLastModifiedTime(0),
+    mNiceFileName()
 {
   InitMime(aPluginInfo->fMimeTypeArray,
            aPluginInfo->fMimeDescriptionArray,
            aPluginInfo->fExtensionArray,
            aPluginInfo->fVariantCount);
   EnsureMembersAreUTF8();
 }
 
@@ -115,28 +115,29 @@ nsPluginTag::nsPluginTag(const char* aNa
                          const char* aFullPath,
                          const char* aVersion,
                          const char* const* aMimeTypes,
                          const char* const* aMimeDescriptions,
                          const char* const* aExtensions,
                          int32_t aVariants,
                          int64_t aLastModifiedTime,
                          bool aArgsAreUTF8)
-: mName(aName),
-mDescription(aDescription),
-mLibrary(nullptr),
-mIsJavaPlugin(false),
-mIsFlashPlugin(false),
-mFileName(aFileName),
-mFullPath(aFullPath),
-mVersion(aVersion),
-mLastModifiedTime(aLastModifiedTime),
-mNiceFileName()
+  : mName(aName),
+    mDescription(aDescription),
+    mLibrary(nullptr),
+    mIsJavaPlugin(false),
+    mIsFlashPlugin(false),
+    mFileName(aFileName),
+    mFullPath(aFullPath),
+    mVersion(aVersion),
+    mLastModifiedTime(aLastModifiedTime),
+    mNiceFileName()
 {
-  InitMime(aMimeTypes, aMimeDescriptions, aExtensions, static_cast<uint32_t>(aVariants));
+  InitMime(aMimeTypes, aMimeDescriptions, aExtensions,
+           static_cast<uint32_t>(aVariants));
   if (!aArgsAreUTF8)
     EnsureMembersAreUTF8();
 }
 
 nsPluginTag::~nsPluginTag()
 {
   NS_ASSERTION(!mNext, "Risk of exhausting the stack space, bug 486349");
 }
@@ -426,29 +427,61 @@ nsPluginTag::SetPluginState(PluginState 
 {
   MOZ_STATIC_ASSERT((uint32_t)nsPluginTag::ePluginState_Disabled == nsIPluginTag::STATE_DISABLED, "nsPluginTag::ePluginState_Disabled must match nsIPluginTag::STATE_DISABLED");
   MOZ_STATIC_ASSERT((uint32_t)nsPluginTag::ePluginState_Clicktoplay == nsIPluginTag::STATE_CLICKTOPLAY, "nsPluginTag::ePluginState_Clicktoplay must match nsIPluginTag::STATE_CLICKTOPLAY");
   MOZ_STATIC_ASSERT((uint32_t)nsPluginTag::ePluginState_Enabled == nsIPluginTag::STATE_ENABLED, "nsPluginTag::ePluginState_Enabled must match nsIPluginTag::STATE_ENABLED");
   SetEnabledState((uint32_t)state);
 }
 
 NS_IMETHODIMP
-nsPluginTag::GetMimeTypes(uint32_t* aCount, nsIDOMMimeType*** aResults)
+nsPluginTag::GetMimeTypes(uint32_t* aCount, PRUnichar*** aResults)
 {
   uint32_t count = mMimeTypes.Length();
-  *aResults = static_cast<nsIDOMMimeType**>
+  *aResults = static_cast<PRUnichar**>
                          (nsMemory::Alloc(count * sizeof(**aResults)));
   if (!*aResults)
     return NS_ERROR_OUT_OF_MEMORY;
   *aCount = count;
 
   for (uint32_t i = 0; i < count; i++) {
-    nsIDOMMimeType* mimeType = new DOMMimeTypeImpl(this, i);
-    (*aResults)[i] = mimeType;
-    NS_ADDREF((*aResults)[i]);
+    (*aResults)[i] = ToNewUnicode(mMimeTypes[i]);
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPluginTag::GetMimeDescriptions(uint32_t* aCount, PRUnichar*** aResults)
+{
+  uint32_t count = mMimeDescriptions.Length();
+  *aResults = static_cast<PRUnichar**>
+                         (nsMemory::Alloc(count * sizeof(**aResults)));
+  if (!*aResults)
+    return NS_ERROR_OUT_OF_MEMORY;
+  *aCount = count;
+
+  for (uint32_t i = 0; i < count; i++) {
+    (*aResults)[i] = ToNewUnicode(mMimeDescriptions[i]);
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPluginTag::GetExtensions(uint32_t* aCount, PRUnichar*** aResults)
+{
+  uint32_t count = mExtensions.Length();
+  *aResults = static_cast<PRUnichar**>
+                         (nsMemory::Alloc(count * sizeof(**aResults)));
+  if (!*aResults)
+    return NS_ERROR_OUT_OF_MEMORY;
+  *aCount = count;
+
+  for (uint32_t i = 0; i < count; i++) {
+    (*aResults)[i] = ToNewUnicode(mExtensions[i]);
   }
 
   return NS_OK;
 }
 
 bool
 nsPluginTag::HasSameNameAndMimes(const nsPluginTag *aPluginTag) const
 {
--- a/dom/plugins/test/mochitest/test_refresh_navigator_plugins.html
+++ b/dom/plugins/test/mochitest/test_refresh_navigator_plugins.html
@@ -32,32 +32,32 @@
         if (plugin.name == navTestPlugin.name) {
           tagTestPlugin = plugin;
           break;
         }
       }
       ok(tagTestPlugin, "plugin tags should have Test Plug-in");
       var mimeType = tagTestPlugin.getMimeTypes()[0];
       ok(mimeType, "should have a MIME type for Test Plug-in");
-      ok(navigator.mimeTypes[mimeType.type], "navigator.mimeTypes should have an entry for '" + mimeType.type + "'");
+      ok(navigator.mimeTypes[mimeType], "navigator.mimeTypes should have an entry for '" + mimeType + "'");
       ok(!tagTestPlugin.disabled, "test plugin should not be disabled");
 
       nextTest = testPart2;
       tagTestPlugin.enabledState = Components.interfaces.nsIPluginTag.STATE_DISABLED;
 
       function testPart2() {
         var navTestPlugin = navigator.plugins.namedItem("Test Plug-in");
         ok(!navTestPlugin, "now navigator.plugins should not have Test Plug-in");
-        ok(!navigator.mimeTypes[mimeType.type], "now navigator.mimeTypes should not have an entry for '" + mimeType.type + "'");
+        ok(!navigator.mimeTypes[mimeType], "now navigator.mimeTypes should not have an entry for '" + mimeType + "'");
 
         nextTest = testPart3;
         tagTestPlugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED;
       }
 
       function testPart3() {
         ok(navTestPlugin, "now navigator.plugins should have Test Plug-in again");
-        ok(navigator.mimeTypes[mimeType.type], "now navigator.mimeTypes should have an entry for '" + mimeType.type + "' again");
+        ok(navigator.mimeTypes[mimeType], "now navigator.mimeTypes should have an entry for '" + mimeType + "' again");
         obsService.removeObserver(observer, "plugin-info-updated");
         SimpleTest.finish();
       }
     </script>
   </body>
 </html>
--- a/toolkit/mozapps/extensions/PluginProvider.jsm
+++ b/toolkit/mozapps/extensions/PluginProvider.jsm
@@ -397,19 +397,29 @@ function PluginWrapper(aId, aName, aDesc
     let paths = [];
     for (let tag of aTags)
       paths.push(tag.fullpath);
     return paths;
   })
 
   this.__defineGetter__("pluginMimeTypes", function() {
     let types = [];
-    for (let tag of aTags)
-      for (let type of tag.getMimeTypes({}))
+    for (let tag of aTags) {
+      let mimeTypes = tag.getMimeTypes({});
+      let mimeDescriptions = tag.getMimeDescriptions({});
+      let extensions = tag.getExtensions({});
+      for (let i = 0; i < mimeTypes.length; i++) {
+        let type = {};
+        type.type = mimeTypes[i];
+        type.description = mimeDescriptions[i];
+        type.suffixes = extensions[i];
+
         types.push(type);
+      }
+    }
     return types;
   });
 
   this.__defineGetter__("installDate", function() {
     let date = 0;
     let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
     for (let tag of aTags) {
       file.initWithPath(tag.fullpath);