Bug 1250833 - Stop using browser.xul globals specific to devtools. r=jryans
authorAlexandre Poirot <poirot.alex@gmail.com>
Sat, 27 Feb 2016 04:51:11 -0800
changeset 324013 c71cf2cec67dd2bc97b0a7091544e6679faa438d
parent 324012 49253a251d3e6b783e7d985a81b669e2eeb31c97
child 324014 9b8fd7fc3d8d9babbc0668230acc4f65e15640bd
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1250833
milestone47.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 1250833 - Stop using browser.xul globals specific to devtools. r=jryans
devtools/client/commandline/test/browser_cmd_commands.js
devtools/client/responsive.html/test/browser/head.js
devtools/client/responsivedesign/resize-commands.js
devtools/client/responsivedesign/test/browser_responsive_cmd.js
devtools/client/responsivedesign/test/head.js
devtools/client/scratchpad/scratchpad-commands.js
devtools/client/scratchpad/scratchpad.js
devtools/client/scratchpad/test/browser_scratchpad_chrome_context_pref.js
devtools/client/scratchpad/test/browser_scratchpad_help_key.js
devtools/client/scratchpad/test/browser_scratchpad_initialization.js
devtools/client/scratchpad/test/browser_scratchpad_open_error_console.js
devtools/client/scratchpad/test/browser_scratchpad_restore.js
devtools/client/scratchpad/test/browser_scratchpad_tab.js
devtools/client/scratchpad/test/browser_scratchpad_unsaved.js
devtools/client/scratchpad/test/head.js
devtools/client/shared/test/browser_telemetry_button_responsive.js
devtools/client/webconsole/test/browser_console_private_browsing.js
devtools/client/webconsole/test/head.js
devtools/shared/gcli/commands/jsb.js
--- a/devtools/client/commandline/test/browser_cmd_commands.js
+++ b/devtools/client/commandline/test/browser_cmd_commands.js
@@ -1,14 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Test various GCLI commands
 
 const TEST_URI = "data:text/html;charset=utf-8,gcli-commands";
+const HUDService = require("devtools/client/webconsole/hudservice");
 
 function test() {
   return Task.spawn(spawnTest).then(finish, helpers.handleError);
 }
 
 function* spawnTest() {
   let options = yield helpers.openTab(TEST_URI);
   yield helpers.openToolbar(options);
--- a/devtools/client/responsive.html/test/browser/head.js
+++ b/devtools/client/responsive.html/test/browser/head.js
@@ -1,47 +1,47 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 /* eslint no-unused-vars: [2, {"vars": "local"}] */
 /* import-globals-from ../../../framework/test/shared-head.js */
 /* import-globals-from ../../../framework/test/shared-redux-head.js */
-/* global ResponsiveUI */
 
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/devtools/client/framework/test/shared-head.js",
   this);
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/devtools/client/framework/test/shared-redux-head.js",
   this);
 
 Services.prefs.setBoolPref("devtools.responsive.html.enabled", true);
 registerCleanupFunction(() => {
   Services.prefs.clearUserPref("devtools.responsive.html.enabled");
 });
