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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8InspectorSessionImpl.cpp

Issue 2260233002: [DevTools] Migrate v8_inspector/public from String16 to String{View,Buffer}. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: styling Created 4 years, 3 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
OLDNEW
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/v8_inspector/InjectedScript.h" 7 #include "platform/v8_inspector/InjectedScript.h"
8 #include "platform/v8_inspector/InspectedContext.h" 8 #include "platform/v8_inspector/InspectedContext.h"
9 #include "platform/v8_inspector/RemoteObjectId.h" 9 #include "platform/v8_inspector/RemoteObjectId.h"
10 #include "platform/v8_inspector/V8ConsoleAgentImpl.h" 10 #include "platform/v8_inspector/V8ConsoleAgentImpl.h"
11 #include "platform/v8_inspector/V8Debugger.h" 11 #include "platform/v8_inspector/V8Debugger.h"
12 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" 12 #include "platform/v8_inspector/V8DebuggerAgentImpl.h"
13 #include "platform/v8_inspector/V8HeapProfilerAgentImpl.h" 13 #include "platform/v8_inspector/V8HeapProfilerAgentImpl.h"
14 #include "platform/v8_inspector/V8InspectorImpl.h" 14 #include "platform/v8_inspector/V8InspectorImpl.h"
15 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" 15 #include "platform/v8_inspector/V8ProfilerAgentImpl.h"
16 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" 16 #include "platform/v8_inspector/V8RuntimeAgentImpl.h"
17 #include "platform/v8_inspector/V8SchemaAgentImpl.h" 17 #include "platform/v8_inspector/V8SchemaAgentImpl.h"
18 #include "platform/v8_inspector/V8StringUtil.h" 18 #include "platform/v8_inspector/V8StringUtil.h"
19 #include "platform/v8_inspector/public/V8ContextInfo.h" 19 #include "platform/v8_inspector/public/V8ContextInfo.h"
20 #include "platform/v8_inspector/public/V8InspectorClient.h" 20 #include "platform/v8_inspector/public/V8InspectorClient.h"
21 21
22 namespace v8_inspector { 22 namespace v8_inspector {
23 23
24 // static 24 // static
25 bool V8InspectorSession::canDispatchMethod(const String16& method) 25 bool V8InspectorSession::canDispatchMethod(const StringView& method)
26 { 26 {
27 return method.startsWith(protocol::Runtime::Metainfo::commandPrefix) 27 return stringViewStartsWith(method, protocol::Runtime::Metainfo::commandPref ix)
28 || method.startsWith(protocol::Debugger::Metainfo::commandPrefix) 28 || stringViewStartsWith(method, protocol::Debugger::Metainfo::commandPre fix)
29 || method.startsWith(protocol::Profiler::Metainfo::commandPrefix) 29 || stringViewStartsWith(method, protocol::Profiler::Metainfo::commandPre fix)
30 || method.startsWith(protocol::HeapProfiler::Metainfo::commandPrefix) 30 || stringViewStartsWith(method, protocol::HeapProfiler::Metainfo::comman dPrefix)
31 || method.startsWith(protocol::Console::Metainfo::commandPrefix) 31 || stringViewStartsWith(method, protocol::Console::Metainfo::commandPref ix)
32 || method.startsWith(protocol::Schema::Metainfo::commandPrefix); 32 || stringViewStartsWith(method, protocol::Schema::Metainfo::commandPrefi x);
33 } 33 }
34 34
35 std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(V8Inspect orImpl* inspector, int contextGroupId, protocol::FrontendChannel* channel, const String16* state) 35 std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(V8Inspect orImpl* inspector, int contextGroupId, protocol::FrontendChannel* channel, const StringView& state)
36 { 36 {
37 return wrapUnique(new V8InspectorSessionImpl(inspector, contextGroupId, chan nel, state)); 37 return wrapUnique(new V8InspectorSessionImpl(inspector, contextGroupId, chan nel, state));
38 } 38 }
39 39
40 V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, int c ontextGroupId, protocol::FrontendChannel* channel, const String16* savedState) 40 V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, int c ontextGroupId, protocol::FrontendChannel* channel, const StringView& savedState)
41 : m_contextGroupId(contextGroupId) 41 : m_contextGroupId(contextGroupId)
42 , m_inspector(inspector) 42 , m_inspector(inspector)
43 , m_customObjectFormatterEnabled(false) 43 , m_customObjectFormatterEnabled(false)
44 , m_dispatcher(channel) 44 , m_dispatcher(channel)
45 , m_state(nullptr) 45 , m_state(nullptr)
46 , m_runtimeAgent(nullptr) 46 , m_runtimeAgent(nullptr)
47 , m_debuggerAgent(nullptr) 47 , m_debuggerAgent(nullptr)
48 , m_heapProfilerAgent(nullptr) 48 , m_heapProfilerAgent(nullptr)
49 , m_profilerAgent(nullptr) 49 , m_profilerAgent(nullptr)
50 , m_consoleAgent(nullptr) 50 , m_consoleAgent(nullptr)
51 , m_schemaAgent(nullptr) 51 , m_schemaAgent(nullptr)
52 { 52 {
53 if (savedState) { 53 if (savedState.length()) {
54 std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState ); 54 std::unique_ptr<protocol::Value> state = protocol::parseJSON(toString16( savedState));
55 if (state) 55 if (state)
56 m_state = protocol::DictionaryValue::cast(std::move(state)); 56 m_state = protocol::DictionaryValue::cast(std::move(state));
57 if (!m_state) 57 if (!m_state)
58 m_state = protocol::DictionaryValue::create(); 58 m_state = protocol::DictionaryValue::create();
59 } else { 59 } else {
60 m_state = protocol::DictionaryValue::create(); 60 m_state = protocol::DictionaryValue::create();
61 } 61 }
62 62
63 m_runtimeAgent = wrapUnique(new V8RuntimeAgentImpl(this, channel, agentState (protocol::Runtime::Metainfo::domainName))); 63 m_runtimeAgent = wrapUnique(new V8RuntimeAgentImpl(this, channel, agentState (protocol::Runtime::Metainfo::domainName)));
64 protocol::Runtime::Dispatcher::wire(&m_dispatcher, m_runtimeAgent.get()); 64 protocol::Runtime::Dispatcher::wire(&m_dispatcher, m_runtimeAgent.get());
65 65
66 m_debuggerAgent = wrapUnique(new V8DebuggerAgentImpl(this, channel, agentSta te(protocol::Debugger::Metainfo::domainName))); 66 m_debuggerAgent = wrapUnique(new V8DebuggerAgentImpl(this, channel, agentSta te(protocol::Debugger::Metainfo::domainName)));
67 protocol::Debugger::Dispatcher::wire(&m_dispatcher, m_debuggerAgent.get()); 67 protocol::Debugger::Dispatcher::wire(&m_dispatcher, m_debuggerAgent.get());
68 68
69 m_profilerAgent = wrapUnique(new V8ProfilerAgentImpl(this, channel, agentSta te(protocol::Profiler::Metainfo::domainName))); 69 m_profilerAgent = wrapUnique(new V8ProfilerAgentImpl(this, channel, agentSta te(protocol::Profiler::Metainfo::domainName)));
70 protocol::Profiler::Dispatcher::wire(&m_dispatcher, m_profilerAgent.get()); 70 protocol::Profiler::Dispatcher::wire(&m_dispatcher, m_profilerAgent.get());
71 71
72 m_heapProfilerAgent = wrapUnique(new V8HeapProfilerAgentImpl(this, channel, agentState(protocol::HeapProfiler::Metainfo::domainName))); 72 m_heapProfilerAgent = wrapUnique(new V8HeapProfilerAgentImpl(this, channel, agentState(protocol::HeapProfiler::Metainfo::domainName)));
73 protocol::HeapProfiler::Dispatcher::wire(&m_dispatcher, m_heapProfilerAgent. get()); 73 protocol::HeapProfiler::Dispatcher::wire(&m_dispatcher, m_heapProfilerAgent. get());
74 74
75 m_consoleAgent = wrapUnique(new V8ConsoleAgentImpl(this, channel, agentState (protocol::Console::Metainfo::domainName))); 75 m_consoleAgent = wrapUnique(new V8ConsoleAgentImpl(this, channel, agentState (protocol::Console::Metainfo::domainName)));
76 protocol::Console::Dispatcher::wire(&m_dispatcher, m_consoleAgent.get()); 76 protocol::Console::Dispatcher::wire(&m_dispatcher, m_consoleAgent.get());
77 77
78 m_schemaAgent = wrapUnique(new V8SchemaAgentImpl(this, channel, agentState(p rotocol::Schema::Metainfo::domainName))); 78 m_schemaAgent = wrapUnique(new V8SchemaAgentImpl(this, channel, agentState(p rotocol::Schema::Metainfo::domainName)));
79 protocol::Schema::Dispatcher::wire(&m_dispatcher, m_schemaAgent.get()); 79 protocol::Schema::Dispatcher::wire(&m_dispatcher, m_schemaAgent.get());
80 80
81 if (savedState) { 81 if (savedState.length()) {
82 m_runtimeAgent->restore(); 82 m_runtimeAgent->restore();
83 m_debuggerAgent->restore(); 83 m_debuggerAgent->restore();
84 m_heapProfilerAgent->restore(); 84 m_heapProfilerAgent->restore();
85 m_profilerAgent->restore(); 85 m_profilerAgent->restore();
86 m_consoleAgent->restore(); 86 m_consoleAgent->restore();
87 } 87 }
88 } 88 }
89 89
90 V8InspectorSessionImpl::~V8InspectorSessionImpl() 90 V8InspectorSessionImpl::~V8InspectorSessionImpl()
91 { 91 {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 context->getInjectedScript()->setCustomObjectFormatterEnabled(true); 169 context->getInjectedScript()->setCustomObjectFormatterEnabled(true);
170 } 170 }
171 return context->getInjectedScript(); 171 return context->getInjectedScript();
172 } 172 }
173 173
174 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr ing, RemoteObjectIdBase* objectId) 174 InjectedScript* V8InspectorSessionImpl::findInjectedScript(ErrorString* errorStr ing, RemoteObjectIdBase* objectId)
175 { 175 {
176 return objectId ? findInjectedScript(errorString, objectId->contextId()) : n ullptr; 176 return objectId ? findInjectedScript(errorString, objectId->contextId()) : n ullptr;
177 } 177 }
178 178
179 void V8InspectorSessionImpl::releaseObjectGroup(const StringView& objectGroup)
180 {
181 releaseObjectGroup(toString16(objectGroup));
182 }
183
179 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup) 184 void V8InspectorSessionImpl::releaseObjectGroup(const String16& objectGroup)
180 { 185 {
181 const V8InspectorImpl::ContextByIdMap* contexts = m_inspector->contextGroup( m_contextGroupId); 186 const V8InspectorImpl::ContextByIdMap* contexts = m_inspector->contextGroup( m_contextGroupId);
182 if (!contexts) 187 if (!contexts)
183 return; 188 return;
184 189
185 std::vector<int> keys; 190 std::vector<int> keys;
186 for (auto& idContext : *contexts) 191 for (auto& idContext : *contexts)
187 keys.push_back(idContext.first); 192 keys.push_back(idContext.first);
188 for (auto& key : keys) { 193 for (auto& key : keys) {
189 contexts = m_inspector->contextGroup(m_contextGroupId); 194 contexts = m_inspector->contextGroup(m_contextGroupId);
190 if (!contexts) 195 if (!contexts)
191 continue; 196 continue;
192 auto contextsIt = contexts->find(key); 197 auto contextsIt = contexts->find(key);
193 if (contextsIt == contexts->end()) 198 if (contextsIt == contexts->end())
194 continue; 199 continue;
195 InjectedScript* injectedScript = contextsIt->second->getInjectedScript() ; 200 InjectedScript* injectedScript = contextsIt->second->getInjectedScript() ;
196 if (injectedScript) 201 if (injectedScript)
197 injectedScript->releaseObjectGroup(objectGroup); // This may destroy some contexts. 202 injectedScript->releaseObjectGroup(objectGroup); // This may destroy some contexts.
198 } 203 }
199 } 204 }
200 205
201 bool V8InspectorSessionImpl::unwrapObject(ErrorString* errorString, const String 16& objectId, v8::Local<v8::Value>* object, v8::Local<v8::Context>* context, Str ing16* objectGroup) 206 bool V8InspectorSessionImpl::unwrapObject(ErrorString* errorString, const String View& objectId, v8::Local<v8::Value>* object, v8::Local<v8::Context>* context, s td::unique_ptr<StringBuffer>* objectGroup)
202 { 207 {
203 std::unique_ptr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString , objectId); 208 std::unique_ptr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString , toString16(objectId));
204 if (!remoteId) 209 if (!remoteId)
205 return false; 210 return false;
206 InjectedScript* injectedScript = findInjectedScript(errorString, remoteId.ge t()); 211 InjectedScript* injectedScript = findInjectedScript(errorString, remoteId.ge t());
207 if (!injectedScript) 212 if (!injectedScript)
208 return false; 213 return false;
209 if (!injectedScript->findObject(errorString, *remoteId, object)) 214 if (!injectedScript->findObject(errorString, *remoteId, object))
210 return false; 215 return false;
211 *context = injectedScript->context()->context(); 216 *context = injectedScript->context()->context();
212 *objectGroup = injectedScript->objectGroupName(*remoteId); 217 if (objectGroup) {
218 String16 group = injectedScript->objectGroupName(*remoteId);
219 *objectGroup = StringBufferImpl::adopt(group);
220 }
213 return true; 221 return true;
214 } 222 }
215 223
216 std::unique_ptr<protocol::Runtime::API::RemoteObject> V8InspectorSessionImpl::wr apObject(v8::Local<v8::Context> context, v8::Local<v8::Value> value, const Strin g16& groupName) 224 std::unique_ptr<protocol::Runtime::API::RemoteObject> V8InspectorSessionImpl::wr apObject(v8::Local<v8::Context> context, v8::Local<v8::Value> value, const Strin gView& groupName)
217 { 225 {
218 return wrapObject(context, value, groupName, false); 226 return wrapObject(context, value, toString16(groupName), false);
219 } 227 }
220 228
221 std::unique_ptr<protocol::Runtime::RemoteObject> V8InspectorSessionImpl::wrapObj ect(v8::Local<v8::Context> context, v8::Local<v8::Value> value, const String16& groupName, bool generatePreview) 229 std::unique_ptr<protocol::Runtime::RemoteObject> V8InspectorSessionImpl::wrapObj ect(v8::Local<v8::Context> context, v8::Local<v8::Value> value, const String16& groupName, bool generatePreview)
222 { 230 {
223 ErrorString errorString; 231 ErrorString errorString;
224 InjectedScript* injectedScript = findInjectedScript(&errorString, V8Debugger ::contextId(context)); 232 InjectedScript* injectedScript = findInjectedScript(&errorString, V8Debugger ::contextId(context));
225 if (!injectedScript) 233 if (!injectedScript)
226 return nullptr; 234 return nullptr;
227 return injectedScript->wrapObject(&errorString, value, groupName, false, gen eratePreview); 235 return injectedScript->wrapObject(&errorString, value, groupName, false, gen eratePreview);
228 } 236 }
(...skipping 22 matching lines...) Expand all
251 259
252 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) 260 void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent)
253 { 261 {
254 const V8InspectorImpl::ContextByIdMap* contexts = m_inspector->contextGroup( m_contextGroupId); 262 const V8InspectorImpl::ContextByIdMap* contexts = m_inspector->contextGroup( m_contextGroupId);
255 if (!contexts) 263 if (!contexts)
256 return; 264 return;
257 for (auto& idContext : *contexts) 265 for (auto& idContext : *contexts)
258 agent->reportExecutionContextCreated(idContext.second.get()); 266 agent->reportExecutionContextCreated(idContext.second.get());
259 } 267 }
260 268
261 void V8InspectorSessionImpl::dispatchProtocolMessage(const String16& message) 269 void V8InspectorSessionImpl::dispatchProtocolMessage(const StringView& message)
262 { 270 {
263 m_dispatcher.dispatch(message); 271 m_dispatcher.dispatch(parseJSON(message));
264 } 272 }
265 273
266 String16 V8InspectorSessionImpl::stateJSON() 274 std::unique_ptr<StringBuffer> V8InspectorSessionImpl::stateJSON()
267 { 275 {
268 return m_state->toJSONString(); 276 String16 json = m_state->toJSONString();
277 return StringBufferImpl::adopt(json);
269 } 278 }
270 279
271 std::unique_ptr<protocol::Array<protocol::Schema::API::Domain>> V8InspectorSessi onImpl::supportedDomains() 280 std::unique_ptr<protocol::Array<protocol::Schema::API::Domain>> V8InspectorSessi onImpl::supportedDomains()
272 { 281 {
273 std::vector<std::unique_ptr<protocol::Schema::Domain>> domains = supportedDo mainsImpl(); 282 std::vector<std::unique_ptr<protocol::Schema::Domain>> domains = supportedDo mainsImpl();
274 std::unique_ptr<protocol::Array<protocol::Schema::API::Domain>> result = pro tocol::Array<protocol::Schema::API::Domain>::create(); 283 std::unique_ptr<protocol::Array<protocol::Schema::API::Domain>> result = pro tocol::Array<protocol::Schema::API::Domain>::create();
275 for (size_t i = 0; i < domains.size(); ++i) 284 for (size_t i = 0; i < domains.size(); ++i)
276 result->addItem(std::move(domains[i])); 285 result->addItem(std::move(domains[i]));
277 return result; 286 return result;
278 } 287 }
(...skipping 16 matching lines...) Expand all
295 m_inspectedObjects.resize(kInspectedObjectBufferSize); 304 m_inspectedObjects.resize(kInspectedObjectBufferSize);
296 } 305 }
297 306
298 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne d num) 307 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne d num)
299 { 308 {
300 if (num >= m_inspectedObjects.size()) 309 if (num >= m_inspectedObjects.size())
301 return nullptr; 310 return nullptr;
302 return m_inspectedObjects[num].get(); 311 return m_inspectedObjects[num].get();
303 } 312 }
304 313
305 void V8InspectorSessionImpl::schedulePauseOnNextStatement(const String16& breakR eason, const String16& breakDetails) 314 void V8InspectorSessionImpl::schedulePauseOnNextStatement(const StringView& brea kReason, const StringView& breakDetails)
306 { 315 {
307 m_debuggerAgent->schedulePauseOnNextStatement(breakReason, protocol::Diction aryValue::cast(parseJSON(breakDetails))); 316 m_debuggerAgent->schedulePauseOnNextStatement(toString16(breakReason), proto col::DictionaryValue::cast(parseJSON(breakDetails)));
308 } 317 }
309 318
310 void V8InspectorSessionImpl::cancelPauseOnNextStatement() 319 void V8InspectorSessionImpl::cancelPauseOnNextStatement()
311 { 320 {
312 m_debuggerAgent->cancelPauseOnNextStatement(); 321 m_debuggerAgent->cancelPauseOnNextStatement();
313 } 322 }
314 323
315 void V8InspectorSessionImpl::breakProgram(const String16& breakReason, const Str ing16& breakDetails) 324 void V8InspectorSessionImpl::breakProgram(const StringView& breakReason, const S tringView& breakDetails)
316 { 325 {
317 m_debuggerAgent->breakProgram(breakReason, protocol::DictionaryValue::cast(p arseJSON(breakDetails))); 326 m_debuggerAgent->breakProgram(toString16(breakReason), protocol::DictionaryV alue::cast(parseJSON(breakDetails)));
318 } 327 }
319 328
320 void V8InspectorSessionImpl::setSkipAllPauses(bool skip) 329 void V8InspectorSessionImpl::setSkipAllPauses(bool skip)
321 { 330 {
322 ErrorString errorString; 331 ErrorString errorString;
323 m_debuggerAgent->setSkipAllPauses(&errorString, skip); 332 m_debuggerAgent->setSkipAllPauses(&errorString, skip);
324 } 333 }
325 334
326 void V8InspectorSessionImpl::resume() 335 void V8InspectorSessionImpl::resume()
327 { 336 {
328 ErrorString errorString; 337 ErrorString errorString;
329 m_debuggerAgent->resume(&errorString); 338 m_debuggerAgent->resume(&errorString);
330 } 339 }
331 340
332 void V8InspectorSessionImpl::stepOver() 341 void V8InspectorSessionImpl::stepOver()
333 { 342 {
334 ErrorString errorString; 343 ErrorString errorString;
335 m_debuggerAgent->stepOver(&errorString); 344 m_debuggerAgent->stepOver(&errorString);
336 } 345 }
337 346
338 std::unique_ptr<protocol::Array<protocol::Debugger::API::SearchMatch>> V8Inspect orSessionImpl::searchInTextByLines(const String16& text, const String16& query, bool caseSensitive, bool isRegex) 347 std::unique_ptr<protocol::Array<protocol::Debugger::API::SearchMatch>> V8Inspect orSessionImpl::searchInTextByLines(const StringView& text, const StringView& que ry, bool caseSensitive, bool isRegex)
339 { 348 {
340 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = sear chInTextByLinesImpl(this, text, query, caseSensitive, isRegex); 349 // TODO(dgozman): search may operate on StringView and avoid copying |text|.
350 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = sear chInTextByLinesImpl(this, toString16(text), toString16(query), caseSensitive, is Regex);
341 std::unique_ptr<protocol::Array<protocol::Debugger::API::SearchMatch>> resul t = protocol::Array<protocol::Debugger::API::SearchMatch>::create(); 351 std::unique_ptr<protocol::Array<protocol::Debugger::API::SearchMatch>> resul t = protocol::Array<protocol::Debugger::API::SearchMatch>::create();
342 for (size_t i = 0; i < matches.size(); ++i) 352 for (size_t i = 0; i < matches.size(); ++i)
343 result->addItem(std::move(matches[i])); 353 result->addItem(std::move(matches[i]));
344 return result; 354 return result;
345 } 355 }
346 356
347 } // namespace v8_inspector 357 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698