Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/v8_inspector/V8InjectedScriptHost.h" | 5 #include "platform/v8_inspector/V8InjectedScriptHost.h" |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/String16.h" | 7 #include "platform/inspector_protocol/String16.h" |
| 8 #include "platform/inspector_protocol/Values.h" | 8 #include "platform/inspector_protocol/Values.h" |
| 9 #include "platform/v8_inspector/InjectedScript.h" | 9 #include "platform/v8_inspector/InjectedScript.h" |
| 10 #include "platform/v8_inspector/InjectedScriptHost.h" | 10 #include "platform/v8_inspector/InjectedScriptHost.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb ackInfo<v8::Value>& info) | 214 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb ackInfo<v8::Value>& info) |
| 215 { | 215 { |
| 216 if (info.Length() < 1 || !info[0]->IsObject()) | 216 if (info.Length() < 1 || !info[0]->IsObject()) |
| 217 return; | 217 return; |
| 218 | 218 |
| 219 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); | 219 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); |
| 220 v8::MaybeLocal<v8::Array> properties = v8::Debug::GetInternalProperties(info .GetIsolate(), object); | 220 v8::MaybeLocal<v8::Array> properties = v8::Debug::GetInternalProperties(info .GetIsolate(), object); |
| 221 v8SetReturnValue(info, properties); | 221 v8SetReturnValue(info, properties); |
| 222 } | 222 } |
| 223 | 223 |
| 224 static v8::Local<v8::Array> wrapListenerFunctions(v8::Isolate* isolate, const pr otocol::Vector<V8EventListenerInfo>& listeners) | 224 static v8::Local<v8::Array> wrapListenerFunctions(v8::Isolate* isolate, const V8 EventListenerInfoList& listeners, const String16& type) |
| 225 { | 225 { |
| 226 v8::Local<v8::Array> result = v8::Array::New(isolate); | 226 v8::Local<v8::Array> result = v8::Array::New(isolate); |
| 227 size_t handlersCount = listeners.size(); | 227 size_t handlersCount = listeners.size(); |
| 228 for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) { | 228 for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) { |
| 229 if (listeners[i].eventType != type) | |
| 230 continue; | |
| 229 v8::Local<v8::Object> function = listeners[i].handler; | 231 v8::Local<v8::Object> function = listeners[i].handler; |
| 230 v8::Local<v8::Object> listenerEntry = v8::Object::New(isolate); | 232 v8::Local<v8::Object> listenerEntry = v8::Object::New(isolate); |
| 231 listenerEntry->Set(toV8StringInternalized(isolate, "listener"), function ); | 233 listenerEntry->Set(toV8StringInternalized(isolate, "listener"), function ); |
| 232 listenerEntry->Set(toV8StringInternalized(isolate, "useCapture"), v8::Bo olean::New(isolate, listeners[i].useCapture)); | 234 listenerEntry->Set(toV8StringInternalized(isolate, "useCapture"), v8::Bo olean::New(isolate, listeners[i].useCapture)); |
| 233 result->Set(v8::Number::New(isolate, outputIndex++), listenerEntry); | 235 result->Set(v8::Number::New(isolate, outputIndex++), listenerEntry); |
| 234 } | 236 } |
| 235 return result; | 237 return result; |
| 236 } | 238 } |
| 237 | 239 |
| 238 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) | 240 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) |
| 239 { | 241 { |
| 240 if (info.Length() < 1) | 242 if (info.Length() < 1) |
| 241 return; | 243 return; |
| 242 | 244 |
| 243 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G etCurrentContext(), info.Holder()); | 245 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G etCurrentContext(), info.Holder()); |
| 244 if (!host->debugger()) | 246 if (!host->debugger()) |
| 245 return; | 247 return; |
| 246 V8DebuggerClient* client = host->debugger()->client(); | 248 V8DebuggerClient* client = host->debugger()->client(); |
| 247 V8EventListenerInfoMap listenerInfo; | 249 V8EventListenerInfoList listenerInfo; |
| 248 client->eventListeners(info[0], listenerInfo); | 250 client->eventListeners(info[0], listenerInfo); |
| 249 | 251 |
| 250 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); | 252 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); |
| 251 protocol::Vector<String16> types; | 253 protocol::Vector<String16> types; |
|
dgozman
2016/03/10 18:59:47
Should be a set now.
pfeldman
2016/03/10 23:30:10
Done.
| |
| 252 for (auto& it : listenerInfo) | 254 for (auto& info : listenerInfo) |
| 253 types.append(it.first); | 255 types.append(info.eventType); |
| 254 std::sort(types.begin(), types.end(), String16::codePointCompareLessThan); | |
| 255 for (const String16& type : types) { | 256 for (const String16& type : types) { |
| 256 v8::Local<v8::Array> listeners = wrapListenerFunctions(info.GetIsolate() , *listenerInfo.get(type)); | 257 v8::Local<v8::Array> listeners = wrapListenerFunctions(info.GetIsolate() , listenerInfo, type); |
| 257 if (!listeners->Length()) | 258 if (!listeners->Length()) |
| 258 continue; | 259 continue; |
| 259 result->Set(toV8String(info.GetIsolate(), type), listeners); | 260 result->Set(toV8String(info.GetIsolate(), type), listeners); |
| 260 } | 261 } |
| 261 | 262 |
| 262 v8SetReturnValue(info, result); | 263 v8SetReturnValue(info, result); |
| 263 } | 264 } |
| 264 | 265 |
| 265 void V8InjectedScriptHost::inspectCallback(const v8::FunctionCallbackInfo<v8::Va lue>& info) | 266 void V8InjectedScriptHost::inspectCallback(const v8::FunctionCallbackInfo<v8::Va lue>& info) |
| 266 { | 267 { |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 { | 603 { |
| 603 return InjectedScriptHostWrapper::wrap(client, constructorTemplate, context, host); | 604 return InjectedScriptHostWrapper::wrap(client, constructorTemplate, context, host); |
| 604 } | 605 } |
| 605 | 606 |
| 606 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context, v8::Local<v8::Object> object) | 607 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context, v8::Local<v8::Object> object) |
| 607 { | 608 { |
| 608 return InjectedScriptHostWrapper::unwrap(context, object); | 609 return InjectedScriptHostWrapper::unwrap(context, object); |
| 609 } | 610 } |
| 610 | 611 |
| 611 } // namespace blink | 612 } // namespace blink |
| OLD | NEW |