Changeset 120769 in webkit
- Timestamp:
- Jun 19, 2012 4:21:03 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r120757 r120769 932 932 inspector/IdentifiersFactory.cpp 933 933 inspector/InjectedScript.cpp 934 inspector/InjectedScriptBase.cpp 934 935 inspector/InjectedScriptHost.cpp 935 936 inspector/InjectedScriptManager.cpp -
trunk/Source/WebCore/ChangeLog
r120765 r120769 1 2012-06-19 Andrey Adaikin <aandrey@chromium.org> 2 3 Web Inspector: Extract InjectedScriptBase class from the InjectedScript 4 https://bugs.webkit.org/show_bug.cgi?id=89107 5 6 Extract methods from the InjectedScript that do not depend on 7 the concrete InjectedScriptSource.js implementation. 8 9 Reviewed by Pavel Feldman. 10 11 * CMakeLists.txt: 12 * GNUmakefile.list.am: 13 * Target.pri: 14 * WebCore.gypi: 15 * WebCore.vcproj/WebCore.vcproj: 16 * WebCore.xcodeproj/project.pbxproj: 17 * inspector/InjectedScript.cpp: 18 (WebCore::InjectedScript::InjectedScript): 19 (WebCore::InjectedScript::evaluate): 20 (WebCore::InjectedScript::callFunctionOn): 21 (WebCore::InjectedScript::evaluateOnCallFrame): 22 (WebCore::InjectedScript::getFunctionDetails): 23 (WebCore::InjectedScript::getProperties): 24 (WebCore::InjectedScript::nodeForObjectId): 25 (WebCore::InjectedScript::releaseObject): 26 (WebCore::InjectedScript::wrapCallFrames): 27 (WebCore::InjectedScript::wrapObject): 28 (WebCore::InjectedScript::wrapSerializedObject): 29 (WebCore::InjectedScript::findObjectById): 30 (WebCore::InjectedScript::inspectNode): 31 (WebCore::InjectedScript::releaseObjectGroup): 32 (WebCore::InjectedScript::nodeAsScriptValue): 33 * inspector/InjectedScript.h: 34 (WebCore): 35 (InjectedScript): 36 * inspector/InjectedScriptBase.cpp: Added. 37 (WebCore): 38 (WebCore::InjectedScriptBase::InjectedScriptBase): 39 (WebCore::InjectedScriptBase::canAccessInspectedWindow): 40 (WebCore::InjectedScriptBase::injectedScriptObject): 41 (WebCore::InjectedScriptBase::callFunctionWithEvalEnabled): 42 (WebCore::InjectedScriptBase::makeCall): 43 (WebCore::InjectedScriptBase::makeEvalCall): 44 * inspector/InjectedScriptBase.h: Copied from Source/WebCore/bindings/js/ScriptObject.h. 45 (WebCore): 46 (InjectedScriptBase): 47 (WebCore::InjectedScriptBase::~InjectedScriptBase): 48 (WebCore::InjectedScriptBase::hasNoValue): 49 (WebCore::InjectedScriptBase::scriptState): 50 * inspector/InspectorAllInOne.cpp: 51 1 52 2012-06-19 Sheriff Bot <webkit.review.bot@gmail.com> 2 53 -
trunk/Source/WebCore/GNUmakefile.list.am
r120757 r120769 2656 2656 Source/WebCore/inspector/InjectedScript.cpp \ 2657 2657 Source/WebCore/inspector/InjectedScript.h \ 2658 Source/WebCore/inspector/InjectedScriptBase.cpp \ 2659 Source/WebCore/inspector/InjectedScriptBase.h \ 2658 2660 Source/WebCore/inspector/InjectedScriptHost.cpp \ 2659 2661 Source/WebCore/inspector/InjectedScriptHost.h \ -
trunk/Source/WebCore/Target.pri
r120757 r120769 892 892 inspector/IdentifiersFactory.cpp \ 893 893 inspector/InjectedScript.cpp \ 894 inspector/InjectedScriptBase.cpp \ 894 895 inspector/InjectedScriptHost.cpp \ 895 896 inspector/InjectedScriptManager.cpp \ … … 2039 2040 inspector/IdentifiersFactory.h \ 2040 2041 inspector/InjectedScript.h \ 2042 inspector/InjectedScriptBase.h \ 2041 2043 inspector/InjectedScriptHost.h \ 2042 2044 inspector/InjectedScriptManager.h \ -
trunk/Source/WebCore/WebCore.gypi
r120757 r120769 2766 2766 'inspector/InjectedScript.cpp', 2767 2767 'inspector/InjectedScript.h', 2768 'inspector/InjectedScriptBase.cpp', 2769 'inspector/InjectedScriptBase.h', 2768 2770 'inspector/InjectedScriptHost.cpp', 2769 2771 'inspector/InjectedScriptHost.h', -
trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj
r120757 r120769 73340 73340 </File> 73341 73341 <File 73342 RelativePath="..\inspector\InjectedScriptBase.cpp" 73343 > 73344 <FileConfiguration 73345 Name="Release|Win32" 73346 ExcludedFromBuild="true" 73347 > 73348 <Tool 73349 Name="VCCLCompilerTool" 73350 /> 73351 </FileConfiguration> 73352 <FileConfiguration 73353 Name="Production|Win32" 73354 ExcludedFromBuild="true" 73355 > 73356 <Tool 73357 Name="VCCLCompilerTool" 73358 /> 73359 </FileConfiguration> 73360 </File> 73361 <File 73362 RelativePath="..\inspector\InjectedScriptBase.h" 73363 > 73364 </File> 73365 <File 73342 73366 RelativePath="..\inspector\InjectedScriptHost.cpp" 73343 73367 > -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r120757 r120769 4466 4466 AA4C3A760B2B1679002334A2 /* StyleElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA4C3A740B2B1679002334A2 /* StyleElement.cpp */; }; 4467 4467 AA4C3A770B2B1679002334A2 /* StyleElement.h in Headers */ = {isa = PBXBuildFile; fileRef = AA4C3A750B2B1679002334A2 /* StyleElement.h */; }; 4468 AAB6054E15874C58007B5031 /* InjectedScriptBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAB6054A15874C58007B5031 /* InjectedScriptBase.cpp */; }; 4469 AAB6054F15874C58007B5031 /* InjectedScriptBase.h in Headers */ = {isa = PBXBuildFile; fileRef = AAB6054B15874C58007B5031 /* InjectedScriptBase.h */; }; 4468 4470 AAD766EB157E502F00E85423 /* InspectorWebGLAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAD766E8157E502F00E85423 /* InspectorWebGLAgent.cpp */; }; 4469 4471 AAD766EC157E502F00E85423 /* InspectorWebGLAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = AAD766E9157E502F00E85423 /* InspectorWebGLAgent.h */; }; … … 11477 11479 AA9030FE157E16A000276247 /* InjectedWebGLScriptSource.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = InjectedWebGLScriptSource.js; sourceTree = "<group>"; }; 11478 11480 AA912750157E35A500454E54 /* InjectedWebGLScriptSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedWebGLScriptSource.h; sourceTree = "<group>"; }; 11481 AAB6054A15874C58007B5031 /* InjectedScriptBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedScriptBase.cpp; sourceTree = "<group>"; }; 11482 AAB6054B15874C58007B5031 /* InjectedScriptBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedScriptBase.h; sourceTree = "<group>"; }; 11479 11483 AAD766E8157E502F00E85423 /* InspectorWebGLAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorWebGLAgent.cpp; sourceTree = "<group>"; }; 11480 11484 AAD766E9157E502F00E85423 /* InspectorWebGLAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorWebGLAgent.h; sourceTree = "<group>"; }; … … 14406 14410 F3644AFD1119805900E0D537 /* InjectedScript.cpp */, 14407 14411 F3644AFE1119805900E0D537 /* InjectedScript.h */, 14412 AAB6054A15874C58007B5031 /* InjectedScriptBase.cpp */, 14413 AAB6054B15874C58007B5031 /* InjectedScriptBase.h */, 14408 14414 7A0E76F610BF08ED00A0276E /* InjectedScriptHost.cpp */, 14409 14415 7A0E76F710BF08ED00A0276E /* InjectedScriptHost.h */, … … 23324 23330 DB23C2CC0A508D29002489EB /* IndentOutdentCommand.h in Headers */, 23325 23331 F3644B001119805900E0D537 /* InjectedScript.h in Headers */, 23332 AAB6054F15874C58007B5031 /* InjectedScriptBase.h in Headers */, 23326 23333 7A0E76FA10BF08ED00A0276E /* InjectedScriptHost.h in Headers */, 23327 23334 F316396C1329481A00A649CB /* InjectedScriptManager.h in Headers */, … … 26462 26469 DB23C2CB0A508D29002489EB /* IndentOutdentCommand.cpp in Sources */, 26463 26470 F3644AFF1119805900E0D537 /* InjectedScript.cpp in Sources */, 26471 AAB6054E15874C58007B5031 /* InjectedScriptBase.cpp in Sources */, 26464 26472 7A0E76F910BF08ED00A0276E /* InjectedScriptHost.cpp in Sources */, 26465 26473 F316396B1329481A00A649CB /* InjectedScriptManager.cpp in Sources */, -
trunk/Source/WebCore/inspector/InjectedScript.cpp
r120709 r120769 1 1 /* 2 * Copyright (C) 201 0, 2011Google Inc. All rights reserved.2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 35 35 #include "InjectedScript.h" 36 36 37 #include "DOMWindow.h"38 #include "Frame.h"39 37 #include "InjectedScriptHost.h" 40 #include "InjectedScriptManager.h"41 #include "InspectorInstrumentation.h"42 38 #include "InspectorValues.h" 43 39 #include "Node.h" 44 40 #include "PlatformString.h" 45 41 #include "ScriptFunctionCall.h" 42 #include "SerializedScriptValue.h" 46 43 47 44 using WebCore::TypeBuilder::Array; … … 54 51 55 52 InjectedScript::InjectedScript() 56 : m_inspectedStateAccessCheck(0)57 53 { 58 54 } 59 55 60 56 InjectedScript::InjectedScript(ScriptObject injectedScriptObject, InspectedStateAccessCheck accessCheck) 61 : m_injectedScriptObject(injectedScriptObject) 62 , m_inspectedStateAccessCheck(accessCheck) 57 : InjectedScriptBase(injectedScriptObject, accessCheck) 63 58 { 64 59 } … … 66 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 64 function.appendArgument(expression); 70 65 function.appendArgument(objectGroup); … … 76 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 74 function.appendArgument(objectId); 80 75 function.appendArgument(expression); … … 86 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 84 function.appendArgument(callFrames); 90 85 function.appendArgument(callFrameId); … … 98 93 void InjectedScript::restartFrame(ErrorString* errorString, const ScriptValue& callFrames, const String& callFrameId, RefPtr<InspectorObject>* result) 99 94 { 100 ScriptFunctionCall function( m_injectedScriptObject, "restartFrame");95 ScriptFunctionCall function(injectedScriptObject(), "restartFrame"); 101 96 function.appendArgument(callFrames); 102 97 function.appendArgument(callFrameId); … … 118 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 116 function.appendArgument(functionId); 122 117 RefPtr<InspectorValue> resultValue; … … 132 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 130 function.appendArgument(objectId); 136 131 function.appendArgument(ownProperties); … … 150 145 return 0; 151 146 152 ScriptFunctionCall function( m_injectedScriptObject, "nodeForObjectId");147 ScriptFunctionCall function(injectedScriptObject(), "nodeForObjectId"); 153 148 function.appendArgument(objectId); 154 149 … … 162 157 void InjectedScript::releaseObject(const String& objectId) 163 158 { 164 ScriptFunctionCall function( m_injectedScriptObject, "releaseObject");159 ScriptFunctionCall function(injectedScriptObject(), "releaseObject"); 165 160 function.appendArgument(objectId); 166 161 RefPtr<InspectorValue> result; … … 172 167 { 173 168 ASSERT(!hasNoValue()); 174 ScriptFunctionCall function( m_injectedScriptObject, "wrapCallFrames");169 ScriptFunctionCall function(injectedScriptObject(), "wrapCallFrames"); 175 170 function.appendArgument(callFrames); 176 171 bool hadException = false; 177 172 ScriptValue callFramesValue = callFunctionWithEvalEnabled(function, hadException); 178 173 ASSERT(!hadException); 179 RefPtr<InspectorValue> result = callFramesValue.toInspectorValue( m_injectedScriptObject.scriptState());174 RefPtr<InspectorValue> result = callFramesValue.toInspectorValue(scriptState()); 180 175 if (result->type() == InspectorValue::TypeArray) 181 176 return Array<CallFrame>::runtimeCast(result); … … 187 182 { 188 183 ASSERT(!hasNoValue()); 189 ScriptFunctionCall wrapFunction( m_injectedScriptObject, "wrapObject");184 ScriptFunctionCall wrapFunction(injectedScriptObject(), "wrapObject"); 190 185 wrapFunction.appendArgument(value); 191 186 wrapFunction.appendArgument(groupName); … … 196 191 return 0; 197 192 } 198 RefPtr<InspectorObject> rawResult = r.toInspectorValue( m_injectedScriptObject.scriptState())->asObject();193 RefPtr<InspectorObject> rawResult = r.toInspectorValue(scriptState())->asObject(); 199 194 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); 200 195 } … … 207 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 205 return scriptValue.hasNoValue() ? 0 : wrapObject(scriptValue, groupName); 211 206 } … … 214 209 { 215 210 ASSERT(!hasNoValue()); 216 ScriptFunctionCall function( m_injectedScriptObject, "findObjectById");211 ScriptFunctionCall function(injectedScriptObject(), "findObjectById"); 217 212 function.appendArgument(objectId); 218 213 … … 226 221 { 227 222 ASSERT(!hasNoValue()); 228 ScriptFunctionCall function( m_injectedScriptObject, "inspectNode");223 ScriptFunctionCall function(injectedScriptObject(), "inspectNode"); 229 224 function.appendArgument(nodeAsScriptValue(node)); 230 225 RefPtr<InspectorValue> result; … … 235 230 { 236 231 ASSERT(!hasNoValue()); 237 ScriptFunctionCall releaseFunction( m_injectedScriptObject, "releaseObjectGroup");232 ScriptFunctionCall releaseFunction(injectedScriptObject(), "releaseObjectGroup"); 238 233 releaseFunction.appendArgument(objectGroup); 239 234 bool hadException = false; … … 242 237 } 243 238 244 bool InjectedScript::canAccessInspectedWindow() const245 {246 return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState());247 }248 249 ScriptValue InjectedScript::callFunctionWithEvalEnabled(ScriptFunctionCall& function, bool& hadException) const250 {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 } else288 *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 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 -
trunk/Source/WebCore/inspector/InjectedScript.h
r120709 r120769 1 1 /* 2 * Copyright (C) 201 0, 2011Google Inc. All rights reserved.2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 32 32 #define InjectedScript_h 33 33 34 #include "InjectedScriptBase.h" 34 35 #include "InjectedScriptManager.h" 35 36 #include "InspectorTypeBuilder.h" … … 42 43 namespace WebCore { 43 44 44 class InspectorArray;45 class InspectorObject;46 class InspectorValue;47 45 class Node; 48 class ScriptFunctionCall; 49 50 typedef String ErrorString; 46 class SerializedScriptValue; 51 47 52 48 #if ENABLE(INSPECTOR) 53 49 54 class InjectedScript {50 class InjectedScript : public InjectedScriptBase { 55 51 public: 56 52 InjectedScript(); 57 53 ~InjectedScript() { } 58 59 bool hasNoValue() const { return m_injectedScriptObject.hasNoValue(); }60 54 61 55 void evaluate(ErrorString*, … … 99 93 void inspectNode(Node*); 100 94 void releaseObjectGroup(const String&); 101 ScriptState* scriptState() const { return m_injectedScriptObject.scriptState(); }102 95 103 96 private: 104 97 friend InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState*); 105 typedef bool (*InspectedStateAccessCheck)(ScriptState*);106 98 InjectedScript(ScriptObject, InspectedStateAccessCheck); 107 99 108 bool canAccessInspectedWindow() const;109 ScriptValue callFunctionWithEvalEnabled(ScriptFunctionCall&, bool& hadException) const;110 void makeCall(ScriptFunctionCall&, RefPtr<InspectorValue>* result);111 void makeEvalCall(ErrorString*, ScriptFunctionCall&, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown);112 100 ScriptValue nodeAsScriptValue(Node*); 113 114 ScriptObject m_injectedScriptObject;115 InspectedStateAccessCheck m_inspectedStateAccessCheck;116 101 }; 117 102 -
trunk/Source/WebCore/inspector/InspectorAllInOne.cpp
r119572 r120769 33 33 #include "IdentifiersFactory.cpp" 34 34 #include "InjectedScript.cpp" 35 #include "InjectedScriptBase.cpp" 35 36 #include "InjectedScriptHost.cpp" 36 37 #include "InjectedScriptManager.cpp"
Note: See TracChangeset
for help on using the changeset viewer.