2012-02-07 21:22:30 +04:00
|
|
|
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2012-02-07 21:22:30 +04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2012-04-12 19:47:56 +04:00
|
|
|
const DBG_XUL = "chrome://browser/content/debugger.xul";
|
2012-05-03 21:36:40 +04:00
|
|
|
const DBG_STRINGS_URI = "chrome://browser/locale/devtools/debugger.properties";
|
2012-10-01 16:15:10 +04:00
|
|
|
const CHROME_DEBUGGER_PROFILE_NAME = "_chrome-debugger-profile";
|
2012-05-31 14:01:13 +04:00
|
|
|
const TAB_SWITCH_NOTIFICATION = "debugger-tab-switch";
|
2012-04-12 19:47:56 +04:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2012-02-07 21:22:30 +04:00
|
|
|
|
2012-10-26 21:10:17 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this,
|
|
|
|
"DebuggerServer", "resource://gre/modules/devtools/dbg-server.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this,
|
|
|
|
"Services", "resource:///modules/Services.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this,
|
|
|
|
"FileUtils", "resource:///modules/FileUtils.jsm");
|
|
|
|
|
2012-02-07 21:22:30 +04:00
|
|
|
let EXPORTED_SYMBOLS = ["DebuggerUI"];
|
|
|
|
|
|
|
|
/**
|
2012-06-20 16:21:46 +04:00
|
|
|
* Provides a simple mechanism of managing debugger instances.
|
2012-04-09 09:15:47 +04:00
|
|
|
*
|
|
|
|
* @param nsIDOMWindow aWindow
|
|
|
|
* The chrome window for which the DebuggerUI instance is created.
|
2012-02-07 21:22:30 +04:00
|
|
|
*/
|
2012-04-09 09:15:47 +04:00
|
|
|
function DebuggerUI(aWindow) {
|
|
|
|
this.chromeWindow = aWindow;
|
2012-06-19 20:56:31 +04:00
|
|
|
this.listenToTabs();
|
2012-02-07 21:22:30 +04:00
|
|
|
}
|
|
|
|
|
2012-04-09 09:15:47 +04:00
|
|
|
DebuggerUI.prototype = {
|
2012-06-19 20:56:31 +04:00
|
|
|
/**
|
|
|
|
* Update the status of tool's menuitems and buttons when
|
2012-10-26 21:10:17 +04:00
|
|
|
* the user switches tabs.
|
2012-06-19 20:56:31 +04:00
|
|
|
*/
|
|
|
|
listenToTabs: function DUI_listenToTabs() {
|
|
|
|
let win = this.chromeWindow;
|
|
|
|
let tabs = win.gBrowser.tabContainer;
|
|
|
|
|
|
|
|
let bound_refreshCommand = this.refreshCommand.bind(this);
|
|
|
|
tabs.addEventListener("TabSelect", bound_refreshCommand, true);
|
|
|
|
|
|
|
|
win.addEventListener("unload", function onClose(aEvent) {
|
|
|
|
win.removeEventListener("unload", onClose, false);
|
2012-09-12 14:39:51 +04:00
|
|
|
tabs.removeEventListener("TabSelect", bound_refreshCommand, true);
|
2012-06-19 20:56:31 +04:00
|
|
|
}, false);
|
|
|
|
},
|
2012-05-31 14:01:13 +04:00
|
|
|
|
2012-05-10 21:33:54 +04:00
|
|
|
/**
|
|
|
|
* Called by the DebuggerPane to update the Debugger toggle switches with the
|
|
|
|
* debugger state.
|
|
|
|
*/
|
|
|
|
refreshCommand: function DUI_refreshCommand() {
|
2012-06-19 20:56:31 +04:00
|
|
|
let scriptDebugger = this.getDebugger();
|
2012-05-10 21:33:54 +04:00
|
|
|
let command = this.chromeWindow.document.getElementById("Tools:Debugger");
|
2012-06-19 20:56:31 +04:00
|
|
|
let selectedTab = this.chromeWindow.gBrowser.selectedTab;
|
2012-05-10 21:33:54 +04:00
|
|
|
|
2012-06-19 20:56:31 +04:00
|
|
|
if (scriptDebugger && scriptDebugger.ownerTab === selectedTab) {
|
2012-05-10 21:33:54 +04:00
|
|
|
command.setAttribute("checked", "true");
|
|
|
|
} else {
|
2012-06-19 20:56:31 +04:00
|
|
|
command.setAttribute("checked", "false");
|
2012-05-10 21:33:54 +04:00
|
|
|
}
|
|
|
|
},
|
2012-02-07 21:22:30 +04:00
|
|
|
|
|
|
|
/**
|
2012-04-09 09:15:47 +04:00
|
|
|
* Starts a debugger for the current tab, or stops it if already started.
|
2012-10-26 21:10:17 +04:00
|
|
|
*
|
|
|
|
* @return DebuggerPane | null
|
|
|
|
* The script debugger instance if it's started, null if stopped.
|
2012-02-07 21:22:30 +04:00
|
|
|
*/
|
2012-04-09 09:15:47 +04:00
|
|
|
toggleDebugger: function DUI_toggleDebugger() {
|
2012-06-20 16:21:46 +04:00
|
|
|
let scriptDebugger = this.findDebugger();
|
2012-05-31 14:01:13 +04:00
|
|
|
let selectedTab = this.chromeWindow.gBrowser.selectedTab;
|
|
|
|
|
|
|
|
if (scriptDebugger) {
|
|
|
|
if (scriptDebugger.ownerTab !== selectedTab) {
|
|
|
|
this.showTabSwitchNotification();
|
|
|
|
return scriptDebugger;
|
|
|
|
}
|
|
|
|
scriptDebugger.close();
|
2012-04-09 09:15:47 +04:00
|
|
|
return null;
|
2012-03-05 21:56:13 +04:00
|
|
|
}
|
2012-05-31 14:01:13 +04:00
|
|
|
return new DebuggerPane(this, selectedTab);
|
2012-04-12 19:47:56 +04:00
|
|
|
},
|
|
|
|
|
2012-04-12 19:47:56 +04:00
|
|
|
/**
|
2012-05-03 21:36:40 +04:00
|
|
|
* Starts a remote debugger in a new window, or stops it if already started.
|
2012-10-26 21:10:17 +04:00
|
|
|
*
|
|
|
|
* @return RemoteDebuggerWindow | null
|
|
|
|
* The remote debugger instance if it's started, null if stopped.
|
2012-04-12 19:47:56 +04:00
|
|
|
*/
|
2012-05-03 21:36:40 +04:00
|
|
|
toggleRemoteDebugger: function DUI_toggleRemoteDebugger() {
|
2012-05-31 14:01:13 +04:00
|
|
|
let remoteDebugger = this.getRemoteDebugger();
|
2012-04-12 19:47:56 +04:00
|
|
|
|
2012-05-31 14:01:13 +04:00
|
|
|
if (remoteDebugger) {
|
|
|
|
remoteDebugger.close();
|
2012-04-12 19:47:56 +04:00
|
|
|
return null;
|
|
|
|
}
|
2012-05-03 21:36:40 +04:00
|
|
|
return new RemoteDebuggerWindow(this);
|
2012-04-12 19:47:56 +04:00
|
|
|
},
|
|
|
|
|
2012-04-26 22:28:11 +04:00
|
|
|
/**
|
|
|
|
* Starts a chrome debugger in a new process, or stops it if already started.
|
2012-10-26 21:10:17 +04:00
|
|
|
*
|
|
|
|
* @return ChromeDebuggerProcess | null
|
|
|
|
* The chrome debugger instance if it's started, null if stopped.
|
2012-04-26 22:28:11 +04:00
|
|
|
*/
|
|
|
|
toggleChromeDebugger: function DUI_toggleChromeDebugger(aOnClose, aOnRun) {
|
2012-05-31 14:01:13 +04:00
|
|
|
let chromeDebugger = this.getChromeDebugger();
|
2012-04-26 22:28:11 +04:00
|
|
|
|
2012-05-31 14:01:13 +04:00
|
|
|
if (chromeDebugger) {
|
|
|
|
chromeDebugger.close();
|
2012-04-26 22:28:11 +04:00
|
|
|
return null;
|
|
|
|
}
|
2012-06-20 16:21:46 +04:00
|
|
|
return new ChromeDebuggerProcess(this, aOnClose, aOnRun);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-10-26 21:10:17 +04:00
|
|
|
* Gets the current script debugger from any open window.
|
2012-06-20 16:21:46 +04:00
|
|
|
*
|
|
|
|
* @return DebuggerPane | null
|
|
|
|
* The script debugger instance if it exists, null otherwise.
|
|
|
|
*/
|
|
|
|
findDebugger: function DUI_findDebugger() {
|
|
|
|
let enumerator = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
while (enumerator.hasMoreElements()) {
|
|
|
|
let chromeWindow = enumerator.getNext().QueryInterface(Ci.nsIDOMWindow);
|
|
|
|
let scriptDebugger = chromeWindow.DebuggerUI.getDebugger();
|
|
|
|
if (scriptDebugger) {
|
|
|
|
return scriptDebugger;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2012-04-26 22:28:11 +04:00
|
|
|
},
|
|
|
|
|
2012-03-05 21:56:13 +04:00
|
|
|
/**
|
2012-05-31 14:01:13 +04:00
|
|
|
* Get the current script debugger.
|
2012-06-20 16:21:46 +04:00
|
|
|
*
|
|
|
|
* @return DebuggerPane | null
|
|
|
|
* The script debugger instance if it exists, null otherwise.
|
2012-03-05 21:56:13 +04:00
|
|
|
*/
|
2012-05-31 14:01:13 +04:00
|
|
|
getDebugger: function DUI_getDebugger() {
|
2012-06-20 16:21:46 +04:00
|
|
|
return '_scriptDebugger' in this ? this._scriptDebugger : null;
|
2012-03-05 21:56:13 +04:00
|
|
|
},
|
|
|
|
|
2012-05-03 21:36:40 +04:00
|
|
|
/**
|
|
|
|
* Get the remote debugger for the current chrome window.
|
2012-06-20 16:21:46 +04:00
|
|
|
*
|
|
|
|
* @return RemoteDebuggerWindow | null
|
|
|
|
* The remote debugger instance if it exists, null otherwise.
|
2012-05-03 21:36:40 +04:00
|
|
|
*/
|
|
|
|
getRemoteDebugger: function DUI_getRemoteDebugger() {
|
2012-06-20 16:21:46 +04:00
|
|
|
return '_remoteDebugger' in this ? this._remoteDebugger : null;
|
2012-05-03 21:36:40 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the chrome debugger for the current firefox instance.
|
2012-06-20 16:21:46 +04:00
|
|
|
*
|
|
|
|
* @return ChromeDebuggerProcess | null
|
|
|
|
* The chrome debugger instance if it exists, null otherwise.
|
2012-05-03 21:36:40 +04:00
|
|
|
*/
|
|
|
|
getChromeDebugger: function DUI_getChromeDebugger() {
|
2012-06-20 16:21:46 +04:00
|
|
|
return '_chromeDebugger' in this ? this._chromeDebugger : null;
|
2012-05-03 21:36:40 +04:00
|
|
|
},
|
|
|
|
|
2012-03-05 21:56:13 +04:00
|
|
|
/**
|
2012-04-09 09:15:47 +04:00
|
|
|
* Get the preferences associated with the debugger frontend.
|
|
|
|
* @return object
|
2012-03-05 21:56:13 +04:00
|
|
|
*/
|
2012-10-26 21:10:17 +04:00
|
|
|
get preferences() Prefs,
|
2012-05-31 14:01:13 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Currently, there can only be one debugger per tab.
|
|
|
|
* Show an asynchronous notification which asks the user to switch the
|
|
|
|
* script debugger to the current tab if it's already open in another one.
|
|
|
|
*/
|
2012-10-26 21:10:17 +04:00
|
|
|
showTabSwitchNotification: function DUI_showTabSwitchNotification() {
|
2012-05-31 14:01:13 +04:00
|
|
|
let gBrowser = this.chromeWindow.gBrowser;
|
|
|
|
let selectedBrowser = gBrowser.selectedBrowser;
|
|
|
|
|
|
|
|
let nbox = gBrowser.getNotificationBox(selectedBrowser);
|
|
|
|
let notification = nbox.getNotificationWithValue(TAB_SWITCH_NOTIFICATION);
|
|
|
|
if (notification) {
|
|
|
|
nbox.removeNotification(notification);
|
|
|
|
return;
|
|
|
|
}
|
2012-10-26 21:10:17 +04:00
|
|
|
let self = this;
|
2012-05-31 14:01:13 +04:00
|
|
|
|
|
|
|
let buttons = [{
|
|
|
|
id: "debugger.confirmTabSwitch.buttonSwitch",
|
|
|
|
label: L10N.getStr("confirmTabSwitch.buttonSwitch"),
|
|
|
|
accessKey: L10N.getStr("confirmTabSwitch.buttonSwitch.accessKey"),
|
|
|
|
callback: function DUI_notificationButtonSwitch() {
|
2012-10-26 21:10:17 +04:00
|
|
|
let scriptDebugger = self.findDebugger();
|
2012-06-20 16:21:46 +04:00
|
|
|
let targetWindow = scriptDebugger.globalUI.chromeWindow;
|
|
|
|
targetWindow.gBrowser.selectedTab = scriptDebugger.ownerTab;
|
|
|
|
targetWindow.focus();
|
2012-10-26 21:10:17 +04:00
|
|
|
}
|
2012-05-31 14:01:13 +04:00
|
|
|
}, {
|
|
|
|
id: "debugger.confirmTabSwitch.buttonOpen",
|
|
|
|
label: L10N.getStr("confirmTabSwitch.buttonOpen"),
|
|
|
|
accessKey: L10N.getStr("confirmTabSwitch.buttonOpen.accessKey"),
|
|
|
|
callback: function DUI_notificationButtonOpen() {
|
2012-10-26 21:10:17 +04:00
|
|
|
let scriptDebugger = self.findDebugger();
|
2012-09-22 19:44:00 +04:00
|
|
|
let targetWindow = scriptDebugger.globalUI.chromeWindow;
|
|
|
|
scriptDebugger.close();
|
2012-10-26 21:10:17 +04:00
|
|
|
|
|
|
|
targetWindow.addEventListener("Debugger:Shutdown", function onShutdown() {
|
|
|
|
targetWindow.removeEventListener("Debugger:Shutdown", onShutdown, false);
|
2012-09-22 19:44:00 +04:00
|
|
|
Services.tm.currentThread.dispatch({ run: function() {
|
|
|
|
self.toggleDebugger();
|
|
|
|
}}, 0);
|
|
|
|
}, false);
|
2012-10-26 21:10:17 +04:00
|
|
|
}
|
2012-05-31 14:01:13 +04:00
|
|
|
}];
|
|
|
|
|
|
|
|
let message = L10N.getStr("confirmTabSwitch.message");
|
|
|
|
let imageURL = "chrome://browser/skin/Info.png";
|
|
|
|
|
|
|
|
notification = nbox.appendNotification(
|
|
|
|
message, TAB_SWITCH_NOTIFICATION,
|
|
|
|
imageURL, nbox.PRIORITY_WARNING_HIGH, buttons, null);
|
|
|
|
|
|
|
|
// Make sure this is not a transient notification, to avoid the automatic
|
|
|
|
// transient notification removal.
|
|
|
|
notification.persistence = -1;
|
2012-04-09 09:15:47 +04:00
|
|
|
}
|
|
|
|
};
|
2012-03-05 21:56:13 +04:00
|
|
|
|
2012-04-09 09:15:47 +04:00
|
|
|
/**
|
|
|
|
* Creates a pane that will host the debugger.
|
|
|
|
*
|
2012-05-03 21:36:40 +04:00
|
|
|
* @param DebuggerUI aDebuggerUI
|
|
|
|
* The parent instance creating the new debugger.
|
2012-04-09 09:15:47 +04:00
|
|
|
* @param XULElement aTab
|
|
|
|
* The tab in which to create the debugger.
|
|
|
|
*/
|
2012-05-10 21:33:54 +04:00
|
|
|
function DebuggerPane(aDebuggerUI, aTab) {
|
2012-06-20 16:21:46 +04:00
|
|
|
this.globalUI = aDebuggerUI;
|
2012-05-31 14:01:13 +04:00
|
|
|
this._win = aDebuggerUI.chromeWindow;
|
2012-04-09 09:15:47 +04:00
|
|
|
this._tab = aTab;
|
2012-05-03 21:36:40 +04:00
|
|
|
|
2012-10-26 21:10:17 +04:00
|
|
|
this.close = this.close.bind(this);
|
2012-04-12 19:47:56 +04:00
|
|
|
this._initServer();
|
2012-04-09 09:15:47 +04:00
|
|
|
this._create();
|
|
|
|
}
|
2012-03-05 21:56:13 +04:00
|
|
|
|
2012-04-09 09:15:47 +04:00
|
|
|
DebuggerPane.prototype = {
|
2012-04-12 19:47:56 +04:00
|
|
|
/**
|
|
|
|
* Initializes the debugger server.
|
|
|
|
*/
|
|
|
|
_initServer: function DP__initServer() {
|
|
|
|
if (!DebuggerServer.initialized) {
|
2012-06-01 19:25:08 +04:00
|
|
|
// Always allow connections from nsIPipe transports.
|
2012-09-14 01:00:18 +04:00
|
|
|
DebuggerServer.init(function() true);
|
2012-04-12 19:47:56 +04:00
|
|
|
DebuggerServer.addBrowserActors();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-05 21:56:13 +04:00
|
|
|
/**
|
2012-04-09 09:15:47 +04:00
|
|
|
* Creates and initializes the widgets containing the debugger UI.
|
2012-03-05 21:56:13 +04:00
|
|
|
*/
|
2012-04-09 09:15:47 +04:00
|
|
|
_create: function DP__create() {
|
2012-06-20 16:21:46 +04:00
|
|
|
this.globalUI._scriptDebugger = this;
|
2012-03-05 21:56:13 +04:00
|
|
|
|
2012-05-31 14:01:13 +04:00
|
|
|
let gBrowser = this._win.gBrowser;
|
2012-04-09 09:15:47 +04:00
|
|
|
let ownerDocument = gBrowser.parentNode.ownerDocument;
|
2012-03-05 21:56:13 +04:00
|
|
|
|
2012-04-09 09:15:47 +04:00
|
|
|
this._splitter = ownerDocument.createElement("splitter");
|
2012-05-09 17:50:33 +04:00
|
|
|
this._splitter.setAttribute("class", "devtools-horizontal-splitter");
|
2012-03-05 21:56:13 +04:00
|
|
|
|
2012-04-09 09:15:47 +04:00
|
|
|
this._frame = ownerDocument.createElement("iframe");
|
2012-10-26 21:10:17 +04:00
|
|
|
this._frame.height = Prefs.height;
|
2012-03-05 21:56:13 +04:00
|
|
|
|
2012-04-09 09:15:47 +04:00
|
|
|
this._nbox = gBrowser.getNotificationBox(this._tab.linkedBrowser);
|
|
|
|
this._nbox.appendChild(this._splitter);
|
|
|
|
this._nbox.appendChild(this._frame);
|
2012-03-05 21:56:13 +04:00
|
|
|
|
2012-04-09 09:15:47 +04:00
|
|
|
let self = this;
|
2012-03-05 21:56:13 +04:00
|
|
|
|
2012-04-09 09:15:47 +04:00
|
|
|
this._frame.addEventListener("Debugger:Loaded", function dbgLoaded() {
|
|
|
|
self._frame.removeEventListener("Debugger:Loaded", dbgLoaded, true);
|
2012-10-26 21:10:17 +04:00
|
|
|
self._frame.addEventListener("Debugger:Unloaded", self.close, true);
|
2012-03-05 21:56:13 +04:00
|
|
|
|
2012-04-09 09:15:47 +04:00
|
|
|
// Bind shortcuts for accessing the breakpoint methods in the debugger.
|
2012-05-03 21:36:40 +04:00
|
|
|
let bkp = self.contentWindow.DebuggerController.Breakpoints;
|
2012-04-09 09:15:47 +04:00
|
|
|
self.addBreakpoint = bkp.addBreakpoint;
|
|
|
|
self.removeBreakpoint = bkp.removeBreakpoint;
|
|
|
|
self.getBreakpoint = bkp.getBreakpoint;
|
2012-10-26 21:10:17 +04:00
|
|
|
self.breakpoints = bkp.store;
|
2012-04-09 09:15:47 +04:00
|
|
|
}, true);
|
2012-03-05 21:56:13 +04:00
|
|
|
|
2012-04-12 19:47:56 +04:00
|
|
|
this._frame.setAttribute("src", DBG_XUL);
|
2012-06-20 16:21:46 +04:00
|
|
|
this.globalUI.refreshCommand();
|
2012-03-05 21:56:13 +04:00
|
|
|
},
|
|
|
|
|
2012-02-07 21:22:30 +04:00
|
|
|
/**
|
2012-04-09 09:15:47 +04:00
|
|
|
* Closes the debugger, removing child nodes and event listeners.
|
2012-06-02 19:43:19 +04:00
|
|
|
*
|
|
|
|
* @param function aCloseCallback
|
|
|
|
* Clients can pass a close callback to be notified when
|
|
|
|
* the panel successfully closes.
|
2012-02-07 21:22:30 +04:00
|
|
|
*/
|
2012-06-02 19:43:19 +04:00
|
|
|
close: function DP_close(aCloseCallback) {
|
2012-06-20 16:21:46 +04:00
|
|
|
if (!this.globalUI) {
|
2012-04-09 09:15:47 +04:00
|
|
|
return;
|
2012-03-05 21:56:13 +04:00
|
|
|
}
|
2012-06-20 16:21:46 +04:00
|
|
|
delete this.globalUI._scriptDebugger;
|
2012-02-07 21:22:30 +04:00
|
|
|
|
2012-06-02 19:43:19 +04:00
|
|
|
// This method is also used as an event handler, so only
|
|
|
|
// use aCloseCallback if it's a function.
|
2012-10-26 21:10:17 +04:00
|
|
|
if (typeof aCloseCallback == "function") {
|
2012-06-02 19:43:19 +04:00
|
|
|
let frame = this._frame;
|
|
|
|
frame.addEventListener("unload", function onUnload() {
|
|
|
|
frame.removeEventListener("unload", onUnload, true);
|
|
|
|
aCloseCallback();
|
|
|
|
}, true)
|
|
|
|
}
|
|
|
|
|
2012-10-26 21:10:17 +04:00
|
|
|
Prefs.height = this._frame.height;
|
|
|
|
this._frame.removeEventListener("Debugger:Unloaded", this.close, true);
|
|
|
|
|
2012-04-09 09:15:47 +04:00
|
|
|
this._nbox.removeChild(this._splitter);
|
|
|
|
this._nbox.removeChild(this._frame);
|
2012-02-07 21:22:30 +04:00
|
|
|
|
|
|
|
this._splitter = null;
|
2012-04-09 09:15:47 +04:00
|
|
|
this._frame = null;
|
|
|
|
this._nbox = null;
|
2012-10-26 21:10:17 +04:00
|
|
|
this._win = null;
|
|
|
|
this._tab = null;
|
|
|
|
|
|
|
|
// Remove shortcuts for accessing the breakpoint methods in the debugger.
|
|
|
|
delete this.addBreakpoint;
|
|
|
|
delete this.removeBreakpoint;
|
|
|
|
delete this.getBreakpoint;
|
|
|
|
delete this.breakpoints;
|
2012-05-10 21:33:54 +04:00
|
|
|
|
2012-06-20 16:21:46 +04:00
|
|
|
this.globalUI.refreshCommand();
|
|
|
|
this.globalUI = null;
|
2012-02-07 21:22:30 +04:00
|
|
|
},
|
|
|
|
|
2012-10-26 21:10:17 +04:00
|
|
|
/**
|
|
|
|
* Gets the chrome window owning this debugger instance.
|
|
|
|
* @return XULWindow
|
|
|
|
*/
|
|
|
|
get ownerWindow() {
|
|
|
|
return this._win;
|
|
|
|
},
|
|
|
|
|
2012-05-31 14:01:13 +04:00
|
|
|
/**
|
|
|
|
* Gets the tab owning this debugger instance.
|
|
|
|
* @return XULElement
|
|
|
|
*/
|
|
|
|
get ownerTab() {
|
|
|
|
return this._tab;
|
|
|
|
},
|
|
|
|
|
2012-02-07 21:22:30 +04:00
|
|
|
/**
|
2012-04-09 09:15:47 +04:00
|
|
|
* Gets the debugger content window.
|
2012-10-26 21:10:17 +04:00
|
|
|
* @return nsIDOMWindow
|
2012-02-07 21:22:30 +04:00
|
|
|
*/
|
2012-05-03 21:36:40 +04:00
|
|
|
get contentWindow() {
|
2012-04-09 09:15:47 +04:00
|
|
|
return this._frame ? this._frame.contentWindow : null;
|
2012-05-03 21:36:40 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a window that will host a remote debugger.
|
|
|
|
*
|
|
|
|
* @param DebuggerUI aDebuggerUI
|
|
|
|
* The parent instance creating the new debugger.
|
|
|
|
*/
|
|
|
|
function RemoteDebuggerWindow(aDebuggerUI) {
|
2012-06-20 16:21:46 +04:00
|
|
|
this.globalUI = aDebuggerUI;
|
2012-05-03 21:36:40 +04:00
|
|
|
this._win = aDebuggerUI.chromeWindow;
|
|
|
|
|
2012-10-26 21:10:17 +04:00
|
|
|
this.close = this.close.bind(this);
|
2012-05-03 21:36:40 +04:00
|
|
|
this._create();
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoteDebuggerWindow.prototype = {
|
|
|
|
/**
|
|
|
|
* Creates and initializes the widgets containing the remote debugger UI.
|
|
|
|
*/
|
|
|
|
_create: function DP__create() {
|
2012-06-20 16:21:46 +04:00
|
|
|
this.globalUI._remoteDebugger = this;
|
2012-05-03 21:36:40 +04:00
|
|
|
|
2012-06-20 16:21:46 +04:00
|
|
|
this._dbgwin = this.globalUI.chromeWindow.open(DBG_XUL,
|
2012-05-03 21:36:40 +04:00
|
|
|
L10N.getStr("remoteDebuggerWindowTitle"),
|
2012-10-26 21:10:17 +04:00
|
|
|
"width=" + Prefs.remoteWinWidth + "," +
|
|
|
|
"height=" + Prefs.remoteWinHeight + "," +
|
2012-05-03 21:36:40 +04:00
|
|
|
"chrome,dependent,resizable,centerscreen");
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
|
|
|
|
this._dbgwin.addEventListener("Debugger:Loaded", function dbgLoaded() {
|
|
|
|
self._dbgwin.removeEventListener("Debugger:Loaded", dbgLoaded, true);
|
2012-10-26 21:10:17 +04:00
|
|
|
self._dbgwin.addEventListener("Debugger:Unloaded", self.close, true);
|
2012-05-03 21:36:40 +04:00
|
|
|
|
|
|
|
// Bind shortcuts for accessing the breakpoint methods in the debugger.
|
|
|
|
let bkp = self.contentWindow.DebuggerController.Breakpoints;
|
|
|
|
self.addBreakpoint = bkp.addBreakpoint;
|
|
|
|
self.removeBreakpoint = bkp.removeBreakpoint;
|
|
|
|
self.getBreakpoint = bkp.getBreakpoint;
|
2012-10-26 21:10:17 +04:00
|
|
|
self.breakpoints = bkp.store;
|
2012-05-03 21:36:40 +04:00
|
|
|
}, true);
|
2012-10-26 21:10:17 +04:00
|
|
|
|
|
|
|
this._dbgwin._remoteFlag = true;
|
2012-05-03 21:36:40 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the remote debugger, along with the parent window if necessary.
|
|
|
|
*/
|
|
|
|
close: function DP_close() {
|
2012-06-20 16:21:46 +04:00
|
|
|
if (!this.globalUI) {
|
2012-05-03 21:36:40 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-06-20 16:21:46 +04:00
|
|
|
delete this.globalUI._remoteDebugger;
|
2012-05-03 21:36:40 +04:00
|
|
|
|
|
|
|
this._dbgwin.close();
|
|
|
|
this._dbgwin = null;
|
2012-10-26 21:10:17 +04:00
|
|
|
this._win = null;
|
|
|
|
|
|
|
|
// Remove shortcuts for accessing the breakpoint methods in the debugger.
|
|
|
|
delete this.addBreakpoint;
|
|
|
|
delete this.removeBreakpoint;
|
|
|
|
delete this.getBreakpoint;
|
|
|
|
delete this.breakpoints;
|
|
|
|
|
|
|
|
this.globalUI = null;
|
2012-05-03 21:36:40 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-10-26 21:10:17 +04:00
|
|
|
* Gets the chrome window owning this debugger instance.
|
|
|
|
* @return XULWindow
|
2012-05-03 21:36:40 +04:00
|
|
|
*/
|
2012-10-26 21:10:17 +04:00
|
|
|
get ownerWindow() {
|
|
|
|
return this._win;
|
2012-05-03 21:36:40 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-10-26 21:10:17 +04:00
|
|
|
* Gets the remote debugger content window.
|
|
|
|
* @return nsIDOMWindow.
|
2012-05-03 21:36:40 +04:00
|
|
|
*/
|
2012-10-26 21:10:17 +04:00
|
|
|
get contentWindow() {
|
|
|
|
return this._dbgwin;
|
2012-02-07 21:22:30 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-05-03 21:36:40 +04:00
|
|
|
* Creates a process that will hold a chrome debugger.
|
2012-04-12 19:47:56 +04:00
|
|
|
*
|
2012-06-20 16:21:46 +04:00
|
|
|
* @param DebuggerUI aDebuggerUI
|
|
|
|
* The parent instance creating the new debugger.
|
2012-04-12 19:47:56 +04:00
|
|
|
* @param function aOnClose
|
|
|
|
* Optional, a function called when the process exits.
|
|
|
|
* @param function aOnRun
|
|
|
|
* Optional, a function called when the process starts running.
|
2012-02-07 21:22:30 +04:00
|
|
|
*/
|
2012-06-20 16:21:46 +04:00
|
|
|
function ChromeDebuggerProcess(aDebuggerUI, aOnClose, aOnRun) {
|
|
|
|
this.globalUI = aDebuggerUI;
|
|
|
|
this._win = aDebuggerUI.chromeWindow;
|
2012-04-12 19:47:56 +04:00
|
|
|
this._closeCallback = aOnClose;
|
|
|
|
this._runCallback = aOnRun;
|
2012-04-26 22:28:11 +04:00
|
|
|
|
2012-05-03 21:36:40 +04:00
|
|
|
this._initServer();
|
2012-04-12 19:47:56 +04:00
|
|
|
this._initProfile();
|
|
|
|
this._create();
|
|
|
|
}
|
|
|
|
|
2012-05-03 21:36:40 +04:00
|
|
|
ChromeDebuggerProcess.prototype = {
|
2012-04-12 19:47:56 +04:00
|
|
|
/**
|
|
|
|
* Initializes the debugger server.
|
|
|
|
*/
|
|
|
|
_initServer: function RDP__initServer() {
|
|
|
|
if (!DebuggerServer.initialized) {
|
2012-09-20 10:40:01 +04:00
|
|
|
DebuggerServer.init();
|
2012-04-12 19:47:56 +04:00
|
|
|
DebuggerServer.addBrowserActors();
|
|
|
|
}
|
2012-10-26 21:10:17 +04:00
|
|
|
DebuggerServer.openListener(Prefs.remotePort);
|
2012-04-12 19:47:56 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a profile for the remote debugger process.
|
|
|
|
*/
|
|
|
|
_initProfile: function RDP__initProfile() {
|
|
|
|
let profileService = Cc["@mozilla.org/toolkit/profile-service;1"]
|
|
|
|
.createInstance(Ci.nsIToolkitProfileService);
|
|
|
|
|
|
|
|
let dbgProfileName;
|
|
|
|
try {
|
2012-10-01 16:15:10 +04:00
|
|
|
dbgProfileName = profileService.selectedProfile.name + CHROME_DEBUGGER_PROFILE_NAME;
|
2012-04-12 19:47:56 +04:00
|
|
|
} catch(e) {
|
2012-10-01 16:15:10 +04:00
|
|
|
dbgProfileName = CHROME_DEBUGGER_PROFILE_NAME;
|
2012-04-12 19:47:56 +04:00
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._dbgProfile = profileService.createProfile(null, null, dbgProfileName);
|
|
|
|
profileService.flush();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and initializes the profile & process for the remote debugger.
|
|
|
|
*/
|
|
|
|
_create: function RDP__create() {
|
2012-06-20 16:21:46 +04:00
|
|
|
this.globalUI._chromeDebugger = this;
|
2012-04-12 19:47:56 +04:00
|
|
|
|
|
|
|
let file = FileUtils.getFile("CurProcD",
|
|
|
|
[Services.appinfo.OS == "WINNT" ? "firefox.exe"
|
|
|
|
: "firefox-bin"]);
|
|
|
|
|
|
|
|
let process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
|
|
|
|
process.init(file);
|
|
|
|
|
|
|
|
let args = [
|
|
|
|
"-no-remote", "-P", this._dbgProfile.name,
|
|
|
|
"-chrome", DBG_XUL,
|
2012-10-26 21:10:17 +04:00
|
|
|
"-width", Prefs.remoteWinWidth,
|
|
|
|
"-height", Prefs.remoteWinHeight];
|
2012-04-12 19:47:56 +04:00
|
|
|
|
|
|
|
process.runwAsync(args, args.length, { observe: this.close.bind(this) });
|
|
|
|
this._dbgProcess = process;
|
|
|
|
|
2012-10-26 21:10:17 +04:00
|
|
|
if (typeof this._runCallback == "function") {
|
2012-04-12 19:47:56 +04:00
|
|
|
this._runCallback.call({}, this);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the remote debugger, removing the profile and killing the process.
|
|
|
|
*/
|
|
|
|
close: function RDP_close() {
|
2012-06-20 16:21:46 +04:00
|
|
|
if (!this.globalUI) {
|
2012-04-12 19:47:56 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-06-20 16:21:46 +04:00
|
|
|
delete this.globalUI._chromeDebugger;
|
2012-04-12 19:47:56 +04:00
|
|
|
|
|
|
|
if (this._dbgProcess.isRunning) {
|
|
|
|
this._dbgProcess.kill();
|
|
|
|
}
|
|
|
|
if (this._dbgProfile) {
|
|
|
|
this._dbgProfile.remove(false);
|
|
|
|
}
|
2012-10-26 21:10:17 +04:00
|
|
|
if (typeof this._closeCallback == "function") {
|
2012-04-12 19:47:56 +04:00
|
|
|
this._closeCallback.call({}, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._dbgProcess = null;
|
|
|
|
this._dbgProfile = null;
|
2012-10-26 21:10:17 +04:00
|
|
|
this._win = null;
|
|
|
|
|
|
|
|
this.globalUI = null;
|
2012-04-12 19:47:56 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-03 21:36:40 +04:00
|
|
|
/**
|
|
|
|
* Localization convenience methods.
|
|
|
|
*/
|
|
|
|
let L10N = {
|
|
|
|
/**
|
|
|
|
* L10N shortcut function.
|
|
|
|
*
|
|
|
|
* @param string aName
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
getStr: function L10N_getStr(aName) {
|
|
|
|
return this.stringBundle.GetStringFromName(aName);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(L10N, "stringBundle", function() {
|
|
|
|
return Services.strings.createBundle(DBG_STRINGS_URI);
|
|
|
|
});
|
|
|
|
|
2012-04-12 19:47:56 +04:00
|
|
|
/**
|
2012-10-26 21:10:17 +04:00
|
|
|
* Shortcuts for accessing various debugger preferences.
|
2012-04-12 19:47:56 +04:00
|
|
|
*/
|
2012-10-26 21:10:17 +04:00
|
|
|
let Prefs = {
|
2012-02-07 21:22:30 +04:00
|
|
|
/**
|
|
|
|
* Gets the preferred height of the debugger pane.
|
|
|
|
* @return number
|
|
|
|
*/
|
|
|
|
get height() {
|
2012-04-09 09:15:47 +04:00
|
|
|
if (this._height === undefined) {
|
2012-02-07 21:22:30 +04:00
|
|
|
this._height = Services.prefs.getIntPref("devtools.debugger.ui.height");
|
|
|
|
}
|
|
|
|
return this._height;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the preferred height of the debugger pane.
|
|
|
|
* @param number value
|
|
|
|
*/
|
|
|
|
set height(value) {
|
|
|
|
Services.prefs.setIntPref("devtools.debugger.ui.height", value);
|
|
|
|
this._height = value;
|
|
|
|
}
|
|
|
|
};
|
2012-04-12 19:47:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the preferred width of the remote debugger window.
|
|
|
|
* @return number
|
|
|
|
*/
|
2012-10-26 21:10:17 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(Prefs, "remoteWinWidth", function() {
|
2012-04-12 19:47:56 +04:00
|
|
|
return Services.prefs.getIntPref("devtools.debugger.ui.remote-win.width");
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the preferred height of the remote debugger window.
|
|
|
|
* @return number
|
|
|
|
*/
|
2012-10-26 21:10:17 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(Prefs, "remoteWinHeight", function() {
|
2012-04-12 19:47:56 +04:00
|
|
|
return Services.prefs.getIntPref("devtools.debugger.ui.remote-win.height");
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the preferred default remote debugging host.
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-10-26 21:10:17 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(Prefs, "remoteHost", function() {
|
2012-04-12 19:47:56 +04:00
|
|
|
return Services.prefs.getCharPref("devtools.debugger.remote-host");
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the preferred default remote debugging port.
|
|
|
|
* @return number
|
|
|
|
*/
|
2012-10-26 21:10:17 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(Prefs, "remotePort", function() {
|
2012-04-12 19:47:56 +04:00
|
|
|
return Services.prefs.getIntPref("devtools.debugger.remote-port");
|
|
|
|
});
|