|
Lines 1-5
a/Source/WebCore/inspector/InjectedScript.cpp_sec1
|
| 1 |
/* |
1 |
/* |
| 2 |
* Copyright (C) 2010, 2011 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 |
|
Lines 34-48
a/Source/WebCore/inspector/InjectedScript.cpp_sec2
|
| 34 |
|
34 |
|
| 35 |
#include "InjectedScript.h" |
35 |
#include "InjectedScript.h" |
| 36 |
|
36 |
|
| 37 |
#include "DOMWindow.h" |
|
|
| 38 |
#include "Frame.h" |
| 39 |
#include "InjectedScriptHost.h" |
37 |
#include "InjectedScriptHost.h" |
| 40 |
#include "InjectedScriptManager.h" |
|
|
| 41 |
#include "InspectorInstrumentation.h" |
| 42 |
#include "InspectorValues.h" |
38 |
#include "InspectorValues.h" |
| 43 |
#include "Node.h" |
39 |
#include "Node.h" |
| 44 |
#include "PlatformString.h" |
40 |
#include "PlatformString.h" |
| 45 |
#include "ScriptFunctionCall.h" |
41 |
#include "ScriptFunctionCall.h" |
|
|
42 |
#include "SerializedScriptValue.h" |
| 46 |
|
43 |
|
| 47 |
using WebCore::TypeBuilder::Array; |
44 |
using WebCore::TypeBuilder::Array; |
| 48 |
using WebCore::TypeBuilder::Debugger::CallFrame; |
45 |
using WebCore::TypeBuilder::Debugger::CallFrame; |
|
Lines 53-71
using WebCore::TypeBuilder::Runtime::RemoteObject;
a/Source/WebCore/inspector/InjectedScript.cpp_sec3
|
| 53 |
namespace WebCore { |
50 |
namespace WebCore { |
| 54 |
|
51 |
|
| 55 |
InjectedScript::InjectedScript() |
52 |
InjectedScript::InjectedScript() |
| 56 |
: m_inspectedStateAccessCheck(0) |
|
|
| 57 |
{ |
53 |
{ |
| 58 |
} |
54 |
} |
| 59 |
|
55 |
|
| 60 |
InjectedScript::InjectedScript(ScriptObject injectedScriptObject, InspectedStateAccessCheck accessCheck) |
56 |
InjectedScript::InjectedScript(ScriptObject injectedScriptObject, InspectedStateAccessCheck accessCheck) |
| 61 |
: m_injectedScriptObject(injectedScriptObject) |
57 |
: InjectedScriptBase(injectedScriptObject, accessCheck) |
| 62 |
, m_inspectedStateAccessCheck(accessCheck) |
|
|
| 63 |
{ |
58 |
{ |
| 64 |
} |
59 |
} |
| 65 |
|
60 |
|
| 66 |
void InjectedScript::evaluate(ErrorString* errorString, const String& expression, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown) |
61 |
void InjectedScript::evaluate(ErrorString* errorString, const String& expression, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown) |
| 67 |
{ |
62 |
{ |
| 68 |
ScriptFunctionCall function(m_injectedScriptObject, "evaluate"); |
63 |
ScriptFunctionCall function(injectedScriptObject(), "evaluate"); |
| 69 |
function.appendArgument(expression); |
64 |
function.appendArgument(expression); |
| 70 |
function.appendArgument(objectGroup); |
65 |
function.appendArgument(objectGroup); |
| 71 |
function.appendArgument(includeCommandLineAPI); |
66 |
function.appendArgument(includeCommandLineAPI); |
|
Lines 75-81
void InjectedScript::evaluate(ErrorString* errorString, const String& expression
a/Source/WebCore/inspector/InjectedScript.cpp_sec4
|
| 75 |
|
70 |
|
| 76 |
void InjectedScript::callFunctionOn(ErrorString* errorString, const String& objectId, const String& expression, const String& arguments, bool returnByValue, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown) |
71 |
void InjectedScript::callFunctionOn(ErrorString* errorString, const String& objectId, const String& expression, const String& arguments, bool returnByValue, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown) |
| 77 |
{ |
72 |
{ |
| 78 |
ScriptFunctionCall function(m_injectedScriptObject, "callFunctionOn"); |
73 |
ScriptFunctionCall function(injectedScriptObject(), "callFunctionOn"); |
| 79 |
function.appendArgument(objectId); |
74 |
function.appendArgument(objectId); |
| 80 |
function.appendArgument(expression); |
75 |
function.appendArgument(expression); |
| 81 |
function.appendArgument(arguments); |
76 |
function.appendArgument(arguments); |
|
Lines 85-91
void InjectedScript::callFunctionOn(ErrorString* errorString, const String& obje
a/Source/WebCore/inspector/InjectedScript.cpp_sec5
|
| 85 |
|
80 |
|
| 86 |
void InjectedScript::evaluateOnCallFrame(ErrorString* errorString, const ScriptValue& callFrames, const String& callFrameId, const String& expression, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, RefPtr<RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown) |
81 |
void InjectedScript::evaluateOnCallFrame(ErrorString* errorString, const ScriptValue& callFrames, const String& callFrameId, const String& expression, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, RefPtr<RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown) |
| 87 |
{ |
82 |
{ |
| 88 |
ScriptFunctionCall function(m_injectedScriptObject, "evaluateOnCallFrame"); |
83 |
ScriptFunctionCall function(injectedScriptObject(), "evaluateOnCallFrame"); |
| 89 |
function.appendArgument(callFrames); |
84 |
function.appendArgument(callFrames); |
| 90 |
function.appendArgument(callFrameId); |
85 |
function.appendArgument(callFrameId); |
| 91 |
function.appendArgument(expression); |
86 |
function.appendArgument(expression); |
|
Lines 117-123
void InjectedScript::restartFrame(ErrorString* errorString, const ScriptValue& c
a/Source/WebCore/inspector/InjectedScript.cpp_sec6
|
| 117 |
|
112 |
|
| 118 |
void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, RefPtr<FunctionDetails>* result) |
113 |
void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, RefPtr<FunctionDetails>* result) |
| 119 |
{ |
114 |
{ |
| 120 |
ScriptFunctionCall function(m_injectedScriptObject, "getFunctionDetails"); |
115 |
ScriptFunctionCall function(injectedScriptObject(), "getFunctionDetails"); |
| 121 |
function.appendArgument(functionId); |
116 |
function.appendArgument(functionId); |
| 122 |
RefPtr<InspectorValue> resultValue; |
117 |
RefPtr<InspectorValue> resultValue; |
| 123 |
makeCall(function, &resultValue); |
118 |
makeCall(function, &resultValue); |
|
Lines 131-137
void InjectedScript::getFunctionDetails(ErrorString* errorString, const String&
a/Source/WebCore/inspector/InjectedScript.cpp_sec7
|
| 131 |
|
126 |
|
| 132 |
void InjectedScript::getProperties(ErrorString* errorString, const String& objectId, bool ownProperties, RefPtr<Array<PropertyDescriptor> >* properties) |
127 |
void InjectedScript::getProperties(ErrorString* errorString, const String& objectId, bool ownProperties, RefPtr<Array<PropertyDescriptor> >* properties) |
| 133 |
{ |
128 |
{ |
| 134 |
ScriptFunctionCall function(m_injectedScriptObject, "getProperties"); |
129 |
ScriptFunctionCall function(injectedScriptObject(), "getProperties"); |
| 135 |
function.appendArgument(objectId); |
130 |
function.appendArgument(objectId); |
| 136 |
function.appendArgument(ownProperties); |
131 |
function.appendArgument(ownProperties); |
| 137 |
|
132 |
|
|
Lines 149-155
Node* InjectedScript::nodeForObjectId(const String& objectId)
a/Source/WebCore/inspector/InjectedScript.cpp_sec8
|
| 149 |
if (hasNoValue() || !canAccessInspectedWindow()) |
144 |
if (hasNoValue() || !canAccessInspectedWindow()) |
| 150 |
return 0; |
145 |
return 0; |
| 151 |
|
146 |
|
| 152 |
ScriptFunctionCall function(m_injectedScriptObject, "nodeForObjectId"); |
147 |
ScriptFunctionCall function(injectedScriptObject(), "nodeForObjectId"); |
| 153 |
function.appendArgument(objectId); |
148 |
function.appendArgument(objectId); |
| 154 |
|
149 |
|
| 155 |
bool hadException = false; |
150 |
bool hadException = false; |
|
Lines 161-167
Node* InjectedScript::nodeForObjectId(const String& objectId)
a/Source/WebCore/inspector/InjectedScript.cpp_sec9
|
| 161 |
|
156 |
|
| 162 |
void InjectedScript::releaseObject(const String& objectId) |
157 |
void InjectedScript::releaseObject(const String& objectId) |
| 163 |
{ |
158 |
{ |
| 164 |
ScriptFunctionCall function(m_injectedScriptObject, "releaseObject"); |
159 |
ScriptFunctionCall function(injectedScriptObject(), "releaseObject"); |
| 165 |
function.appendArgument(objectId); |
160 |
function.appendArgument(objectId); |
| 166 |
RefPtr<InspectorValue> result; |
161 |
RefPtr<InspectorValue> result; |
| 167 |
makeCall(function, &result); |
162 |
makeCall(function, &result); |
|
Lines 171-182
void InjectedScript::releaseObject(const String& objectId)
a/Source/WebCore/inspector/InjectedScript.cpp_sec10
|
| 171 |
PassRefPtr<Array<CallFrame> > InjectedScript::wrapCallFrames(const ScriptValue& callFrames) |
166 |
PassRefPtr<Array<CallFrame> > InjectedScript::wrapCallFrames(const ScriptValue& callFrames) |
| 172 |
{ |
167 |
{ |
| 173 |
ASSERT(!hasNoValue()); |
168 |
ASSERT(!hasNoValue()); |
| 174 |
ScriptFunctionCall function(m_injectedScriptObject, "wrapCallFrames"); |
169 |
ScriptFunctionCall function(injectedScriptObject(), "wrapCallFrames"); |
| 175 |
function.appendArgument(callFrames); |
170 |
function.appendArgument(callFrames); |
| 176 |
bool hadException = false; |
171 |
bool hadException = false; |
| 177 |
ScriptValue callFramesValue = callFunctionWithEvalEnabled(function, hadException); |
172 |
ScriptValue callFramesValue = callFunctionWithEvalEnabled(function, hadException); |
| 178 |
ASSERT(!hadException); |
173 |
ASSERT(!hadException); |
| 179 |
RefPtr<InspectorValue> result = callFramesValue.toInspectorValue(m_injectedScriptObject.scriptState()); |
174 |
RefPtr<InspectorValue> result = callFramesValue.toInspectorValue(scriptState()); |
| 180 |
if (result->type() == InspectorValue::TypeArray) |
175 |
if (result->type() == InspectorValue::TypeArray) |
| 181 |
return Array<CallFrame>::runtimeCast(result); |
176 |
return Array<CallFrame>::runtimeCast(result); |
| 182 |
return Array<CallFrame>::create(); |
177 |
return Array<CallFrame>::create(); |
|
Lines 186-192
PassRefPtr<Array<CallFrame> > InjectedScript::wrapCallFrames(const ScriptValue&
a/Source/WebCore/inspector/InjectedScript.cpp_sec11
|
| 186 |
PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObject(ScriptValue value, const String& groupName) const |
181 |
PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObject(ScriptValue value, const String& groupName) const |
| 187 |
{ |
182 |
{ |
| 188 |
ASSERT(!hasNoValue()); |
183 |
ASSERT(!hasNoValue()); |
| 189 |
ScriptFunctionCall wrapFunction(m_injectedScriptObject, "wrapObject"); |
184 |
ScriptFunctionCall wrapFunction(injectedScriptObject(), "wrapObject"); |
| 190 |
wrapFunction.appendArgument(value); |
185 |
wrapFunction.appendArgument(value); |
| 191 |
wrapFunction.appendArgument(groupName); |
186 |
wrapFunction.appendArgument(groupName); |
| 192 |
wrapFunction.appendArgument(canAccessInspectedWindow()); |
187 |
wrapFunction.appendArgument(canAccessInspectedWindow()); |
|
Lines 195-201
PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObject(Script
a/Source/WebCore/inspector/InjectedScript.cpp_sec12
|
| 195 |
if (hadException) { |
190 |
if (hadException) { |
| 196 |
return 0; |
191 |
return 0; |
| 197 |
} |
192 |
} |
| 198 |
RefPtr<InspectorObject> rawResult = r.toInspectorValue(m_injectedScriptObject.scriptState())->asObject(); |
193 |
RefPtr<InspectorObject> rawResult = r.toInspectorValue(scriptState())->asObject(); |
| 199 |
return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); |
194 |
return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); |
| 200 |
} |
195 |
} |
| 201 |
|
196 |
|
|
Lines 206-219
PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapNode(Node* no
a/Source/WebCore/inspector/InjectedScript.cpp_sec13
|
| 206 |
|
201 |
|
| 207 |
PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapSerializedObject(SerializedScriptValue* serializedScriptValue, const String& groupName) const |
202 |
PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapSerializedObject(SerializedScriptValue* serializedScriptValue, const String& groupName) const |
| 208 |
{ |
203 |
{ |
| 209 |
ScriptValue scriptValue = serializedScriptValue->deserializeForInspector(m_injectedScriptObject.scriptState()); |
204 |
ScriptValue scriptValue = serializedScriptValue->deserializeForInspector(scriptState()); |
| 210 |
return scriptValue.hasNoValue() ? 0 : wrapObject(scriptValue, groupName); |
205 |
return scriptValue.hasNoValue() ? 0 : wrapObject(scriptValue, groupName); |
| 211 |
} |
206 |
} |
| 212 |
|
207 |
|
| 213 |
ScriptValue InjectedScript::findObjectById(const String& objectId) const |
208 |
ScriptValue InjectedScript::findObjectById(const String& objectId) const |
| 214 |
{ |
209 |
{ |
| 215 |
ASSERT(!hasNoValue()); |
210 |
ASSERT(!hasNoValue()); |
| 216 |
ScriptFunctionCall function(m_injectedScriptObject, "findObjectById"); |
211 |
ScriptFunctionCall function(injectedScriptObject(), "findObjectById"); |
| 217 |
function.appendArgument(objectId); |
212 |
function.appendArgument(objectId); |
| 218 |
|
213 |
|
| 219 |
bool hadException = false; |
214 |
bool hadException = false; |
|
Lines 225-231
ScriptValue InjectedScript::findObjectById(const String& objectId) const
a/Source/WebCore/inspector/InjectedScript.cpp_sec14
|
| 225 |
void InjectedScript::inspectNode(Node* node) |
220 |
void InjectedScript::inspectNode(Node* node) |
| 226 |
{ |
221 |
{ |
| 227 |
ASSERT(!hasNoValue()); |
222 |
ASSERT(!hasNoValue()); |
| 228 |
ScriptFunctionCall function(m_injectedScriptObject, "inspectNode"); |
223 |
ScriptFunctionCall function(injectedScriptObject(), "inspectNode"); |
| 229 |
function.appendArgument(nodeAsScriptValue(node)); |
224 |
function.appendArgument(nodeAsScriptValue(node)); |
| 230 |
RefPtr<InspectorValue> result; |
225 |
RefPtr<InspectorValue> result; |
| 231 |
makeCall(function, &result); |
226 |
makeCall(function, &result); |
|
Lines 234-323
void InjectedScript::inspectNode(Node* node)
a/Source/WebCore/inspector/InjectedScript.cpp_sec15
|
| 234 |
void InjectedScript::releaseObjectGroup(const String& objectGroup) |
229 |
void InjectedScript::releaseObjectGroup(const String& objectGroup) |
| 235 |
{ |
230 |
{ |
| 236 |
ASSERT(!hasNoValue()); |
231 |
ASSERT(!hasNoValue()); |
| 237 |
ScriptFunctionCall releaseFunction(m_injectedScriptObject, "releaseObjectGroup"); |
232 |
ScriptFunctionCall releaseFunction(injectedScriptObject(), "releaseObjectGroup"); |
| 238 |
releaseFunction.appendArgument(objectGroup); |
233 |
releaseFunction.appendArgument(objectGroup); |
| 239 |
bool hadException = false; |
234 |
bool hadException = false; |
| 240 |
callFunctionWithEvalEnabled(releaseFunction, hadException); |
235 |
callFunctionWithEvalEnabled(releaseFunction, hadException); |
| 241 |
ASSERT(!hadException); |
236 |
ASSERT(!hadException); |
| 242 |
} |
237 |
} |
| 243 |
|
238 |
|
| 244 |
bool InjectedScript::canAccessInspectedWindow() const |
|
|
| 245 |
{ |
| 246 |
return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState()); |
| 247 |
} |
| 248 |
|
| 249 |
ScriptValue InjectedScript::callFunctionWithEvalEnabled(ScriptFunctionCall& function, bool& hadException) const |
| 250 |
{ |
| 251 |
ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextFromScriptState(m_injectedScriptObject.scriptState()); |
| 252 |
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willCallFunction(scriptExecutionContext, "InjectedScript", 1); |
| 253 |
|
| 254 |
ScriptState* scriptState = m_injectedScriptObject.scriptState(); |
| 255 |
bool evalIsDisabled = false; |
| 256 |
if (scriptState) { |
| 257 |
evalIsDisabled = !evalEnabled(scriptState); |
| 258 |
// Temporarily enable allow evals for inspector. |
| 259 |
if (evalIsDisabled) |
| 260 |
setEvalEnabled(scriptState, true); |
| 261 |
} |
| 262 |
|
| 263 |
ScriptValue resultValue = function.call(hadException); |
| 264 |
|
| 265 |
if (evalIsDisabled) |
| 266 |
setEvalEnabled(scriptState, false); |
| 267 |
|
| 268 |
InspectorInstrumentation::didCallFunction(cookie); |
| 269 |
return resultValue; |
| 270 |
} |
| 271 |
|
| 272 |
void InjectedScript::makeCall(ScriptFunctionCall& function, RefPtr<InspectorValue>* result) |
| 273 |
{ |
| 274 |
if (hasNoValue() || !canAccessInspectedWindow()) { |
| 275 |
*result = InspectorValue::null(); |
| 276 |
return; |
| 277 |
} |
| 278 |
|
| 279 |
bool hadException = false; |
| 280 |
ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException); |
| 281 |
|
| 282 |
ASSERT(!hadException); |
| 283 |
if (!hadException) { |
| 284 |
*result = resultValue.toInspectorValue(m_injectedScriptObject.scriptState()); |
| 285 |
if (!*result) |
| 286 |
*result = InspectorString::create(String::format("Object has too long reference chain(must not be longer than %d)", InspectorValue::maxDepth)); |
| 287 |
} else |
| 288 |
*result = InspectorString::create("Exception while making a call."); |
| 289 |
} |
| 290 |
|
| 291 |
void InjectedScript::makeEvalCall(ErrorString* errorString, ScriptFunctionCall& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuilder::OptOutput<bool>* wasThrown) |
| 292 |
{ |
| 293 |
RefPtr<InspectorValue> result; |
| 294 |
makeCall(function, &result); |
| 295 |
if (!result) { |
| 296 |
*errorString = "Internal error: result value is empty"; |
| 297 |
return; |
| 298 |
} |
| 299 |
if (result->type() == InspectorValue::TypeString) { |
| 300 |
result->asString(errorString); |
| 301 |
return; |
| 302 |
} |
| 303 |
RefPtr<InspectorObject> resultPair = result->asObject(); |
| 304 |
if (!resultPair) { |
| 305 |
*errorString = "Internal error: result is not an Object"; |
| 306 |
return; |
| 307 |
} |
| 308 |
RefPtr<InspectorObject> resultObj = resultPair->getObject("result"); |
| 309 |
bool wasThrownVal = false; |
| 310 |
if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { |
| 311 |
*errorString = "Internal error: result is not a pair of value and wasThrown flag"; |
| 312 |
return; |
| 313 |
} |
| 314 |
*objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj); |
| 315 |
*wasThrown = wasThrownVal; |
| 316 |
} |
| 317 |
|
| 318 |
ScriptValue InjectedScript::nodeAsScriptValue(Node* node) |
239 |
ScriptValue InjectedScript::nodeAsScriptValue(Node* node) |
| 319 |
{ |
240 |
{ |
| 320 |
return InjectedScriptHost::nodeAsScriptValue(m_injectedScriptObject.scriptState(), node); |
241 |
return InjectedScriptHost::nodeAsScriptValue(scriptState(), node); |
| 321 |
} |
242 |
} |
| 322 |
|
243 |
|
| 323 |
} // namespace WebCore |
244 |
} // namespace WebCore |