WorkerInspectorController.cpp [plain text]
#include "config.h"
#if ENABLE(INSPECTOR) && ENABLE(WORKERS)
#include "WorkerInspectorController.h"
#include "InjectedScriptHost.h"
#include "InjectedScriptManager.h"
#include "InspectorBackendDispatcher.h"
#include "InspectorClient.h"
#include "InspectorFrontend.h"
#include "InspectorFrontendChannel.h"
#include "InspectorRuntimeAgent.h"
#include "InspectorState.h"
#include "InstrumentingAgents.h"
#include "WorkerDebuggerAgent.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
namespace {
class WorkerRuntimeAgent : public InspectorRuntimeAgent {
public:
WorkerRuntimeAgent(InjectedScriptManager* injectedScriptManager, WorkerContext* workerContext)
: InspectorRuntimeAgent(injectedScriptManager)
, m_workerContext(workerContext) { }
virtual ~WorkerRuntimeAgent() { }
private:
virtual ScriptState* getDefaultInspectedState()
{
return scriptStateFromWorkerContext(m_workerContext);
}
WorkerContext* m_workerContext;
};
}
WorkerInspectorController::WorkerInspectorController(WorkerContext* workerContext)
: m_workerContext(workerContext)
, m_state(adoptPtr(new InspectorState(0)))
, m_instrumentingAgents(adoptPtr(new InstrumentingAgents()))
, m_injectedScriptManager(InjectedScriptManager::createForWorker())
#if ENABLE(JAVASCRIPT_DEBUGGER)
, m_debuggerAgent(WorkerDebuggerAgent::create(m_instrumentingAgents.get(), m_state.get(), workerContext, m_injectedScriptManager.get()))
#endif
, m_runtimeAgent(adoptPtr(new WorkerRuntimeAgent(m_injectedScriptManager.get(), workerContext)))
{
m_injectedScriptManager->injectedScriptHost()->init(0
, 0
#if ENABLE(DATABASE)
, 0
#endif
#if ENABLE(DOM_STORAGE)
, 0
#endif
);
}
WorkerInspectorController::~WorkerInspectorController()
{
}
void WorkerInspectorController::connectFrontend(InspectorFrontendChannel* channel)
{
ASSERT(!m_frontend);
m_state->unmute();
m_frontend = adoptPtr(new InspectorFrontend(channel));
m_backendDispatcher = adoptPtr(new InspectorBackendDispatcher(
channel,
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
0, #endif
#if ENABLE(JAVASCRIPT_DEBUGGER)
0, #endif
0, 0, 0, #if ENABLE(DOM_STORAGE)
0, #endif
#if ENABLE(DATABASE)
0, #endif
#if ENABLE(JAVASCRIPT_DEBUGGER)
m_debuggerAgent.get(),
#endif
0, 0, #if ENABLE(JAVASCRIPT_DEBUGGER)
0, #endif
m_runtimeAgent.get(),
0, 0 ));
m_injectedScriptManager->injectedScriptHost()->setFrontend(m_frontend.get());
#if ENABLE(JAVASCRIPT_DEBUGGER)
m_debuggerAgent->setFrontend(m_frontend.get());
#endif
}
void WorkerInspectorController::disconnectFrontend()
{
if (!m_frontend)
return;
m_backendDispatcher.clear();
m_state->mute();
#if ENABLE(JAVASCRIPT_DEBUGGER)
m_debuggerAgent->clearFrontend();
#endif
m_injectedScriptManager->injectedScriptHost()->clearFrontend();
m_frontend.clear();
}
void WorkerInspectorController::dispatchMessageFromFrontend(const String& message)
{
if (m_backendDispatcher)
m_backendDispatcher->dispatch(message);
}
}
#endif