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

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

Issue 2035653006: [DevTools] Move Console to v8 inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: improved api a bit Created 4 years, 5 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"
11 #include "bindings/core/v8/V8Event.h" 11 #include "bindings/core/v8/V8Event.h"
12 #include "bindings/core/v8/V8EventListener.h" 12 #include "bindings/core/v8/V8EventListener.h"
13 #include "bindings/core/v8/V8EventListenerInfo.h" 13 #include "bindings/core/v8/V8EventListenerInfo.h"
14 #include "bindings/core/v8/V8EventListenerList.h" 14 #include "bindings/core/v8/V8EventListenerList.h"
15 #include "bindings/core/v8/V8HTMLAllCollection.h" 15 #include "bindings/core/v8/V8HTMLAllCollection.h"
16 #include "bindings/core/v8/V8HTMLCollection.h" 16 #include "bindings/core/v8/V8HTMLCollection.h"
17 #include "bindings/core/v8/V8Node.h" 17 #include "bindings/core/v8/V8Node.h"
18 #include "bindings/core/v8/V8NodeList.h" 18 #include "bindings/core/v8/V8NodeList.h"
19 #include "core/inspector/ConsoleMessage.h" 19 #include "core/inspector/ConsoleMessage.h"
20 #include "core/inspector/InspectorDOMDebuggerAgent.h" 20 #include "core/inspector/InspectorDOMDebuggerAgent.h"
21 #include "core/inspector/InspectorTraceEvents.h" 21 #include "core/inspector/InspectorTraceEvents.h"
22 #include "core/inspector/ScriptArguments.h"
23 #include "platform/ScriptForbiddenScope.h" 22 #include "platform/ScriptForbiddenScope.h"
24 #include "wtf/CurrentTime.h" 23 #include "wtf/CurrentTime.h"
25 #include "wtf/PtrUtil.h" 24 #include "wtf/PtrUtil.h"
26 #include <memory> 25 #include <memory>
27 26
28 namespace blink { 27 namespace blink {
29 28
30 ThreadDebugger::ThreadDebugger(v8::Isolate* isolate) 29 ThreadDebugger::ThreadDebugger(v8::Isolate* isolate)
31 : m_isolate(isolate) 30 : m_isolate(isolate)
32 , m_debugger(V8Debugger::create(isolate, this)) 31 , m_debugger(V8Debugger::create(isolate, this))
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 228
230 void ThreadDebugger::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info ) 229 void ThreadDebugger::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info )
231 { 230 {
232 if (info.Length() < 1) 231 if (info.Length() < 1)
233 return; 232 return;
234 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern al>::Cast(info.Data())->Value()); 233 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern al>::Cast(info.Data())->Value());
235 DCHECK(debugger); 234 DCHECK(debugger);
236 Event* event = V8Event::toImplWithTypeCheck(info.GetIsolate(), info[0]); 235 Event* event = V8Event::toImplWithTypeCheck(info.GetIsolate(), info[0]);
237 if (!event) 236 if (!event)
238 return; 237 return;
239 238 debugger->debugger()->logToConsole(info.GetIsolate()->GetCurrentContext(), e vent->type(), v8String(info.GetIsolate(), event->type()), info[0]);
240 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
241 ScriptState* scriptState = ScriptState::from(context);
242 DCHECK(scriptState->contextIsValid());
243 Vector<ScriptValue> arguments = Vector<ScriptValue>({
244 ScriptValue(scriptState, v8String(info.GetIsolate(), event->type())),
245 ScriptValue(scriptState, info[0])
246 });
247
248 ConsoleMessage* consoleMessage = ConsoleMessage::createForConsoleAPI(LogMess ageLevel, LogMessageType, event->type(), ScriptArguments::create(scriptState, ar guments));
249 debugger->reportMessageToConsole(context, consoleMessage);
250 } 239 }
251 240
252 v8::Local<v8::Function> ThreadDebugger::eventLogFunction() 241 v8::Local<v8::Function> ThreadDebugger::eventLogFunction()
253 { 242 {
254 if (m_eventLogFunction.IsEmpty()) 243 if (m_eventLogFunction.IsEmpty())
255 m_eventLogFunction.Reset(m_isolate, v8::Function::New(m_isolate, logCall back, v8::External::New(m_isolate, this))); 244 m_eventLogFunction.Reset(m_isolate, v8::Function::New(m_isolate, logCall back, v8::External::New(m_isolate, this)));
256 return m_eventLogFunction.Get(m_isolate); 245 return m_eventLogFunction.Get(m_isolate);
257 } 246 }
258 247
259 static EventTarget* firstArgumentAsEventTarget(const v8::FunctionCallbackInfo<v8 ::Value>& info) 248 static EventTarget* firstArgumentAsEventTarget(const v8::FunctionCallbackInfo<v8 ::Value>& info)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 if (info.Length() < 1) 291 if (info.Length() < 1)
303 return; 292 return;
304 293
305 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern al>::Cast(info.Data())->Value()); 294 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern al>::Cast(info.Data())->Value());
306 DCHECK(debugger); 295 DCHECK(debugger);
307 v8::Isolate* isolate = info.GetIsolate(); 296 v8::Isolate* isolate = info.GetIsolate();
308 297
309 V8EventListenerInfoList listenerInfo; 298 V8EventListenerInfoList listenerInfo;
310 // eventListeners call can produce message on ErrorEvent during lazy event l istener compilation. 299 // eventListeners call can produce message on ErrorEvent during lazy event l istener compilation.
311 debugger->muteWarningsAndDeprecations(); 300 debugger->muteWarningsAndDeprecations();
301 debugger->debugger()->muteConsole();
312 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis tenerInfo); 302 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis tenerInfo);
303 debugger->debugger()->unmuteConsole();
313 debugger->unmuteWarningsAndDeprecations(); 304 debugger->unmuteWarningsAndDeprecations();
314 305
315 v8::Local<v8::Object> result = v8::Object::New(isolate); 306 v8::Local<v8::Object> result = v8::Object::New(isolate);
316 AtomicString currentEventType; 307 AtomicString currentEventType;
317 v8::Local<v8::Array> listeners; 308 v8::Local<v8::Array> listeners;
318 size_t outputIndex = 0; 309 size_t outputIndex = 0;
319 for (auto& info : listenerInfo) { 310 for (auto& info : listenerInfo) {
320 if (currentEventType != info.eventType) { 311 if (currentEventType != info.eventType) {
321 currentEventType = info.eventType; 312 currentEventType = info.eventType;
322 listeners = v8::Array::New(isolate); 313 listeners = v8::Array::New(isolate);
323 outputIndex = 0; 314 outputIndex = 0;
324 result->Set(v8String(isolate, currentEventType), listeners); 315 result->Set(v8String(isolate, currentEventType), listeners);
325 } 316 }
326 317
327 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate); 318 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate);
328 listenerObject->Set(v8String(isolate, "listener"), info.handler); 319 listenerObject->Set(v8String(isolate, "listener"), info.handler);
329 listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(is olate, info.useCapture)); 320 listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(is olate, info.useCapture));
330 listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isola te, info.passive)); 321 listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isola te, info.passive));
331 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current EventType)); 322 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current EventType));
332 v8::Local<v8::Function> removeFunction; 323 v8::Local<v8::Function> removeFunction;
333 if (info.removeFunction.ToLocal(&removeFunction)) 324 if (info.removeFunction.ToLocal(&removeFunction))
334 listenerObject->Set(v8String(isolate, "remove"), removeFunction); 325 listenerObject->Set(v8String(isolate, "remove"), removeFunction);
335 listeners->Set(outputIndex++, listenerObject); 326 listeners->Set(outputIndex++, listenerObject);
336 } 327 }
337 info.GetReturnValue().Set(result); 328 info.GetReturnValue().Set(result);
338 } 329 }
339 330
340 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)
341 {
342 ScriptState* scriptState = ScriptState::from(context);
343 ScriptArguments* scriptArguments = nullptr;
344 if (arguments && scriptState->contextIsValid())
345 scriptArguments = ScriptArguments::create(scriptState, *arguments, skipA rgumentCount);
346 String messageText = message;
347 if (messageText.isEmpty() && scriptArguments)
348 scriptArguments->getFirstArgumentAsString(messageText);
349
350 reportMessageToConsole(context, ConsoleMessage::createForConsoleAPI(level, t ype, messageText, scriptArguments));
351 }
352
353 void ThreadDebugger::consoleTime(const String16& title) 331 void ThreadDebugger::consoleTime(const String16& title)
354 { 332 {
355 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", String(title).utf8().data(), this); 333 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", String(title).utf8().data(), this);
356 } 334 }
357 335
358 void ThreadDebugger::consoleTimeEnd(const String16& title) 336 void ThreadDebugger::consoleTimeEnd(const String16& title)
359 { 337 {
360 TRACE_EVENT_COPY_ASYNC_END0("blink.console", String(title).utf8().data(), th is); 338 TRACE_EVENT_COPY_ASYNC_END0("blink.console", String(title).utf8().data(), th is);
361 } 339 }
362 340
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 { 372 {
395 for (size_t index = 0; index < m_timers.size(); ++index) { 373 for (size_t index = 0; index < m_timers.size(); ++index) {
396 if (m_timers[index].get() == timer) { 374 if (m_timers[index].get() == timer) {
397 m_timerCallbacks[index](m_timerData[index]); 375 m_timerCallbacks[index](m_timerData[index]);
398 return; 376 return;
399 } 377 }
400 } 378 }
401 } 379 }
402 380
403 } // namespace blink 381 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698