Chromium Code Reviews| 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 v8::Isolate* isolate = info.GetIsolate(); | 159 v8::Isolate* isolate = info.GetIsolate(); |
| 163 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 160 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 164 | 161 |
| 165 Vector<String> types; | 162 Vector<String> types; |
| 166 if (info.Length() > 1 && info[1]->IsString()) | 163 if (info.Length() > 1 && info[1]->IsString()) |
| 167 types.append(toCoreString(info[1].As<v8::String>())); | 164 types.append(toCoreString(info[1].As<v8::String>())); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 if (!eventListener) | 246 if (!eventListener) |
| 250 return; | 247 return; |
| 251 for (size_t i = 0; i < types.size(); ++i) { | 248 for (size_t i = 0; i < types.size(); ++i) { |
| 252 if (enabled) | 249 if (enabled) |
| 253 eventTarget->addEventListener(AtomicString(types[i]), eventListener, false); | 250 eventTarget->addEventListener(AtomicString(types[i]), eventListener, false); |
| 254 else | 251 else |
| 255 eventTarget->removeEventListener(AtomicString(types[i]), eventListen er, false); | 252 eventTarget->removeEventListener(AtomicString(types[i]), eventListen er, false); |
| 256 } | 253 } |
| 257 } | 254 } |
| 258 | 255 |
| 256 static void removeEventListenerCallback(const v8::FunctionCallbackInfo<v8::Value >& info) | |
| 257 { | |
| 258 v8::Isolate* isolate = info.GetIsolate(); | |
| 259 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
| 260 EventTarget* eventTarget = V8EventTarget::toImplWithTypeCheck(isolate, info. Data()); | |
| 261 if (!eventTarget) | |
| 262 return; | |
| 263 v8::Local<v8::Value> thisHandler; | |
| 264 if (!info.Holder()->Get(context, v8String(isolate, "listener")).ToLocal(&thi sHandler) || !thisHandler->IsObject()) | |
| 265 return; | |
| 266 v8::Local<v8::Value> v8ThisType; | |
| 267 if (!info.Holder()->Get(context, v8String(isolate, "type")).ToLocal(&v8ThisT ype) || !v8ThisType->IsString()) | |
| 268 return; | |
| 269 AtomicString thisType = AtomicString(toCoreString(v8::Local<v8::String>::Cas t(v8ThisType))); | |
| 270 v8::Local<v8::Value> thisUseCapture; | |
| 271 if (!info.Holder()->Get(context, v8String(isolate, "useCapture")).ToLocal(&t hisUseCapture) || !thisUseCapture->IsBoolean()) | |
| 272 return; | |
| 273 | |
| 274 EventListener* eventListener = V8EventListenerList::getEventListener(ScriptS tate::current(info.GetIsolate()), thisHandler, false, ListenerFindOnly); | |
| 275 if (!eventListener) | |
| 276 eventListener = V8EventListenerList::getEventListener(ScriptState::curre nt(info.GetIsolate()), thisHandler, true, ListenerFindOnly); | |
| 277 if (!eventListener) | |
| 278 return; | |
| 279 EventListenerOptions options; | |
| 280 options.setCapture(v8::Local<v8::Boolean>::Cast(thisUseCapture)->Value()); | |
|
dgozman
2016/05/20 18:48:21
// TODO(dtapuska): we should pass "passive" flag a
dtapuska
2016/05/20 18:50:50
No remove; doesn't have a passive flag. It isn't a
kozy
2016/05/20 18:56:59
Done.
| |
| 281 eventTarget->removeEventListener(thisType, eventListener, options); | |
| 282 } | |
| 283 | |
| 284 // static | |
| 285 void ThreadDebugger::getEventListenersCallback(const v8::FunctionCallbackInfo<v8 ::Value>& info) | |
| 286 { | |
| 287 if (info.Length() < 1) | |
| 288 return; | |
| 289 | |
| 290 ThreadDebugger* debugger = static_cast<ThreadDebugger*>(v8::Local<v8::Extern al>::Cast(info.Data())->Value()); | |
| 291 DCHECK(debugger); | |
| 292 v8::Isolate* isolate = info.GetIsolate(); | |
| 293 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
| 294 | |
| 295 V8EventListenerInfoList listenerInfo; | |
| 296 // eventListeners call can produce message on ErrorEvent during lazy event l istener compilation. | |
| 297 debugger->muteWarningsAndDeprecations(); | |
| 298 InspectorDOMDebuggerAgent::eventListenersInfoForTarget(isolate, info[0], lis tenerInfo); | |
| 299 debugger->unmuteWarningsAndDeprecations(); | |
| 300 | |
| 301 v8::Local<v8::Object> result = v8::Object::New(isolate); | |
| 302 | |
| 303 v8::Local<v8::Function> removeFunc = v8::Function::New(isolate, removeEventL istenerCallback, info[0]); | |
| 304 v8::Local<v8::Function> toStringFunction; | |
| 305 if (v8::Function::New(context, returnDataCallback, v8String(isolate, "functi on remove() { [Command Line API] }")).ToLocal(&toStringFunction)) | |
| 306 removeFunc->Set(v8String(context->GetIsolate(), "toString"), toStringFun ction); | |
| 307 | |
| 308 AtomicString currentEventType; | |
| 309 v8::Local<v8::Array> listeners; | |
| 310 size_t outputIndex = 0; | |
| 311 for (auto& info : listenerInfo) { | |
| 312 if (currentEventType != info.eventType) { | |
| 313 currentEventType = info.eventType; | |
| 314 listeners = v8::Array::New(isolate); | |
| 315 outputIndex = 0; | |
| 316 result->Set(v8String(isolate, currentEventType), listeners); | |
| 317 } | |
| 318 | |
| 319 v8::Local<v8::Object> listenerObject = v8::Object::New(isolate); | |
| 320 listenerObject->Set(v8String(isolate, "listener"), info.handler); | |
| 321 listenerObject->Set(v8String(isolate, "useCapture"), v8::Boolean::New(is olate, info.useCapture)); | |
| 322 listenerObject->Set(v8String(isolate, "passive"), v8::Boolean::New(isola te, info.passive)); | |
| 323 listenerObject->Set(v8String(isolate, "type"), v8String(isolate, current EventType)); | |
| 324 listenerObject->Set(v8String(isolate, "remove"), removeFunc); | |
| 325 listeners->Set(outputIndex++, listenerObject); | |
| 326 } | |
| 327 info.GetReturnValue().Set(result); | |
| 328 } | |
| 329 | |
| 259 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) | 330 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) |
| 260 { | 331 { |
| 261 ScriptState* scriptState = ScriptState::from(context); | 332 ScriptState* scriptState = ScriptState::from(context); |
| 262 ScriptArguments* scriptArguments = nullptr; | 333 ScriptArguments* scriptArguments = nullptr; |
| 263 if (arguments && scriptState->contextIsValid()) | 334 if (arguments && scriptState->contextIsValid()) |
| 264 scriptArguments = ScriptArguments::create(scriptState, *arguments, skipA rgumentCount); | 335 scriptArguments = ScriptArguments::create(scriptState, *arguments, skipA rgumentCount); |
| 265 String messageText = message; | 336 String messageText = message; |
| 266 if (messageText.isEmpty() && scriptArguments) | 337 if (messageText.isEmpty() && scriptArguments) |
| 267 scriptArguments->getFirstArgumentAsString(messageText); | 338 scriptArguments->getFirstArgumentAsString(messageText); |
| 268 | 339 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 { | 389 { |
| 319 for (size_t index = 0; index < m_timers.size(); ++index) { | 390 for (size_t index = 0; index < m_timers.size(); ++index) { |
| 320 if (m_timers[index] == timer) { | 391 if (m_timers[index] == timer) { |
| 321 m_timerCallbacks[index](m_timerData[index]); | 392 m_timerCallbacks[index](m_timerData[index]); |
| 322 return; | 393 return; |
| 323 } | 394 } |
| 324 } | 395 } |
| 325 } | 396 } |
| 326 | 397 |
| 327 } // namespace blink | 398 } // namespace blink |
| OLD | NEW |