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

Side by Side Diff: src/inspector/v8-inspector-session-impl.cc

Issue 2905543004: [inspector] Prepare some methods in V8InspectorImpl to multiple sessions (Closed)
Patch Set: rebased Created 3 years, 6 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
« no previous file with comments | « src/inspector/v8-inspector-session-impl.h ('k') | src/inspector/v8-runtime-agent-impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project 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 "src/inspector/v8-inspector-session-impl.h" 5 #include "src/inspector/v8-inspector-session-impl.h"
6 6
7 #include "src/inspector/injected-script.h" 7 #include "src/inspector/injected-script.h"
8 #include "src/inspector/inspected-context.h" 8 #include "src/inspector/inspected-context.h"
9 #include "src/inspector/protocol/Protocol.h" 9 #include "src/inspector/protocol/Protocol.h"
10 #include "src/inspector/remote-object-id.h" 10 #include "src/inspector/remote-object-id.h"
(...skipping 25 matching lines...) Expand all
36 stringViewStartsWith(method, 36 stringViewStartsWith(method,
37 protocol::Schema::Metainfo::commandPrefix); 37 protocol::Schema::Metainfo::commandPrefix);
38 } 38 }
39 39
40 // static 40 // static
41 int V8ContextInfo::executionContextId(v8::Local<v8::Context> context) { 41 int V8ContextInfo::executionContextId(v8::Local<v8::Context> context) {
42 return InspectedContext::contextId(context); 42 return InspectedContext::contextId(context);
43 } 43 }
44 44
45 std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create( 45 std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(
46 V8InspectorImpl* inspector, int contextGroupId, 46 V8InspectorImpl* inspector, int contextGroupId, int sessionId,
47 V8Inspector::Channel* channel, const StringView& state) { 47 V8Inspector::Channel* channel, const StringView& state) {
48 return std::unique_ptr<V8InspectorSessionImpl>( 48 return std::unique_ptr<V8InspectorSessionImpl>(new V8InspectorSessionImpl(
49 new V8InspectorSessionImpl(inspector, contextGroupId, channel, state)); 49 inspector, contextGroupId, sessionId, channel, state));
50 } 50 }
51 51
52 V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, 52 V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector,
53 int contextGroupId, 53 int contextGroupId,
54 int sessionId,
54 V8Inspector::Channel* channel, 55 V8Inspector::Channel* channel,
55 const StringView& savedState) 56 const StringView& savedState)
56 : m_contextGroupId(contextGroupId), 57 : m_contextGroupId(contextGroupId),
58 m_sessionId(sessionId),
57 m_inspector(inspector), 59 m_inspector(inspector),
58 m_channel(channel), 60 m_channel(channel),
59 m_customObjectFormatterEnabled(false), 61 m_customObjectFormatterEnabled(false),
60 m_dispatcher(this), 62 m_dispatcher(this),
61 m_state(nullptr), 63 m_state(nullptr),
62 m_runtimeAgent(nullptr), 64 m_runtimeAgent(nullptr),
63 m_debuggerAgent(nullptr), 65 m_debuggerAgent(nullptr),
64 m_heapProfilerAgent(nullptr), 66 m_heapProfilerAgent(nullptr),
65 m_profilerAgent(nullptr), 67 m_profilerAgent(nullptr),
66 m_consoleAgent(nullptr), 68 m_consoleAgent(nullptr),
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 176 }
175 177
176 void V8InspectorSessionImpl::reset() { 178 void V8InspectorSessionImpl::reset() {
177 m_debuggerAgent->reset(); 179 m_debuggerAgent->reset();
178 m_runtimeAgent->reset(); 180 m_runtimeAgent->reset();
179 discardInjectedScripts(); 181 discardInjectedScripts();
180 } 182 }
181 183
182 void V8InspectorSessionImpl::discardInjectedScripts() { 184 void V8InspectorSessionImpl::discardInjectedScripts() {
183 m_inspectedObjects.clear(); 185 m_inspectedObjects.clear();
184 const V8InspectorImpl::ContextByIdMap* contexts = 186 m_inspector->forEachContext(m_contextGroupId, [](InspectedContext* context) {
185 m_inspector->contextGroup(m_contextGroupId); 187 context->discardInjectedScript();
186 if (!contexts) return; 188 });
187
188 std::vector<int> keys;
189 keys.reserve(contexts->size());
190 for (auto& idContext : *contexts) keys.push_back(idContext.first);
191 for (auto& key : keys) {
192 contexts = m_inspector->contextGroup(m_contextGroupId);
193 if (!contexts) continue;
194 auto contextIt = contexts->find(key);
195 if (contextIt != contexts->end())
196 contextIt->second
197 ->discardInjectedScript(); // This may destroy some contexts.
198 }
199 } 189 }
200 190
201 Response V8InspectorSessionImpl::findInjectedScript( 191 Response V8InspectorSessionImpl::findInjectedScript(
202 int contextId, InjectedScript*& injectedScript) { 192 int contextId, InjectedScript*& injectedScript) {
203 injectedScript = nullptr; 193 injectedScript = nullptr;
204 if (!contextId) 194 InspectedContext* context =
205 return Response::Error("Cannot find context with specified id"); 195 m_inspector->getContext(m_contextGroupId, contextId);
206 196 if (!context) return Response::Error("Cannot find context with specified id");
207 const V8InspectorImpl::ContextByIdMap* contexts =
208 m_inspector->contextGroup(m_contextGroupId);
209 if (!contexts)
210 return Response::Error("Cannot find context with specified id");
211
212 auto contextsIt = contexts->find(contextId);
213 if (contextsIt == contexts->end())
214 return Response::Error("Cannot find context with specified id");
215
216 const std::unique_ptr<InspectedContext>& context = contextsIt->second;
217 if (!context->getInjectedScript()) { 197 if (!context->getInjectedScript()) {
218 if (!context->createInjectedScript()) 198 if (!context->createInjectedScript())
219 return Response::Error("Cannot access specified execution context"); 199 return Response::Error("Cannot access specified execution context");
220 if (m_customObjectFormatterEnabled) 200 if (m_customObjectFormatterEnabled)
221 context->getInjectedScript()->setCustomObjectFormatterEnabled(true); 201 context->getInjectedScript()->setCustomObjectFormatterEnabled(true);
222 } 202 }
223 injectedScript = context->getInjectedScript(); 203 injectedScript = context->getInjectedScript();
224 return Response::OK(); 204 return Response::OK();
225 } 205 }
226 206
227 Response V8InspectorSessionImpl::findInjectedScript( 207 Response V8InspectorSessionImpl::findInjectedScript(
228 RemoteObjectIdBase* objectId, InjectedScript*& injectedScript) { 208 RemoteObjectIdBase* objectId, InjectedScript*& injectedScript) {
229 return findInjectedScript(objectId->contextId(), injectedScript); 209 return findInjectedScript(objectId->contextId(), injectedScript);
230 } 210 }
231 211
232 void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) { 212 void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) {
233 releaseObjectGroup(toString16(objectGroup)); 213 releaseObjectGroup(toString16(objectGroup));
234 } 214 }
235 215
236 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) { 216 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) {
237 const V8InspectorImpl::ContextByIdMap* contexts = 217 m_inspector->forEachContext(
238 m_inspector->contextGroup(m_contextGroupId); 218 m_contextGroupId, [&objectGroup](InspectedContext* context) {
239 if (!contexts) return; 219 InjectedScript* injectedScript = context->getInjectedScript();
240 220 if (injectedScript) injectedScript->releaseObjectGroup(objectGroup);
241 std::vector<int> keys; 221 });
242 for (auto& idContext : *contexts) keys.push_back(idContext.first);
243 for (auto& key : keys) {
244 contexts = m_inspector->contextGroup(m_contextGroupId);
245 if (!contexts) continue;
246 auto contextsIt = contexts->find(key);
247 if (contextsIt == contexts->end()) continue;
248 InjectedScript* injectedScript = contextsIt->second->getInjectedScript();
249 if (injectedScript)
250 injectedScript->releaseObjectGroup(
251 objectGroup); // This may destroy some contexts.
252 }
253 } 222 }
254 223
255 bool V8InspectorSessionImpl::unwrapObject( 224 bool V8InspectorSessionImpl::unwrapObject(
256 std::unique_ptr<StringBuffer>* error, const StringView& objectId, 225 std::unique_ptr<StringBuffer>* error, const StringView& objectId,
257 v8::Local<v8::Value>* object, v8::Local<v8::Context>* context, 226 v8::Local<v8::Value>* object, v8::Local<v8::Context>* context,
258 std::unique_ptr<StringBuffer>* objectGroup) { 227 std::unique_ptr<StringBuffer>* objectGroup) {
259 String16 objectGroupString; 228 String16 objectGroupString;
260 Response response = unwrapObject(toString16(objectId), object, context, 229 Response response = unwrapObject(toString16(objectId), object, context,
261 objectGroup ? &objectGroupString : nullptr); 230 objectGroup ? &objectGroupString : nullptr);
262 if (!response.isSuccess()) { 231 if (!response.isSuccess()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 v8::Local<v8::Value> table, 281 v8::Local<v8::Value> table,
313 v8::Local<v8::Value> columns) { 282 v8::Local<v8::Value> columns) {
314 InjectedScript* injectedScript = nullptr; 283 InjectedScript* injectedScript = nullptr;
315 findInjectedScript(InspectedContext::contextId(context), injectedScript); 284 findInjectedScript(InspectedContext::contextId(context), injectedScript);
316 if (!injectedScript) return nullptr; 285 if (!injectedScript) return nullptr;
317 return injectedScript->wrapTable(table, columns); 286 return injectedScript->wrapTable(table, columns);
318 } 287 }
319 288
320 void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) { 289 void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) {
321 m_customObjectFormatterEnabled = enabled; 290 m_customObjectFormatterEnabled = enabled;
322 const V8InspectorImpl::ContextByIdMap* contexts = 291 m_inspector->forEachContext(
323 m_inspector->contextGroup(m_contextGroupId); 292 m_contextGroupId, [&enabled](InspectedContext* context) {
324 if (!contexts) return; 293 InjectedScript* injectedScript = context->getInjectedScript();
325 for (auto& idContext : *contexts) { 294 if (injectedScript)
326 InjectedScript* injectedScript = idContext.second->getInjectedScript(); 295 injectedScript->setCustomObjectFormatterEnabled(enabled);
327 if (injectedScript) 296 });
328 injectedScript->setCustomObjectFormatterEnabled(enabled);
329 }
330 } 297 }
331 298
332 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) { 299 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) {
333 const V8InspectorImpl::ContextByIdMap* contexts = 300 m_inspector->forEachContext(m_contextGroupId,
334 m_inspector->contextGroup(m_contextGroupId); 301 [&agent](InspectedContext* context) {
335 if (!contexts) return; 302 agent->reportExecutionContextCreated(context);
336 for (auto& idContext : *contexts) 303 });
337 agent->reportExecutionContextCreated(idContext.second.get());
338 } 304 }
339 305
340 void V8InspectorSessionImpl::dispatchProtocolMessage( 306 void V8InspectorSessionImpl::dispatchProtocolMessage(
341 const StringView& message) { 307 const StringView& message) {
342 m_dispatcher.dispatch(protocol::StringUtil::parseJSON(message)); 308 m_dispatcher.dispatch(protocol::StringUtil::parseJSON(message));
343 } 309 }
344 310
345 std::unique_ptr<StringBuffer> V8InspectorSessionImpl::stateJSON() { 311 std::unique_ptr<StringBuffer> V8InspectorSessionImpl::stateJSON() {
346 String16 json = m_state->serialize(); 312 String16 json = m_state->serialize();
347 return StringBufferImpl::adopt(json); 313 return StringBufferImpl::adopt(json);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = 398 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches =
433 searchInTextByLinesImpl(this, toString16(text), toString16(query), 399 searchInTextByLinesImpl(this, toString16(text), toString16(query),
434 caseSensitive, isRegex); 400 caseSensitive, isRegex);
435 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> result; 401 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> result;
436 for (size_t i = 0; i < matches.size(); ++i) 402 for (size_t i = 0; i < matches.size(); ++i)
437 result.push_back(std::move(matches[i])); 403 result.push_back(std::move(matches[i]));
438 return result; 404 return result;
439 } 405 }
440 406
441 } // namespace v8_inspector 407 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-inspector-session-impl.h ('k') | src/inspector/v8-runtime-agent-impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698