This source file includes following definitions.
- sendMessageToFrontend
- flush
- updateInspectorStateCookie
- m_agents
- connectFrontend
- disconnectFrontend
- restoreInspectorStateFromCookie
- dispatchMessageFromFrontend
- resume
#include "config.h"
#include "core/inspector/WorkerInspectorController.h"
#include "InspectorBackendDispatcher.h"
#include "InspectorFrontend.h"
#include "core/inspector/InjectedScriptHost.h"
#include "core/inspector/InjectedScriptManager.h"
#include "core/inspector/InspectorConsoleAgent.h"
#include "core/inspector/InspectorFrontendChannel.h"
#include "core/inspector/InspectorHeapProfilerAgent.h"
#include "core/inspector/InspectorProfilerAgent.h"
#include "core/inspector/InspectorState.h"
#include "core/inspector/InspectorStateClient.h"
#include "core/inspector/InspectorTimelineAgent.h"
#include "core/inspector/InstrumentingAgents.h"
#include "core/inspector/WorkerConsoleAgent.h"
#include "core/inspector/WorkerDebuggerAgent.h"
#include "core/inspector/WorkerRuntimeAgent.h"
#include "core/workers/WorkerGlobalScope.h"
#include "core/workers/WorkerReportingProxy.h"
#include "core/workers/WorkerThread.h"
#include "wtf/PassOwnPtr.h"
namespace WebCore {
namespace {
class PageInspectorProxy FINAL : public InspectorFrontendChannel {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit PageInspectorProxy(WorkerGlobalScope* workerGlobalScope) : m_workerGlobalScope(workerGlobalScope) { }
virtual ~PageInspectorProxy() { }
private:
virtual void sendMessageToFrontend(PassRefPtr<JSONObject> message) OVERRIDE
{
m_workerGlobalScope->thread()->workerReportingProxy().postMessageToPageInspector(message->toJSONString());
}
virtual void flush() OVERRIDE { }
WorkerGlobalScope* m_workerGlobalScope;
};
class WorkerStateClient FINAL : public InspectorStateClient {
WTF_MAKE_FAST_ALLOCATED;
public:
WorkerStateClient(WorkerGlobalScope* context) : m_workerGlobalScope(context) { }
virtual ~WorkerStateClient() { }
private:
virtual void updateInspectorStateCookie(const String& cookie) OVERRIDE
{
m_workerGlobalScope->thread()->workerReportingProxy().updateInspectorStateCookie(cookie);
}
WorkerGlobalScope* m_workerGlobalScope;
};
}
WorkerInspectorController::WorkerInspectorController(WorkerGlobalScope* workerGlobalScope)
: m_workerGlobalScope(workerGlobalScope)
, m_stateClient(adoptPtr(new WorkerStateClient(workerGlobalScope)))
, m_state(adoptPtr(new InspectorCompositeState(m_stateClient.get())))
, m_instrumentingAgents(InstrumentingAgents::create())
, m_injectedScriptManager(InjectedScriptManager::createForWorker())
, m_debugServer(adoptPtr(new WorkerScriptDebugServer(workerGlobalScope)))
, m_agents(m_instrumentingAgents.get(), m_state.get())
{
m_agents.append(WorkerRuntimeAgent::create(m_injectedScriptManager.get(), m_debugServer.get(), workerGlobalScope));
OwnPtr<InspectorTimelineAgent> timelineAgent = InspectorTimelineAgent::create(0, 0, 0, 0, InspectorTimelineAgent::WorkerInspector, 0);
m_agents.append(WorkerDebuggerAgent::create(m_debugServer.get(), workerGlobalScope, m_injectedScriptManager.get()));
m_agents.append(InspectorProfilerAgent::create(m_injectedScriptManager.get(), 0));
m_agents.append(InspectorHeapProfilerAgent::create(m_injectedScriptManager.get()));
m_agents.append(WorkerConsoleAgent::create(timelineAgent.get(), m_injectedScriptManager.get()));
m_agents.append(timelineAgent.release());
m_injectedScriptManager->injectedScriptHost()->init(m_instrumentingAgents.get(), m_debugServer.get());
}
WorkerInspectorController::~WorkerInspectorController()
{
m_instrumentingAgents->reset();
disconnectFrontend();
}
void WorkerInspectorController::connectFrontend()
{
ASSERT(!m_frontend);
m_state->unmute();
m_frontendChannel = adoptPtr(new PageInspectorProxy(m_workerGlobalScope));
m_frontend = adoptPtr(new InspectorFrontend(m_frontendChannel.get()));
m_backendDispatcher = InspectorBackendDispatcher::create(m_frontendChannel.get());
m_agents.registerInDispatcher(m_backendDispatcher.get());
m_agents.setFrontend(m_frontend.get());
}
void WorkerInspectorController::disconnectFrontend()
{
if (!m_frontend)
return;
m_backendDispatcher->clearFrontend();
m_backendDispatcher.clear();
m_state->mute();
m_agents.clearFrontend();
m_frontend.clear();
m_frontendChannel.clear();
}
void WorkerInspectorController::restoreInspectorStateFromCookie(const String& inspectorCookie)
{
ASSERT(!m_frontend);
connectFrontend();
m_state->loadFromCookie(inspectorCookie);
m_agents.restore();
}
void WorkerInspectorController::dispatchMessageFromFrontend(const String& message)
{
if (m_backendDispatcher)
m_backendDispatcher->dispatch(message);
}
void WorkerInspectorController::resume()
{
if (WorkerRuntimeAgent* runtimeAgent = m_instrumentingAgents->workerRuntimeAgent()) {
ErrorString unused;
runtimeAgent->run(&unused);
}
}
}