diff options
Diffstat (limited to 'WebCore/inspector/front-end/BreakpointManager.js')
-rw-r--r-- | WebCore/inspector/front-end/BreakpointManager.js | 174 |
1 files changed, 116 insertions, 58 deletions
diff --git a/WebCore/inspector/front-end/BreakpointManager.js b/WebCore/inspector/front-end/BreakpointManager.js index 77ba89d..221a777 100644 --- a/WebCore/inspector/front-end/BreakpointManager.js +++ b/WebCore/inspector/front-end/BreakpointManager.js @@ -28,7 +28,6 @@ WebInspector.BreakpointManager = function() { this._breakpoints = {}; this._nativeBreakpoints = {}; - this._domBreakpoints = {}; } WebInspector.BreakpointManager.prototype = { @@ -137,13 +136,12 @@ WebInspector.BreakpointManager.prototype = { var breakpoint = new WebInspector.DOMBreakpoint(this, frontendId, nodeId, domEventType); this._nativeBreakpoints[frontendId] = breakpoint; - this._domBreakpoints[frontendId] = breakpoint; this.dispatchEventToListeners("dom-breakpoint-added", breakpoint); breakpoint.enabled = !disabled; return breakpoint; }, - createEventListenerBreakpoint: function(eventName, disabled) + createEventListenerBreakpoint: function(eventName) { var frontendId = eventName; if (frontendId in this._nativeBreakpoints) @@ -151,7 +149,8 @@ WebInspector.BreakpointManager.prototype = { var breakpoint = new WebInspector.EventListenerBreakpoint(this, frontendId, eventName); this._nativeBreakpoints[frontendId] = breakpoint; - breakpoint.enabled = !disabled; + this.dispatchEventToListeners("event-listener-breakpoint-added", { breakpoint: breakpoint, eventName: eventName }); + breakpoint.enabled = true; return breakpoint; }, @@ -175,8 +174,7 @@ WebInspector.BreakpointManager.prototype = { if (breakpoint.enabled) this._removeNativeBreakpointFromBackend(breakpoint); delete this._nativeBreakpoints[breakpoint._frontendId]; - if (breakpoint._type === "DOM") - delete this._domBreakpoints[breakpoint._frontendId]; + this._updateNativeBreakpointsInSettings(); breakpoint.dispatchEventToListeners("removed"); }, @@ -195,7 +193,7 @@ WebInspector.BreakpointManager.prototype = { _setNativeBreakpointOnBackend: function(breakpoint) { breakpoint._beingSetOnBackend = true; - var data = { type: breakpoint._type, condition: breakpoint._condition() }; + var data = { type: breakpoint._type, condition: breakpoint._condition }; InspectorBackend.setNativeBreakpoint(data, didSetNativeBreakpoint.bind(this)); function didSetNativeBreakpoint(backendBreakpointId) @@ -206,6 +204,7 @@ WebInspector.BreakpointManager.prototype = { this._breakpoints[backendBreakpointId] = breakpoint; } breakpoint.dispatchEventToListeners("enable-changed"); + this._updateNativeBreakpointsInSettings(); } }, @@ -215,6 +214,18 @@ WebInspector.BreakpointManager.prototype = { delete this._breakpoints[breakpoint._backendId] delete breakpoint._backendId; breakpoint.dispatchEventToListeners("enable-changed"); + this._updateNativeBreakpointsInSettings(); + }, + + _updateNativeBreakpointsInSettings: function() + { + var persistentBreakpoints = []; + for (var id in this._nativeBreakpoints) { + var breakpoint = this._nativeBreakpoints[id]; + if (breakpoint._persistentCondition) + persistentBreakpoints.push({ type: breakpoint._type, enabled: breakpoint.enabled, condition: breakpoint._persistentCondition }); + } + WebInspector.settings.nativeBreakpoints = persistentBreakpoints; }, debuggerPaused: function(details) @@ -242,31 +253,60 @@ WebInspector.BreakpointManager.prototype = { delete this._lastHitBreakpoint; }, + restoreBreakpoints: function() + { + var breakpoints = this._persistentBreakpoints(); + for (var i = 0; i < breakpoints.length; ++i) { + if (breakpoints[i].type === "EventListener") + this.createEventListenerBreakpoint(breakpoints[i].condition.eventName); + else if (breakpoints[i].type === "XHR") + this.createXHRBreakpoint(breakpoints[i].condition.url, !breakpoints[i].enabled); + } + }, + restoreDOMBreakpoints: function() { - var domBreakpoints = this._domBreakpoints; - this._domBreakpoints = {}; + function didPushNodeByPathToFrontend(path, nodeId) + { + pathToNodeId[path] = nodeId; + pendingCalls -= 1; + if (pendingCalls) + return; + for (var i = 0; i < breakpoints.length; ++i) { + var breakpoint = breakpoints[i]; + var nodeId = pathToNodeId[breakpoint.condition.path]; + if (nodeId) + this.createDOMBreakpoint(nodeId, breakpoint.condition.type, !breakpoint.enabled); + } + } - var breakpointsToRestore = {}; - for (var frontendId in domBreakpoints) { - var breakpoint = domBreakpoints[frontendId]; - var path = breakpoint._path; - if (!path) + var breakpoints = this._persistentBreakpoints(); + var pathToNodeId = {}; + var pendingCalls = 0; + for (var i = 0; i < breakpoints.length; ++i) { + if (breakpoints[i].type !== "DOM") continue; - if (!breakpointsToRestore[path]) { - breakpointsToRestore[path] = []; - InspectorBackend.pushNodeByPathToFrontend(path, restoreBreakpointsForNode.bind(this, breakpointsToRestore[path])); - } - breakpointsToRestore[path].push(breakpoint); + var path = breakpoints[i].condition.path; + if (path in pathToNodeId) + continue; + pathToNodeId[path] = 0; + pendingCalls += 1; + InspectorBackend.pushNodeByPathToFrontend(path, didPushNodeByPathToFrontend.bind(this, path)); } + }, - function restoreBreakpointsForNode(breakpoints, nodeId) - { - if (!nodeId) - return; - for (var i = 0; i < breakpoints.length; ++i) - this.createDOMBreakpoint(nodeId, breakpoints[i]._domEventType, !breakpoints[i].enabled); + _persistentBreakpoints: function() + { + var result = []; + var breakpoints = WebInspector.settings.nativeBreakpoints; + if (breakpoints instanceof Array) { + for (var i = 0; i < breakpoints.length; ++i) { + var breakpoint = breakpoints[i]; + if ("type" in breakpoint && "condition" in breakpoint) + result.push(breakpoint) + } } + return result; } } @@ -307,7 +347,7 @@ WebInspector.Breakpoint.prototype = { set sourceText(text) { this._sourceText = text; - this.dispatchEventToListeners("text-changed"); + this.dispatchEventToListeners("label-changed"); }, get id() @@ -332,6 +372,11 @@ WebInspector.Breakpoint.prototype = { this.dispatchEventToListeners("condition-changed"); }, + click: function(event) + { + WebInspector.panels.scripts.showSourceLine(this.url, this.line); + }, + compareTo: function(other) { if (this.url != other.url) @@ -341,6 +386,18 @@ WebInspector.Breakpoint.prototype = { return 0; }, + populateLabelElement: function(element) + { + var displayName = this.url ? WebInspector.displayNameForURL(this.url) : WebInspector.UIString("(program)"); + var labelElement = document.createTextNode(displayName + ":" + this.line); + element.appendChild(labelElement); + + var sourceTextElement = document.createElement("div"); + sourceTextElement.textContent = this.sourceText; + sourceTextElement.className = "source-text monospace"; + element.appendChild(sourceTextElement); + }, + remove: function() { InspectorBackend.removeBreakpoint(this.sourceID, this.line); @@ -405,20 +462,16 @@ WebInspector.DOMBreakpoint = function(manager, frontendId, nodeId, domEventType) WebInspector.NativeBreakpoint.call(this, manager, frontendId, "DOM"); this._nodeId = nodeId; this._domEventType = domEventType; + this._condition = { nodeId: this._nodeId, type: this._domEventType }; var node = WebInspector.domAgent.nodeForId(this._nodeId); if (node) { node.breakpoints[this._domEventType] = this; - this._path = node.path(); + this._persistentCondition = { path: node.path(), type: this._domEventType }; } } WebInspector.DOMBreakpoint.prototype = { - click: function() - { - WebInspector.updateFocusedNode(this._nodeId); - }, - compareTo: function(other) { return this._compare(this._domEventType, other._domEventType); @@ -426,9 +479,14 @@ WebInspector.DOMBreakpoint.prototype = { populateLabelElement: function(element) { - element.appendChild(WebInspector.panels.elements.linkifyNodeById(this._nodeId)); - element.appendChild(document.createTextNode(" - ")); - element.appendChild(document.createTextNode(WebInspector.domBreakpointTypeLabel(this._domEventType))); + // FIXME: this should belong to the view, not the manager. + var linkifiedNode = WebInspector.panels.elements.linkifyNodeById(this._nodeId); + linkifiedNode.addStyleClass("monospace"); + element.appendChild(linkifiedNode); + var description = document.createElement("div"); + description.className = "source-text"; + description.textContent = WebInspector.domBreakpointTypeLabel(this._domEventType); + element.appendChild(description); }, populateStatusMessageElement: function(element, eventData) @@ -459,11 +517,6 @@ WebInspector.DOMBreakpoint.prototype = { WebInspector.formatLocalized("Paused on a \"%s\" breakpoint set on %s.", substitutions, formatters, "", append); }, - _condition: function() - { - return { nodeId: this._nodeId, type: this._domEventType }; - }, - _onRemove: function() { var node = WebInspector.domAgent.nodeForId(this._nodeId); @@ -478,6 +531,20 @@ WebInspector.EventListenerBreakpoint = function(manager, frontendId, eventName) { WebInspector.NativeBreakpoint.call(this, manager, frontendId, "EventListener"); this._eventName = eventName; + this._condition = { eventName: this._eventName }; + this._persistentCondition = this._condition; +} + +WebInspector.EventListenerBreakpoint.eventNameForUI = function(eventName) +{ + if (!WebInspector.EventListenerBreakpoint._eventNamesForUI) { + WebInspector.EventListenerBreakpoint._eventNamesForUI = { + "instrumentation:setTimer": WebInspector.UIString("Set Timer"), + "instrumentation:clearTimer": WebInspector.UIString("Clear Timer"), + "instrumentation:timerFired": WebInspector.UIString("Timer Fired") + }; + } + return WebInspector.EventListenerBreakpoint._eventNamesForUI[eventName] || eventName.substring(eventName.indexOf(":") + 1); } WebInspector.EventListenerBreakpoint.prototype = { @@ -497,21 +564,9 @@ WebInspector.EventListenerBreakpoint.prototype = { element.appendChild(document.createTextNode(status)); }, - _condition: function() - { - return { eventName: this._eventName }; - }, - _uiEventName: function() { - if (!WebInspector.EventListenerBreakpoint._uiEventNames) { - WebInspector.EventListenerBreakpoint._uiEventNames = { - "instrumentation:setTimer": WebInspector.UIString("Set Timer"), - "instrumentation:clearTimer": WebInspector.UIString("Clear Timer"), - "instrumentation:timerFired": WebInspector.UIString("Timer Fired") - }; - } - return WebInspector.EventListenerBreakpoint._uiEventNames[this._eventName] || this._eventName.substring(this._eventName.indexOf(":") + 1); + return WebInspector.EventListenerBreakpoint.eventNameForUI(this._eventName); } } @@ -521,6 +576,8 @@ WebInspector.XHRBreakpoint = function(manager, frontendId, url) { WebInspector.NativeBreakpoint.call(this, manager, frontendId, "XHR"); this._url = url; + this._condition = { url: this._url }; + this._persistentCondition = this._condition; } WebInspector.XHRBreakpoint.prototype = { @@ -529,6 +586,11 @@ WebInspector.XHRBreakpoint.prototype = { return this._compare(this._url, other._url); }, + populateEditElement: function(element) + { + element.textContent = this._url; + }, + populateLabelElement: function(element) { var label; @@ -537,17 +599,13 @@ WebInspector.XHRBreakpoint.prototype = { else label = WebInspector.UIString("URL contains \"%s\"", this._url); element.appendChild(document.createTextNode(label)); + element.addStyleClass("cursor-auto"); }, populateStatusMessageElement: function(element) { var status = WebInspector.UIString("Paused on a XMLHttpRequest."); element.appendChild(document.createTextNode(status)); - }, - - _condition: function() - { - return { url: this._url }; } } |