Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / inspector / WorkerDebuggerAgent.cpp
index 7eeec11..8fe2475 100644 (file)
 #include "config.h"
 #include "core/inspector/WorkerDebuggerAgent.h"
 
-#include "bindings/v8/ScriptDebugServer.h"
+#include "bindings/core/v8/ScriptDebugServer.h"
+#include "core/inspector/WorkerInspectorController.h"
 #include "core/workers/WorkerGlobalScope.h"
 #include "core/workers/WorkerThread.h"
 #include "wtf/MessageQueue.h"
 
-namespace WebCore {
+namespace blink {
 
 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 {
+class RunInspectorCommandsTask final : public ScriptDebugServer::Task {
 public:
-    RunInspectorCommandsTask(WorkerThread* thread, WorkerGlobalScope* workerGlobalScope)
-        : m_thread(thread)
-        , m_workerGlobalScope(workerGlobalScope) { }
+    explicit RunInspectorCommandsTask(WorkerThread* thread)
+        : m_thread(thread) { }
     virtual ~RunInspectorCommandsTask() { }
-    virtual void run() OVERRIDE
+    virtual void run() override
     {
-        // Process all queued debugger commands. It is safe to use m_workerGlobalScope here
-        // because it is alive if RunWorkerLoop is not terminated, otherwise it will
-        // just be ignored. WorkerThread is certainly alive if this task is being executed.
-        while (MessageQueueMessageReceived == m_thread->runLoop().runInMode(m_workerGlobalScope, WorkerDebuggerAgent::debuggerTaskMode, WorkerRunLoop::DontWaitForMessage)) { }
+        // Process all queued debugger commands. WorkerThread is certainly
+        // alive if this task is being executed.
+        m_thread->willEnterNestedLoop();
+        while (MessageQueueMessageReceived == m_thread->runDebuggerTask(WorkerThread::DontWaitForMessage)) { }
+        m_thread->didLeaveNestedLoop();
     }
 
 private:
     WorkerThread* m_thread;
-    WorkerGlobalScope* m_workerGlobalScope;
 };
 
 } // namespace
 
-const char WorkerDebuggerAgent::debuggerTaskMode[] = "debugger";
-
-PassOwnPtr<WorkerDebuggerAgent> WorkerDebuggerAgent::create(WorkerScriptDebugServer* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injectedScriptManager)
+PassOwnPtrWillBeRawPtr<WorkerDebuggerAgent> WorkerDebuggerAgent::create(WorkerScriptDebugServer* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injectedScriptManager)
 {
-    return adoptPtr(new WorkerDebuggerAgent(scriptDebugServer, inspectedWorkerGlobalScope, injectedScriptManager));
+    return adoptPtrWillBeNoop(new WorkerDebuggerAgent(scriptDebugServer, inspectedWorkerGlobalScope, injectedScriptManager));
 }
 
 WorkerDebuggerAgent::WorkerDebuggerAgent(WorkerScriptDebugServer* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injectedScriptManager)
@@ -88,23 +71,21 @@ WorkerDebuggerAgent::WorkerDebuggerAgent(WorkerScriptDebugServer* scriptDebugSer
     , 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)
+void WorkerDebuggerAgent::trace(Visitor* visitor)
 {
-    MutexLocker lock(workerDebuggerAgentsMutex());
-    WorkerDebuggerAgent* agent = workerDebuggerAgents().get(thread);
-    if (agent)
-        agent->m_scriptDebugServer->interruptAndRunTask(adoptPtr(new RunInspectorCommandsTask(thread, agent->m_inspectedWorkerGlobalScope)));
+    visitor->trace(m_inspectedWorkerGlobalScope);
+    InspectorDebuggerAgent::trace(visitor);
+}
+
+void WorkerDebuggerAgent::interruptAndDispatchInspectorCommands()
+{
+    scriptDebugServer().interruptAndRunTask(adoptPtr(new RunInspectorCommandsTask(m_inspectedWorkerGlobalScope->thread())));
 }
 
 void WorkerDebuggerAgent::startListeningScriptDebugServer()
@@ -124,12 +105,13 @@ WorkerScriptDebugServer& WorkerDebuggerAgent::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);
+    if (!executionContextId)
+        return injectedScriptManager()->injectedScriptFor(m_inspectedWorkerGlobalScope->script()->scriptState());
+
+    InjectedScript injectedScript = injectedScriptManager()->injectedScriptForId(*executionContextId);
+    if (injectedScript.isEmpty())
+        *error = "Execution context with given id not found.";
+    return injectedScript;
 }
 
 void WorkerDebuggerAgent::muteConsole()
@@ -142,4 +124,4 @@ void WorkerDebuggerAgent::unmuteConsole()
     // We don't need to mute console for workers.
 }
 
-} // namespace WebCore
+} // namespace blink