Chromium Code Reviews| Index: third_party/WebKit/Source/core/inspector/InspectorDOMDebuggerAgent.cpp |
| diff --git a/third_party/WebKit/Source/core/inspector/InspectorDOMDebuggerAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorDOMDebuggerAgent.cpp |
| index aad900e61f11827fa405d21d39a0f3b207f2e552..7a2a8aef86523d1895e02b26297a78c5a69c4333 100644 |
| --- a/third_party/WebKit/Source/core/inspector/InspectorDOMDebuggerAgent.cpp |
| +++ b/third_party/WebKit/Source/core/inspector/InspectorDOMDebuggerAgent.cpp |
| @@ -33,6 +33,7 @@ |
| #include "bindings/core/v8/ScriptEventListener.h" |
| #include "bindings/core/v8/V8EventTarget.h" |
| #include "core/dom/Element.h" |
| +#include "core/dom/ElementTraversal.h" |
| #include "core/dom/Node.h" |
| #include "core/events/Event.h" |
| #include "core/events/EventTarget.h" |
| @@ -41,6 +42,8 @@ |
| #include "platform/inspector_protocol/Values.h" |
| #include "platform/v8_inspector/public/V8InspectorSession.h" |
| +namespace blink { |
| + |
| namespace { |
| enum DOMBreakpointType { |
| @@ -56,33 +59,9 @@ static const char instrumentationEventCategoryType[] = "instrumentation:"; |
| const uint32_t inheritableDOMBreakpointTypesMask = (1 << SubtreeModified); |
| const int domBreakpointDerivedTypeShift = 16; |
| -} // namespace |
| - |
| -namespace blink { |
| - |
| -static const char webglErrorFiredEventName[] = "webglErrorFired"; |
| -static const char webglWarningFiredEventName[] = "webglWarningFired"; |
| -static const char webglErrorNameProperty[] = "webglErrorName"; |
| - |
| -namespace DOMDebuggerAgentState { |
| -static const char eventListenerBreakpoints[] = "eventListenerBreakpoints"; |
| -static const char eventTargetAny[] = "*"; |
| -static const char pauseOnAllXHRs[] = "pauseOnAllXHRs"; |
| -static const char xhrBreakpoints[] = "xhrBreakpoints"; |
| -static const char enabled[] = "enabled"; |
| -} |
| - |
| -void InspectorDOMDebuggerAgent::eventListenersInfoForTarget(v8::Isolate* isolate, v8::Local<v8::Value> value, V8EventListenerInfoList& eventInformation) |
| +void addEventListenersForEventTarget(EventTarget* target, EventListenerFilter filterMask, v8::Local<v8::Context> mainContext, V8EventListenerInfoList& eventInformation) |
| { |
| - EventTarget* target = V8EventTarget::toImplWithTypeCheck(isolate, value); |
| - // We need to handle LocalDOMWindow specially, because LocalDOMWindow wrapper exists on prototype chain. |
| - if (!target) |
| - target = toDOMWindow(isolate, value); |
| - if (!target || !target->getExecutionContext()) |
| - return; |
| - |
| ExecutionContext* executionContext = target->getExecutionContext(); |
| - |
| // Nodes and their Listeners for the concerned event types (order is top to bottom) |
| Vector<AtomicString> eventTypes = target->eventTypes(); |
| for (size_t j = 0; j < eventTypes.size(); ++j) { |
| @@ -91,13 +70,18 @@ void InspectorDOMDebuggerAgent::eventListenersInfoForTarget(v8::Isolate* isolate |
| if (!listeners) |
| continue; |
| for (size_t k = 0; k < listeners->size(); ++k) { |
| - EventListener* eventListener = listeners->at(k).listener(); |
| + auto& registeredEventListener = listeners->at(k); |
| + EventListener* eventListener = registeredEventListener.listener(); |
| if (eventListener->type() != EventListener::JSEventListenerType) |
| continue; |
| + if ((filterMask & EventListenerFilter::ShowPassive) == EventListenerFilter::ShowNothing && registeredEventListener.passive()) |
| + continue; |
| + if ((filterMask & EventListenerFilter::ShowBlocking) == EventListenerFilter::ShowNothing && !registeredEventListener.passive()) |
| + continue; |
| V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(eventListener); |
| v8::Local<v8::Context> context = toV8Context(executionContext, v8Listener->world()); |
| // Hide listeners from other contexts. |
| - if (context != isolate->GetCurrentContext()) |
| + if (context != mainContext) |
|
pfeldman
2016/05/27 22:32:12
We should use access checks instead of context com
dtapuska
2016/05/31 21:26:07
I removed the context check and moved it up to the
|
| continue; |
| // getListenerObject() may cause JS in the event attribute to get |
| // compiled, potentially unsuccessfully. In that case, the function |
| @@ -105,7 +89,53 @@ void InspectorDOMDebuggerAgent::eventListenersInfoForTarget(v8::Isolate* isolate |
| v8::Local<v8::Object> handler = v8Listener->getListenerObject(executionContext); |
| if (handler.IsEmpty()) |
| continue; |
| - eventInformation.append(V8EventListenerInfo(type, listeners->at(k).capture(), listeners->at(k).passive(), handler)); |
| + eventInformation.append(V8EventListenerInfo(type, registeredEventListener.capture(), registeredEventListener.passive(), handler)); |
| + } |
| + } |
| +} |
| + |
| +static const char webglErrorFiredEventName[] = "webglErrorFired"; |
| +static const char webglWarningFiredEventName[] = "webglWarningFired"; |
| +static const char webglErrorNameProperty[] = "webglErrorName"; |
| + |
| +} // namespace |
| + |
| +namespace DOMDebuggerAgentState { |
| + |
| +static const char eventListenerBreakpoints[] = "eventListenerBreakpoints"; |
| +static const char eventTargetAny[] = "*"; |
| +static const char pauseOnAllXHRs[] = "pauseOnAllXHRs"; |
| +static const char xhrBreakpoints[] = "xhrBreakpoints"; |
| +static const char enabled[] = "enabled"; |
| + |
| +} // namespace DOMDebuggerAgentState |
| + |
| +void InspectorDOMDebuggerAgent::eventListenersInfoForTarget(v8::Isolate* isolate, v8::Local<v8::Value> value, EventListenerFilter filterMask, V8EventListenerInfoList& eventInformation) |
| +{ |
| + EventTarget* target = V8EventTarget::toImplWithTypeCheck(isolate, value); |
| + // We need to handle LocalDOMWindow specially, because LocalDOMWindow wrapper exists on prototype chain. |
| + if (!target) |
|
pfeldman
2016/05/27 22:32:12
Why would we fall back to the window?
dtapuska
2016/05/31 21:26:07
This code was copied from previous impl (see remov
|
| + target = toDOMWindow(isolate, value); |
| + if (!target || !target->getExecutionContext()) |
| + return; |
| + |
| + v8::Local<v8::Context> mainContext = isolate->GetCurrentContext(); |
| + addEventListenersForEventTarget(target, filterMask, mainContext, eventInformation); |
| + |
| + if ((filterMask & EventListenerFilter::ShowDescendants) != EventListenerFilter::ShowNothing) { |
|
pfeldman
2016/05/27 22:32:12
Get rid of the ShowNothing, simply if w/ mask test
dtapuska
2016/05/31 21:26:07
Done.
|
| + Node* rootNode = nullptr; |
| + if (LocalDOMWindow* window = target->toLocalDOMWindow()) { |
|
pfeldman
2016/05/27 22:32:12
What if target is not window?
dtapuska
2016/05/31 21:26:07
See else if path.
|
| + if (Document* document = window->document()) { |
| + addEventListenersForEventTarget(document, filterMask, mainContext, eventInformation); |
| + rootNode = document; |
| + } |
| + } else if (Node* node = target->toNode()) { |
| + rootNode = node; |
| + } |
| + |
| + if (rootNode) { |
| + for (Element& element : ElementTraversal::descendantsOf(*rootNode)) |
| + addEventListenersForEventTarget(&element, filterMask, mainContext, eventInformation); |
|
pfeldman
2016/05/27 22:32:12
Do you intend to cross the frame boundary?
dtapuska
2016/05/31 21:26:07
I wanted to; I've added this back. It seemed to me
|
| } |
| } |
| } |
| @@ -330,7 +360,7 @@ void InspectorDOMDebuggerAgent::removeDOMBreakpoint(ErrorString* errorString, in |
| didRemoveBreakpoint(); |
| } |
| -void InspectorDOMDebuggerAgent::getEventListeners(ErrorString* errorString, const String16& objectId, std::unique_ptr<protocol::Array<protocol::DOMDebugger::EventListener>>* listenersArray) |
| +void InspectorDOMDebuggerAgent::getEventListeners(ErrorString* errorString, const String16& objectId, const Maybe<bool>& inDescendants, std::unique_ptr<protocol::Array<protocol::DOMDebugger::EventListener>>* listenersArray) |
| { |
| v8::HandleScope handles(m_isolate); |
| @@ -339,15 +369,19 @@ void InspectorDOMDebuggerAgent::getEventListeners(ErrorString* errorString, cons |
| v8::Local<v8::Value> value = m_v8Session->findObject(errorString, objectId, &context, &objectGroup); |
| if (value.IsEmpty()) |
| return; |
| + |
| v8::Context::Scope scope(context); |
| *listenersArray = protocol::Array<protocol::DOMDebugger::EventListener>::create(); |
| - eventListeners(context, value, objectGroup, listenersArray->get()); |
| + EventListenerFilter filterMask = EventListenerFilter::ShowPassive | EventListenerFilter::ShowBlocking; |
| + if (inDescendants.fromMaybe(false)) |
| + filterMask |= EventListenerFilter::ShowDescendants; |
| + eventListeners(context, value, objectGroup, filterMask, listenersArray->get()); |
| } |
| -void InspectorDOMDebuggerAgent::eventListeners(v8::Local<v8::Context> context, v8::Local<v8::Value> object, const String16& objectGroup, protocol::Array<protocol::DOMDebugger::EventListener>* listenersArray) |
| +void InspectorDOMDebuggerAgent::eventListeners(v8::Local<v8::Context> context, v8::Local<v8::Value> object, const String16& objectGroup, EventListenerFilter filterMask, protocol::Array<protocol::DOMDebugger::EventListener>* listenersArray) |
| { |
| V8EventListenerInfoList eventInformation; |
| - InspectorDOMDebuggerAgent::eventListenersInfoForTarget(context->GetIsolate(), object, eventInformation); |
| + InspectorDOMDebuggerAgent::eventListenersInfoForTarget(context->GetIsolate(), object, filterMask, eventInformation); |
| for (const auto& info : eventInformation) { |
| if (!info.useCapture) |
| continue; |