tizen beta release
[profile/ivi/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 #include "WebInspectorClient.h"
33 #include "WebKitDLL.h"
34 #include "WebView.h"
35 #include <WebCore/InspectorController.h>
36 #include <WebCore/Page.h>
37 #include <wtf/Assertions.h>
38
39 using namespace WebCore;
40
41 WebInspector* WebInspector::createInstance(WebView* webView, WebInspectorClient* inspectorClient)
42 {
43     WebInspector* inspector = new WebInspector(webView, inspectorClient);
44     inspector->AddRef();
45     return inspector;
46 }
47
48 WebInspector::WebInspector(WebView* webView, WebInspectorClient* inspectorClient)
49     : m_refCount(0)
50     , m_webView(webView)
51     , m_inspectorClient(inspectorClient)
52 {
53     ASSERT_ARG(webView, webView);
54
55     gClassCount++;
56     gClassNameCount.add("WebInspector");
57 }
58
59 WebInspector::~WebInspector()
60 {
61     gClassCount--;
62     gClassNameCount.remove("WebInspector");
63 }
64
65 WebInspectorFrontendClient* WebInspector::frontendClient()
66 {
67     return m_inspectorClient ? m_inspectorClient->frontendClient() : 0;
68 }
69
70 void WebInspector::webViewClosed()
71 {
72     m_webView = 0;
73     m_inspectorClient = 0;
74 }
75
76 HRESULT STDMETHODCALLTYPE WebInspector::QueryInterface(REFIID riid, void** ppvObject)
77 {
78     *ppvObject = 0;
79     if (IsEqualGUID(riid, IID_IWebInspector))
80         *ppvObject = static_cast<IWebInspector*>(this);
81     else if (IsEqualGUID(riid, IID_IWebInspectorPrivate))
82         *ppvObject = static_cast<IWebInspectorPrivate*>(this);
83     else if (IsEqualGUID(riid, IID_IUnknown))
84         *ppvObject = static_cast<IWebInspector*>(this);
85     else
86         return E_NOINTERFACE;
87
88     AddRef();
89     return S_OK;
90 }
91
92 ULONG STDMETHODCALLTYPE WebInspector::AddRef(void)
93 {
94     return ++m_refCount;
95 }
96
97 ULONG STDMETHODCALLTYPE WebInspector::Release(void)
98 {
99     ULONG newRef = --m_refCount;
100     if (!newRef)
101         delete this;
102
103     return newRef;
104 }
105
106 HRESULT STDMETHODCALLTYPE WebInspector::show()
107 {
108     if (m_webView)
109         if (Page* page = m_webView->page())
110             page->inspectorController()->show();
111
112     return S_OK;
113 }
114
115 HRESULT STDMETHODCALLTYPE WebInspector::showConsole()
116 {
117     if (frontendClient())
118         frontendClient()->showConsole();
119
120     return S_OK;
121 }
122
123 HRESULT STDMETHODCALLTYPE WebInspector::unused1()
124 {
125     return S_OK;
126 }
127
128 HRESULT STDMETHODCALLTYPE WebInspector::close()
129 {
130     if (m_webView)
131         if (Page* page = m_webView->page())
132             page->inspectorController()->close();
133
134     return S_OK;
135 }
136
137 HRESULT STDMETHODCALLTYPE WebInspector::attach()
138 {
139     return S_OK;
140 }
141
142 HRESULT STDMETHODCALLTYPE WebInspector::detach()
143 {
144     return S_OK;
145 }
146
147 HRESULT STDMETHODCALLTYPE WebInspector::isDebuggingJavaScript(BOOL* isDebugging)
148 {
149     if (!isDebugging)
150         return E_POINTER;
151
152     *isDebugging = FALSE;
153
154     if (!frontendClient())
155         return S_OK;
156
157     *isDebugging = frontendClient()->isDebuggingEnabled();
158     return S_OK;
159 }
160
161 HRESULT STDMETHODCALLTYPE WebInspector::toggleDebuggingJavaScript()
162 {
163     show();
164
165     if (!frontendClient())
166         return S_OK;
167
168     if (frontendClient()->isDebuggingEnabled())
169         frontendClient()->setDebuggingEnabled(false);
170     else
171         frontendClient()->setDebuggingEnabled(true);
172
173     return S_OK;
174 }
175
176 HRESULT STDMETHODCALLTYPE WebInspector::isProfilingJavaScript(BOOL* isProfiling)
177 {
178     if (!isProfiling)
179         return E_POINTER;
180
181     *isProfiling = FALSE;
182
183     if (!frontendClient())
184         return S_OK;
185
186     *isProfiling = frontendClient()->isProfilingJavaScript();
187
188     return S_OK;
189 }
190
191 HRESULT STDMETHODCALLTYPE WebInspector::toggleProfilingJavaScript()
192 {
193     show();
194
195     if (!frontendClient())
196         return S_OK;
197
198     if (frontendClient()->isProfilingJavaScript())
199         frontendClient()->stopProfilingJavaScript();
200     else
201         frontendClient()->startProfilingJavaScript();
202
203     return S_OK;
204 }
205
206 HRESULT STDMETHODCALLTYPE WebInspector::isJavaScriptProfilingEnabled(BOOL* isProfilingEnabled)
207 {
208     if (!isProfilingEnabled)
209         return E_POINTER;
210
211     *isProfilingEnabled = FALSE;
212
213     if (!m_webView)
214         return S_OK;
215
216     Page* page = m_webView->page();
217     if (!page)
218         return S_OK;
219
220     *isProfilingEnabled = page->inspectorController()->profilerEnabled();
221     return S_OK;
222 }
223
224 HRESULT STDMETHODCALLTYPE WebInspector::setJavaScriptProfilingEnabled(BOOL enabled)
225 {
226     if (!m_webView)
227         return S_OK;
228
229     Page* page = m_webView->page();
230     if (!page)
231         return S_OK;
232
233     if (enabled)
234         page->inspectorController()->enableProfiler();
235     else
236         page->inspectorController()->disableProfiler();
237
238     return S_OK;
239 }
240
241 HRESULT STDMETHODCALLTYPE  WebInspector::evaluateInFrontend(ULONG callId, BSTR bScript)
242 {
243     if (!m_webView)
244         return S_OK;
245
246     Page* page = m_webView->page();
247     if (!page)
248         return S_OK;
249
250     String script(bScript, SysStringLen(bScript));
251     page->inspectorController()->evaluateForTestInFrontend(callId, script);
252     return S_OK;
253 }
254
255 HRESULT STDMETHODCALLTYPE WebInspector::isTimelineProfilingEnabled(BOOL* isEnabled)
256 {
257     if (!isEnabled)
258         return E_POINTER;
259
260     *isEnabled = FALSE;
261
262     if (!frontendClient())
263         return S_OK;
264
265     *isEnabled = frontendClient()->isTimelineProfilingEnabled();
266     return S_OK;
267 }
268
269 HRESULT STDMETHODCALLTYPE WebInspector::setTimelineProfilingEnabled(BOOL enabled)
270 {
271     show();
272
273     if (!frontendClient())
274         return S_OK;
275
276     frontendClient()->setTimelineProfilingEnabled(enabled);
277     return S_OK;
278 }