Bug 1550928 part 1. Stop using [array] in nsIPluginTag. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 14 May 2019 09:11:37 +0000
changeset 532585 aa417164d4c7beb948c37df4b6d57986548a00ca
parent 532584 49dd0db0018af5f94f38a4dec13ad0246964827d
child 532586 b0c2270a44f33555ee54c4708f4b35a039375696
push id11270
push userrgurzau@mozilla.com
push dateWed, 15 May 2019 15:07:19 +0000
treeherdermozilla-beta@571bc76da583 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1550928
milestone68.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 1550928 part 1. Stop using [array] in nsIPluginTag. r=peterv Differential Revision: https://phabricator.services.mozilla.com/D30766
dom/plugins/base/nsIPluginTag.idl
dom/plugins/base/nsPluginTags.cpp
dom/plugins/test/mochitest/test_bug986930.html
toolkit/components/telemetry/app/TelemetryEnvironment.jsm
toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
toolkit/mozapps/extensions/internal/PluginProvider.jsm
--- a/dom/plugins/base/nsIPluginTag.idl
+++ b/dom/plugins/base/nsIPluginTag.idl
@@ -53,24 +53,19 @@ interface nsIPluginTag : nsISupports
   readonly attribute boolean clicktoplay;
   [infallible]
   readonly attribute boolean loaded;
   // See the STATE_* values above.
            attribute unsigned long enabledState;
 
   readonly attribute PRTime lastModifiedTime;
 
-  void getMimeTypes([optional] out unsigned long aCount,
-                    [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);
+  Array<AUTF8String> getMimeTypes();
+  Array<AUTF8String> getMimeDescriptions();
+  Array<AUTF8String> getExtensions();
 };
 
 /**
  * An interface representing a "fake" plugin: one implemented in JavaScript, not
  * as a NPAPI plug-in.  See nsIPluginHost.registerFakePlugin and the
  * documentation for the FakePluginTagInit dictionary.
  */
 [builtinclass, scriptable, uuid(6d22c968-226d-4156-b230-da6ad6bbf6e8)]
--- a/dom/plugins/base/nsPluginTags.cpp
+++ b/dom/plugins/base/nsPluginTags.cpp
@@ -117,35 +117,16 @@ static nsCString MakePrefNameForPlugin(c
   pref.AssignLiteral("plugin.");
   pref.Append(subname);
   pref.Append('.');
   pref.Append(pluginName);
 
   return pref;
 }
 
