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

Side by Side Diff: third_party/WebKit/Source/core/inspector/ThreadDebugger.cpp

Issue 2034533002: [DevTools] Add removeFunction to EventListener protocol object (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/inspector/ThreadDebugger.h" 5 #include "core/inspector/ThreadDebugger.h"
6 6
7 #include "bindings/core/v8/ScriptValue.h" 7 #include "bindings/core/v8/ScriptValue.h"
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/V8DOMException.h" 9 #include "bindings/core/v8/V8DOMException.h"
10 #include "bindings/core/v8/V8DOMTokenList.h" 10 #include "bindings/core/v8/V8DOMTokenList.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 { 251 {
252 setMonitorEventsCallback(info, true); 252 setMonitorEventsCallback(info, true);
253 } 253 }
254 254
255 // static 255 // static
256 void ThreadDebugger::unmonitorEventsCallback(const v8::FunctionCallbackInfo<v8:: Value>& info) 256 void ThreadDebugger::unmonitorEventsCallback(const v8::FunctionCallbackInfo<v8:: Value>& info)
257 { 257 {
258 setMonitorEventsCallback(info, false); 258 setMonitorEventsCallback(info, false);
259 } 259 }
260 260
261 static void removeEventListenerCallback(const v8::FunctionCallbackInfo<v8::Value >& info)
262 {
263 v8::Isolate* isolate = info.GetIsolate();
264 v8::Local<v8::Context> context = isolate->GetCurrentContext();
265 EventTarget* eventTarget = V8EventTarget::toImplWithTypeCheck(isolate, info. Data());
266 if (!eventTarget)
267 return;
268 v8::Local<v8::Value> thisHandler;
269 if (!info.Holder()->Get(context, v8String(isolate, "listener")).ToLocal(&thi sHandler) || !thisHandler->IsObject())
270 return;
271 v8::Local<v8::Value> v8ThisType;
272 if (!info.Holder()->Get(context, v8String(isolate, "type")).ToLocal(&v8ThisT ype) || !v8ThisType->IsString())
273 return;
274 AtomicString thisType = AtomicString(toCoreString(v8::Local<v8::String>::Cas t(v8ThisType)));
275 v8::Local<v8::Value> thisUseCapture;
276 if (!info.Holder()->Get(context, v8String(isolate, "useCapture")).ToLocal(&t hisUseCapture) || !thisUseCapture->IsBoolean())
277 return;
278
279 EventListener* eventListener = V8EventListenerList::getEventListener(ScriptS tate::current(info.GetIsolate()), thisHandler, false, ListenerFindOnly);
280 if (!eventListener)
281 eventListener = V8EventListenerList::getEventListener(ScriptState::curre nt(info.GetIsolate()), thisHandler, true, ListenerFindOnly);
282 if (!eventListener)
283 return;
284 EventListenerOptions options;
285 options.setCapture(v8::Local<v8::Boolean>::Cast(thisUseCapture)->Value());
286 eventTarget->removeEventListener(thisType, eventListener, options);
287 }
288
289 // static 261 // static
290 void ThreadDebugger::getEventListenersCallback(const v8::FunctionCallbackInfo<v8 ::Value>& info) 262 void ThreadDebugger::getEventListenersCallback(const v8::FunctionCallbackInfo<v8 ::Value>& info)
291 { 263 {
292 if (info.Length() < 1) 264 if (info.Length() < 1)
293 return; 265 return;
294 266
295 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern al>::Cast(info.Data())->Value()); 267 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern al>::Cast(info.Data())->Value());
296 DCHECK(debugger); 268 DCHECK(debugger);
297 v8::Isolate* isolate = info.GetIsolate(); 269 v8::Isolate* isolate = info.GetIsolate();
298 v8::Local<v8::Context> context = isolate->GetCurrentContext();
299 270
300 V8EventListenerInfoList listenerInfo; 271 V8EventListenerInfoList listenerInfo;
301 // eventListeners call can produce message on ErrorEvent during lazy event l istener compilation. 272 // eventListeners call can produce message on ErrorEvent during lazy event l istener compilation.
302 debugger->muteWarningsAndDeprecations(); 273 debugger->muteWarningsAndDeprecations();
303 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis tenerInfo); 274 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis tenerInfo);
304 debugger->unmuteWarningsAndDeprecations(); 275 debugger->unmuteWarningsAndDeprecations();
305 276
306 v8::Local<v8::Object> result = v8::Object::New(isolate); 277 v8::Local<v8::Object> result = v8::Object::New(isolate);
307
308 v8::Local<v8::Function> removeFunc = v8::Function::New(isolate, removeEventL istenerCallback, info[0]);
309 v8::Local<v8::Function> toStringFunction;
310 if (v8::Function::New(context, returnDataCallback, v8String(isolate, "functi on remove() { [Command Line API] }")).ToLocal(&toStringFunction))
311 removeFunc->Set(v8String(context->GetIsolate(), "toString"), toStringFun ction);
312
313 AtomicString currentEventType; 278 AtomicString currentEventType;
314 v8::Local<v8::Array> listeners; 279 v8::Local<v8::Array> listeners;
315 size_t outputIndex = 0; 280 size_t outputIndex = 0;
316 for (auto& info : listenerInfo) { 281 for (auto& info : listenerInfo) {
317 if (currentEventType != info.eventType) { 282 if (currentEventType != info.eventType) {
318 currentEventType = info.eventType; 283 currentEventType = info.eventType;
319 listeners = v8::Array::New(isolate); 284 listeners = v8::Array::New(isolate);
320 outputIndex = 0; 285 outputIndex = 0;
321 result->Set(v8String(isolate, currentEventType), listeners); 286 result->Set(v8String(isolate, currentEventType), listeners);
322 } 287 }
323 288
324 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate); 289 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate);
325 listenerObject->Set(v8String(isolate, "listener"), info.handler); 290 listenerObject->Set(v8String(isolate, "listener"), info.handler);
326 listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(is olate, info.useCapture)); 291 listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(is olate, info.useCapture));
327 listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isola te, info.passive)); 292 listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isola te, info.passive));
328 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current EventType)); 293 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current EventType));
329 listenerObject->Set(v8String(isolate, "remove"), removeFunc); 294 v8::Local<v8::Function> removeFunction;
295 if (info.removeFunction.ToLocal(&removeFunction))
296 listenerObject->Set(v8String(isolate, "remove"), removeFunction);
330 listeners->Set(outputIndex++, listenerObject); 297 listeners->Set(outputIndex++, listenerObject);
331 } 298 }
332 info.GetReturnValue().Set(result); 299 info.GetReturnValue().Set(result);
333 } 300 }
334 301
335 void ThreadDebugger::reportMessageToConsole(v8::Local<v8::Context> context, Mess ageType type, MessageLevel level, const String16& message, const v8::FunctionCal lbackInfo<v8::Value>* arguments, unsigned skipArgumentCount) 302 void ThreadDebugger::reportMessageToConsole(v8::Local<v8::Context> context, Mess ageType type, MessageLevel level, const String16& message, const v8::FunctionCal lbackInfo<v8::Value>* arguments, unsigned skipArgumentCount)
336 { 303 {
337 ScriptState* scriptState = ScriptState::from(context); 304 ScriptState* scriptState = ScriptState::from(context);
338 ScriptArguments* scriptArguments = nullptr; 305 ScriptArguments* scriptArguments = nullptr;
339 if (arguments && scriptState->contextIsValid()) 306 if (arguments && scriptState->contextIsValid())
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 { 356 {
390 for (size_t index = 0; index < m_timers.size(); ++index) { 357 for (size_t index = 0; index < m_timers.size(); ++index) {
391 if (m_timers[index] == timer) { 358 if (m_timers[index] == timer) {
392 m_timerCallbacks[index](m_timerData[index]); 359 m_timerCallbacks[index](m_timerData[index]);
393 return; 360 return;
394 } 361 }
395 } 362 }
396 } 363 }
397 364
398 } // namespace blink 365 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698