Title: [111529] trunk
Revision
111529
Author
[email protected]
Date
2012-03-21 06:22:08 -0700 (Wed, 21 Mar 2012)

Log Message

Web Inspector: expose getEventListeners() to console command line API
https://bugs.webkit.org/show_bug.cgi?id=81658

Reviewed by Yury Semikhatsky.

Source/WebCore:

Test: inspector/console/command-line-api-getEventListeners.html

* bindings/js/JSInjectedScriptHostCustom.cpp:
(WebCore::JSInjectedScriptHost::functionDetails):
(WebCore):
(WebCore::getJSListenerFunctions):
(WebCore::JSInjectedScriptHost::getEventListeners):
* bindings/v8/custom/V8InjectedScriptHostCustom.cpp:
(WebCore::getJSListenerFunctions):
(WebCore):
(WebCore::V8InjectedScriptHost::getEventListenersCallback):
* inspector/InjectedScriptHost.cpp:
(WebCore::InjectedScriptHost::InjectedScriptHost):
(WebCore::InjectedScriptHost::disconnect):
(WebCore::InjectedScriptHost::getEventListenersImpl):
(WebCore):
* inspector/InjectedScriptHost.h:
(WebCore):
(WebCore::InjectedScriptHost::init):
(InjectedScriptHost):
* inspector/InjectedScriptHost.idl:
* inspector/InjectedScriptSource.js:
(.):
* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::getEventListenersForNode):
(WebCore::InspectorDOMAgent::getEventListeners):
(WebCore):
* inspector/InspectorDOMAgent.h:
(InspectorDOMAgent):
* inspector/WorkerInspectorController.cpp:
(WebCore::WorkerInspectorController::WorkerInspectorController):

LayoutTests:

* inspector/console/command-line-api-getEventListeners-expected.txt: Added.
* inspector/console/command-line-api-getEventListeners.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (111528 => 111529)


--- trunk/LayoutTests/ChangeLog	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/LayoutTests/ChangeLog	2012-03-21 13:22:08 UTC (rev 111529)
@@ -1,3 +1,13 @@
+2012-03-21  Andrey Kosyakov  <[email protected]>
+
+        Web Inspector: expose getEventListeners() to console command line API
+        https://bugs.webkit.org/show_bug.cgi?id=81658
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/console/command-line-api-getEventListeners-expected.txt: Added.
+        * inspector/console/command-line-api-getEventListeners.html: Added.
+
 2012-03-21  Vineet Chaudhary  <[email protected]>
 
         https://bugs.webkit.org/show_bug.cgi?id=81705

Added: trunk/LayoutTests/inspector/console/command-line-api-getEventListeners-expected.txt (0 => 111529)


--- trunk/LayoutTests/inspector/console/command-line-api-getEventListeners-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/console/command-line-api-getEventListeners-expected.txt	2012-03-21 13:22:08 UTC (rev 111529)
@@ -0,0 +1,54 @@
+Tests getEventListeners() method of console command line API.
+
+
+- inner -
+keydown: {
+    0: {
+        listener: function listener1() { }
+        useCapture: false
+    }
+    1: {
+        listener: function listener2() { }
+        useCapture: true
+    }
+}
+- outer -
+mousemove: {
+    0: {
+        listener: function listener1() { }
+        useCapture: false
+    }
+}
+keydown: {
+    0: {
+        listener: function listener2() { }
+        useCapture: true
+    }
+}
+mousedown: {
+    0: {
+        listener: function listener2() { }
+        useCapture: true
+    }
+}
+- attribute event listeners -
+mouseover: {
+    0: {
+        listener: function onmouseover(event) { listener2() }
+        useCapture: false
+    }
+}
+click: {
+    0: {
+        listener: function onclick(event) { alert(1) }
+        useCapture: false
+    }
+}
+- empty -
+- object -
+undefined
+- null -
+undefined
+- undefined -
+undefined
+
Property changes on: trunk/LayoutTests/inspector/console/command-line-api-getEventListeners-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/console/command-line-api-getEventListeners.html (0 => 111529)