-static nsresult CStringArrayToXPCArray(nsTArray<nsCString>& aArray,
-                                       uint32_t* aCount, char16_t*** aResults) {
-  uint32_t count = aArray.Length();
-  if (!count) {
-    *aResults = nullptr;
-    *aCount = 0;
-    return NS_OK;
-  }
-
-  *aResults = static_cast<char16_t**>(moz_xmalloc(count * sizeof(**aResults)));
-  *aCount = count;
-
-  for (uint32_t i = 0; i < count; i++) {
-    (*aResults)[i] = ToNewUnicode(NS_ConvertUTF8toUTF16(aArray[i]));
-  }
-
-  return NS_OK;
-}
-
 static nsCString GetStatePrefNameForPlugin(nsIInternalPluginTag* aTag) {
   return MakePrefNameForPlugin("state", aTag);
 }
 
 static nsresult IsEnabledStateLockedForPlugin(nsIInternalPluginTag* aTag,
                                               bool* aIsEnabledStateLocked) {
   *aIsEnabledStateLocked = false;
   nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
@@ -586,28 +567,31 @@ void nsPluginTag::SetPluginState(PluginS
   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, char16_t*** aResults) {
-  return CStringArrayToXPCArray(mMimeTypes, aCount, aResults);
+nsPluginTag::GetMimeTypes(nsTArray<nsCString>& aResults) {
+  aResults = mMimeTypes;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPluginTag::GetMimeDescriptions(uint32_t* aCount, char16_t*** aResults) {
-  return CStringArrayToXPCArray(mMimeDescriptions, aCount, aResults);
+nsPluginTag::GetMimeDescriptions(nsTArray<nsCString>& aResults) {
+  aResults = mMimeDescriptions;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPluginTag::GetExtensions(uint32_t* aCount, char16_t*** aResults) {
-  return CStringArrayToXPCArray(mExtensions, aCount, aResults);
+nsPluginTag::GetExtensions(nsTArray<nsCString>& aResults) {
+  aResults = mExtensions;
+  return NS_OK;
 }
 
 bool nsPluginTag::HasSameNameAndMimes(const nsPluginTag* aPluginTag) const {
   NS_ENSURE_TRUE(aPluginTag, false);
 
   if ((!mName.Equals(aPluginTag->mName)) ||
       (mMimeTypes.Length() != aPluginTag->mMimeTypes.Length())) {
     return false;
@@ -859,28 +843,31 @@ NS_IMETHODIMP
 nsFakePluginTag::SetEnabledState(uint32_t aEnabledState) {
   // There are static asserts above enforcing that this enum matches
   mState = (nsPluginTag::PluginState)aEnabledState;
   // FIXME-jsplugins update
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsFakePluginTag::GetMimeTypes(uint32_t* aCount, char16_t*** aResults) {
-  return CStringArrayToXPCArray(mMimeTypes, aCount, aResults);
+nsFakePluginTag::GetMimeTypes(nsTArray<nsCString>& aResults) {
+  aResults = mMimeTypes;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-nsFakePluginTag::GetMimeDescriptions(uint32_t* aCount, char16_t*** aResults) {
-  return CStringArrayToXPCArray(mMimeDescriptions, aCount, aResults);
+nsFakePluginTag::GetMimeDescriptions(nsTArray<nsCString>& aResults) {
+  aResults = mMimeDescriptions;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-nsFakePluginTag::GetExtensions(uint32_t* aCount, char16_t*** aResults) {
-  return CStringArrayToXPCArray(mExtensions, aCount, aResults);
+nsFakePluginTag::GetExtensions(nsTArray<nsCString>& aResults) {
+  aResults = mExtensions;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFakePluginTag::GetActive(bool* aResult) {
   // Fake plugins can't be blocklisted, so this is just !Disabled
   *aResult = IsEnabled();
   return NS_OK;
 }
--- a/dom/plugins/test/mochitest/test_bug986930.html
+++ b/dom/plugins/test/mochitest/test_bug986930.html
@@ -6,15 +6,15 @@
   <script src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript" src="plugin-utils.js"></script>
 </head>
 <body>
   <script class="testbody" type="application/javascript">
     var testPlugin = getTestPlugin("Test Plug-in");
 
-    var mimeDescriptions = testPlugin.getMimeDescriptions({});
+    var mimeDescriptions = testPlugin.getMimeDescriptions();
 
     is(mimeDescriptions[0], "Test \u2122 mimetype",
        "Plugin should handle non-ascii mime description");
   </script>
 </body>
 </html>
--- a/toolkit/components/telemetry/app/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/app/TelemetryEnvironment.jsm
@@ -843,17 +843,17 @@ EnvironmentAddonBuilder.prototype = {
 
         activePlugins.push({
           name: limitStringToLength(tag.name, MAX_ADDON_STRING_LENGTH),
           version: limitStringToLength(tag.version, MAX_ADDON_STRING_LENGTH),
           description: limitStringToLength(tag.description, MAX_ADDON_STRING_LENGTH),
           blocklisted: tag.blocklisted,
           disabled: tag.disabled,
           clicktoplay: tag.clicktoplay,
-          mimeTypes: tag.getMimeTypes({}),
+          mimeTypes: tag.getMimeTypes(),
           updateDay: Utils.millisecondsToDays(updateDate.getTime()),
         });
       } catch (ex) {
         this._environment._log.error("_getActivePlugins - A plugin was discarded due to an error", ex);
         continue;
       }
     }
 
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
@@ -109,18 +109,17 @@ PluginTag.prototype = {
     return this.pluginTag.enabledState == Ci.nsIPluginTag.STATE_DISABLED;
   },
   set disabled(val) {
     this.pluginTag.enabledState = Ci.nsIPluginTag[val ? "STATE_DISABLED" : "STATE_CLICKTOPLAY"];
   },
 
   mimeTypes: [ PLUGIN_MIME_TYPE1, PLUGIN_MIME_TYPE2 ],
 
-  getMimeTypes(count) {
-    count.value = this.mimeTypes.length;
+  getMimeTypes() {
     return this.mimeTypes;
   },
 };
 
 // A container for the plugins handled by the fake plugin host.
 var gInstalledPlugins = [
   new PluginTag("Java", "A mock Java plugin", "1.0", false /* Disabled */),
   new PluginTag(FLASH_PLUGIN_NAME, FLASH_PLUGIN_DESC, FLASH_PLUGIN_VERSION, true),
--- a/toolkit/mozapps/extensions/internal/PluginProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/PluginProvider.jsm
@@ -382,19 +382,19 @@ PluginWrapper.prototype = {
     for (let tag of pluginFor(this).tags)
       paths.push(tag.fullpath);
     return paths;
   },
 
   get pluginMimeTypes() {
     let types = [];
     for (let tag of pluginFor(this).tags) {
-      let mimeTypes = tag.getMimeTypes({});
-      let mimeDescriptions = tag.getMimeDescriptions({});
-      let extensions = tag.getExtensions({});
+      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);
       }