[Release] Webkit2-efl-123997_0.11.86
[framework/web/webkit-efl.git] / Source / WebKit / win / WebInspector.cpp
1 /*
2  * Copyright (C) 2007 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  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14  *     its contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #include "config.h"
30 #include "WebInspector.h"
31
32 #if ENABLE(INSPECTOR)
33
34 #include "WebInspectorClient.h"
35 #include "WebKitDLL.h"
36 #include "WebView.h"
37 #include <WebCore/InspectorController.h>
38 #include <WebCore/Page.h>
39 #include <wtf/Assertions.h>
40
41 using namespace WebCore;
42
43 WebInspector* WebInspector::createInstance(WebView* webView, WebInspectorClient* inspectorClient)
44 {
45     WebInspector* inspector = new WebInspector(webView, inspectorClient);
46     inspector->AddRef();
47     return inspector;
48 }
49
50 WebInspector::WebInspector(WebView* webView, WebInspectorClient* inspectorClient)
51     : m_refCount(0)
52     , m_webView(webView)
53     , m_inspectorClient(inspectorClient)
54 {
55     ASSERT_ARG(webView, webView);
56
57     gClassCount++;
58     gClassNameCount.add("WebInspector");
59 }
60
61 WebInspector::~WebInspector()
62 {
63     gClassCount--;
64     gClassNameCount.remove("WebInspector");
65 }
66
67 WebInspectorFrontendClient* WebInspector::frontendClient()
68 {
69     return m_inspectorClient ? m_inspectorClient->frontendClient() : 0;
70 }
71
72 void WebInspector::webViewClosed()
73 {
74     m_webView = 0;
75     m_inspectorClient = 0;
76 }
77
78 HRESULT STDMETHODCALLTYPE WebInspector::QueryInterface(REFIID riid, void** ppvObject)
79 {
80     *ppvObject = 0;
81     if (IsEqualGUID(riid, IID_IWebInspector))
82         *ppvObject = static_cast<IWebInspector*>(this);
83     else if (IsEqualGUID(riid, IID_IWebInspectorPrivate))
84         *ppvObject = static_cast<IWebInspectorPrivate*>(this);
85     else if (IsEqualGUID(riid, IID_IUnknown))
86         *ppvObject = static_cast<IWebInspector*>(this);
87     else
88         return E_NOINTERFACE;
89
90     AddRef();
91     return S_OK;
92 }
93
94 ULONG STDMETHODCALLTYPE WebInspector::AddRef(void)
95 {
96     return ++m_refCount;
97 }
98
99 ULONG STDMETHODCALLTYPE WebInspector::Release(void)
100 {
101     ULONG newRef = --m_refCount;
102     if (!newRef)
103         delete this;
104
105     return newRef;
106 }
107
108 HRESULT STDMETHODCALLTYPE WebInspector::show()
109 {
110     if (m_webView)
111         if (Page* page = m_webView->page())
112             page->inspectorController()->show();
113
114     return S_OK;
115 }
116
117 HRESULT STDMETHODCALLTYPE WebInspector::showConsole()
118 {
119     if (frontendClient())
120         frontendClient()->showConsole();
121
122     return S_OK;
123 }
124
125 HRESULT STDMETHODCALLTYPE WebInspector::unused1()
126 {
127     return S_OK;
128 }
129
130 HRESULT STDMETHODCALLTYPE WebInspector::close()
131 {
132     if (m_webView)
133         if (Page* page = m_webView->page())
134             page->inspectorController()->close();
135
136     return S_OK;
137 }
138
139 HRESULT STDMETHODCALLTYPE WebInspector::attach()
140 {
141     return S_OK;
142 }
143
144 HRESULT STDMETHODCALLTYPE WebInspector::detach()
145 {
146     return S_OK;
147 }
148
149 HRESULT STDMETHODCALLTYPE WebInspector::isDebuggingJavaScript(BOOL* isDebugging)
150 {
151     if (!isDebugging)
152         return E_POINTER;
153
154     *isDebugging = FALSE;
155
156     if (!frontendClient())
157         return S_OK;
158
159     *isDebugging = frontendClient()->isDebuggingEnabled();
160     return S_OK;
161 }
162
163 HRESULT STDMETHODCALLTYPE WebInspector::toggleDebuggingJavaScript()
164 {
165     show();
166
167     if (!frontendClient())
168         return S_OK;
169
170     if (frontendClient()->isDebuggingEnabled())
171         frontendClient()->setDebuggingEnabled(false);
172     else
173         frontendClient()->setDebuggingEnabled(true);
174
175     return S_OK;
176 }
177
178 HRESULT STDMETHODCALLTYPE WebInspector::isProfilingJavaScript(BOOL* isProfiling)
179 {
180     if (!isProfiling)
181         return E_POINTER;
182
183     *isProfiling = FALSE;
184
185     if (!frontendClient())
186         return S_OK;
187
188     *isProfiling = frontendClient()->isProfilingJavaScript();
189
190     return S_OK;
191 }
192
193 HRESULT STDMETHODCALLTYPE WebInspector::toggleProfilingJavaScript()
194 {
195     show();
196
197     if (!frontendClient())
198         return S_OK;
199
200     if (frontendClient()->isProfilingJavaScript())
201         frontendClient()->stopProfilingJavaScript();
202     else
203         frontendClient()->startProfilingJavaScript();
204
205     return S_OK;
206 }
207
208 HRESULT STDMETHODCALLTYPE WebInspector::isJavaScriptProfilingEnabled(BOOL* isProfilingEnabled)
209 {
210     if (!isProfilingEnabled)
211         return E_POINTER;
212
213     *isProfilingEnabled = FALSE;
214
215     if (!m_webView)
216         return S_OK;
217
218     Page* page = m_webView->page();
219     if (!page)
220         return S_OK;
221
222     *isProfilingEnabled = page->inspectorController()->profilerEnabled();
223     return S_OK;
224 }
225
226 HRESULT STDMETHODCALLTYPE WebInspector::setJavaScriptProfilingEnabled(BOOL enabled)
227 {
228     if (!m_webView)
229         return S_OK;
230
231     Page* page = m_webView->page();
232     if (!page)
233         return S_OK;
234
235     page->inspectorController()->setProfilerEnabled(enabled);
236
237     return S_OK;
238 }
239
240 HRESULT STDMETHODCALLTYPE  WebInspector::evaluateInFrontend(ULONG callId, BSTR bScript)
241 {
242     if (!m_webView)
243         return S_OK;
244
245     Page* page = m_webView->page();
246     if (!page)
247         return S_OK;
248
249     String script(bScript, SysStringLen(bScript));
250     page->inspectorController()->evaluateForTestInFrontend(callId, script);
251     return S_OK;
252 }
253
254 HRESULT STDMETHODCALLTYPE WebInspector::isTimelineProfilingEnabled(BOOL* isEnabled)
255 {
256     if (!isEnabled)
257         return E_POINTER;
258
259     *isEnabled = FALSE;
260
261     if (!frontendClient())
262         return S_OK;
263
264     *isEnabled = frontendClient()->isTimelineProfilingEnabled();
265     return S_OK;
266 }
267
268 HRESULT STDMETHODCALLTYPE WebInspector::setTimelineProfilingEnabled(BOOL enabled)
269 {
270     show();
271
272     if (!frontendClient())
273         return S_OK;
274
275     frontendClient()->setTimelineProfilingEnabled(enabled);
276     return S_OK;
277 }
278
279 #endif // ENABLE(INSPECTOR)