--- trunk/LayoutTests/inspector/console/command-line-api-getEventListeners.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/console/command-line-api-getEventListeners.html	2012-03-21 13:22:08 UTC (rev 111529)
@@ -0,0 +1,93 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<script>
+
+var test = function()
+{
+    InspectorTest.evaluateInConsole("runTestsInPage(getEventListeners)", InspectorTest.completeTest.bind(InspectorTest));
+}
+
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p id="foo">
+Tests getEventListeners() method of console command line API.
+</p>
+<div id="outer">
+<div id="inner">
+</div>
+</div>
+<div id="empty">
+</div>
+<button id="button" _onclick_="alert(1)" _onmouseover_="listener2()"></button>
+
+<script>
+function listener1()
+{
+}
+function listener2()
+{
+}
+
+document.getElementById("inner").addEventListener("keydown", listener1, false);
+document.getElementById("inner").addEventListener("keydown", listener2, true);
+document.getElementById("outer").addEventListener("mousemove", listener1, false);
+document.getElementById("outer").addEventListener("mousedown", listener2, true);
+document.getElementById("outer").addEventListener("keydown", listener2, true);
+
+function dumpObject(object, prefix)
+{
+    prefix = prefix || "";
+    var keys = Object.keys(object);
+    for (var i = 0; i < keys.length; ++i) {
+        var value = object[keys[i]];
+        var nameWithPrefix = prefix + keys[i] + ": ";
+        switch (typeof(value)) {
+        case "object":
+            if (value === null) {
+                output(nameWithPrefix + "null");
+                break;
+            }
+            output(nameWithPrefix + "{");
+            dumpObject(value, prefix + "    ")
+            output(prefix + "}");
+            break;
+        case "string":
+            output(nameWithPrefix + JSON.stringify(value));
+            break;
+        case "function":
+            var body = value.toString().replace(/[ \n]+/gm, " ");
+            body = body.replace(/; }/g, " }");
+            output(nameWithPrefix + body);
+            break;
+        default:
+            output(nameWithPrefix + String(value));
+            break;
+        }
+    }
+}
+
+function runTestsInPage(getEventListeners)
+{
+    output("- inner -");
+    dumpObject(getEventListeners(document.getElementById("inner")));
+    output("- outer -");
+    dumpObject(getEventListeners(document.getElementById("outer")));
+    output("- attribute event listeners -");
+    dumpObject(getEventListeners(document.getElementById("button")));
+    output("- empty -");
+    dumpObject(getEventListeners(document.getElementById("empty")));
+    output("- object -");
+    output(typeof getEventListeners({}));
+    output("- null -");
+    output(typeof getEventListeners(null));
+    output("- undefined -");
+    output(typeof getEventListeners(undefined));
+}
+
+</script>
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/console/command-line-api-getEventListeners.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (111528 => 111529)


--- trunk/Source/WebCore/ChangeLog	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/Source/WebCore/ChangeLog	2012-03-21 13:22:08 UTC (rev 111529)
@@ -1,3 +1,44 @@
+2012-03-21  Andrey Kosyakov  <[email protected]>
+
+        Web Inspector: expose getEventListeners() to console command line API
+        https://bugs.webkit.org/show_bug.cgi?id=81658
+
+        Reviewed by Yury Semikhatsky.
+
+        Test: inspector/console/command-line-api-getEventListeners.html
+
+        * bindings/js/JSInjectedScriptHostCustom.cpp:
+        (WebCore::JSInjectedScriptHost::functionDetails):
+        (WebCore):
+        (WebCore::getJSListenerFunctions):
+        (WebCore::JSInjectedScriptHost::getEventListeners):
+        * bindings/v8/custom/V8InjectedScriptHostCustom.cpp:
+        (WebCore::getJSListenerFunctions):
+        (WebCore):
+        (WebCore::V8InjectedScriptHost::getEventListenersCallback):
+        * inspector/InjectedScriptHost.cpp:
+        (WebCore::InjectedScriptHost::InjectedScriptHost):
+        (WebCore::InjectedScriptHost::disconnect):
+        (WebCore::InjectedScriptHost::getEventListenersImpl):
+        (WebCore):
+        * inspector/InjectedScriptHost.h:
+        (WebCore):
+        (WebCore::InjectedScriptHost::init):
+        (InjectedScriptHost):
+        * inspector/InjectedScriptHost.idl:
+        * inspector/InjectedScriptSource.js:
+        (.):
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::getEventListenersForNode):
+        (WebCore::InspectorDOMAgent::getEventListeners):
+        (WebCore):
+        * inspector/InspectorDOMAgent.h:
+        (InspectorDOMAgent):
+        * inspector/WorkerInspectorController.cpp:
+        (WebCore::WorkerInspectorController::WorkerInspectorController):
+
 2012-03-21  Kentaro Hara  <[email protected]>
 
         Unreviewed, rebaselined run-bindings-tests results.

