2 * Copyright (C) 2010 Apple 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
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebInspector.h"
31 #include "WebInspectorFrontendClient.h"
32 #include "WebInspectorProxyMessages.h"
34 #include "WebPageCreationParameters.h"
35 #include "WebProcess.h"
36 #include <WebCore/InspectorController.h>
37 #include <WebCore/InspectorFrontendChannel.h>
38 #include <WebCore/Page.h>
40 using namespace WebCore;
44 PassRefPtr<WebInspector> WebInspector::create(WebPage* page, InspectorFrontendChannel* frontendChannel)
46 return adoptRef(new WebInspector(page, frontendChannel));
49 WebInspector::WebInspector(WebPage* page, InspectorFrontendChannel* frontendChannel)
53 , m_frontendChannel(frontendChannel)
54 #if ENABLE(INSPECTOR_SERVER)
55 , m_remoteFrontendConnected(false)
60 // Called from WebInspectorClient
61 WebPage* WebInspector::createInspectorPage()
66 ASSERT(!m_inspectorPage);
67 ASSERT(!m_frontendClient);
69 uint64_t inspectorPageID = 0;
70 WebPageCreationParameters parameters;
72 if (!WebProcess::shared().connection()->sendSync(Messages::WebInspectorProxy::CreateInspectorPage(),
73 Messages::WebInspectorProxy::CreateInspectorPage::Reply(inspectorPageID, parameters),
74 m_page->pageID(), CoreIPC::Connection::NoTimeout)) {
81 WebProcess::shared().createWebPage(inspectorPageID, parameters);
82 m_inspectorPage = WebProcess::shared().webPage(inspectorPageID);
83 ASSERT(m_inspectorPage);
85 OwnPtr<WebInspectorFrontendClient> frontendClient = adoptPtr(new WebInspectorFrontendClient(m_page, m_inspectorPage));
86 m_frontendClient = frontendClient.get();
87 m_inspectorPage->corePage()->inspectorController()->setInspectorFrontendClient(frontendClient.release());
88 return m_inspectorPage;
91 void WebInspector::destroyInspectorPage()
95 m_frontendChannel = 0;
98 // Called from WebInspectorFrontendClient
99 void WebInspector::didLoadInspectorPage()
101 WebProcess::shared().connection()->send(Messages::WebInspectorProxy::DidLoadInspectorPage(), m_page->pageID());
104 void WebInspector::didClose()
106 WebProcess::shared().connection()->send(Messages::WebInspectorProxy::DidClose(), m_page->pageID());
107 destroyInspectorPage();
110 void WebInspector::bringToFront()
112 WebProcess::shared().connection()->send(Messages::WebInspectorProxy::BringToFront(), m_page->pageID());
115 void WebInspector::inspectedURLChanged(const String& urlString)
117 WebProcess::shared().connection()->send(Messages::WebInspectorProxy::InspectedURLChanged(urlString), m_page->pageID());
120 void WebInspector::attach()
122 WebProcess::shared().connection()->send(Messages::WebInspectorProxy::Attach(), m_page->pageID());
125 void WebInspector::detach()
127 WebProcess::shared().connection()->send(Messages::WebInspectorProxy::Detach(), m_page->pageID());
130 void WebInspector::setAttachedWindowHeight(unsigned height)
132 WebProcess::shared().connection()->send(Messages::WebInspectorProxy::SetAttachedWindowHeight(height), m_page->pageID());
135 // Called by WebInspector messages
136 void WebInspector::show()
138 m_page->corePage()->inspectorController()->show();
141 void WebInspector::close()
143 m_page->corePage()->inspectorController()->close();
146 void WebInspector::evaluateScriptForTest(long callID, const String& script)
148 m_page->corePage()->inspectorController()->evaluateForTestInFrontend(callID, script);
151 void WebInspector::showConsole()
153 m_page->corePage()->inspectorController()->show();
154 if (m_frontendClient)
155 m_frontendClient->showConsole();
158 void WebInspector::showResources()
160 m_page->corePage()->inspectorController()->show();
161 if (m_frontendClient)
162 m_frontendClient->showResources();
165 void WebInspector::showMainResourceForFrame(uint64_t frameID)
167 WebFrame* frame = WebProcess::shared().webFrame(frameID);
171 m_page->corePage()->inspectorController()->show();
172 if (m_frontendClient)
173 m_frontendClient->showMainResourceForFrame(frame->coreFrame());
176 void WebInspector::startJavaScriptDebugging()
178 #if ENABLE(JAVASCRIPT_DEBUGGER)
179 m_page->corePage()->inspectorController()->show();
180 if (m_frontendClient)
181 m_frontendClient->setDebuggingEnabled(true);
185 void WebInspector::stopJavaScriptDebugging()
187 #if ENABLE(JAVASCRIPT_DEBUGGER)
188 m_page->corePage()->inspectorController()->show();
189 if (m_frontendClient)
190 m_frontendClient->setDebuggingEnabled(false);
194 void WebInspector::setJavaScriptProfilingEnabled(bool enabled)
196 #if ENABLE(JAVASCRIPT_DEBUGGER)
197 m_page->corePage()->inspectorController()->show();
198 if (!m_frontendClient)
201 m_page->corePage()->inspectorController()->setProfilerEnabled(enabled);
205 void WebInspector::startJavaScriptProfiling()
207 #if ENABLE(JAVASCRIPT_DEBUGGER)
208 m_page->corePage()->inspectorController()->show();
209 if (m_frontendClient)
210 m_frontendClient->startProfilingJavaScript();
214 void WebInspector::stopJavaScriptProfiling()
216 #if ENABLE(JAVASCRIPT_DEBUGGER)
217 m_page->corePage()->inspectorController()->show();
218 if (m_frontendClient)
219 m_frontendClient->stopProfilingJavaScript();
223 void WebInspector::startPageProfiling()
225 m_page->corePage()->inspectorController()->show();
226 if (m_frontendClient)
227 m_frontendClient->setTimelineProfilingEnabled(true);
230 void WebInspector::stopPageProfiling()
232 m_page->corePage()->inspectorController()->show();
233 if (m_frontendClient)
234 m_frontendClient->setTimelineProfilingEnabled(false);
237 void WebInspector::updateDockingAvailability()
239 if (m_frontendClient)
240 m_frontendClient->setDockingUnavailable(!m_frontendClient->canAttachWindow());
243 #if ENABLE(INSPECTOR_SERVER)
244 void WebInspector::sendMessageToRemoteFrontend(const String& message)
246 ASSERT(m_remoteFrontendConnected);
247 WebProcess::shared().connection()->send(Messages::WebInspectorProxy::SendMessageToRemoteFrontend(message), m_page->pageID());
250 void WebInspector::dispatchMessageFromRemoteFrontend(const String& message)
252 m_page->corePage()->inspectorController()->dispatchMessageFromFrontend(message);
255 void WebInspector::remoteFrontendConnected()
257 ASSERT(!m_remoteFrontendConnected);
258 // Switching between in-process and remote inspectors isn't supported yet.
259 ASSERT(!m_inspectorPage);
261 m_page->corePage()->inspectorController()->connectFrontend(m_frontendChannel);
262 m_remoteFrontendConnected = true;
265 void WebInspector::remoteFrontendDisconnected()
267 ASSERT(m_remoteFrontendConnected);
268 m_page->corePage()->inspectorController()->disconnectFrontend();
269 m_remoteFrontendConnected = false;
273 } // namespace WebKit
275 #endif // ENABLE(INSPECTOR)