Bug 1550928 part 2. Stop using [array] in nsIPluginHost. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 14 May 2019 09:11:45 +0000
changeset 532586 b0c2270a44f33555ee54c4708f4b35a039375696
parent 532585 aa417164d4c7beb948c37df4b6d57986548a00ca
child 532587 d4ee430e90c2c4b21d13b2f1de063928f1b53d1d
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 2. Stop using [array] in nsIPluginHost. r=peterv Differential Revision: https://phabricator.services.mozilla.com/D30767
dom/plugins/base/nsIPluginHost.idl
dom/plugins/base/nsPluginHost.cpp
toolkit/components/telemetry/app/TelemetryEnvironment.jsm
toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
toolkit/mozapps/extensions/internal/PluginProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/head_addons.js
--- a/dom/plugins/base/nsIPluginHost.idl
+++ b/dom/plugins/base/nsIPluginHost.idl
@@ -25,18 +25,17 @@ interface nsIClearSiteDataCallback : nsI
 interface nsIPluginHost : nsISupports
 {
   /**
    * Causes the plugins directory to be searched again for new plugin
    * libraries.
    */
   void reloadPlugins();
 
-  void getPluginTags([optional] out unsigned long aPluginCount,
-    [retval, array, size_is(aPluginCount)] out nsIPluginTag aResults);
+  Array<nsIPluginTag> getPluginTags();
 
   /*
    * Flags for use with clearSiteData.
    *
    * FLAG_CLEAR_ALL: clear all data associated with a site.
    * FLAG_CLEAR_CACHE: clear cached data that can be retrieved again without
    *                   loss of functionality. To be used out of concern for
    *                   space and not necessarily privacy.
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -1085,43 +1085,25 @@ void nsPluginHost::GetPlugins(
       aPluginArray.AppendElement(plugin);
     }
     plugin = plugin->mNext;
   }
 }
 
 // FIXME-jsplugins Check users for order of fake v non-fake
 NS_IMETHODIMP
-nsPluginHost::GetPluginTags(uint32_t* aPluginCount, nsIPluginTag*** aResults) {
+nsPluginHost::GetPluginTags(nsTArray<RefPtr<nsIPluginTag>>& aResults) {
   LoadPlugins();
 
-  uint32_t count = 0;
-  uint32_t fakeCount = mFakePlugins.Length();
-  RefPtr<nsPluginTag> plugin = mPlugins;
-  while (plugin != nullptr) {
-    count++;
-    plugin = plugin->mNext;
+  for (nsPluginTag* plugin = mPlugins; plugin; plugin = plugin->mNext) {
+    aResults.AppendElement(plugin);
   }
 
-  *aResults = static_cast<nsIPluginTag**>(
-      moz_xmalloc((fakeCount + count) * sizeof(**aResults)));
-
-  *aPluginCount = count + fakeCount;
-
-  plugin = mPlugins;
-  for (uint32_t i = 0; i < count; i++) {
-    (*aResults)[i] = plugin;
-    NS_ADDREF((*aResults)[i]);
-    plugin = plugin->mNext;
-  }
-
-  for (uint32_t i = 0; i < fakeCount; i++) {
-    (*aResults)[i + count] =
-        static_cast<nsIInternalPluginTag*>(mFakePlugins[i]);
-    NS_ADDREF((*aResults)[i + count]);
+  for (nsIInternalPluginTag* plugin : mFakePlugins) {
+    aResults.AppendElement(plugin);
   }
 
   return NS_OK;
 }
 
 nsPluginTag* nsPluginHost::FindPreferredPlugin(
     const InfallibleTArray<nsPluginTag*>& matches) {
   // We prefer the plugin with the highest version number.
--- a/toolkit/components/telemetry/app/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/app/TelemetryEnvironment.jsm
@@ -823,17 +823,17 @@ EnvironmentAddonBuilder.prototype = {
       return [{
         name: "dummy", version: "0.1", description: "Blocklist unavailable",
         blocklisted: false, disabled: true, clicktoplay: false,
         mimeTypes: ["text/there.is.only.blocklist"],
         updateDay: Utils.millisecondsToDays(Date.now()),
       }];
     }
     let pluginTags =
-      Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost).getPluginTags({});
+      Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost).getPluginTags();
 
     let activePlugins = [];
     for (let tag of pluginTags) {
       // Skip plugins which are not active.
       if (tag.disabled) {
         continue;
       }
 
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
@@ -122,18 +122,17 @@ PluginTag.prototype = {
 // 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 fake plugin host for testing plugin telemetry environment.
 var PluginHost = {
-  getPluginTags(countRef) {
-    countRef.value = gInstalledPlugins.length;
+  getPluginTags() {
     return gInstalledPlugins.map(plugin => plugin.pluginTag);
   },
 
   QueryInterface: ChromeUtils.generateQI(["nsIPluginHost"]),
 };
 
 function registerFakePluginHost() {
   MockRegistrar.register("@mozilla.org/plugin/host;1", PluginHost);
--- a/toolkit/mozapps/extensions/internal/PluginProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/PluginProvider.jsm
@@ -135,17 +135,17 @@ var PluginProvider = {
   /**
    * Builds a list of the current plugins reported by the plugin host
    *
    * @return a dictionary of plugins indexed by our generated ID
    */
   getPluginList() {
     let tags = Cc["@mozilla.org/plugin/host;1"].
                getService(Ci.nsIPluginHost).
-               getPluginTags({});
+               getPluginTags();
 
     let list = {};
     let seenPlugins = {};
     for (let tag of tags) {
       if (!(tag.name in seenPlugins))
         seenPlugins[tag.name] = {};
       if (!(tag.description in seenPlugins[tag.name])) {
         let plugin = {
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -1065,18 +1065,17 @@ class MockPluginTag {
   }
   set enabledState(val) {
     this.pluginTag.enabledState = val;
   }
 }
 
 function mockPluginHost(plugins) {
   let PluginHost = {
-    getPluginTags(count) {
-      count.value = plugins.length;
+    getPluginTags() {
       return plugins.map(p => p.pluginTag);
     },
 
     QueryInterface: ChromeUtils.generateQI(["nsIPluginHost"]),
   };
 
   MockRegistrar.register("@mozilla.org/plugin/host;1", PluginHost);
 }