Bug 1494615 - Remove concept of availableAddons in WebIDE;r=ladybenko
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 04 Oct 2018 16:09:44 +0000
changeset 495385 274c5774f6fb762d3124b11dd21824edf2d1301a
parent 495384 2f3ac50f1ce9fb8c9add3390085843975a5be10d
child 495386 3d5b641b9783187b6dba552bb246ec6d28d0dbbd
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersladybenko
bugs1494615
milestone64.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 1494615 - Remove concept of availableAddons in WebIDE;r=ladybenko There is only one addon to manage in WebIDe, removing the concept of available addons will make it easier to move the ADBAddon module to a shared folder. Differential Revision: https://phabricator.services.mozilla.com/D7402
devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js
devtools/client/webide/content/addons.js
devtools/client/webide/content/webide.js
devtools/client/webide/modules/addons.js
--- a/devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js
+++ b/devtools/client/aboutdebugging-new/src/modules/usb-runtimes.js
@@ -1,34 +1,34 @@
 /* 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/. */
 
 "use strict";
 
 const { ADBScanner } = require("devtools/shared/adb/adb-scanner");
-const { GetAvailableAddons } = require("devtools/client/webide/modules/addons");
+const { getADBAddon } = require("devtools/client/webide/modules/addons");
 
 /**
  * This module provides a collection of helper methods to detect USB runtimes whom Firefox
  * is running on.
  */
 function addUSBRuntimesObserver(listener) {
   ADBScanner.on("runtime-list-updated", listener);
 }
 exports.addUSBRuntimesObserver = addUSBRuntimesObserver;
 
 function disableUSBRuntimes() {
   ADBScanner.disable();
 }
 exports.disableUSBRuntimes = disableUSBRuntimes;
 
 async function enableUSBRuntimes() {
-  const { adb } = GetAvailableAddons();
-  if (adb.status !== "installed") {
+  const adbAddon = getADBAddon();
+  if (adbAddon.status !== "installed") {
     console.error("ADB extension is not installed");
     return;
   }
 
   ADBScanner.enable();
 }
 exports.enableUSBRuntimes = enableUSBRuntimes;
 
--- a/devtools/client/webide/content/addons.js
+++ b/devtools/client/webide/content/addons.js
@@ -1,44 +1,42 @@
 /* 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/. */
 
 const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
 const Services = require("Services");
 const {gDevTools} = require("devtools/client/framework/devtools");
-const {GetAvailableAddons, ForgetAddonsList} = require("devtools/client/webide/modules/addons");
+const {getADBAddon, forgetADBAddon} = require("devtools/client/webide/modules/addons");
 const Strings = Services.strings.createBundle("chrome://devtools/locale/webide.properties");
 const {ADBScanner} = require("devtools/shared/adb/adb-scanner");
 const {RuntimeScanners} = require("devtools/client/webide/modules/runtimes");
 
 window.addEventListener("load", function() {
   document.querySelector("#aboutaddons").onclick = function() {
     const browserWin = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
     if (browserWin && browserWin.BrowserOpenAddonsMgr) {
       browserWin.BrowserOpenAddonsMgr("addons://list/extension");
     }
   };
   document.querySelector("#close").onclick = CloseUI;
-  BuildUI(GetAvailableAddons());
+  BuildUI();
 }, {capture: true, once: true});
 
 window.addEventListener("unload", function() {
-  ForgetAddonsList();
+  forgetADBAddon();
 }, {capture: true, once: true});
 
 function CloseUI() {
   window.parent.UI.openProject();
 }
 
-function BuildUI(addons) {
-  BuildItem(addons.adb, "adb");
-}
+function BuildUI() {
+  const addon = getADBAddon();
 
-function BuildItem(addon, type) {
   function onAddonUpdate(arg) {
     progress.removeAttribute("value");
     li.setAttribute("status", addon.status);
     status.textContent = Strings.GetStringFromName("addons_status_" + addon.status);
     if (addon.status == "installed") {
       RuntimeScanners.add(ADBScanner);
     } else if (addon.status == "uninstalled") {
       RuntimeScanners.remove(ADBScanner);
@@ -68,22 +66,18 @@ function BuildItem(addon, type) {
   }, {once: true});
 
   const li = document.createElement("li");
   li.setAttribute("status", addon.status);
 
   const name = document.createElement("span");
   name.className = "name";
 
-  switch (type) {
-    case "adb":
-      li.setAttribute("addon", type);
-      name.textContent = "ADB Extension";
-      break;
-  }
+  li.setAttribute("addon", "adb");
+  name.textContent = "ADB Extension";
 
   li.appendChild(name);
 
   const status = document.createElement("span");
   status.className = "status";
   status.textContent = Strings.GetStringFromName("addons_status_" + addon.status);
   li.appendChild(status);
 
@@ -97,17 +91,15 @@ function BuildItem(addon, type) {
   uninstallButton.className = "uninstall-button";
   uninstallButton.onclick = () => addon.uninstall();
   uninstallButton.textContent = Strings.GetStringFromName("addons_uninstall_button");
   li.appendChild(uninstallButton);
 
   const progress = document.createElement("progress");
   li.appendChild(progress);
 
-  if (type == "adb") {
-    const warning = document.createElement("p");
-    warning.textContent = Strings.GetStringFromName("addons_adb_warning");
-    warning.className = "warning";
-    li.appendChild(warning);
-  }
+  const warning = document.createElement("p");
+  warning.textContent = Strings.GetStringFromName("addons_adb_warning");
+  warning.className = "warning";
+  li.appendChild(warning);
 
   document.querySelector("ul").appendChild(li);
 }
--- a/devtools/client/webide/content/webide.js
+++ b/devtools/client/webide/content/webide.js
@@ -11,17 +11,17 @@ const {gDevTools} = require("devtools/cl
 const {gDevToolsBrowser} = require("devtools/client/framework/devtools-browser");
 const {Toolbox} = require("devtools/client/framework/toolbox");
 const Services = require("Services");
 const {AppProjects} = require("devtools/client/webide/modules/app-projects");
 const {Connection} = require("devtools/shared/client/connection-manager");
 const {AppManager} = require("devtools/client/webide/modules/app-manager");
 const EventEmitter = require("devtools/shared/event-emitter");
 const promise = require("promise");
-const {GetAvailableAddons} = require("devtools/client/webide/modules/addons");
+const {getADBAddon} = require("devtools/client/webide/modules/addons");
 const {getJSON} = require("devtools/client/shared/getjson");
 const Telemetry = require("devtools/client/shared/telemetry");
 const {RuntimeScanners} = require("devtools/client/webide/modules/runtimes");
 const {openContentLink} = require("devtools/client/shared/link");
 
 const Strings =
   Services.strings.createBundle("chrome://devtools/locale/webide.properties");
 
@@ -81,18 +81,18 @@ var UI = {
       console.error(e);
       this.reportError("error_appProjectsLoadFailed");
     });
 
     // Auto install the ADB Addon Helper. Only once.
     // If the user decides to uninstall any of this addon, we won't install it again.
     const autoinstallADBExtension = Services.prefs.getBoolPref("devtools.webide.autoinstallADBExtension");
     if (autoinstallADBExtension) {
-      const addons = GetAvailableAddons();
-      addons.adb.install();
+      const adbAddon = getADBAddon();
+      adbAddon.install();
     }
 
     Services.prefs.setBoolPref("devtools.webide.autoinstallADBExtension", false);
 
     this.setupDeck();
 
     this.contentViewer = window.docShell.contentViewer;
     this.contentViewer.fullZoom = Services.prefs.getCharPref("devtools.webide.zoom");
--- a/devtools/client/webide/modules/addons.js
+++ b/devtools/client/webide/modules/addons.js
@@ -29,33 +29,30 @@ if (platform.includes("Win")) {
   }
 }
 
 var addonsListener = {};
 addonsListener.onEnabled =
 addonsListener.onDisabled =
 addonsListener.onInstalled =
 addonsListener.onUninstalled = (updatedAddon) => {
-  const addons = GetAvailableAddons();
-  addons.adb.updateInstallStatus();
+  getADBAddon().updateInstallStatus();
 };
 AddonManager.addAddonListener(addonsListener);
 
-var AvailableAddons = null;
-var GetAvailableAddons = exports.GetAvailableAddons = function() {
-  if (!AvailableAddons) {
-    AvailableAddons = {
-      adb: new ADBAddon()
-    };
+var adbAddon = null;
+var getADBAddon = exports.getADBAddon = function() {
+  if (!adbAddon) {
+    adbAddon = new ADBAddon();
   }
-  return AvailableAddons;
+  return adbAddon;
 };
 
-exports.ForgetAddonsList = function() {
-  AvailableAddons = null;
+exports.forgetADBAddon = function() {
+  adbAddon = null;
 };
 
 function ADBAddon() {
   EventEmitter.decorate(this);
 
   // This addon uses the string "linux" for "linux32"
   const fixedOS = OS == "linux32" ? "linux" : OS;
   this.xpiLink = ADB_LINK.replace(/#OS#/g, fixedOS);