| OLD | NEW |
| 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" |
| 11 #include "bindings/core/v8/V8DOMTokenList.h" | 11 #include "bindings/core/v8/V8DOMTokenList.h" |
| 12 #include "bindings/core/v8/V8Event.h" | 12 #include "bindings/core/v8/V8Event.h" |
| 13 #include "bindings/core/v8/V8EventListener.h" | 13 #include "bindings/core/v8/V8EventListener.h" |
| 14 #include "bindings/core/v8/V8EventListenerInfo.h" |
| 14 #include "bindings/core/v8/V8EventListenerList.h" | 15 #include "bindings/core/v8/V8EventListenerList.h" |
| 15 #include "bindings/core/v8/V8HTMLAllCollection.h" | 16 #include "bindings/core/v8/V8HTMLAllCollection.h" |
| 16 #include "bindings/core/v8/V8HTMLCollection.h" | 17 #include "bindings/core/v8/V8HTMLCollection.h" |
| 17 #include "bindings/core/v8/V8Node.h" | 18 #include "bindings/core/v8/V8Node.h" |
| 18 #include "bindings/core/v8/V8NodeList.h" | 19 #include "bindings/core/v8/V8NodeList.h" |
| 19 #include "core/inspector/ConsoleMessage.h" | 20 #include "core/inspector/ConsoleMessage.h" |
| 20 #include "core/inspector/InspectorDOMDebuggerAgent.h" | 21 #include "core/inspector/InspectorDOMDebuggerAgent.h" |
| 21 #include "core/inspector/InspectorTraceEvents.h" | 22 #include "core/inspector/InspectorTraceEvents.h" |
| 22 #include "core/inspector/ScriptArguments.h" | 23 #include "core/inspector/ScriptArguments.h" |
| 23 #include "platform/ScriptForbiddenScope.h" | 24 #include "platform/ScriptForbiddenScope.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 void ThreadDebugger::beginUserGesture() | 67 void ThreadDebugger::beginUserGesture() |
| 67 { | 68 { |
| 68 m_userGestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcess
ingNewUserGesture)); | 69 m_userGestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcess
ingNewUserGesture)); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void ThreadDebugger::endUserGesture() | 72 void ThreadDebugger::endUserGesture() |
| 72 { | 73 { |
| 73 m_userGestureIndicator.clear(); | 74 m_userGestureIndicator.clear(); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void ThreadDebugger::eventListeners(v8::Local<v8::Value> value, V8EventListenerI
nfoList& result) | |
| 77 { | |
| 78 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(m_isolate, value, res
ult); | |
| 79 } | |
| 80 | |
| 81 String16 ThreadDebugger::valueSubtype(v8::Local<v8::Value> value) | 77 String16 ThreadDebugger::valueSubtype(v8::Local<v8::Value> value) |
| 82 { | 78 { |
| 83 if (V8Node::hasInstance(value, m_isolate)) | 79 if (V8Node::hasInstance(value, m_isolate)) |
| 84 return "node"; | 80 return "node"; |
| 85 if (V8NodeList::hasInstance(value, m_isolate) | 81 if (V8NodeList::hasInstance(value, m_isolate) |
| 86 || V8DOMTokenList::hasInstance(value, m_isolate) | 82 || V8DOMTokenList::hasInstance(value, m_isolate) |
| 87 || V8HTMLCollection::hasInstance(value, m_isolate) | 83 || V8HTMLCollection::hasInstance(value, m_isolate) |
| 88 || V8HTMLAllCollection::hasInstance(value, m_isolate)) { | 84 || V8HTMLAllCollection::hasInstance(value, m_isolate)) { |
| 89 return "array"; | 85 return "array"; |
| 90 } | 86 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 if (v8::Function::New(context, returnDataCallback, returnValue).ToLocal(&toS
tringFunction)) | 133 if (v8::Function::New(context, returnDataCallback, returnValue).ToLocal(&toS
tringFunction)) |
| 138 func->Set(v8String(context->GetIsolate(), "toString"), toStringFunction)
; | 134 func->Set(v8String(context->GetIsolate(), "toString"), toStringFunction)
; |
| 139 if (!object->Set(context, funcName, func).FromMaybe(false)) | 135 if (!object->Set(context, funcName, func).FromMaybe(false)) |
| 140 return; | 136 return; |
| 141 } | 137 } |
| 142 | 138 |
| 143 bool ThreadDebugger::isCommandLineAPIMethod(const String& name) | 139 bool ThreadDebugger::isCommandLineAPIMethod(const String& name) |
| 144 { | 140 { |
| 145 DEFINE_STATIC_LOCAL(HashSet<String>, methods, ()); | 141 DEFINE_STATIC_LOCAL(HashSet<String>, methods, ()); |
| 146 if (methods.size() == 0) { | 142 if (methods.size() == 0) { |
| 147 const char* members[] = { "monitorEvents", "unmonitorEvents" }; | 143 const char* members[] = { "monitorEvents", "unmonitorEvents", "getEventL
isteners" }; |
| 148 for (size_t i = 0; i < WTF_ARRAY_LENGTH(members); ++i) | 144 for (size_t i = 0; i < WTF_ARRAY_LENGTH(members); ++i) |
| 149 methods.add(members[i]); | 145 methods.add(members[i]); |
| 150 } | 146 } |
| 151 return methods.find(name) != methods.end() || V8Debugger::isCommandLineAPIMe
thod(name); | 147 return methods.find(name) != methods.end() || V8Debugger::isCommandLineAPIMe
thod(name); |
| 152 } | 148 } |
| 153 | 149 |
| 154 void ThreadDebugger::installAdditionalCommandLineAPI(v8::Local<v8::Context> cont
ext, v8::Local<v8::Object> object) | 150 void ThreadDebugger::installAdditionalCommandLineAPI(v8::Local<v8::Context> cont
ext, v8::Local<v8::Object> object) |
| 155 { | 151 { |
| 156 createFunctionProperty(context, object, "monitorEvents", ThreadDebugger::mon
itorEventsCallback, "function monitorEvents(object, [types]) { [Command Line API
] }"); | 152 createFunctionProperty(context, object, "monitorEvents", ThreadDebugger::mon
itorEventsCallback, "function monitorEvents(object, [types]) { [Command Line API
] }"); |
| 157 createFunctionProperty(context, object, "unmonitorEvents", ThreadDebugger::u
nmonitorEventsCallback, "function unmonitorEvents(object, [types]) { [Command Li
ne API] }"); | 153 createFunctionProperty(context, object, "unmonitorEvents", ThreadDebugger::u
nmonitorEventsCallback, "function unmonitorEvents(object, [types]) { [Command Li
ne API] }"); |
| 154 createFunctionProperty(context, object, "getEventListeners", ThreadDebugger:
:getEventListenersCallback, "function getEventListeners(node) { [Command Line AP
I] }"); |
| 158 } | 155 } |
| 159 | 156 |
| 160 static Vector<String> normalizeEventTypes(const v8::FunctionCallbackInfo<v8::Val
ue>& info) | 157 static Vector<String> normalizeEventTypes(const v8::FunctionCallbackInfo<v8::Val
ue>& info) |
| 161 { | 158 { |
| 162 Vector<String> types; | 159 Vector<String> types; |
| 163 if (info.Length() > 1 && info[1]->IsString()) | 160 if (info.Length() > 1 && info[1]->IsString()) |
| 164 types.append(toCoreString(info[1].As<v8::String>())); | 161 types.append(toCoreString(info[1].As<v8::String>())); |
| 165 if (info.Length() > 1 && info[1]->IsArray()) { | 162 if (info.Length() > 1 && info[1]->IsArray()) { |
| 166 v8::Local<v8::Array> typesArray = v8::Local<v8::Array>::Cast(info[1]); | 163 v8::Local<v8::Array> typesArray = v8::Local<v8::Array>::Cast(info[1]); |
| 167 for (size_t i = 0; i < typesArray->Length(); ++i) { | 164 for (size_t i = 0; i < typesArray->Length(); ++i) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 { | 254 { |
| 258 setMonitorEventsCallback(info, true); | 255 setMonitorEventsCallback(info, true); |
| 259 } | 256 } |
| 260 | 257 |
| 261 // static | 258 // static |
| 262 void ThreadDebugger::unmonitorEventsCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) | 259 void ThreadDebugger::unmonitorEventsCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) |
| 263 { | 260 { |
| 264 setMonitorEventsCallback(info, false); | 261 setMonitorEventsCallback(info, false); |
| 265 } | 262 } |
| 266 | 263 |
| 264 static void removeEventListenerCallback(const v8::FunctionCallbackInfo<v8::Value
>& info) |
| 265 { |
| 266 v8::Isolate* isolate = info.GetIsolate(); |
| 267 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 268 EventTarget* eventTarget = V8EventTarget::toImplWithTypeCheck(isolate, info.
Data()); |
| 269 if (!eventTarget) |
| 270 return; |
| 271 v8::Local<v8::Value> thisHandler; |
| 272 if (!info.Holder()->Get(context, v8String(isolate, "listener")).ToLocal(&thi
sHandler) || !thisHandler->IsObject()) |
| 273 return; |
| 274 v8::Local<v8::Value> v8ThisType; |
| 275 if (!info.Holder()->Get(context, v8String(isolate, "type")).ToLocal(&v8ThisT
ype) || !v8ThisType->IsString()) |
| 276 return; |
| 277 AtomicString thisType = AtomicString(toCoreString(v8::Local<v8::String>::Cas
t(v8ThisType))); |
| 278 v8::Local<v8::Value> thisUseCapture; |
| 279 if (!info.Holder()->Get(context, v8String(isolate, "useCapture")).ToLocal(&t
hisUseCapture) || !thisUseCapture->IsBoolean()) |
| 280 return; |
| 281 |
| 282 EventListener* eventListener = V8EventListenerList::getEventListener(ScriptS
tate::current(info.GetIsolate()), thisHandler, false, ListenerFindOnly); |
| 283 if (!eventListener) |
| 284 eventListener = V8EventListenerList::getEventListener(ScriptState::curre
nt(info.GetIsolate()), thisHandler, true, ListenerFindOnly); |
| 285 if (!eventListener) |
| 286 return; |
| 287 EventListenerOptions options; |
| 288 options.setCapture(v8::Local<v8::Boolean>::Cast(thisUseCapture)->Value()); |
| 289 eventTarget->removeEventListener(thisType, eventListener, options); |
| 290 } |
| 291 |
| 292 // static |
| 293 void ThreadDebugger::getEventListenersCallback(const v8::FunctionCallbackInfo<v8
::Value>& info) |
| 294 { |
| 295 if (info.Length() < 1) |
| 296 return; |
| 297 |
| 298 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern
al>::Cast(info.Data())->Value()); |
| 299 DCHECK(debugger); |
| 300 v8::Isolate* isolate = info.GetIsolate(); |
| 301 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 302 |
| 303 V8EventListenerInfoList listenerInfo; |
| 304 // eventListeners call can produce message on ErrorEvent during lazy event l
istener compilation. |
| 305 debugger->muteWarningsAndDeprecations(); |
| 306 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis
tenerInfo); |
| 307 debugger->unmuteWarningsAndDeprecations(); |
| 308 |
| 309 v8::Local<v8::Object> result = v8::Object::New(isolate); |
| 310 |
| 311 v8::Local<v8::Function> removeFunc = v8::Function::New(isolate, removeEventL
istenerCallback, info[0]); |
| 312 v8::Local<v8::Function> toStringFunction; |
| 313 if (v8::Function::New(context, returnDataCallback, v8String(isolate, "functi
on remove() { [Command Line API] }")).ToLocal(&toStringFunction)) |
| 314 removeFunc->Set(v8String(context->GetIsolate(), "toString"), toStringFun
ction); |
| 315 |
| 316 AtomicString currentEventType; |
| 317 v8::Local<v8::Array> listeners; |
| 318 size_t outputIndex = 0; |
| 319 for (auto& info : listenerInfo) { |
| 320 if (currentEventType != info.eventType) { |
| 321 currentEventType = info.eventType; |
| 322 listeners = v8::Array::New(isolate); |
| 323 outputIndex = 0; |
| 324 result->Set(v8String(isolate, currentEventType), listeners); |
| 325 } |
| 326 |
| 327 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate); |
| 328 listenerObject->Set(v8String(isolate, "listener"), info.handler); |
| 329 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)); |
| 331 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current
EventType)); |
| 332 listenerObject->Set(v8String(isolate, "remove"), removeFunc); |
| 333 listeners->Set(outputIndex++, listenerObject); |
| 334 } |
| 335 info.GetReturnValue().Set(result); |
| 336 } |
| 337 |
| 267 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) | 338 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) |
| 268 { | 339 { |
| 269 ScriptState* scriptState = ScriptState::from(context); | 340 ScriptState* scriptState = ScriptState::from(context); |
| 270 ScriptArguments* scriptArguments = nullptr; | 341 ScriptArguments* scriptArguments = nullptr; |
| 271 if (arguments && scriptState->contextIsValid()) | 342 if (arguments && scriptState->contextIsValid()) |
| 272 scriptArguments = ScriptArguments::create(scriptState, *arguments, skipA
rgumentCount); | 343 scriptArguments = ScriptArguments::create(scriptState, *arguments, skipA
rgumentCount); |
| 273 String messageText = message; | 344 String messageText = message; |
| 274 if (messageText.isEmpty() && scriptArguments) | 345 if (messageText.isEmpty() && scriptArguments) |
| 275 scriptArguments->getFirstArgumentAsString(messageText); | 346 scriptArguments->getFirstArgumentAsString(messageText); |
| 276 | 347 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 { | 397 { |
| 327 for (size_t index = 0; index < m_timers.size(); ++index) { | 398 for (size_t index = 0; index < m_timers.size(); ++index) { |
| 328 if (m_timers[index] == timer) { | 399 if (m_timers[index] == timer) { |
| 329 m_timerCallbacks[index](m_timerData[index]); | 400 m_timerCallbacks[index](m_timerData[index]); |
| 330 return; | 401 return; |
| 331 } | 402 } |
| 332 } | 403 } |
| 333 } | 404 } |
| 334 | 405 |
| 335 } // namespace blink | 406 } // namespace blink |
| OLD | NEW |