OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
4 * Copyright (C) 2012 Google Inc. All rights reserved. | 4 * Copyright (C) 2012 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * | 9 * |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 namespace blink { | 44 namespace blink { |
45 | 45 |
46 PassOwnPtr<InjectedScriptManager> InjectedScriptManager::create(V8DebuggerImpl*
debugger) | 46 PassOwnPtr<InjectedScriptManager> InjectedScriptManager::create(V8DebuggerImpl*
debugger) |
47 { | 47 { |
48 return adoptPtr(new InjectedScriptManager(debugger)); | 48 return adoptPtr(new InjectedScriptManager(debugger)); |
49 } | 49 } |
50 | 50 |
51 InjectedScriptManager::InjectedScriptManager(V8DebuggerImpl* debugger) | 51 InjectedScriptManager::InjectedScriptManager(V8DebuggerImpl* debugger) |
52 : m_injectedScriptHost(InjectedScriptHost::create(debugger)) | 52 : m_injectedScriptHost(InjectedScriptHost::create(debugger)) |
53 , m_customObjectFormatterEnabled(false) | 53 , m_customObjectFormatterEnabled(false) |
54 , m_client(debugger->client()) | 54 , m_debugger(debugger) |
55 { | 55 { |
56 } | 56 } |
57 | 57 |
58 InjectedScriptManager::~InjectedScriptManager() | 58 InjectedScriptManager::~InjectedScriptManager() |
59 { | 59 { |
60 m_injectedScriptHost->disconnect(); | 60 m_injectedScriptHost->disconnect(); |
61 } | 61 } |
62 | 62 |
63 InjectedScriptHost* InjectedScriptManager::injectedScriptHost() | 63 InjectedScriptHost* InjectedScriptManager::injectedScriptHost() |
64 { | 64 { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 InjectedScript* InjectedScriptManager::injectedScriptFor(v8::Local<v8::Context>
context) | 124 InjectedScript* InjectedScriptManager::injectedScriptFor(v8::Local<v8::Context>
context) |
125 { | 125 { |
126 v8::Context::Scope scope(context); | 126 v8::Context::Scope scope(context); |
127 int contextId = V8Debugger::contextId(context); | 127 int contextId = V8Debugger::contextId(context); |
128 | 128 |
129 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); | 129 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); |
130 if (it != m_idToInjectedScript.end()) | 130 if (it != m_idToInjectedScript.end()) |
131 return it->second; | 131 return it->second; |
132 | 132 |
133 v8::Local<v8::Context> callingContext = context->GetIsolate()->GetCallingCon
text(); | 133 v8::Local<v8::Context> callingContext = context->GetIsolate()->GetCallingCon
text(); |
134 if (!callingContext.IsEmpty() && !m_client->callingContextCanAccessContext(c
allingContext, context)) | 134 if (!callingContext.IsEmpty() && !m_debugger->client()->callingContextCanAcc
essContext(callingContext, context)) |
135 return nullptr; | 135 return nullptr; |
136 | 136 |
137 OwnPtr<InjectedScriptNative> injectedScriptNative = adoptPtr(new InjectedScr
iptNative(context->GetIsolate())); | 137 OwnPtr<InjectedScriptNative> injectedScriptNative = adoptPtr(new InjectedScr
iptNative(context->GetIsolate())); |
138 String16 injectedScriptSource(reinterpret_cast<const char*>(InjectedScriptSo
urce_js), sizeof(InjectedScriptSource_js)); | 138 String16 injectedScriptSource(reinterpret_cast<const char*>(InjectedScriptSo
urce_js), sizeof(InjectedScriptSource_js)); |
139 | 139 |
140 v8::Local<v8::Object> object = createInjectedScript(injectedScriptSource, co
ntext, contextId, injectedScriptNative.get()); | 140 v8::Local<v8::Object> object = createInjectedScript(injectedScriptSource, co
ntext, contextId, injectedScriptNative.get()); |
141 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(this, context, o
bject, m_client, injectedScriptNative.release(), contextId)); | 141 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(this, context, o
bject, injectedScriptNative.release(), contextId)); |
142 InjectedScript* resultPtr = result.get(); | 142 InjectedScript* resultPtr = result.get(); |
143 if (m_customObjectFormatterEnabled) | 143 if (m_customObjectFormatterEnabled) |
144 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); | 144 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); |
145 m_idToInjectedScript.set(contextId, result.release()); | 145 m_idToInjectedScript.set(contextId, result.release()); |
146 | 146 |
147 return resultPtr; | 147 return resultPtr; |
148 } | 148 } |
149 | 149 |
150 v8::Local<v8::Object> InjectedScriptManager::createInjectedScript(const String16
& source, v8::Local<v8::Context> context, int id, InjectedScriptNative* injected
ScriptNative) | 150 v8::Local<v8::Object> InjectedScriptManager::createInjectedScript(const String16
& source, v8::Local<v8::Context> context, int id, InjectedScriptNative* injected
ScriptNative) |
151 { | 151 { |
152 v8::Isolate* isolate = context->GetIsolate(); | 152 v8::Isolate* isolate = context->GetIsolate(); |
153 v8::Context::Scope scope(context); | 153 v8::Context::Scope scope(context); |
154 | 154 |
155 v8::Local<v8::FunctionTemplate> wrapperTemplate = m_injectedScriptHost->wrap
perTemplate(isolate); | 155 v8::Local<v8::FunctionTemplate> wrapperTemplate = m_injectedScriptHost->wrap
perTemplate(isolate); |
156 if (wrapperTemplate.IsEmpty()) { | 156 if (wrapperTemplate.IsEmpty()) { |
157 wrapperTemplate = V8InjectedScriptHost::createWrapperTemplate(isolate); | 157 wrapperTemplate = V8InjectedScriptHost::createWrapperTemplate(isolate); |
158 m_injectedScriptHost->setWrapperTemplate(wrapperTemplate, isolate); | 158 m_injectedScriptHost->setWrapperTemplate(wrapperTemplate, isolate); |
159 } | 159 } |
160 | 160 |
161 v8::Local<v8::Object> scriptHostWrapper = V8InjectedScriptHost::wrap(m_clien
t, wrapperTemplate, context, m_injectedScriptHost.get()); | 161 v8::Local<v8::Object> scriptHostWrapper = V8InjectedScriptHost::wrap(wrapper
Template, context, m_injectedScriptHost.get()); |
162 if (scriptHostWrapper.IsEmpty()) | 162 if (scriptHostWrapper.IsEmpty()) |
163 return v8::Local<v8::Object>(); | 163 return v8::Local<v8::Object>(); |
164 | 164 |
165 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper); | 165 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper); |
166 | 166 |
167 // Inject javascript into the context. The compiled script is supposed to ev
aluate into | 167 // Inject javascript into the context. The compiled script is supposed to ev
aluate into |
168 // a single anonymous function(it's anonymous to avoid cluttering the global
object with | 168 // a single anonymous function(it's anonymous to avoid cluttering the global
object with |
169 // inspector's stuff) the function is called a few lines below with Injected
ScriptHost wrapper, | 169 // inspector's stuff) the function is called a few lines below with Injected
ScriptHost wrapper, |
170 // injected script id and explicit reference to the inspected global object.
The function is expected | 170 // injected script id and explicit reference to the inspected global object.
The function is expected |
171 // to create and configure InjectedScript instance that is going to be used
by the inspector. | 171 // to create and configure InjectedScript instance that is going to be used
by the inspector. |
172 v8::Local<v8::Value> value; | 172 v8::Local<v8::Value> value; |
173 if (!m_client->compileAndRunInternalScript(toV8String(isolate, source)).ToLo
cal(&value)) | 173 if (!m_debugger->compileAndRunInternalScript(context, toV8String(isolate, so
urce)).ToLocal(&value)) |
174 return v8::Local<v8::Object>(); | 174 return v8::Local<v8::Object>(); |
175 ASSERT(value->IsFunction()); | 175 ASSERT(value->IsFunction()); |
176 | 176 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); |
177 v8::Local<v8::Object> windowGlobal = context->Global(); | 177 v8::Local<v8::Object> windowGlobal = context->Global(); |
178 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number:
:New(context->GetIsolate(), id) }; | 178 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number:
:New(context->GetIsolate(), id) }; |
| 179 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM
icrotasks); |
179 v8::Local<v8::Value> injectedScriptValue; | 180 v8::Local<v8::Value> injectedScriptValue; |
180 if (!m_client->callInternalFunction(v8::Local<v8::Function>::Cast(value), wi
ndowGlobal, WTF_ARRAY_LENGTH(info), info).ToLocal(&injectedScriptValue)) | 181 if (!function->Call(context, windowGlobal, WTF_ARRAY_LENGTH(info), info).ToL
ocal(&injectedScriptValue)) |
181 return v8::Local<v8::Object>(); | 182 return v8::Local<v8::Object>(); |
182 if (!injectedScriptValue->IsObject()) | 183 if (!injectedScriptValue->IsObject()) |
183 return v8::Local<v8::Object>(); | 184 return v8::Local<v8::Object>(); |
184 return injectedScriptValue.As<v8::Object>(); | 185 return injectedScriptValue.As<v8::Object>(); |
185 } | 186 } |
186 | 187 |
187 } // namespace blink | 188 } // namespace blink |
OLD | NEW |