Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorDOMDebuggerAgent.cpp

Issue 1950403002: Add the ability to return descedant event listeners. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 dfcd08bb838054a3df02fc66db4ddca0047e6267..9463915c9de4346cce64f8a5b3836d4a45533baf 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"
@@ -42,6 +43,8 @@
#include "platform/v8_inspector/public/V8EventListenerInfo.h"
#include "platform/v8_inspector/public/V8InspectorSession.h"
+namespace blink {
+
namespace {
enum DOMBreakpointType {
@@ -57,33 +60,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, unsigned 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) {
@@ -92,13 +71,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 & V8EventListenerInfo::EventListenerFilterShowPassive) == 0 && registeredEventListener.passive())
+ continue;
+ if ((filterMask & V8EventListenerInfo::EventListenerFilterShowBlocking) == 0 && !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)
continue;
// getListenerObject() may cause JS in the event attribute to get
// compiled, potentially unsuccessfully. In that case, the function
@@ -106,7 +90,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));
+ }
+ }
+
+ if (filterMask & V8EventListenerInfo::EventListenerFilterShowDescendants) {
+ if (LocalDOMWindow* window = target->toLocalDOMWindow()) {
caseq 2016/05/20 00:47:24 Can we move this logic up to eventListenersInfoFor
dtapuska 2016/05/26 20:37:44 Ya; sorry this was less confusing when the iframe
+ if (Document* document = window->document()) {
+ addEventListenersForEventTarget(document, filterMask, mainContext, eventInformation);
+ for (Element& element : ElementTraversal::descendantsOf(*document))
+ addEventListenersForEventTarget(&element, filterMask, mainContext, eventInformation);
+ }
+ }
+ }
+}
+
+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, unsigned filterMask, 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;
+
+ v8::Local<v8::Context> mainContext = isolate->GetCurrentContext();
+ addEventListenersForEventTarget(target, filterMask, mainContext, eventInformation);
+
+ if (filterMask & V8EventListenerInfo::EventListenerFilterShowDescendants) {
+ if (Node* node = target->toNode()) {
+ for (Element& element : ElementTraversal::descendantsOf(*node))
+ addEventListenersForEventTarget(&element, filterMask, mainContext, eventInformation);
}
}
}
@@ -331,7 +361,7 @@ void InspectorDOMDebuggerAgent::removeDOMBreakpoint(ErrorString* errorString, in
didRemoveBreakpoint();
}
-void InspectorDOMDebuggerAgent::getEventListeners(ErrorString* errorString, const String16& objectId, OwnPtr<protocol::Array<protocol::DOMDebugger::EventListener>>* listenersArray)
+void InspectorDOMDebuggerAgent::getEventListeners(ErrorString* errorString, const String16& objectId, const Maybe<bool>& inDescendants, OwnPtr<protocol::Array<protocol::DOMDebugger::EventListener>>* listenersArray)
{
v8::HandleScope handles(m_isolate);
@@ -340,15 +370,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());
+ unsigned filterMask = V8EventListenerInfo::EventListenerFilterShowPassive | V8EventListenerInfo::EventListenerFilterShowBlocking;
+ if (inDescendants.fromMaybe(false))
+ filterMask |= V8EventListenerInfo::EventListenerFilterShowDescendants;
+ 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, unsigned 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;

Powered by Google App Engine
This is Rietveld 408576698