Modified: trunk/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp (111528 => 111529)


--- trunk/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp	2012-03-21 13:22:08 UTC (rev 111529)
@@ -42,8 +42,10 @@
 #endif
 #include "ExceptionCode.h"
 #include "InjectedScriptHost.h"
+#include "InspectorDOMAgent.h"
 #include "InspectorDebuggerAgent.h"
 #include "InspectorValues.h"
+#include "JSEventListener.h"
 #include "JSFloat32Array.h"
 #include "JSFloat64Array.h"
 #include "JSHTMLAllCollection.h"
@@ -185,6 +187,56 @@
     return result;
 }
 
+static JSArray* getJSListenerFunctions(ExecState* exec, Document* document, const EventListenerInfo& listenerInfo)
+{
+    JSArray* result = constructEmptyArray(exec);
+    size_t handlersCount = listenerInfo.eventListenerVector.size();
+    for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) {
+        const JSEventListener* jsListener = JSEventListener::cast(listenerInfo.eventListenerVector[i].listener.get());
+        if (!jsListener)
+            continue;
+        // Hide listeners from other contexts.
+        if (jsListener->isolatedWorld() != currentWorld(exec))
+            continue;
+        JSObject* function = jsListener->jsFunction(document);
+        JSObject* listenerEntry = constructEmptyObject(exec);
+        listenerEntry->putDirect(exec->globalData(), Identifier(exec, "listener"), function);
+        listenerEntry->putDirect(exec->globalData(), Identifier(exec, "useCapture"), jsBoolean(listenerInfo.eventListenerVector[i].useCapture));
+        result->putDirectIndex(exec, outputIndex++, JSValue(listenerEntry));
+    }
+    return result;
+}
+
+JSValue JSInjectedScriptHost::getEventListeners(ExecState* exec)
+{
+    if (exec->argumentCount() < 1)
+        return jsUndefined();
+    JSValue value = exec->argument(0);
+    if (!value.isObject() || value.isNull())
+        return jsUndefined();
+    Node* node = toNode(value);
+    if (!node)
+        return jsUndefined();
+    // This can only happen for orphan DocumentType nodes.
+    Document* document = node->document();
+    if (!node->document())
+        return jsUndefined();
+
+    Vector<EventListenerInfo> listenersArray;
+    impl()->getEventListenersImpl(node, listenersArray);
+
+    JSObject* result = constructEmptyObject(exec);
+    for (size_t i = 0; i < listenersArray.size(); ++i) {
+        JSArray* listeners = getJSListenerFunctions(exec, document, listenersArray[i]);
+        if (!listeners->length())
+            continue;
+        AtomicString eventType = listenersArray[i].eventType;
+        result->putDirect(exec->globalData(), Identifier(exec, eventType.impl()), JSValue(listeners));
+    }
+
+    return result;
+}
+
 JSValue JSInjectedScriptHost::inspect(ExecState* exec)
 {
     if (exec->argumentCount() >= 2) {

Modified: trunk/Source/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp (111528 => 111529)


--- trunk/Source/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/Source/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp	2012-03-21 13:22:08 UTC (rev 111529)
@@ -35,6 +35,7 @@
 #include "Database.h"
 #include "InjectedScript.h"
 #include "InjectedScriptHost.h"
+#include "InspectorDOMAgent.h"
 #include "InspectorValues.h"
 #include "ScriptValue.h"
 #include "V8Binding.h"
@@ -182,6 +183,63 @@
     return result;
 }
 
+static v8::Handle<v8::Array> getJSListenerFunctions(Document* document, const EventListenerInfo& listenerInfo)
+{
+    v8::Local<v8::Array> result = v8::Array::New();
+    size_t handlersCount = listenerInfo.eventListenerVector.size();
+    for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) {
+        RefPtr<EventListener> listener = listenerInfo.eventListenerVector[i].listener;
+        if (listener->type() != EventListener::JSEventListenerType)
+            continue;
+        V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(listener.get());
+        v8::Local<v8::Context> context = toV8Context(document, v8Listener->worldContext());
+        // Hide listeners from other contexts.
+        if (context != V8Proxy::currentContext())
+            continue;
+        v8::Local<v8::Object> function = v8Listener->getListenerObject(document);
+        v8::Local<v8::Object> listenerEntry = v8::Object::New();
+        listenerEntry->Set(v8::String::New("listener"), function);
+        listenerEntry->Set(v8::String::New("useCapture"), v8::Boolean::New(listenerInfo.eventListenerVector[i].useCapture));
+        result->Set(v8::Number::New(outputIndex++), listenerEntry);
+    }
+    return result;
+}
+
+v8::Handle<v8::Value> V8InjectedScriptHost::getEventListenersCallback(const v8::Arguments& args)
+{
+    INC_STATS("InjectedScriptHost.queryEventListenerCallback()");
+    if (args.Length() < 1)
+        return v8::Undefined();
+
+    v8::HandleScope handleScope;
+
+    v8::Local<v8::Value> value = args[0];
+    if (!value->IsObject())
+        return v8::Undefined();
+    Node* node = V8Node::toNative(value->ToObject());
+    if (!node)
+        return v8::Undefined();
+    // This can only happen for orphan DocumentType nodes.
+    Document* document = node->document();
+    if (!node->document())
+        return v8::Undefined();
+
+    InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder());
+    Vector<EventListenerInfo> listenersArray;
+    host->getEventListenersImpl(node, listenersArray);
+
+    v8::Local<v8::Object> result = v8::Object::New();
+    for (size_t i = 0; i < listenersArray.size(); ++i) {
+        v8::Handle<v8::Array> listeners = getJSListenerFunctions(document, listenersArray[i]);
+        if (!listeners->Length())
+            continue;
+        AtomicString eventType = listenersArray[i].eventType;
+        result->Set(v8::String::New(fromWebCoreString(eventType), eventType.length()), listeners);
+    }
+
+    return result;
+}
+
 v8::Handle<v8::Value> V8InjectedScriptHost::inspectCallback(const v8::Arguments& args)
 {
     INC_STATS("InjectedScriptHost.inspect()");

Modified: trunk/Source/WebCore/inspector/InjectedScriptHost.cpp (111528 => 111529)


--- trunk/Source/WebCore/inspector/InjectedScriptHost.cpp	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/Source/WebCore/inspector/InjectedScriptHost.cpp	2012-03-21 13:22:08 UTC (rev 111529)
@@ -42,6 +42,7 @@
 #include "InspectorAgent.h"
 #include "InspectorClient.h"
 #include "InspectorConsoleAgent.h"
+#include "InspectorDOMAgent.h"
 #include "InspectorDOMStorageAgent.h"
 #include "InspectorDatabaseAgent.h"
 #include "InspectorFrontend.h"
@@ -74,6 +75,7 @@
     , m_databaseAgent(0)
 #endif
     , m_domStorageAgent(0)
+    , m_domAgent(0)
     , m_lastWorkerId(1 << 31) // Distinguish ids of fake workers from real ones, to minimize the chances they overlap.
 {
     m_defaultInspectableObject = adoptPtr(new InspectableObject());
@@ -91,6 +93,7 @@
     m_databaseAgent = 0;
 #endif
     m_domStorageAgent = 0;
+    m_domAgent = 0;
 }
 
 void InjectedScriptHost::inspectImpl(PassRefPtr<InspectorValue> object, PassRefPtr<InspectorValue> hints)
@@ -99,6 +102,12 @@
         m_inspectorAgent->inspect(object->asObject(), hints->asObject());
 }
 