+const { ResponsiveUIManager } = Cu.import("resource://devtools/client/responsivedesign/responsivedesign.jsm", {});
 
 /**
  * Open responsive design mode for the given tab.
  */
 var openRDM = Task.async(function*(tab) {
   info("Opening responsive design mode");
-  let manager = ResponsiveUI.ResponsiveUIManager;
+  let manager = ResponsiveUIManager;
   let ui = yield manager.openIfNeeded(window, tab);
   info("Responsive design mode opened");
   return { ui, manager };
 });
 
 /**
  * Close responsive design mode for the given tab.
  */
 var closeRDM = Task.async(function*(tab) {
   info("Closing responsive design mode");
-  let manager = ResponsiveUI.ResponsiveUIManager;
+  let manager = ResponsiveUIManager;
   manager.closeIfNeeded(window, tab);
   info("Responsive design mode closed");
 });
 
 /**
  * Adds a new test task that adds a tab with the given URL, opens responsive
  * design mode, runs the given generator, closes responsive design mode, and
  * removes the tab.
--- a/devtools/client/responsivedesign/resize-commands.js
+++ b/devtools/client/responsivedesign/resize-commands.js
@@ -1,16 +1,18 @@
 /* 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, Cu } = require("chrome");
 
+loader.lazyImporter(this, "ResponsiveUIManager", "resource://devtools/client/responsivedesign/responsivedesign.jsm");
+
 const BRAND_SHORT_NAME = Cc["@mozilla.org/intl/stringbundle;1"].
                          getService(Ci.nsIStringBundleService).
                          createBundle("chrome://branding/locale/brand.properties").
                          GetStringFromName("brandShortName");
 
 const l10n = require("gcli/l10n");
 
 exports.items = [
@@ -43,34 +45,28 @@ exports.items = [
     tooltipText: l10n.lookup("resizeModeToggleTooltip"),
     description: l10n.lookup('resizeModeToggleDesc'),
     manual: l10n.lookupFormat('resizeModeManual2', [BRAND_SHORT_NAME]),
     state: {
       isChecked: function(aTarget) {
         if (!aTarget.tab) {
           return false;
         }
-        let browserWindow = aTarget.tab.ownerDocument.defaultView;
-        let mgr = browserWindow.ResponsiveUI.ResponsiveUIManager;
-        return mgr.isActiveForTab(aTarget.tab);
+        return ResponsiveUIManager.isActiveForTab(aTarget.tab);
       },
       onChange: function(aTarget, aChangeHandler) {
         if (aTarget.tab) {
-          let browserWindow = aTarget.tab.ownerDocument.defaultView;
-          let mgr = browserWindow.ResponsiveUI.ResponsiveUIManager;
-          mgr.on("on", aChangeHandler);
-          mgr.on("off", aChangeHandler);
+          ResponsiveUIManager.on("on", aChangeHandler);
+          ResponsiveUIManager.on("off", aChangeHandler);
         }
       },
       offChange: function(aTarget, aChangeHandler) {
         if (aTarget.tab) {
-          let browserWindow = aTarget.tab.ownerDocument.defaultView;
-          let mgr = browserWindow.ResponsiveUI.ResponsiveUIManager;
-          mgr.off("on", aChangeHandler);
-          mgr.off("off", aChangeHandler);
+          ResponsiveUIManager.off("on", aChangeHandler);
+          ResponsiveUIManager.off("off", aChangeHandler);
         }
       },
     },
     exec: gcli_cmd_resize
   },
   {
     item: "command",
     runAt: "client",
@@ -89,14 +85,13 @@ exports.items = [
       },
     ],
     exec: gcli_cmd_resize
   }
 ];
 
 function* gcli_cmd_resize(args, context) {
   let browserWindow = context.environment.chromeWindow;
-  let mgr = browserWindow.ResponsiveUI.ResponsiveUIManager;
-  yield mgr.handleGcliCommand(browserWindow,
-                              browserWindow.gBrowser.selectedTab,
-                              this.name,
-                              args);
+  yield ResponsiveUIManager.handleGcliCommand(browserWindow,
+                                              browserWindow.gBrowser.selectedTab,
+                                              this.name,
+                                              args);
 }
--- a/devtools/client/responsivedesign/test/browser_responsive_cmd.js
+++ b/devtools/client/responsivedesign/test/browser_responsive_cmd.js
@@ -6,17 +6,17 @@
 ///////////////////
 //
 // Whitelisting this test.
 // As part of bug 1077403, the leaking uncaught rejection should be fixed.
 //
 thisTestLeaksUncaughtRejectionsAndShouldBeFixed("destroy");
 
 function test() {
-  let manager = ResponsiveUI.ResponsiveUIManager;
+  let manager = ResponsiveUIManager;
   let done;
 
   function isOpen() {
     return gBrowser.getBrowserContainer(gBrowser.selectedBrowser)
                    .hasAttribute("responsivemode");
   }
 
   helpers.addTabWithToolbar("data:text/html;charset=utf-8,hi", (options) => {
--- a/devtools/client/responsivedesign/test/head.js
+++ b/devtools/client/responsivedesign/test/head.js
@@ -19,25 +19,27 @@ registerCleanupFunction(() => {
   Services.prefs.clearUserPref("devtools.responsiveUI.customHeight");
   Services.prefs.clearUserPref("devtools.responsiveUI.customWidth");
   Services.prefs.clearUserPref("devtools.responsiveUI.presets");
   Services.prefs.clearUserPref("devtools.responsiveUI.rotate");
 });
 
 SimpleTest.requestCompleteLog();
 
+const { ResponsiveUIManager } = Cu.import("resource://devtools/client/responsivedesign/responsivedesign.jsm", {});
+
 /**
  * Open the Responsive Design Mode
  * @param {Tab} The browser tab to open it into (defaults to the selected tab).
  * @param {method} The method to use to open the RDM (values: menu, keyboard)
  * @return {rdm, manager} Returns the RUI instance and the manager
  */
 var openRDM = Task.async(function*(tab = gBrowser.selectedTab,
                                    method = "menu") {
-  let manager = ResponsiveUI.ResponsiveUIManager;
+  let manager = ResponsiveUIManager;
 
   let opened = once(manager, "on");
   let resized = once(manager, "contentResize");
   if (method == "menu") {
     document.getElementById("Tools:ResponsiveUI").doCommand();
   } else {
     synthesizeKeyFromKeyTag(document.getElementById("key_responsiveUI"));
   }
@@ -56,17 +58,17 @@ var openRDM = Task.async(function*(tab =
   return {rdm, manager};
 });
 
 /**
  * Close a responsive mode instance
  * @param {rdm} ResponsiveUI instance for the tab
  */
 var closeRDM = Task.async(function*(rdm) {
-  let manager = ResponsiveUI.ResponsiveUIManager;
+  let manager = ResponsiveUIManager;
   if (!rdm) {
     rdm = manager.getResponsiveUIForTab(gBrowser.selectedTab);
   }
   let closed = once(manager, "off");
   let resized = once(manager, "contentResize");
   rdm.close();
   yield resized;
   yield closed;
--- a/devtools/client/scratchpad/scratchpad-commands.js
+++ b/devtools/client/scratchpad/scratchpad-commands.js
@@ -1,21 +1,22 @@
 /* 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 l10n = require("gcli/l10n");
+const {Cu} = require("chrome");
 
 exports.items = [{
   item: "command",
   runAt: "client",
   name: "scratchpad",
   buttonId: "command-button-scratchpad",
   buttonClass: "command-button command-button-invertable",
   tooltipText: l10n.lookup("scratchpadOpenTooltip"),
   hidden: true,
   exec: function(args, context) {
-    let Scratchpad = context.environment.chromeWindow.Scratchpad;
-    Scratchpad.ScratchpadManager.openScratchpad();
+    const {ScratchpadManager} = Cu.import("resource://devtools/client/scratchpad/scratchpad-manager.jsm", {});
+    ScratchpadManager.openScratchpad();
   }
 }];
--- a/devtools/client/scratchpad/scratchpad.js
+++ b/devtools/client/scratchpad/scratchpad.js
@@ -76,16 +76,17 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "VariablesViewController",
   "resource://devtools/client/shared/widgets/VariablesViewController.jsm");
 
 loader.lazyRequireGetter(this, "DebuggerServer", "devtools/server/main", true);
 
 loader.lazyRequireGetter(this, "DebuggerClient", "devtools/shared/client/main", true);
 loader.lazyRequireGetter(this, "EnvironmentClient", "devtools/shared/client/main", true);
 loader.lazyRequireGetter(this, "ObjectClient", "devtools/shared/client/main", true);
+loader.lazyRequireGetter(this, "HUDService", "devtools/client/webconsole/hudservice");
 
 XPCOMUtils.defineLazyGetter(this, "REMOTE_TIMEOUT", () =>
   Services.prefs.getIntPref("devtools.debugger.remote-timeout"));
 
 XPCOMUtils.defineLazyModuleGetter(this, "ShortcutUtils",
   "resource://gre/modules/ShortcutUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Reflect",
@@ -1586,17 +1587,17 @@ var Scratchpad = {
     }
   },
 
   /**
    * Open the Error Console.
    */
   openErrorConsole: function SP_openErrorConsole()
   {
-    this.browserWindow.HUDService.toggleBrowserConsole();
+    HUDService.toggleBrowserConsole();
   },
 
   /**
    * Open the Web Console.
    */
   openWebConsole: function SP_openWebConsole()
   {
     let target = TargetFactory.forTab(this.gBrowser.selectedTab);
--- a/devtools/client/scratchpad/test/browser_scratchpad_chrome_context_pref.js
+++ b/devtools/client/scratchpad/test/browser_scratchpad_chrome_context_pref.js
@@ -10,18 +10,16 @@ function test()
   waitForExplicitFinish();
 
   Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, true);
 
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
     gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
 
-    ok(window.Scratchpad, "Scratchpad variable exists");
-
     openScratchpad(runTests);
   }, true);
 
   content.location = "data:text/html,Scratchpad test for bug 646070 - chrome context preference";
 }
 
 function runTests()
 {
--- a/devtools/client/scratchpad/test/browser_scratchpad_help_key.js
+++ b/devtools/client/scratchpad/test/browser_scratchpad_help_key.js
@@ -7,18 +7,16 @@ function test()
 {
   waitForExplicitFinish();
 
   gBrowser.selectedTab = gBrowser.addTab();
   content.location = "data:text/html,Test keybindings for opening Scratchpad MDN Documentation, bug 650760";
   gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() {
     gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
 
-    ok(window.Scratchpad, "Scratchpad variable exists");
-
     openScratchpad(runTest);
   }, true);
 }
 
 function runTest()
 {
   let sp = gScratchpadWindow.Scratchpad;
   ok(sp, "Scratchpad object exists in new window");
--- a/devtools/client/scratchpad/test/browser_scratchpad_initialization.js
+++ b/devtools/client/scratchpad/test/browser_scratchpad_initialization.js
@@ -8,18 +8,16 @@ function test()
 {
   waitForExplicitFinish();
 
   Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, false);
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
     gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
 
-    ok(window.Scratchpad, "Scratchpad variable exists");
-
     openScratchpad(runTests);
   }, true);
 
   content.location = "data:text/html,initialization test for Scratchpad";
 }
 
 function runTests()
 {
--- a/devtools/client/scratchpad/test/browser_scratchpad_open_error_console.js
+++ b/devtools/client/scratchpad/test/browser_scratchpad_open_error_console.js
@@ -1,12 +1,14 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+const HUDService = require("devtools/client/webconsole/hudservice");
+
 function test()
 {
   waitForExplicitFinish();
 
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
     gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
     openScratchpad(runTests);
--- a/devtools/client/scratchpad/test/browser_scratchpad_restore.js
+++ b/devtools/client/scratchpad/test/browser_scratchpad_restore.js
@@ -1,14 +1,12 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-var ScratchpadManager = Scratchpad.ScratchpadManager;
-
 /* Call the iterator for each item in the list,
    calling the final callback with all the results
    after every iterator call has sent its result */
 function asyncMap(items, iterator, callback)
 {
   let expected = items.length;
   let results = [];
 
--- a/devtools/client/scratchpad/test/browser_scratchpad_tab.js
+++ b/devtools/client/scratchpad/test/browser_scratchpad_tab.js
@@ -6,18 +6,16 @@
 function test()
 {
   waitForExplicitFinish();
 
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() {
     gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
 
-    ok(window.Scratchpad, "Scratchpad variable exists");
-
     Services.prefs.setIntPref("devtools.editor.tabsize", 5);
 
     openScratchpad(runTests);
   }, true);
 
   content.location = "data:text/html,Scratchpad test for the Tab key, bug 660560";
 }
 
--- a/devtools/client/scratchpad/test/browser_scratchpad_unsaved.js
+++ b/devtools/client/scratchpad/test/browser_scratchpad_unsaved.js
@@ -8,18 +8,16 @@ const expected = 4;
 var count = 0;
 function done()
 {
   if (++count == expected) {
     finish();
   }
 }
 
-var ScratchpadManager = Scratchpad.ScratchpadManager;
-
 
 function test()
 {
   waitForExplicitFinish();
 
   testListeners();
   testRestoreNotFromFile();
   testRestoreFromFileSaved();
--- a/devtools/client/scratchpad/test/head.js
+++ b/devtools/client/scratchpad/test/head.js
@@ -2,16 +2,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const {NetUtil} = Cu.import("resource://gre/modules/NetUtil.jsm", {});
 const {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm", {});
 const {console} = Cu.import("resource://gre/modules/Console.jsm", {});
+const {ScratchpadManager} = Cu.import("resource://devtools/client/scratchpad/scratchpad-manager.jsm", {});
 const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
 const Services = require("Services");
 const DevToolsUtils = require("devtools/shared/DevToolsUtils");
 const promise = require("promise");
 
 
 var gScratchpadWindow; // Reference to the Scratchpad chrome window object
 
@@ -39,17 +40,17 @@ SimpleTest.registerCleanupFunction(() =>
  * @return nsIDOMWindow
  *         The new window object that holds Scratchpad. Note that the
  *         gScratchpadWindow global is also updated to reference the new window
  *         object.
  */
 function openScratchpad(aReadyCallback, aOptions = {})
 {
   let win = aOptions.window ||
-            Scratchpad.ScratchpadManager.openScratchpad(aOptions.state);
+            ScratchpadManager.openScratchpad(aOptions.state);
   if (!win) {
     return;
   }
 
   let onLoad = function() {
     win.removeEventListener("load", onLoad, false);
 
     win.Scratchpad.addObserver({
--- a/devtools/client/shared/test/browser_telemetry_button_responsive.js
+++ b/devtools/client/shared/test/browser_telemetry_button_responsive.js
@@ -3,16 +3,18 @@
 
 const TEST_URI = "data:text/html;charset=utf-8," +
   "<p>browser_telemetry_button_responsive.js</p>";
 
 // Because we need to gather stats for the period of time that a tool has been
 // opened we make use of setTimeout() to create tool active times.
 const TOOL_DELAY = 200;
 
+const { ResponsiveUIManager } = Cu.import("resource://devtools/client/responsivedesign/responsivedesign.jsm", {});
+
 add_task(function*() {
   yield addTab(TEST_URI);
   let Telemetry = loadTelemetryAndRecordLogs();
 
   let target = TargetFactory.forTab(gBrowser.selectedTab);
   let toolbox = yield gDevTools.showToolbox(target, "inspector");
   info("inspector opened");
 
@@ -33,23 +35,22 @@ function* testButton(toolbox, Telemetry)
   yield delayedClicks(button, 4);
 
   checkResults("_RESPONSIVE_", Telemetry);
 }
 
 function waitForToggle() {
   return new Promise(resolve => {
     let handler = () => {
-      manager.off("on", handler);
-      manager.off("off", handler);
+      ResponsiveUIManager.off("on", handler);
+      ResponsiveUIManager.off("off", handler);
       resolve();
     };
-    let manager = ResponsiveUI.ResponsiveUIManager;
-    manager.on("on", handler);
-    manager.on("off", handler);
+    ResponsiveUIManager.on("on", handler);
+    ResponsiveUIManager.on("off", handler);
   });
 }
 
 var delayedClicks = Task.async(function*(node, clicks) {
   for (let i = 0; i < clicks; i++) {
     info("Clicking button " + node.id);
     let toggled = waitForToggle();
     node.click();
--- a/devtools/client/webconsole/test/browser_console_private_browsing.js
+++ b/devtools/client/webconsole/test/browser_console_private_browsing.js
@@ -122,17 +122,17 @@ function test() {
       messages: expectedMessages,
     }).then(testBrowserConsole);
   }
 
   function testBrowserConsole() {
     info("testBrowserConsole()");
     closeConsole(privateTab).then(() => {
       info("web console closed");
-      privateWindow.HUDService.toggleBrowserConsole().then(onBrowserConsoleOpen);
+      HUDService.toggleBrowserConsole().then(onBrowserConsoleOpen);
     });
   }
 
   // Make sure that the cached messages from private tabs are not displayed in
   // the browser console.
   function checkNoPrivateMessages() {
     let text = hud.outputNode.textContent;
     is(text.indexOf("fooBazBaz"), -1, "no exception displayed");
@@ -158,17 +158,17 @@ function test() {
   function testPrivateWindowClose() {
     info("close the private window and check if the private messages are removed");
     hud.jsterm.once("private-messages-cleared", () => {
       isnot(hud.outputNode.textContent.indexOf("bug874061-not-private"), -1,
             "non-private messages are still shown after private window closed");
       checkNoPrivateMessages();
 
       info("close the browser console");
-      privateWindow.HUDService.toggleBrowserConsole().then(() => {
+      HUDService.toggleBrowserConsole().then(() => {
         info("reopen the browser console");
         executeSoon(() =>
           HUDService.toggleBrowserConsole().then(onBrowserConsoleReopen));
       });
     });
     privateWindow.BrowserTryToCloseWindow();
   }
 
--- a/devtools/client/webconsole/test/head.js
+++ b/devtools/client/webconsole/test/head.js
@@ -7,16 +7,17 @@
 
 // shared-head.js handles imports, constants, and utility functions
 Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/client/framework/test/shared-head.js", this);
 
 var {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
 var {Utils: WebConsoleUtils} = require("devtools/shared/webconsole/utils");
 var {Messages} = require("devtools/client/webconsole/console-output");
 const asyncStorage = require("devtools/shared/async-storage");
+const HUDService = require("devtools/client/webconsole/hudservice");
 
 // Services.prefs.setBoolPref("devtools.debugger.log", true);
 
 var gPendingOutputTest = 0;
 
 // The various categories of messages.
 const CATEGORY_NETWORK = 0;
 const CATEGORY_CSS = 1;
--- a/devtools/shared/gcli/commands/jsb.js
+++ b/devtools/shared/gcli/commands/jsb.js
@@ -4,16 +4,17 @@
 
 "use strict";
 
 const { Cc, Ci, Cu } = require("chrome");
 const l10n = require("gcli/l10n");
 const XMLHttpRequest = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"];
 
 loader.lazyImporter(this, "Preferences", "resource://gre/modules/Preferences.jsm");
+loader.lazyImporter(this, "ScratchpadManager", "resource://devtools/client/scratchpad/scratchpad-manager.jsm");
 
 loader.lazyRequireGetter(this, "beautify", "devtools/shared/jsbeautify/beautify");
 
 exports.items = [
   {
     item: "command",
     runAt: "client",
     name: "jsb",
@@ -111,22 +112,19 @@ exports.items = [
         return l10n.lookup("jsbInvalidURL");
       }
 
       let deferred = context.defer();
 
       xhr.onreadystatechange = function() {
         if (xhr.readyState == 4) {
           if (xhr.status == 200 || xhr.status == 0) {
-            let browserDoc = context.environment.chromeDocument;
-            let browserWindow = browserDoc.defaultView;
-            let gBrowser = browserWindow.gBrowser;
             let result = beautify.js(xhr.responseText, opts);
 
-            browserWindow.Scratchpad.ScratchpadManager.openScratchpad({text: result});
+            ScratchpadManager.openScratchpad({text: result});
 
             deferred.resolve();
           } else {
             deferred.reject("Unable to load page to beautify: " + args.url + " " +
                             xhr.status + " " + xhr.statusText);
           }
         };
       }