Bug 1502437 - Hide system add-ons in about:performance when browser internals are hidden, r=felipe a=jcristau
authorFlorian Quèze <florian@queze.net>
Wed, 31 Oct 2018 19:10:51 +0100
changeset 501075 02f3ab06c2eb5abc97b49c12d3702d50c439526f
parent 501074 61362de96df954b728a8a9787e1839bc8b15dbc1
child 501076 ab7f1db24dde0647fbe476237b6684a5201f07cb
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, jcristau
bugs1502437
milestone64.0
Bug 1502437 - Hide system add-ons in about:performance when browser internals are hidden, r=felipe a=jcristau
toolkit/components/aboutperformance/content/aboutPerformance.js
--- a/toolkit/components/aboutperformance/content/aboutPerformance.js
+++ b/toolkit/components/aboutperformance/content/aboutPerformance.js
@@ -4,16 +4,17 @@
  * 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/. */
 
 "use strict";
 
 const { PerformanceStats } = ChromeUtils.import("resource://gre/modules/PerformanceStats.jsm", {});
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm", {});
 const { ObjectUtils } = ChromeUtils.import("resource://gre/modules/ObjectUtils.jsm", {});
+const { AddonManager } = ChromeUtils.import("resource://gre/modules/AddonManager.jsm", {});
 const { ExtensionParent } = ChromeUtils.import("resource://gre/modules/ExtensionParent.jsm", {});
 
 const {WebExtensionPolicy} = Cu.getGlobalForObject(Services);
 
 // Time in ms before we start changing the sort order again after receiving a
 // mousemove event.
 const TIME_BEFORE_SORTING_AGAIN = 5000;
 
@@ -76,16 +77,23 @@ const MODE_RECENT = "recent";
 function performanceCountersEnabled() {
   return Services.prefs.getBoolPref("dom.performance.enable_scheduler_timing", false);
 }
 
 function extensionCountersEnabled() {
   return Services.prefs.getBoolPref("extensions.webextensions.enablePerformanceCounters", false);
 }
 
+// The ids of system add-ons, so that we can hide them when the
+// toolkit.aboutPerformance.showInternals pref is false.
+// The API to access addons is async, so we cache the list during init.
+// The list is unlikely to change while the about:performance
+// tab is open, so not updating seems fine.
+var gSystemAddonIds = new Set();
+
 let tabFinder = {
   update() {
     this._map = new Map();
     for (let win of Services.wm.getEnumerator("navigator:browser")) {
       let tabbrowser = win.gBrowser;
       for (let browser of tabbrowser.browsers) {
         let id = browser.outerWindowID; // May be `null` if the browser isn't loaded yet
         if (id != null) {
@@ -635,17 +643,17 @@ var State = {
       } else if (id == 1) {
         name = BRAND_NAME;
         image = "chrome://branding/content/icon32.png";
         type = "browser";
       } else if (/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/.test(host)) {
         let addon = WebExtensionPolicy.getByHostname(host);
         name = `${addon.name} (${addon.id})`;
         image = "chrome://mozapps/skin/extensions/extensionGeneric-16.svg";
-        type = "addon";
+        type = gSystemAddonIds.has(addon.id) ? "system-addon" : "addon";
       } else if (id == 0 && !tab.isWorker) {
         name = {id: "ghost-windows"};
       }
 
       if (type != "tab" && type != "addon" &&
           !Services.prefs.getBoolPref("toolkit.aboutPerformance.showInternals", false)) {
         continue;
       }
@@ -1047,16 +1055,18 @@ var View = {
       elt.classList.add("indent");
     else
       elt.classList.add("root");
     if (["tracker", "worker"].includes(type))
       elt.classList.add(type);
     row.appendChild(elt);
 
     elt = document.createElement("td");
+    if (type == "system-addon")
+      type = "addon";
     document.l10n.setAttributes(elt, "type-" + type);
     row.appendChild(elt);
 
     elt = document.createElement("td");
     this.displayEnergyImpact(elt, energyImpact);
     row.appendChild(elt);
 
     if (tooltip)
@@ -1396,16 +1406,23 @@ var Control = {
 var go = async function() {
 
   Control.init();
 
   if (performanceCountersEnabled()) {
     let opt = document.querySelector(".options");
     opt.style.display = "none";
     opt.nextElementSibling.style.display = "none";
+
+    let addons = await AddonManager.getAddonsByTypes(["extension"]);
+    for (let addon of addons) {
+      if (addon.isSystem) {
+        gSystemAddonIds.add(addon.id);
+      }
+    }
   } else {
     document.getElementById("dispatch-table").parentNode.style.display = "none";
   }
 
   // Setup a hook to allow tests to configure and control this page
   let testUpdate = function(subject, topic, value) {
     let options = JSON.parse(value);
     Control._setOptions(options);