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 12 matching lines...) Expand all Loading... |
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "core/inspector/InjectedScriptManager.h" | 31 #include "core/inspector/InjectedScriptManager.h" |
32 | 32 |
33 #include "bindings/core/v8/V8Binding.h" | |
34 #include "core/inspector/InjectedScript.h" | 33 #include "core/inspector/InjectedScript.h" |
35 #include "core/inspector/InjectedScriptHost.h" | 34 #include "core/inspector/InjectedScriptHost.h" |
36 #include "core/inspector/InjectedScriptNative.h" | 35 #include "core/inspector/InjectedScriptNative.h" |
37 #include "core/inspector/RemoteObjectId.h" | 36 #include "core/inspector/RemoteObjectId.h" |
38 #include "core/inspector/v8/V8Debugger.h" | 37 #include "core/inspector/v8/V8Debugger.h" |
39 #include "core/inspector/v8/V8DebuggerClient.h" | 38 #include "core/inspector/v8/V8DebuggerClient.h" |
40 #include "core/inspector/v8/V8InjectedScriptHost.h" | |
41 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
42 #include "public/platform/WebData.h" | 40 #include "public/platform/WebData.h" |
43 #include "wtf/PassOwnPtr.h" | 41 #include "wtf/PassOwnPtr.h" |
44 | 42 |
45 namespace blink { | 43 namespace blink { |
46 | 44 |
47 PassOwnPtr<InjectedScriptManager> InjectedScriptManager::create(V8DebuggerClient
* client) | 45 PassOwnPtr<InjectedScriptManager> InjectedScriptManager::create(V8DebuggerClient
* client) |
48 { | 46 { |
49 return adoptPtr(new InjectedScriptManager(client)); | 47 return adoptPtr(new InjectedScriptManager(client)); |
50 } | 48 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 112 |
115 void InjectedScriptManager::setCustomObjectFormatterEnabled(bool enabled) | 113 void InjectedScriptManager::setCustomObjectFormatterEnabled(bool enabled) |
116 { | 114 { |
117 m_customObjectFormatterEnabled = enabled; | 115 m_customObjectFormatterEnabled = enabled; |
118 IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end(); | 116 IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end(); |
119 for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it !
= end; ++it) { | 117 for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it !
= end; ++it) { |
120 it->value->setCustomObjectFormatterEnabled(enabled); | 118 it->value->setCustomObjectFormatterEnabled(enabled); |
121 } | 119 } |
122 } | 120 } |
123 | 121 |
| 122 String InjectedScriptManager::injectedScriptSource() |
| 123 { |
| 124 const WebData& injectedScriptSourceResource = Platform::current()->loadResou
rce("InjectedScriptSource.js"); |
| 125 return String(injectedScriptSourceResource.data(), injectedScriptSourceResou
rce.size()); |
| 126 } |
| 127 |
124 InjectedScript* InjectedScriptManager::injectedScriptFor(v8::Local<v8::Context>
context) | 128 InjectedScript* InjectedScriptManager::injectedScriptFor(v8::Local<v8::Context>
context) |
125 { | 129 { |
126 v8::Context::Scope scope(context); | 130 v8::Context::Scope scope(context); |
127 int contextId = V8Debugger::contextId(context); | 131 int contextId = V8Debugger::contextId(context); |
128 | 132 |
129 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); | 133 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); |
130 if (it != m_idToInjectedScript.end()) | 134 if (it != m_idToInjectedScript.end()) |
131 return it->value.get(); | 135 return it->value.get(); |
132 | 136 |
133 v8::Local<v8::Context> callingContext = context->GetIsolate()->GetCallingCon
text(); | 137 v8::Local<v8::Context> callingContext = context->GetIsolate()->GetCallingCon
text(); |
134 if (!callingContext.IsEmpty() && !m_client->callingContextCanAccessContext(c
allingContext, context)) | 138 if (!callingContext.IsEmpty() && !m_client->callingContextCanAccessContext(c
allingContext, context)) |
135 return nullptr; | 139 return nullptr; |
136 | 140 |
137 RefPtr<InjectedScriptNative> injectedScriptNative = adoptRef(new InjectedScr
iptNative(context->GetIsolate())); | 141 RefPtr<InjectedScriptNative> injectedScriptNative = adoptRef(new InjectedScr
iptNative(context->GetIsolate())); |
138 | 142 v8::Local<v8::Object> object = createInjectedScript(injectedScriptSource(),
context, contextId, injectedScriptNative.get()); |
139 const WebData& injectedScriptSourceResource = Platform::current()->loadResou
rce("InjectedScriptSource.js"); | |
140 String injectedScriptSource(injectedScriptSourceResource.data(), injectedScr
iptSourceResource.size()); | |
141 | |
142 v8::Local<v8::Object> object = createInjectedScript(injectedScriptSource, co
ntext, contextId, injectedScriptNative.get()); | |
143 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(this, context, o
bject, m_client, injectedScriptNative.release(), contextId)); | 143 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(this, context, o
bject, m_client, injectedScriptNative.release(), contextId)); |
144 InjectedScript* resultPtr = result.get(); | 144 InjectedScript* resultPtr = result.get(); |
145 if (m_customObjectFormatterEnabled) | 145 if (m_customObjectFormatterEnabled) |
146 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); | 146 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); |
147 m_idToInjectedScript.set(contextId, result.release()); | 147 m_idToInjectedScript.set(contextId, result.release()); |
148 return resultPtr; | 148 return resultPtr; |
149 } | 149 } |
150 | 150 |
151 v8::Local<v8::Object> InjectedScriptManager::createInjectedScript(const String&
scriptSource, v8::Local<v8::Context> context, int id, InjectedScriptNative* inje
ctedScriptNative) | |
152 { | |
153 v8::Isolate* isolate = context->GetIsolate(); | |
154 v8::Context::Scope scope(context); | |
155 | |
156 v8::Local<v8::FunctionTemplate> wrapperTemplate = m_injectedScriptHost->wrap
perTemplate(isolate); | |
157 if (wrapperTemplate.IsEmpty()) { | |
158 wrapperTemplate = V8InjectedScriptHost::createWrapperTemplate(isolate); | |
159 m_injectedScriptHost->setWrapperTemplate(wrapperTemplate, isolate); | |
160 } | |
161 | |
162 v8::Local<v8::Object> scriptHostWrapper = V8InjectedScriptHost::wrap(wrapper
Template, context, m_injectedScriptHost); | |
163 if (scriptHostWrapper.IsEmpty()) | |
164 return v8::Local<v8::Object>(); | |
165 | |
166 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper); | |
167 | |
168 // Inject javascript into the context. The compiled script is supposed to ev
aluate into | |
169 // a single anonymous function(it's anonymous to avoid cluttering the global
object with | |
170 // inspector's stuff) the function is called a few lines below with Injected
ScriptHost wrapper, | |
171 // injected script id and explicit reference to the inspected global object.
The function is expected | |
172 // to create and configure InjectedScript instance that is going to be used
by the inspector. | |
173 v8::Local<v8::Value> value; | |
174 if (!m_client->compileAndRunInternalScript(scriptSource).ToLocal(&value)) | |
175 return v8::Local<v8::Object>(); | |
176 ASSERT(value->IsFunction()); | |
177 | |
178 v8::Local<v8::Object> windowGlobal = context->Global(); | |
179 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number:
:New(context->GetIsolate(), id) }; | |
180 v8::Local<v8::Value> injectedScriptValue; | |
181 if (!m_client->callInternalFunction(v8::Local<v8::Function>::Cast(value), wi
ndowGlobal, WTF_ARRAY_LENGTH(info), info).ToLocal(&injectedScriptValue)) | |
182 return v8::Local<v8::Object>(); | |
183 if (!injectedScriptValue->IsObject()) | |
184 return v8::Local<v8::Object>(); | |
185 return injectedScriptValue.As<v8::Object>(); | |
186 } | |
187 | |
188 } // namespace blink | 151 } // namespace blink |
OLD | NEW |