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 "platform/v8_inspector/V8InspectorSessionImpl.h" | 5 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
6 | 6 |
7 #include "platform/v8_inspector/InjectedScript.h" | 7 #include "platform/v8_inspector/InjectedScript.h" |
8 #include "platform/v8_inspector/InspectedContext.h" | 8 #include "platform/v8_inspector/InspectedContext.h" |
9 #include "platform/v8_inspector/RemoteObjectId.h" | 9 #include "platform/v8_inspector/RemoteObjectId.h" |
10 #include "platform/v8_inspector/V8ConsoleAgentImpl.h" | 10 #include "platform/v8_inspector/V8ConsoleAgentImpl.h" |
11 #include "platform/v8_inspector/V8Debugger.h" | 11 #include "platform/v8_inspector/V8Debugger.h" |
12 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" | 12 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" |
13 #include "platform/v8_inspector/V8HeapProfilerAgentImpl.h" | 13 #include "platform/v8_inspector/V8HeapProfilerAgentImpl.h" |
14 #include "platform/v8_inspector/V8InspectorImpl.h" | 14 #include "platform/v8_inspector/V8InspectorImpl.h" |
15 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" | 15 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" |
16 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" | 16 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" |
17 #include "platform/v8_inspector/V8StringUtil.h" | 17 #include "platform/v8_inspector/V8StringUtil.h" |
18 #include "platform/v8_inspector/public/V8ContextInfo.h" | 18 #include "platform/v8_inspector/public/V8ContextInfo.h" |
19 #include "platform/v8_inspector/public/V8InspectorClient.h" | 19 #include "platform/v8_inspector/public/V8InspectorClient.h" |
20 | 20 |
21 namespace v8_inspector { | 21 namespace v8_inspector { |
22 | 22 |
23 // static | 23 // static |
24 bool V8InspectorSession::canDispatchMethod(const String16& method) | 24 bool V8InspectorSession::canDispatchMethod(const StringView& method) |
25 { | 25 { |
26 return method.startsWith(protocol::Runtime::Metainfo::commandPrefix) | 26 return stringViewStartsWith(method, protocol::Runtime::Metainfo::commandPref
ix) |
27 || method.startsWith(protocol::Debugger::Metainfo::commandPrefix) | 27 || stringViewStartsWith(method, protocol::Debugger::Metainfo::commandPre
fix) |
28 || method.startsWith(protocol::Profiler::Metainfo::commandPrefix) | 28 || stringViewStartsWith(method, protocol::Profiler::Metainfo::commandPre
fix) |
29 || method.startsWith(protocol::HeapProfiler::Metainfo::commandPrefix) | 29 || stringViewStartsWith(method, protocol::HeapProfiler::Metainfo::comman
dPrefix) |
30 || method.startsWith(protocol::Console::Metainfo::commandPrefix); | 30 || stringViewStartsWith(method, protocol::Console::Metainfo::commandPref
ix); |
31 } | 31 } |
32 | 32 |
33 std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(V8Inspect
orImpl* inspector, int contextGroupId, protocol::FrontendChannel* channel, const
String16* state) | 33 std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(V8Inspect
orImpl* inspector, int contextGroupId, protocol::FrontendChannel* channel, const
StringView& state) |
34 { | 34 { |
35 return wrapUnique(new V8InspectorSessionImpl(inspector, contextGroupId, chan
nel, state)); | 35 return wrapUnique(new V8InspectorSessionImpl(inspector, contextGroupId, chan
nel, state)); |
36 } | 36 } |
37 | 37 |
38 V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, int c
ontextGroupId, protocol::FrontendChannel* channel, const String16* savedState) | 38 V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, int c
ontextGroupId, protocol::FrontendChannel* channel, const StringView& savedState) |
39 : m_contextGroupId(contextGroupId) | 39 : m_contextGroupId(contextGroupId) |
40 , m_inspector(inspector) | 40 , m_inspector(inspector) |
41 , m_customObjectFormatterEnabled(false) | 41 , m_customObjectFormatterEnabled(false) |
42 , m_dispatcher(channel) | 42 , m_dispatcher(channel) |
43 , m_state(nullptr) | 43 , m_state(nullptr) |
44 , m_runtimeAgent(nullptr) | 44 , m_runtimeAgent(nullptr) |
45 , m_debuggerAgent(nullptr) | 45 , m_debuggerAgent(nullptr) |
46 , m_heapProfilerAgent(nullptr) | 46 , m_heapProfilerAgent(nullptr) |
47 , m_profilerAgent(nullptr) | 47 , m_profilerAgent(nullptr) |
48 , m_consoleAgent(nullptr) | 48 , m_consoleAgent(nullptr) |
49 { | 49 { |
50 if (savedState) { | 50 if (savedState.length()) { |
51 std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState
); | 51 std::unique_ptr<protocol::Value> state = protocol::parseJSON(toString16(
savedState)); |
52 if (state) | 52 if (state) |
53 m_state = protocol::DictionaryValue::cast(std::move(state)); | 53 m_state = protocol::DictionaryValue::cast(std::move(state)); |
54 if (!m_state) | 54 if (!m_state) |
55 m_state = protocol::DictionaryValue::create(); | 55 m_state = protocol::DictionaryValue::create(); |
56 } else { | 56 } else { |
57 m_state = protocol::DictionaryValue::create(); | 57 m_state = protocol::DictionaryValue::create(); |
58 } | 58 } |
59 | 59 |
60 m_runtimeAgent = wrapUnique(new V8RuntimeAgentImpl(this, channel, agentState
(protocol::Runtime::Metainfo::domainName))); | 60 m_runtimeAgent = wrapUnique(new V8RuntimeAgentImpl(this, channel, agentState
(protocol::Runtime::Metainfo::domainName))); |
61 protocol::Runtime::Dispatcher::wire(&m_dispatcher, m_runtimeAgent.get()); | 61 protocol::Runtime::Dispatcher::wire(&m_dispatcher, m_runtimeAgent.get()); |
62 | 62 |
63 m_debuggerAgent = wrapUnique(new V8DebuggerAgentImpl(this, channel, agentSta
te(protocol::Debugger::Metainfo::domainName))); | 63 m_debuggerAgent = wrapUnique(new V8DebuggerAgentImpl(this, channel, agentSta
te(protocol::Debugger::Metainfo::domainName))); |
64 protocol::Debugger::Dispatcher::wire(&m_dispatcher, m_debuggerAgent.get()); | 64 protocol::Debugger::Dispatcher::wire(&m_dispatcher, m_debuggerAgent.get()); |
65 | 65 |
66 m_profilerAgent = wrapUnique(new V8ProfilerAgentImpl(this, channel, agentSta
te(protocol::Profiler::Metainfo::domainName))); | 66 m_profilerAgent = wrapUnique(new V8ProfilerAgentImpl(this, channel, agentSta
te(protocol::Profiler::Metainfo::domainName))); |
67 protocol::Profiler::Dispatcher::wire(&m_dispatcher, m_profilerAgent.get()); | 67 protocol::Profiler::Dispatcher::wire(&m_dispatcher, m_profilerAgent.get()); |
68 | 68 |
69 m_heapProfilerAgent = wrapUnique(new V8HeapProfilerAgentImpl(this, channel,
agentState(protocol::HeapProfiler::Metainfo::domainName))); | 69 m_heapProfilerAgent = wrapUnique(new V8HeapProfilerAgentImpl(this, channel,
agentState(protocol::HeapProfiler::Metainfo::domainName))); |
70 protocol::HeapProfiler::Dispatcher::wire(&m_dispatcher, m_heapProfilerAgent.
get()); | 70 protocol::HeapProfiler::Dispatcher::wire(&m_dispatcher, m_heapProfilerAgent.
get()); |
71 | 71 |
72 m_consoleAgent = wrapUnique(new V8ConsoleAgentImpl(this, channel, agentState
(protocol::Console::Metainfo::domainName))); | 72 m_consoleAgent = wrapUnique(new V8ConsoleAgentImpl(this, channel, agentState
(protocol::Console::Metainfo::domainName))); |
73 protocol::Console::Dispatcher::wire(&m_dispatcher, m_consoleAgent.get()); | 73 protocol::Console::Dispatcher::wire(&m_dispatcher, m_consoleAgent.get()); |
74 | 74 |
75 if (savedState) { | 75 if (savedState.length()) { |
76 m_runtimeAgent->restore(); | 76 m_runtimeAgent->restore(); |
77 m_debuggerAgent->restore(); | 77 m_debuggerAgent->restore(); |
78 m_heapProfilerAgent->restore(); | 78 m_heapProfilerAgent->restore(); |
79 m_profilerAgent->restore(); | 79 m_profilerAgent->restore(); |
80 m_consoleAgent->restore(); | 80 m_consoleAgent->restore(); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 V8InspectorSessionImpl::~V8InspectorSessionImpl() | 84 V8InspectorSessionImpl::~V8InspectorSessionImpl() |
85 { | 85 { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 context->getInjectedScript()->setCustomObjectFormatterEnabled(true); | 163 context->getInjectedScript()->setCustomObjectFormatterEnabled(true); |
164 } | 164 } |
165 return context->getInjectedScript(); | 165 return context->getInjectedScript(); |
166 } | 166 } |
167 | 167 |
168 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr
ing, RemoteObjectIdBase* objectId) | 168 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr
ing, RemoteObjectIdBase* objectId) |
169 { | 169 { |
170 return objectId ? findInjectedScript(errorString, objectId->contextId()) : n
ullptr; | 170 return objectId ? findInjectedScript(errorString, objectId->contextId()) : n
ullptr; |
171 } | 171 } |
172 | 172 |
| 173 void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) |
| 174 { |
| 175 releaseObjectGroup(toString16(objectGroup)); |
| 176 } |
| 177 |
173 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) | 178 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) |
174 { | 179 { |
175 const V8InspectorImpl::ContextByIdMap* contexts = m_inspector->contextGroup(
m_contextGroupId); | 180 const V8InspectorImpl::ContextByIdMap* contexts = m_inspector->contextGroup(
m_contextGroupId); |
176 if (!contexts) | 181 if (!contexts) |
177 return; | 182 return; |
178 | 183 |
179 std::vector<int> keys; | 184 std::vector<int> keys; |
180 for (auto& idContext : *contexts) | 185 for (auto& idContext : *contexts) |
181 keys.push_back(idContext.first); | 186 keys.push_back(idContext.first); |
182 for (auto& key : keys) { | 187 for (auto& key : keys) { |
183 contexts = m_inspector->contextGroup(m_contextGroupId); | 188 contexts = m_inspector->contextGroup(m_contextGroupId); |
184 if (!contexts) | 189 if (!contexts) |
185 continue; | 190 continue; |
186 auto contextsIt = contexts->find(key); | 191 auto contextsIt = contexts->find(key); |
187 if (contextsIt == contexts->end()) | 192 if (contextsIt == contexts->end()) |
188 continue; | 193 continue; |
189 InjectedScript* injectedScript = contextsIt->second->getInjectedScript()
; | 194 InjectedScript* injectedScript = contextsIt->second->getInjectedScript()
; |
190 if (injectedScript) | 195 if (injectedScript) |
191 injectedScript->releaseObjectGroup(objectGroup); // This may destroy
some contexts. | 196 injectedScript->releaseObjectGroup(objectGroup); // This may destroy
some contexts. |
192 } | 197 } |
193 } | 198 } |
194 | 199 |
| 200 bool V8InspectorSessionImpl::unwrapObject(ErrorString* errorString, const String
View& objectId, v8::Local<v8::Value>* object, v8::Local<v8::Context>* context, s
td::unique_ptr<StringBuffer>* objectGroup) |
| 201 { |
| 202 String16 group; |
| 203 bool result = unwrapObject(errorString, toString16(objectId), object, contex
t, &group); |
| 204 *objectGroup = StringBufferImpl::adopt(group); |
| 205 return result; |
| 206 } |
| 207 |
195 bool V8InspectorSessionImpl::unwrapObject(ErrorString* errorString, const String
16& objectId, v8::Local<v8::Value>* object, v8::Local<v8::Context>* context, Str
ing16* objectGroup) | 208 bool V8InspectorSessionImpl::unwrapObject(ErrorString* errorString, const String
16& objectId, v8::Local<v8::Value>* object, v8::Local<v8::Context>* context, Str
ing16* objectGroup) |
196 { | 209 { |
197 std::unique_ptr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString
, objectId); | 210 std::unique_ptr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString
, objectId); |
198 if (!remoteId) | 211 if (!remoteId) |
199 return false; | 212 return false; |
200 InjectedScript* injectedScript = findInjectedScript(errorString, remoteId.ge
t()); | 213 InjectedScript* injectedScript = findInjectedScript(errorString, remoteId.ge
t()); |
201 if (!injectedScript) | 214 if (!injectedScript) |
202 return false; | 215 return false; |
203 if (!injectedScript->findObject(errorString, *remoteId, object)) | 216 if (!injectedScript->findObject(errorString, *remoteId, object)) |
204 return false; | 217 return false; |
205 *context = injectedScript->context()->context(); | 218 *context = injectedScript->context()->context(); |
206 *objectGroup = injectedScript->objectGroupName(*remoteId); | 219 *objectGroup = injectedScript->objectGroupName(*remoteId); |
207 return true; | 220 return true; |
208 } | 221 } |
209 | 222 |
210 std::unique_ptr<protocol::Runtime::API::RemoteObject> V8InspectorSessionImpl::wr
apObject(v8::Local<v8::Context> context, v8::Local<v8::Value> value, const Strin
g16& groupName) | 223 std::unique_ptr<protocol::Runtime::API::RemoteObject> V8InspectorSessionImpl::wr
apObject(v8::Local<v8::Context> context, v8::Local<v8::Value> value, const Strin
gView& groupName) |
211 { | 224 { |
212 return wrapObject(context, value, groupName, false); | 225 return wrapObject(context, value, toString16(groupName), false); |
213 } | 226 } |
214 | 227 |
215 std::unique_ptr<protocol::Runtime::RemoteObject> V8InspectorSessionImpl::wrapObj
ect(v8::Local<v8::Context> context, v8::Local<v8::Value> value, const String16&
groupName, bool generatePreview) | 228 std::unique_ptr<protocol::Runtime::RemoteObject> V8InspectorSessionImpl::wrapObj
ect(v8::Local<v8::Context> context, v8::Local<v8::Value> value, const String16&
groupName, bool generatePreview) |
216 { | 229 { |
217 ErrorString errorString; | 230 ErrorString errorString; |
218 InjectedScript* injectedScript = findInjectedScript(&errorString, V8Debugger
::contextId(context)); | 231 InjectedScript* injectedScript = findInjectedScript(&errorString, V8Debugger
::contextId(context)); |
219 if (!injectedScript) | 232 if (!injectedScript) |
220 return nullptr; | 233 return nullptr; |
221 return injectedScript->wrapObject(&errorString, value, groupName, false, gen
eratePreview); | 234 return injectedScript->wrapObject(&errorString, value, groupName, false, gen
eratePreview); |
222 } | 235 } |
(...skipping 22 matching lines...) Expand all Loading... |
245 | 258 |
246 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) | 259 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) |
247 { | 260 { |
248 const V8InspectorImpl::ContextByIdMap* contexts = m_inspector->contextGroup(
m_contextGroupId); | 261 const V8InspectorImpl::ContextByIdMap* contexts = m_inspector->contextGroup(
m_contextGroupId); |
249 if (!contexts) | 262 if (!contexts) |
250 return; | 263 return; |
251 for (auto& idContext : *contexts) | 264 for (auto& idContext : *contexts) |
252 agent->reportExecutionContextCreated(idContext.second.get()); | 265 agent->reportExecutionContextCreated(idContext.second.get()); |
253 } | 266 } |
254 | 267 |
255 void V8InspectorSessionImpl::dispatchProtocolMessage(const String16& message) | 268 void V8InspectorSessionImpl::dispatchProtocolMessage(const StringView& message) |
256 { | 269 { |
257 m_dispatcher.dispatch(message); | 270 m_dispatcher.dispatch(parseJSON(message)); |
258 } | 271 } |
259 | 272 |
260 String16 V8InspectorSessionImpl::stateJSON() | 273 std::unique_ptr<StringBuffer> V8InspectorSessionImpl::stateJSON() |
261 { | 274 { |
262 return m_state->toJSONString(); | 275 String16 json = m_state->toJSONString(); |
| 276 return StringBufferImpl::adopt(json); |
263 } | 277 } |
264 | 278 |
265 void V8InspectorSessionImpl::addInspectedObject(std::unique_ptr<V8InspectorSessi
on::Inspectable> inspectable) | 279 void V8InspectorSessionImpl::addInspectedObject(std::unique_ptr<V8InspectorSessi
on::Inspectable> inspectable) |
266 { | 280 { |
267 m_inspectedObjects.insert(m_inspectedObjects.begin(), std::move(inspectable)
); | 281 m_inspectedObjects.insert(m_inspectedObjects.begin(), std::move(inspectable)
); |
268 if (m_inspectedObjects.size() > kInspectedObjectBufferSize) | 282 if (m_inspectedObjects.size() > kInspectedObjectBufferSize) |
269 m_inspectedObjects.resize(kInspectedObjectBufferSize); | 283 m_inspectedObjects.resize(kInspectedObjectBufferSize); |
270 } | 284 } |
271 | 285 |
272 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne
d num) | 286 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne
d num) |
273 { | 287 { |
274 if (num >= m_inspectedObjects.size()) | 288 if (num >= m_inspectedObjects.size()) |
275 return nullptr; | 289 return nullptr; |
276 return m_inspectedObjects[num].get(); | 290 return m_inspectedObjects[num].get(); |
277 } | 291 } |
278 | 292 |
279 void V8InspectorSessionImpl::schedulePauseOnNextStatement(const String16& breakR
eason, const String16& breakDetails) | 293 void V8InspectorSessionImpl::schedulePauseOnNextStatement(const StringView& brea
kReason, const StringView& breakDetails) |
280 { | 294 { |
281 m_debuggerAgent->schedulePauseOnNextStatement(breakReason, protocol::Diction
aryValue::cast(parseJSON(breakDetails))); | 295 m_debuggerAgent->schedulePauseOnNextStatement(toString16(breakReason), proto
col::DictionaryValue::cast(parseJSON(breakDetails))); |
282 } | 296 } |
283 | 297 |
284 void V8InspectorSessionImpl::cancelPauseOnNextStatement() | 298 void V8InspectorSessionImpl::cancelPauseOnNextStatement() |
285 { | 299 { |
286 m_debuggerAgent->cancelPauseOnNextStatement(); | 300 m_debuggerAgent->cancelPauseOnNextStatement(); |
287 } | 301 } |
288 | 302 |
289 void V8InspectorSessionImpl::breakProgram(const String16& breakReason, const Str
ing16& breakDetails) | 303 void V8InspectorSessionImpl::breakProgram(const StringView& breakReason, const S
tringView& breakDetails) |
290 { | 304 { |
291 m_debuggerAgent->breakProgram(breakReason, protocol::DictionaryValue::cast(p
arseJSON(breakDetails))); | 305 m_debuggerAgent->breakProgram(toString16(breakReason), protocol::DictionaryV
alue::cast(parseJSON(breakDetails))); |
292 } | 306 } |
293 | 307 |
294 void V8InspectorSessionImpl::setSkipAllPauses(bool skip) | 308 void V8InspectorSessionImpl::setSkipAllPauses(bool skip) |
295 { | 309 { |
296 ErrorString errorString; | 310 ErrorString errorString; |
297 m_debuggerAgent->setSkipAllPauses(&errorString, skip); | 311 m_debuggerAgent->setSkipAllPauses(&errorString, skip); |
298 } | 312 } |
299 | 313 |
300 void V8InspectorSessionImpl::resume() | 314 void V8InspectorSessionImpl::resume() |
301 { | 315 { |
302 ErrorString errorString; | 316 ErrorString errorString; |
303 m_debuggerAgent->resume(&errorString); | 317 m_debuggerAgent->resume(&errorString); |
304 } | 318 } |
305 | 319 |
306 void V8InspectorSessionImpl::stepOver() | 320 void V8InspectorSessionImpl::stepOver() |
307 { | 321 { |
308 ErrorString errorString; | 322 ErrorString errorString; |
309 m_debuggerAgent->stepOver(&errorString); | 323 m_debuggerAgent->stepOver(&errorString); |
310 } | 324 } |
311 | 325 |
312 std::unique_ptr<protocol::Array<protocol::Debugger::API::SearchMatch>> V8Inspect
orSessionImpl::searchInTextByLines(const String16& text, const String16& query,
bool caseSensitive, bool isRegex) | 326 std::unique_ptr<protocol::Array<protocol::Debugger::API::SearchMatch>> V8Inspect
orSessionImpl::searchInTextByLines(const StringView& text, const StringView& que
ry, bool caseSensitive, bool isRegex) |
313 { | 327 { |
314 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = sear
chInTextByLinesImpl(this, text, query, caseSensitive, isRegex); | 328 // TODO(dgozman): search may operate on StringView and avoid copying |text|. |
| 329 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = sear
chInTextByLinesImpl(this, toString16(text), toString16(query), caseSensitive, is
Regex); |
315 std::unique_ptr<protocol::Array<protocol::Debugger::API::SearchMatch>> resul
t = protocol::Array<protocol::Debugger::API::SearchMatch>::create(); | 330 std::unique_ptr<protocol::Array<protocol::Debugger::API::SearchMatch>> resul
t = protocol::Array<protocol::Debugger::API::SearchMatch>::create(); |
316 for (size_t i = 0; i < matches.size(); ++i) | 331 for (size_t i = 0; i < matches.size(); ++i) |
317 result->addItem(std::move(matches[i])); | 332 result->addItem(std::move(matches[i])); |
318 return result; | 333 return result; |
319 } | 334 } |
320 | 335 |
321 } // namespace v8_inspector | 336 } // namespace v8_inspector |
OLD | NEW |