Web Inspector: allow breakpoints to be set for specific event listeners
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Aug 2018 02:15:28 +0000 (02:15 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Aug 2018 02:15:28 +0000 (02:15 +0000)
commit11bcf78a66c96cefa3d3cafb38e1247fb0e775cc
tree935eae3c8942d980d9394c3b2c765c6898442179
parent048cf73b30bee777a3be6c5cfbfb438f0666d177
Web Inspector: allow breakpoints to be set for specific event listeners
https://bugs.webkit.org/show_bug.cgi?id=183138

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

* inspector/protocol/DOM.json:
Add `setBreakpointForEventListener` and `removeBreakpointForEventListener`, each of which
takes an `eventListenerId` and toggles whether that specific usage of that event listener
should have a breakpoint and pause before running.

Source/WebCore:

Test: inspector/dom/breakpoint-for-event-listener.html

* inspector/agents/InspectorDOMAgent.h:
* inspector/agents/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::getEventListenersForNode):
(WebCore::InspectorDOMAgent::setEventListenerDisabled):
(WebCore::InspectorDOMAgent::setBreakpointForEventListener): Added.
(WebCore::InspectorDOMAgent::removeBreakpointForEventListener): Added.
(WebCore::InspectorDOMAgent::buildObjectForEventListener):
(WebCore::InspectorDOMAgent::willRemoveEventListener):
(WebCore::InspectorDOMAgent::isEventListenerDisabled):
(WebCore::InspectorDOMAgent::hasBreakpointForEventListener): Added.
(WebCore::InspectorDOMAgent::idForEventListener): Added.
Rework the event listener data structure to be based on ID instead of `EventListener`, since
it is possible to have the same `EventListener` be used for multiple events.

* inspector/agents/InspectorDOMDebuggerAgent.h:
* inspector/agents/InspectorDOMDebuggerAgent.cpp:
(WebCore::InspectorDOMDebuggerAgent::setEventListenerBreakpoint):
(WebCore::InspectorDOMDebuggerAgent::setInstrumentationBreakpoint):
(WebCore::InspectorDOMDebuggerAgent::removeEventListenerBreakpoint):
(WebCore::InspectorDOMDebuggerAgent::removeInstrumentationBreakpoint):
(WebCore::InspectorDOMDebuggerAgent::willHandleEvent): Added.
(WebCore::InspectorDOMDebuggerAgent::pauseOnNativeEventIfNeeded):
For DOM events, also check to see if there is a matching event listener specific breakpoint
set via the DOMAgent, and break on it if one is found.

* inspector/InspectorInstrumentation.h:
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::didInstallTimerImpl):
(WebCore::InspectorInstrumentation::didRemoveTimerImpl):
(WebCore::InspectorInstrumentation::willHandleEventImpl):
(WebCore::InspectorInstrumentation::willFireTimerImpl):
(WebCore::InspectorInstrumentation::pauseOnNativeEventIfNeeded):
(WebCore::InspectorInstrumentation::didRequestAnimationFrameImpl):
(WebCore::InspectorInstrumentation::didCancelAnimationFrameImpl):
(WebCore::InspectorInstrumentation::willFireAnimationFrameImpl):
Split off `pauseOnNativeEventIfNeeded` to only handle non-DOM events, since all DOM events
would already only go through `willHandleEvent`.

Source/WebInspectorUI:

* Localizations/en.lproj/localizedStrings.js:

* UserInterface/Models/EventBreakpoint.js:
(WI.EventBreakpoint):
(WI.EventBreakpoint.fromPayload): Added.
(WI.EventBreakpoint.prototype.get eventListener): Added.

* UserInterface/Controllers/DOMDebuggerManager.js:
(WI.DOMDebuggerManager):

* UserInterface/Controllers/DOMTreeManager.js:
(WI.DOMTreeManager):
(WI.DOMTreeManager.prototype.get eventBreakpoints): Added.
(WI.DOMTreeManager.prototype._setDocument):
(WI.DOMTreeManager.prototype.setEventListenerDisabled):
(WI.DOMTreeManager.prototype.setBreakpointForEventListener): Added.
(WI.DOMTreeManager.prototype.removeBreakpointForEventListener): Added.
(WI.DOMTreeManager.prototype.breakpointForEventListenerId): Added.

* UserInterface/Controllers/EventBreakpointTreeController.js:
(WI.EventBreakpointTreeController):

* UserInterface/Views/DebuggerSidebarPanel.js:
(WI.DebuggerSidebarPanel.prototype._updatePauseReasonSection):

* UserInterface/Views/EventListenerSectionGroup.js:
(WI.EventListenerSectionGroup):
(WI.EventListenerSectionGroup.prototype._createDisabledToggleRow):
(WI.EventListenerSectionGroup.prototype._createBreakpointToggleRow): Added.

* UserInterface/Views/EventBreakpointTreeElement.js:
(WI.EventBreakpointTreeElement):
(WI.EventBreakpointTreeElement.prototype.ondelete):
(WI.EventBreakpointTreeElement.prototype.populateContextMenu):
(WI.EventBreakpointTreeElement.prototype._toggleBreakpoint):

LayoutTests:

* inspector/dom/breakpoint-for-event-listener-expected.txt: Added.
* inspector/dom/breakpoint-for-event-listener.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235103 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/dom/breakpoint-for-event-listener-expected.txt [new file with mode: 0644]
LayoutTests/inspector/dom/breakpoint-for-event-listener.html [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/protocol/DOM.json
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/agents/InspectorDOMAgent.cpp
Source/WebCore/inspector/agents/InspectorDOMAgent.h
Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp
Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.h
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
Source/WebInspectorUI/UserInterface/Controllers/DOMDebuggerManager.js
Source/WebInspectorUI/UserInterface/Controllers/DOMTreeManager.js
Source/WebInspectorUI/UserInterface/Controllers/EventBreakpointTreeController.js
Source/WebInspectorUI/UserInterface/Models/EventBreakpoint.js
Source/WebInspectorUI/UserInterface/Views/DebuggerSidebarPanel.js
Source/WebInspectorUI/UserInterface/Views/EventBreakpointTreeElement.js
Source/WebInspectorUI/UserInterface/Views/EventListenerSectionGroup.js