Bug 1492374 - Uninstall ADB Helper when starting WebIDE addons module;r=ladybenko
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 01 Oct 2018 15:42:23 +0000
changeset 487392 77089282928991ef69a040b48b23cdff377598e9
parent 487391 e68feba6bf0178a01e5098f7a88b0a5bcc007473
child 487393 6341cb6ae607587609d46353fee88a1d737a7fa2
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersladybenko
bugs1492374
milestone64.0a1
Bug 1492374 - Uninstall ADB Helper when starting WebIDE addons module;r=ladybenko Depends on D7058. To test this you should first install ADB helper (xpis at https://ftp.mozilla.org/pub/labs/fxos-simulator/adb-helper/mac64/) and then start webIDE. Normally ADB Helper should be removed. Differential Revision: https://phabricator.services.mozilla.com/D7059
devtools/client/webide/modules/addons.js
--- a/devtools/client/webide/modules/addons.js
+++ b/devtools/client/webide/modules/addons.js
@@ -7,16 +7,19 @@
 const {AddonManager} = require("resource://gre/modules/AddonManager.jsm");
 const {Devices} = require("resource://devtools/shared/apps/Devices.jsm");
 const Services = require("Services");
 const EventEmitter = require("devtools/shared/event-emitter");
 
 var ADB_LINK = Services.prefs.getCharPref("devtools.remote.adb.extensionURL");
 var ADB_ADDON_ID = Services.prefs.getCharPref("devtools.remote.adb.extensionID");
 
+// Extension ID for adb helper extension that might be installed on Firefox 63 or older.
+const OLD_ADB_ADDON_ID = "adbhelper@mozilla.org";
+
 var platform = Services.appShell.hiddenDOMWindow.navigator.platform;
 var OS = "";
 if (platform.includes("Win")) {
   OS = "win32";
 } else if (platform.includes("Mac")) {
   OS = "mac64";
 } else if (platform.includes("Linux")) {
   if (platform.includes("x86_64")) {
@@ -47,19 +50,24 @@ var GetAvailableAddons = exports.GetAvai
 };
 
 exports.ForgetAddonsList = function() {
   AvailableAddons = 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);
+
+  // Uninstall old version of the extension that might be installed on this profile.
+  this.uninstallOldExtension();
+
   this.updateInstallStatus();
 }
 
 ADBAddon.prototype = {
   _status: "unknown",
   set status(value) {
     Devices.adbExtensionInstalled = (value == "installed");
     if (this._status != value) {
@@ -97,16 +105,23 @@ ADBAddon.prototype = {
     }
   },
 
   uninstall: async function() {
     const addon = await AddonManager.getAddonByID(ADB_ADDON_ID);
     addon.uninstall();
   },
 
+  uninstallOldExtension: async function() {
+    const oldAddon = await AddonManager.getAddonByID(OLD_ADB_ADDON_ID);
+    if (oldAddon) {
+      oldAddon.uninstall();
+    }
+  },
+
   installFailureHandler: function(install, message) {
     this.status = "uninstalled";
     this.emit("failure", message);
   },
 
   onDownloadStarted: function() {
     this.status = "downloading";
   },