+void InjectedScriptHost::getEventListenersImpl(Node* node, Vector<EventListenerInfo>& listenersArray)
+{
+    if (m_domAgent)
+        m_domAgent->getEventListeners(node, listenersArray, false);
+}
+
 void InjectedScriptHost::clearConsoleMessages()
 {
     if (m_consoleAgent) {

Modified: trunk/Source/WebCore/inspector/InjectedScriptHost.h (111528 => 111529)


--- trunk/Source/WebCore/inspector/InjectedScriptHost.h	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/Source/WebCore/inspector/InjectedScriptHost.h	2012-03-21 13:22:08 UTC (rev 111529)
@@ -39,9 +39,11 @@
 namespace WebCore {
 
 class Database;
+class EventListenerInfo;
 class InjectedScript;
 class InspectorAgent;
 class InspectorConsoleAgent;
+class InspectorDOMAgent;
 class InspectorDOMStorageAgent;
 class InspectorDatabaseAgent;
 class InspectorFrontend;
@@ -63,6 +65,7 @@
             , InspectorDatabaseAgent* databaseAgent
 #endif
             , InspectorDOMStorageAgent* domStorageAgent
+            , InspectorDOMAgent* domAgent
         )
     {
         m_inspectorAgent = inspectorAgent;
@@ -71,6 +74,7 @@
         m_databaseAgent = databaseAgent;
 #endif
         m_domStorageAgent = domStorageAgent;
+        m_domAgent = domAgent;
     }
 
     static Node* scriptValueAsNode(ScriptValue);
@@ -88,6 +92,8 @@
     InspectableObject* inspectedObject(unsigned int num);
 
     void inspectImpl(PassRefPtr<InspectorValue> objectToInspect, PassRefPtr<InspectorValue> hints);
+    void getEventListenersImpl(Node*, Vector<EventListenerInfo>& listenersArray);
+
     void clearConsoleMessages();
     void copyText(const String& text);
 #if ENABLE(SQL_DATABASE)
@@ -109,6 +115,7 @@
     InspectorDatabaseAgent* m_databaseAgent;
 #endif
     InspectorDOMStorageAgent* m_domStorageAgent;
+    InspectorDOMAgent* m_domAgent;
     long m_lastWorkerId;
     Vector<OwnPtr<InspectableObject> > m_inspectedObjects;
     OwnPtr<InspectableObject> m_defaultInspectableObject;

Modified: trunk/Source/WebCore/inspector/InjectedScriptHost.idl (111528 => 111529)


--- trunk/Source/WebCore/inspector/InjectedScriptHost.idl	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/Source/WebCore/inspector/InjectedScriptHost.idl	2012-03-21 13:22:08 UTC (rev 111529)
@@ -43,6 +43,7 @@
         [Custom] boolean isHTMLAllCollection(in DOMObject object);
         [Custom] DOMString type(in DOMObject object);
         [Custom] DOMObject functionDetails(in DOMObject object);
+        [Custom] Array getEventListeners(in Node node);
 
         [Custom] int databaseId(in DOMObject database);
         [Custom] int storageId(in DOMObject storage);

Modified: trunk/Source/WebCore/inspector/InjectedScriptSource.js (111528 => 111529)


--- trunk/Source/WebCore/inspector/InjectedScriptSource.js	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/Source/WebCore/inspector/InjectedScriptSource.js	2012-03-21 13:22:08 UTC (rev 111529)
@@ -577,7 +577,7 @@
 
 CommandLineAPI.members_ = [
     "$", "$$", "$x", "dir", "dirxml", "keys", "values", "profile", "profileEnd",
-    "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear"
+    "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "getEventListeners"
 ];
 
 function CommandLineAPIImpl()
@@ -685,6 +685,11 @@
         InjectedScriptHost.clearConsoleMessages();
     },
 
+    getEventListeners: function(node)
+    {
+        return InjectedScriptHost.getEventListeners(node);
+    },
+
     _inspectedObject: function(num)
     {
         return InjectedScriptHost.inspectedObject(num);

Modified: trunk/Source/WebCore/inspector/InspectorController.cpp (111528 => 111529)


--- trunk/Source/WebCore/inspector/InspectorController.cpp	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/Source/WebCore/inspector/InspectorController.cpp	2012-03-21 13:22:08 UTC (rev 111529)
@@ -150,6 +150,7 @@
         , databaseAgent
 #endif
         , domStorageAgent
+        , m_domAgent
     );
 
 #if ENABLE(_javascript__DEBUGGER)

Modified: trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp (111528 => 111529)


--- trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp	2012-03-21 13:22:08 UTC (rev 111529)
@@ -723,45 +723,18 @@
     m_domEditor->replaceWholeText(toText(node), value, errorString);
 }
 
