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

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

Issue 1950403002: Add the ability to return descedant event listeners. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits 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/ScriptCallStack.h" 7 #include "bindings/core/v8/ScriptCallStack.h"
8 #include "bindings/core/v8/ScriptValue.h" 8 #include "bindings/core/v8/ScriptValue.h"
9 #include "bindings/core/v8/V8Binding.h" 9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/core/v8/V8DOMException.h" 10 #include "bindings/core/v8/V8DOMException.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 void ThreadDebugger::getEventListenersCallback(const v8::FunctionCallbackInfo<v8 ::Value>& info) 291 void ThreadDebugger::getEventListenersCallback(const v8::FunctionCallbackInfo<v8 ::Value>& info)
292 { 292 {
293 if (info.Length() < 1) 293 if (info.Length() < 1)
294 return; 294 return;
295 295
296 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern al>::Cast(info.Data())->Value()); 296 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern al>::Cast(info.Data())->Value());
297 DCHECK(debugger); 297 DCHECK(debugger);
298 v8::Isolate* isolate = info.GetIsolate(); 298 v8::Isolate* isolate = info.GetIsolate();
299 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 299 v8::Local<v8::Context> context = isolate->GetCurrentContext();
300 300
301 EventListenerFilter filterMask = EventListenerFilter::ShowPassive | EventLis tenerFilter::ShowBlocking;
302 if (info.Length() > 1 && info[1]->IsObject()) {
303 v8::Local<v8::Object> options = v8::Local<v8::Object>::Cast(info[1]);
304
305 v8::Local<v8::Value> setting;
306 if (options->Get(context, v8String(isolate, "descendants")).ToLocal(&set ting) && setting->IsTrue())
307 filterMask |= EventListenerFilter::ShowDescendants;
308
309 if (options->Get(context, v8String(isolate, "passive")).ToLocal(&setting ) && !setting->IsUndefined()) {
310 if (setting->IsFalse())
311 filterMask &= ~EventListenerFilter::ShowPassive;
312 else
313 filterMask &= ~EventListenerFilter::ShowBlocking;
314 }
315 }
316
301 V8EventListenerInfoList listenerInfo; 317 V8EventListenerInfoList listenerInfo;
302 // eventListeners call can produce message on ErrorEvent during lazy event l istener compilation. 318 // eventListeners call can produce message on ErrorEvent during lazy event l istener compilation.
303 debugger->muteWarningsAndDeprecations(); 319 debugger->muteWarningsAndDeprecations();
304 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis tenerInfo); 320 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], fil terMask, listenerInfo);
pfeldman 2016/05/27 21:54:01 We should not mix data from different worlds in th
dtapuska 2016/05/27 22:12:39 Yes there is a check inside the query. Is there so
pfeldman 2016/05/27 22:32:12 We want InspectorDOMDebuggerAgent::eventListenersI
dtapuska 2016/05/31 21:26:07 Can you be more explicit of which security checks?
305 debugger->unmuteWarningsAndDeprecations(); 321 debugger->unmuteWarningsAndDeprecations();
306 322
307 v8::Local<v8::Object> result = v8::Object::New(isolate); 323 v8::Local<v8::Object> result = v8::Object::New(isolate);
308 324
309 v8::Local<v8::Function> removeFunc = v8::Function::New(isolate, removeEventL istenerCallback, info[0]); 325 v8::Local<v8::Function> removeFunc = v8::Function::New(isolate, removeEventL istenerCallback, info[0]);
310 v8::Local<v8::Function> toStringFunction; 326 v8::Local<v8::Function> toStringFunction;
311 if (v8::Function::New(context, returnDataCallback, v8String(isolate, "functi on remove() { [Command Line API] }")).ToLocal(&toStringFunction)) 327 if (v8::Function::New(context, returnDataCallback, v8String(isolate, "functi on remove() { [Command Line API] }")).ToLocal(&toStringFunction))
312 removeFunc->Set(v8String(context->GetIsolate(), "toString"), toStringFun ction); 328 removeFunc->Set(v8String(context->GetIsolate(), "toString"), toStringFun ction);
313 329
314 AtomicString currentEventType; 330 AtomicString currentEventType;
315 v8::Local<v8::Array> listeners; 331 v8::Local<v8::Array> listeners;
316 size_t outputIndex = 0; 332 size_t outputIndex = 0;
317 for (auto& info : listenerInfo) { 333 for (auto& info : listenerInfo) {
318 if (currentEventType != info.eventType) { 334 if (currentEventType != info.eventType) {
319 currentEventType = info.eventType; 335 currentEventType = info.eventType;
320 listeners = v8::Array::New(isolate); 336 v8::Local<v8::Value> matchingList;
321 outputIndex = 0; 337 if (result->Get(context, v8String(isolate, currentEventType)).ToLoca l(&matchingList) && matchingList->IsArray()) {
322 result->Set(v8String(isolate, currentEventType), listeners); 338 listeners = v8::Local<v8::Array>::Cast(matchingList);
339 outputIndex = listeners->Length();
340 } else {
341 listeners = v8::Array::New(isolate);
342 outputIndex = 0;
343 result->Set(v8String(isolate, currentEventType), listeners);
344 }
323 } 345 }
324 346
325 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate); 347 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate);
326 listenerObject->Set(v8String(isolate, "listener"), info.handler); 348 listenerObject->Set(v8String(isolate, "listener"), info.handler);
327 listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(is olate, info.useCapture)); 349 listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(is olate, info.useCapture));
328 listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isola te, info.passive)); 350 listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isola te, info.passive));
329 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current EventType)); 351 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current EventType));
330 listenerObject->Set(v8String(isolate, "remove"), removeFunc); 352 listenerObject->Set(v8String(isolate, "remove"), removeFunc);
331 listeners->Set(outputIndex++, listenerObject); 353 listeners->Set(outputIndex++, listenerObject);
332 } 354 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 { 412 {
391 for (size_t index = 0; index < m_timers.size(); ++index) { 413 for (size_t index = 0; index < m_timers.size(); ++index) {
392 if (m_timers[index] == timer) { 414 if (m_timers[index] == timer) {
393 m_timerCallbacks[index](m_timerData[index]); 415 m_timerCallbacks[index](m_timerData[index]);
394 return; 416 return;
395 } 417 }
396 } 418 }
397 } 419 }
398 420
399 } // namespace blink 421 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698