| OLD | NEW |
| 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/inspector_protocol/Parser.h" |
| 8 #include "platform/v8_inspector/InjectedScript.h" | 8 #include "platform/v8_inspector/InjectedScript.h" |
| 9 #include "platform/v8_inspector/InspectedContext.h" | 9 #include "platform/v8_inspector/InspectedContext.h" |
| 10 #include "platform/v8_inspector/RemoteObjectId.h" | 10 #include "platform/v8_inspector/RemoteObjectId.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 discardInjectedScripts(); | 104 discardInjectedScripts(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void V8InspectorSessionImpl::discardInjectedScripts() | 107 void V8InspectorSessionImpl::discardInjectedScripts() |
| 108 { | 108 { |
| 109 m_inspectedObjects.clear(); | 109 m_inspectedObjects.clear(); |
| 110 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_
contextGroupId); | 110 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_
contextGroupId); |
| 111 if (!contexts) | 111 if (!contexts) |
| 112 return; | 112 return; |
| 113 | 113 |
| 114 protocol::Vector<int> keys; | 114 std::vector<int> keys; |
| 115 keys.reserve(contexts->size()); |
| 115 for (auto& idContext : *contexts) | 116 for (auto& idContext : *contexts) |
| 116 keys.append(idContext.first); | 117 keys.push_back(idContext.first); |
| 117 for (auto& key : keys) { | 118 for (auto& key : keys) { |
| 118 contexts = m_debugger->contextGroup(m_contextGroupId); | 119 contexts = m_debugger->contextGroup(m_contextGroupId); |
| 119 if (contexts && contexts->contains(key)) | 120 if (!contexts) |
| 120 contexts->get(key)->discardInjectedScript(); // This may destroy som
e contexts. | 121 continue; |
| 122 auto contextIt = contexts->find(key); |
| 123 if (contextIt != contexts->end()) |
| 124 contextIt->second->discardInjectedScript(); // This may destroy some
contexts. |
| 121 } | 125 } |
| 122 } | 126 } |
| 123 | 127 |
| 124 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr
ing, int contextId) | 128 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr
ing, int contextId) |
| 125 { | 129 { |
| 126 if (!contextId) { | 130 if (!contextId) { |
| 127 *errorString = "Cannot find context with specified id"; | 131 *errorString = "Cannot find context with specified id"; |
| 128 return nullptr; | 132 return nullptr; |
| 129 } | 133 } |
| 130 | 134 |
| 131 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_
contextGroupId); | 135 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_
contextGroupId); |
| 132 if (!contexts || !contexts->contains(contextId)) { | 136 auto contextsIt = contexts ? contexts->find(contextId) : contexts->end(); |
| 137 if (contextsIt == contexts->end()) { |
| 133 *errorString = "Cannot find context with specified id"; | 138 *errorString = "Cannot find context with specified id"; |
| 134 return nullptr; | 139 return nullptr; |
| 135 } | 140 } |
| 136 | 141 |
| 137 InspectedContext* context = contexts->get(contextId); | 142 const std::unique_ptr<InspectedContext>& context = contextsIt->second; |
| 138 if (!context->getInjectedScript()) { | 143 if (!context->getInjectedScript()) { |
| 139 context->createInjectedScript(); | 144 context->createInjectedScript(); |
| 140 if (!context->getInjectedScript()) { | 145 if (!context->getInjectedScript()) { |
| 141 *errorString = "Cannot access specified execution context"; | 146 *errorString = "Cannot access specified execution context"; |
| 142 return nullptr; | 147 return nullptr; |
| 143 } | 148 } |
| 144 if (m_customObjectFormatterEnabled) | 149 if (m_customObjectFormatterEnabled) |
| 145 context->getInjectedScript()->setCustomObjectFormatterEnabled(true); | 150 context->getInjectedScript()->setCustomObjectFormatterEnabled(true); |
| 146 } | 151 } |
| 147 return context->getInjectedScript(); | 152 return context->getInjectedScript(); |
| 148 } | 153 } |
| 149 | 154 |
| 150 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr
ing, RemoteObjectIdBase* objectId) | 155 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr
ing, RemoteObjectIdBase* objectId) |
| 151 { | 156 { |
| 152 return objectId ? findInjectedScript(errorString, objectId->contextId()) : n
ullptr; | 157 return objectId ? findInjectedScript(errorString, objectId->contextId()) : n
ullptr; |
| 153 } | 158 } |
| 154 | 159 |
| 155 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) | 160 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) |
| 156 { | 161 { |
| 157 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_
contextGroupId); | 162 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_
contextGroupId); |
| 158 if (!contexts) | 163 if (!contexts) |
| 159 return; | 164 return; |
| 160 | 165 |
| 161 protocol::Vector<int> keys; | 166 std::vector<int> keys; |
| 162 for (auto& idContext : *contexts) | 167 for (auto& idContext : *contexts) |
| 163 keys.append(idContext.first); | 168 keys.push_back(idContext.first); |
| 164 for (auto& key : keys) { | 169 for (auto& key : keys) { |
| 165 contexts = m_debugger->contextGroup(m_contextGroupId); | 170 contexts = m_debugger->contextGroup(m_contextGroupId); |
| 166 if (contexts && contexts->contains(key)) { | 171 if (!contexts) |
| 167 InjectedScript* injectedScript = contexts->get(key)->getInjectedScri
pt(); | 172 continue; |
| 168 if (injectedScript) | 173 auto contextsIt = contexts->find(key); |
| 169 injectedScript->releaseObjectGroup(objectGroup); // This may des
troy some contexts. | 174 if (contextsIt == contexts->end()) |
| 170 } | 175 continue; |
| 176 InjectedScript* injectedScript = contextsIt->second->getInjectedScript()
; |
| 177 if (injectedScript) |
| 178 injectedScript->releaseObjectGroup(objectGroup); // This may destroy
some contexts. |
| 171 } | 179 } |
| 172 } | 180 } |
| 173 | 181 |
| 174 v8::Local<v8::Value> V8InspectorSessionImpl::findObject(ErrorString* errorString
, const String16& objectId, v8::Local<v8::Context>* context, String16* groupName
) | 182 v8::Local<v8::Value> V8InspectorSessionImpl::findObject(ErrorString* errorString
, const String16& objectId, v8::Local<v8::Context>* context, String16* groupName
) |
| 175 { | 183 { |
| 176 std::unique_ptr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString
, objectId); | 184 std::unique_ptr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString
, objectId); |
| 177 if (!remoteId) | 185 if (!remoteId) |
| 178 return v8::Local<v8::Value>(); | 186 return v8::Local<v8::Value>(); |
| 179 InjectedScript* injectedScript = findInjectedScript(errorString, remoteId.ge
t()); | 187 InjectedScript* injectedScript = findInjectedScript(errorString, remoteId.ge
t()); |
| 180 if (!injectedScript) | 188 if (!injectedScript) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 injectedScript->setCustomObjectFormatterEnabled(enabled); | 228 injectedScript->setCustomObjectFormatterEnabled(enabled); |
| 221 } | 229 } |
| 222 } | 230 } |
| 223 | 231 |
| 224 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) | 232 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) |
| 225 { | 233 { |
| 226 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_
contextGroupId); | 234 const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->contextGroup(m_
contextGroupId); |
| 227 if (!contexts) | 235 if (!contexts) |
| 228 return; | 236 return; |
| 229 for (auto& idContext : *contexts) | 237 for (auto& idContext : *contexts) |
| 230 agent->reportExecutionContextCreated(idContext.second); | 238 agent->reportExecutionContextCreated(idContext.second.get()); |
| 231 } | 239 } |
| 232 | 240 |
| 233 void V8InspectorSessionImpl::changeInstrumentationCounter(int delta) | 241 void V8InspectorSessionImpl::changeInstrumentationCounter(int delta) |
| 234 { | 242 { |
| 235 DCHECK_GE(m_instrumentationCounter + delta, 0); | 243 DCHECK_GE(m_instrumentationCounter + delta, 0); |
| 236 if (!m_instrumentationCounter) | 244 if (!m_instrumentationCounter) |
| 237 m_client->startInstrumenting(); | 245 m_client->startInstrumenting(); |
| 238 m_instrumentationCounter += delta; | 246 m_instrumentationCounter += delta; |
| 239 if (!m_instrumentationCounter) | 247 if (!m_instrumentationCounter) |
| 240 m_client->stopInstrumenting(); | 248 m_client->stopInstrumenting(); |
| 241 } | 249 } |
| 242 | 250 |
| 243 void V8InspectorSessionImpl::dispatchProtocolMessage(const String16& message) | 251 void V8InspectorSessionImpl::dispatchProtocolMessage(const String16& message) |
| 244 { | 252 { |
| 245 m_dispatcher.dispatch(message); | 253 m_dispatcher.dispatch(message); |
| 246 } | 254 } |
| 247 | 255 |
| 248 String16 V8InspectorSessionImpl::stateJSON() | 256 String16 V8InspectorSessionImpl::stateJSON() |
| 249 { | 257 { |
| 250 return m_state->toJSONString(); | 258 return m_state->toJSONString(); |
| 251 } | 259 } |
| 252 | 260 |
| 253 void V8InspectorSessionImpl::addInspectedObject(std::unique_ptr<V8InspectorSessi
on::Inspectable> inspectable) | 261 void V8InspectorSessionImpl::addInspectedObject(std::unique_ptr<V8InspectorSessi
on::Inspectable> inspectable) |
| 254 { | 262 { |
| 255 m_inspectedObjects.prepend(std::move(inspectable)); | 263 m_inspectedObjects.insert(m_inspectedObjects.begin(), std::move(inspectable)
); |
| 256 while (m_inspectedObjects.size() > kInspectedObjectBufferSize) | 264 if (m_inspectedObjects.size() > kInspectedObjectBufferSize) |
| 257 m_inspectedObjects.removeLast(); | 265 m_inspectedObjects.resize(kInspectedObjectBufferSize); |
| 258 } | 266 } |
| 259 | 267 |
| 260 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne
d num) | 268 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne
d num) |
| 261 { | 269 { |
| 262 if (num >= m_inspectedObjects.size()) | 270 if (num >= m_inspectedObjects.size()) |
| 263 return nullptr; | 271 return nullptr; |
| 264 return m_inspectedObjects[num]; | 272 return m_inspectedObjects[num].get(); |
| 265 } | 273 } |
| 266 | 274 |
| 267 void V8InspectorSessionImpl::schedulePauseOnNextStatement(const String16& breakR
eason, std::unique_ptr<protocol::DictionaryValue> data) | 275 void V8InspectorSessionImpl::schedulePauseOnNextStatement(const String16& breakR
eason, std::unique_ptr<protocol::DictionaryValue> data) |
| 268 { | 276 { |
| 269 m_debuggerAgent->schedulePauseOnNextStatement(breakReason, std::move(data)); | 277 m_debuggerAgent->schedulePauseOnNextStatement(breakReason, std::move(data)); |
| 270 } | 278 } |
| 271 | 279 |
| 272 void V8InspectorSessionImpl::cancelPauseOnNextStatement() | 280 void V8InspectorSessionImpl::cancelPauseOnNextStatement() |
| 273 { | 281 { |
| 274 m_debuggerAgent->cancelPauseOnNextStatement(); | 282 m_debuggerAgent->cancelPauseOnNextStatement(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 296 m_debuggerAgent->resume(&errorString); | 304 m_debuggerAgent->resume(&errorString); |
| 297 } | 305 } |
| 298 | 306 |
| 299 void V8InspectorSessionImpl::stepOver() | 307 void V8InspectorSessionImpl::stepOver() |
| 300 { | 308 { |
| 301 ErrorString errorString; | 309 ErrorString errorString; |
| 302 m_debuggerAgent->stepOver(&errorString); | 310 m_debuggerAgent->stepOver(&errorString); |
| 303 } | 311 } |
| 304 | 312 |
| 305 } // namespace blink | 313 } // namespace blink |
| OLD | NEW |