• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29  */
30 
31 #include "config.h"
32 #include "core/inspector/WorkerDebuggerAgent.h"
33 
34 #include "bindings/core/v8/ScriptDebugServer.h"
35 #include "core/inspector/WorkerInspectorController.h"
36 #include "core/workers/WorkerGlobalScope.h"
37 #include "core/workers/WorkerThread.h"
38 #include "wtf/MessageQueue.h"
39 
40 namespace blink {
41 
42 namespace {
43 
44 class RunInspectorCommandsTask FINAL : public ScriptDebugServer::Task {
45 public:
RunInspectorCommandsTask(WorkerThread * thread)46     explicit RunInspectorCommandsTask(WorkerThread* thread)
47         : m_thread(thread) { }
~RunInspectorCommandsTask()48     virtual ~RunInspectorCommandsTask() { }
run()49     virtual void run() OVERRIDE
50     {
51         // Process all queued debugger commands. WorkerThread is certainly
52         // alive if this task is being executed.
53         m_thread->willEnterNestedLoop();
54         while (MessageQueueMessageReceived == m_thread->runDebuggerTask(WorkerThread::DontWaitForMessage)) { }
55         m_thread->didLeaveNestedLoop();
56     }
57 
58 private:
59     WorkerThread* m_thread;
60 };
61 
62 } // namespace
63 
create(WorkerScriptDebugServer * scriptDebugServer,WorkerGlobalScope * inspectedWorkerGlobalScope,InjectedScriptManager * injectedScriptManager)64 PassOwnPtrWillBeRawPtr<WorkerDebuggerAgent> WorkerDebuggerAgent::create(WorkerScriptDebugServer* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injectedScriptManager)
65 {
66     return adoptPtrWillBeNoop(new WorkerDebuggerAgent(scriptDebugServer, inspectedWorkerGlobalScope, injectedScriptManager));
67 }
68 
WorkerDebuggerAgent(WorkerScriptDebugServer * scriptDebugServer,WorkerGlobalScope * inspectedWorkerGlobalScope,InjectedScriptManager * injectedScriptManager)69 WorkerDebuggerAgent::WorkerDebuggerAgent(WorkerScriptDebugServer* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injectedScriptManager)
70     : InspectorDebuggerAgent(injectedScriptManager)
71     , m_scriptDebugServer(scriptDebugServer)
72     , m_inspectedWorkerGlobalScope(inspectedWorkerGlobalScope)
73 {
74 }
75 
~WorkerDebuggerAgent()76 WorkerDebuggerAgent::~WorkerDebuggerAgent()
77 {
78 }
79 
trace(Visitor * visitor)80 void WorkerDebuggerAgent::trace(Visitor* visitor)
81 {
82     visitor->trace(m_inspectedWorkerGlobalScope);
83     InspectorDebuggerAgent::trace(visitor);
84 }
85 
interruptAndDispatchInspectorCommands()86 void WorkerDebuggerAgent::interruptAndDispatchInspectorCommands()
87 {
88     scriptDebugServer().interruptAndRunTask(adoptPtr(new RunInspectorCommandsTask(m_inspectedWorkerGlobalScope->thread())));
89 }
90 
startListeningScriptDebugServer()91 void WorkerDebuggerAgent::startListeningScriptDebugServer()
92 {
93     scriptDebugServer().addListener(this);
94 }
95 
stopListeningScriptDebugServer()96 void WorkerDebuggerAgent::stopListeningScriptDebugServer()
97 {
98     scriptDebugServer().removeListener(this);
99 }
100 
scriptDebugServer()101 WorkerScriptDebugServer& WorkerDebuggerAgent::scriptDebugServer()
102 {
103     return *m_scriptDebugServer;
104 }
105 
injectedScriptForEval(ErrorString * error,const int * executionContextId)106 InjectedScript WorkerDebuggerAgent::injectedScriptForEval(ErrorString* error, const int* executionContextId)
107 {
108     if (executionContextId) {
109         *error = "Execution context id is not supported for workers as there is only one execution context.";
110         return InjectedScript();
111     }
112     return injectedScriptManager()->injectedScriptFor(m_inspectedWorkerGlobalScope->script()->scriptState());
113 }
114 
muteConsole()115 void WorkerDebuggerAgent::muteConsole()
116 {
117     // We don't need to mute console for workers.
118 }
119 
unmuteConsole()120 void WorkerDebuggerAgent::unmuteConsole()
121 {
122     // We don't need to mute console for workers.
123 }
124 
125 } // namespace blink
126