Line data Source code
1 : /*
2 : * Copyright (C) 2012 Google Inc. All rights reserved.
3 : *
4 : * Redistribution and use in source and binary forms, with or without
5 : * modification, are permitted provided that the following conditions are
6 : * met:
7 : *
8 : * * Redistributions of source code must retain the above copyright
9 : * notice, this list of conditions and the following disclaimer.
10 : * * Redistributions in binary form must reproduce the above
11 : * copyright notice, this list of conditions and the following disclaimer
12 : * in the documentation and/or other materials provided with the
13 : * distribution.
14 : * * Neither the name of Google Inc. nor the names of its
15 : * contributors may be used to endorse or promote products derived from
16 : * this software without specific prior written permission.
17 : *
18 : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 : * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 : * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 : * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 : * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 : * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 : * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 : * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 : */
30 :
31 : #include "src/inspector/injected-script.h"
32 :
33 : #include "src/inspector/injected-script-native.h"
34 : #include "src/inspector/injected-script-source.h"
35 : #include "src/inspector/inspected-context.h"
36 : #include "src/inspector/protocol/Protocol.h"
37 : #include "src/inspector/remote-object-id.h"
38 : #include "src/inspector/string-util.h"
39 : #include "src/inspector/v8-console.h"
40 : #include "src/inspector/v8-function-call.h"
41 : #include "src/inspector/v8-injected-script-host.h"
42 : #include "src/inspector/v8-inspector-impl.h"
43 : #include "src/inspector/v8-inspector-session-impl.h"
44 : #include "src/inspector/v8-stack-trace-impl.h"
45 : #include "src/inspector/v8-value-copier.h"
46 :
47 : #include "include/v8-inspector.h"
48 :
49 : namespace v8_inspector {
50 :
51 : using protocol::Array;
52 : using protocol::Runtime::PropertyDescriptor;
53 : using protocol::Runtime::InternalPropertyDescriptor;
54 : using protocol::Runtime::RemoteObject;
55 : using protocol::Maybe;
56 :
57 4109 : std::unique_ptr<InjectedScript> InjectedScript::create(
58 16436 : InspectedContext* inspectedContext) {
59 4109 : v8::Isolate* isolate = inspectedContext->isolate();
60 4109 : v8::HandleScope handles(isolate);
61 4109 : v8::Local<v8::Context> context = inspectedContext->context();
62 : v8::Context::Scope scope(context);
63 :
64 : std::unique_ptr<InjectedScriptNative> injectedScriptNative(
65 4109 : new InjectedScriptNative(isolate));
66 : v8::Local<v8::Object> scriptHostWrapper =
67 4109 : V8InjectedScriptHost::create(context, inspectedContext->inspector());
68 4109 : injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper);
69 :
70 : // Inject javascript into the context. The compiled script is supposed to
71 : // evaluate into
72 : // a single anonymous function(it's anonymous to avoid cluttering the global
73 : // object with
74 : // inspector's stuff) the function is called a few lines below with
75 : // InjectedScriptHost wrapper,
76 : // injected script id and explicit reference to the inspected global object.
77 : // The function is expected
78 : // to create and configure InjectedScript instance that is going to be used by
79 : // the inspector.
80 : String16 injectedScriptSource(
81 : reinterpret_cast<const char*>(InjectedScriptSource_js),
82 4109 : sizeof(InjectedScriptSource_js));
83 : v8::Local<v8::Value> value;
84 4109 : if (!inspectedContext->inspector()
85 : ->compileAndRunInternalScript(
86 4109 : context, toV8String(isolate, injectedScriptSource))
87 8218 : .ToLocal(&value))
88 : return nullptr;
89 : DCHECK(value->IsFunction());
90 : v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value);
91 4109 : v8::Local<v8::Object> windowGlobal = context->Global();
92 : v8::Local<v8::Value> info[] = {
93 : scriptHostWrapper, windowGlobal,
94 4109 : v8::Number::New(isolate, inspectedContext->contextId())};
95 : v8::MicrotasksScope microtasksScope(isolate,
96 8218 : v8::MicrotasksScope::kDoNotRunMicrotasks);
97 :
98 : int contextGroupId = inspectedContext->contextGroupId();
99 : int contextId = inspectedContext->contextId();
100 : V8InspectorImpl* inspector = inspectedContext->inspector();
101 : v8::Local<v8::Value> injectedScriptValue;
102 4109 : if (!function->Call(context, windowGlobal, arraysize(info), info)
103 8218 : .ToLocal(&injectedScriptValue))
104 : return nullptr;
105 4109 : if (inspector->getContext(contextGroupId, contextId) != inspectedContext)
106 : return nullptr;
107 4109 : if (!injectedScriptValue->IsObject()) return nullptr;
108 : return std::unique_ptr<InjectedScript>(
109 : new InjectedScript(inspectedContext, injectedScriptValue.As<v8::Object>(),
110 16436 : std::move(injectedScriptNative)));
111 : }
112 :
113 4109 : InjectedScript::InjectedScript(
114 : InspectedContext* context, v8::Local<v8::Object> object,
115 : std::unique_ptr<InjectedScriptNative> injectedScriptNative)
116 : : m_context(context),
117 : m_value(context->isolate(), object),
118 8218 : m_native(std::move(injectedScriptNative)) {}
119 :
120 8218 : InjectedScript::~InjectedScript() {}
121 :
122 106248 : Response InjectedScript::getProperties(
123 : v8::Local<v8::Object> object, const String16& groupName, bool ownProperties,
124 : bool accessorPropertiesOnly, bool generatePreview,
125 : std::unique_ptr<Array<PropertyDescriptor>>* properties,
126 : Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) {
127 212496 : v8::HandleScope handles(m_context->isolate());
128 106248 : v8::Local<v8::Context> context = m_context->context();
129 : V8FunctionCall function(m_context->inspector(), m_context->context(),
130 318744 : v8Value(), "getProperties");
131 106248 : function.appendArgument(object);
132 106248 : function.appendArgument(groupName);
133 106248 : function.appendArgument(ownProperties);
134 106248 : function.appendArgument(accessorPropertiesOnly);
135 106248 : function.appendArgument(generatePreview);
136 :
137 212496 : v8::TryCatch tryCatch(m_context->isolate());
138 106248 : v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling();
139 106248 : if (tryCatch.HasCaught()) {
140 : Response response = createExceptionDetails(
141 0 : tryCatch, groupName, generatePreview, exceptionDetails);
142 0 : if (!response.isSuccess()) return response;
143 : // FIXME: make properties optional
144 : *properties = Array<PropertyDescriptor>::create();
145 0 : return Response::OK();
146 : }
147 106248 : if (resultValue.IsEmpty()) return Response::InternalError();
148 106248 : std::unique_ptr<protocol::Value> protocolValue;
149 106248 : Response response = toProtocolValue(context, resultValue, &protocolValue);
150 106248 : if (!response.isSuccess()) return response;
151 212496 : protocol::ErrorSupport errors;
152 : std::unique_ptr<Array<PropertyDescriptor>> result =
153 106248 : Array<PropertyDescriptor>::fromValue(protocolValue.get(), &errors);
154 106248 : if (errors.hasErrors()) return Response::Error(errors.errors());
155 : *properties = std::move(result);
156 212496 : return Response::OK();
157 : }
158 :
159 6 : void InjectedScript::releaseObject(const String16& objectId) {
160 : std::unique_ptr<protocol::Value> parsedObjectId =
161 6 : protocol::StringUtil::parseJSON(objectId);
162 6 : if (!parsedObjectId) return;
163 : protocol::DictionaryValue* object =
164 : protocol::DictionaryValue::cast(parsedObjectId.get());
165 6 : if (!object) return;
166 6 : int boundId = 0;
167 12 : if (!object->getInteger("id", &boundId)) return;
168 12 : m_native->unbind(boundId);
169 : }
170 :
171 31965 : Response InjectedScript::wrapObject(
172 : v8::Local<v8::Value> value, const String16& groupName, bool forceValueType,
173 : bool generatePreview,
174 : std::unique_ptr<protocol::Runtime::RemoteObject>* result) const {
175 31965 : v8::HandleScope handles(m_context->isolate());
176 : v8::Local<v8::Value> wrappedObject;
177 31965 : v8::Local<v8::Context> context = m_context->context();
178 : Response response = wrapValue(value, groupName, forceValueType,
179 31965 : generatePreview, &wrappedObject);
180 31965 : if (!response.isSuccess()) return response;
181 63900 : protocol::ErrorSupport errors;
182 31950 : std::unique_ptr<protocol::Value> protocolValue;
183 63900 : response = toProtocolValue(context, wrappedObject, &protocolValue);
184 31950 : if (!response.isSuccess()) return response;
185 :
186 63888 : *result =
187 : protocol::Runtime::RemoteObject::fromValue(protocolValue.get(), &errors);
188 31944 : if (!result->get()) return Response::Error(errors.errors());
189 63909 : return Response::OK();
190 : }
191 :
192 200104 : Response InjectedScript::wrapObjectProperty(v8::Local<v8::Object> object,
193 : v8::Local<v8::Name> key,
194 : const String16& groupName,
195 : bool forceValueType,
196 : bool generatePreview) const {
197 : v8::Local<v8::Value> property;
198 200104 : v8::Local<v8::Context> context = m_context->context();
199 400208 : if (!object->Get(context, key).ToLocal(&property))
200 0 : return Response::InternalError();
201 : v8::Local<v8::Value> wrappedProperty;
202 : Response response = wrapValue(property, groupName, forceValueType,
203 200104 : generatePreview, &wrappedProperty);
204 200104 : if (!response.isSuccess()) return response;
205 : v8::Maybe<bool> success =
206 200102 : createDataProperty(context, object, key, wrappedProperty);
207 400204 : if (success.IsNothing() || !success.FromJust())
208 0 : return Response::InternalError();
209 200102 : return Response::OK();
210 : }
211 :
212 191418 : Response InjectedScript::wrapPropertyInArray(v8::Local<v8::Array> array,
213 : v8::Local<v8::String> property,
214 : const String16& groupName,
215 : bool forceValueType,
216 : bool generatePreview) const {
217 : V8FunctionCall function(m_context->inspector(), m_context->context(),
218 382836 : v8Value(), "wrapPropertyInArray");
219 191418 : function.appendArgument(array);
220 191418 : function.appendArgument(property);
221 191418 : function.appendArgument(groupName);
222 191418 : function.appendArgument(forceValueType);
223 191418 : function.appendArgument(generatePreview);
224 191418 : bool hadException = false;
225 191418 : function.call(hadException);
226 382836 : return hadException ? Response::InternalError() : Response::OK();
227 : }
228 :
229 232069 : Response InjectedScript::wrapValue(v8::Local<v8::Value> value,
230 : const String16& groupName,
231 : bool forceValueType, bool generatePreview,
232 : v8::Local<v8::Value>* result) const {
233 : V8FunctionCall function(m_context->inspector(), m_context->context(),
234 464138 : v8Value(), "wrapObject");
235 232069 : function.appendArgument(value);
236 232069 : function.appendArgument(groupName);
237 232069 : function.appendArgument(forceValueType);
238 232069 : function.appendArgument(generatePreview);
239 232069 : bool hadException = false;
240 232069 : *result = function.call(hadException);
241 464121 : if (hadException || result->IsEmpty()) return Response::InternalError();
242 232052 : return Response::OK();
243 : }
244 :
245 120 : std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(
246 : v8::Local<v8::Value> table, v8::Local<v8::Value> columns) const {
247 240 : v8::HandleScope handles(m_context->isolate());
248 120 : v8::Local<v8::Context> context = m_context->context();
249 : V8FunctionCall function(m_context->inspector(), context, v8Value(),
250 360 : "wrapTable");
251 120 : function.appendArgument(table);
252 120 : if (columns.IsEmpty())
253 120 : function.appendArgument(false);
254 : else
255 0 : function.appendArgument(columns);
256 120 : bool hadException = false;
257 120 : v8::Local<v8::Value> r = function.call(hadException);
258 240 : if (hadException || r.IsEmpty()) return nullptr;
259 120 : std::unique_ptr<protocol::Value> protocolValue;
260 120 : Response response = toProtocolValue(context, r, &protocolValue);
261 120 : if (!response.isSuccess()) return nullptr;
262 240 : protocol::ErrorSupport errors;
263 : return protocol::Runtime::RemoteObject::fromValue(protocolValue.get(),
264 240 : &errors);
265 : }
266 :
267 107328 : Response InjectedScript::findObject(const RemoteObjectId& objectId,
268 : v8::Local<v8::Value>* outObject) const {
269 107328 : *outObject = m_native->objectForId(objectId.id());
270 107328 : if (outObject->IsEmpty())
271 0 : return Response::Error("Could not find object with given id");
272 107328 : return Response::OK();
273 : }
274 :
275 107298 : String16 InjectedScript::objectGroupName(const RemoteObjectId& objectId) const {
276 107298 : return m_native->groupName(objectId.id());
277 : }
278 :
279 64524 : void InjectedScript::releaseObjectGroup(const String16& objectGroup) {
280 64524 : m_native->releaseObjectGroup(objectGroup);
281 129048 : if (objectGroup == "console") m_lastEvaluationResult.Reset();
282 64524 : }
283 :
284 6 : void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) {
285 12 : v8::HandleScope handles(m_context->isolate());
286 : V8FunctionCall function(m_context->inspector(), m_context->context(),
287 18 : v8Value(), "setCustomObjectFormatterEnabled");
288 6 : function.appendArgument(enabled);
289 6 : bool hadException = false;
290 6 : function.call(hadException);
291 6 : DCHECK(!hadException);
292 6 : }
293 :
294 529861 : v8::Local<v8::Value> InjectedScript::v8Value() const {
295 1059722 : return m_value.Get(m_context->isolate());
296 : }
297 :
298 66 : v8::Local<v8::Value> InjectedScript::lastEvaluationResult() const {
299 66 : if (m_lastEvaluationResult.IsEmpty())
300 12 : return v8::Undefined(m_context->isolate());
301 60 : return m_lastEvaluationResult.Get(m_context->isolate());
302 : }
303 :
304 212 : Response InjectedScript::resolveCallArgument(
305 : protocol::Runtime::CallArgument* callArgument,
306 : v8::Local<v8::Value>* result) {
307 212 : if (callArgument->hasObjectId()) {
308 30 : std::unique_ptr<RemoteObjectId> remoteObjectId;
309 : Response response =
310 90 : RemoteObjectId::parse(callArgument->getObjectId(""), &remoteObjectId);
311 30 : if (!response.isSuccess()) return response;
312 206 : if (remoteObjectId->contextId() != m_context->contextId())
313 : return Response::Error(
314 : "Argument should belong to the same JavaScript world as target "
315 0 : "object");
316 30 : return findObject(*remoteObjectId, result);
317 : }
318 194 : if (callArgument->hasValue() || callArgument->hasUnserializableValue()) {
319 : String16 value =
320 : callArgument->hasValue()
321 170 : ? callArgument->getValue(nullptr)->serialize()
322 370 : : "Number(\"" + callArgument->getUnserializableValue("") + "\")";
323 176 : if (!m_context->inspector()
324 : ->compileAndRunInternalScript(
325 176 : m_context->context(), toV8String(m_context->isolate(), value))
326 352 : .ToLocal(result)) {
327 0 : return Response::Error("Couldn't parse value object in call argument");
328 : }
329 176 : return Response::OK();
330 : }
331 12 : *result = v8::Undefined(m_context->isolate());
332 6 : return Response::OK();
333 : }
334 :
335 1590 : Response InjectedScript::createExceptionDetails(
336 : const v8::TryCatch& tryCatch, const String16& objectGroup,
337 : bool generatePreview, Maybe<protocol::Runtime::ExceptionDetails>* result) {
338 1590 : if (!tryCatch.HasCaught()) return Response::InternalError();
339 1590 : v8::Local<v8::Message> message = tryCatch.Message();
340 1590 : v8::Local<v8::Value> exception = tryCatch.Exception();
341 : String16 messageText =
342 3180 : message.IsEmpty() ? String16() : toProtocolString(message->Get());
343 : std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails =
344 : protocol::Runtime::ExceptionDetails::create()
345 4770 : .setExceptionId(m_context->inspector()->nextExceptionId())
346 4770 : .setText(exception.IsEmpty() ? messageText : String16("Uncaught"))
347 : .setLineNumber(
348 : message.IsEmpty()
349 : ? 0
350 3180 : : message->GetLineNumber(m_context->context()).FromMaybe(1) -
351 3180 : 1)
352 : .setColumnNumber(
353 : message.IsEmpty()
354 : ? 0
355 4806 : : message->GetStartColumn(m_context->context()).FromMaybe(0))
356 : .build();
357 1590 : if (!message.IsEmpty()) {
358 : exceptionDetails->setScriptId(String16::fromInteger(
359 3180 : static_cast<int>(message->GetScriptOrigin().ScriptID()->Value())));
360 1590 : v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace();
361 1590 : if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0)
362 : exceptionDetails->setStackTrace(m_context->inspector()
363 : ->debugger()
364 : ->createStackTrace(stackTrace)
365 180 : ->buildInspectorObjectImpl());
366 : }
367 1590 : if (!exception.IsEmpty()) {
368 1590 : std::unique_ptr<protocol::Runtime::RemoteObject> wrapped;
369 : Response response =
370 : wrapObject(exception, objectGroup, false /* forceValueType */,
371 1590 : generatePreview && !exception->IsNativeError(), &wrapped);
372 1590 : if (!response.isSuccess()) return response;
373 : exceptionDetails->setException(std::move(wrapped));
374 : }
375 : *result = std::move(exceptionDetails);
376 1590 : return Response::OK();
377 : }
378 :
379 18985 : Response InjectedScript::wrapEvaluateResult(
380 : v8::MaybeLocal<v8::Value> maybeResultValue, const v8::TryCatch& tryCatch,
381 : const String16& objectGroup, bool returnByValue, bool generatePreview,
382 : std::unique_ptr<protocol::Runtime::RemoteObject>* result,
383 : Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) {
384 : v8::Local<v8::Value> resultValue;
385 18985 : if (!tryCatch.HasCaught()) {
386 17410 : if (!maybeResultValue.ToLocal(&resultValue))
387 0 : return Response::InternalError();
388 : Response response = wrapObject(resultValue, objectGroup, returnByValue,
389 17410 : generatePreview, result);
390 17410 : if (!response.isSuccess()) return response;
391 34820 : if (objectGroup == "console")
392 198 : m_lastEvaluationResult.Reset(m_context->isolate(), resultValue);
393 : } else {
394 1575 : v8::Local<v8::Value> exception = tryCatch.Exception();
395 : Response response =
396 : wrapObject(exception, objectGroup, false,
397 1575 : generatePreview && !exception->IsNativeError(), result);
398 1575 : if (!response.isSuccess()) return response;
399 : // We send exception in result for compatibility reasons, even though it's
400 : // accessible through exceptionDetails.exception.
401 3120 : response = createExceptionDetails(tryCatch, objectGroup, generatePreview,
402 : exceptionDetails);
403 1560 : if (!response.isSuccess()) return response;
404 : }
405 18970 : return Response::OK();
406 : }
407 :
408 408 : v8::Local<v8::Object> InjectedScript::commandLineAPI() {
409 408 : if (m_commandLineAPI.IsEmpty()) {
410 : m_commandLineAPI.Reset(
411 : m_context->isolate(),
412 : m_context->inspector()->console()->createCommandLineAPI(
413 108 : m_context->context()));
414 : }
415 816 : return m_commandLineAPI.Get(m_context->isolate());
416 : }
417 :
418 379875 : InjectedScript::Scope::Scope(V8InspectorImpl* inspector, int contextGroupId)
419 : : m_inspector(inspector),
420 : m_contextGroupId(contextGroupId),
421 : m_injectedScript(nullptr),
422 : m_handleScope(inspector->isolate()),
423 : m_tryCatch(inspector->isolate()),
424 : m_ignoreExceptionsAndMuteConsole(false),
425 : m_previousPauseOnExceptionsState(v8::debug::NoBreakOnException),
426 506500 : m_userGesture(false) {}
427 :
428 146360 : Response InjectedScript::Scope::initialize() {
429 146360 : cleanup();
430 : // TODO(dgozman): what if we reattach to the same context group during
431 : // evaluate? Introduce a session id?
432 : V8InspectorSessionImpl* session =
433 146360 : m_inspector->sessionForContextGroup(m_contextGroupId);
434 146360 : if (!session) return Response::InternalError();
435 146354 : Response response = findInjectedScript(session);
436 146354 : if (!response.isSuccess()) return response;
437 146342 : m_context = m_injectedScript->context()->context();
438 146342 : m_context->Enter();
439 146342 : return Response::OK();
440 : }
441 :
442 408 : void InjectedScript::Scope::installCommandLineAPI() {
443 : DCHECK(m_injectedScript && !m_context.IsEmpty() &&
444 : !m_commandLineAPIScope.get());
445 : m_commandLineAPIScope.reset(new V8Console::CommandLineAPIScope(
446 1224 : m_context, m_injectedScript->commandLineAPI(), m_context->Global()));
447 408 : }
448 :
449 106254 : void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() {
450 : DCHECK(!m_ignoreExceptionsAndMuteConsole);
451 106254 : m_ignoreExceptionsAndMuteConsole = true;
452 106254 : m_inspector->client()->muteMetrics(m_contextGroupId);
453 106254 : m_inspector->muteExceptions(m_contextGroupId);
454 : m_previousPauseOnExceptionsState =
455 106254 : setPauseOnExceptionsState(v8::debug::NoBreakOnException);
456 106254 : }
457 :
458 212508 : v8::debug::ExceptionBreakState InjectedScript::Scope::setPauseOnExceptionsState(
459 : v8::debug::ExceptionBreakState newState) {
460 425016 : if (!m_inspector->debugger()->enabled()) return newState;
461 : v8::debug::ExceptionBreakState presentState =
462 423816 : m_inspector->debugger()->getPauseOnExceptionsState();
463 211908 : if (presentState != newState)
464 864 : m_inspector->debugger()->setPauseOnExceptionsState(newState);
465 211908 : return presentState;
466 : }
467 :
468 0 : void InjectedScript::Scope::pretendUserGesture() {
469 : DCHECK(!m_userGesture);
470 0 : m_userGesture = true;
471 0 : m_inspector->client()->beginUserGesture();
472 0 : }
473 :
474 272985 : void InjectedScript::Scope::cleanup() {
475 : m_commandLineAPIScope.reset();
476 272985 : if (!m_context.IsEmpty()) {
477 146342 : m_context->Exit();
478 : m_context.Clear();
479 : }
480 272985 : }
481 :
482 253250 : InjectedScript::Scope::~Scope() {
483 126625 : if (m_ignoreExceptionsAndMuteConsole) {
484 106254 : setPauseOnExceptionsState(m_previousPauseOnExceptionsState);
485 106254 : m_inspector->client()->unmuteMetrics(m_contextGroupId);
486 106254 : m_inspector->unmuteExceptions(m_contextGroupId);
487 : }
488 126625 : if (m_userGesture) m_inspector->client()->endUserGesture();
489 126625 : cleanup();
490 126625 : }
491 :
492 5435 : InjectedScript::ContextScope::ContextScope(V8InspectorImpl* inspector,
493 : int contextGroupId,
494 : int executionContextId)
495 : : InjectedScript::Scope(inspector, contextGroupId),
496 5435 : m_executionContextId(executionContextId) {}
497 :
498 5435 : InjectedScript::ContextScope::~ContextScope() {}
499 :
500 10264 : Response InjectedScript::ContextScope::findInjectedScript(
501 : V8InspectorSessionImpl* session) {
502 10264 : return session->findInjectedScript(m_executionContextId, m_injectedScript);
503 : }
504 :
505 106632 : InjectedScript::ObjectScope::ObjectScope(V8InspectorImpl* inspector,
506 : int contextGroupId,
507 : const String16& remoteObjectId)
508 : : InjectedScript::Scope(inspector, contextGroupId),
509 213264 : m_remoteObjectId(remoteObjectId) {}
510 :
511 213264 : InjectedScript::ObjectScope::~ObjectScope() {}
512 :
513 107298 : Response InjectedScript::ObjectScope::findInjectedScript(
514 : V8InspectorSessionImpl* session) {
515 107298 : std::unique_ptr<RemoteObjectId> remoteId;
516 107298 : Response response = RemoteObjectId::parse(m_remoteObjectId, &remoteId);
517 107298 : if (!response.isSuccess()) return response;
518 107298 : InjectedScript* injectedScript = nullptr;
519 214596 : response = session->findInjectedScript(remoteId.get(), injectedScript);
520 107298 : if (!response.isSuccess()) return response;
521 214596 : m_objectGroupName = injectedScript->objectGroupName(*remoteId);
522 321894 : response = injectedScript->findObject(*remoteId, &m_object);
523 107298 : if (!response.isSuccess()) return response;
524 107298 : m_injectedScript = injectedScript;
525 107298 : return Response::OK();
526 : }
527 :
528 14558 : InjectedScript::CallFrameScope::CallFrameScope(V8InspectorImpl* inspector,
529 : int contextGroupId,
530 : const String16& remoteObjectId)
531 : : InjectedScript::Scope(inspector, contextGroupId),
532 29116 : m_remoteCallFrameId(remoteObjectId) {}
533 :
534 29116 : InjectedScript::CallFrameScope::~CallFrameScope() {}
535 :
536 28792 : Response InjectedScript::CallFrameScope::findInjectedScript(
537 : V8InspectorSessionImpl* session) {
538 28792 : std::unique_ptr<RemoteCallFrameId> remoteId;
539 28792 : Response response = RemoteCallFrameId::parse(m_remoteCallFrameId, &remoteId);
540 28792 : if (!response.isSuccess()) return response;
541 28792 : m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal());
542 28792 : return session->findInjectedScript(remoteId.get(), m_injectedScript);
543 : }
544 :
545 : } // namespace v8_inspector
|