2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
33 #if ENABLE(INSPECTOR) && ENABLE(WORKERS)
35 #include "WorkerInspectorController.h"
37 #include "InjectedScriptHost.h"
38 #include "InjectedScriptManager.h"
39 #include "InspectorBackendDispatcher.h"
40 #include "InspectorClient.h"
41 #include "InspectorConsoleAgent.h"
42 #include "InspectorFrontend.h"
43 #include "InspectorFrontendChannel.h"
44 #include "InspectorState.h"
45 #include "InspectorStateClient.h"
46 #include "InstrumentingAgents.h"
47 #include "WorkerConsoleAgent.h"
48 #include "WorkerContext.h"
49 #include "WorkerDebuggerAgent.h"
50 #include "WorkerReportingProxy.h"
51 #include "WorkerRuntimeAgent.h"
52 #include "WorkerThread.h"
53 #include <wtf/PassOwnPtr.h>
59 class PageInspectorProxy : public InspectorFrontendChannel {
61 explicit PageInspectorProxy(WorkerContext* workerContext) : m_workerContext(workerContext) { }
62 virtual ~PageInspectorProxy() { }
64 virtual bool sendMessageToFrontend(const String& message)
66 m_workerContext->thread()->workerReportingProxy().postMessageToPageInspector(message);
69 WorkerContext* m_workerContext;
72 class WorkerStateClient : public InspectorStateClient {
74 WorkerStateClient(WorkerContext* context) : m_workerContext(context) { }
75 virtual ~WorkerStateClient() { }
78 virtual void updateInspectorStateCookie(const String& cookie)
80 m_workerContext->thread()->workerReportingProxy().updateInspectorStateCookie(cookie);
83 WorkerContext* m_workerContext;
88 WorkerInspectorController::WorkerInspectorController(WorkerContext* workerContext)
89 : m_workerContext(workerContext)
90 , m_stateClient(adoptPtr(new WorkerStateClient(workerContext)))
91 , m_state(adoptPtr(new InspectorState(m_stateClient.get())))
92 , m_instrumentingAgents(adoptPtr(new InstrumentingAgents()))
93 , m_injectedScriptManager(InjectedScriptManager::createForWorker())
96 #if ENABLE(JAVASCRIPT_DEBUGGER)
97 m_debuggerAgent = WorkerDebuggerAgent::create(m_instrumentingAgents.get(), m_state.get(), workerContext, m_injectedScriptManager.get());
99 m_runtimeAgent = WorkerRuntimeAgent::create(m_instrumentingAgents.get(), m_state.get(), m_injectedScriptManager.get(), workerContext);
100 m_consoleAgent = WorkerConsoleAgent::create(m_instrumentingAgents.get(), m_state.get(), m_injectedScriptManager.get());
102 m_injectedScriptManager->injectedScriptHost()->init(0
104 #if ENABLE(SQL_DATABASE)
110 #if ENABLE(JAVASCRIPT_DEBUGGER)
111 m_runtimeAgent->setScriptDebugServer(&m_debuggerAgent->scriptDebugServer());
115 WorkerInspectorController::~WorkerInspectorController()
117 disconnectFrontend();
120 void WorkerInspectorController::connectFrontend()
124 m_frontendChannel = adoptPtr(new PageInspectorProxy(m_workerContext));
125 m_frontend = adoptPtr(new InspectorFrontend(m_frontendChannel.get()));
126 m_backendDispatcher = adoptRef(new InspectorBackendDispatcher(m_frontendChannel.get()));
127 m_consoleAgent->registerInDispatcher(m_backendDispatcher.get());
128 #if ENABLE(JAVASCRIPT_DEBUGGER)
129 m_debuggerAgent->registerInDispatcher(m_backendDispatcher.get());
131 m_runtimeAgent->registerInDispatcher(m_backendDispatcher.get());
133 #if ENABLE(JAVASCRIPT_DEBUGGER)
134 m_debuggerAgent->setFrontend(m_frontend.get());
136 m_consoleAgent->setFrontend(m_frontend.get());
139 void WorkerInspectorController::disconnectFrontend()
143 m_backendDispatcher->clearFrontend();
144 m_backendDispatcher.clear();
145 // Destroying agents would change the state, but we don't want that.
146 // Pre-disconnect state will be used to restore inspector agents.
148 #if ENABLE(JAVASCRIPT_DEBUGGER)
149 m_debuggerAgent->clearFrontend();
151 m_consoleAgent->clearFrontend();
154 m_frontendChannel.clear();
157 void WorkerInspectorController::restoreInspectorStateFromCookie(const String& inspectorCookie)
161 m_state->loadFromCookie(inspectorCookie);
163 #if ENABLE(JAVASCRIPT_DEBUGGER)
164 m_debuggerAgent->restore();
166 m_consoleAgent->restore();
169 void WorkerInspectorController::dispatchMessageFromFrontend(const String& message)
171 if (m_backendDispatcher)
172 m_backendDispatcher->dispatch(message);
175 #if ENABLE(JAVASCRIPT_DEBUGGER)
176 void WorkerInspectorController::resume()
179 m_runtimeAgent->run(&unused);