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

Unified Diff: Source/core/inspector/InjectedScriptSource.js

Issue 1268353005: [DevTools] Support JQuery event listeners (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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: Source/core/inspector/InjectedScriptSource.js
diff --git a/Source/core/inspector/InjectedScriptSource.js b/Source/core/inspector/InjectedScriptSource.js
index fa2c21aa111638bd91281808842d108ed9e12acf..2be005e560af4385ec4c29cb80d864b4c11a8569 100644
--- a/Source/core/inspector/InjectedScriptSource.js
+++ b/Source/core/inspector/InjectedScriptSource.js
@@ -1136,6 +1136,66 @@ InjectedScript.prototype = {
setCustomObjectFormatterEnabled: function(enabled)
{
this._customObjectFormatterEnabled = enabled;
+ },
+
+ /**
+ * @param {string} objectId
+ * @return {!Array.<!{type: string, listener: function(), useCapture: boolean}>}
+ */
+ librariesEventListenersByObjectId: function(objectId)
yurys 2015/08/11 21:10:24 Can you move id -> object resolution to C++ ?
kozy 2015/08/12 18:02:22 Done.
+ {
+ var parsedObjectId = this._parseObjectId(objectId);
+ var object = this._objectForId(parsedObjectId);
+ if (this._subtype(object) === "node")
+ return this.librariesEventListeners(object);
+ return [];
+ },
+
+ /**
+ * @param {!Node} node
+ * @return {!Array.<!{type: string, listener: function(), useCapture: boolean}>}
+ */
+ librariesEventListeners: function(node)
yurys 2015/08/11 21:10:24 frameworkEventListeners?
kozy 2015/08/12 18:02:22 Done.
+ {
+ var hasJQuery = (typeof jQuery !== 'undefined') && jQuery.fn;
+ if (!hasJQuery)
+ return [];
+ var listeners = [];
+ var data = jQuery._data || jQuery.data;
+ if (data) {
yurys 2015/08/11 21:10:24 && typeof data === "function" ?
kozy 2015/08/12 18:02:22 Done.
+ var events = data(node, "events");
+ for (var type in events) {
+ for (var key in events[type]) {
+ var listener = events[type][key];
+ if (typeof listener === "object" || typeof listener === "function") {
+ var listener = {
+ handler: listener.handler || listener,
+ useCapture: true,
+ type: type
+ }
+ listeners.push(listener);
yurys 2015/08/11 21:10:24 push(listeners, listener); to avoid calling push o
kozy 2015/08/12 18:02:22 Done.
+ }
+ }
+ }
+ }
+ var entry = jQuery(node)[0];
+ if (entry) {
+ var entryEvents = entry["$events"];
+ for (var type in entryEvents) {
+ var events = entryEvents[type];
+ for (var key in events) {
+ if (typeof events[key] === "function") {
yurys 2015/08/11 21:10:24 wrong alignment
kozy 2015/08/12 18:02:22 Done.
+ var listener = {
+ handler: events[key],
+ useCapture: true,
+ type: type
+ }
+ listeners.push(listener);
+ }
+ }
+ }
+ }
+ return listeners;
}
}
@@ -1849,6 +1909,12 @@ CommandLineAPIImpl.prototype = {
var result = nullifyObjectProto(InjectedScriptHost.getEventListeners(node));
if (!result)
return result;
+
+ var jQueryListeners = injectedScript.librariesEventListeners(node);
+ for (var i = 0; i < jQueryListeners.length; ++i) {
+ result[jQueryListeners[i].type] = result[jQueryListeners[i].type] || [];
+ result[jQueryListeners[i].type].push(jQueryListeners[i]);
+ }
/** @this {{type: string, listener: function(), useCapture: boolean}} */
var removeFunc = function()
{

Powered by Google App Engine
This is Rietveld 408576698