This source file includes following definitions.
- workerDebuggerAgentsMutex
- workerDebuggerAgents
- run
- create
- m_inspectedWorkerGlobalScope
- interruptAndDispatchInspectorCommands
- startListeningScriptDebugServer
- stopListeningScriptDebugServer
- scriptDebugServer
- injectedScriptForEval
- muteConsole
- unmuteConsole
#include "config.h"
#include "core/inspector/WorkerDebuggerAgent.h"
#include "bindings/v8/ScriptDebugServer.h"
#include "core/workers/WorkerGlobalScope.h"
#include "core/workers/WorkerThread.h"
#include "wtf/MessageQueue.h"
namespace WebCore {
namespace {
Mutex& workerDebuggerAgentsMutex()
{
AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
return mutex;
}
typedef HashMap<WorkerThread*, WorkerDebuggerAgent*> WorkerDebuggerAgents;
WorkerDebuggerAgents& workerDebuggerAgents()
{
DEFINE_STATIC_LOCAL(WorkerDebuggerAgents, agents, ());
return agents;
}
class RunInspectorCommandsTask FINAL : public ScriptDebugServer::Task {
public:
explicit RunInspectorCommandsTask(WorkerThread* thread)
: m_thread(thread) { }
virtual ~RunInspectorCommandsTask() { }
virtual void run() OVERRIDE
{
while (MessageQueueMessageReceived == m_thread->runLoop().runDebuggerTask(WorkerRunLoop::DontWaitForMessage)) { }
}
private:
WorkerThread* m_thread;
};
}
PassOwnPtr<WorkerDebuggerAgent> WorkerDebuggerAgent::create(WorkerScriptDebugServer* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injectedScriptManager)
{
return adoptPtr(new WorkerDebuggerAgent(scriptDebugServer, inspectedWorkerGlobalScope, injectedScriptManager));
}
WorkerDebuggerAgent::WorkerDebuggerAgent(WorkerScriptDebugServer* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injectedScriptManager)
: InspectorDebuggerAgent(injectedScriptManager)
, m_scriptDebugServer(scriptDebugServer)
, m_inspectedWorkerGlobalScope(inspectedWorkerGlobalScope)
{
MutexLocker lock(workerDebuggerAgentsMutex());
workerDebuggerAgents().set(inspectedWorkerGlobalScope->thread(), this);
}
WorkerDebuggerAgent::~WorkerDebuggerAgent()
{
MutexLocker lock(workerDebuggerAgentsMutex());
ASSERT(workerDebuggerAgents().contains(m_inspectedWorkerGlobalScope->thread()));
workerDebuggerAgents().remove(m_inspectedWorkerGlobalScope->thread());
}
void WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(WorkerThread* thread)
{
MutexLocker lock(workerDebuggerAgentsMutex());
WorkerDebuggerAgent* agent = workerDebuggerAgents().get(thread);
if (agent)
agent->m_scriptDebugServer->interruptAndRunTask(adoptPtr(new RunInspectorCommandsTask(thread)));
}
void WorkerDebuggerAgent::startListeningScriptDebugServer()
{
scriptDebugServer().addListener(this);
}
void WorkerDebuggerAgent::stopListeningScriptDebugServer()
{
scriptDebugServer().removeListener(this);
}
WorkerScriptDebugServer& WorkerDebuggerAgent::scriptDebugServer()
{
return *m_scriptDebugServer;
}
InjectedScript WorkerDebuggerAgent::injectedScriptForEval(ErrorString* error, const int* executionContextId)
{
if (executionContextId) {
*error = "Execution context id is not supported for workers as there is only one execution context.";
return InjectedScript();
}
ScriptState* scriptState = scriptStateFromWorkerGlobalScope(m_inspectedWorkerGlobalScope);
return injectedScriptManager()->injectedScriptFor(scriptState);
}
void WorkerDebuggerAgent::muteConsole()
{
}
void WorkerDebuggerAgent::unmuteConsole()
{
}
}