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.
32 #include "InspectorController.h"
37 #include "GraphicsContext.h"
38 #include "InjectedScriptHost.h"
39 #include "InjectedScriptManager.h"
40 #include "InspectorAgent.h"
41 #include "InspectorBackendDispatcher.h"
42 #include "InspectorBrowserDebuggerAgent.h"
43 #include "InspectorDebuggerAgent.h"
44 #include "InspectorClient.h"
45 #include "InspectorDOMAgent.h"
46 #include "InspectorFrontend.h"
47 #include "InspectorFrontendClient.h"
48 #include "InspectorInstrumentation.h"
49 #include "InspectorProfilerAgent.h"
50 #include "InspectorTimelineAgent.h"
51 #include "InspectorWorkerAgent.h"
53 #include "ScriptObject.h"
55 #include <wtf/UnusedParam.h>
59 InspectorController::InspectorController(Page* page, InspectorClient* inspectorClient)
60 : m_injectedScriptManager(InjectedScriptManager::createForPage())
61 , m_inspectorAgent(adoptPtr(new InspectorAgent(page, inspectorClient, m_injectedScriptManager.get())))
62 , m_inspectorClient(inspectorClient)
63 , m_openingFrontend(false)
64 , m_startUserInitiatedDebuggingWhenFrontedIsConnected(false)
68 InspectorController::~InspectorController()
72 void InspectorController::setInspectorFrontendClient(PassOwnPtr<InspectorFrontendClient> inspectorFrontendClient)
74 m_inspectorFrontendClient = inspectorFrontendClient;
77 bool InspectorController::hasInspectorFrontendClient() const
79 return m_inspectorFrontendClient;
82 void InspectorController::didClearWindowObjectInWorld(Frame* frame, DOMWrapperWorld* world)
84 if (world != mainThreadNormalWorld())
87 // If the page is supposed to serve as InspectorFrontend notify inspector frontend
88 // client that it's cleared so that the client can expose inspector bindings.
89 if (m_inspectorFrontendClient && frame == m_inspectorAgent->inspectedPage()->mainFrame())
90 m_inspectorFrontendClient->windowObjectCleared();
93 void InspectorController::startTimelineProfiler()
96 m_inspectorAgent->timelineAgent()->start(&error);
99 void InspectorController::stopTimelineProfiler()
102 m_inspectorAgent->timelineAgent()->stop(&error);
105 void InspectorController::connectFrontend()
107 m_openingFrontend = false;
108 m_inspectorFrontend = new InspectorFrontend(m_inspectorClient);
109 m_injectedScriptManager->injectedScriptHost()->setFrontend(m_inspectorFrontend.get());
110 m_inspectorAgent->setFrontend(m_inspectorFrontend.get());
112 if (!InspectorInstrumentation::hasFrontends())
113 ScriptController::setCaptureCallStackForUncaughtExceptions(true);
114 InspectorInstrumentation::frontendCreated();
116 ASSERT(m_inspectorClient);
117 m_inspectorBackendDispatcher = new InspectorBackendDispatcher(
119 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
120 m_inspectorAgent->applicationCacheAgent(),
122 #if ENABLE(JAVASCRIPT_DEBUGGER)
123 m_inspectorAgent->browserDebuggerAgent(),
125 m_inspectorAgent->cssAgent(),
126 m_inspectorAgent->consoleAgent(),
127 m_inspectorAgent->domAgent(),
128 #if ENABLE(DOM_STORAGE)
129 m_inspectorAgent->domStorageAgent(),
132 m_inspectorAgent->databaseAgent(),
134 #if ENABLE(JAVASCRIPT_DEBUGGER)
135 m_inspectorAgent->debuggerAgent(),
137 m_inspectorAgent->resourceAgent(),
138 m_inspectorAgent->pageAgent(),
139 #if ENABLE(JAVASCRIPT_DEBUGGER)
140 m_inspectorAgent->profilerAgent(),
142 m_inspectorAgent->runtimeAgent(),
143 m_inspectorAgent->timelineAgent()
145 , m_inspectorAgent->workerAgent()
149 if (m_startUserInitiatedDebuggingWhenFrontedIsConnected) {
150 m_inspectorFrontend->inspector()->startUserInitiatedDebugging();
151 m_startUserInitiatedDebuggingWhenFrontedIsConnected = false;
155 void InspectorController::disconnectFrontend()
157 if (!m_inspectorFrontend)
159 m_inspectorBackendDispatcher.clear();
161 m_inspectorAgent->disconnectFrontend();
162 m_injectedScriptManager->injectedScriptHost()->clearFrontend();
164 m_inspectorFrontend.clear();
166 InspectorInstrumentation::frontendDeleted();
167 if (!InspectorInstrumentation::hasFrontends())
168 ScriptController::setCaptureCallStackForUncaughtExceptions(false);
171 void InspectorController::show()
176 if (m_openingFrontend)
179 if (m_inspectorFrontend)
180 m_inspectorFrontend->inspector()->bringToFront();
182 m_openingFrontend = true;
183 m_inspectorClient->openInspectorFrontend(this);
187 void InspectorController::close()
189 if (!m_inspectorFrontend)
191 m_inspectorFrontend->inspector()->disconnectFromBackend();
192 disconnectFrontend();
195 void InspectorController::restoreInspectorStateFromCookie(const String& inspectorStateCookie)
197 ASSERT(!m_inspectorFrontend);
199 m_inspectorAgent->restoreInspectorStateFromCookie(inspectorStateCookie);
202 void InspectorController::evaluateForTestInFrontend(long callId, const String& script)
204 m_inspectorAgent->evaluateForTestInFrontend(callId, script);
207 void InspectorController::drawNodeHighlight(GraphicsContext& context) const
209 m_inspectorAgent->domAgent()->drawNodeHighlight(context);
212 void InspectorController::showConsole()
217 m_inspectorAgent->showConsole();
220 void InspectorController::inspect(Node* node)
227 m_inspectorAgent->domAgent()->inspect(node);
230 bool InspectorController::enabled() const
232 return m_inspectorAgent->enabled();
235 Page* InspectorController::inspectedPage() const
237 return m_inspectorAgent->inspectedPage();
240 bool InspectorController::timelineProfilerEnabled()
242 return m_inspectorAgent->timelineAgent()->started();
245 void InspectorController::setInspectorExtensionAPI(const String& source)
247 m_inspectorAgent->setInspectorExtensionAPI(source);
250 void InspectorController::dispatchMessageFromFrontend(const String& message)
252 if (m_inspectorBackendDispatcher)
253 m_inspectorBackendDispatcher->dispatch(message);
256 void InspectorController::hideHighlight()
259 m_inspectorAgent->domAgent()->hideHighlight(&error);
262 Node* InspectorController::highlightedNode() const
264 return m_inspectorAgent->domAgent()->highlightedNode();
267 #if ENABLE(JAVASCRIPT_DEBUGGER)
268 void InspectorController::enableProfiler()
271 m_inspectorAgent->profilerAgent()->enable(&error);
274 void InspectorController::disableProfiler()
277 m_inspectorAgent->profilerAgent()->disable(&error);
280 bool InspectorController::profilerEnabled()
282 return m_inspectorAgent->profilerAgent()->enabled();
285 bool InspectorController::debuggerEnabled()
287 return m_inspectorAgent->debuggerAgent()->enabled();
290 void InspectorController::showAndEnableDebugger()
296 if (m_inspectorFrontend)
297 m_inspectorFrontend->inspector()->startUserInitiatedDebugging();
299 m_startUserInitiatedDebuggingWhenFrontedIsConnected = true;
302 void InspectorController::disableDebugger()
304 m_inspectorAgent->debuggerAgent()->disable();
307 void InspectorController::startUserInitiatedProfiling()
309 m_inspectorAgent->profilerAgent()->startUserInitiatedProfiling();
312 void InspectorController::stopUserInitiatedProfiling()
317 m_inspectorAgent->profilerAgent()->stopUserInitiatedProfiling();
318 m_inspectorAgent->showProfilesPanel();
321 bool InspectorController::isRecordingUserInitiatedProfile() const
323 return m_inspectorAgent->profilerAgent()->isRecordingUserInitiatedProfile();
326 void InspectorController::resume()
328 if (InspectorDebuggerAgent* debuggerAgent = m_inspectorAgent->debuggerAgent()) {
330 debuggerAgent->resume(&error);
336 } // namespace WebCore
338 #endif // ENABLE(INSPECTOR)