Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (120768 => 120769)
--- trunk/Source/WebCore/CMakeLists.txt 2012-06-19 23:19:19 UTC (rev 120768)
+++ trunk/Source/WebCore/CMakeLists.txt 2012-06-19 23:21:03 UTC (rev 120769)
@@ -931,6 +931,7 @@
inspector/DOMPatchSupport.cpp
inspector/IdentifiersFactory.cpp
inspector/InjectedScript.cpp
+ inspector/InjectedScriptBase.cpp
inspector/InjectedScriptHost.cpp
inspector/InjectedScriptManager.cpp
inspector/InspectorAgent.cpp
Modified: trunk/Source/WebCore/ChangeLog (120768 => 120769)
--- trunk/Source/WebCore/ChangeLog 2012-06-19 23:19:19 UTC (rev 120768)
+++ trunk/Source/WebCore/ChangeLog 2012-06-19 23:21:03 UTC (rev 120769)
@@ -1,3 +1,54 @@
+2012-06-19 Andrey Adaikin <[email protected]>
+
+ Web Inspector: Extract InjectedScriptBase class from the InjectedScript
+ https://bugs.webkit.org/show_bug.cgi?id=89107
+
+ Extract methods from the InjectedScript that do not depend on
+ the concrete InjectedScriptSource.js implementation.
+
+ Reviewed by Pavel Feldman.
+
+ * CMakeLists.txt:
+ * GNUmakefile.list.am:
+ * Target.pri:
+ * WebCore.gypi:
+ * WebCore.vcproj/WebCore.vcproj:
+ * WebCore.xcodeproj/project.pbxproj:
+ * inspector/InjectedScript.cpp:
+ (WebCore::InjectedScript::InjectedScript):
+ (WebCore::InjectedScript::evaluate):
+ (WebCore::InjectedScript::callFunctionOn):
+ (WebCore::InjectedScript::evaluateOnCallFrame):
+ (WebCore::InjectedScript::getFunctionDetails):
+ (WebCore::InjectedScript::getProperties):
+ (WebCore::InjectedScript::nodeForObjectId):
+ (WebCore::InjectedScript::releaseObject):
+ (WebCore::InjectedScript::wrapCallFrames):
+ (WebCore::InjectedScript::wrapObject):
+ (WebCore::InjectedScript::wrapSerializedObject):
+ (WebCore::InjectedScript::findObjectById):
+ (WebCore::InjectedScript::inspectNode):
+ (WebCore::InjectedScript::releaseObjectGroup):
+ (WebCore::InjectedScript::nodeAsScriptValue):
+ * inspector/InjectedScript.h:
+ (WebCore):
+ (InjectedScript):
+ * inspector/InjectedScriptBase.cpp: Added.
+ (WebCore):
+ (WebCore::InjectedScriptBase::InjectedScriptBase):
+ (WebCore::InjectedScriptBase::canAccessInspectedWindow):
+ (WebCore::InjectedScriptBase::injectedScriptObject):
+ (WebCore::InjectedScriptBase::callFunctionWithEvalEnabled):
+ (WebCore::InjectedScriptBase::makeCall):
+ (WebCore::InjectedScriptBase::makeEvalCall):
+ * inspector/InjectedScriptBase.h: Copied from Source/WebCore/bindings/js/ScriptObject.h.
+ (WebCore):
+ (InjectedScriptBase):
+ (WebCore::InjectedScriptBase::~InjectedScriptBase):
+ (WebCore::InjectedScriptBase::hasNoValue):
+ (WebCore::InjectedScriptBase::scriptState):
+ * inspector/InspectorAllInOne.cpp:
+
2012-06-19 Sheriff Bot <[email protected]>
Unreviewed, rolling out r120621.
Modified: trunk/Source/WebCore/GNUmakefile.list.am (120768 => 120769)
--- trunk/Source/WebCore/GNUmakefile.list.am 2012-06-19 23:19:19 UTC (rev 120768)
+++ trunk/Source/WebCore/GNUmakefile.list.am 2012-06-19 23:21:03 UTC (rev 120769)
@@ -2655,6 +2655,8 @@
Source/WebCore/inspector/IdentifiersFactory.h \
Source/WebCore/inspector/InjectedScript.cpp \
Source/WebCore/inspector/InjectedScript.h \
+ Source/WebCore/inspector/InjectedScriptBase.cpp \
+ Source/WebCore/inspector/InjectedScriptBase.h \
Source/WebCore/inspector/InjectedScriptHost.cpp \
Source/WebCore/inspector/InjectedScriptHost.h \
Source/WebCore/inspector/InjectedScriptManager.cpp \
Modified: trunk/Source/WebCore/Target.pri (120768 => 120769)
--- trunk/Source/WebCore/Target.pri 2012-06-19 23:19:19 UTC (rev 120768)
+++ trunk/Source/WebCore/Target.pri 2012-06-19 23:21:03 UTC (rev 120769)
@@ -891,6 +891,7 @@
inspector/DOMPatchSupport.cpp \
inspector/IdentifiersFactory.cpp \
inspector/InjectedScript.cpp \
+ inspector/InjectedScriptBase.cpp \
inspector/InjectedScriptHost.cpp \
inspector/InjectedScriptManager.cpp \
inspector/InspectorAgent.cpp \
@@ -2038,6 +2039,7 @@
inspector/DOMWrapperVisitor.h \
inspector/IdentifiersFactory.h \
inspector/InjectedScript.h \
+ inspector/InjectedScriptBase.h \
inspector/InjectedScriptHost.h \
inspector/InjectedScriptManager.h \
inspector/InspectorAgent.h \
Modified: trunk/Source/WebCore/WebCore.gypi (120768 => 120769)
--- trunk/Source/WebCore/WebCore.gypi 2012-06-19 23:19:19 UTC (rev 120768)
+++ trunk/Source/WebCore/WebCore.gypi 2012-06-19 23:21:03 UTC (rev 120769)
@@ -2765,6 +2765,8 @@
'inspector/IdentifiersFactory.h',
'inspector/InjectedScript.cpp',
'inspector/InjectedScript.h',
+ 'inspector/InjectedScriptBase.cpp',
+ 'inspector/InjectedScriptBase.h',
'inspector/InjectedScriptHost.cpp',
'inspector/InjectedScriptHost.h',
'inspector/InjectedScriptManager.cpp',
Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (120768 => 120769)
--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-06-19 23:19:19 UTC (rev 120768)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-06-19 23:21:03 UTC (rev 120769)
@@ -73339,6 +73339,30 @@
>
</File>
<File
+ RelativePath="..\inspector\InjectedScriptBase.cpp"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Production|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\inspector\InjectedScriptBase.h"
+ >
+ </File>
+ <File
RelativePath="..\inspector\InjectedScriptHost.cpp"
>
<FileConfiguration
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (120768 => 120769)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2012-06-19 23:19:19 UTC (rev 120768)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2012-06-19 23:21:03 UTC (rev 120769)
@@ -4465,6 +4465,8 @@
AA21ECCD0ABF0FC6002B834C /* CSSCursorImageValue.h in Headers */ = {isa = PBXBuildFile; fileRef = AA0978EE0ABAA6E100874480 /* CSSCursorImageValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
AA4C3A760B2B1679002334A2 /* StyleElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA4C3A740B2B1679002334A2 /* StyleElement.cpp */; };
AA4C3A770B2B1679002334A2 /* StyleElement.h in Headers */ = {isa = PBXBuildFile; fileRef = AA4C3A750B2B1679002334A2 /* StyleElement.h */; };
+ AAB6054E15874C58007B5031 /* InjectedScriptBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAB6054A15874C58007B5031 /* InjectedScriptBase.cpp */; };
+ AAB6054F15874C58007B5031 /* InjectedScriptBase.h in Headers */ = {isa = PBXBuildFile; fileRef = AAB6054B15874C58007B5031 /* InjectedScriptBase.h */; };
AAD766EB157E502F00E85423 /* InspectorWebGLAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAD766E8157E502F00E85423 /* InspectorWebGLAgent.cpp */; };
AAD766EC157E502F00E85423 /* InspectorWebGLAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = AAD766E9157E502F00E85423 /* InspectorWebGLAgent.h */; };
AAD766ED157E502F00E85423 /* InspectorWebGLInstrumentation.h in Headers */ = {isa = PBXBuildFile; fileRef = AAD766EA157E502F00E85423 /* InspectorWebGLInstrumentation.h */; };
@@ -11476,6 +11478,8 @@
AA4C3A750B2B1679002334A2 /* StyleElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = StyleElement.h; sourceTree = "<group>"; };
AA9030FE157E16A000276247 /* InjectedWebGLScriptSource.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; path = InjectedWebGLScriptSource.js; sourceTree = "<group>"; };
AA912750157E35A500454E54 /* InjectedWebGLScriptSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedWebGLScriptSource.h; sourceTree = "<group>"; };
+ AAB6054A15874C58007B5031 /* InjectedScriptBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedScriptBase.cpp; sourceTree = "<group>"; };
+ AAB6054B15874C58007B5031 /* InjectedScriptBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedScriptBase.h; sourceTree = "<group>"; };
AAD766E8157E502F00E85423 /* InspectorWebGLAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorWebGLAgent.cpp; sourceTree = "<group>"; };
AAD766E9157E502F00E85423 /* InspectorWebGLAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorWebGLAgent.h; sourceTree = "<group>"; };
AAD766EA157E502F00E85423 /* InspectorWebGLInstrumentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorWebGLInstrumentation.h; sourceTree = "<group>"; };
@@ -14405,6 +14409,8 @@
5913A24013D49EBA00F5B05C /* IdentifiersFactory.h */,
F3644AFD1119805900E0D537 /* InjectedScript.cpp */,
F3644AFE1119805900E0D537 /* InjectedScript.h */,
+ AAB6054A15874C58007B5031 /* InjectedScriptBase.cpp */,
+ AAB6054B15874C58007B5031 /* InjectedScriptBase.h */,
7A0E76F610BF08ED00A0276E /* InjectedScriptHost.cpp */,
7A0E76F710BF08ED00A0276E /* InjectedScriptHost.h */,
7A0E76F810BF08ED00A0276E /* InjectedScriptHost.idl */,
@@ -23323,6 +23329,7 @@
316FE1180E6E1DA700BF6088 /* ImplicitAnimation.h in Headers */,
DB23C2CC0A508D29002489EB /* IndentOutdentCommand.h in Headers */,
F3644B001119805900E0D537 /* InjectedScript.h in Headers */,
+ AAB6054F15874C58007B5031 /* InjectedScriptBase.h in Headers */,
7A0E76FA10BF08ED00A0276E /* InjectedScriptHost.h in Headers */,
F316396C1329481A00A649CB /* InjectedScriptManager.h in Headers */,
A8CFF5E50A155A05000A4234 /* InlineBox.h in Headers */,
@@ -26461,6 +26468,7 @@
316FE1170E6E1DA700BF6088 /* ImplicitAnimation.cpp in Sources */,
DB23C2CB0A508D29002489EB /* IndentOutdentCommand.cpp in Sources */,
F3644AFF1119805900E0D537 /* InjectedScript.cpp in Sources */,
+ AAB6054E15874C58007B5031 /* InjectedScriptBase.cpp in Sources */,
7A0E76F910BF08ED00A0276E /* InjectedScriptHost.cpp in Sources */,
F316396B1329481A00A649CB /* InjectedScriptManager.cpp in Sources */,
A8CFF5E60A155A05000A4234 /* InlineBox.cpp in Sources */,
Modified: trunk/Source/WebCore/inspector/InjectedScript.cpp (120768 => 120769)
--- trunk/Source/WebCore/inspector/InjectedScript.cpp 2012-06-19 23:19:19 UTC (rev 120768)
+++ trunk/Source/WebCore/inspector/InjectedScript.cpp 2012-06-19 23:21:03 UTC (rev 120769)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010, 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -34,15 +34,12 @@
#include "InjectedScript.h"
-#include "DOMWindow.h"
-#include "Frame.h"
#include "InjectedScriptHost.h"
-#include "InjectedScriptManager.h"
-#include "InspectorInstrumentation.h"
#include "InspectorValues.h"
#include "Node.h"
#include "PlatformString.h"
#include "ScriptFunctionCall.h"
+#include "SerializedScriptValue.h"
using WebCore::TypeBuilder::Array;
using WebCore::TypeBuilder::Debugger::CallFrame;
@@ -53,19 +50,17 @@
namespace WebCore {
InjectedScript::InjectedScript()
- : m_inspectedStateAccessCheck(0)
{
}
InjectedScript::InjectedScript(ScriptObject injectedScriptObject, InspectedStateAccessCheck accessCheck)
- : m_injectedScriptObject(injectedScriptObject)
- , m_inspectedStateAccessCheck(accessCheck)
+ : InjectedScriptBase(injectedScriptObject, accessCheck)
{
}
void InjectedScript::evaluate(ErrorString* errorString, const String& _expression_, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown)
{
- ScriptFunctionCall function(m_injectedScriptObject, "evaluate");
+ ScriptFunctionCall function(injectedScriptObject(), "evaluate");
function.appendArgument(_expression_);
function.appendArgument(objectGroup);
function.appendArgument(includeCommandLineAPI);
@@ -75,7 +70,7 @@
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)
{
- ScriptFunctionCall function(m_injectedScriptObject, "callFunctionOn");
+ ScriptFunctionCall function(injectedScriptObject(), "callFunctionOn");
function.appendArgument(objectId);
function.appendArgument(_expression_);
function.appendArgument(arguments);
@@ -85,7 +80,7 @@
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)
{
- ScriptFunctionCall function(m_injectedScriptObject, "evaluateOnCallFrame");
+ ScriptFunctionCall function(injectedScriptObject(), "evaluateOnCallFrame");
function.appendArgument(callFrames);
function.appendArgument(callFrameId);
function.appendArgument(_expression_);
@@ -97,7 +92,7 @@
void InjectedScript::restartFrame(ErrorString* errorString, const ScriptValue& callFrames, const String& callFrameId, RefPtr<InspectorObject>* result)
{
- ScriptFunctionCall function(m_injectedScriptObject, "restartFrame");
+ ScriptFunctionCall function(injectedScriptObject(), "restartFrame");
function.appendArgument(callFrames);
function.appendArgument(callFrameId);
RefPtr<InspectorValue> resultValue;
@@ -117,7 +112,7 @@
void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, RefPtr<FunctionDetails>* result)
{
- ScriptFunctionCall function(m_injectedScriptObject, "getFunctionDetails");
+ ScriptFunctionCall function(injectedScriptObject(), "getFunctionDetails");
function.appendArgument(functionId);
RefPtr<InspectorValue> resultValue;
makeCall(function, &resultValue);
@@ -131,7 +126,7 @@
void InjectedScript::getProperties(ErrorString* errorString, const String& objectId, bool ownProperties, RefPtr<Array<PropertyDescriptor> >* properties)
{
- ScriptFunctionCall function(m_injectedScriptObject, "getProperties");
+ ScriptFunctionCall function(injectedScriptObject(), "getProperties");
function.appendArgument(objectId);
function.appendArgument(ownProperties);
@@ -149,7 +144,7 @@
if (hasNoValue() || !canAccessInspectedWindow())
return 0;
- ScriptFunctionCall function(m_injectedScriptObject, "nodeForObjectId");
+ ScriptFunctionCall function(injectedScriptObject(), "nodeForObjectId");
function.appendArgument(objectId);
bool hadException = false;
@@ -161,7 +156,7 @@
void InjectedScript::releaseObject(const String& objectId)
{
- ScriptFunctionCall function(m_injectedScriptObject, "releaseObject");
+ ScriptFunctionCall function(injectedScriptObject(), "releaseObject");
function.appendArgument(objectId);
RefPtr<InspectorValue> result;
makeCall(function, &result);
@@ -171,12 +166,12 @@
PassRefPtr<Array<CallFrame> > InjectedScript::wrapCallFrames(const ScriptValue& callFrames)
{
ASSERT(!hasNoValue());
- ScriptFunctionCall function(m_injectedScriptObject, "wrapCallFrames");
+ ScriptFunctionCall function(injectedScriptObject(), "wrapCallFrames");
function.appendArgument(callFrames);
bool hadException = false;
ScriptValue callFramesValue = callFunctionWithEvalEnabled(function, hadException);
ASSERT(!hadException);
- RefPtr<InspectorValue> result = callFramesValue.toInspectorValue(m_injectedScriptObject.scriptState());
+ RefPtr<InspectorValue> result = callFramesValue.toInspectorValue(scriptState());
if (result->type() == InspectorValue::TypeArray)
return Array<CallFrame>::runtimeCast(result);
return Array<CallFrame>::create();
@@ -186,7 +181,7 @@
PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObject(ScriptValue value, const String& groupName) const
{
ASSERT(!hasNoValue());
- ScriptFunctionCall wrapFunction(m_injectedScriptObject, "wrapObject");
+ ScriptFunctionCall wrapFunction(injectedScriptObject(), "wrapObject");
wrapFunction.appendArgument(value);
wrapFunction.appendArgument(groupName);
wrapFunction.appendArgument(canAccessInspectedWindow());
@@ -195,7 +190,7 @@
if (hadException) {
return 0;
}
- RefPtr<InspectorObject> rawResult = r.toInspectorValue(m_injectedScriptObject.scriptState())->asObject();
+ RefPtr<InspectorObject> rawResult = r.toInspectorValue(scriptState())->asObject();
return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult);
}
@@ -206,14 +201,14 @@
PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapSerializedObject(SerializedScriptValue* serializedScriptValue, const String& groupName) const
{
- ScriptValue scriptValue = serializedScriptValue->deserializeForInspector(m_injectedScriptObject.scriptState());
+ ScriptValue scriptValue = serializedScriptValue->deserializeForInspector(scriptState());
return scriptValue.hasNoValue() ? 0 : wrapObject(scriptValue, groupName);
}
ScriptValue InjectedScript::findObjectById(const String& objectId) const
{
ASSERT(!hasNoValue());
- ScriptFunctionCall function(m_injectedScriptObject, "findObjectById");
+ ScriptFunctionCall function(injectedScriptObject(), "findObjectById");
function.appendArgument(objectId);
bool hadException = false;
@@ -225,7 +220,7 @@
void InjectedScript::inspectNode(Node* node)
{
ASSERT(!hasNoValue());
- ScriptFunctionCall function(m_injectedScriptObject, "inspectNode");
+ ScriptFunctionCall function(injectedScriptObject(), "inspectNode");
function.appendArgument(nodeAsScriptValue(node));
RefPtr<InspectorValue> result;
makeCall(function, &result);
@@ -234,90 +229,16 @@
void InjectedScript::releaseObjectGroup(const String& objectGroup)
{
ASSERT(!hasNoValue());
- ScriptFunctionCall releaseFunction(m_injectedScriptObject, "releaseObjectGroup");
+ ScriptFunctionCall releaseFunction(injectedScriptObject(), "releaseObjectGroup");
releaseFunction.appendArgument(objectGroup);
bool hadException = false;
callFunctionWithEvalEnabled(releaseFunction, hadException);
ASSERT(!hadException);
}
-bool InjectedScript::canAccessInspectedWindow() const
-{
- return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState());
-}
-
-ScriptValue InjectedScript::callFunctionWithEvalEnabled(ScriptFunctionCall& function, bool& hadException) const
-{
- ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextFromScriptState(m_injectedScriptObject.scriptState());
- InspectorInstrumentationCookie cookie = InspectorInstrumentation::willCallFunction(scriptExecutionContext, "InjectedScript", 1);
-
- ScriptState* scriptState = m_injectedScriptObject.scriptState();
- bool evalIsDisabled = false;
- if (scriptState) {
- evalIsDisabled = !evalEnabled(scriptState);
- // Temporarily enable allow evals for inspector.
- if (evalIsDisabled)
- setEvalEnabled(scriptState, true);
- }
-
- ScriptValue resultValue = function.call(hadException);
-
- if (evalIsDisabled)
- setEvalEnabled(scriptState, false);
-
- InspectorInstrumentation::didCallFunction(cookie);
- return resultValue;
-}
-
-void InjectedScript::makeCall(ScriptFunctionCall& function, RefPtr<InspectorValue>* result)
-{
- if (hasNoValue() || !canAccessInspectedWindow()) {
- *result = InspectorValue::null();
- return;
- }
-
- bool hadException = false;
- ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException);
-
- ASSERT(!hadException);
- if (!hadException) {
- *result = resultValue.toInspectorValue(m_injectedScriptObject.scriptState());
- if (!*result)
- *result = InspectorString::create(String::format("Object has too long reference chain(must not be longer than %d)", InspectorValue::maxDepth));
- } else
- *result = InspectorString::create("Exception while making a call.");
-}
-
-void InjectedScript::makeEvalCall(ErrorString* errorString, ScriptFunctionCall& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuilder::OptOutput<bool>* wasThrown)
-{
- RefPtr<InspectorValue> result;
- makeCall(function, &result);
- if (!result) {
- *errorString = "Internal error: result value is empty";
- return;
- }
- if (result->type() == InspectorValue::TypeString) {
- result->asString(errorString);
- return;
- }
- RefPtr<InspectorObject> resultPair = result->asObject();
- if (!resultPair) {
- *errorString = "Internal error: result is not an Object";
- return;
- }
- RefPtr<InspectorObject> resultObj = resultPair->getObject("result");
- bool wasThrownVal = false;
- if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) {
- *errorString = "Internal error: result is not a pair of value and wasThrown flag";
- return;
- }
- *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj);
- *wasThrown = wasThrownVal;
-}
-
ScriptValue InjectedScript::nodeAsScriptValue(Node* node)
{
- return InjectedScriptHost::nodeAsScriptValue(m_injectedScriptObject.scriptState(), node);
+ return InjectedScriptHost::nodeAsScriptValue(scriptState(), node);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/inspector/InjectedScript.h (120768 => 120769)
--- trunk/Source/WebCore/inspector/InjectedScript.h 2012-06-19 23:19:19 UTC (rev 120768)
+++ trunk/Source/WebCore/inspector/InjectedScript.h 2012-06-19 23:21:03 UTC (rev 120769)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010, 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -31,6 +31,7 @@
#ifndef InjectedScript_h
#define InjectedScript_h
+#include "InjectedScriptBase.h"
#include "InjectedScriptManager.h"
#include "InspectorTypeBuilder.h"
#include "ScriptObject.h"
@@ -41,23 +42,16 @@
namespace WebCore {
-class InspectorArray;
-class InspectorObject;
-class InspectorValue;
class Node;
-class ScriptFunctionCall;
+class SerializedScriptValue;
-typedef String ErrorString;
-
#if ENABLE(INSPECTOR)
-class InjectedScript {
+class InjectedScript : public InjectedScriptBase {
public:
InjectedScript();
~InjectedScript() { }
- bool hasNoValue() const { return m_injectedScriptObject.hasNoValue(); }
-
void evaluate(ErrorString*,
const String& _expression_,
const String& objectGroup,
@@ -98,21 +92,12 @@
void inspectNode(Node*);
void releaseObjectGroup(const String&);
- ScriptState* scriptState() const { return m_injectedScriptObject.scriptState(); }
private:
friend InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState*);
- typedef bool (*InspectedStateAccessCheck)(ScriptState*);
InjectedScript(ScriptObject, InspectedStateAccessCheck);
- bool canAccessInspectedWindow() const;
- ScriptValue callFunctionWithEvalEnabled(ScriptFunctionCall&, bool& hadException) const;
- void makeCall(ScriptFunctionCall&, RefPtr<InspectorValue>* result);
- void makeEvalCall(ErrorString*, ScriptFunctionCall&, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown);
ScriptValue nodeAsScriptValue(Node*);
-
- ScriptObject m_injectedScriptObject;
- InspectedStateAccessCheck m_inspectedStateAccessCheck;
};
#endif
Added: trunk/Source/WebCore/inspector/InjectedScriptBase.cpp (0 => 120769)
--- trunk/Source/WebCore/inspector/InjectedScriptBase.cpp (rev 0)
+++ trunk/Source/WebCore/inspector/InjectedScriptBase.cpp 2012-06-19 23:21:03 UTC (rev 120769)
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(INSPECTOR)
+
+#include "InjectedScriptBase.h"
+
+#include "InspectorInstrumentation.h"
+#include "InspectorValues.h"
+#include "PlatformString.h"
+#include "ScriptFunctionCall.h"
+
+using WebCore::TypeBuilder::Runtime::RemoteObject;
+
+namespace WebCore {
+
+InjectedScriptBase::InjectedScriptBase()
+ : m_inspectedStateAccessCheck(0)
+{
+}
+
+InjectedScriptBase::InjectedScriptBase(ScriptObject injectedScriptObject, InspectedStateAccessCheck accessCheck)
+ : m_injectedScriptObject(injectedScriptObject)
+ , m_inspectedStateAccessCheck(accessCheck)
+{
+}
+
+bool InjectedScriptBase::canAccessInspectedWindow() const
+{
+ return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState());
+}
+
+const ScriptObject& InjectedScriptBase::injectedScriptObject() const
+{
+ return m_injectedScriptObject;
+}
+
+ScriptValue InjectedScriptBase::callFunctionWithEvalEnabled(ScriptFunctionCall& function, bool& hadException) const
+{
+ ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextFromScriptState(m_injectedScriptObject.scriptState());
+ InspectorInstrumentationCookie cookie = InspectorInstrumentation::willCallFunction(scriptExecutionContext, "InjectedScript", 1);
+
+ ScriptState* scriptState = m_injectedScriptObject.scriptState();
+ bool evalIsDisabled = false;
+ if (scriptState) {
+ evalIsDisabled = !evalEnabled(scriptState);
+ // Temporarily enable allow evals for inspector.
+ if (evalIsDisabled)
+ setEvalEnabled(scriptState, true);
+ }
+
+ ScriptValue resultValue = function.call(hadException);
+
+ if (evalIsDisabled)
+ setEvalEnabled(scriptState, false);
+
+ InspectorInstrumentation::didCallFunction(cookie);
+ return resultValue;
+}
+
+void InjectedScriptBase::makeCall(ScriptFunctionCall& function, RefPtr<InspectorValue>* result)
+{
+ if (hasNoValue() || !canAccessInspectedWindow()) {
+ *result = InspectorValue::null();
+ return;
+ }
+
+ bool hadException = false;
+ ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException);
+
+ ASSERT(!hadException);
+ if (!hadException) {
+ *result = resultValue.toInspectorValue(m_injectedScriptObject.scriptState());
+ if (!*result)
+ *result = InspectorString::create(String::format("Object has too long reference chain(must not be longer than %d)", InspectorValue::maxDepth));
+ } else
+ *result = InspectorString::create("Exception while making a call.");
+}
+
+void InjectedScriptBase::makeEvalCall(ErrorString* errorString, ScriptFunctionCall& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuilder::OptOutput<bool>* wasThrown)
+{
+ RefPtr<InspectorValue> result;
+ makeCall(function, &result);
+ if (!result) {
+ *errorString = "Internal error: result value is empty";
+ return;
+ }
+ if (result->type() == InspectorValue::TypeString) {
+ result->asString(errorString);
+ return;
+ }
+ RefPtr<InspectorObject> resultPair = result->asObject();
+ if (!resultPair) {
+ *errorString = "Internal error: result is not an Object";
+ return;
+ }
+ RefPtr<InspectorObject> resultObj = resultPair->getObject("result");
+ bool wasThrownVal = false;
+ if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) {
+ *errorString = "Internal error: result is not a pair of value and wasThrown flag";
+ return;
+ }
+ *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj);
+ *wasThrown = wasThrownVal;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INSPECTOR)
Property changes on: trunk/Source/WebCore/inspector/InjectedScriptBase.cpp
___________________________________________________________________
Added: svn:eol-style
Added: trunk/Source/WebCore/inspector/InjectedScriptBase.h (0 => 120769)
--- trunk/Source/WebCore/inspector/InjectedScriptBase.h (rev 0)
+++ trunk/Source/WebCore/inspector/InjectedScriptBase.h 2012-06-19 23:21:03 UTC (rev 120769)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef InjectedScriptBase_h
+#define InjectedScriptBase_h
+
+#include "InspectorTypeBuilder.h"
+#include "ScriptObject.h"
+#include <wtf/Forward.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class InspectorValue;
+class ScriptFunctionCall;
+
+typedef String ErrorString;
+
+#if ENABLE(INSPECTOR)
+
+class InjectedScriptBase {
+public:
+ virtual ~InjectedScriptBase() { }
+
+ bool hasNoValue() const { return m_injectedScriptObject.hasNoValue(); }
+ ScriptState* scriptState() const { return m_injectedScriptObject.scriptState(); }
+
+protected:
+ typedef bool (*InspectedStateAccessCheck)(ScriptState*);
+ InjectedScriptBase();
+ InjectedScriptBase(ScriptObject, InspectedStateAccessCheck);
+
+ bool canAccessInspectedWindow() const;
+ const ScriptObject& injectedScriptObject() const;
+ ScriptValue callFunctionWithEvalEnabled(ScriptFunctionCall&, bool& hadException) const;
+ void makeCall(ScriptFunctionCall&, RefPtr<InspectorValue>* result);
+ void makeEvalCall(ErrorString*, ScriptFunctionCall&, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown);
+
+private:
+ ScriptObject m_injectedScriptObject;
+ InspectedStateAccessCheck m_inspectedStateAccessCheck;
+};
+
+#endif
+
+} // namespace WebCore
+
+#endif
Property changes on: trunk/Source/WebCore/inspector/InjectedScriptBase.h
___________________________________________________________________
Added: svn:eol-style
Modified: trunk/Source/WebCore/inspector/InspectorAllInOne.cpp (120768 => 120769)
--- trunk/Source/WebCore/inspector/InspectorAllInOne.cpp 2012-06-19 23:19:19 UTC (rev 120768)
+++ trunk/Source/WebCore/inspector/InspectorAllInOne.cpp 2012-06-19 23:21:03 UTC (rev 120769)
@@ -32,6 +32,7 @@
#include "DOMPatchSupport.cpp"
#include "IdentifiersFactory.cpp"
#include "InjectedScript.cpp"
+#include "InjectedScriptBase.cpp"
#include "InjectedScriptHost.cpp"
#include "InjectedScriptManager.cpp"
#include "InspectorAgent.cpp"