OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include "core/inspector/WorkerDebuggerAgent.h" | 33 #include "core/inspector/WorkerDebuggerAgent.h" |
34 | 34 |
35 #include "bindings/v8/ScriptDebugServer.h" | 35 #include "bindings/v8/ScriptDebugServer.h" |
36 #include "core/workers/WorkerContext.h" | 36 #include "core/workers/WorkerGlobalScope.h" |
37 #include "core/workers/WorkerThread.h" | 37 #include "core/workers/WorkerThread.h" |
38 #include <wtf/MessageQueue.h> | 38 #include <wtf/MessageQueue.h> |
39 | 39 |
40 namespace WebCore { | 40 namespace WebCore { |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 Mutex& workerDebuggerAgentsMutex() | 44 Mutex& workerDebuggerAgentsMutex() |
45 { | 45 { |
46 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); | 46 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); |
47 return mutex; | 47 return mutex; |
48 } | 48 } |
49 | 49 |
50 typedef HashMap<WorkerThread*, WorkerDebuggerAgent*> WorkerDebuggerAgents; | 50 typedef HashMap<WorkerThread*, WorkerDebuggerAgent*> WorkerDebuggerAgents; |
51 | 51 |
52 WorkerDebuggerAgents& workerDebuggerAgents() | 52 WorkerDebuggerAgents& workerDebuggerAgents() |
53 { | 53 { |
54 DEFINE_STATIC_LOCAL(WorkerDebuggerAgents, agents, ()); | 54 DEFINE_STATIC_LOCAL(WorkerDebuggerAgents, agents, ()); |
55 return agents; | 55 return agents; |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 class RunInspectorCommandsTask : public ScriptDebugServer::Task { | 59 class RunInspectorCommandsTask : public ScriptDebugServer::Task { |
60 public: | 60 public: |
61 RunInspectorCommandsTask(WorkerThread* thread, WorkerContext* workerContext) | 61 RunInspectorCommandsTask(WorkerThread* thread, WorkerGlobalScope* workerGlob
alScope) |
62 : m_thread(thread) | 62 : m_thread(thread) |
63 , m_workerContext(workerContext) { } | 63 , m_workerGlobalScope(workerGlobalScope) { } |
64 virtual ~RunInspectorCommandsTask() { } | 64 virtual ~RunInspectorCommandsTask() { } |
65 virtual void run() | 65 virtual void run() |
66 { | 66 { |
67 // Process all queued debugger commands. It is safe to use m_workerConte
xt here | 67 // Process all queued debugger commands. It is safe to use m_workerGloba
lScope here |
68 // because it is alive if RunWorkerLoop is not terminated, otherwise it
will | 68 // because it is alive if RunWorkerLoop is not terminated, otherwise it
will |
69 // just be ignored. WorkerThread is certainly alive if this task is bein
g executed. | 69 // just be ignored. WorkerThread is certainly alive if this task is bein
g executed. |
70 while (MessageQueueMessageReceived == m_thread->runLoop().runInMode(m_wo
rkerContext, WorkerDebuggerAgent::debuggerTaskMode, WorkerRunLoop::DontWaitForMe
ssage)) { } | 70 while (MessageQueueMessageReceived == m_thread->runLoop().runInMode(m_wo
rkerGlobalScope, WorkerDebuggerAgent::debuggerTaskMode, WorkerRunLoop::DontWaitF
orMessage)) { } |
71 } | 71 } |
72 | 72 |
73 private: | 73 private: |
74 WorkerThread* m_thread; | 74 WorkerThread* m_thread; |
75 WorkerContext* m_workerContext; | 75 WorkerGlobalScope* m_workerGlobalScope; |
76 }; | 76 }; |
77 | 77 |
78 } // namespace | 78 } // namespace |
79 | 79 |
80 const char* WorkerDebuggerAgent::debuggerTaskMode = "debugger"; | 80 const char* WorkerDebuggerAgent::debuggerTaskMode = "debugger"; |
81 | 81 |
82 PassOwnPtr<WorkerDebuggerAgent> WorkerDebuggerAgent::create(InstrumentingAgents*
instrumentingAgents, InspectorCompositeState* inspectorState, WorkerScriptDebug
Server* scriptDebugServer, WorkerContext* inspectedWorkerContext, InjectedScript
Manager* injectedScriptManager) | 82 PassOwnPtr<WorkerDebuggerAgent> WorkerDebuggerAgent::create(InstrumentingAgents*
instrumentingAgents, InspectorCompositeState* inspectorState, WorkerScriptDebug
Server* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, Inject
edScriptManager* injectedScriptManager) |
83 { | 83 { |
84 return adoptPtr(new WorkerDebuggerAgent(instrumentingAgents, inspectorState,
scriptDebugServer, inspectedWorkerContext, injectedScriptManager)); | 84 return adoptPtr(new WorkerDebuggerAgent(instrumentingAgents, inspectorState,
scriptDebugServer, inspectedWorkerGlobalScope, injectedScriptManager)); |
85 } | 85 } |
86 | 86 |
87 WorkerDebuggerAgent::WorkerDebuggerAgent(InstrumentingAgents* instrumentingAgent
s, InspectorCompositeState* inspectorState, WorkerScriptDebugServer* scriptDebug
Server, WorkerContext* inspectedWorkerContext, InjectedScriptManager* injectedSc
riptManager) | 87 WorkerDebuggerAgent::WorkerDebuggerAgent(InstrumentingAgents* instrumentingAgent
s, InspectorCompositeState* inspectorState, WorkerScriptDebugServer* scriptDebug
Server, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* in
jectedScriptManager) |
88 : InspectorDebuggerAgent(instrumentingAgents, inspectorState, injectedScript
Manager) | 88 : InspectorDebuggerAgent(instrumentingAgents, inspectorState, injectedScript
Manager) |
89 , m_scriptDebugServer(scriptDebugServer) | 89 , m_scriptDebugServer(scriptDebugServer) |
90 , m_inspectedWorkerContext(inspectedWorkerContext) | 90 , m_inspectedWorkerGlobalScope(inspectedWorkerGlobalScope) |
91 { | 91 { |
92 MutexLocker lock(workerDebuggerAgentsMutex()); | 92 MutexLocker lock(workerDebuggerAgentsMutex()); |
93 workerDebuggerAgents().set(inspectedWorkerContext->thread(), this); | 93 workerDebuggerAgents().set(inspectedWorkerGlobalScope->thread(), this); |
94 } | 94 } |
95 | 95 |
96 WorkerDebuggerAgent::~WorkerDebuggerAgent() | 96 WorkerDebuggerAgent::~WorkerDebuggerAgent() |
97 { | 97 { |
98 MutexLocker lock(workerDebuggerAgentsMutex()); | 98 MutexLocker lock(workerDebuggerAgentsMutex()); |
99 ASSERT(workerDebuggerAgents().contains(m_inspectedWorkerContext->thread())); | 99 ASSERT(workerDebuggerAgents().contains(m_inspectedWorkerGlobalScope->thread(
))); |
100 workerDebuggerAgents().remove(m_inspectedWorkerContext->thread()); | 100 workerDebuggerAgents().remove(m_inspectedWorkerGlobalScope->thread()); |
101 } | 101 } |
102 | 102 |
103 void WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(WorkerThread* th
read) | 103 void WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(WorkerThread* th
read) |
104 { | 104 { |
105 MutexLocker lock(workerDebuggerAgentsMutex()); | 105 MutexLocker lock(workerDebuggerAgentsMutex()); |
106 WorkerDebuggerAgent* agent = workerDebuggerAgents().get(thread); | 106 WorkerDebuggerAgent* agent = workerDebuggerAgents().get(thread); |
107 if (agent) | 107 if (agent) |
108 agent->m_scriptDebugServer->interruptAndRunTask(adoptPtr(new RunInspecto
rCommandsTask(thread, agent->m_inspectedWorkerContext))); | 108 agent->m_scriptDebugServer->interruptAndRunTask(adoptPtr(new RunInspecto
rCommandsTask(thread, agent->m_inspectedWorkerGlobalScope))); |
109 } | 109 } |
110 | 110 |
111 void WorkerDebuggerAgent::startListeningScriptDebugServer() | 111 void WorkerDebuggerAgent::startListeningScriptDebugServer() |
112 { | 112 { |
113 scriptDebugServer().addListener(this); | 113 scriptDebugServer().addListener(this); |
114 } | 114 } |
115 | 115 |
116 void WorkerDebuggerAgent::stopListeningScriptDebugServer() | 116 void WorkerDebuggerAgent::stopListeningScriptDebugServer() |
117 { | 117 { |
118 scriptDebugServer().removeListener(this); | 118 scriptDebugServer().removeListener(this); |
119 } | 119 } |
120 | 120 |
121 WorkerScriptDebugServer& WorkerDebuggerAgent::scriptDebugServer() | 121 WorkerScriptDebugServer& WorkerDebuggerAgent::scriptDebugServer() |
122 { | 122 { |
123 return *m_scriptDebugServer; | 123 return *m_scriptDebugServer; |
124 } | 124 } |
125 | 125 |
126 InjectedScript WorkerDebuggerAgent::injectedScriptForEval(ErrorString* error, co
nst int* executionContextId) | 126 InjectedScript WorkerDebuggerAgent::injectedScriptForEval(ErrorString* error, co
nst int* executionContextId) |
127 { | 127 { |
128 if (executionContextId) { | 128 if (executionContextId) { |
129 *error = "Execution context id is not supported for workers as there is
only one execution context."; | 129 *error = "Execution context id is not supported for workers as there is
only one execution context."; |
130 return InjectedScript(); | 130 return InjectedScript(); |
131 } | 131 } |
132 ScriptState* scriptState = scriptStateFromWorkerContext(m_inspectedWorkerCon
text); | 132 ScriptState* scriptState = scriptStateFromWorkerGlobalScope(m_inspectedWorke
rGlobalScope); |
133 return injectedScriptManager()->injectedScriptFor(scriptState); | 133 return injectedScriptManager()->injectedScriptFor(scriptState); |
134 } | 134 } |
135 | 135 |
136 void WorkerDebuggerAgent::muteConsole() | 136 void WorkerDebuggerAgent::muteConsole() |
137 { | 137 { |
138 // We don't need to mute console for workers. | 138 // We don't need to mute console for workers. |
139 } | 139 } |
140 | 140 |
141 void WorkerDebuggerAgent::unmuteConsole() | 141 void WorkerDebuggerAgent::unmuteConsole() |
142 { | 142 { |
143 // We don't need to mute console for workers. | 143 // We don't need to mute console for workers. |
144 } | 144 } |
145 | 145 |
146 void WorkerDebuggerAgent::addConsoleMessage(MessageSource source, MessageLevel l
evel, const String& message, const String& sourceURL) | 146 void WorkerDebuggerAgent::addConsoleMessage(MessageSource source, MessageLevel l
evel, const String& message, const String& sourceURL) |
147 { | 147 { |
148 ScriptExecutionContext* context = m_inspectedWorkerContext; | 148 ScriptExecutionContext* context = m_inspectedWorkerGlobalScope; |
149 context->addConsoleMessage(source, level, message, sourceURL, 0); | 149 context->addConsoleMessage(source, level, message, sourceURL, 0); |
150 } | 150 } |
151 | 151 |
152 } // namespace WebCore | 152 } // namespace WebCore |
OLD | NEW |