Bug 1401324 - Remember last folder used to load a temporary extension r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 07 May 2019 06:32:00 +0000
changeset 531666 ecc1127396f971e2bddee56a4d101129ec067e2f
parent 531665 2104abac31980477345157f35a84b09b8c0891d5
child 531667 1f27cacfb9cf3cb7d16925ab1ab70617e05f7f73
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1401324
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 1401324 - Remember last folder used to load a temporary extension r=daisuke Differential Revision: https://phabricator.services.mozilla.com/D29141
devtools/client/aboutdebugging-new/src/constants.js
devtools/client/aboutdebugging-new/src/modules/extensions-helper.js
--- a/devtools/client/aboutdebugging-new/src/constants.js
+++ b/devtools/client/aboutdebugging-new/src/constants.js
@@ -104,16 +104,18 @@ const PAGE_TYPES = {
 
 const PREFERENCES = {
   // Preference that drives the display of the "Tabs" category on This Firefox.
   LOCAL_TAB_DEBUGGING_ENABLED: "devtools.aboutdebugging.local-tab-debugging",
   // Preference that drives the display of the "Processes" debug target category.
   PROCESS_DEBUGGING_ENABLED: "devtools.aboutdebugging.process-debugging",
   // Preference that drives the display of hidden & system addons in about:debugging.
   SHOW_HIDDEN_ADDONS: "devtools.aboutdebugging.showHiddenAddons",
+  // Preference to store the last path used for loading a temporary extension.
+  TEMPORARY_EXTENSION_PATH: "devtools.aboutdebugging.tmpExtDirPath",
   // Preference that disables installing extensions when set to false.
   XPINSTALL_ENABLED: "xpinstall.enabled",
 };
 
 const RUNTIME_PREFERENCE = {
   CHROME_DEBUG_ENABLED: "devtools.chrome.enabled",
   CONNECTION_PROMPT: "devtools.debugger.prompt-connection",
   PERMANENT_PRIVATE_BROWSING: "browser.privatebrowsing.autostart",
--- a/devtools/client/aboutdebugging-new/src/modules/extensions-helper.js
+++ b/devtools/client/aboutdebugging-new/src/modules/extensions-helper.js
@@ -1,20 +1,23 @@
 /* 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 { Cc, Ci } = require("chrome");
+const Services = require("Services");
 loader.lazyImporter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
+loader.lazyRequireGetter(this, "FileUtils", "resource://gre/modules/FileUtils.jsm", true);
 
 const {Toolbox} = require("devtools/client/framework/toolbox");
+const {gDevTools} = require("devtools/client/framework/devtools");
 
-const {gDevTools} = require("devtools/client/framework/devtools");
+const { PREFERENCES } = require("../constants");
 
 let addonToolbox = null;
 
 /**
  * Start debugging an addon.
  *
  * @param {String} id
  *        The addon id to debug.
@@ -80,24 +83,38 @@ exports.getExtensionUuid = function(exte
  *         The help message that should be displayed to the user in the filepicker.
  * @return {Promise} returns a promise that resolves a File object corresponding to the
  *         file selected by the user.
  */
 exports.openTemporaryExtension = function(win, message) {
   return new Promise(resolve => {
     const fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
     fp.init(win, message, Ci.nsIFilePicker.modeOpen);
+
+    // Try to set the last directory used as "displayDirectory".
+    try {
+      const lastDirPath =
+        Services.prefs.getCharPref(PREFERENCES.TEMPORARY_EXTENSION_PATH, "");
+      const lastDir = new FileUtils.File(lastDirPath);
+      fp.displayDirectory = lastDir;
+    } catch (e) {
+      // Empty or invalid value, nothing to handle.
+    }
+
     fp.open(res => {
       if (res == Ci.nsIFilePicker.returnCancel || !fp.file) {
         return;
       }
       let file = fp.file;
       // AddonManager.installTemporaryAddon accepts either
       // addon directory or final xpi file.
       if (!file.isDirectory() &&
           !file.leafName.endsWith(".xpi") && !file.leafName.endsWith(".zip")) {
         file = file.parent;
       }
 
+      // We are about to resolve, store the path to the file for the next call.
+      Services.prefs.setCharPref(PREFERENCES.TEMPORARY_EXTENSION_PATH, file.path);
+
       resolve(file);
     });
   });
 };