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

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

Issue 2467853003: [inspector] migrate Runtime to new style (Closed)
Patch Set: one more addressed comment Created 4 years, 1 month 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.h » ('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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 if (savedState.length()) { 97 if (savedState.length()) {
98 m_runtimeAgent->restore(); 98 m_runtimeAgent->restore();
99 m_debuggerAgent->restore(); 99 m_debuggerAgent->restore();
100 m_heapProfilerAgent->restore(); 100 m_heapProfilerAgent->restore();
101 m_profilerAgent->restore(); 101 m_profilerAgent->restore();
102 m_consoleAgent->restore(); 102 m_consoleAgent->restore();
103 } 103 }
104 } 104 }
105 105
106 V8InspectorSessionImpl::~V8InspectorSessionImpl() { 106 V8InspectorSessionImpl::~V8InspectorSessionImpl() {
107 ErrorString errorString; 107 protocol::ErrorString errorString;
108 m_consoleAgent->disable(); 108 m_consoleAgent->disable();
109 m_profilerAgent->disable(); 109 m_profilerAgent->disable();
110 m_heapProfilerAgent->disable(); 110 m_heapProfilerAgent->disable();
111 m_debuggerAgent->disable(&errorString); 111 m_debuggerAgent->disable(&errorString);
112 m_runtimeAgent->disable(&errorString); 112 m_runtimeAgent->disable();
113 113
114 discardInjectedScripts(); 114 discardInjectedScripts();
115 m_inspector->disconnect(this); 115 m_inspector->disconnect(this);
116 } 116 }
117 117
118 protocol::DictionaryValue* V8InspectorSessionImpl::agentState( 118 protocol::DictionaryValue* V8InspectorSessionImpl::agentState(
119 const String16& name) { 119 const String16& name) {
120 protocol::DictionaryValue* state = m_state->getObject(name); 120 protocol::DictionaryValue* state = m_state->getObject(name);
121 if (!state) { 121 if (!state) {
122 std::unique_ptr<protocol::DictionaryValue> newState = 122 std::unique_ptr<protocol::DictionaryValue> newState =
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 for (auto& key : keys) { 158 for (auto& key : keys) {
159 contexts = m_inspector->contextGroup(m_contextGroupId); 159 contexts = m_inspector->contextGroup(m_contextGroupId);
160 if (!contexts) continue; 160 if (!contexts) continue;
161 auto contextIt = contexts->find(key); 161 auto contextIt = contexts->find(key);
162 if (contextIt != contexts->end()) 162 if (contextIt != contexts->end())
163 contextIt->second 163 contextIt->second
164 ->discardInjectedScript(); // This may destroy some contexts. 164 ->discardInjectedScript(); // This may destroy some contexts.
165 } 165 }
166 } 166 }
167 167
168 InjectedScript* V8InspectorSessionImpl::findInjectedScript( 168 Response V8InspectorSessionImpl::findInjectedScript(
169 ErrorString* errorString, int contextId) { 169 int contextId, InjectedScript*& injectedScript) {
170 if (!contextId) { 170 injectedScript = nullptr;
171 *errorString = "Cannot find context with specified id"; 171 if (!contextId)
172 return nullptr; 172 return Response::Error("Cannot find context with specified id");
173 }
174 173
175 const V8InspectorImpl::ContextByIdMap* contexts = 174 const V8InspectorImpl::ContextByIdMap* contexts =
176 m_inspector->contextGroup(m_contextGroupId); 175 m_inspector->contextGroup(m_contextGroupId);
177 if (!contexts) { 176 if (!contexts)
178 *errorString = "Cannot find context with specified id"; 177 return Response::Error("Cannot find context with specified id");
179 return nullptr;
180 }
181 178
182 auto contextsIt = contexts->find(contextId); 179 auto contextsIt = contexts->find(contextId);
183 if (contextsIt == contexts->end()) { 180 if (contextsIt == contexts->end())
184 *errorString = "Cannot find context with specified id"; 181 return Response::Error("Cannot find context with specified id");
185 return nullptr;
186 }
187 182
188 const std::unique_ptr<InspectedContext>& context = contextsIt->second; 183 const std::unique_ptr<InspectedContext>& context = contextsIt->second;
189 if (!context->getInjectedScript()) { 184 if (!context->getInjectedScript()) {
190 if (!context->createInjectedScript()) { 185 if (!context->createInjectedScript())
191 *errorString = "Cannot access specified execution context"; 186 return Response::Error("Cannot access specified execution context");
192 return nullptr;
193 }
194 if (m_customObjectFormatterEnabled) 187 if (m_customObjectFormatterEnabled)
195 context->getInjectedScript()->setCustomObjectFormatterEnabled(true); 188 context->getInjectedScript()->setCustomObjectFormatterEnabled(true);
196 } 189 }
197 return context->getInjectedScript(); 190 injectedScript = context->getInjectedScript();
191 return Response::OK();
198 } 192 }
199 193
200 InjectedScript* V8InspectorSessionImpl::findInjectedScript( 194 Response V8InspectorSessionImpl::findInjectedScript(
201 ErrorString* errorString, RemoteObjectIdBase* objectId) { 195 RemoteObjectIdBase* objectId, InjectedScript*& injectedScript) {
202 return objectId ? findInjectedScript(errorString, objectId->contextId()) 196 if (!objectId) return Response::InternalError();
dgozman 2016/11/03 22:23:49 Let's just remove this line?
kozy 2016/11/03 22:26:20 Done.
203 : nullptr; 197 return findInjectedScript(objectId->contextId(), injectedScript);
204 } 198 }
205 199
206 void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) { 200 void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) {
207 releaseObjectGroup(toString16(objectGroup)); 201 releaseObjectGroup(toString16(objectGroup));
208 } 202 }
209 203
210 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) { 204 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) {
211 const V8InspectorImpl::ContextByIdMap* contexts = 205 const V8InspectorImpl::ContextByIdMap* contexts =
212 m_inspector->contextGroup(m_contextGroupId); 206 m_inspector->contextGroup(m_contextGroupId);
213 if (!contexts) return; 207 if (!contexts) return;
214 208
215 std::vector<int> keys; 209 std::vector<int> keys;
216 for (auto& idContext : *contexts) keys.push_back(idContext.first); 210 for (auto& idContext : *contexts) keys.push_back(idContext.first);
217 for (auto& key : keys) { 211 for (auto& key : keys) {
218 contexts = m_inspector->contextGroup(m_contextGroupId); 212 contexts = m_inspector->contextGroup(m_contextGroupId);
219 if (!contexts) continue; 213 if (!contexts) continue;
220 auto contextsIt = contexts->find(key); 214 auto contextsIt = contexts->find(key);
221 if (contextsIt == contexts->end()) continue; 215 if (contextsIt == contexts->end()) continue;
222 InjectedScript* injectedScript = contextsIt->second->getInjectedScript(); 216 InjectedScript* injectedScript = contextsIt->second->getInjectedScript();
223 if (injectedScript) 217 if (injectedScript)
224 injectedScript->releaseObjectGroup( 218 injectedScript->releaseObjectGroup(
225 objectGroup); // This may destroy some contexts. 219 objectGroup); // This may destroy some contexts.
226 } 220 }
227 } 221 }
228 222
229 bool V8InspectorSessionImpl::unwrapObject( 223 bool V8InspectorSessionImpl::unwrapObject(
230 std::unique_ptr<StringBuffer>* error, const StringView& objectId, 224 std::unique_ptr<StringBuffer>* error, const StringView& objectId,
231 v8::Local<v8::Value>* object, v8::Local<v8::Context>* context, 225 v8::Local<v8::Value>* object, v8::Local<v8::Context>* context,
232 std::unique_ptr<StringBuffer>* objectGroup) { 226 std::unique_ptr<StringBuffer>* objectGroup) {
233 ErrorString errorString;
234 String16 objectGroupString; 227 String16 objectGroupString;
235 bool result = 228 Response response = unwrapObject(toString16(objectId), object, context,
236 unwrapObject(&errorString, toString16(objectId), object, context, 229 objectGroup ? &objectGroupString : nullptr);
237 objectGroup ? &objectGroupString : nullptr); 230 if (!response.isSuccess()) {
238 if (error) *error = StringBufferImpl::adopt(errorString); 231 if (error) {
232 String16 errorMessage = response.errorMessage();
233 *error = StringBufferImpl::adopt(errorMessage);
234 }
235 return false;
236 }
239 if (objectGroup) *objectGroup = StringBufferImpl::adopt(objectGroupString); 237 if (objectGroup) *objectGroup = StringBufferImpl::adopt(objectGroupString);
240 return result;
241 }
242
243 bool V8InspectorSessionImpl::unwrapObject(ErrorString* errorString,
244 const String16& objectId,
245 v8::Local<v8::Value>* object,
246 v8::Local<v8::Context>* context,
247 String16* objectGroup) {
248 std::unique_ptr<RemoteObjectId> remoteId =
249 RemoteObjectId::parse(errorString, objectId);
250 if (!remoteId) return false;
251 InjectedScript* injectedScript =
252 findInjectedScript(errorString, remoteId.get());
253 if (!injectedScript) return false;
254 if (!injectedScript->findObject(errorString, *remoteId, object)) return false;
255 *context = injectedScript->context()->context();
256 if (objectGroup) *objectGroup = injectedScript->objectGroupName(*remoteId);
257 return true; 238 return true;
258 } 239 }
259 240
241 Response V8InspectorSessionImpl::unwrapObject(const String16& objectId,
242 v8::Local<v8::Value>* object,
243 v8::Local<v8::Context>* context,
244 String16* objectGroup) {
245 std::unique_ptr<RemoteObjectId> remoteId;
246 Response response = RemoteObjectId::parse(objectId, &remoteId);
247 if (!response.isSuccess()) return response;
248 InjectedScript* injectedScript = nullptr;
249 response = findInjectedScript(remoteId.get(), injectedScript);
250 if (!response.isSuccess()) return response;
251 response = injectedScript->findObject(*remoteId, object);
252 if (!response.isSuccess()) return response;
253 *context = injectedScript->context()->context();
254 if (objectGroup) *objectGroup = injectedScript->objectGroupName(*remoteId);
255 return Response::OK();
256 }
257
260 std::unique_ptr<protocol::Runtime::API::RemoteObject> 258 std::unique_ptr<protocol::Runtime::API::RemoteObject>
261 V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context, 259 V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context,
262 v8::Local<v8::Value> value, 260 v8::Local<v8::Value> value,
263 const StringView& groupName) { 261 const StringView& groupName) {
264 return wrapObject(context, value, toString16(groupName), false); 262 return wrapObject(context, value, toString16(groupName), false);
265 } 263 }
266 264
267 std::unique_ptr<protocol::Runtime::RemoteObject> 265 std::unique_ptr<protocol::Runtime::RemoteObject>
268 V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context, 266 V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context,
269 v8::Local<v8::Value> value, 267 v8::Local<v8::Value> value,
270 const String16& groupName, 268 const String16& groupName,
271 bool generatePreview) { 269 bool generatePreview) {
272 ErrorString errorString; 270 InjectedScript* injectedScript = nullptr;
273 InjectedScript* injectedScript = 271 findInjectedScript(V8Debugger::contextId(context), injectedScript);
274 findInjectedScript(&errorString, V8Debugger::contextId(context));
275 if (!injectedScript) return nullptr; 272 if (!injectedScript) return nullptr;
276 return injectedScript->wrapObject(&errorString, value, groupName, false, 273 std::unique_ptr<protocol::Runtime::RemoteObject> result;
277 generatePreview); 274 injectedScript->wrapObject(value, groupName, false, generatePreview, &result);
275 return result;
278 } 276 }
279 277
280 std::unique_ptr<protocol::Runtime::RemoteObject> 278 std::unique_ptr<protocol::Runtime::RemoteObject>
281 V8InspectorSessionImpl::wrapTable(v8::Local<v8::Context> context, 279 V8InspectorSessionImpl::wrapTable(v8::Local<v8::Context> context,
282 v8::Local<v8::Value> table, 280 v8::Local<v8::Value> table,
283 v8::Local<v8::Value> columns) { 281 v8::Local<v8::Value> columns) {
284 ErrorString errorString; 282 InjectedScript* injectedScript = nullptr;
285 InjectedScript* injectedScript = 283 findInjectedScript(V8Debugger::contextId(context), injectedScript);
286 findInjectedScript(&errorString, V8Debugger::contextId(context));
287 if (!injectedScript) return nullptr; 284 if (!injectedScript) return nullptr;
288 return injectedScript->wrapTable(table, columns); 285 return injectedScript->wrapTable(table, columns);
289 } 286 }
290 287
291 void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) { 288 void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) {
292 m_customObjectFormatterEnabled = enabled; 289 m_customObjectFormatterEnabled = enabled;
293 const V8InspectorImpl::ContextByIdMap* contexts = 290 const V8InspectorImpl::ContextByIdMap* contexts =
294 m_inspector->contextGroup(m_contextGroupId); 291 m_inspector->contextGroup(m_contextGroupId);
295 if (!contexts) return; 292 if (!contexts) return;
296 for (auto& idContext : *contexts) { 293 for (auto& idContext : *contexts) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 } 376 }
380 377
381 void V8InspectorSessionImpl::breakProgram(const StringView& breakReason, 378 void V8InspectorSessionImpl::breakProgram(const StringView& breakReason,
382 const StringView& breakDetails) { 379 const StringView& breakDetails) {
383 m_debuggerAgent->breakProgram( 380 m_debuggerAgent->breakProgram(
384 toString16(breakReason), 381 toString16(breakReason),
385 protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails))); 382 protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails)));
386 } 383 }
387 384
388 void V8InspectorSessionImpl::setSkipAllPauses(bool skip) { 385 void V8InspectorSessionImpl::setSkipAllPauses(bool skip) {
389 ErrorString errorString; 386 protocol::ErrorString errorString;
390 m_debuggerAgent->setSkipAllPauses(&errorString, skip); 387 m_debuggerAgent->setSkipAllPauses(&errorString, skip);
391 } 388 }
392 389
393 void V8InspectorSessionImpl::resume() { 390 void V8InspectorSessionImpl::resume() {
394 ErrorString errorString; 391 protocol::ErrorString errorString;
395 m_debuggerAgent->resume(&errorString); 392 m_debuggerAgent->resume(&errorString);
396 } 393 }
397 394
398 void V8InspectorSessionImpl::stepOver() { 395 void V8InspectorSessionImpl::stepOver() {
399 ErrorString errorString; 396 protocol::ErrorString errorString;
400 m_debuggerAgent->stepOver(&errorString); 397 m_debuggerAgent->stepOver(&errorString);
401 } 398 }
402 399
403 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> 400 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>>
404 V8InspectorSessionImpl::searchInTextByLines(const StringView& text, 401 V8InspectorSessionImpl::searchInTextByLines(const StringView& text,
405 const StringView& query, 402 const StringView& query,
406 bool caseSensitive, bool isRegex) { 403 bool caseSensitive, bool isRegex) {
407 // TODO(dgozman): search may operate on StringView and avoid copying |text|. 404 // TODO(dgozman): search may operate on StringView and avoid copying |text|.
408 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = 405 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches =
409 searchInTextByLinesImpl(this, toString16(text), toString16(query), 406 searchInTextByLinesImpl(this, toString16(text), toString16(query),
410 caseSensitive, isRegex); 407 caseSensitive, isRegex);
411 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> result; 408 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> result;
412 for (size_t i = 0; i < matches.size(); ++i) 409 for (size_t i = 0; i < matches.size(); ++i)
413 result.push_back(std::move(matches[i])); 410 result.push_back(std::move(matches[i]));
414 return result; 411 return result;
415 } 412 }
416 413
417 } // namespace v8_inspector 414 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-inspector-session-impl.h ('k') | src/inspector/v8-runtime-agent-impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698