| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 return findInjectedScript(objectId->contextId(), injectedScript); |
| 203 : nullptr; | |
| 204 } | 197 } |
| 205 | 198 |
| 206 void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) { | 199 void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup) { |
| 207 releaseObjectGroup(toString16(objectGroup)); | 200 releaseObjectGroup(toString16(objectGroup)); |
| 208 } | 201 } |
| 209 | 202 |
| 210 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) { | 203 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) { |
| 211 const V8InspectorImpl::ContextByIdMap* contexts = | 204 const V8InspectorImpl::ContextByIdMap* contexts = |
| 212 m_inspector->contextGroup(m_contextGroupId); | 205 m_inspector->contextGroup(m_contextGroupId); |
| 213 if (!contexts) return; | 206 if (!contexts) return; |
| 214 | 207 |
| 215 std::vector<int> keys; | 208 std::vector<int> keys; |
| 216 for (auto& idContext : *contexts) keys.push_back(idContext.first); | 209 for (auto& idContext : *contexts) keys.push_back(idContext.first); |
| 217 for (auto& key : keys) { | 210 for (auto& key : keys) { |
| 218 contexts = m_inspector->contextGroup(m_contextGroupId); | 211 contexts = m_inspector->contextGroup(m_contextGroupId); |
| 219 if (!contexts) continue; | 212 if (!contexts) continue; |
| 220 auto contextsIt = contexts->find(key); | 213 auto contextsIt = contexts->find(key); |
| 221 if (contextsIt == contexts->end()) continue; | 214 if (contextsIt == contexts->end()) continue; |
| 222 InjectedScript* injectedScript = contextsIt->second->getInjectedScript(); | 215 InjectedScript* injectedScript = contextsIt->second->getInjectedScript(); |
| 223 if (injectedScript) | 216 if (injectedScript) |
| 224 injectedScript->releaseObjectGroup( | 217 injectedScript->releaseObjectGroup( |
| 225 objectGroup); // This may destroy some contexts. | 218 objectGroup); // This may destroy some contexts. |
| 226 } | 219 } |
| 227 } | 220 } |
| 228 | 221 |
| 229 bool V8InspectorSessionImpl::unwrapObject( | 222 bool V8InspectorSessionImpl::unwrapObject( |
| 230 std::unique_ptr<StringBuffer>* error, const StringView& objectId, | 223 std::unique_ptr<StringBuffer>* error, const StringView& objectId, |
| 231 v8::Local<v8::Value>* object, v8::Local<v8::Context>* context, | 224 v8::Local<v8::Value>* object, v8::Local<v8::Context>* context, |
| 232 std::unique_ptr<StringBuffer>* objectGroup) { | 225 std::unique_ptr<StringBuffer>* objectGroup) { |
| 233 ErrorString errorString; | |
| 234 String16 objectGroupString; | 226 String16 objectGroupString; |
| 235 bool result = | 227 Response response = unwrapObject(toString16(objectId), object, context, |
| 236 unwrapObject(&errorString, toString16(objectId), object, context, | 228 objectGroup ? &objectGroupString : nullptr); |
| 237 objectGroup ? &objectGroupString : nullptr); | 229 if (!response.isSuccess()) { |
| 238 if (error) *error = StringBufferImpl::adopt(errorString); | 230 if (error) { |
| 231 String16 errorMessage = response.errorMessage(); |
| 232 *error = StringBufferImpl::adopt(errorMessage); |
| 233 } |
| 234 return false; |
| 235 } |
| 239 if (objectGroup) *objectGroup = StringBufferImpl::adopt(objectGroupString); | 236 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; | 237 return true; |
| 258 } | 238 } |
| 259 | 239 |
| 240 Response V8InspectorSessionImpl::unwrapObject(const String16& objectId, |
| 241 v8::Local<v8::Value>* object, |
| 242 v8::Local<v8::Context>* context, |
| 243 String16* objectGroup) { |
| 244 std::unique_ptr<RemoteObjectId> remoteId; |
| 245 Response response = RemoteObjectId::parse(objectId, &remoteId); |
| 246 if (!response.isSuccess()) return response; |
| 247 InjectedScript* injectedScript = nullptr; |
| 248 response = findInjectedScript(remoteId.get(), injectedScript); |
| 249 if (!response.isSuccess()) return response; |
| 250 response = injectedScript->findObject(*remoteId, object); |
| 251 if (!response.isSuccess()) return response; |
| 252 *context = injectedScript->context()->context(); |
| 253 if (objectGroup) *objectGroup = injectedScript->objectGroupName(*remoteId); |
| 254 return Response::OK(); |
| 255 } |
| 256 |
| 260 std::unique_ptr<protocol::Runtime::API::RemoteObject> | 257 std::unique_ptr<protocol::Runtime::API::RemoteObject> |
| 261 V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context, | 258 V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context, |
| 262 v8::Local<v8::Value> value, | 259 v8::Local<v8::Value> value, |
| 263 const StringView& groupName) { | 260 const StringView& groupName) { |
| 264 return wrapObject(context, value, toString16(groupName), false); | 261 return wrapObject(context, value, toString16(groupName), false); |
| 265 } | 262 } |
| 266 | 263 |
| 267 std::unique_ptr<protocol::Runtime::RemoteObject> | 264 std::unique_ptr<protocol::Runtime::RemoteObject> |
| 268 V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context, | 265 V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context, |
| 269 v8::Local<v8::Value> value, | 266 v8::Local<v8::Value> value, |
| 270 const String16& groupName, | 267 const String16& groupName, |
| 271 bool generatePreview) { | 268 bool generatePreview) { |
| 272 ErrorString errorString; | 269 InjectedScript* injectedScript = nullptr; |
| 273 InjectedScript* injectedScript = | 270 findInjectedScript(V8Debugger::contextId(context), injectedScript); |
| 274 findInjectedScript(&errorString, V8Debugger::contextId(context)); | |
| 275 if (!injectedScript) return nullptr; | 271 if (!injectedScript) return nullptr; |
| 276 return injectedScript->wrapObject(&errorString, value, groupName, false, | 272 std::unique_ptr<protocol::Runtime::RemoteObject> result; |
| 277 generatePreview); | 273 injectedScript->wrapObject(value, groupName, false, generatePreview, &result); |
| 274 return result; |
| 278 } | 275 } |
| 279 | 276 |
| 280 std::unique_ptr<protocol::Runtime::RemoteObject> | 277 std::unique_ptr<protocol::Runtime::RemoteObject> |
| 281 V8InspectorSessionImpl::wrapTable(v8::Local<v8::Context> context, | 278 V8InspectorSessionImpl::wrapTable(v8::Local<v8::Context> context, |
| 282 v8::Local<v8::Value> table, | 279 v8::Local<v8::Value> table, |
| 283 v8::Local<v8::Value> columns) { | 280 v8::Local<v8::Value> columns) { |
| 284 ErrorString errorString; | 281 InjectedScript* injectedScript = nullptr; |
| 285 InjectedScript* injectedScript = | 282 findInjectedScript(V8Debugger::contextId(context), injectedScript); |
| 286 findInjectedScript(&errorString, V8Debugger::contextId(context)); | |
| 287 if (!injectedScript) return nullptr; | 283 if (!injectedScript) return nullptr; |
| 288 return injectedScript->wrapTable(table, columns); | 284 return injectedScript->wrapTable(table, columns); |
| 289 } | 285 } |
| 290 | 286 |
| 291 void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) { | 287 void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) { |
| 292 m_customObjectFormatterEnabled = enabled; | 288 m_customObjectFormatterEnabled = enabled; |
| 293 const V8InspectorImpl::ContextByIdMap* contexts = | 289 const V8InspectorImpl::ContextByIdMap* contexts = |
| 294 m_inspector->contextGroup(m_contextGroupId); | 290 m_inspector->contextGroup(m_contextGroupId); |
| 295 if (!contexts) return; | 291 if (!contexts) return; |
| 296 for (auto& idContext : *contexts) { | 292 for (auto& idContext : *contexts) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 } | 375 } |
| 380 | 376 |
| 381 void V8InspectorSessionImpl::breakProgram(const StringView& breakReason, | 377 void V8InspectorSessionImpl::breakProgram(const StringView& breakReason, |
| 382 const StringView& breakDetails) { | 378 const StringView& breakDetails) { |
| 383 m_debuggerAgent->breakProgram( | 379 m_debuggerAgent->breakProgram( |
| 384 toString16(breakReason), | 380 toString16(breakReason), |
| 385 protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails))); | 381 protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails))); |
| 386 } | 382 } |
| 387 | 383 |
| 388 void V8InspectorSessionImpl::setSkipAllPauses(bool skip) { | 384 void V8InspectorSessionImpl::setSkipAllPauses(bool skip) { |
| 389 ErrorString errorString; | 385 protocol::ErrorString errorString; |
| 390 m_debuggerAgent->setSkipAllPauses(&errorString, skip); | 386 m_debuggerAgent->setSkipAllPauses(&errorString, skip); |
| 391 } | 387 } |
| 392 | 388 |
| 393 void V8InspectorSessionImpl::resume() { | 389 void V8InspectorSessionImpl::resume() { |
| 394 ErrorString errorString; | 390 protocol::ErrorString errorString; |
| 395 m_debuggerAgent->resume(&errorString); | 391 m_debuggerAgent->resume(&errorString); |
| 396 } | 392 } |
| 397 | 393 |
| 398 void V8InspectorSessionImpl::stepOver() { | 394 void V8InspectorSessionImpl::stepOver() { |
| 399 ErrorString errorString; | 395 protocol::ErrorString errorString; |
| 400 m_debuggerAgent->stepOver(&errorString); | 396 m_debuggerAgent->stepOver(&errorString); |
| 401 } | 397 } |
| 402 | 398 |
| 403 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> | 399 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> |
| 404 V8InspectorSessionImpl::searchInTextByLines(const StringView& text, | 400 V8InspectorSessionImpl::searchInTextByLines(const StringView& text, |
| 405 const StringView& query, | 401 const StringView& query, |
| 406 bool caseSensitive, bool isRegex) { | 402 bool caseSensitive, bool isRegex) { |
| 407 // TODO(dgozman): search may operate on StringView and avoid copying |text|. | 403 // TODO(dgozman): search may operate on StringView and avoid copying |text|. |
| 408 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = | 404 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = |
| 409 searchInTextByLinesImpl(this, toString16(text), toString16(query), | 405 searchInTextByLinesImpl(this, toString16(text), toString16(query), |
| 410 caseSensitive, isRegex); | 406 caseSensitive, isRegex); |
| 411 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> result; | 407 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> result; |
| 412 for (size_t i = 0; i < matches.size(); ++i) | 408 for (size_t i = 0; i < matches.size(); ++i) |
| 413 result.push_back(std::move(matches[i])); | 409 result.push_back(std::move(matches[i])); |
| 414 return result; | 410 return result; |
| 415 } | 411 } |
| 416 | 412 |
| 417 } // namespace v8_inspector | 413 } // namespace v8_inspector |
| OLD | NEW |