2012-10-26 10:10:17 -07: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: */
|
|
|
|
/* 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";
|
|
|
|
|
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Functions handling the sources UI.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-02-20 15:33:36 -08:00
|
|
|
function SourcesView() {
|
|
|
|
dumpn("SourcesView was instantiated");
|
|
|
|
|
2013-09-18 17:56:20 -07:00
|
|
|
this.prettyPrint = this.prettyPrint.bind(this);
|
2012-11-15 22:42:52 -08:00
|
|
|
this._onEditorLoad = this._onEditorLoad.bind(this);
|
|
|
|
this._onEditorUnload = this._onEditorUnload.bind(this);
|
|
|
|
this._onEditorSelection = this._onEditorSelection.bind(this);
|
|
|
|
this._onEditorContextMenu = this._onEditorContextMenu.bind(this);
|
2013-02-20 15:33:36 -08:00
|
|
|
this._onSourceSelect = this._onSourceSelect.bind(this);
|
|
|
|
this._onSourceClick = this._onSourceClick.bind(this);
|
2013-06-21 07:33:56 -07:00
|
|
|
this._onBreakpointRemoved = this._onBreakpointRemoved.bind(this);
|
2013-07-23 10:15:10 -07:00
|
|
|
this._onSourceCheck = this._onSourceCheck.bind(this);
|
2013-07-30 20:36:13 -07:00
|
|
|
this._onStopBlackBoxing = this._onStopBlackBoxing.bind(this);
|
2012-11-15 22:42:52 -08:00
|
|
|
this._onBreakpointClick = this._onBreakpointClick.bind(this);
|
2013-02-20 15:33:36 -08:00
|
|
|
this._onBreakpointCheckboxClick = this._onBreakpointCheckboxClick.bind(this);
|
2012-11-15 22:42:52 -08:00
|
|
|
this._onConditionalPopupShowing = this._onConditionalPopupShowing.bind(this);
|
|
|
|
this._onConditionalPopupShown = this._onConditionalPopupShown.bind(this);
|
|
|
|
this._onConditionalPopupHiding = this._onConditionalPopupHiding.bind(this);
|
2013-02-20 15:33:36 -08:00
|
|
|
this._onConditionalTextboxInput = this._onConditionalTextboxInput.bind(this);
|
2012-11-15 22:42:52 -08:00
|
|
|
this._onConditionalTextboxKeyPress = this._onConditionalTextboxKeyPress.bind(this);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
SourcesView.prototype = Heritage.extend(WidgetMethods, {
|
2012-10-26 10:10:17 -07:00
|
|
|
/**
|
|
|
|
* Initialization function, called when the debugger is started.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
initialize: function() {
|
2013-02-20 15:33:36 -08:00
|
|
|
dumpn("Initializing the SourcesView");
|
|
|
|
|
2013-07-23 10:15:10 -07:00
|
|
|
this.widget = new SideMenuWidget(document.getElementById("sources"), {
|
2013-10-04 00:33:08 -07:00
|
|
|
showItemCheckboxes: true,
|
2013-07-25 11:30:58 -07:00
|
|
|
showArrows: true
|
2013-07-23 10:15:10 -07:00
|
|
|
});
|
2013-09-13 06:23:13 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
this.emptyText = L10N.getStr("noSourcesText");
|
2013-07-23 10:15:10 -07:00
|
|
|
this._blackBoxCheckboxTooltip = L10N.getStr("blackBoxCheckboxTooltip");
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2012-11-15 22:42:52 -08:00
|
|
|
this._commandset = document.getElementById("debuggerCommands");
|
2012-10-26 13:28:54 -07:00
|
|
|
this._popupset = document.getElementById("debuggerPopupset");
|
2012-11-20 02:57:05 -08:00
|
|
|
this._cmPopup = document.getElementById("sourceEditorContextMenu");
|
2012-11-15 22:42:52 -08:00
|
|
|
this._cbPanel = document.getElementById("conditional-breakpoint-panel");
|
2013-02-20 15:33:36 -08:00
|
|
|
this._cbTextbox = document.getElementById("conditional-breakpoint-panel-textbox");
|
2013-07-30 20:36:13 -07:00
|
|
|
this._stopBlackBoxButton = document.getElementById("black-boxed-message-button");
|
2013-09-18 17:56:20 -07:00
|
|
|
this._prettyPrintButton = document.getElementById("pretty-print");
|
2012-11-15 22:42:52 -08:00
|
|
|
|
2013-10-11 13:52:50 -07:00
|
|
|
if (Prefs.prettyPrintEnabled) {
|
|
|
|
this._prettyPrintButton.removeAttribute("hidden");
|
|
|
|
}
|
|
|
|
|
2013-09-13 06:23:14 -07:00
|
|
|
window.on(EVENTS.EDITOR_LOADED, this._onEditorLoad, false);
|
|
|
|
window.on(EVENTS.EDITOR_UNLOADED, this._onEditorUnload, false);
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget.addEventListener("select", this._onSourceSelect, false);
|
|
|
|
this.widget.addEventListener("click", this._onSourceClick, false);
|
2013-07-23 10:15:10 -07:00
|
|
|
this.widget.addEventListener("check", this._onSourceCheck, false);
|
2013-07-30 20:36:13 -07:00
|
|
|
this._stopBlackBoxButton.addEventListener("click", this._onStopBlackBoxing, false);
|
2013-09-18 17:56:20 -07:00
|
|
|
this._prettyPrintButton.addEventListener("click", this.prettyPrint, false);
|
2012-11-21 00:49:45 -08:00
|
|
|
this._cbPanel.addEventListener("popupshowing", this._onConditionalPopupShowing, false);
|
|
|
|
this._cbPanel.addEventListener("popupshown", this._onConditionalPopupShown, false);
|
|
|
|
this._cbPanel.addEventListener("popuphiding", this._onConditionalPopupHiding, false);
|
2013-02-20 15:33:36 -08:00
|
|
|
this._cbTextbox.addEventListener("input", this._onConditionalTextboxInput, false);
|
2012-11-15 22:42:52 -08:00
|
|
|
this._cbTextbox.addEventListener("keypress", this._onConditionalTextboxKeyPress, false);
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-06-05 23:53:08 -07:00
|
|
|
this.autoFocusOnSelection = false;
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
// Show an empty label by default.
|
|
|
|
this.empty();
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destruction function, called when the debugger is closed.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
destroy: function() {
|
2013-02-20 15:33:36 -08:00
|
|
|
dumpn("Destroying the SourcesView");
|
|
|
|
|
2013-09-13 06:23:14 -07:00
|
|
|
window.off(EVENTS.EDITOR_LOADED, this._onEditorLoad, false);
|
|
|
|
window.off(EVENTS.EDITOR_UNLOADED, this._onEditorUnload, false);
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget.removeEventListener("select", this._onSourceSelect, false);
|
|
|
|
this.widget.removeEventListener("click", this._onSourceClick, false);
|
2013-07-23 10:15:10 -07:00
|
|
|
this.widget.removeEventListener("check", this._onSourceCheck, false);
|
2013-07-30 20:36:13 -07:00
|
|
|
this._stopBlackBoxButton.removeEventListener("click", this._onStopBlackBoxing, false);
|
2013-09-18 17:56:20 -07:00
|
|
|
this._prettyPrintButton.removeEventListener("click", this.prettyPrint, false);
|
2012-11-15 22:42:52 -08:00
|
|
|
this._cbPanel.removeEventListener("popupshowing", this._onConditionalPopupShowing, false);
|
2013-02-20 15:33:36 -08:00
|
|
|
this._cbPanel.removeEventListener("popupshowing", this._onConditionalPopupShown, false);
|
2012-11-21 00:49:45 -08:00
|
|
|
this._cbPanel.removeEventListener("popuphiding", this._onConditionalPopupHiding, false);
|
2013-02-20 15:33:36 -08:00
|
|
|
this._cbTextbox.removeEventListener("input", this._onConditionalTextboxInput, false);
|
2012-11-15 22:42:52 -08:00
|
|
|
this._cbTextbox.removeEventListener("keypress", this._onConditionalTextboxKeyPress, false);
|
2013-02-20 15:33:36 -08:00
|
|
|
},
|
2012-11-20 03:38:45 -08:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
|
|
|
* Sets the preferred location to be selected in this sources container.
|
2013-09-13 06:23:13 -07:00
|
|
|
* @param string aUrl
|
2013-02-20 15:33:36 -08:00
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
set preferredSource(aUrl) {
|
|
|
|
this._preferredValue = aUrl;
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
// Selects the element with the specified value in this sources container,
|
|
|
|
// if already inserted.
|
2013-09-13 06:23:13 -07:00
|
|
|
if (this.containsValue(aUrl)) {
|
|
|
|
this.selectedValue = aUrl;
|
2013-02-20 15:33:36 -08:00
|
|
|
}
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Adds a source to this sources container.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-02-20 15:33:36 -08:00
|
|
|
* @param object aSource
|
|
|
|
* The source object coming from the active thread.
|
|
|
|
* @param object aOptions [optional]
|
|
|
|
* Additional options for adding the source. Supported options:
|
2013-09-13 06:23:13 -07:00
|
|
|
* - staged: true to stage the item to be appended later
|
2013-02-20 15:33:36 -08:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
addSource: function(aSource, aOptions = {}) {
|
2013-05-29 01:45:58 -07:00
|
|
|
let url = aSource.url;
|
2013-03-14 21:57:00 -07:00
|
|
|
let label = SourceUtils.getSourceLabel(url.split(" -> ").pop());
|
|
|
|
let group = SourceUtils.getSourceGroup(url.split(" -> ").pop());
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
// Append a source item to this container.
|
2013-06-21 07:33:56 -07:00
|
|
|
this.push([label, url, group], {
|
2013-02-20 15:33:36 -08:00
|
|
|
staged: aOptions.staged, /* stage the item to be appended later? */
|
2012-10-26 10:10:17 -07:00
|
|
|
attachment: {
|
2013-07-23 10:15:10 -07:00
|
|
|
checkboxState: !aSource.isBlackBoxed,
|
|
|
|
checkboxTooltip: this._blackBoxCheckboxTooltip,
|
2013-02-20 15:33:36 -08:00
|
|
|
source: aSource
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
});
|
2013-02-20 15:33:36 -08:00
|
|
|
},
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
|
|
|
* Adds a breakpoint to this sources container.
|
|
|
|
*
|
2013-09-13 06:23:12 -07:00
|
|
|
* @param object aBreakpointData
|
|
|
|
* Information about the breakpoint to be shown.
|
|
|
|
* This object must have the following properties:
|
|
|
|
* - location: the breakpoint's source location and line number
|
2013-09-14 02:34:08 -07:00
|
|
|
* - disabled: the breakpoint's disabled state, boolean
|
2013-09-13 06:23:12 -07:00
|
|
|
* - text: the breakpoint's line text to be displayed
|
|
|
|
* @param object aOptions [optional]
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2013-02-20 15:33:36 -08:00
|
|
|
*/
|
2013-09-13 06:23:12 -07:00
|
|
|
addBreakpoint: function(aBreakpointData, aOptions = {}) {
|
2013-09-14 02:34:08 -07:00
|
|
|
let { location, disabled } = aBreakpointData;
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
// Make sure we're not duplicating anything. If a breakpoint at the
|
2013-09-14 02:34:08 -07:00
|
|
|
// specified source url and line already exists, just toggle it.
|
2013-09-13 06:23:12 -07:00
|
|
|
if (this.getBreakpoint(location)) {
|
2013-09-14 02:34:08 -07:00
|
|
|
this[disabled ? "disableBreakpoint" : "enableBreakpoint"](location);
|
2012-10-26 10:10:17 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
// Get the source item to which the breakpoint should be attached.
|
2013-09-13 06:23:12 -07:00
|
|
|
let sourceItem = this.getItemByValue(location.url);
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
// Create the element node and menu popup for the breakpoint item.
|
2013-09-13 06:23:12 -07:00
|
|
|
let breakpointArgs = Heritage.extend(aBreakpointData, aOptions);
|
|
|
|
let breakpointView = this._createBreakpointView.call(this, breakpointArgs);
|
|
|
|
let contextMenu = this._createContextMenu.call(this, breakpointArgs);
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
// Append a breakpoint child item to the corresponding source item.
|
2013-09-13 06:23:12 -07:00
|
|
|
sourceItem.append(breakpointView.container, {
|
|
|
|
attachment: Heritage.extend(breakpointArgs, {
|
|
|
|
url: location.url,
|
|
|
|
line: location.line,
|
2013-06-21 07:33:56 -07:00
|
|
|
view: breakpointView,
|
|
|
|
popup: contextMenu
|
2013-02-20 15:33:36 -08:00
|
|
|
}),
|
|
|
|
attributes: [
|
|
|
|
["contextmenu", contextMenu.menupopupId]
|
|
|
|
],
|
|
|
|
// Make sure that when the breakpoint item is removed, the corresponding
|
|
|
|
// menupopup and commandset are also destroyed.
|
|
|
|
finalize: this._onBreakpointRemoved
|
|
|
|
});
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Highlight the newly appended breakpoint child item if necessary.
|
|
|
|
if (aOptions.openPopup || !aOptions.noEditorUpdate) {
|
|
|
|
this.highlightBreakpoint(location, aOptions);
|
2012-11-15 22:42:52 -08:00
|
|
|
}
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Removes a breakpoint from this sources container.
|
2013-09-13 06:23:12 -07:00
|
|
|
* It does not also remove the breakpoint from the controller. Be careful.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-09-13 06:23:12 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:12 -07:00
|
|
|
removeBreakpoint: function(aLocation) {
|
2013-02-20 15:33:36 -08:00
|
|
|
// When a parent source item is removed, all the child breakpoint items are
|
|
|
|
// also automagically removed.
|
2013-09-13 06:23:12 -07:00
|
|
|
let sourceItem = this.getItemByValue(aLocation.url);
|
2013-02-20 15:33:36 -08:00
|
|
|
if (!sourceItem) {
|
|
|
|
return;
|
|
|
|
}
|
2013-09-13 06:23:12 -07:00
|
|
|
let breakpointItem = this.getBreakpoint(aLocation);
|
2013-02-20 15:33:36 -08:00
|
|
|
if (!breakpointItem) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Clear the breakpoint view.
|
2013-02-20 15:33:36 -08:00
|
|
|
sourceItem.remove(breakpointItem);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
2013-09-13 06:23:12 -07:00
|
|
|
* Returns the breakpoint at the specified source url and line.
|
2013-02-20 15:33:36 -08:00
|
|
|
*
|
2013-09-13 06:23:12 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2013-06-21 07:33:56 -07:00
|
|
|
* @return object
|
2013-02-20 15:33:36 -08:00
|
|
|
* The corresponding breakpoint item if found, null otherwise.
|
|
|
|
*/
|
2013-09-13 06:23:12 -07:00
|
|
|
getBreakpoint: function(aLocation) {
|
|
|
|
return this.getItemForPredicate(aItem =>
|
|
|
|
aItem.attachment.url == aLocation.url &&
|
|
|
|
aItem.attachment.line == aLocation.line);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all breakpoints which are not at the specified source url and line.
|
|
|
|
*
|
2013-09-14 02:34:07 -07:00
|
|
|
* @param object aLocation [optional]
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2013-09-13 06:23:12 -07:00
|
|
|
* @param array aStore [optional]
|
|
|
|
* A list in which to store the corresponding breakpoints.
|
|
|
|
* @return array
|
|
|
|
* The corresponding breakpoints if found, an empty array otherwise.
|
|
|
|
*/
|
2013-09-14 02:34:07 -07:00
|
|
|
getOtherBreakpoints: function(aLocation = {}, aStore = []) {
|
2013-09-13 06:23:12 -07:00
|
|
|
for (let source in this) {
|
|
|
|
for (let breakpointItem in source) {
|
2013-09-14 02:34:07 -07:00
|
|
|
let { url, line } = breakpointItem.attachment;
|
|
|
|
if (url != aLocation.url || line != aLocation.line) {
|
2013-09-13 06:23:12 -07:00
|
|
|
aStore.push(breakpointItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aStore;
|
2013-02-20 15:33:36 -08:00
|
|
|
},
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
/**
|
|
|
|
* Enables a breakpoint.
|
|
|
|
*
|
2013-09-13 06:23:12 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2012-10-26 10:10:17 -07:00
|
|
|
* @param object aOptions [optional]
|
|
|
|
* Additional options or flags supported by this operation:
|
|
|
|
* - silent: pass true to not update the checkbox checked state;
|
|
|
|
* this is usually necessary when the checked state will
|
|
|
|
* be updated automatically (e.g: on a checkbox click).
|
2013-09-13 06:23:12 -07:00
|
|
|
* @return object
|
|
|
|
* A promise that is resolved after the breakpoint is enabled, or
|
|
|
|
* rejected if no breakpoint was found at the specified location.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:12 -07:00
|
|
|
enableBreakpoint: function(aLocation, aOptions = {}) {
|
|
|
|
let breakpointItem = this.getBreakpoint(aLocation);
|
2013-02-20 15:33:36 -08:00
|
|
|
if (!breakpointItem) {
|
2013-09-13 06:23:12 -07:00
|
|
|
return promise.reject(new Error("No breakpoint found."));
|
2013-02-20 15:33:36 -08:00
|
|
|
}
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Breakpoint will now be enabled.
|
|
|
|
let attachment = breakpointItem.attachment;
|
|
|
|
attachment.disabled = false;
|
|
|
|
|
|
|
|
// Update the corresponding menu items to reflect the enabled state.
|
|
|
|
let prefix = "bp-cMenu-"; // "breakpoints context menu"
|
2013-09-14 02:34:07 -07:00
|
|
|
let identifier = DebuggerController.Breakpoints.getIdentifier(attachment);
|
|
|
|
let enableSelfId = prefix + "enableSelf-" + identifier + "-menuitem";
|
|
|
|
let disableSelfId = prefix + "disableSelf-" + identifier + "-menuitem";
|
2013-09-13 06:23:12 -07:00
|
|
|
document.getElementById(enableSelfId).setAttribute("hidden", "true");
|
|
|
|
document.getElementById(disableSelfId).removeAttribute("hidden");
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
// Update the checkbox state if necessary.
|
|
|
|
if (!aOptions.silent) {
|
2013-09-13 06:23:12 -07:00
|
|
|
attachment.view.checkbox.setAttribute("checked", "true");
|
2013-06-21 07:33:56 -07:00
|
|
|
}
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
return DebuggerController.Breakpoints.addBreakpoint(aLocation, {
|
|
|
|
// No need to update the pane, since this method is invoked because
|
|
|
|
// a breakpoint's view was interacted with.
|
|
|
|
noPaneUpdate: true
|
|
|
|
});
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables a breakpoint.
|
|
|
|
*
|
2013-09-13 06:23:12 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2012-10-26 10:10:17 -07:00
|
|
|
* @param object aOptions [optional]
|
|
|
|
* Additional options or flags supported by this operation:
|
|
|
|
* - silent: pass true to not update the checkbox checked state;
|
|
|
|
* this is usually necessary when the checked state will
|
|
|
|
* be updated automatically (e.g: on a checkbox click).
|
2013-09-13 06:23:12 -07:00
|
|
|
* @return object
|
|
|
|
* A promise that is resolved after the breakpoint is disabled, or
|
|
|
|
* rejected if no breakpoint was found at the specified location.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:12 -07:00
|
|
|
disableBreakpoint: function(aLocation, aOptions = {}) {
|
|
|
|
let breakpointItem = this.getBreakpoint(aLocation);
|
2013-02-20 15:33:36 -08:00
|
|
|
if (!breakpointItem) {
|
2013-09-13 06:23:12 -07:00
|
|
|
return promise.reject(new Error("No breakpoint found."));
|
2013-02-20 15:33:36 -08:00
|
|
|
}
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Breakpoint will now be disabled.
|
|
|
|
let attachment = breakpointItem.attachment;
|
|
|
|
attachment.disabled = true;
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Update the corresponding menu items to reflect the disabled state.
|
|
|
|
let prefix = "bp-cMenu-"; // "breakpoints context menu"
|
2013-09-14 02:34:07 -07:00
|
|
|
let identifier = DebuggerController.Breakpoints.getIdentifier(attachment);
|
|
|
|
let enableSelfId = prefix + "enableSelf-" + identifier + "-menuitem";
|
|
|
|
let disableSelfId = prefix + "disableSelf-" + identifier + "-menuitem";
|
2013-09-13 06:23:12 -07:00
|
|
|
document.getElementById(enableSelfId).removeAttribute("hidden");
|
|
|
|
document.getElementById(disableSelfId).setAttribute("hidden", "true");
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Update the checkbox state if necessary.
|
|
|
|
if (!aOptions.silent) {
|
|
|
|
attachment.view.checkbox.removeAttribute("checked");
|
2013-06-21 07:33:56 -07:00
|
|
|
}
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
return DebuggerController.Breakpoints.removeBreakpoint(aLocation, {
|
|
|
|
// No need to update this pane, since this method is invoked because
|
|
|
|
// a breakpoint's view was interacted with.
|
2013-09-14 02:34:08 -07:00
|
|
|
noPaneUpdate: true,
|
|
|
|
// Mark this breakpoint as being "disabled", not completely removed.
|
|
|
|
// This makes sure it will not be forgotten across target navigations.
|
|
|
|
rememberDisabled: true
|
2013-09-13 06:23:12 -07:00
|
|
|
});
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Highlights a breakpoint in this sources container.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-09-13 06:23:12 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
|
|
|
* @param object aOptions [optional]
|
2012-11-15 22:42:52 -08:00
|
|
|
* An object containing some of the following boolean properties:
|
2013-09-13 06:23:12 -07:00
|
|
|
* - openPopup: tells if the expression popup should be shown.
|
|
|
|
* - noEditorUpdate: tells if you want to skip editor updates.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:12 -07:00
|
|
|
highlightBreakpoint: function(aLocation, aOptions = {}) {
|
|
|
|
let breakpointItem = this.getBreakpoint(aLocation);
|
2013-02-20 15:33:36 -08:00
|
|
|
if (!breakpointItem) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-15 22:42:52 -08:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Breakpoint will now be selected.
|
2013-02-20 15:33:36 -08:00
|
|
|
this._selectBreakpoint(breakpointItem);
|
2012-11-15 22:42:52 -08:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Update the editor location if necessary.
|
|
|
|
if (!aOptions.noEditorUpdate) {
|
2013-09-13 06:23:13 -07:00
|
|
|
DebuggerView.setEditorLocation(aLocation.url, aLocation.line, { noDebug: true });
|
2012-11-15 22:42:52 -08:00
|
|
|
}
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
// If the breakpoint requires a new conditional expression, display
|
|
|
|
// the panel to input the corresponding expression.
|
2013-09-13 06:23:12 -07:00
|
|
|
if (aOptions.openPopup) {
|
2013-02-20 15:33:36 -08:00
|
|
|
this._openConditionalPopup();
|
|
|
|
} else {
|
|
|
|
this._hideConditionalPopup();
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Unhighlights the current breakpoint in this sources container.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
unhighlightBreakpoint: function() {
|
2013-02-20 15:33:36 -08:00
|
|
|
this._unselectBreakpoint();
|
|
|
|
this._hideConditionalPopup();
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
2013-09-18 17:56:20 -07:00
|
|
|
/**
|
|
|
|
* Pretty print the selected source.
|
|
|
|
*/
|
|
|
|
prettyPrint: function() {
|
2013-10-14 11:44:00 -07:00
|
|
|
if (this._prettyPrintButton.hasAttribute("disabled")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-22 09:03:15 -07:00
|
|
|
const resetEditor = ([{ url }]) => {
|
2013-09-18 17:56:20 -07:00
|
|
|
// Only set the text when the source is still selected.
|
2013-09-22 09:03:15 -07:00
|
|
|
if (url == this.selectedValue) {
|
|
|
|
DebuggerView.setEditorLocation(url, 0, { force: true });
|
2013-09-18 17:56:20 -07:00
|
|
|
}
|
|
|
|
};
|
2013-09-22 09:03:15 -07:00
|
|
|
const printError = ([{ url }, error]) => {
|
|
|
|
let err = DevToolsUtils.safeErrorString(error);
|
|
|
|
let msg = "Couldn't prettify source: " + url + "\n" + err;
|
|
|
|
Cu.reportError(msg);
|
|
|
|
dumpn(msg);
|
|
|
|
return;
|
|
|
|
}
|
2013-09-18 17:56:20 -07:00
|
|
|
|
2013-10-14 13:06:50 -07:00
|
|
|
DebuggerView.showProgressBar();
|
|
|
|
const { source } = this.selectedItem.attachment;
|
|
|
|
DebuggerController.SourceScripts.prettyPrint(source)
|
|
|
|
.then(resetEditor, printError)
|
|
|
|
.then(DebuggerView.showEditor);
|
2013-09-18 17:56:20 -07:00
|
|
|
},
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Marks a breakpoint as selected in this sources container.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-06-21 07:33:56 -07:00
|
|
|
* @param object aItem
|
2013-02-20 15:33:36 -08:00
|
|
|
* The breakpoint item to select.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_selectBreakpoint: function(aItem) {
|
2013-09-13 06:23:12 -07:00
|
|
|
if (this._selectedBreakpointItem == aItem) {
|
2013-02-20 15:33:36 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._unselectBreakpoint();
|
2013-09-13 06:23:12 -07:00
|
|
|
this._selectedBreakpointItem = aItem;
|
|
|
|
this._selectedBreakpointItem.target.classList.add("selected");
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
// Ensure the currently selected breakpoint is visible.
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget.ensureElementIsVisible(aItem.target);
|
2013-02-20 15:33:36 -08:00
|
|
|
},
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
|
|
|
* Marks the current breakpoint as unselected in this sources container.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_unselectBreakpoint: function() {
|
2013-09-13 06:23:12 -07:00
|
|
|
if (!this._selectedBreakpointItem) {
|
|
|
|
return;
|
2013-02-20 15:33:36 -08:00
|
|
|
}
|
2013-09-13 06:23:12 -07:00
|
|
|
this._selectedBreakpointItem.target.classList.remove("selected");
|
|
|
|
this._selectedBreakpointItem = null;
|
2013-02-20 15:33:36 -08:00
|
|
|
},
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
|
|
|
* Opens a conditional breakpoint's expression input popup.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_openConditionalPopup: function() {
|
2013-09-13 06:23:12 -07:00
|
|
|
let breakpointItem = this._selectedBreakpointItem;
|
|
|
|
let attachment = breakpointItem.attachment;
|
|
|
|
|
|
|
|
// Check if this is an enabled conditional breakpoint, and if so,
|
|
|
|
// retrieve the current conditional epression.
|
|
|
|
let breakpointPromise = DebuggerController.Breakpoints._getAdded(attachment);
|
|
|
|
if (breakpointPromise) {
|
|
|
|
breakpointPromise.then(aBreakpointClient => {
|
|
|
|
let isConditionalBreakpoint = "conditionalExpression" in aBreakpointClient;
|
|
|
|
let conditionalExpression = aBreakpointClient.conditionalExpression;
|
|
|
|
doOpen.call(this, isConditionalBreakpoint ? conditionalExpression : "")
|
|
|
|
});
|
2013-02-20 15:33:36 -08:00
|
|
|
} else {
|
2013-09-13 06:23:12 -07:00
|
|
|
doOpen.call(this, "")
|
2013-02-20 15:33:36 -08:00
|
|
|
}
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
function doOpen(aConditionalExpression) {
|
|
|
|
// Update the conditional expression textbox. If no expression was
|
|
|
|
// previously set, revert to using an empty string by default.
|
|
|
|
this._cbTextbox.value = aConditionalExpression;
|
|
|
|
|
|
|
|
// Show the conditional expression panel. The popup arrow should be pointing
|
|
|
|
// at the line number node in the breakpoint item view.
|
|
|
|
this._cbPanel.hidden = false;
|
|
|
|
this._cbPanel.openPopup(breakpointItem.attachment.view.lineNumber,
|
|
|
|
BREAKPOINT_CONDITIONAL_POPUP_POSITION,
|
|
|
|
BREAKPOINT_CONDITIONAL_POPUP_OFFSET_X,
|
|
|
|
BREAKPOINT_CONDITIONAL_POPUP_OFFSET_Y);
|
|
|
|
}
|
2013-02-20 15:33:36 -08:00
|
|
|
},
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
|
|
|
* Hides a conditional breakpoint's expression input popup.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_hideConditionalPopup: function() {
|
2013-02-20 15:33:36 -08:00
|
|
|
this._cbPanel.hidden = true;
|
|
|
|
this._cbPanel.hidePopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customization function for creating a breakpoint item's UI.
|
|
|
|
*
|
|
|
|
* @param object aOptions
|
2013-09-13 06:23:12 -07:00
|
|
|
* A couple of options or flags supported by this operation:
|
|
|
|
* - location: the breakpoint's source location and line number
|
2013-09-14 02:34:08 -07:00
|
|
|
* - disabled: the breakpoint's disabled state, boolean
|
|
|
|
* - text: the breakpoint's line text to be displayed
|
2013-02-20 15:33:36 -08:00
|
|
|
* @return object
|
|
|
|
* An object containing the breakpoint container, checkbox,
|
|
|
|
* line number and line text nodes.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_createBreakpointView: function(aOptions) {
|
2013-09-14 02:34:08 -07:00
|
|
|
let { location, disabled, text } = aOptions;
|
2013-09-14 02:34:07 -07:00
|
|
|
let identifier = DebuggerController.Breakpoints.getIdentifier(location);
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
let checkbox = document.createElement("checkbox");
|
2013-09-14 02:34:08 -07:00
|
|
|
checkbox.setAttribute("checked", !disabled);
|
2013-09-08 04:18:51 -07:00
|
|
|
checkbox.className = "dbg-breakpoint-checkbox";
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
let lineNumberNode = document.createElement("label");
|
|
|
|
lineNumberNode.className = "plain dbg-breakpoint-line";
|
2013-09-14 02:34:07 -07:00
|
|
|
lineNumberNode.setAttribute("value", location.line);
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
let lineTextNode = document.createElement("label");
|
|
|
|
lineTextNode.className = "plain dbg-breakpoint-text";
|
2013-09-14 02:34:07 -07:00
|
|
|
lineTextNode.setAttribute("value", text);
|
2013-02-20 15:33:36 -08:00
|
|
|
lineTextNode.setAttribute("crop", "end");
|
|
|
|
lineTextNode.setAttribute("flex", "1");
|
2013-09-13 06:23:12 -07:00
|
|
|
|
2013-09-14 02:34:07 -07:00
|
|
|
let tooltip = text.substr(0, BREAKPOINT_LINE_TOOLTIP_MAX_LENGTH);
|
2013-09-13 06:23:12 -07:00
|
|
|
lineTextNode.setAttribute("tooltiptext", tooltip);
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
let container = document.createElement("hbox");
|
2013-09-14 02:34:07 -07:00
|
|
|
container.id = "breakpoint-" + identifier;
|
2013-09-13 06:23:13 -07:00
|
|
|
container.className = "dbg-breakpoint side-menu-widget-item-other";
|
|
|
|
container.classList.add("devtools-monospace");
|
2013-02-20 15:33:36 -08:00
|
|
|
container.setAttribute("align", "center");
|
|
|
|
container.setAttribute("flex", "1");
|
|
|
|
|
|
|
|
container.addEventListener("click", this._onBreakpointClick, false);
|
|
|
|
checkbox.addEventListener("click", this._onBreakpointCheckboxClick, false);
|
|
|
|
|
|
|
|
container.appendChild(checkbox);
|
|
|
|
container.appendChild(lineNumberNode);
|
|
|
|
container.appendChild(lineTextNode);
|
|
|
|
|
|
|
|
return {
|
|
|
|
container: container,
|
|
|
|
checkbox: checkbox,
|
|
|
|
lineNumber: lineNumberNode,
|
|
|
|
lineText: lineTextNode
|
|
|
|
};
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a context menu for a breakpoint element.
|
|
|
|
*
|
2013-09-14 02:34:07 -07:00
|
|
|
* @param object aOptions
|
2013-09-13 06:23:12 -07:00
|
|
|
* A couple of options or flags supported by this operation:
|
2013-09-14 02:34:07 -07:00
|
|
|
* - location: the breakpoint's source location and line number
|
2013-09-14 02:34:08 -07:00
|
|
|
* - disabled: the breakpoint's disabled state, boolean
|
2013-02-20 15:33:36 -08:00
|
|
|
* @return object
|
|
|
|
* An object containing the breakpoint commandset and menu popup ids.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_createContextMenu: function(aOptions) {
|
2013-09-14 02:34:08 -07:00
|
|
|
let { location, disabled } = aOptions;
|
2013-09-14 02:34:07 -07:00
|
|
|
let identifier = DebuggerController.Breakpoints.getIdentifier(location);
|
2012-10-26 10:10:17 -07:00
|
|
|
|
|
|
|
let commandset = document.createElement("commandset");
|
|
|
|
let menupopup = document.createElement("menupopup");
|
2013-09-14 02:34:07 -07:00
|
|
|
commandset.id = "bp-cSet-" + identifier;
|
|
|
|
menupopup.id = "bp-mPop-" + identifier;
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-14 02:34:08 -07:00
|
|
|
createMenuItem.call(this, "enableSelf", !disabled);
|
|
|
|
createMenuItem.call(this, "disableSelf", disabled);
|
2013-02-20 15:33:36 -08:00
|
|
|
createMenuItem.call(this, "deleteSelf");
|
2012-10-26 10:10:17 -07:00
|
|
|
createMenuSeparator();
|
2013-02-20 15:33:36 -08:00
|
|
|
createMenuItem.call(this, "setConditional");
|
2012-10-26 10:10:17 -07:00
|
|
|
createMenuSeparator();
|
|
|
|
createMenuItem.call(this, "enableOthers");
|
|
|
|
createMenuItem.call(this, "disableOthers");
|
|
|
|
createMenuItem.call(this, "deleteOthers");
|
|
|
|
createMenuSeparator();
|
2013-02-20 15:33:36 -08:00
|
|
|
createMenuItem.call(this, "enableAll");
|
|
|
|
createMenuItem.call(this, "disableAll");
|
2012-11-15 22:42:52 -08:00
|
|
|
createMenuSeparator();
|
2013-02-20 15:33:36 -08:00
|
|
|
createMenuItem.call(this, "deleteAll");
|
2012-10-26 10:10:17 -07:00
|
|
|
|
|
|
|
this._popupset.appendChild(menupopup);
|
2012-11-15 22:42:52 -08:00
|
|
|
this._commandset.appendChild(commandset);
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
return {
|
2013-09-14 02:34:07 -07:00
|
|
|
commandsetId: commandset.id,
|
|
|
|
menupopupId: menupopup.id
|
2013-02-20 15:33:36 -08:00
|
|
|
};
|
2012-10-26 10:10:17 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a menu item specified by a name with the appropriate attributes
|
|
|
|
* (label and handler).
|
|
|
|
*
|
|
|
|
* @param string aName
|
|
|
|
* A global identifier for the menu item.
|
|
|
|
* @param boolean aHiddenFlag
|
|
|
|
* True if this menuitem should be hidden.
|
|
|
|
*/
|
|
|
|
function createMenuItem(aName, aHiddenFlag) {
|
|
|
|
let menuitem = document.createElement("menuitem");
|
|
|
|
let command = document.createElement("command");
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
let prefix = "bp-cMenu-"; // "breakpoints context menu"
|
2013-09-14 02:34:07 -07:00
|
|
|
let commandId = prefix + aName + "-" + identifier + "-command";
|
|
|
|
let menuitemId = prefix + aName + "-" + identifier + "-menuitem";
|
2012-10-26 10:10:17 -07:00
|
|
|
|
|
|
|
let label = L10N.getStr("breakpointMenuItem." + aName);
|
2013-06-21 07:33:56 -07:00
|
|
|
let func = "_on" + aName.charAt(0).toUpperCase() + aName.slice(1);
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
command.id = commandId;
|
2012-10-26 10:10:17 -07:00
|
|
|
command.setAttribute("label", label);
|
2013-09-14 02:34:07 -07:00
|
|
|
command.addEventListener("command", () => this[func](location), false);
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
menuitem.id = menuitemId;
|
|
|
|
menuitem.setAttribute("command", commandId);
|
2013-06-21 07:33:56 -07:00
|
|
|
aHiddenFlag && menuitem.setAttribute("hidden", "true");
|
2012-10-26 10:10:17 -07:00
|
|
|
|
|
|
|
commandset.appendChild(command);
|
|
|
|
menupopup.appendChild(menuitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a simple menu separator element and appends it to the current
|
|
|
|
* menupopup hierarchy.
|
|
|
|
*/
|
|
|
|
function createMenuSeparator() {
|
|
|
|
let menuseparator = document.createElement("menuseparator");
|
|
|
|
menupopup.appendChild(menuseparator);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function called each time a breakpoint item is removed.
|
2013-02-20 15:33:36 -08:00
|
|
|
*
|
2013-06-21 07:33:56 -07:00
|
|
|
* @param object aItem
|
|
|
|
* The corresponding item.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onBreakpointRemoved: function(aItem) {
|
2013-02-20 15:33:36 -08:00
|
|
|
dumpn("Finalizing breakpoint item: " + aItem);
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
// Destroy the context menu for the breakpoint.
|
|
|
|
let contextMenu = aItem.attachment.popup;
|
|
|
|
document.getElementById(contextMenu.commandsetId).remove();
|
|
|
|
document.getElementById(contextMenu.menupopupId).remove();
|
2013-07-08 03:14:17 -07:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Clear the breakpoint selection.
|
|
|
|
if (this._selectedBreakpointItem == aItem) {
|
|
|
|
this._selectedBreakpointItem = null;
|
2013-07-08 03:14:17 -07:00
|
|
|
}
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
2012-11-15 22:42:52 -08:00
|
|
|
/**
|
|
|
|
* The load listener for the source editor.
|
|
|
|
*/
|
2013-09-13 06:23:14 -07:00
|
|
|
_onEditorLoad: function(aName, aEditor) {
|
|
|
|
aEditor.addEventListener(SourceEditor.EVENTS.SELECTION, this._onEditorSelection, false);
|
|
|
|
aEditor.addEventListener(SourceEditor.EVENTS.CONTEXT_MENU, this._onEditorContextMenu, false);
|
2012-11-15 22:42:52 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The unload listener for the source editor.
|
|
|
|
*/
|
2013-09-13 06:23:14 -07:00
|
|
|
_onEditorUnload: function(aName, aEditor) {
|
|
|
|
aEditor.removeEventListener(SourceEditor.EVENTS.SELECTION, this._onEditorSelection, false);
|
|
|
|
aEditor.removeEventListener(SourceEditor.EVENTS.CONTEXT_MENU, this._onEditorContextMenu, false);
|
2012-11-15 22:42:52 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The selection listener for the source editor.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onEditorSelection: function(e) {
|
2012-11-15 22:42:52 -08:00
|
|
|
let { start, end } = e.newValue;
|
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
let url = this.selectedValue;
|
2012-11-15 22:42:52 -08:00
|
|
|
let lineStart = DebuggerView.editor.getLineAtOffset(start) + 1;
|
|
|
|
let lineEnd = DebuggerView.editor.getLineAtOffset(end) + 1;
|
2013-09-13 06:23:12 -07:00
|
|
|
let location = { url: url, line: lineStart };
|
2012-11-15 22:42:52 -08:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
if (this.getBreakpoint(location) && lineStart == lineEnd) {
|
|
|
|
this.highlightBreakpoint(location, { noEditorUpdate: true });
|
2012-11-15 22:42:52 -08:00
|
|
|
} else {
|
|
|
|
this.unhighlightBreakpoint();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The context menu listener for the source editor.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onEditorContextMenu: function({ x, y }) {
|
2012-11-15 22:42:52 -08:00
|
|
|
let offset = DebuggerView.editor.getOffsetAtLocation(x, y);
|
|
|
|
let line = DebuggerView.editor.getLineAtOffset(offset);
|
|
|
|
this._editorContextMenuLineNumber = line;
|
|
|
|
},
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
|
|
|
* The select listener for the sources container.
|
|
|
|
*/
|
2013-06-21 07:33:56 -07:00
|
|
|
_onSourceSelect: function({ detail: sourceItem }) {
|
|
|
|
if (!sourceItem) {
|
2013-02-20 15:33:36 -08:00
|
|
|
return;
|
|
|
|
}
|
2013-06-21 07:33:56 -07:00
|
|
|
// The container is not empty and an actual item was selected.
|
2013-09-13 06:23:13 -07:00
|
|
|
DebuggerView.setEditorLocation(sourceItem.value);
|
2013-10-11 15:09:00 -07:00
|
|
|
|
|
|
|
// Set window title.
|
|
|
|
let script = sourceItem.value.split(" -> ").pop();
|
|
|
|
document.title = L10N.getFormatStr("DebuggerWindowScriptTitle", script);
|
|
|
|
|
2013-10-14 13:06:50 -07:00
|
|
|
DebuggerView.maybeShowBlackBoxMessage();
|
2013-10-14 11:44:00 -07:00
|
|
|
this._updatePrettyPrintButtonState();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable or disable the pretty print button depending on whether the selected
|
|
|
|
* source is black boxed or not.
|
|
|
|
*/
|
|
|
|
_updatePrettyPrintButtonState: function() {
|
|
|
|
const { source } = this.selectedItem.attachment;
|
|
|
|
if (gThreadClient.source(source).isBlackBoxed) {
|
|
|
|
this._prettyPrintButton.setAttribute("disabled", true);
|
|
|
|
} else {
|
|
|
|
this._prettyPrintButton.removeAttribute("disabled");
|
|
|
|
}
|
2013-07-30 20:36:13 -07:00
|
|
|
},
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
|
|
|
* The click listener for the sources container.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onSourceClick: function() {
|
2013-02-20 15:33:36 -08:00
|
|
|
// Use this container as a filtering target.
|
|
|
|
DebuggerView.Filtering.target = this;
|
|
|
|
},
|
|
|
|
|
2013-07-23 10:15:10 -07:00
|
|
|
/**
|
|
|
|
* The check listener for the sources container.
|
|
|
|
*/
|
|
|
|
_onSourceCheck: function({ detail: { checked }, target }) {
|
2013-10-14 11:44:00 -07:00
|
|
|
const shouldBlackBox = !checked;
|
|
|
|
|
|
|
|
// Be optimistic that the (un-)black boxing will succeed and enable/disable
|
|
|
|
// the pretty print button immediately. Then, once we actually get the
|
|
|
|
// results from the server, make sure that it is in the correct state again
|
|
|
|
// by calling `_updatePrettyPrintButtonState`.
|
|
|
|
|
|
|
|
if (shouldBlackBox) {
|
|
|
|
this._prettyPrintButton.setAttribute("disabled", true);
|
|
|
|
} else {
|
|
|
|
this._prettyPrintButton.removeAttribute("disabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
const { source } = this.getItemForElement(target).attachment;
|
|
|
|
DebuggerController.SourceScripts.blackBox(source, shouldBlackBox)
|
|
|
|
.then(this._updatePrettyPrintButtonState,
|
|
|
|
this._updatePrettyPrintButtonState);
|
2013-07-23 10:15:10 -07:00
|
|
|
},
|
|
|
|
|
2013-07-30 20:36:13 -07:00
|
|
|
/**
|
2013-09-13 06:23:13 -07:00
|
|
|
* The click listener for the "stop black boxing" button.
|
2013-07-30 20:36:13 -07:00
|
|
|
*/
|
|
|
|
_onStopBlackBoxing: function() {
|
2013-09-13 06:23:13 -07:00
|
|
|
let sourceForm = this.selectedItem.attachment.source;
|
|
|
|
DebuggerController.SourceScripts.blackBox(sourceForm, false);
|
2013-07-30 20:36:13 -07:00
|
|
|
},
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
|
|
|
* The click listener for a breakpoint container.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onBreakpointClick: function(e) {
|
2013-02-20 15:33:36 -08:00
|
|
|
let sourceItem = this.getItemForElement(e.target);
|
|
|
|
let breakpointItem = this.getItemForElement.call(sourceItem, e.target);
|
2013-09-13 06:23:12 -07:00
|
|
|
let attachment = breakpointItem.attachment;
|
2013-06-21 07:33:56 -07:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Check if this is an enabled conditional breakpoint.
|
|
|
|
let breakpointPromise = DebuggerController.Breakpoints._getAdded(attachment);
|
|
|
|
if (breakpointPromise) {
|
|
|
|
breakpointPromise.then(aBreakpointClient => {
|
|
|
|
doHighlight.call(this, "conditionalExpression" in aBreakpointClient);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
doHighlight.call(this, false);
|
|
|
|
}
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
function doHighlight(aConditionalBreakpointFlag) {
|
|
|
|
// Highlight the breakpoint in this pane and in the editor.
|
|
|
|
this.highlightBreakpoint(attachment, {
|
|
|
|
// Don't show the conditional expression popup if this is not a
|
|
|
|
// conditional breakpoint, or the right mouse button was pressed (to
|
|
|
|
// avoid clashing the popup with the context menu).
|
|
|
|
openPopup: aConditionalBreakpointFlag && e.button == 0
|
|
|
|
});
|
|
|
|
}
|
2013-02-20 15:33:36 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The click listener for a breakpoint checkbox.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onBreakpointCheckboxClick: function(e) {
|
2013-02-20 15:33:36 -08:00
|
|
|
let sourceItem = this.getItemForElement(e.target);
|
|
|
|
let breakpointItem = this.getItemForElement.call(sourceItem, e.target);
|
2013-09-13 06:23:12 -07:00
|
|
|
let attachment = breakpointItem.attachment;
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Toggle the breakpoint enabled or disabled.
|
|
|
|
this[attachment.disabled ? "enableBreakpoint" : "disableBreakpoint"](attachment, {
|
|
|
|
// Do this silently (don't update the checkbox checked state), since
|
|
|
|
// this listener is triggered because a checkbox was already clicked.
|
2013-02-20 15:33:36 -08:00
|
|
|
silent: true
|
|
|
|
});
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
// Don't update the editor location (avoid propagating into _onBreakpointClick).
|
2013-02-20 15:33:36 -08:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The popup showing listener for the breakpoints conditional expression panel.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onConditionalPopupShowing: function() {
|
2013-09-13 06:23:13 -07:00
|
|
|
this._conditionalPopupVisible = true; // Used in tests.
|
2013-09-13 06:23:14 -07:00
|
|
|
window.emit(EVENTS.CONDITIONAL_BREAKPOINT_POPUP_SHOWING);
|
2013-02-20 15:33:36 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The popup shown listener for the breakpoints conditional expression panel.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onConditionalPopupShown: function() {
|
2013-02-20 15:33:36 -08:00
|
|
|
this._cbTextbox.focus();
|
|
|
|
this._cbTextbox.select();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The popup hiding listener for the breakpoints conditional expression panel.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onConditionalPopupHiding: function() {
|
2013-09-13 06:23:13 -07:00
|
|
|
this._conditionalPopupVisible = false; // Used in tests.
|
2013-09-13 06:23:14 -07:00
|
|
|
window.emit(EVENTS.CONDITIONAL_BREAKPOINT_POPUP_HIDING);
|
2013-02-20 15:33:36 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The input listener for the breakpoints conditional expression textbox.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onConditionalTextboxInput: function() {
|
2013-09-13 06:23:12 -07:00
|
|
|
let breakpointItem = this._selectedBreakpointItem;
|
|
|
|
let attachment = breakpointItem.attachment;
|
|
|
|
|
|
|
|
// Check if this is an enabled conditional breakpoint, and if so,
|
|
|
|
// save the current conditional epression.
|
|
|
|
let breakpointPromise = DebuggerController.Breakpoints._getAdded(attachment);
|
|
|
|
if (breakpointPromise) {
|
|
|
|
breakpointPromise.then(aBreakpointClient => {
|
|
|
|
aBreakpointClient.conditionalExpression = this._cbTextbox.value;
|
|
|
|
});
|
|
|
|
}
|
2013-02-20 15:33:36 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The keypress listener for the breakpoints conditional expression textbox.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onConditionalTextboxKeyPress: function(e) {
|
2013-02-20 15:33:36 -08:00
|
|
|
if (e.keyCode == e.DOM_VK_RETURN || e.keyCode == e.DOM_VK_ENTER) {
|
|
|
|
this._hideConditionalPopup();
|
|
|
|
}
|
2012-11-20 02:57:05 -08:00
|
|
|
},
|
|
|
|
|
2012-11-15 22:42:52 -08:00
|
|
|
/**
|
|
|
|
* Called when the add breakpoint key sequence was pressed.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onCmdAddBreakpoint: function() {
|
2012-11-15 22:42:52 -08:00
|
|
|
// If this command was executed via the context menu, add the breakpoint
|
|
|
|
// on the currently hovered line in the source editor.
|
|
|
|
if (this._editorContextMenuLineNumber >= 0) {
|
|
|
|
DebuggerView.editor.setCaretPosition(this._editorContextMenuLineNumber);
|
|
|
|
}
|
|
|
|
// Avoid placing breakpoints incorrectly when using key shortcuts.
|
|
|
|
this._editorContextMenuLineNumber = -1;
|
|
|
|
|
|
|
|
let url = DebuggerView.Sources.selectedValue;
|
|
|
|
let line = DebuggerView.editor.getCaretPosition().line + 1;
|
2013-09-13 06:23:12 -07:00
|
|
|
let location = { url: url, line: line };
|
|
|
|
let breakpointItem = this.getBreakpoint(location);
|
2012-11-15 22:42:52 -08:00
|
|
|
|
|
|
|
// If a breakpoint already existed, remove it now.
|
|
|
|
if (breakpointItem) {
|
2013-09-13 06:23:12 -07:00
|
|
|
DebuggerController.Breakpoints.removeBreakpoint(location);
|
2012-11-15 22:42:52 -08:00
|
|
|
}
|
|
|
|
// No breakpoint existed at the required location, add one now.
|
|
|
|
else {
|
2013-09-13 06:23:12 -07:00
|
|
|
DebuggerController.Breakpoints.addBreakpoint(location);
|
2012-11-15 22:42:52 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the add conditional breakpoint key sequence was pressed.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onCmdAddConditionalBreakpoint: function() {
|
2012-11-15 22:42:52 -08:00
|
|
|
// If this command was executed via the context menu, add the breakpoint
|
|
|
|
// on the currently hovered line in the source editor.
|
|
|
|
if (this._editorContextMenuLineNumber >= 0) {
|
|
|
|
DebuggerView.editor.setCaretPosition(this._editorContextMenuLineNumber);
|
|
|
|
}
|
|
|
|
// Avoid placing breakpoints incorrectly when using key shortcuts.
|
|
|
|
this._editorContextMenuLineNumber = -1;
|
|
|
|
|
|
|
|
let url = DebuggerView.Sources.selectedValue;
|
|
|
|
let line = DebuggerView.editor.getCaretPosition().line + 1;
|
2013-09-13 06:23:12 -07:00
|
|
|
let location = { url: url, line: line };
|
|
|
|
let breakpointItem = this.getBreakpoint(location);
|
2012-11-15 22:42:52 -08:00
|
|
|
|
|
|
|
// If a breakpoint already existed or wasn't a conditional, morph it now.
|
|
|
|
if (breakpointItem) {
|
2013-09-13 06:23:12 -07:00
|
|
|
this.highlightBreakpoint(location, { openPopup: true });
|
2012-11-15 22:42:52 -08:00
|
|
|
}
|
|
|
|
// No breakpoint existed at the required location, add one now.
|
|
|
|
else {
|
2013-09-13 06:23:12 -07:00
|
|
|
DebuggerController.Breakpoints.addBreakpoint(location, { openPopup: true });
|
2012-11-15 22:42:52 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Function invoked on the "setConditional" menuitem command.
|
2012-11-15 22:42:52 -08:00
|
|
|
*
|
2013-09-14 02:34:07 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2013-06-21 07:33:56 -07:00
|
|
|
*/
|
2013-09-14 02:34:07 -07:00
|
|
|
_onSetConditional: function(aLocation) {
|
2013-06-21 07:33:56 -07:00
|
|
|
// Highlight the breakpoint and show a conditional expression popup.
|
2013-09-14 02:34:07 -07:00
|
|
|
this.highlightBreakpoint(aLocation, { openPopup: true });
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Function invoked on the "enableSelf" menuitem command.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-09-14 02:34:07 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2013-06-21 07:33:56 -07:00
|
|
|
*/
|
2013-09-14 02:34:07 -07:00
|
|
|
_onEnableSelf: function(aLocation) {
|
2013-06-21 07:33:56 -07:00
|
|
|
// Enable the breakpoint, in this container and the controller store.
|
2013-09-14 02:34:07 -07:00
|
|
|
this.enableBreakpoint(aLocation);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Function invoked on the "disableSelf" menuitem command.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-09-14 02:34:07 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2013-06-21 07:33:56 -07:00
|
|
|
*/
|
2013-09-14 02:34:07 -07:00
|
|
|
_onDisableSelf: function(aLocation) {
|
2013-06-21 07:33:56 -07:00
|
|
|
// Disable the breakpoint, in this container and the controller store.
|
2013-09-14 02:34:07 -07:00
|
|
|
this.disableBreakpoint(aLocation);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Function invoked on the "deleteSelf" menuitem command.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-09-14 02:34:07 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2013-06-21 07:33:56 -07:00
|
|
|
*/
|
2013-09-14 02:34:07 -07:00
|
|
|
_onDeleteSelf: function(aLocation) {
|
2013-06-21 07:33:56 -07:00
|
|
|
// Remove the breakpoint, from this container and the controller store.
|
2013-09-14 02:34:07 -07:00
|
|
|
this.removeBreakpoint(aLocation);
|
|
|
|
DebuggerController.Breakpoints.removeBreakpoint(aLocation);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Function invoked on the "enableOthers" menuitem command.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-09-14 02:34:07 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2013-06-21 07:33:56 -07:00
|
|
|
*/
|
2013-09-14 02:34:07 -07:00
|
|
|
_onEnableOthers: function(aLocation) {
|
|
|
|
let enableOthers = aCallback => {
|
|
|
|
let other = this.getOtherBreakpoints(aLocation);
|
2013-09-13 06:23:12 -07:00
|
|
|
let outstanding = other.map(e => this.enableBreakpoint(e.attachment));
|
|
|
|
promise.all(outstanding).then(aCallback);
|
|
|
|
}
|
2013-06-21 07:33:56 -07:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
// Breakpoints can only be set while the debuggee is paused. To avoid
|
|
|
|
// an avalanche of pause/resume interrupts of the main thread, simply
|
|
|
|
// pause it beforehand if it's not already.
|
2013-10-04 00:33:08 -07:00
|
|
|
if (gThreadClient.state != "paused") {
|
2013-09-13 06:23:12 -07:00
|
|
|
gThreadClient.interrupt(() => enableOthers(() => gThreadClient.resume()));
|
2013-10-04 00:33:08 -07:00
|
|
|
} else {
|
|
|
|
enableOthers();
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Function invoked on the "disableOthers" menuitem command.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-09-14 02:34:07 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2013-06-21 07:33:56 -07:00
|
|
|
*/
|
2013-09-14 02:34:07 -07:00
|
|
|
_onDisableOthers: function(aLocation) {
|
|
|
|
let other = this.getOtherBreakpoints(aLocation);
|
|
|
|
other.forEach(e => this._onDisableSelf(e.attachment));
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Function invoked on the "deleteOthers" menuitem command.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-09-14 02:34:07 -07:00
|
|
|
* @param object aLocation
|
|
|
|
* @see DebuggerController.Breakpoints.addBreakpoint
|
2013-06-21 07:33:56 -07:00
|
|
|
*/
|
2013-09-14 02:34:07 -07:00
|
|
|
_onDeleteOthers: function(aLocation) {
|
|
|
|
let other = this.getOtherBreakpoints(aLocation);
|
|
|
|
other.forEach(e => this._onDeleteSelf(e.attachment));
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Function invoked on the "enableAll" menuitem command.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:12 -07:00
|
|
|
_onEnableAll: function() {
|
2013-09-14 02:34:07 -07:00
|
|
|
this._onEnableOthers(undefined);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Function invoked on the "disableAll" menuitem command.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:12 -07:00
|
|
|
_onDisableAll: function() {
|
2013-09-14 02:34:07 -07:00
|
|
|
this._onDisableOthers(undefined);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Function invoked on the "deleteAll" menuitem command.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:12 -07:00
|
|
|
_onDeleteAll: function() {
|
2013-09-14 02:34:07 -07:00
|
|
|
this._onDeleteOthers(undefined);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
2012-11-15 22:42:52 -08:00
|
|
|
_commandset: null,
|
2013-02-20 15:33:36 -08:00
|
|
|
_popupset: null,
|
2012-11-20 02:57:05 -08:00
|
|
|
_cmPopup: null,
|
2012-11-15 22:42:52 -08:00
|
|
|
_cbPanel: null,
|
|
|
|
_cbTextbox: null,
|
2013-09-13 06:23:12 -07:00
|
|
|
_selectedBreakpointItem: null,
|
2013-02-20 15:33:36 -08:00
|
|
|
_editorContextMenuLineNumber: -1,
|
|
|
|
_conditionalPopupVisible: false
|
2012-10-26 10:10:17 -07:00
|
|
|
});
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
|
|
|
* Utility functions for handling sources.
|
|
|
|
*/
|
|
|
|
let SourceUtils = {
|
2013-03-11 23:50:42 -07:00
|
|
|
_labelsCache: new Map(), // Can't use WeakMaps because keys are strings.
|
2013-02-20 15:33:36 -08:00
|
|
|
_groupsCache: new Map(),
|
|
|
|
|
2013-09-22 09:03:15 -07:00
|
|
|
/**
|
|
|
|
* Returns true if the specified url and/or content type are specific to
|
|
|
|
* javascript files.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
* True if the source is likely javascript.
|
|
|
|
*/
|
|
|
|
isJavaScript: function(aUrl, aContentType = "") {
|
|
|
|
return /\.jsm?$/.test(this.trimUrlQuery(aUrl)) ||
|
|
|
|
aContentType.contains("javascript");
|
|
|
|
},
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
|
|
|
* Clears the labels cache, populated by methods like
|
|
|
|
* SourceUtils.getSourceLabel or Source Utils.getSourceGroup.
|
|
|
|
* This should be done every time the content location changes.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
clearCache: function() {
|
2013-03-11 23:50:42 -07:00
|
|
|
this._labelsCache.clear();
|
|
|
|
this._groupsCache.clear();
|
2013-02-20 15:33:36 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a unique, simplified label from a source url.
|
|
|
|
*
|
|
|
|
* @param string aUrl
|
|
|
|
* The source url.
|
|
|
|
* @return string
|
|
|
|
* The simplified label.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
getSourceLabel: function(aUrl) {
|
2013-03-26 09:57:55 -07:00
|
|
|
let cachedLabel = this._labelsCache.get(aUrl);
|
2013-02-20 15:33:36 -08:00
|
|
|
if (cachedLabel) {
|
|
|
|
return cachedLabel;
|
|
|
|
}
|
|
|
|
|
2013-03-26 09:57:55 -07:00
|
|
|
let sourceLabel = this.trimUrl(aUrl);
|
2013-03-11 23:50:42 -07:00
|
|
|
let unicodeLabel = NetworkHelper.convertToUnicode(unescape(sourceLabel));
|
2013-03-26 09:57:55 -07:00
|
|
|
this._labelsCache.set(aUrl, unicodeLabel);
|
2013-02-20 15:33:36 -08:00
|
|
|
return unicodeLabel;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets as much information as possible about the hostname and directory paths
|
|
|
|
* of an url to create a short url group identifier.
|
|
|
|
*
|
|
|
|
* @param string aUrl
|
|
|
|
* The source url.
|
|
|
|
* @return string
|
|
|
|
* The simplified group.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
getSourceGroup: function(aUrl) {
|
2013-02-20 15:33:36 -08:00
|
|
|
let cachedGroup = this._groupsCache.get(aUrl);
|
|
|
|
if (cachedGroup) {
|
|
|
|
return cachedGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Use an nsIURL to parse all the url path parts.
|
|
|
|
var uri = Services.io.newURI(aUrl, null, null).QueryInterface(Ci.nsIURL);
|
|
|
|
} catch (e) {
|
|
|
|
// This doesn't look like a url, or nsIURL can't handle it.
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-07-08 07:47:30 -07:00
|
|
|
let { scheme, directory, fileName } = uri;
|
|
|
|
let hostPort;
|
|
|
|
// Add-on SDK jar: URLs will cause accessing hostPort to throw.
|
|
|
|
if (scheme != "jar") {
|
|
|
|
hostPort = uri.hostPort;
|
|
|
|
}
|
2013-02-20 15:33:36 -08:00
|
|
|
let lastDir = directory.split("/").reverse()[1];
|
|
|
|
let group = [];
|
|
|
|
|
|
|
|
// Only show interesting schemes, http is implicit.
|
|
|
|
if (scheme != "http") {
|
|
|
|
group.push(scheme);
|
|
|
|
}
|
|
|
|
// Hostnames don't always exist for files or some resource urls.
|
|
|
|
// e.g. file://foo/bar.js or resource:///foo/bar.js don't have a host.
|
|
|
|
if (hostPort) {
|
|
|
|
// If the hostname is a dot-separated identifier, show the first 2 parts.
|
|
|
|
group.push(hostPort.split(".").slice(0, 2).join("."));
|
|
|
|
}
|
|
|
|
// Append the last directory if the path leads to an actual file.
|
|
|
|
// e.g. http://foo.org/bar/ should only show "foo.org", not "foo.org bar"
|
|
|
|
if (fileName) {
|
|
|
|
group.push(lastDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
let groupLabel = group.join(" ");
|
2013-03-11 23:50:42 -07:00
|
|
|
let unicodeLabel = NetworkHelper.convertToUnicode(unescape(groupLabel));
|
2013-02-20 15:33:36 -08:00
|
|
|
this._groupsCache.set(aUrl, unicodeLabel)
|
|
|
|
return unicodeLabel;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trims the url by shortening it if it exceeds a certain length, adding an
|
|
|
|
* ellipsis at the end.
|
|
|
|
*
|
|
|
|
* @param string aUrl
|
|
|
|
* The source url.
|
|
|
|
* @param number aLength [optional]
|
|
|
|
* The expected source url length.
|
|
|
|
* @param number aSection [optional]
|
|
|
|
* The section to trim. Supported values: "start", "center", "end"
|
|
|
|
* @return string
|
|
|
|
* The shortened url.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
trimUrlLength: function(aUrl, aLength, aSection) {
|
2013-02-20 15:33:36 -08:00
|
|
|
aLength = aLength || SOURCE_URL_DEFAULT_MAX_LENGTH;
|
|
|
|
aSection = aSection || "end";
|
|
|
|
|
|
|
|
if (aUrl.length > aLength) {
|
|
|
|
switch (aSection) {
|
|
|
|
case "start":
|
|
|
|
return L10N.ellipsis + aUrl.slice(-aLength);
|
|
|
|
break;
|
|
|
|
case "center":
|
|
|
|
return aUrl.substr(0, aLength / 2 - 1) + L10N.ellipsis + aUrl.slice(-aLength / 2 + 1);
|
|
|
|
break;
|
|
|
|
case "end":
|
|
|
|
return aUrl.substr(0, aLength) + L10N.ellipsis;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aUrl;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trims the query part or reference identifier of a url string, if necessary.
|
|
|
|
*
|
|
|
|
* @param string aUrl
|
|
|
|
* The source url.
|
|
|
|
* @return string
|
|
|
|
* The shortened url.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
trimUrlQuery: function(aUrl) {
|
2013-02-20 15:33:36 -08:00
|
|
|
let length = aUrl.length;
|
|
|
|
let q1 = aUrl.indexOf('?');
|
|
|
|
let q2 = aUrl.indexOf('&');
|
|
|
|
let q3 = aUrl.indexOf('#');
|
|
|
|
let q = Math.min(q1 != -1 ? q1 : length,
|
|
|
|
q2 != -1 ? q2 : length,
|
|
|
|
q3 != -1 ? q3 : length);
|
|
|
|
|
|
|
|
return aUrl.slice(0, q);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trims as much as possible from a url, while keeping the label unique
|
|
|
|
* in the sources container.
|
|
|
|
*
|
|
|
|
* @param string | nsIURL aUrl
|
|
|
|
* The source url.
|
|
|
|
* @param string aLabel [optional]
|
|
|
|
* The resulting label at each step.
|
|
|
|
* @param number aSeq [optional]
|
|
|
|
* The current iteration step.
|
|
|
|
* @return string
|
|
|
|
* The resulting label at the final step.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
trimUrl: function(aUrl, aLabel, aSeq) {
|
2013-02-20 15:33:36 -08:00
|
|
|
if (!(aUrl instanceof Ci.nsIURL)) {
|
|
|
|
try {
|
|
|
|
// Use an nsIURL to parse all the url path parts.
|
|
|
|
aUrl = Services.io.newURI(aUrl, null, null).QueryInterface(Ci.nsIURL);
|
|
|
|
} catch (e) {
|
|
|
|
// This doesn't look like a url, or nsIURL can't handle it.
|
|
|
|
return aUrl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!aSeq) {
|
|
|
|
let name = aUrl.fileName;
|
|
|
|
if (name) {
|
|
|
|
// This is a regular file url, get only the file name (contains the
|
|
|
|
// base name and extension if available).
|
|
|
|
|
|
|
|
// If this url contains an invalid query, unfortunately nsIURL thinks
|
|
|
|
// it's part of the file extension. It must be removed.
|
|
|
|
aLabel = aUrl.fileName.replace(/\&.*/, "");
|
|
|
|
} else {
|
|
|
|
// This is not a file url, hence there is no base name, nor extension.
|
|
|
|
// Proceed using other available information.
|
|
|
|
aLabel = "";
|
|
|
|
}
|
|
|
|
aSeq = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a label and it doesn't only contain a query...
|
|
|
|
if (aLabel && aLabel.indexOf("?") != 0) {
|
|
|
|
// A page may contain multiple requests to the same url but with different
|
|
|
|
// queries. It is *not* redundant to show each one.
|
|
|
|
if (!DebuggerView.Sources.containsLabel(aLabel)) {
|
|
|
|
return aLabel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append the url query.
|
|
|
|
if (aSeq == 1) {
|
|
|
|
let query = aUrl.query;
|
|
|
|
if (query) {
|
|
|
|
return this.trimUrl(aUrl, aLabel + "?" + query, aSeq + 1);
|
|
|
|
}
|
|
|
|
aSeq++;
|
|
|
|
}
|
|
|
|
// Append the url reference.
|
|
|
|
if (aSeq == 2) {
|
|
|
|
let ref = aUrl.ref;
|
|
|
|
if (ref) {
|
|
|
|
return this.trimUrl(aUrl, aLabel + "#" + aUrl.ref, aSeq + 1);
|
|
|
|
}
|
|
|
|
aSeq++;
|
|
|
|
}
|
|
|
|
// Prepend the url directory.
|
|
|
|
if (aSeq == 3) {
|
|
|
|
let dir = aUrl.directory;
|
|
|
|
if (dir) {
|
|
|
|
return this.trimUrl(aUrl, dir.replace(/^\//, "") + aLabel, aSeq + 1);
|
|
|
|
}
|
|
|
|
aSeq++;
|
|
|
|
}
|
|
|
|
// Prepend the hostname and port number.
|
|
|
|
if (aSeq == 4) {
|
|
|
|
let host = aUrl.hostPort;
|
|
|
|
if (host) {
|
|
|
|
return this.trimUrl(aUrl, host + "/" + aLabel, aSeq + 1);
|
|
|
|
}
|
|
|
|
aSeq++;
|
|
|
|
}
|
|
|
|
// Use the whole url spec but ignoring the reference.
|
|
|
|
if (aSeq == 5) {
|
|
|
|
return this.trimUrl(aUrl, aUrl.specIgnoringRef, aSeq + 1);
|
|
|
|
}
|
|
|
|
// Give up.
|
|
|
|
return aUrl.spec;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-11-17 11:41:04 -08:00
|
|
|
/**
|
|
|
|
* Functions handling the watch expressions UI.
|
|
|
|
*/
|
|
|
|
function WatchExpressionsView() {
|
|
|
|
dumpn("WatchExpressionsView was instantiated");
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2012-11-27 08:19:23 -08:00
|
|
|
this.switchExpression = this.switchExpression.bind(this);
|
|
|
|
this.deleteExpression = this.deleteExpression.bind(this);
|
2012-11-17 11:41:04 -08:00
|
|
|
this._createItemView = this._createItemView.bind(this);
|
|
|
|
this._onClick = this._onClick.bind(this);
|
|
|
|
this._onClose = this._onClose.bind(this);
|
|
|
|
this._onBlur = this._onBlur.bind(this);
|
|
|
|
this._onKeyPress = this._onKeyPress.bind(this);
|
|
|
|
}
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
WatchExpressionsView.prototype = Heritage.extend(WidgetMethods, {
|
2012-11-17 11:41:04 -08:00
|
|
|
/**
|
|
|
|
* Initialization function, called when the debugger is started.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
initialize: function() {
|
2012-11-17 11:41:04 -08:00
|
|
|
dumpn("Initializing the WatchExpressionsView");
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget = new ListWidget(document.getElementById("expressions"));
|
|
|
|
this.widget.permaText = L10N.getStr("addWatchExpressionText");
|
|
|
|
this.widget.itemFactory = this._createItemView;
|
|
|
|
this.widget.setAttribute("context", "debuggerWatchExpressionsContextMenu");
|
|
|
|
this.widget.addEventListener("click", this._onClick, false);
|
2012-11-17 11:41:04 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destruction function, called when the debugger is closed.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
destroy: function() {
|
2012-11-17 11:41:04 -08:00
|
|
|
dumpn("Destroying the WatchExpressionsView");
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget.removeEventListener("click", this._onClick, false);
|
2012-11-17 11:41:04 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a watch expression in this container.
|
|
|
|
*
|
|
|
|
* @param string aExpression [optional]
|
|
|
|
* An optional initial watch expression text.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
addExpression: function(aExpression = "") {
|
2012-11-17 11:41:04 -08:00
|
|
|
// Watch expressions are UI elements which benefit from visible panes.
|
2013-02-20 15:33:36 -08:00
|
|
|
DebuggerView.showInstrumentsPane();
|
2012-11-17 11:41:04 -08:00
|
|
|
|
|
|
|
// Append a watch expression item to this container.
|
2013-03-09 21:05:09 -08:00
|
|
|
let expressionItem = this.push([, aExpression], {
|
2013-02-20 15:33:36 -08:00
|
|
|
index: 0, /* specifies on which position should the item be appended */
|
2013-03-09 21:05:09 -08:00
|
|
|
relaxed: true, /* this container should allow dupes & degenerates */
|
2012-11-17 11:41:04 -08:00
|
|
|
attachment: {
|
|
|
|
initialExpression: aExpression,
|
2013-06-21 07:33:56 -07:00
|
|
|
currentExpression: ""
|
2012-11-17 11:41:04 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
// Automatically focus the new watch expression input.
|
|
|
|
expressionItem.attachment.inputNode.select();
|
|
|
|
expressionItem.attachment.inputNode.focus();
|
2013-06-21 07:33:56 -07:00
|
|
|
DebuggerView.Variables.parentNode.scrollTop = 0;
|
2012-11-17 11:41:04 -08:00
|
|
|
},
|
|
|
|
|
2012-11-27 08:19:23 -08:00
|
|
|
/**
|
|
|
|
* Changes the watch expression corresponding to the specified variable item.
|
2013-02-20 15:33:36 -08:00
|
|
|
* This function is called whenever a watch expression's code is edited in
|
|
|
|
* the variables view container.
|
2012-11-27 08:19:23 -08:00
|
|
|
*
|
|
|
|
* @param Variable aVar
|
|
|
|
* The variable representing the watch expression evaluation.
|
|
|
|
* @param string aExpression
|
|
|
|
* The new watch expression text.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
switchExpression: function(aVar, aExpression) {
|
2012-11-27 08:19:23 -08:00
|
|
|
let expressionItem =
|
2013-06-21 07:33:56 -07:00
|
|
|
[i for (i in this) if (i.attachment.currentExpression == aVar.name)][0];
|
2012-11-27 08:19:23 -08:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
// Remove the watch expression if it's going to be empty or a duplicate.
|
2013-06-21 07:33:56 -07:00
|
|
|
if (!aExpression || this.getAllStrings().indexOf(aExpression) != -1) {
|
2012-11-27 08:19:23 -08:00
|
|
|
this.deleteExpression(aVar);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the watch expression code string.
|
2013-01-24 03:28:52 -08:00
|
|
|
expressionItem.attachment.currentExpression = aExpression;
|
2013-02-20 15:33:36 -08:00
|
|
|
expressionItem.attachment.inputNode.value = aExpression;
|
2012-11-27 08:19:23 -08:00
|
|
|
|
|
|
|
// Synchronize with the controller's watch expressions store.
|
|
|
|
DebuggerController.StackFrames.syncWatchExpressions();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the watch expression corresponding to the specified variable item.
|
2013-02-20 15:33:36 -08:00
|
|
|
* This function is called whenever a watch expression's value is edited in
|
|
|
|
* the variables view container.
|
2012-11-27 08:19:23 -08:00
|
|
|
*
|
|
|
|
* @param Variable aVar
|
|
|
|
* The variable representing the watch expression evaluation.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
deleteExpression: function(aVar) {
|
2012-11-27 08:19:23 -08:00
|
|
|
let expressionItem =
|
2013-06-21 07:33:56 -07:00
|
|
|
[i for (i in this) if (i.attachment.currentExpression == aVar.name)][0];
|
2012-11-27 08:19:23 -08:00
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
// Remove the watch expression.
|
|
|
|
this.remove(expressionItem);
|
2012-11-27 08:19:23 -08:00
|
|
|
|
|
|
|
// Synchronize with the controller's watch expressions store.
|
|
|
|
DebuggerController.StackFrames.syncWatchExpressions();
|
|
|
|
},
|
|
|
|
|
2012-11-17 11:41:04 -08:00
|
|
|
/**
|
|
|
|
* Gets the watch expression code string for an item in this container.
|
|
|
|
*
|
|
|
|
* @param number aIndex
|
|
|
|
* The index used to identify the watch expression.
|
|
|
|
* @return string
|
|
|
|
* The watch expression code string.
|
|
|
|
*/
|
2013-06-21 07:33:56 -07:00
|
|
|
getString: function(aIndex) {
|
|
|
|
return this.getItemAtIndex(aIndex).attachment.currentExpression;
|
2012-11-17 11:41:04 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the watch expressions code strings for all items in this container.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* The watch expressions code strings.
|
|
|
|
*/
|
2013-06-21 07:33:56 -07:00
|
|
|
getAllStrings: function() {
|
2013-09-13 06:23:13 -07:00
|
|
|
return this.items.map(e => e.attachment.currentExpression);
|
2012-11-17 11:41:04 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customization function for creating an item's UI.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aElementNode
|
|
|
|
* The element associated with the displayed item.
|
2013-02-20 15:33:36 -08:00
|
|
|
* @param any aAttachment
|
|
|
|
* Some attached primitive/object.
|
2012-11-17 11:41:04 -08:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_createItemView: function(aElementNode, aAttachment) {
|
2012-11-17 11:41:04 -08:00
|
|
|
let arrowNode = document.createElement("box");
|
2013-02-20 15:33:36 -08:00
|
|
|
arrowNode.className = "dbg-expression-arrow";
|
2012-11-17 11:41:04 -08:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
let inputNode = document.createElement("textbox");
|
2013-08-26 01:24:41 -07:00
|
|
|
inputNode.className = "plain dbg-expression-input devtools-monospace";
|
2013-02-20 15:33:36 -08:00
|
|
|
inputNode.setAttribute("value", aAttachment.initialExpression);
|
2012-11-17 11:41:04 -08:00
|
|
|
inputNode.setAttribute("flex", "1");
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
let closeNode = document.createElement("toolbarbutton");
|
|
|
|
closeNode.className = "plain variables-view-delete";
|
|
|
|
|
2012-11-17 11:41:04 -08:00
|
|
|
closeNode.addEventListener("click", this._onClose, false);
|
|
|
|
inputNode.addEventListener("blur", this._onBlur, false);
|
|
|
|
inputNode.addEventListener("keypress", this._onKeyPress, false);
|
|
|
|
|
2013-06-22 12:01:27 -07:00
|
|
|
aElementNode.className = "dbg-expression";
|
2012-11-17 11:41:04 -08:00
|
|
|
aElementNode.appendChild(arrowNode);
|
|
|
|
aElementNode.appendChild(inputNode);
|
|
|
|
aElementNode.appendChild(closeNode);
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
aAttachment.arrowNode = arrowNode;
|
|
|
|
aAttachment.inputNode = inputNode;
|
|
|
|
aAttachment.closeNode = closeNode;
|
2012-11-17 11:41:04 -08:00
|
|
|
},
|
|
|
|
|
2012-12-01 01:21:23 -08:00
|
|
|
/**
|
|
|
|
* Called when the add watch expression key sequence was pressed.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onCmdAddExpression: function(aText) {
|
2012-12-01 01:21:23 -08:00
|
|
|
// Only add a new expression if there's no pending input.
|
2013-06-21 07:33:56 -07:00
|
|
|
if (this.getAllStrings().indexOf("") == -1) {
|
2012-12-01 01:21:23 -08:00
|
|
|
this.addExpression(aText || DebuggerView.editor.getSelectedText());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the remove all watch expressions key sequence was pressed.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onCmdRemoveAllExpressions: function() {
|
2012-12-01 01:21:23 -08:00
|
|
|
// Empty the view of all the watch expressions and clear the cache.
|
|
|
|
this.empty();
|
|
|
|
|
|
|
|
// Synchronize with the controller's watch expressions store.
|
|
|
|
DebuggerController.StackFrames.syncWatchExpressions();
|
|
|
|
},
|
|
|
|
|
2012-11-17 11:41:04 -08:00
|
|
|
/**
|
|
|
|
* The click listener for this container.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onClick: function(e) {
|
2012-12-01 01:21:23 -08:00
|
|
|
if (e.button != 0) {
|
|
|
|
// Only allow left-click to trigger this event.
|
|
|
|
return;
|
|
|
|
}
|
2012-11-17 11:41:04 -08:00
|
|
|
let expressionItem = this.getItemForElement(e.target);
|
|
|
|
if (!expressionItem) {
|
|
|
|
// The container is empty or we didn't click on an actual item.
|
|
|
|
this.addExpression();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The click listener for a watch expression's close button.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onClose: function(e) {
|
2013-06-21 07:33:56 -07:00
|
|
|
// Remove the watch expression.
|
|
|
|
this.remove(this.getItemForElement(e.target));
|
2012-11-17 11:41:04 -08:00
|
|
|
|
|
|
|
// Synchronize with the controller's watch expressions store.
|
|
|
|
DebuggerController.StackFrames.syncWatchExpressions();
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
// Prevent clicking the expression element itself.
|
2012-11-17 11:41:04 -08:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The blur listener for a watch expression's textbox.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onBlur: function({ target: textbox }) {
|
2012-11-17 11:41:04 -08:00
|
|
|
let expressionItem = this.getItemForElement(textbox);
|
2013-01-24 03:28:52 -08:00
|
|
|
let oldExpression = expressionItem.attachment.currentExpression;
|
2012-11-27 08:19:23 -08:00
|
|
|
let newExpression = textbox.value.trim();
|
2012-11-17 11:41:04 -08:00
|
|
|
|
|
|
|
// Remove the watch expression if it's empty.
|
|
|
|
if (!newExpression) {
|
2013-06-21 07:33:56 -07:00
|
|
|
this.remove(expressionItem);
|
2012-11-17 11:41:04 -08:00
|
|
|
}
|
|
|
|
// Remove the watch expression if it's a duplicate.
|
2013-06-21 07:33:56 -07:00
|
|
|
else if (!oldExpression && this.getAllStrings().indexOf(newExpression) != -1) {
|
|
|
|
this.remove(expressionItem);
|
2012-11-17 11:41:04 -08:00
|
|
|
}
|
|
|
|
// Expression is eligible.
|
|
|
|
else {
|
2013-01-24 03:28:52 -08:00
|
|
|
expressionItem.attachment.currentExpression = newExpression;
|
2012-11-17 11:41:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Synchronize with the controller's watch expressions store.
|
|
|
|
DebuggerController.StackFrames.syncWatchExpressions();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The keypress listener for a watch expression's textbox.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onKeyPress: function(e) {
|
2012-11-17 11:41:04 -08:00
|
|
|
switch(e.keyCode) {
|
|
|
|
case e.DOM_VK_RETURN:
|
|
|
|
case e.DOM_VK_ENTER:
|
|
|
|
case e.DOM_VK_ESCAPE:
|
|
|
|
DebuggerView.editor.focus();
|
|
|
|
return;
|
|
|
|
}
|
2013-06-21 07:33:56 -07:00
|
|
|
}
|
2012-11-17 11:41:04 -08:00
|
|
|
});
|
|
|
|
|
2013-10-04 00:33:08 -07:00
|
|
|
/**
|
|
|
|
* Functions handling the event listeners UI.
|
|
|
|
*/
|
|
|
|
function EventListenersView() {
|
|
|
|
dumpn("EventListenersView was instantiated");
|
|
|
|
|
|
|
|
this._onCheck = this._onCheck.bind(this);
|
|
|
|
this._onClick = this._onClick.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
EventListenersView.prototype = Heritage.extend(WidgetMethods, {
|
|
|
|
/**
|
|
|
|
* Initialization function, called when the debugger is started.
|
|
|
|
*/
|
|
|
|
initialize: function() {
|
|
|
|
dumpn("Initializing the EventListenersView");
|
|
|
|
|
|
|
|
this.widget = new SideMenuWidget(document.getElementById("event-listeners"), {
|
|
|
|
theme: "light",
|
|
|
|
showItemCheckboxes: true,
|
|
|
|
showGroupCheckboxes: true
|
|
|
|
});
|
|
|
|
|
|
|
|
this.emptyText = L10N.getStr("noEventListenersText");
|
|
|
|
this._eventCheckboxTooltip = L10N.getStr("eventCheckboxTooltip");
|
|
|
|
this._onSelectorString = " " + L10N.getStr("eventOnSelector") + " ";
|
|
|
|
this._inSourceString = " " + L10N.getStr("eventInSource") + " ";
|
2013-10-04 00:33:08 -07:00
|
|
|
this._inNativeCodeString = L10N.getStr("eventNative");
|
2013-10-04 00:33:08 -07:00
|
|
|
|
|
|
|
this.widget.addEventListener("check", this._onCheck, false);
|
|
|
|
this.widget.addEventListener("click", this._onClick, false);
|
|
|
|
|
|
|
|
// Show an empty label by default.
|
|
|
|
this.empty();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destruction function, called when the debugger is closed.
|
|
|
|
*/
|
|
|
|
destroy: function() {
|
|
|
|
dumpn("Destroying the EventListenersView");
|
|
|
|
|
|
|
|
this.widget.removeEventListener("check", this._onCheck, false);
|
|
|
|
this.widget.removeEventListener("click", this._onClick, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an event to this event listeners container.
|
|
|
|
*
|
|
|
|
* @param object aListener
|
|
|
|
* The listener object coming from the active thread.
|
|
|
|
* @param object aOptions [optional]
|
|
|
|
* Additional options for adding the source. Supported options:
|
|
|
|
* - staged: true to stage the item to be appended later
|
|
|
|
*/
|
|
|
|
addListener: function(aListener, aOptions = {}) {
|
|
|
|
let { node: { selector }, function: { url }, type } = aListener;
|
2013-10-05 06:26:08 -07:00
|
|
|
if (!type) return;
|
|
|
|
|
|
|
|
// Some listener objects may be added from plugins, thus getting
|
|
|
|
// translated to native code.
|
|
|
|
if (!url) {
|
|
|
|
url = this._inNativeCodeString;
|
|
|
|
}
|
2013-10-04 00:33:08 -07:00
|
|
|
|
|
|
|
// If an event item for this listener's url and type was already added,
|
|
|
|
// avoid polluting the view and simply increase the "targets" count.
|
|
|
|
let eventItem = this.getItemForPredicate(aItem =>
|
|
|
|
aItem.attachment.url == url &&
|
|
|
|
aItem.attachment.type == type);
|
|
|
|
if (eventItem) {
|
|
|
|
let { selectors, view: { targets } } = eventItem.attachment;
|
|
|
|
if (selectors.indexOf(selector) == -1) {
|
|
|
|
selectors.push(selector);
|
|
|
|
targets.setAttribute("value", L10N.getFormatStr("eventNodes", selectors.length));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There's no easy way of grouping event types into higher-level groups,
|
|
|
|
// so we need to do this by hand.
|
|
|
|
let is = (...args) => args.indexOf(type) != -1;
|
|
|
|
let has = str => type.contains(str);
|
|
|
|
let starts = str => type.startsWith(str);
|
|
|
|
let group;
|
|
|
|
|
|
|
|
if (starts("animation")) {
|
|
|
|
group = L10N.getStr("animationEvents");
|
|
|
|
} else if (starts("audio")) {
|
|
|
|
group = L10N.getStr("audioEvents");
|
|
|
|
} else if (is("levelchange")) {
|
|
|
|
group = L10N.getStr("batteryEvents");
|
|
|
|
} else if (is("cut", "copy", "paste")) {
|
|
|
|
group = L10N.getStr("clipboardEvents");
|
|
|
|
} else if (starts("composition")) {
|
|
|
|
group = L10N.getStr("compositionEvents");
|
|
|
|
} else if (starts("device")) {
|
|
|
|
group = L10N.getStr("deviceEvents");
|
|
|
|
} else if (is("fullscreenchange", "fullscreenerror", "orientationchange",
|
|
|
|
"overflow", "resize", "scroll", "underflow", "zoom")) {
|
|
|
|
group = L10N.getStr("displayEvents");
|
|
|
|
} else if (starts("drag") || starts("drop")) {
|
|
|
|
group = L10N.getStr("Drag and dropEvents");
|
|
|
|
} else if (starts("gamepad")) {
|
|
|
|
group = L10N.getStr("gamepadEvents");
|
|
|
|
} else if (is("canplay", "canplaythrough", "durationchange", "emptied",
|
|
|
|
"ended", "loadeddata", "loadedmetadata", "pause", "play", "playing",
|
|
|
|
"ratechange", "seeked", "seeking", "stalled", "suspend", "timeupdate",
|
|
|
|
"volumechange", "waiting")) {
|
|
|
|
group = L10N.getStr("mediaEvents");
|
|
|
|
} else if (is("blocked", "complete", "success", "upgradeneeded", "versionchange")) {
|
|
|
|
group = L10N.getStr("indexedDBEvents");
|
|
|
|
} else if (is("blur", "change", "focus", "focusin", "focusout", "invalid",
|
|
|
|
"reset", "select", "submit")) {
|
|
|
|
group = L10N.getStr("interactionEvents");
|
|
|
|
} else if (starts("key") || is("input")) {
|
|
|
|
group = L10N.getStr("keyboardEvents");
|
|
|
|
} else if (starts("mouse") || has("click") || is("contextmenu", "show", "wheel")) {
|
|
|
|
group = L10N.getStr("mouseEvents");
|
|
|
|
} else if (starts("DOM")) {
|
|
|
|
group = L10N.getStr("mutationEvents");
|
|
|
|
} else if (is("abort", "error", "hashchange", "load", "loadend", "loadstart",
|
|
|
|
"pagehide", "pageshow", "progress", "timeout", "unload", "uploadprogress",
|
|
|
|
"visibilitychange")) {
|
|
|
|
group = L10N.getStr("navigationEvents");
|
|
|
|
} else if (is("pointerlockchange", "pointerlockerror")) {
|
|
|
|
group = L10N.getStr("Pointer lockEvents");
|
|
|
|
} else if (is("compassneedscalibration", "userproximity")) {
|
|
|
|
group = L10N.getStr("sensorEvents");
|
|
|
|
} else if (starts("storage")) {
|
|
|
|
group = L10N.getStr("storageEvents");
|
|
|
|
} else if (is("beginEvent", "endEvent", "repeatEvent")) {
|
|
|
|
group = L10N.getStr("timeEvents");
|
|
|
|
} else if (starts("touch")) {
|
|
|
|
group = L10N.getStr("touchEvents");
|
|
|
|
} else {
|
|
|
|
group = L10N.getStr("otherEvents");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the element node for the event listener item.
|
|
|
|
let itemView = this._createItemView(type, selector, url);
|
|
|
|
|
|
|
|
// Event breakpoints survive target navigations. Make sure the newly
|
|
|
|
// inserted event item is correctly checked.
|
|
|
|
let checkboxState =
|
|
|
|
DebuggerController.Breakpoints.DOM.activeEventNames.indexOf(type) != -1;
|
|
|
|
|
|
|
|
// Append an event listener item to this container.
|
|
|
|
this.push([itemView.container, url, group], {
|
|
|
|
staged: aOptions.staged, /* stage the item to be appended later? */
|
|
|
|
attachment: {
|
|
|
|
url: url,
|
|
|
|
type: type,
|
|
|
|
view: itemView,
|
|
|
|
selectors: [selector],
|
|
|
|
checkboxState: checkboxState,
|
|
|
|
checkboxTooltip: this._eventCheckboxTooltip
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets all the event types known to this container.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* List of event types, for example ["load", "click"...]
|
|
|
|
*/
|
|
|
|
getAllEvents: function() {
|
|
|
|
return this.attachments.map(e => e.type);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the checked event types in this container.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* List of event types, for example ["load", "click"...]
|
|
|
|
*/
|
|
|
|
getCheckedEvents: function() {
|
|
|
|
return this.attachments.filter(e => e.checkboxState).map(e => e.type);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customization function for creating an item's UI.
|
|
|
|
*
|
|
|
|
* @param string aType
|
|
|
|
* The event type, for example "click".
|
|
|
|
* @param string aSelector
|
|
|
|
* The target element's selector.
|
|
|
|
* @param string url
|
|
|
|
* The source url in which the event listener is located.
|
|
|
|
* @return object
|
|
|
|
* An object containing the event listener view nodes.
|
|
|
|
*/
|
|
|
|
_createItemView: function(aType, aSelector, aUrl) {
|
|
|
|
let container = document.createElement("hbox");
|
|
|
|
container.className = "dbg-event-listener";
|
|
|
|
|
|
|
|
let eventType = document.createElement("label");
|
|
|
|
eventType.className = "plain dbg-event-listener-type";
|
|
|
|
eventType.setAttribute("value", aType);
|
|
|
|
container.appendChild(eventType);
|
|
|
|
|
|
|
|
let typeSeparator = document.createElement("label");
|
|
|
|
typeSeparator.className = "plain dbg-event-listener-separator";
|
|
|
|
typeSeparator.setAttribute("value", this._onSelectorString);
|
|
|
|
container.appendChild(typeSeparator);
|
|
|
|
|
|
|
|
let eventTargets = document.createElement("label");
|
|
|
|
eventTargets.className = "plain dbg-event-listener-targets";
|
|
|
|
eventTargets.setAttribute("value", aSelector);
|
|
|
|
container.appendChild(eventTargets);
|
|
|
|
|
|
|
|
let selectorSeparator = document.createElement("label");
|
|
|
|
selectorSeparator.className = "plain dbg-event-listener-separator";
|
|
|
|
selectorSeparator.setAttribute("value", this._inSourceString);
|
|
|
|
container.appendChild(selectorSeparator);
|
|
|
|
|
|
|
|
let eventLocation = document.createElement("label");
|
|
|
|
eventLocation.className = "plain dbg-event-listener-location";
|
|
|
|
eventLocation.setAttribute("value", SourceUtils.getSourceLabel(aUrl));
|
|
|
|
eventLocation.setAttribute("flex", "1");
|
|
|
|
eventLocation.setAttribute("crop", "center");
|
|
|
|
container.appendChild(eventLocation);
|
|
|
|
|
|
|
|
return {
|
|
|
|
container: container,
|
|
|
|
type: eventType,
|
|
|
|
targets: eventTargets,
|
|
|
|
location: eventLocation
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The check listener for the event listeners container.
|
|
|
|
*/
|
|
|
|
_onCheck: function({ detail: { description, checked }, target }) {
|
|
|
|
if (description == "item") {
|
|
|
|
this.getItemForElement(target).attachment.checkboxState = checked;
|
|
|
|
DebuggerController.Breakpoints.DOM.scheduleEventBreakpointsUpdate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check all the event items in this group.
|
|
|
|
this.items
|
|
|
|
.filter(e => e.description == description)
|
|
|
|
.forEach(e => this.callMethod("checkItem", e.target, checked));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The select listener for the event listeners container.
|
|
|
|
*/
|
|
|
|
_onClick: function({ target }) {
|
|
|
|
// Changing the checkbox state is handled by the _onCheck event. Avoid
|
|
|
|
// handling that again in this click event, so pass in "noSiblings"
|
|
|
|
// when retrieving the target's item, to ignore the checkbox.
|
|
|
|
let eventItem = this.getItemForElement(target, { noSiblings: true });
|
|
|
|
if (eventItem) {
|
|
|
|
let newState = eventItem.attachment.checkboxState ^= 1;
|
|
|
|
this.callMethod("checkItem", eventItem.target, newState);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_eventCheckboxTooltip: "",
|
|
|
|
_onSelectorString: "",
|
2013-10-04 00:33:08 -07:00
|
|
|
_inSourceString: "",
|
|
|
|
_inNativeCodeString: ""
|
2013-10-04 00:33:08 -07:00
|
|
|
});
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
/**
|
|
|
|
* Functions handling the global search UI.
|
|
|
|
*/
|
|
|
|
function GlobalSearchView() {
|
|
|
|
dumpn("GlobalSearchView was instantiated");
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
this._createItemView = this._createItemView.bind(this);
|
|
|
|
this._onHeaderClick = this._onHeaderClick.bind(this);
|
|
|
|
this._onLineClick = this._onLineClick.bind(this);
|
|
|
|
this._onMatchClick = this._onMatchClick.bind(this);
|
|
|
|
}
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
GlobalSearchView.prototype = Heritage.extend(WidgetMethods, {
|
2012-10-26 10:10:17 -07:00
|
|
|
/**
|
|
|
|
* Initialization function, called when the debugger is started.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
initialize: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Initializing the GlobalSearchView");
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget = new ListWidget(document.getElementById("globalsearch"));
|
2013-02-20 15:33:36 -08:00
|
|
|
this._splitter = document.querySelector("#globalsearch + .devtools-horizontal-splitter");
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget.emptyText = L10N.getStr("noMatchingStringsText");
|
|
|
|
this.widget.itemFactory = this._createItemView;
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destruction function, called when the debugger is closed.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
destroy: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Destroying the GlobalSearchView");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the results container hidden or visible. It's hidden by default.
|
|
|
|
* @param boolean aFlag
|
|
|
|
*/
|
|
|
|
set hidden(aFlag) {
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget.setAttribute("hidden", aFlag);
|
2012-10-26 10:10:17 -07:00
|
|
|
this._splitter.setAttribute("hidden", aFlag);
|
|
|
|
},
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
/**
|
|
|
|
* Gets the visibility state of the global search container.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
get hidden()
|
|
|
|
this.widget.getAttribute("hidden") == "true" ||
|
|
|
|
this._splitter.getAttribute("hidden") == "true",
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Hides and removes all items from this search container.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
clearView: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
this.hidden = true;
|
|
|
|
this.empty();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Selects the next found item in this container.
|
|
|
|
* Does not change the currently focused node.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-06-21 07:33:56 -07:00
|
|
|
selectNext: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
let totalLineResults = LineResults.size();
|
|
|
|
if (!totalLineResults) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (++this._currentlyFocusedMatch >= totalLineResults) {
|
|
|
|
this._currentlyFocusedMatch = 0;
|
|
|
|
}
|
|
|
|
this._onMatchClick({
|
|
|
|
target: LineResults.getElementAtIndex(this._currentlyFocusedMatch)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Selects the previously found item in this container.
|
|
|
|
* Does not change the currently focused node.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-06-21 07:33:56 -07:00
|
|
|
selectPrev: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
let totalLineResults = LineResults.size();
|
|
|
|
if (!totalLineResults) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (--this._currentlyFocusedMatch < 0) {
|
|
|
|
this._currentlyFocusedMatch = totalLineResults - 1;
|
|
|
|
}
|
|
|
|
this._onMatchClick({
|
|
|
|
target: LineResults.getElementAtIndex(this._currentlyFocusedMatch)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedules searching for a string in all of the sources.
|
2012-11-21 00:49:45 -08:00
|
|
|
*
|
2013-09-13 06:23:13 -07:00
|
|
|
* @param string aToken
|
2012-11-21 00:49:45 -08:00
|
|
|
* The string to search for.
|
2013-09-13 06:23:13 -07:00
|
|
|
* @param number aWait
|
|
|
|
* The amount of milliseconds to wait until draining.
|
|
|
|
*/
|
|
|
|
scheduleSearch: function(aToken, aWait) {
|
|
|
|
// The amount of time to wait for the requests to settle.
|
|
|
|
let maxDelay = GLOBAL_SEARCH_ACTION_MAX_DELAY;
|
|
|
|
let delay = aWait === undefined ? maxDelay / aToken.length : aWait;
|
|
|
|
|
|
|
|
// Allow requests to settle down first.
|
|
|
|
setNamedTimeout("global-search", delay, () => {
|
|
|
|
// Start fetching as many sources as possible, then perform the search.
|
|
|
|
let urls = DebuggerView.Sources.values;
|
|
|
|
let sourcesFetched = DebuggerController.SourceScripts.getTextForSources(urls);
|
|
|
|
sourcesFetched.then(aSources => this._doSearch(aToken, aSources));
|
|
|
|
});
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-09-13 06:23:13 -07:00
|
|
|
* Finds string matches in all the sources stored in the controller's cache,
|
|
|
|
* and groups them by url and line number.
|
2012-11-21 00:49:45 -08:00
|
|
|
*
|
2013-09-13 06:23:13 -07:00
|
|
|
* @param string aToken
|
2012-11-21 00:49:45 -08:00
|
|
|
* The string to search for.
|
2013-09-13 06:23:13 -07:00
|
|
|
* @param array aSources
|
|
|
|
* An array of [url, text] tuples for each source.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
_doSearch: function(aToken, aSources) {
|
|
|
|
// Don't continue filtering if the searched token is an empty string.
|
|
|
|
if (!aToken) {
|
2012-10-26 10:10:17 -07:00
|
|
|
this.clearView();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search is not case sensitive, prepare the actual searched token.
|
2013-09-13 06:23:13 -07:00
|
|
|
let lowerCaseToken = aToken.toLowerCase();
|
|
|
|
let tokenLength = aToken.length;
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// Create a Map containing search details for each source.
|
2012-10-26 10:10:17 -07:00
|
|
|
let globalResults = new GlobalResults();
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// Search for the specified token in each source's text.
|
|
|
|
for (let [url, text] of aSources) {
|
2012-10-26 10:10:17 -07:00
|
|
|
// Verify that the search token is found anywhere in the source.
|
2013-09-13 06:23:13 -07:00
|
|
|
if (!text.toLowerCase().contains(lowerCaseToken)) {
|
2012-10-26 10:10:17 -07:00
|
|
|
continue;
|
|
|
|
}
|
2013-09-13 06:23:13 -07:00
|
|
|
// ...and if so, create a Map containing search details for each line.
|
|
|
|
let sourceResults = new SourceResults(url, globalResults);
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// Search for the specified token in each line's text.
|
|
|
|
text.split("\n").forEach((aString, aLine) => {
|
|
|
|
// Search is not case sensitive, prepare the actual searched line.
|
|
|
|
let lowerCaseLine = aString.toLowerCase();
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// Verify that the search token is found anywhere in this line.
|
2012-10-26 10:10:17 -07:00
|
|
|
if (!lowerCaseLine.contains(lowerCaseToken)) {
|
2013-09-13 06:23:13 -07:00
|
|
|
return;
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
2013-09-13 06:23:13 -07:00
|
|
|
// ...and if so, create a Map containing search details for each word.
|
|
|
|
let lineResults = new LineResults(aLine, sourceResults);
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// Search for the specified token this line's text.
|
|
|
|
lowerCaseLine.split(lowerCaseToken).reduce((aPrev, aCurr, aIndex, aArray) => {
|
|
|
|
let prevLength = aPrev.length;
|
|
|
|
let currLength = aCurr.length;
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// Everything before the token is unmatched.
|
|
|
|
let unmatched = aString.substr(prevLength, currLength);
|
2012-10-26 10:10:17 -07:00
|
|
|
lineResults.add(unmatched);
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// The lowered-case line was split by the lowered-case token. So,
|
|
|
|
// get the actual matched text from the original line's text.
|
|
|
|
if (aIndex != aArray.length - 1) {
|
|
|
|
let matched = aString.substr(prevLength + currLength, tokenLength);
|
|
|
|
let range = { start: prevLength + currLength, length: matched.length };
|
2012-10-26 10:10:17 -07:00
|
|
|
lineResults.add(matched, range, true);
|
|
|
|
}
|
2013-09-13 06:23:13 -07:00
|
|
|
|
|
|
|
// Continue with the next sub-region in this line's text.
|
2013-09-13 06:23:13 -07:00
|
|
|
return aPrev + aToken + aCurr;
|
2012-10-26 10:10:17 -07:00
|
|
|
}, "");
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
if (lineResults.matchCount) {
|
|
|
|
sourceResults.add(lineResults);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
2013-09-13 06:23:13 -07:00
|
|
|
});
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
if (sourceResults.matchCount) {
|
2013-09-13 06:23:13 -07:00
|
|
|
globalResults.add(sourceResults);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// Rebuild the results, then signal if there are any matches.
|
|
|
|
if (globalResults.matchCount) {
|
2012-10-26 10:10:17 -07:00
|
|
|
this.hidden = false;
|
|
|
|
this._currentlyFocusedMatch = -1;
|
|
|
|
this._createGlobalResultsUI(globalResults);
|
2013-09-13 06:23:14 -07:00
|
|
|
window.emit(EVENTS.GLOBAL_SEARCH_MATCH_FOUND);
|
2012-10-26 10:10:17 -07:00
|
|
|
} else {
|
2013-09-13 06:23:14 -07:00
|
|
|
window.emit(EVENTS.GLOBAL_SEARCH_MATCH_NOT_FOUND);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates global search results entries and adds them to this container.
|
|
|
|
*
|
|
|
|
* @param GlobalResults aGlobalResults
|
|
|
|
* An object containing all source results, grouped by source location.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_createGlobalResultsUI: function(aGlobalResults) {
|
2012-10-26 10:10:17 -07:00
|
|
|
let i = 0;
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
for (let sourceResults in aGlobalResults) {
|
2012-10-26 10:10:17 -07:00
|
|
|
if (i++ == 0) {
|
2013-09-13 06:23:13 -07:00
|
|
|
this._createSourceResultsUI(sourceResults);
|
2012-10-26 10:10:17 -07:00
|
|
|
} else {
|
|
|
|
// Dispatch subsequent document manipulation operations, to avoid
|
|
|
|
// blocking the main thread when a large number of search results
|
|
|
|
// is found, thus giving the impression of faster searching.
|
|
|
|
Services.tm.currentThread.dispatch({ run:
|
2013-09-13 06:23:13 -07:00
|
|
|
this._createSourceResultsUI.bind(this, sourceResults)
|
|
|
|
}, 0);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates source search results entries and adds them to this container.
|
|
|
|
*
|
|
|
|
* @param SourceResults aSourceResults
|
|
|
|
* An object containing all the matched lines for a specific source.
|
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
_createSourceResultsUI: function(aSourceResults) {
|
2012-10-26 10:10:17 -07:00
|
|
|
// Append a source results item to this container.
|
2013-09-13 06:23:13 -07:00
|
|
|
this.push([], {
|
2013-02-20 15:33:36 -08:00
|
|
|
index: -1, /* specifies on which position should the item be appended */
|
2013-03-09 21:05:09 -08:00
|
|
|
relaxed: true, /* this container should allow dupes & degenerates */
|
2012-10-26 10:10:17 -07:00
|
|
|
attachment: {
|
2013-09-13 06:23:13 -07:00
|
|
|
sourceResults: aSourceResults
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customization function for creating an item's UI.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aElementNode
|
|
|
|
* The element associated with the displayed item.
|
2013-02-20 15:33:36 -08:00
|
|
|
* @param any aAttachment
|
|
|
|
* Some attached primitive/object.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
_createItemView: function(aElementNode, aAttachment) {
|
|
|
|
aAttachment.sourceResults.createView(aElementNode, {
|
2012-10-26 10:10:17 -07:00
|
|
|
onHeaderClick: this._onHeaderClick,
|
|
|
|
onLineClick: this._onLineClick,
|
|
|
|
onMatchClick: this._onMatchClick
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The click listener for a results header.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onHeaderClick: function(e) {
|
2012-10-26 10:10:17 -07:00
|
|
|
let sourceResultsItem = SourceResults.getItemForElement(e.target);
|
|
|
|
sourceResultsItem.instance.toggle(e);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The click listener for a results line.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onLineClick: function(e) {
|
2012-10-26 10:10:17 -07:00
|
|
|
let lineResultsItem = LineResults.getItemForElement(e.target);
|
|
|
|
this._onMatchClick({ target: lineResultsItem.firstMatch });
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The click listener for a result match.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onMatchClick: function(e) {
|
2012-10-26 10:10:17 -07:00
|
|
|
if (e instanceof Event) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
2013-09-13 06:23:13 -07:00
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
let target = e.target;
|
|
|
|
let sourceResultsItem = SourceResults.getItemForElement(target);
|
|
|
|
let lineResultsItem = LineResults.getItemForElement(target);
|
|
|
|
|
2012-11-15 22:34:13 -08:00
|
|
|
sourceResultsItem.instance.expand();
|
2012-10-26 10:10:17 -07:00
|
|
|
this._currentlyFocusedMatch = LineResults.indexOfElement(target);
|
|
|
|
this._scrollMatchIntoViewIfNeeded(target);
|
|
|
|
this._bounceMatch(target);
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
let url = sourceResultsItem.instance.url;
|
|
|
|
let line = lineResultsItem.instance.line;
|
|
|
|
DebuggerView.setEditorLocation(url, line + 1, { noDebug: true });
|
2012-10-26 10:10:17 -07:00
|
|
|
|
|
|
|
let editor = DebuggerView.editor;
|
|
|
|
let offset = editor.getCaretOffset();
|
|
|
|
let { start, length } = lineResultsItem.lineData.range;
|
|
|
|
editor.setSelection(offset + start, offset + start + length);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Scrolls a match into view if not already visible.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
|
|
|
* @param nsIDOMNode aMatch
|
|
|
|
* The match to scroll into view.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_scrollMatchIntoViewIfNeeded: function(aMatch) {
|
2013-06-21 07:33:56 -07:00
|
|
|
// TODO: Accessing private widget properties. Figure out what's the best
|
|
|
|
// way to expose such things. Bug 876271.
|
2013-06-21 07:33:56 -07:00
|
|
|
let boxObject = this.widget._parent.boxObject.QueryInterface(Ci.nsIScrollBoxObject);
|
2013-02-20 15:33:36 -08:00
|
|
|
boxObject.ensureElementIsVisible(aMatch);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts a bounce animation for a match.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aMatch
|
|
|
|
* The match to start a bounce animation for.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_bounceMatch: function(aMatch) {
|
2013-09-13 06:23:13 -07:00
|
|
|
Services.tm.currentThread.dispatch({ run: () => {
|
2012-10-26 10:10:17 -07:00
|
|
|
aMatch.addEventListener("transitionend", function onEvent() {
|
|
|
|
aMatch.removeEventListener("transitionend", onEvent);
|
|
|
|
aMatch.removeAttribute("focused");
|
|
|
|
});
|
2013-01-03 23:37:18 -08:00
|
|
|
aMatch.setAttribute("focused", "");
|
2012-10-26 10:10:17 -07:00
|
|
|
}}, 0);
|
2013-02-20 15:33:36 -08:00
|
|
|
aMatch.setAttribute("focusing", "");
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_splitter: null,
|
|
|
|
_currentlyFocusedMatch: -1,
|
2013-09-13 06:23:13 -07:00
|
|
|
_forceExpandResults: false
|
2012-10-26 10:10:17 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object containing all source results, grouped by source location.
|
|
|
|
* Iterable via "for (let [location, sourceResults] in globalResults) { }".
|
|
|
|
*/
|
|
|
|
function GlobalResults() {
|
2013-09-13 06:23:13 -07:00
|
|
|
this._store = [];
|
2012-10-26 10:10:17 -07:00
|
|
|
SourceResults._itemsByElement = new Map();
|
|
|
|
LineResults._itemsByElement = new Map();
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalResults.prototype = {
|
|
|
|
/**
|
|
|
|
* Adds source results to this store.
|
|
|
|
*
|
|
|
|
* @param SourceResults aSourceResults
|
2013-09-13 06:23:13 -07:00
|
|
|
* An object containing search results for a specific source.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
add: function(aSourceResults) {
|
|
|
|
this._store.push(aSourceResults);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the number of source results in this store.
|
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
get matchCount() this._store.length
|
2012-10-26 10:10:17 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object containing all the matched lines for a specific source.
|
|
|
|
* Iterable via "for (let [lineNumber, lineResults] in sourceResults) { }".
|
2013-09-13 06:23:13 -07:00
|
|
|
*
|
|
|
|
* @param string aUrl
|
|
|
|
* The target source url.
|
|
|
|
* @param GlobalResults aGlobalResults
|
|
|
|
* An object containing all source results, grouped by source location.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
function SourceResults(aUrl, aGlobalResults) {
|
|
|
|
this.url = aUrl;
|
|
|
|
this._globalResults = aGlobalResults;
|
|
|
|
this._store = [];
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceResults.prototype = {
|
|
|
|
/**
|
|
|
|
* Adds line results to this store.
|
|
|
|
*
|
|
|
|
* @param LineResults aLineResults
|
2013-09-13 06:23:13 -07:00
|
|
|
* An object containing search results for a specific line.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
add: function(aLineResults) {
|
|
|
|
this._store.push(aLineResults);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-09-13 06:23:13 -07:00
|
|
|
* Gets the number of line results in this store.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
get matchCount() this._store.length,
|
2012-10-26 10:10:17 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Expands the element, showing all the added details.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
expand: function() {
|
2013-09-13 06:23:13 -07:00
|
|
|
this._resultsContainer.removeAttribute("hidden");
|
|
|
|
this._arrow.setAttribute("open", "");
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Collapses the element, hiding all the added details.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
collapse: function() {
|
2013-09-13 06:23:13 -07:00
|
|
|
this._resultsContainer.setAttribute("hidden", "true");
|
|
|
|
this._arrow.removeAttribute("open");
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles between the element collapse/expand state.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
toggle: function(e) {
|
2012-10-26 10:10:17 -07:00
|
|
|
this.expanded ^= 1;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets this element's expanded state.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2013-02-20 15:33:36 -08:00
|
|
|
get expanded()
|
2013-09-13 06:23:13 -07:00
|
|
|
this._resultsContainer.getAttribute("hidden") != "true" &&
|
|
|
|
this._arrow.hasAttribute("open"),
|
2012-10-26 10:10:17 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets this element's expanded state.
|
|
|
|
* @param boolean aFlag
|
|
|
|
*/
|
|
|
|
set expanded(aFlag) this[aFlag ? "expand" : "collapse"](),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the element associated with this item.
|
|
|
|
* @return nsIDOMNode
|
|
|
|
*/
|
|
|
|
get target() this._target,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customization function for creating this item's UI.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aElementNode
|
|
|
|
* The element associated with the displayed item.
|
|
|
|
* @param object aCallbacks
|
|
|
|
* An object containing all the necessary callback functions:
|
|
|
|
* - onHeaderClick
|
|
|
|
* - onMatchClick
|
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
createView: function(aElementNode, aCallbacks) {
|
2012-10-26 10:10:17 -07:00
|
|
|
this._target = aElementNode;
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
let arrow = this._arrow = document.createElement("box");
|
2012-10-26 10:10:17 -07:00
|
|
|
arrow.className = "arrow";
|
|
|
|
|
|
|
|
let locationNode = document.createElement("label");
|
2013-02-20 15:33:36 -08:00
|
|
|
locationNode.className = "plain dbg-results-header-location";
|
2013-09-13 06:23:13 -07:00
|
|
|
locationNode.setAttribute("value", this.url);
|
2012-10-26 10:10:17 -07:00
|
|
|
|
|
|
|
let matchCountNode = document.createElement("label");
|
2013-02-20 15:33:36 -08:00
|
|
|
matchCountNode.className = "plain dbg-results-header-match-count";
|
2013-09-13 06:23:13 -07:00
|
|
|
matchCountNode.setAttribute("value", "(" + this.matchCount + ")");
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
let resultsHeader = this._resultsHeader = document.createElement("hbox");
|
2012-10-26 10:10:17 -07:00
|
|
|
resultsHeader.className = "dbg-results-header";
|
|
|
|
resultsHeader.setAttribute("align", "center")
|
|
|
|
resultsHeader.appendChild(arrow);
|
|
|
|
resultsHeader.appendChild(locationNode);
|
|
|
|
resultsHeader.appendChild(matchCountNode);
|
|
|
|
resultsHeader.addEventListener("click", aCallbacks.onHeaderClick, false);
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
let resultsContainer = this._resultsContainer = document.createElement("vbox");
|
2012-10-26 10:10:17 -07:00
|
|
|
resultsContainer.className = "dbg-results-container";
|
2013-02-20 15:33:36 -08:00
|
|
|
resultsContainer.setAttribute("hidden", "true");
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// Create lines search results entries and add them to this container.
|
|
|
|
// Afterwards, if the number of matches is reasonable, expand this
|
|
|
|
// container automatically.
|
|
|
|
for (let lineResults of this._store) {
|
|
|
|
lineResults.createView(resultsContainer, aCallbacks);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
2013-09-13 06:23:13 -07:00
|
|
|
if (this.matchCount < GLOBAL_SEARCH_EXPAND_MAX_RESULTS) {
|
2012-11-15 22:34:13 -08:00
|
|
|
this.expand();
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
let resultsBox = document.createElement("vbox");
|
|
|
|
resultsBox.setAttribute("flex", "1");
|
|
|
|
resultsBox.appendChild(resultsHeader);
|
|
|
|
resultsBox.appendChild(resultsContainer);
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
aElementNode.id = "source-results-" + this.url;
|
2012-10-26 10:10:17 -07:00
|
|
|
aElementNode.className = "dbg-source-results";
|
|
|
|
aElementNode.appendChild(resultsBox);
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
SourceResults._itemsByElement.set(aElementNode, { instance: this });
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
url: "",
|
|
|
|
_globalResults: null,
|
2012-10-26 10:10:17 -07:00
|
|
|
_store: null,
|
|
|
|
_target: null,
|
2013-09-13 06:23:13 -07:00
|
|
|
_arrow: null,
|
|
|
|
_resultsHeader: null,
|
|
|
|
_resultsContainer: null
|
2012-10-26 10:10:17 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object containing all the matches for a specific line.
|
|
|
|
* Iterable via "for (let chunk in lineResults) { }".
|
2013-09-13 06:23:13 -07:00
|
|
|
*
|
|
|
|
* @param number aLine
|
|
|
|
* The target line in the source.
|
|
|
|
* @param SourceResults aSourceResults
|
|
|
|
* An object containing all the matched lines for a specific source.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
function LineResults(aLine, aSourceResults) {
|
|
|
|
this.line = aLine;
|
|
|
|
this._sourceResults = aSourceResults;
|
2012-10-26 10:10:17 -07:00
|
|
|
this._store = [];
|
2013-09-13 06:23:13 -07:00
|
|
|
this._matchCount = 0;
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
LineResults.prototype = {
|
|
|
|
/**
|
|
|
|
* Adds string details to this store.
|
|
|
|
*
|
|
|
|
* @param string aString
|
|
|
|
* The text contents chunk in the line.
|
|
|
|
* @param object aRange
|
|
|
|
* An object containing the { start, length } of the chunk.
|
|
|
|
* @param boolean aMatchFlag
|
|
|
|
* True if the chunk is a matched string, false if just text content.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
add: function(aString, aRange, aMatchFlag) {
|
2013-09-13 06:23:13 -07:00
|
|
|
this._store.push({ string: aString, range: aRange, match: !!aMatchFlag });
|
|
|
|
this._matchCount += aMatchFlag ? 1 : 0;
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
/**
|
|
|
|
* Gets the number of word results in this store.
|
|
|
|
*/
|
|
|
|
get matchCount() this._matchCount,
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
/**
|
|
|
|
* Gets the element associated with this item.
|
|
|
|
* @return nsIDOMNode
|
|
|
|
*/
|
|
|
|
get target() this._target,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customization function for creating this item's UI.
|
|
|
|
*
|
2013-09-13 06:23:13 -07:00
|
|
|
* @param nsIDOMNode aElementNode
|
2012-10-26 10:10:17 -07:00
|
|
|
* The element associated with the displayed item.
|
|
|
|
* @param object aCallbacks
|
|
|
|
* An object containing all the necessary callback functions:
|
|
|
|
* - onMatchClick
|
|
|
|
* - onLineClick
|
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
createView: function(aElementNode, aCallbacks) {
|
|
|
|
this._target = aElementNode;
|
2012-10-26 10:10:17 -07:00
|
|
|
|
|
|
|
let lineNumberNode = document.createElement("label");
|
2013-09-13 06:23:13 -07:00
|
|
|
lineNumberNode.className = "plain dbg-results-line-number";
|
|
|
|
lineNumberNode.classList.add("devtools-monospace");
|
|
|
|
lineNumberNode.setAttribute("value", this.line + 1);
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
let lineContentsNode = document.createElement("hbox");
|
2013-09-13 06:23:13 -07:00
|
|
|
lineContentsNode.className = "light list-widget-item dbg-results-line-contents";
|
|
|
|
lineContentsNode.classList.add("devtools-monospace");
|
|
|
|
lineContentsNode.setAttribute("flex", "1");
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
let lineString = "";
|
|
|
|
let lineLength = 0;
|
|
|
|
let firstMatch = null;
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
for (let lineChunk of this._store) {
|
|
|
|
let { string, range, match } = lineChunk;
|
2012-10-26 10:10:17 -07:00
|
|
|
lineString = string.substr(0, GLOBAL_SEARCH_LINE_MAX_LENGTH - lineLength);
|
|
|
|
lineLength += string.length;
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
let lineChunkNode = document.createElement("label");
|
|
|
|
lineChunkNode.className = "plain dbg-results-line-contents-string";
|
|
|
|
lineChunkNode.setAttribute("value", lineString);
|
|
|
|
lineChunkNode.setAttribute("match", match);
|
|
|
|
lineContentsNode.appendChild(lineChunkNode);
|
2012-10-26 10:10:17 -07:00
|
|
|
|
|
|
|
if (match) {
|
2013-09-13 06:23:13 -07:00
|
|
|
this._entangleMatch(lineChunkNode, lineChunk);
|
|
|
|
lineChunkNode.addEventListener("click", aCallbacks.onMatchClick, false);
|
|
|
|
firstMatch = firstMatch || lineChunkNode;
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
if (lineLength >= GLOBAL_SEARCH_LINE_MAX_LENGTH) {
|
|
|
|
lineContentsNode.appendChild(this._ellipsis.cloneNode());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._entangleLine(lineContentsNode, firstMatch);
|
|
|
|
lineContentsNode.addEventListener("click", aCallbacks.onLineClick, false);
|
|
|
|
|
|
|
|
let searchResult = document.createElement("hbox");
|
|
|
|
searchResult.className = "dbg-search-result";
|
|
|
|
searchResult.appendChild(lineNumberNode);
|
|
|
|
searchResult.appendChild(lineContentsNode);
|
2013-09-13 06:23:13 -07:00
|
|
|
|
|
|
|
aElementNode.appendChild(searchResult);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles a match while creating the view.
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
* @param object aMatchChunk
|
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
_entangleMatch: function(aNode, aMatchChunk) {
|
2012-10-26 10:10:17 -07:00
|
|
|
LineResults._itemsByElement.set(aNode, {
|
2013-09-13 06:23:13 -07:00
|
|
|
instance: this,
|
2012-10-26 10:10:17 -07:00
|
|
|
lineData: aMatchChunk
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles a line while creating the view.
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
* @param nsIDOMNode aFirstMatch
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_entangleLine: function(aNode, aFirstMatch) {
|
2012-10-26 10:10:17 -07:00
|
|
|
LineResults._itemsByElement.set(aNode, {
|
2013-09-13 06:23:13 -07:00
|
|
|
instance: this,
|
2012-10-26 10:10:17 -07:00
|
|
|
firstMatch: aFirstMatch,
|
2013-09-13 06:23:13 -07:00
|
|
|
ignored: true
|
2012-10-26 10:10:17 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An nsIDOMNode label with an ellipsis value.
|
|
|
|
*/
|
|
|
|
_ellipsis: (function() {
|
|
|
|
let label = document.createElement("label");
|
2013-02-20 15:33:36 -08:00
|
|
|
label.className = "plain dbg-results-line-contents-string";
|
2012-10-26 10:10:17 -07:00
|
|
|
label.setAttribute("value", L10N.ellipsis);
|
|
|
|
return label;
|
|
|
|
})(),
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
line: 0,
|
|
|
|
_sourceResults: null,
|
2012-10-26 10:10:17 -07:00
|
|
|
_store: null,
|
|
|
|
_target: null
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A generator-iterator over the global, source or line results.
|
|
|
|
*/
|
|
|
|
GlobalResults.prototype.__iterator__ =
|
|
|
|
SourceResults.prototype.__iterator__ =
|
2013-05-13 00:01:00 -07:00
|
|
|
LineResults.prototype.__iterator__ = function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
for (let item of this._store) {
|
|
|
|
yield item;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the item associated with the specified element.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aElement
|
|
|
|
* The element used to identify the item.
|
|
|
|
* @return object
|
|
|
|
* The matched item, or null if nothing is found.
|
|
|
|
*/
|
|
|
|
SourceResults.getItemForElement =
|
2013-05-13 00:01:00 -07:00
|
|
|
LineResults.getItemForElement = function(aElement) {
|
2013-09-13 06:23:15 -07:00
|
|
|
return WidgetMethods.getItemForElement.call(this, aElement, { noSiblings: true });
|
2012-10-26 10:10:17 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the element associated with a particular item at a specified index.
|
|
|
|
*
|
|
|
|
* @param number aIndex
|
|
|
|
* The index used to identify the item.
|
|
|
|
* @return nsIDOMNode
|
|
|
|
* The matched element, or null if nothing is found.
|
|
|
|
*/
|
|
|
|
SourceResults.getElementAtIndex =
|
2013-05-13 00:01:00 -07:00
|
|
|
LineResults.getElementAtIndex = function(aIndex) {
|
2012-10-26 10:10:17 -07:00
|
|
|
for (let [element, item] of this._itemsByElement) {
|
2013-09-13 06:23:13 -07:00
|
|
|
if (!item.ignored && !aIndex--) {
|
2012-10-26 10:10:17 -07:00
|
|
|
return element;
|
|
|
|
}
|
|
|
|
}
|
2013-02-20 15:33:36 -08:00
|
|
|
return null;
|
2012-10-26 10:10:17 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the index of an item associated with the specified element.
|
|
|
|
*
|
2013-03-09 21:05:09 -08:00
|
|
|
* @param nsIDOMNode aElement
|
|
|
|
* The element to get the index for.
|
2012-10-26 10:10:17 -07:00
|
|
|
* @return number
|
2013-03-09 21:05:09 -08:00
|
|
|
* The index of the matched element, or -1 if nothing is found.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
|
|
|
SourceResults.indexOfElement =
|
2013-05-13 00:01:00 -07:00
|
|
|
LineResults.indexOfElement = function(aElement) {
|
2012-10-26 10:10:17 -07:00
|
|
|
let count = 0;
|
|
|
|
for (let [element, item] of this._itemsByElement) {
|
|
|
|
if (element == aElement) {
|
|
|
|
return count;
|
|
|
|
}
|
2013-09-13 06:23:13 -07:00
|
|
|
if (!item.ignored) {
|
2012-10-26 10:10:17 -07:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the number of cached items associated with a specified element.
|
|
|
|
*
|
|
|
|
* @return number
|
|
|
|
* The number of key/value pairs in the corresponding map.
|
|
|
|
*/
|
|
|
|
SourceResults.size =
|
2013-05-13 00:01:00 -07:00
|
|
|
LineResults.size = function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
let count = 0;
|
2012-11-15 22:34:13 -08:00
|
|
|
for (let [, item] of this._itemsByElement) {
|
2013-09-13 06:23:13 -07:00
|
|
|
if (!item.ignored) {
|
2012-10-26 10:10:17 -07:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Preliminary setup for the DebuggerView object.
|
|
|
|
*/
|
2013-02-20 15:33:36 -08:00
|
|
|
DebuggerView.Sources = new SourcesView();
|
2012-11-17 11:41:04 -08:00
|
|
|
DebuggerView.WatchExpressions = new WatchExpressionsView();
|
2013-10-04 00:33:08 -07:00
|
|
|
DebuggerView.EventListeners = new EventListenersView();
|
2012-10-26 10:10:17 -07:00
|
|
|
DebuggerView.GlobalSearch = new GlobalSearchView();
|