-void InspectorDOMAgent::getEventListenersForNode(ErrorString*, int nodeId, RefPtr<InspectorArray>& listenersArray)
+void InspectorDOMAgent::getEventListenersForNode(ErrorString* errorString, int nodeId, RefPtr<InspectorArray>& listenersArray)
 {
     Node* node = nodeForId(nodeId);
-    EventTargetData* d;
-
-    // Quick break if a null node or no listeners at all
-    if (!node || !(d = node->eventTargetData()))
+    if (!node) {
+        *errorString = "No such node";
         return;
-
-    // Get the list of event types this Node is concerned with
-    Vector<AtomicString> eventTypes = d->eventListenerMap.eventTypes();
-
-    // Quick break if no useful listeners
-    size_t eventTypesLength = eventTypes.size();
-    if (!eventTypesLength)
+    }
+    Vector<EventListenerInfo> eventInformation;
+    getEventListeners(node, eventInformation, true);
+    if (eventInformation.isEmpty())
         return;
 
-    // The Node's Ancestors (not including self)
-    Vector<ContainerNode*> ancestors;
-    for (ContainerNode* ancestor = node->parentOrHostNode(); ancestor; ancestor = ancestor->parentOrHostNode())
-        ancestors.append(ancestor);
-
-    // Nodes and their Listeners for the concerned event types (order is top to bottom)
-    Vector<EventListenerInfo> eventInformation;
-    for (size_t i = ancestors.size(); i; --i) {
-        ContainerNode* ancestor = ancestors[i - 1];
-        for (size_t j = 0; j < eventTypesLength; ++j) {
-            AtomicString& type = eventTypes[j];
-            if (ancestor->hasEventListeners(type))
-                eventInformation.append(EventListenerInfo(ancestor, type, ancestor->getEventListeners(type)));
-        }
-    }
-
-    // Insert the Current Node at the end of that list (last in capturing, first in bubbling)
-    for (size_t i = 0; i < eventTypesLength; ++i) {
-        const AtomicString& type = eventTypes[i];
-        eventInformation.append(EventListenerInfo(node, type, node->getEventListeners(type)));
-    }
-
     // Get Capturing Listeners (in this order)
     size_t eventInformationLength = eventInformation.size();
     for (size_t i = 0; i < eventInformationLength; ++i) {
@@ -786,6 +759,46 @@
     }
 }
 
