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

Side by Side Diff: src/inspector/injected-script.cc

Issue 2916803005: [inspector] Create InjectedScript per session in each context (Closed)
Patch Set: rebased Created 3 years, 6 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
« no previous file with comments | « src/inspector/injected-script.h ('k') | src/inspector/inspected-context.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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 static const char privateKeyName[] = "v8-inspector#injectedScript"; 51 static const char privateKeyName[] = "v8-inspector#injectedScript";
52 } 52 }
53 53
54 using protocol::Array; 54 using protocol::Array;
55 using protocol::Runtime::PropertyDescriptor; 55 using protocol::Runtime::PropertyDescriptor;
56 using protocol::Runtime::InternalPropertyDescriptor; 56 using protocol::Runtime::InternalPropertyDescriptor;
57 using protocol::Runtime::RemoteObject; 57 using protocol::Runtime::RemoteObject;
58 using protocol::Maybe; 58 using protocol::Maybe;
59 59
60 std::unique_ptr<InjectedScript> InjectedScript::create( 60 std::unique_ptr<InjectedScript> InjectedScript::create(
61 InspectedContext* inspectedContext) { 61 InspectedContext* inspectedContext, int sessionId) {
62 v8::Isolate* isolate = inspectedContext->isolate(); 62 v8::Isolate* isolate = inspectedContext->isolate();
63 v8::HandleScope handles(isolate); 63 v8::HandleScope handles(isolate);
64 v8::Local<v8::Context> context = inspectedContext->context(); 64 v8::Local<v8::Context> context = inspectedContext->context();
65 v8::Context::Scope scope(context); 65 v8::Context::Scope scope(context);
66 66
67 // Inject javascript into the context. The compiled script is supposed to 67 // Inject javascript into the context. The compiled script is supposed to
68 // evaluate into 68 // evaluate into
69 // a single anonymous function(it's anonymous to avoid cluttering the global 69 // a single anonymous function(it's anonymous to avoid cluttering the global
70 // object with 70 // object with
71 // inspector's stuff) the function is called a few lines below with 71 // inspector's stuff) the function is called a few lines below with
(...skipping 27 matching lines...) Expand all
99 V8InspectorImpl* inspector = inspectedContext->inspector(); 99 V8InspectorImpl* inspector = inspectedContext->inspector();
100 v8::Local<v8::Value> injectedScriptValue; 100 v8::Local<v8::Value> injectedScriptValue;
101 if (!function->Call(context, windowGlobal, arraysize(info), info) 101 if (!function->Call(context, windowGlobal, arraysize(info), info)
102 .ToLocal(&injectedScriptValue)) 102 .ToLocal(&injectedScriptValue))
103 return nullptr; 103 return nullptr;
104 if (inspector->getContext(contextGroupId, contextId) != inspectedContext) 104 if (inspector->getContext(contextGroupId, contextId) != inspectedContext)
105 return nullptr; 105 return nullptr;
106 if (!injectedScriptValue->IsObject()) return nullptr; 106 if (!injectedScriptValue->IsObject()) return nullptr;
107 107
108 std::unique_ptr<InjectedScript> injectedScript(new InjectedScript( 108 std::unique_ptr<InjectedScript> injectedScript(new InjectedScript(
109 inspectedContext, injectedScriptValue.As<v8::Object>())); 109 inspectedContext, injectedScriptValue.As<v8::Object>(), sessionId));
110 v8::Local<v8::Private> privateKey = v8::Private::ForApi( 110 v8::Local<v8::Private> privateKey = v8::Private::ForApi(
111 isolate, v8::String::NewFromUtf8(isolate, privateKeyName, 111 isolate, v8::String::NewFromUtf8(isolate, privateKeyName,
112 v8::NewStringType::kInternalized) 112 v8::NewStringType::kInternalized)
113 .ToLocalChecked()); 113 .ToLocalChecked());
114 scriptHostWrapper->SetPrivate( 114 scriptHostWrapper->SetPrivate(
115 context, privateKey, v8::External::New(isolate, injectedScript.get())); 115 context, privateKey, v8::External::New(isolate, injectedScript.get()));
116 return injectedScript; 116 return injectedScript;
117 } 117 }
118 118
119 InjectedScript::InjectedScript(InspectedContext* context, 119 InjectedScript::InjectedScript(InspectedContext* context,
120 v8::Local<v8::Object> object) 120 v8::Local<v8::Object> object, int sessionId)
121 : m_context(context), m_value(context->isolate(), object) {} 121 : m_context(context),
122 m_value(context->isolate(), object),
123 m_sessionId(sessionId) {}
122 124
123 InjectedScript::~InjectedScript() {} 125 InjectedScript::~InjectedScript() {}
124 126
125 Response InjectedScript::getProperties( 127 Response InjectedScript::getProperties(
126 v8::Local<v8::Object> object, const String16& groupName, bool ownProperties, 128 v8::Local<v8::Object> object, const String16& groupName, bool ownProperties,
127 bool accessorPropertiesOnly, bool generatePreview, 129 bool accessorPropertiesOnly, bool generatePreview,
128 std::unique_ptr<Array<PropertyDescriptor>>* properties, 130 std::unique_ptr<Array<PropertyDescriptor>>* properties,
129 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { 131 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) {
130 v8::HandleScope handles(m_context->isolate()); 132 v8::HandleScope handles(m_context->isolate());
131 v8::Local<v8::Context> context = m_context->context(); 133 v8::Local<v8::Context> context = m_context->context();
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 if (!response.isSuccess()) return response; 415 if (!response.isSuccess()) return response;
414 } 416 }
415 return Response::OK(); 417 return Response::OK();
416 } 418 }
417 419
418 v8::Local<v8::Object> InjectedScript::commandLineAPI() { 420 v8::Local<v8::Object> InjectedScript::commandLineAPI() {
419 if (m_commandLineAPI.IsEmpty()) { 421 if (m_commandLineAPI.IsEmpty()) {
420 m_commandLineAPI.Reset( 422 m_commandLineAPI.Reset(
421 m_context->isolate(), 423 m_context->isolate(),
422 m_context->inspector()->console()->createCommandLineAPI( 424 m_context->inspector()->console()->createCommandLineAPI(
423 m_context->context())); 425 m_context->context(), m_sessionId));
424 } 426 }
425 return m_commandLineAPI.Get(m_context->isolate()); 427 return m_commandLineAPI.Get(m_context->isolate());
426 } 428 }
427 429
428 InjectedScript::Scope::Scope(V8InspectorSessionImpl* session) 430 InjectedScript::Scope::Scope(V8InspectorSessionImpl* session)
429 : m_inspector(session->inspector()), 431 : m_inspector(session->inspector()),
430 m_injectedScript(nullptr), 432 m_injectedScript(nullptr),
431 m_handleScope(m_inspector->isolate()), 433 m_handleScope(m_inspector->isolate()),
432 m_tryCatch(m_inspector->isolate()), 434 m_tryCatch(m_inspector->isolate()),
433 m_ignoreExceptionsAndMuteConsole(false), 435 m_ignoreExceptionsAndMuteConsole(false),
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 } 575 }
574 return id; 576 return id;
575 } 577 }
576 578
577 void InjectedScript::unbindObject(int id) { 579 void InjectedScript::unbindObject(int id) {
578 m_idToWrappedObject.erase(id); 580 m_idToWrappedObject.erase(id);
579 m_idToObjectGroupName.erase(id); 581 m_idToObjectGroupName.erase(id);
580 } 582 }
581 583
582 } // namespace v8_inspector 584 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/injected-script.h ('k') | src/inspector/inspected-context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698