Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (120841 => 120842)
--- trunk/Source/WebCore/CMakeLists.txt 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/CMakeLists.txt 2012-06-20 18:28:05 UTC (rev 120842)
@@ -930,6 +930,7 @@
inspector/DOMNodeHighlighter.cpp
inspector/DOMPatchSupport.cpp
inspector/IdentifiersFactory.cpp
+ inspector/InjectedScriptModule.cpp
inspector/InjectedScript.cpp
inspector/InjectedScriptBase.cpp
inspector/InjectedScriptHost.cpp
Modified: trunk/Source/WebCore/ChangeLog (120841 => 120842)
--- trunk/Source/WebCore/ChangeLog 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/ChangeLog 2012-06-20 18:28:05 UTC (rev 120842)
@@ -1,3 +1,55 @@
+2012-06-20 Andrey Adaikin <[email protected]>
+
+ Web Inspector: Allow module injections into the InjectedScript
+ https://bugs.webkit.org/show_bug.cgi?id=89530
+
+ Add a new InjectedScriptModule abstract class that inherits InjectedScriptBase
+ to reuse implementation, and which _javascript_ code is injected via
+ InjectedScript.
+
+ Reviewed by Pavel Feldman.
+
+ * CMakeLists.txt:
+ * GNUmakefile.list.am:
+ * Target.pri:
+ * WebCore.gypi:
+ * WebCore.vcproj/WebCore.vcproj:
+ * WebCore.xcodeproj/project.pbxproj:
+ * bindings/js/ScriptObject.cpp:
+ (WebCore::ScriptObject::ScriptObject):
+ (WebCore):
+ * bindings/js/ScriptObject.h:
+ (ScriptObject):
+ (WebCore::ScriptObject::ScriptObject):
+ * bindings/v8/ScriptObject.cpp:
+ (WebCore::ScriptObject::ScriptObject):
+ (WebCore):
+ * bindings/v8/ScriptObject.h:
+ (ScriptObject):
+ (WebCore::ScriptObject::~ScriptObject):
+ * inspector/InjectedScript.cpp:
+ * inspector/InjectedScript.h:
+ (WebCore):
+ (WebCore::InjectedScript::name):
+ (InjectedScript):
+ * inspector/InjectedScriptBase.cpp:
+ (WebCore::InjectedScriptBase::callFunctionWithEvalEnabled):
+ * inspector/InjectedScriptBase.h:
+ (WebCore):
+ (InjectedScriptBase):
+ * inspector/InjectedScriptManager.h:
+ (InjectedScriptManager):
+ (WebCore::InjectedScriptManager::inspectedStateAccessCheck):
+ * inspector/InjectedScriptModule.cpp: Copied from Source/WebCore/inspector/InjectedScriptBase.h.
+ (WebCore):
+ (WebCore::InjectedScriptModule::InjectedScriptModule):
+ (WebCore::InjectedScriptModule::ensureInjected):
+ * inspector/InjectedScriptModule.h: Copied from Source/WebCore/bindings/js/ScriptObject.h.
+ (WebCore):
+ (InjectedScriptModule):
+ * inspector/InjectedScriptSource.js:
+ (.):
+
2012-06-20 Pavel Feldman <[email protected]>
Web Inspector: Timeline label bar jiggles when scrolling
Modified: trunk/Source/WebCore/GNUmakefile.list.am (120841 => 120842)
--- trunk/Source/WebCore/GNUmakefile.list.am 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/GNUmakefile.list.am 2012-06-20 18:28:05 UTC (rev 120842)
@@ -2653,6 +2653,8 @@
Source/WebCore/inspector/DOMWrapperVisitor.h \
Source/WebCore/inspector/IdentifiersFactory.cpp \
Source/WebCore/inspector/IdentifiersFactory.h \
+ Source/WebCore/inspector/InjectedScriptModule.cpp \
+ Source/WebCore/inspector/InjectedScriptModule.h \
Source/WebCore/inspector/InjectedScript.cpp \
Source/WebCore/inspector/InjectedScript.h \
Source/WebCore/inspector/InjectedScriptBase.cpp \
Modified: trunk/Source/WebCore/Target.pri (120841 => 120842)
--- trunk/Source/WebCore/Target.pri 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/Target.pri 2012-06-20 18:28:05 UTC (rev 120842)
@@ -890,6 +890,7 @@
inspector/DOMNodeHighlighter.cpp \
inspector/DOMPatchSupport.cpp \
inspector/IdentifiersFactory.cpp \
+ inspector/InjectedScriptModule.cpp \
inspector/InjectedScript.cpp \
inspector/InjectedScriptBase.cpp \
inspector/InjectedScriptHost.cpp \
@@ -2039,6 +2040,7 @@
inspector/DOMPatchSupport.h \
inspector/DOMWrapperVisitor.h \
inspector/IdentifiersFactory.h \
+ inspector/InjectedScriptModule.h \
inspector/InjectedScript.h \
inspector/InjectedScriptBase.h \
inspector/InjectedScriptHost.h \
Modified: trunk/Source/WebCore/WebCore.gypi (120841 => 120842)
--- trunk/Source/WebCore/WebCore.gypi 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/WebCore.gypi 2012-06-20 18:28:05 UTC (rev 120842)
@@ -2766,6 +2766,8 @@
'inspector/DOMWrapperVisitor.h',
'inspector/IdentifiersFactory.cpp',
'inspector/IdentifiersFactory.h',
+ 'inspector/InjectedScriptModule.cpp',
+ 'inspector/InjectedScriptModule.h',
'inspector/InjectedScript.cpp',
'inspector/InjectedScript.h',
'inspector/InjectedScriptBase.cpp',
Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (120841 => 120842)
--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-06-20 18:28:05 UTC (rev 120842)
@@ -73315,6 +73315,30 @@
>
</File>
<File
+ RelativePath="..\inspector\InjectedScriptModule.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\InjectedScriptModule.h"
+ >
+ </File>
+ <File
RelativePath="..\inspector\InjectedScript.cpp"
>
<FileConfiguration
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (120841 => 120842)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2012-06-20 18:28:05 UTC (rev 120842)
@@ -4467,6 +4467,8 @@
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 */; };
+ AAB6055015874C58007B5031 /* InjectedScriptModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAB6054C15874C58007B5031 /* InjectedScriptModule.cpp */; };
+ AAB6055115874C58007B5031 /* InjectedScriptModule.h in Headers */ = {isa = PBXBuildFile; fileRef = AAB6054D15874C58007B5031 /* InjectedScriptModule.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 */; };
@@ -11480,6 +11482,8 @@
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>"; };
+ AAB6054C15874C58007B5031 /* InjectedScriptModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedScriptModule.cpp; sourceTree = "<group>"; };
+ AAB6054D15874C58007B5031 /* InjectedScriptModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedScriptModule.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>"; };
@@ -14416,6 +14420,8 @@
7A0E76F810BF08ED00A0276E /* InjectedScriptHost.idl */,
F31639691329481A00A649CB /* InjectedScriptManager.cpp */,
F316396A1329481A00A649CB /* InjectedScriptManager.h */,
+ AAB6054C15874C58007B5031 /* InjectedScriptModule.cpp */,
+ AAB6054D15874C58007B5031 /* InjectedScriptModule.h */,
7A563F9512DF5C9100F4536D /* InjectedScriptSource.js */,
AA9030FE157E16A000276247 /* InjectedWebGLScriptSource.js */,
1C435CD414E8545B004E10EA /* Inspector-0.1.json */,
@@ -23332,6 +23338,7 @@
AAB6054F15874C58007B5031 /* InjectedScriptBase.h in Headers */,
7A0E76FA10BF08ED00A0276E /* InjectedScriptHost.h in Headers */,
F316396C1329481A00A649CB /* InjectedScriptManager.h in Headers */,
+ AAB6055115874C58007B5031 /* InjectedScriptModule.h in Headers */,
A8CFF5E50A155A05000A4234 /* InlineBox.h in Headers */,
A8CFF5E30A155A05000A4234 /* InlineFlowBox.h in Headers */,
BCE789161120D6080060ECE5 /* InlineIterator.h in Headers */,
@@ -26471,6 +26478,7 @@
AAB6054E15874C58007B5031 /* InjectedScriptBase.cpp in Sources */,
7A0E76F910BF08ED00A0276E /* InjectedScriptHost.cpp in Sources */,
F316396B1329481A00A649CB /* InjectedScriptManager.cpp in Sources */,
+ AAB6055015874C58007B5031 /* InjectedScriptModule.cpp in Sources */,
A8CFF5E60A155A05000A4234 /* InlineBox.cpp in Sources */,
A8CFF5E40A155A05000A4234 /* InlineFlowBox.cpp in Sources */,
BCEA4859097D93020094C9E4 /* InlineTextBox.cpp in Sources */,
Modified: trunk/Source/WebCore/bindings/js/ScriptObject.cpp (120841 => 120842)
--- trunk/Source/WebCore/bindings/js/ScriptObject.cpp 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/bindings/js/ScriptObject.cpp 2012-06-20 18:28:05 UTC (rev 120842)
@@ -50,6 +50,12 @@
{
}
+ScriptObject::ScriptObject(ScriptState* scriptState, const ScriptValue& scriptValue)
+ : ScriptValue(scriptState->globalData(), scriptValue.jsValue())
+ , m_scriptState(scriptState)
+{
+}
+
static bool handleException(ScriptState* scriptState)
{
if (!scriptState->hadException())
Modified: trunk/Source/WebCore/bindings/js/ScriptObject.h (120841 => 120842)
--- trunk/Source/WebCore/bindings/js/ScriptObject.h 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/bindings/js/ScriptObject.h 2012-06-20 18:28:05 UTC (rev 120842)
@@ -44,7 +44,8 @@
class ScriptObject : public ScriptValue {
public:
ScriptObject(ScriptState*, JSC::JSObject*);
- ScriptObject() {}
+ ScriptObject(ScriptState*, const ScriptValue&);
+ ScriptObject() { }
JSC::JSObject* jsObject() const { return asObject(jsValue()); }
ScriptState* scriptState() const { return m_scriptState; }
Modified: trunk/Source/WebCore/bindings/v8/ScriptObject.cpp (120841 => 120842)
--- trunk/Source/WebCore/bindings/v8/ScriptObject.cpp 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/bindings/v8/ScriptObject.cpp 2012-06-20 18:28:05 UTC (rev 120842)
@@ -51,6 +51,12 @@
{
}
+ScriptObject::ScriptObject(ScriptState* scriptState, const ScriptValue& scriptValue)
+ : ScriptValue(scriptValue)
+ , m_scriptState(scriptState)
+{
+}
+
v8::Local<v8::Object> ScriptObject::v8Object() const
{
ASSERT(v8Value()->IsObject());
Modified: trunk/Source/WebCore/bindings/v8/ScriptObject.h (120841 => 120842)
--- trunk/Source/WebCore/bindings/v8/ScriptObject.h 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/bindings/v8/ScriptObject.h 2012-06-20 18:28:05 UTC (rev 120842)
@@ -43,8 +43,9 @@
class ScriptObject : public ScriptValue {
public:
ScriptObject(ScriptState*, v8::Handle<v8::Object>);
+ ScriptObject(ScriptState*, const ScriptValue&);
ScriptObject() : m_scriptState(0) { };
- virtual ~ScriptObject() {}
+ virtual ~ScriptObject() { }
v8::Local<v8::Object> v8Object() const;
ScriptState* scriptState() const { return m_scriptState; }
Modified: trunk/Source/WebCore/inspector/InjectedScript.cpp (120841 => 120842)
--- trunk/Source/WebCore/inspector/InjectedScript.cpp 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/inspector/InjectedScript.cpp 2012-06-20 18:28:05 UTC (rev 120842)
@@ -35,6 +35,7 @@
#include "InjectedScript.h"
#include "InjectedScriptHost.h"
+#include "InjectedScriptModule.h"
#include "InspectorValues.h"
#include "Node.h"
#include "PlatformString.h"
@@ -50,11 +51,12 @@
namespace WebCore {
InjectedScript::InjectedScript()
+ : InjectedScriptBase("InjectedScript")
{
}
InjectedScript::InjectedScript(ScriptObject injectedScriptObject, InspectedStateAccessCheck accessCheck)
- : InjectedScriptBase(injectedScriptObject, accessCheck)
+ : InjectedScriptBase("InjectedScript", injectedScriptObject, accessCheck)
{
}
Modified: trunk/Source/WebCore/inspector/InjectedScript.h (120841 => 120842)
--- trunk/Source/WebCore/inspector/InjectedScript.h 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/inspector/InjectedScript.h 2012-06-20 18:28:05 UTC (rev 120842)
@@ -42,6 +42,7 @@
namespace WebCore {
+class InjectedScriptModule;
class Node;
class SerializedScriptValue;
@@ -94,6 +95,7 @@
void releaseObjectGroup(const String&);
private:
+ friend class InjectedScriptModule;
friend InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState*);
InjectedScript(ScriptObject, InspectedStateAccessCheck);
Modified: trunk/Source/WebCore/inspector/InjectedScriptBase.cpp (120841 => 120842)
--- trunk/Source/WebCore/inspector/InjectedScriptBase.cpp 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/inspector/InjectedScriptBase.cpp 2012-06-20 18:28:05 UTC (rev 120842)
@@ -43,17 +43,25 @@
namespace WebCore {
-InjectedScriptBase::InjectedScriptBase()
- : m_inspectedStateAccessCheck(0)
+InjectedScriptBase::InjectedScriptBase(const String& name)
+ : m_name(name)
+ , m_inspectedStateAccessCheck(0)
{
}
-InjectedScriptBase::InjectedScriptBase(ScriptObject injectedScriptObject, InspectedStateAccessCheck accessCheck)
- : m_injectedScriptObject(injectedScriptObject)
+InjectedScriptBase::InjectedScriptBase(const String& name, ScriptObject injectedScriptObject, InspectedStateAccessCheck accessCheck)
+ : m_name(name)
+ , m_injectedScriptObject(injectedScriptObject)
, m_inspectedStateAccessCheck(accessCheck)
{
}
+void InjectedScriptBase::initialize(ScriptObject injectedScriptObject, InspectedStateAccessCheck accessCheck)
+{
+ m_injectedScriptObject = injectedScriptObject;
+ m_inspectedStateAccessCheck = accessCheck;
+}
+
bool InjectedScriptBase::canAccessInspectedWindow() const
{
return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState());
@@ -67,7 +75,7 @@
ScriptValue InjectedScriptBase::callFunctionWithEvalEnabled(ScriptFunctionCall& function, bool& hadException) const
{
ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextFromScriptState(m_injectedScriptObject.scriptState());
- InspectorInstrumentationCookie cookie = InspectorInstrumentation::willCallFunction(scriptExecutionContext, "InjectedScript", 1);
+ InspectorInstrumentationCookie cookie = InspectorInstrumentation::willCallFunction(scriptExecutionContext, name(), 1);
ScriptState* scriptState = m_injectedScriptObject.scriptState();
bool evalIsDisabled = false;
Modified: trunk/Source/WebCore/inspector/InjectedScriptBase.h (120841 => 120842)
--- trunk/Source/WebCore/inspector/InjectedScriptBase.h 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/inspector/InjectedScriptBase.h 2012-06-20 18:28:05 UTC (rev 120842)
@@ -49,14 +49,16 @@
public:
virtual ~InjectedScriptBase() { }
+ const String& name() const { return m_name; }
bool hasNoValue() const { return m_injectedScriptObject.hasNoValue(); }
ScriptState* scriptState() const { return m_injectedScriptObject.scriptState(); }
protected:
typedef bool (*InspectedStateAccessCheck)(ScriptState*);
- InjectedScriptBase();
- InjectedScriptBase(ScriptObject, InspectedStateAccessCheck);
+ InjectedScriptBase(const String& name);
+ InjectedScriptBase(const String& name, ScriptObject, InspectedStateAccessCheck);
+ void initialize(ScriptObject, InspectedStateAccessCheck);
bool canAccessInspectedWindow() const;
const ScriptObject& injectedScriptObject() const;
ScriptValue callFunctionWithEvalEnabled(ScriptFunctionCall&, bool& hadException) const;
@@ -64,6 +66,7 @@
void makeEvalCall(ErrorString*, ScriptFunctionCall&, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown);
private:
+ String m_name;
ScriptObject m_injectedScriptObject;
InspectedStateAccessCheck m_inspectedStateAccessCheck;
};
Modified: trunk/Source/WebCore/inspector/InjectedScriptManager.h (120841 => 120842)
--- trunk/Source/WebCore/inspector/InjectedScriptManager.h 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/inspector/InjectedScriptManager.h 2012-06-20 18:28:05 UTC (rev 120842)
@@ -68,8 +68,10 @@
ScriptObject wrapWebGLRenderingContextForInstrumentation(const ScriptObject&);
#endif
+ typedef bool (*InspectedStateAccessCheck)(ScriptState*);
+ InspectedStateAccessCheck inspectedStateAccessCheck() const { return m_inspectedStateAccessCheck; }
+
private:
- typedef bool (*InspectedStateAccessCheck)(ScriptState*);
explicit InjectedScriptManager(InspectedStateAccessCheck);
String injectedScriptSource();
Copied: trunk/Source/WebCore/inspector/InjectedScriptModule.cpp (from rev 120841, trunk/Source/WebCore/inspector/InjectedScriptBase.h) (0 => 120842)
--- trunk/Source/WebCore/inspector/InjectedScriptModule.cpp (rev 0)
+++ trunk/Source/WebCore/inspector/InjectedScriptModule.cpp 2012-06-20 18:28:05 UTC (rev 120842)
@@ -0,0 +1,79 @@
+/*
+ * 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 "InjectedScriptModule.h"
+
+#include "InjectedScript.h"
+#include "InjectedScriptManager.h"
+#include "ScriptFunctionCall.h"
+#include "ScriptObject.h"
+
+namespace WebCore {
+
+InjectedScriptModule::InjectedScriptModule(const String& name)
+ : InjectedScriptBase(name)
+{
+}
+
+void InjectedScriptModule::ensureInjected(InjectedScriptManager& injectedScriptManager, ScriptState* scriptState)
+{
+ InjectedScript injectedScript = injectedScriptManager.injectedScriptFor(scriptState);
+ ASSERT(!injectedScript.hasNoValue());
+ if (injectedScript.hasNoValue())
+ return;
+
+ // FIXME: Make the InjectedScript a module itself.
+ ScriptFunctionCall function(injectedScript.injectedScriptObject(), "module");
+ function.appendArgument(name());
+ bool hadException = false;
+ ScriptValue resultValue = injectedScript.callFunctionWithEvalEnabled(function, hadException);
+ ASSERT(!hadException);
+ if (hadException || resultValue.hasNoValue() || !resultValue.isObject()) {
+ ScriptFunctionCall function(injectedScript.injectedScriptObject(), "injectModule");
+ function.appendArgument(name());
+ function.appendArgument(source());
+ resultValue = injectedScript.callFunctionWithEvalEnabled(function, hadException);
+ if (hadException || resultValue.hasNoValue() || !resultValue.isObject()) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+ }
+
+ ScriptObject moduleObject(scriptState, resultValue);
+ initialize(moduleObject, injectedScriptManager.inspectedStateAccessCheck());
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INSPECTOR)
Copied: trunk/Source/WebCore/inspector/InjectedScriptModule.h (from rev 120841, trunk/Source/WebCore/bindings/js/ScriptObject.h) (0 => 120842)
--- trunk/Source/WebCore/inspector/InjectedScriptModule.h (rev 0)
+++ trunk/Source/WebCore/inspector/InjectedScriptModule.h 2012-06-20 18:28:05 UTC (rev 120842)
@@ -0,0 +1,60 @@
+/*
+ * 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 InjectedScriptModule_h
+#define InjectedScriptModule_h
+
+#include "InjectedScriptBase.h"
+#include "PlatformString.h"
+#include "ScriptState.h"
+
+namespace WebCore {
+
+class InjectedScriptManager;
+
+#if ENABLE(INSPECTOR)
+
+class InjectedScriptModule : public InjectedScriptBase {
+public:
+ virtual String source() const = 0;
+
+protected:
+ // Do not expose constructor in the child classes as well. Instead provide
+ // a static factory method that would create a new instance of the class
+ // and call its ensureInjected() method immediately.
+ InjectedScriptModule(const String& name);
+ void ensureInjected(InjectedScriptManager&, ScriptState*);
+};
+
+#endif
+
+} // namespace WebCore
+
+#endif
Modified: trunk/Source/WebCore/inspector/InjectedScriptSource.js (120841 => 120842)
--- trunk/Source/WebCore/inspector/InjectedScriptSource.js 2012-06-20 18:24:02 UTC (rev 120841)
+++ trunk/Source/WebCore/inspector/InjectedScriptSource.js 2012-06-20 18:28:05 UTC (rev 120842)
@@ -40,6 +40,7 @@
this._idToWrappedObject = {};
this._idToObjectGroupName = {};
this._objectGroups = {};
+ this._modules = {};
}
InjectedScript.primitiveTypes = {
@@ -411,6 +412,19 @@
return object;
},
+ module: function(name)
+ {
+ return this._modules[name];
+ },
+
+ injectModule: function(name, source)
+ {
+ delete this._modules[name];
+ var module = eval("(" + source + ")");
+ this._modules[name] = module;
+ return module;
+ },
+
_isDefined: function(object)
{
return object || this._isHTMLAllCollection(object);