This source file includes following definitions.
- create
- m_scriptDebugServer
- disconnect
- inspectImpl
- getEventListenersImpl
- clearConsoleMessages
- get
- addInspectedObject
- clearInspectedObjects
- inspectedObject
- debugFunction
- undebugFunction
- monitorFunction
- unmonitorFunction
#include "config.h"
#include "core/inspector/InjectedScriptHost.h"
#include "core/inspector/InspectorConsoleAgent.h"
#include "core/inspector/InspectorDOMAgent.h"
#include "core/inspector/InspectorDebuggerAgent.h"
#include "core/inspector/InspectorInspectorAgent.h"
#include "core/inspector/InstrumentingAgents.h"
#include "platform/JSONValues.h"
#include "wtf/RefPtr.h"
#include "wtf/text/StringBuilder.h"
using namespace std;
namespace WebCore {
PassRefPtr<InjectedScriptHost> InjectedScriptHost::create()
{
return adoptRef(new InjectedScriptHost());
}
InjectedScriptHost::InjectedScriptHost()
: m_instrumentingAgents(0)
, m_scriptDebugServer(0)
{
ScriptWrappable::init(this);
m_defaultInspectableObject = adoptPtr(new InspectableObject());
}
InjectedScriptHost::~InjectedScriptHost()
{
}
void InjectedScriptHost::disconnect()
{
m_instrumentingAgents = 0;
m_scriptDebugServer = 0;
}
void InjectedScriptHost::inspectImpl(PassRefPtr<JSONValue> object, PassRefPtr<JSONValue> hints)
{
if (InspectorInspectorAgent* inspectorAgent = m_instrumentingAgents ? m_instrumentingAgents->inspectorInspectorAgent() : 0) {
RefPtr<TypeBuilder::Runtime::RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::runtimeCast(object);
inspectorAgent->inspect(remoteObject, hints->asObject());
}
}
void InjectedScriptHost::getEventListenersImpl(EventTarget* target, Vector<EventListenerInfo>& listenersArray)
{
InspectorDOMAgent::getEventListeners(target, listenersArray, false);
}
void InjectedScriptHost::clearConsoleMessages()
{
if (InspectorConsoleAgent* consoleAgent = m_instrumentingAgents ? m_instrumentingAgents->inspectorConsoleAgent() : 0) {
ErrorString error;
consoleAgent->clearMessages(&error);
}
}
ScriptValue InjectedScriptHost::InspectableObject::get(ScriptState*)
{
return ScriptValue();
};
void InjectedScriptHost::addInspectedObject(PassOwnPtr<InjectedScriptHost::InspectableObject> object)
{
m_inspectedObjects.prepend(object);
while (m_inspectedObjects.size() > 5)
m_inspectedObjects.removeLast();
}
void InjectedScriptHost::clearInspectedObjects()
{
m_inspectedObjects.clear();
}
InjectedScriptHost::InspectableObject* InjectedScriptHost::inspectedObject(unsigned num)
{
if (num >= m_inspectedObjects.size())
return m_defaultInspectableObject.get();
return m_inspectedObjects[num].get();
}
void InjectedScriptHost::debugFunction(const String& scriptId, int lineNumber, int columnNumber)
{
if (InspectorDebuggerAgent* debuggerAgent = m_instrumentingAgents ? m_instrumentingAgents->inspectorDebuggerAgent() : 0)
debuggerAgent->setBreakpoint(scriptId, lineNumber, columnNumber, InspectorDebuggerAgent::DebugCommandBreakpointSource);
}
void InjectedScriptHost::undebugFunction(const String& scriptId, int lineNumber, int columnNumber)
{
if (InspectorDebuggerAgent* debuggerAgent = m_instrumentingAgents ? m_instrumentingAgents->inspectorDebuggerAgent() : 0)
debuggerAgent->removeBreakpoint(scriptId, lineNumber, columnNumber, InspectorDebuggerAgent::DebugCommandBreakpointSource);
}
void InjectedScriptHost::monitorFunction(const String& scriptId, int lineNumber, int columnNumber, const String& functionName)
{
StringBuilder builder;
builder.appendLiteral("console.log(\"function ");
if (functionName.isEmpty())
builder.appendLiteral("(anonymous function)");
else
builder.append(functionName);
builder.appendLiteral(" called\" + (arguments.length > 0 ? \" with arguments: \" + Array.prototype.join.call(arguments, \", \") : \"\")) && false");
if (InspectorDebuggerAgent* debuggerAgent = m_instrumentingAgents ? m_instrumentingAgents->inspectorDebuggerAgent() : 0)
debuggerAgent->setBreakpoint(scriptId, lineNumber, columnNumber, InspectorDebuggerAgent::MonitorCommandBreakpointSource, builder.toString());
}
void InjectedScriptHost::unmonitorFunction(const String& scriptId, int lineNumber, int columnNumber)
{
if (InspectorDebuggerAgent* debuggerAgent = m_instrumentingAgents ? m_instrumentingAgents->inspectorDebuggerAgent() : 0)
debuggerAgent->removeBreakpoint(scriptId, lineNumber, columnNumber, InspectorDebuggerAgent::MonitorCommandBreakpointSource);
}
}