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

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

Issue 1999843002: [DevTools] Move CommandLineAPI.getEventListeners to native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-monitor-events-to-native
Patch Set: 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/ThreadDebugger.cpp
diff --git a/third_party/WebKit/Source/core/inspector/ThreadDebugger.cpp b/third_party/WebKit/Source/core/inspector/ThreadDebugger.cpp
index 5ba98053d559fc5cf55d204f85166632be4a2796..a6fdcfaae80dc88b05840a870b045fbdf6fa0fdb 100644
--- a/third_party/WebKit/Source/core/inspector/ThreadDebugger.cpp
+++ b/third_party/WebKit/Source/core/inspector/ThreadDebugger.cpp
@@ -11,6 +11,7 @@
#include "bindings/core/v8/V8DOMTokenList.h"
#include "bindings/core/v8/V8Event.h"
#include "bindings/core/v8/V8EventListener.h"
+#include "bindings/core/v8/V8EventListenerInfo.h"
#include "bindings/core/v8/V8EventListenerList.h"
#include "bindings/core/v8/V8HTMLAllCollection.h"
#include "bindings/core/v8/V8HTMLCollection.h"
@@ -73,11 +74,6 @@ void ThreadDebugger::endUserGesture()
m_userGestureIndicator.clear();
}
-void ThreadDebugger::eventListeners(v8::Local<v8::Value> value, V8EventListenerInfoList& result)
-{
- InspectorDOMDebuggerAgent::eventListenersInfoForTarget(m_isolate, value, result);
-}
-
String16 ThreadDebugger::valueSubtype(v8::Local<v8::Value> value)
{
if (V8Node::hasInstance(value, m_isolate))
@@ -144,7 +140,7 @@ bool ThreadDebugger::isCommandLineAPIMethod(const String& name)
{
DEFINE_STATIC_LOCAL(HashSet<String>, methods, ());
if (methods.size() == 0) {
- const char* members[] = { "monitorEvents", "unmonitorEvents" };
+ const char* members[] = { "monitorEvents", "unmonitorEvents", "getEventListeners" };
for (size_t i = 0; i < WTF_ARRAY_LENGTH(members); ++i)
methods.add(members[i]);
}
@@ -155,6 +151,7 @@ void ThreadDebugger::installAdditionalCommandLineAPI(v8::Local<v8::Context> cont
{
createFunctionProperty(context, object, "monitorEvents", ThreadDebugger::monitorEventsCallback, "function monitorEvents(object, [types]) { [Command Line API] }");
createFunctionProperty(context, object, "unmonitorEvents", ThreadDebugger::unmonitorEventsCallback, "function unmonitorEvents(object, [types]) { [Command Line API] }");
+ createFunctionProperty(context, object, "getEventListeners", ThreadDebugger::getEventListenersCallback, "function getEventListeners(node) { [Command Line API] }");
}
static Vector<String> normalizeEventTypes(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -264,6 +261,80 @@ void ThreadDebugger::unmonitorEventsCallback(const v8::FunctionCallbackInfo<v8::
setMonitorEventsCallback(info, false);
}
+static void removeEventListenerCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+ EventTarget* eventTarget = V8EventTarget::toImplWithTypeCheck(isolate, info.Data());
+ if (!eventTarget)
+ return;
+ v8::Local<v8::Value> thisHandler;
+ if (!info.Holder()->Get(context, v8String(isolate, "listener")).ToLocal(&thisHandler) || !thisHandler->IsObject())
+ return;
+ v8::Local<v8::Value> v8ThisType;
+ if (!info.Holder()->Get(context, v8String(isolate, "type")).ToLocal(&v8ThisType) || !v8ThisType->IsString())
+ return;
+ AtomicString thisType = AtomicString(toCoreString(v8::Local<v8::String>::Cast(v8ThisType)));
+ v8::Local<v8::Value> thisUseCapture;
+ if (!info.Holder()->Get(context, v8String(isolate, "useCapture")).ToLocal(&thisUseCapture) || !thisUseCapture->IsBoolean())
+ return;
+
+ EventListener* eventListener = V8EventListenerList::getEventListener(ScriptState::current(info.GetIsolate()), thisHandler, false, ListenerFindOnly);
+ if (!eventListener)
+ eventListener = V8EventListenerList::getEventListener(ScriptState::current(info.GetIsolate()), thisHandler, true, ListenerFindOnly);
+ if (!eventListener)
+ return;
+ EventListenerOptions options;
+ options.setCapture(v8::Local<v8::Boolean>::Cast(thisUseCapture)->Value());
+ eventTarget->removeEventListener(thisType, eventListener, options);
+}
+
+// static
+void ThreadDebugger::getEventListenersCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ if (info.Length() < 1)
+ return;
+
+ ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::External>::Cast(info.Data())->Value());
+ DCHECK(debugger);
+ v8::Isolate* isolate = info.GetIsolate();
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+
+ V8EventListenerInfoList listenerInfo;
+ // eventListeners call can produce message on ErrorEvent during lazy event listener compilation.
+ debugger->muteWarningsAndDeprecations();
+ InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], listenerInfo);
+ debugger->unmuteWarningsAndDeprecations();
+
+ v8::Local<v8::Object> result = v8::Object::New(isolate);
+
+ v8::Local<v8::Function> removeFunc = v8::Function::New(isolate, removeEventListenerCallback, info[0]);
+ v8::Local<v8::Function> toStringFunction;
+ if (v8::Function::New(context, returnDataCallback, v8String(isolate, "function remove() { [Command Line API] }")).ToLocal(&toStringFunction))
+ removeFunc->Set(v8String(context->GetIsolate(), "toString"), toStringFunction);
+
+ AtomicString currentEventType;
+ v8::Local<v8::Array> listeners;
+ size_t outputIndex = 0;
+ for (auto& info : listenerInfo) {
+ if (currentEventType != info.eventType) {
+ currentEventType = info.eventType;
+ listeners = v8::Array::New(isolate);
+ outputIndex = 0;
+ result->Set(v8String(isolate, currentEventType), listeners);
+ }
+
+ v8::Local<v8::Object> listenerObject = v8::Object::New(isolate);
+ listenerObject->Set(v8String(isolate, "listener"), info.handler);
+ listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(isolate, info.useCapture));
+ listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isolate, info.passive));
+ listenerObject->Set(v8String(isolate, "type"), v8String(isolate, currentEventType));
+ listenerObject->Set(v8String(isolate, "remove"), removeFunc);
+ listeners->Set(outputIndex++, listenerObject);
+ }
+ info.GetReturnValue().Set(result);
+}
+
void ThreadDebugger::reportMessageToConsole(v8::Local<v8::Context> context, MessageType type, MessageLevel level, const String16& message, const v8::FunctionCallbackInfo<v8::Value>* arguments, unsigned skipArgumentCount)
{
ScriptState* scriptState = ScriptState::from(context);
« no previous file with comments | « third_party/WebKit/Source/core/inspector/ThreadDebugger.h ('k') | third_party/WebKit/Source/platform/blink_platform.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698