Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebKit / win / WebInspector.cpp
blobe4ac32ba29420df5d918129f559c894f65cf052f
1 /*
2 * Copyright (C) 2007 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
6 * are met:
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.
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.
29 #include "config.h"
30 #include "WebInspector.h"
32 #include "WebKitDLL.h"
33 #include "WebView.h"
34 #pragma warning(push, 0)
35 #include <WebCore/InspectorController.h>
36 #include <WebCore/Page.h>
37 #pragma warning(pop)
38 #include <wtf/Assertions.h>
40 using namespace WebCore;
42 WebInspector* WebInspector::createInstance(WebView* webView)
44 WebInspector* inspector = new WebInspector(webView);
45 inspector->AddRef();
46 return inspector;
49 WebInspector::WebInspector(WebView* webView)
50 : m_refCount(0)
51 , m_webView(webView)
53 ASSERT_ARG(webView, webView);
55 gClassCount++;
56 gClassNameCount.add("WebInspector");
59 WebInspector::~WebInspector()
61 gClassCount--;
62 gClassNameCount.remove("WebInspector");
65 void WebInspector::webViewClosed()
67 m_webView = 0;
70 HRESULT STDMETHODCALLTYPE WebInspector::QueryInterface(REFIID riid, void** ppvObject)
72 *ppvObject = 0;
73 if (IsEqualGUID(riid, IID_IWebInspector))
74 *ppvObject = static_cast<IWebInspector*>(this);
75 else if (IsEqualGUID(riid, IID_IWebInspectorPrivate))
76 *ppvObject = static_cast<IWebInspectorPrivate*>(this);
77 else if (IsEqualGUID(riid, IID_IUnknown))
78 *ppvObject = static_cast<IWebInspector*>(this);
79 else
80 return E_NOINTERFACE;
82 AddRef();
83 return S_OK;
86 ULONG STDMETHODCALLTYPE WebInspector::AddRef(void)
88 return ++m_refCount;
91 ULONG STDMETHODCALLTYPE WebInspector::Release(void)
93 ULONG newRef = --m_refCount;
94 if (!newRef)
95 delete this;
97 return newRef;
100 HRESULT STDMETHODCALLTYPE WebInspector::show()
102 if (m_webView)
103 if (Page* page = m_webView->page())
104 page->inspectorController()->show();
106 return S_OK;
109 HRESULT STDMETHODCALLTYPE WebInspector::showConsole()
111 if (m_webView)
112 if (Page* page = m_webView->page())
113 page->inspectorController()->showPanel(InspectorController::ConsolePanel);
115 return S_OK;
118 HRESULT STDMETHODCALLTYPE WebInspector::unused1()
120 return S_OK;
123 HRESULT STDMETHODCALLTYPE WebInspector::close()
125 if (m_webView)
126 if (Page* page = m_webView->page())
127 page->inspectorController()->close();
129 return S_OK;
132 HRESULT STDMETHODCALLTYPE WebInspector::attach()
134 if (m_webView)
135 if (Page* page = m_webView->page())
136 page->inspectorController()->attachWindow();
138 return S_OK;
141 HRESULT STDMETHODCALLTYPE WebInspector::detach()
143 if (m_webView)
144 if (Page* page = m_webView->page())
145 page->inspectorController()->detachWindow();
147 return S_OK;
150 HRESULT STDMETHODCALLTYPE WebInspector::isDebuggingJavaScript(BOOL* isDebugging)
152 if (!isDebugging)
153 return E_POINTER;
155 *isDebugging = FALSE;
157 if (!m_webView)
158 return S_OK;
160 Page* page = m_webView->page();
161 if (!page)
162 return S_OK;
164 *isDebugging = page->inspectorController()->debuggerEnabled();
165 return S_OK;
168 HRESULT STDMETHODCALLTYPE WebInspector::toggleDebuggingJavaScript()
170 if (!m_webView)
171 return S_OK;
173 Page* page = m_webView->page();
174 if (!page)
175 return S_OK;
177 InspectorController* inspector = page->inspectorController();
179 if (inspector->debuggerEnabled())
180 inspector->disableDebugger();
181 else {
182 inspector->showPanel(InspectorController::ScriptsPanel);
183 inspector->enableDebugger();
186 return S_OK;
189 HRESULT STDMETHODCALLTYPE WebInspector::isProfilingJavaScript(BOOL* isProfiling)
191 if (!isProfiling)
192 return E_POINTER;
194 *isProfiling = FALSE;
196 if (!m_webView)
197 return S_OK;
199 Page* page = m_webView->page();
200 if (!page)
201 return S_OK;
203 *isProfiling = page->inspectorController()->isRecordingUserInitiatedProfile();
204 return S_OK;
207 HRESULT STDMETHODCALLTYPE WebInspector::toggleProfilingJavaScript()
209 if (!m_webView)
210 return S_OK;
212 Page* page = m_webView->page();
213 if (!page)
214 return S_OK;
216 InspectorController* inspector = page->inspectorController();
218 if (inspector->isRecordingUserInitiatedProfile()) {
219 inspector->stopUserInitiatedProfiling();
220 inspector->showPanel(InspectorController::ProfilesPanel);
221 } else
222 inspector->startUserInitiatedProfiling();
224 return S_OK;
227 HRESULT STDMETHODCALLTYPE WebInspector::isJavaScriptProfilingEnabled(BOOL* isProfilingEnabled)
229 if (!isProfilingEnabled)
230 return E_POINTER;
232 *isProfilingEnabled = FALSE;
234 if (!m_webView)
235 return S_OK;
237 Page* page = m_webView->page();
238 if (!page)
239 return S_OK;
241 *isProfilingEnabled = page->inspectorController()->profilerEnabled();
242 return S_OK;
245 HRESULT STDMETHODCALLTYPE WebInspector::setJavaScriptProfilingEnabled(BOOL enabled)
247 if (!m_webView)
248 return S_OK;
250 Page* page = m_webView->page();
251 if (!page)
252 return S_OK;
254 if (enabled)
255 page->inspectorController()->enableProfiler();
256 else
257 page->inspectorController()->disableProfiler();
259 return S_OK;
262 HRESULT STDMETHODCALLTYPE WebInspector::evaluateInFrontend(ULONG callId, BSTR bScript)
264 if (!m_webView)
265 return S_OK;
267 Page* page = m_webView->page();
268 if (!page)
269 return S_OK;
271 String script(bScript, SysStringLen(bScript));
272 page->inspectorController()->evaluateForTestInFrontend(callId, script);
273 return S_OK;
276 HRESULT STDMETHODCALLTYPE WebInspector::isTimelineProfilingEnabled(BOOL* isEnabled)
278 if (!isEnabled)
279 return E_POINTER;
281 *isEnabled = FALSE;
283 if (!m_webView)
284 return S_OK;
286 Page* page = m_webView->page();
287 if (!page)
288 return S_OK;
290 *isEnabled = page->inspectorController()->timelineAgent() != 0;
291 return S_OK;
294 HRESULT STDMETHODCALLTYPE WebInspector::setTimelineProfilingEnabled(BOOL enabled)
296 if (!m_webView)
297 return S_OK;
299 Page* page = m_webView->page();
300 if (!page)
301 return S_OK;
303 if (enabled)
304 page->inspectorController()->startTimelineProfiler();
305 else
306 page->inspectorController()->stopTimelineProfiler();
308 return S_OK;