+void InspectorDOMAgent::getEventListeners(Node* node, Vector<EventListenerInfo>& eventInformation, bool includeAncestors)
+{
+    EventTargetData* d;
+
+    // Quick break if no listeners at all
+    if (!(d = node->eventTargetData()))
+        return;
+
+    // Get the list of event types this Node is concerned with
+    Vector<AtomicString> eventTypes = d->eventListenerMap.eventTypes();
+
+    // Quick break if no useful listeners
+    size_t eventTypesLength = eventTypes.size();
+    if (!eventTypesLength)
+        return;
+
+    if (includeAncestors) {
+        // The Node's Ancestors (not including self)
+        Vector<ContainerNode*> ancestors;
+        for (ContainerNode* ancestor = node->parentOrHostNode(); ancestor; ancestor = ancestor->parentOrHostNode())
+            ancestors.append(ancestor);
+
+        // Nodes and their Listeners for the concerned event types (order is top to bottom)
+        for (size_t i = ancestors.size(); i; --i) {
+            ContainerNode* ancestor = ancestors[i - 1];
+            for (size_t j = 0; j < eventTypesLength; ++j) {
+                AtomicString& type = eventTypes[j];
+                if (ancestor->hasEventListeners(type))
+                    eventInformation.append(EventListenerInfo(ancestor, type, ancestor->getEventListeners(type)));
+            }
+        }
+    }
+
+    // Insert the Current Node at the end of that list (last in capturing, first in bubbling)
+    for (size_t i = 0; i < eventTypesLength; ++i) {
+        const AtomicString& type = eventTypes[i];
+        eventInformation.append(EventListenerInfo(node, type, node->getEventListeners(type)));
+    }
+}
+
 void InspectorDOMAgent::performSearch(ErrorString*, const String& whitespaceTrimmedQuery, String* searchId, int* resultCount)
 {
     // FIXME: Few things are missing here:

Modified: trunk/Source/WebCore/inspector/InspectorDOMAgent.h (111528 => 111529)


--- trunk/Source/WebCore/inspector/InspectorDOMAgent.h	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/Source/WebCore/inspector/InspectorDOMAgent.h	2012-03-21 13:22:08 UTC (rev 111529)
@@ -153,6 +153,8 @@
 
     Node* highlightedNode() const;
 
+    void getEventListeners(Node*, Vector<EventListenerInfo>& listenersArray, bool includeAncestors);
+
     // Methods called from the InspectorInstrumentation.
     void setDocument(Document*);
     void releaseDanglingNodes();

Modified: trunk/Source/WebCore/inspector/WorkerInspectorController.cpp (111528 => 111529)


--- trunk/Source/WebCore/inspector/WorkerInspectorController.cpp	2012-03-21 12:53:27 UTC (rev 111528)
+++ trunk/Source/WebCore/inspector/WorkerInspectorController.cpp	2012-03-21 13:22:08 UTC (rev 111529)
@@ -110,6 +110,7 @@
         , 0
 #endif
         , 0
+        , 0
     );
 
 #if ENABLE(_javascript__DEBUGGER)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to