Bug 1369801 - dt-addon: set extensions.startupScanScopes in BrowserToolbox profile;r=ochameau draft
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 11 Aug 2017 17:04:38 +0200
changeset 658595 6e9a31febd1e1aa40fb6bdb88366e7debf4cdb7c
parent 658594 d4497cdd76481c911b1864c4fe6fc34da76461d0
child 729703 911a441102a269d606360ef466da79c8c7e2cc75
push id77820
push userjdescottes@mozilla.com
push dateMon, 04 Sep 2017 11:44:42 +0000
reviewersochameau
bugs1369801
milestone57.0a1
Bug 1369801 - dt-addon: set extensions.startupScanScopes in BrowserToolbox profile;r=ochameau Create a user.js file for the chrome_debugger_profile to set startupScanScopes to AddonManager.SCOPE_ALL This will force Firefox to scan the system addon and install it when starting the profile. MozReview-Commit-ID: palK2hION0
devtools/client/framework/ToolboxProcess.jsm
--- a/devtools/client/framework/ToolboxProcess.jsm
+++ b/devtools/client/framework/ToolboxProcess.jsm
@@ -8,18 +8,20 @@
 
 const { interfaces: Ci, utils: Cu, results: Cr } = Components;
 
 const DBG_XUL = "chrome://devtools/content/framework/toolbox-process-window.xul";
 const CHROME_DEBUGGER_PROFILE_NAME = "chrome_debugger_profile";
 
 const { require, DevToolsLoader } = Cu.import("resource://devtools/shared/Loader.jsm", {});
 const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
+const { FileUtils } = require("resource://gre/modules/FileUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Subprocess", "resource://gre/modules/Subprocess.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
 XPCOMUtils.defineLazyGetter(this, "Telemetry", function () {
   return require("devtools/client/shared/telemetry");
 });
 XPCOMUtils.defineLazyGetter(this, "EventEmitter", function () {
   return require("devtools/shared/old-event-emitter");
 });
 XPCOMUtils.defineLazyGetter(this, "system", function () {
   return require("devtools/shared/system");
@@ -188,16 +190,30 @@ BrowserToolboxProcess.prototype = {
       return;
     }
 
     this._dbgProfilePath = debuggingProfileDir.path;
 
     // We would like to copy prefs into this new profile...
     let prefsFile = debuggingProfileDir.clone();
     prefsFile.append("prefs.js");
+
+    // We set extensions.startupScanScopes to SCOPE_ALL to force the BrowserToolbox
+    // profile to scan the system addon on startup, and write it to user.js
+    let userFile = debuggingProfileDir.clone();
+    userFile.append("user.js");
+    if (!userFile.exists()) {
+      userFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
+      let out = FileUtils.openFileOutputStream(userFile,
+            FileUtils.MODE_WRONLY | FileUtils.MODE_APPEND);
+      let str = `user_pref("extensions.startupScanScopes", ${AddonManager.SCOPE_ALL});\n`;
+      out.write(str, str.length);
+      out.close();
+    }
+
     // ... but unfortunately, when we run tests, it seems the starting profile
     // clears out the prefs file before re-writing it, and in practice the
     // file is empty when we get here. So just copying doesn't work in that
     // case.
     // We could force a sync pref flush and then copy it... but if we're doing
     // that, we might as well just flush directly to the new profile, which
     // always works:
     Services.prefs.savePrefFile(prefsFile);