Merge "[Release] Webkit2-efl-123997_0.11.75" into tizen_2.2
[framework/web/webkit-efl.git] / Source / WebKit2 / WebProcess / WebPage / WebInspector.cpp
1 /*
2  * Copyright (C) 2010 Apple 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
6  * are met:
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.
12  *
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.
24  */
25
26 #include "config.h"
27 #include "WebInspector.h"
28
29 #if ENABLE(INSPECTOR)
30 #include "WebFrame.h"
31 #include "WebInspectorFrontendClient.h"
32 #include "WebInspectorProxyMessages.h"
33 #include "WebPage.h"
34 #include "WebPageCreationParameters.h"
35 #include "WebProcess.h"
36 #include <WebCore/InspectorController.h>
37 #include <WebCore/InspectorFrontendChannel.h>
38 #include <WebCore/Page.h>
39
40 using namespace WebCore;
41
42 namespace WebKit {
43
44 PassRefPtr<WebInspector> WebInspector::create(WebPage* page, InspectorFrontendChannel* frontendChannel)
45 {
46     return adoptRef(new WebInspector(page, frontendChannel));
47 }
48
49 WebInspector::WebInspector(WebPage* page, InspectorFrontendChannel* frontendChannel)
50     : m_page(page)
51     , m_inspectorPage(0)
52     , m_frontendClient(0)
53     , m_frontendChannel(frontendChannel)
54 #if ENABLE(INSPECTOR_SERVER)
55     , m_remoteFrontendConnected(false)
56 #endif
57 {
58 }
59
60 // Called from WebInspectorClient
61 WebPage* WebInspector::createInspectorPage()
62 {
63     if (!m_page)
64         return 0;
65
66     ASSERT(!m_inspectorPage);
67     ASSERT(!m_frontendClient);
68
69     uint64_t inspectorPageID = 0;
70     WebPageCreationParameters parameters;
71
72     if (!WebProcess::shared().connection()->sendSync(Messages::WebInspectorProxy::CreateInspectorPage(),
73             Messages::WebInspectorProxy::CreateInspectorPage::Reply(inspectorPageID, parameters),
74             m_page->pageID(), CoreIPC::Connection::NoTimeout)) {
75         return 0;
76     }
77
78     if (!inspectorPageID)
79         return 0;
80
81     WebProcess::shared().createWebPage(inspectorPageID, parameters);
82     m_inspectorPage = WebProcess::shared().webPage(inspectorPageID);
83     ASSERT(m_inspectorPage);
84
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;
89 }
90
91 void WebInspector::destroyInspectorPage()
92 {
93     m_inspectorPage = 0;
94     m_frontendClient = 0;
95     m_frontendChannel = 0;
96 }
97
98 // Called from WebInspectorFrontendClient
99 void WebInspector::didLoadInspectorPage()
100 {
101     WebProcess::shared().connection()->send(Messages::WebInspectorProxy::DidLoadInspectorPage(), m_page->pageID());
102 }
103
104 void WebInspector::didClose()
105 {
106     WebProcess::shared().connection()->send(Messages::WebInspectorProxy::DidClose(), m_page->pageID());
107     destroyInspectorPage();
108 }
109
110 void WebInspector::bringToFront()
111 {
112     WebProcess::shared().connection()->send(Messages::WebInspectorProxy::BringToFront(), m_page->pageID());
113 }
114
115 void WebInspector::inspectedURLChanged(const String& urlString)
116 {
117     WebProcess::shared().connection()->send(Messages::WebInspectorProxy::InspectedURLChanged(urlString), m_page->pageID());
118 }
119
120 void WebInspector::attach()
121 {
122     WebProcess::shared().connection()->send(Messages::WebInspectorProxy::Attach(), m_page->pageID());
123 }
124
125 void WebInspector::detach()
126 {
127     WebProcess::shared().connection()->send(Messages::WebInspectorProxy::Detach(), m_page->pageID());
128 }
129
130 void WebInspector::setAttachedWindowHeight(unsigned height)
131 {
132     WebProcess::shared().connection()->send(Messages::WebInspectorProxy::SetAttachedWindowHeight(height), m_page->pageID());
133 }
134
135 // Called by WebInspector messages
136 void WebInspector::show()
137 {
138     m_page->corePage()->inspectorController()->show();
139 }
140
141 void WebInspector::close()
142 {
143     m_page->corePage()->inspectorController()->close();
144 }
145
146 void WebInspector::evaluateScriptForTest(long callID, const String& script)
147 {
148     m_page->corePage()->inspectorController()->evaluateForTestInFrontend(callID, script);
149 }
150
151 void WebInspector::showConsole()
152 {
153     m_page->corePage()->inspectorController()->show();
154     if (m_frontendClient)
155         m_frontendClient->showConsole();
156 }
157
158 void WebInspector::showResources()
159 {
160     m_page->corePage()->inspectorController()->show();
161     if (m_frontendClient)
162         m_frontendClient->showResources();
163 }
164
165 void WebInspector::showMainResourceForFrame(uint64_t frameID)
166 {
167     WebFrame* frame = WebProcess::shared().webFrame(frameID);
168     if (!frame)
169         return;
170
171     m_page->corePage()->inspectorController()->show();
172     if (m_frontendClient)
173         m_frontendClient->showMainResourceForFrame(frame->coreFrame());
174 }
175
176 void WebInspector::startJavaScriptDebugging()
177 {
178 #if ENABLE(JAVASCRIPT_DEBUGGER)
179     m_page->corePage()->inspectorController()->show();
180     if (m_frontendClient)
181         m_frontendClient->setDebuggingEnabled(true);
182 #endif
183 }
184
185 void WebInspector::stopJavaScriptDebugging()
186 {
187 #if ENABLE(JAVASCRIPT_DEBUGGER)
188     m_page->corePage()->inspectorController()->show();
189     if (m_frontendClient)
190         m_frontendClient->setDebuggingEnabled(false);
191 #endif
192 }
193
194 void WebInspector::setJavaScriptProfilingEnabled(bool enabled)
195 {
196 #if ENABLE(JAVASCRIPT_DEBUGGER)
197     m_page->corePage()->inspectorController()->show();
198     if (!m_frontendClient)
199         return;
200
201     m_page->corePage()->inspectorController()->setProfilerEnabled(enabled);
202 #endif
203 }
204
205 void WebInspector::startJavaScriptProfiling()
206 {
207 #if ENABLE(JAVASCRIPT_DEBUGGER)
208     m_page->corePage()->inspectorController()->show();
209     if (m_frontendClient)
210         m_frontendClient->startProfilingJavaScript();
211 #endif
212 }
213
214 void WebInspector::stopJavaScriptProfiling()
215 {
216 #if ENABLE(JAVASCRIPT_DEBUGGER)
217     m_page->corePage()->inspectorController()->show();
218     if (m_frontendClient)
219         m_frontendClient->stopProfilingJavaScript();
220 #endif
221 }
222
223 void WebInspector::startPageProfiling()
224 {
225     m_page->corePage()->inspectorController()->show();
226     if (m_frontendClient)
227         m_frontendClient->setTimelineProfilingEnabled(true);
228 }
229
230 void WebInspector::stopPageProfiling()
231 {
232     m_page->corePage()->inspectorController()->show();
233     if (m_frontendClient)
234         m_frontendClient->setTimelineProfilingEnabled(false);
235 }
236
237 void WebInspector::updateDockingAvailability()
238 {
239     if (m_frontendClient)
240         m_frontendClient->setDockingUnavailable(!m_frontendClient->canAttachWindow());
241 }
242
243 #if ENABLE(INSPECTOR_SERVER)
244 void WebInspector::sendMessageToRemoteFrontend(const String& message)
245 {
246     ASSERT(m_remoteFrontendConnected);
247     WebProcess::shared().connection()->send(Messages::WebInspectorProxy::SendMessageToRemoteFrontend(message), m_page->pageID());
248 }
249
250 void WebInspector::dispatchMessageFromRemoteFrontend(const String& message)
251 {
252     m_page->corePage()->inspectorController()->dispatchMessageFromFrontend(message);
253 }
254
255 void WebInspector::remoteFrontendConnected()
256 {
257     ASSERT(!m_remoteFrontendConnected);
258     // Switching between in-process and remote inspectors isn't supported yet.
259     ASSERT(!m_inspectorPage);
260     
261     m_page->corePage()->inspectorController()->connectFrontend(m_frontendChannel);
262     m_remoteFrontendConnected = true;
263 }
264
265 void WebInspector::remoteFrontendDisconnected()
266 {
267     ASSERT(m_remoteFrontendConnected);
268     m_page->corePage()->inspectorController()->disconnectFrontend();
269     m_remoteFrontendConnected = false;
270 }
271 #endif
272
273 } // namespace WebKit
274
275 #endif // ENABLE(INSPECTOR)