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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8InspectorSessionImpl.cpp

Issue 1967933002: [DevTools] Dispatch messages to V8InspectorSession directly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@1936593002
Patch Set: rebased Created 4 years, 7 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 "platform/v8_inspector/V8InspectorSessionImpl.h" 5 #include "platform/v8_inspector/V8InspectorSessionImpl.h"
6 6
7 #include "platform/inspector_protocol/Parser.h"
7 #include "platform/v8_inspector/InjectedScript.h" 8 #include "platform/v8_inspector/InjectedScript.h"
8 #include "platform/v8_inspector/InspectedContext.h" 9 #include "platform/v8_inspector/InspectedContext.h"
9 #include "platform/v8_inspector/RemoteObjectId.h" 10 #include "platform/v8_inspector/RemoteObjectId.h"
10 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" 11 #include "platform/v8_inspector/V8DebuggerAgentImpl.h"
11 #include "platform/v8_inspector/V8DebuggerImpl.h" 12 #include "platform/v8_inspector/V8DebuggerImpl.h"
12 #include "platform/v8_inspector/V8HeapProfilerAgentImpl.h" 13 #include "platform/v8_inspector/V8HeapProfilerAgentImpl.h"
13 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" 14 #include "platform/v8_inspector/V8ProfilerAgentImpl.h"
14 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" 15 #include "platform/v8_inspector/V8RuntimeAgentImpl.h"
15 #include "platform/v8_inspector/public/V8ContextInfo.h" 16 #include "platform/v8_inspector/public/V8ContextInfo.h"
16 #include "platform/v8_inspector/public/V8DebuggerClient.h" 17 #include "platform/v8_inspector/public/V8DebuggerClient.h"
17 18
18 namespace blink { 19 namespace blink {
19 20
20 const char V8InspectorSession::backtraceObjectGroup[] = "backtrace"; 21 const char V8InspectorSession::backtraceObjectGroup[] = "backtrace";
21 22
22 PassOwnPtr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(V8DebuggerImpl * debugger, int contextGroupId) 23 // static
24 bool V8InspectorSession::isV8ProtocolMethod(const String16& method)
23 { 25 {
24 return adoptPtr(new V8InspectorSessionImpl(debugger, contextGroupId)); 26 return method.startWith("Debugger.") || method.startWith("HeapProfiler.") || method.startWith("Profiler.") || method.startWith("Runtime.");
25 } 27 }
26 28
27 V8InspectorSessionImpl::V8InspectorSessionImpl(V8DebuggerImpl* debugger, int con textGroupId) 29 PassOwnPtr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(V8DebuggerImpl * debugger, int contextGroupId, V8InspectorSessionClient* client, const String16 * state)
30 {
31 return adoptPtr(new V8InspectorSessionImpl(debugger, contextGroupId, client, state));
32 }
33
34 V8InspectorSessionImpl::V8InspectorSessionImpl(V8DebuggerImpl* debugger, int con textGroupId, V8InspectorSessionClient* client, const String16* savedState)
28 : m_contextGroupId(contextGroupId) 35 : m_contextGroupId(contextGroupId)
29 , m_debugger(debugger) 36 , m_debugger(debugger)
30 , m_client(nullptr) 37 , m_client(client)
31 , m_customObjectFormatterEnabled(false) 38 , m_customObjectFormatterEnabled(false)
32 , m_instrumentationCounter(0) 39 , m_instrumentationCounter(0)
33 , m_runtimeAgent(adoptPtr(new V8RuntimeAgentImpl(this))) 40 , m_frontend(adoptPtr(new protocol::Frontend(client)))
34 , m_debuggerAgent(adoptPtr(new V8DebuggerAgentImpl(this))) 41 , m_dispatcher(protocol::Dispatcher::create(client))
35 , m_heapProfilerAgent(adoptPtr(new V8HeapProfilerAgentImpl(this))) 42 , m_state(nullptr)
36 , m_profilerAgent(adoptPtr(new V8ProfilerAgentImpl(this))) 43 , m_runtimeAgent(nullptr)
44 , m_debuggerAgent(nullptr)
45 , m_heapProfilerAgent(nullptr)
46 , m_profilerAgent(nullptr)
37 { 47 {
48 if (savedState) {
49 OwnPtr<protocol::Value> state = protocol::parseJSON(*savedState);
50 if (state)
51 m_state = protocol::DictionaryValue::cast(std::move(state));
52 if (!m_state)
53 m_state = protocol::DictionaryValue::create();
54 } else {
55 m_state = protocol::DictionaryValue::create();
56 }
57
58 m_runtimeAgent = adoptPtr(new V8RuntimeAgentImpl(this, protocol::Frontend::R untime::from(m_frontend.get()), agentState("Runtime")));
59 m_dispatcher->registerAgent(static_cast<protocol::Backend::Runtime*>(m_runti meAgent.get()));
60
61 m_debuggerAgent = adoptPtr(new V8DebuggerAgentImpl(this, protocol::Frontend: :Debugger::from(m_frontend.get()), agentState("Debugger")));
62 m_dispatcher->registerAgent(static_cast<protocol::Backend::Debugger*>(m_debu ggerAgent.get()));
63
64 m_heapProfilerAgent = adoptPtr(new V8HeapProfilerAgentImpl(this, protocol::F rontend::HeapProfiler::from(m_frontend.get()), agentState("HeapProfiler")));
65 m_dispatcher->registerAgent(static_cast<protocol::Backend::HeapProfiler*>(m_ heapProfilerAgent.get()));
66
67 m_profilerAgent = adoptPtr(new V8ProfilerAgentImpl(this, protocol::Frontend: :Profiler::from(m_frontend.get()), agentState("Profiler")));
68 m_dispatcher->registerAgent(static_cast<protocol::Backend::Profiler*>(m_prof ilerAgent.get()));
69
70 if (savedState) {
71 m_runtimeAgent->restore();
72 m_debuggerAgent->restore();
73 m_heapProfilerAgent->restore();
74 m_profilerAgent->restore();
75 }
38 } 76 }
39 77
40 V8InspectorSessionImpl::~V8InspectorSessionImpl() 78 V8InspectorSessionImpl::~V8InspectorSessionImpl()
41 { 79 {
80 m_dispatcher->clearFrontend();
81 m_dispatcher.clear();
82
83 ErrorString errorString;
84 m_profilerAgent->disable(&errorString);
85 m_heapProfilerAgent->disable(&errorString);
86 m_debuggerAgent->disable(&errorString);
87 m_runtimeAgent->disable(&errorString);
88
89 m_frontend.clear();
42 discardInjectedScripts(); 90 discardInjectedScripts();
43 m_debugger->disconnect(this); 91 m_debugger->disconnect(this);
44 } 92 }
45 93
46 V8DebuggerAgent* V8InspectorSessionImpl::debuggerAgent() 94 protocol::DictionaryValue* V8InspectorSessionImpl::agentState(const String16& na me)
47 { 95 {
48 return m_debuggerAgent.get(); 96 protocol::DictionaryValue* state = m_state->getObject(name);
49 } 97 if (!state) {
50 98 OwnPtr<protocol::DictionaryValue> newState = protocol::DictionaryValue:: create();
51 V8HeapProfilerAgent* V8InspectorSessionImpl::heapProfilerAgent() 99 state = newState.get();
52 { 100 m_state->setObject(name, std::move(newState));
53 return m_heapProfilerAgent.get(); 101 }
54 } 102 return state;
55
56 V8ProfilerAgent* V8InspectorSessionImpl::profilerAgent()
57 {
58 return m_profilerAgent.get();
59 }
60
61 V8RuntimeAgent* V8InspectorSessionImpl::runtimeAgent()
62 {
63 return m_runtimeAgent.get();
64 }
65
66 void V8InspectorSessionImpl::setClient(V8InspectorSessionClient* client)
67 {
68 m_client = client;
69 } 103 }
70 104
71 void V8InspectorSessionImpl::reset() 105 void V8InspectorSessionImpl::reset()
72 { 106 {
73 m_debuggerAgent->reset(); 107 m_debuggerAgent->reset();
74 m_runtimeAgent->reset(); 108 m_runtimeAgent->reset();
75 discardInjectedScripts(); 109 discardInjectedScripts();
76 } 110 }
77 111
78 void V8InspectorSessionImpl::discardInjectedScripts() 112 void V8InspectorSessionImpl::discardInjectedScripts()
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_ contextGroupId); 231 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_ contextGroupId);
198 if (!contexts) 232 if (!contexts)
199 return; 233 return;
200 for (auto& idContext : *contexts) 234 for (auto& idContext : *contexts)
201 agent->reportExecutionContextCreated(idContext.second); 235 agent->reportExecutionContextCreated(idContext.second);
202 } 236 }
203 237
204 void V8InspectorSessionImpl::changeInstrumentationCounter(int delta) 238 void V8InspectorSessionImpl::changeInstrumentationCounter(int delta)
205 { 239 {
206 DCHECK_GE(m_instrumentationCounter + delta, 0); 240 DCHECK_GE(m_instrumentationCounter + delta, 0);
207 if (!m_instrumentationCounter && m_client) 241 if (!m_instrumentationCounter)
208 m_client->startInstrumenting(); 242 m_client->startInstrumenting();
209 m_instrumentationCounter += delta; 243 m_instrumentationCounter += delta;
210 if (!m_instrumentationCounter && m_client) 244 if (!m_instrumentationCounter)
211 m_client->stopInstrumenting(); 245 m_client->stopInstrumenting();
212 } 246 }
213 247
248 void V8InspectorSessionImpl::dispatchProtocolMessage(const String16& message)
249 {
250 m_dispatcher->dispatch(message);
251 }
252
253 String16 V8InspectorSessionImpl::stateJSON()
254 {
255 return m_state->toJSONString();
256 }
257
214 void V8InspectorSessionImpl::addInspectedObject(PassOwnPtr<V8InspectorSession::I nspectable> inspectable) 258 void V8InspectorSessionImpl::addInspectedObject(PassOwnPtr<V8InspectorSession::I nspectable> inspectable)
215 { 259 {
216 m_inspectedObjects.prepend(std::move(inspectable)); 260 m_inspectedObjects.prepend(std::move(inspectable));
217 while (m_inspectedObjects.size() > kInspectedObjectBufferSize) 261 while (m_inspectedObjects.size() > kInspectedObjectBufferSize)
218 m_inspectedObjects.removeLast(); 262 m_inspectedObjects.removeLast();
219 } 263 }
220 264
221 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne d num) 265 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne d num)
222 { 266 {
223 if (num >= m_inspectedObjects.size()) 267 if (num >= m_inspectedObjects.size())
(...skipping 20 matching lines...) Expand all
244 { 288 {
245 m_debuggerAgent->breakProgramOnException(breakReason, std::move(data)); 289 m_debuggerAgent->breakProgramOnException(breakReason, std::move(data));
246 } 290 }
247 291
248 void V8InspectorSessionImpl::setSkipAllPauses(bool skip) 292 void V8InspectorSessionImpl::setSkipAllPauses(bool skip)
249 { 293 {
250 ErrorString errorString; 294 ErrorString errorString;
251 m_debuggerAgent->setSkipAllPauses(&errorString, skip); 295 m_debuggerAgent->setSkipAllPauses(&errorString, skip);
252 } 296 }
253 297
298 void V8InspectorSessionImpl::resume()
299 {
300 ErrorString errorString;
301 m_debuggerAgent->resume(&errorString);
302 }
303
304 void V8InspectorSessionImpl::stepOver()
305 {
306 ErrorString errorString;
307 m_debuggerAgent->stepOver(&errorString);
308 }
309
254 void V8InspectorSessionImpl::asyncTaskScheduled(const String16& taskName, void* task, bool recurring) 310 void V8InspectorSessionImpl::asyncTaskScheduled(const String16& taskName, void* task, bool recurring)
255 { 311 {
256 m_debuggerAgent->asyncTaskScheduled(taskName, task, recurring); 312 m_debuggerAgent->asyncTaskScheduled(taskName, task, recurring);
257 } 313 }
258 314
259 void V8InspectorSessionImpl::asyncTaskCanceled(void* task) 315 void V8InspectorSessionImpl::asyncTaskCanceled(void* task)
260 { 316 {
261 m_debuggerAgent->asyncTaskCanceled(task); 317 m_debuggerAgent->asyncTaskCanceled(task);
262 } 318 }
263 319
264 void V8InspectorSessionImpl::asyncTaskStarted(void* task) 320 void V8InspectorSessionImpl::asyncTaskStarted(void* task)
265 { 321 {
266 m_debuggerAgent->asyncTaskStarted(task); 322 m_debuggerAgent->asyncTaskStarted(task);
267 } 323 }
268 324
269 void V8InspectorSessionImpl::asyncTaskFinished(void* task) 325 void V8InspectorSessionImpl::asyncTaskFinished(void* task)
270 { 326 {
271 m_debuggerAgent->asyncTaskFinished(task); 327 m_debuggerAgent->asyncTaskFinished(task);
272 } 328 }
273 329
274 void V8InspectorSessionImpl::allAsyncTasksCanceled() 330 void V8InspectorSessionImpl::allAsyncTasksCanceled()
275 { 331 {
276 m_debuggerAgent->allAsyncTasksCanceled(); 332 m_debuggerAgent->allAsyncTasksCanceled();
277 } 333 }
278 334
279 } // namespace blink 335 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698