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_debugger(debugger) | 54 , m_client(debugger->client()) |
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 InjectedScript* InjectedScriptManager::injectedScriptFor(v8::Local<v8::Context>
context) | 118 InjectedScript* InjectedScriptManager::injectedScriptFor(v8::Local<v8::Context>
context) |
119 { | 119 { |
120 v8::Context::Scope scope(context); | 120 v8::Context::Scope scope(context); |
121 int contextId = V8Debugger::contextId(context); | 121 int contextId = V8Debugger::contextId(context); |
122 | 122 |
123 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); | 123 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); |
124 if (it != m_idToInjectedScript.end()) | 124 if (it != m_idToInjectedScript.end()) |
125 return it->second; | 125 return it->second; |
126 | 126 |
127 v8::Local<v8::Context> callingContext = context->GetIsolate()->GetCallingCon
text(); | 127 v8::Local<v8::Context> callingContext = context->GetIsolate()->GetCallingCon
text(); |
128 if (!callingContext.IsEmpty() && !m_debugger->client()->callingContextCanAcc
essContext(callingContext, context)) | 128 if (!callingContext.IsEmpty() && !m_client->callingContextCanAccessContext(c
allingContext, context)) |
129 return nullptr; | 129 return nullptr; |
130 | 130 |
131 OwnPtr<InjectedScriptNative> injectedScriptNative = adoptPtr(new InjectedScr
iptNative(context->GetIsolate())); | 131 OwnPtr<InjectedScriptNative> injectedScriptNative = adoptPtr(new InjectedScr
iptNative(context->GetIsolate())); |
132 String16 injectedScriptSource(reinterpret_cast<const char*>(InjectedScriptSo
urce_js), sizeof(InjectedScriptSource_js)); | 132 String16 injectedScriptSource(reinterpret_cast<const char*>(InjectedScriptSo
urce_js), sizeof(InjectedScriptSource_js)); |
133 | 133 |
134 v8::Local<v8::Object> object = createInjectedScript(injectedScriptSource, co
ntext, contextId, injectedScriptNative.get()); | 134 v8::Local<v8::Object> object = createInjectedScript(injectedScriptSource, co
ntext, contextId, injectedScriptNative.get()); |
135 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(this, context, o
bject, injectedScriptNative.release(), contextId)); | 135 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(this, context, o
bject, m_client, injectedScriptNative.release(), contextId)); |
136 InjectedScript* resultPtr = result.get(); | 136 InjectedScript* resultPtr = result.get(); |
137 if (m_customObjectFormatterEnabled) | 137 if (m_customObjectFormatterEnabled) |
138 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); | 138 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); |
139 m_idToInjectedScript.set(contextId, result.release()); | 139 m_idToInjectedScript.set(contextId, result.release()); |
140 | 140 |
141 return resultPtr; | 141 return resultPtr; |
142 } | 142 } |
143 | 143 |
144 v8::Local<v8::Object> InjectedScriptManager::createInjectedScript(const String16
& source, v8::Local<v8::Context> context, int id, InjectedScriptNative* injected
ScriptNative) | 144 v8::Local<v8::Object> InjectedScriptManager::createInjectedScript(const String16
& source, v8::Local<v8::Context> context, int id, InjectedScriptNative* injected
ScriptNative) |
145 { | 145 { |
146 v8::Isolate* isolate = context->GetIsolate(); | 146 v8::Isolate* isolate = context->GetIsolate(); |
147 v8::Context::Scope scope(context); | 147 v8::Context::Scope scope(context); |
148 | 148 |
149 v8::Local<v8::FunctionTemplate> wrapperTemplate = m_injectedScriptHost->wrap
perTemplate(isolate); | 149 v8::Local<v8::FunctionTemplate> wrapperTemplate = m_injectedScriptHost->wrap
perTemplate(isolate); |
150 if (wrapperTemplate.IsEmpty()) { | 150 if (wrapperTemplate.IsEmpty()) { |
151 wrapperTemplate = V8InjectedScriptHost::createWrapperTemplate(isolate); | 151 wrapperTemplate = V8InjectedScriptHost::createWrapperTemplate(isolate); |
152 m_injectedScriptHost->setWrapperTemplate(wrapperTemplate, isolate); | 152 m_injectedScriptHost->setWrapperTemplate(wrapperTemplate, isolate); |
153 } | 153 } |
154 | 154 |
155 v8::Local<v8::Object> scriptHostWrapper = V8InjectedScriptHost::wrap(wrapper
Template, context, m_injectedScriptHost.get()); | 155 v8::Local<v8::Object> scriptHostWrapper = V8InjectedScriptHost::wrap(m_clien
t, wrapperTemplate, context, m_injectedScriptHost.get()); |
156 if (scriptHostWrapper.IsEmpty()) | 156 if (scriptHostWrapper.IsEmpty()) |
157 return v8::Local<v8::Object>(); | 157 return v8::Local<v8::Object>(); |
158 | 158 |
159 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper); | 159 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper); |
160 | 160 |
161 // Inject javascript into the context. The compiled script is supposed to ev
aluate into | 161 // Inject javascript into the context. The compiled script is supposed to ev
aluate into |
162 // a single anonymous function(it's anonymous to avoid cluttering the global
object with | 162 // a single anonymous function(it's anonymous to avoid cluttering the global
object with |
163 // inspector's stuff) the function is called a few lines below with Injected
ScriptHost wrapper, | 163 // inspector's stuff) the function is called a few lines below with Injected
ScriptHost wrapper, |
164 // injected script id and explicit reference to the inspected global object.
The function is expected | 164 // injected script id and explicit reference to the inspected global object.
The function is expected |
165 // to create and configure InjectedScript instance that is going to be used
by the inspector. | 165 // to create and configure InjectedScript instance that is going to be used
by the inspector. |
166 v8::Local<v8::Value> value; | 166 v8::Local<v8::Value> value; |
167 if (!m_debugger->compileAndRunInternalScript(context, toV8String(isolate, so
urce)).ToLocal(&value)) | 167 if (!m_client->compileAndRunInternalScript(toV8String(isolate, source)).ToLo
cal(&value)) |
168 return v8::Local<v8::Object>(); | 168 return v8::Local<v8::Object>(); |
169 ASSERT(value->IsFunction()); | 169 ASSERT(value->IsFunction()); |
170 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); | 170 |
171 v8::Local<v8::Object> windowGlobal = context->Global(); | 171 v8::Local<v8::Object> windowGlobal = context->Global(); |
172 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number:
:New(context->GetIsolate(), id) }; | 172 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number:
:New(context->GetIsolate(), id) }; |
173 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM
icrotasks); | |
174 v8::Local<v8::Value> injectedScriptValue; | 173 v8::Local<v8::Value> injectedScriptValue; |
175 if (!function->Call(context, windowGlobal, WTF_ARRAY_LENGTH(info), info).ToL
ocal(&injectedScriptValue)) | 174 if (!m_client->callInternalFunction(v8::Local<v8::Function>::Cast(value), wi
ndowGlobal, WTF_ARRAY_LENGTH(info), info).ToLocal(&injectedScriptValue)) |
176 return v8::Local<v8::Object>(); | 175 return v8::Local<v8::Object>(); |
177 if (!injectedScriptValue->IsObject()) | 176 if (!injectedScriptValue->IsObject()) |
178 return v8::Local<v8::Object>(); | 177 return v8::Local<v8::Object>(); |
179 return injectedScriptValue.As<v8::Object>(); | 178 return injectedScriptValue.As<v8::Object>(); |
180 } | 179 } |
181 | 180 |
182 } // namespace blink | 181 } // namespace blink |
OLD | NEW |