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

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

Issue 2916803005: [inspector] Create InjectedScript per session in each context (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-console.cc ('k') | test/inspector/inspector-test.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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 176 }
177 177
178 void V8InspectorSessionImpl::reset() { 178 void V8InspectorSessionImpl::reset() {
179 m_debuggerAgent->reset(); 179 m_debuggerAgent->reset();
180 m_runtimeAgent->reset(); 180 m_runtimeAgent->reset();
181 discardInjectedScripts(); 181 discardInjectedScripts();
182 } 182 }
183 183
184 void V8InspectorSessionImpl::discardInjectedScripts() { 184 void V8InspectorSessionImpl::discardInjectedScripts() {
185 m_inspectedObjects.clear(); 185 m_inspectedObjects.clear();
186 m_inspector->forEachContext(m_contextGroupId, [](InspectedContext* context) { 186 int sessionId = m_sessionId;
187 context->discardInjectedScript(); 187 m_inspector->forEachContext(m_contextGroupId,
188 }); 188 [&sessionId](InspectedContext* context) {
189 context->discardInjectedScript(sessionId);
190 });
189 } 191 }
190 192
191 Response V8InspectorSessionImpl::findInjectedScript( 193 Response V8InspectorSessionImpl::findInjectedScript(
192 int contextId, InjectedScript*& injectedScript) { 194 int contextId, InjectedScript*& injectedScript) {
193 injectedScript = nullptr; 195 injectedScript = nullptr;
194 InspectedContext* context = 196 InspectedContext* context =
195 m_inspector->getContext(m_contextGroupId, contextId); 197 m_inspector->getContext(m_contextGroupId, contextId);
196 if (!context) return Response::Error("Cannot find context with specified id"); 198 if (!context) return Response::Error("Cannot find context with specified id");
197 if (!context->getInjectedScript()) { 199 injectedScript = context->getInjectedScript(m_sessionId);
198 if (!context->createInjectedScript()) 200 if (!injectedScript) {
201 if (!context->createInjectedScript(m_sessionId))
199 return Response::Error("Cannot access specified execution context"); 202 return Response::Error("Cannot access specified execution context");
203 injectedScript = context->getInjectedScript(m_sessionId);
200 if (m_customObjectFormatterEnabled) 204 if (m_customObjectFormatterEnabled)
201 context->getInjectedScript()->setCustomObjectFormatterEnabled(true); 205 injectedScript->setCustomObjectFormatterEnabled(true);
202 } 206 }
203 injectedScript = context->getInjectedScript();
204 return Response::OK(); 207 return Response::OK();
205 } 208 }
206 209
207 Response V8InspectorSessionImpl::findInjectedScript( 210 Response V8InspectorSessionImpl::findInjectedScript(
208 RemoteObjectIdBase* objectId, InjectedScript*& injectedScript) { 211 RemoteObjectIdBase* objectId, InjectedScript*& injectedScript) {
209 return findInjectedScript(objectId->contextId(), injectedScript); 212 return findInjectedScript(objectId->contextId(), injectedScript);
210 } 213 }
211 214
212 void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) { 215 void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) {
213 releaseObjectGroup(toString16(objectGroup)); 216 releaseObjectGroup(toString16(objectGroup));
214 } 217 }
215 218
216 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) { 219 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) {
220 int sessionId = m_sessionId;
217 m_inspector->forEachContext( 221 m_inspector->forEachContext(
218 m_contextGroupId, [&objectGroup](InspectedContext* context) { 222 m_contextGroupId, [&objectGroup, &sessionId](InspectedContext* context) {
219 InjectedScript* injectedScript = context->getInjectedScript(); 223 InjectedScript* injectedScript = context->getInjectedScript(sessionId);
220 if (injectedScript) injectedScript->releaseObjectGroup(objectGroup); 224 if (injectedScript) injectedScript->releaseObjectGroup(objectGroup);
221 }); 225 });
222 } 226 }
223 227
224 bool V8InspectorSessionImpl::unwrapObject( 228 bool V8InspectorSessionImpl::unwrapObject(
225 std::unique_ptr<StringBuffer>* error, const StringView& objectId, 229 std::unique_ptr<StringBuffer>* error, const StringView& objectId,
226 v8::Local<v8::Value>* object, v8::Local<v8::Context>* context, 230 v8::Local<v8::Value>* object, v8::Local<v8::Context>* context,
227 std::unique_ptr<StringBuffer>* objectGroup) { 231 std::unique_ptr<StringBuffer>* objectGroup) {
228 String16 objectGroupString; 232 String16 objectGroupString;
229 Response response = unwrapObject(toString16(objectId), object, context, 233 Response response = unwrapObject(toString16(objectId), object, context,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 v8::Local<v8::Value> table, 285 v8::Local<v8::Value> table,
282 v8::Local<v8::Value> columns) { 286 v8::Local<v8::Value> columns) {
283 InjectedScript* injectedScript = nullptr; 287 InjectedScript* injectedScript = nullptr;
284 findInjectedScript(InspectedContext::contextId(context), injectedScript); 288 findInjectedScript(InspectedContext::contextId(context), injectedScript);
285 if (!injectedScript) return nullptr; 289 if (!injectedScript) return nullptr;
286 return injectedScript->wrapTable(table, columns); 290 return injectedScript->wrapTable(table, columns);
287 } 291 }
288 292
289 void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) { 293 void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) {
290 m_customObjectFormatterEnabled = enabled; 294 m_customObjectFormatterEnabled = enabled;
295 int sessionId = m_sessionId;
291 m_inspector->forEachContext( 296 m_inspector->forEachContext(
292 m_contextGroupId, [&enabled](InspectedContext* context) { 297 m_contextGroupId, [&enabled, &sessionId](InspectedContext* context) {
293 InjectedScript* injectedScript = context->getInjectedScript(); 298 InjectedScript* injectedScript = context->getInjectedScript(sessionId);
294 if (injectedScript) 299 if (injectedScript)
295 injectedScript->setCustomObjectFormatterEnabled(enabled); 300 injectedScript->setCustomObjectFormatterEnabled(enabled);
296 }); 301 });
297 } 302 }
298 303
299 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) { 304 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) {
300 m_inspector->forEachContext(m_contextGroupId, 305 m_inspector->forEachContext(m_contextGroupId,
301 [&agent](InspectedContext* context) { 306 [&agent](InspectedContext* context) {
302 agent->reportExecutionContextCreated(context); 307 agent->reportExecutionContextCreated(context);
303 }); 308 });
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = 403 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches =
399 searchInTextByLinesImpl(this, toString16(text), toString16(query), 404 searchInTextByLinesImpl(this, toString16(text), toString16(query),
400 caseSensitive, isRegex); 405 caseSensitive, isRegex);
401 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> result; 406 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> result;
402 for (size_t i = 0; i < matches.size(); ++i) 407 for (size_t i = 0; i < matches.size(); ++i)
403 result.push_back(std::move(matches[i])); 408 result.push_back(std::move(matches[i]));
404 return result; 409 return result;
405 } 410 }
406 411
407 } // namespace v8_inspector 412 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-console.cc ('k') | test/inspector/inspector-test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698