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
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.
30 #include "WebInspector.h"
34 #include "WebInspectorClient.h"
35 #include "WebKitDLL.h"
37 #include <WebCore/InspectorController.h>
38 #include <WebCore/Page.h>
39 #include <wtf/Assertions.h>
41 using namespace WebCore;
43 WebInspector* WebInspector::createInstance(WebView* webView, WebInspectorClient* inspectorClient)
45 WebInspector* inspector = new WebInspector(webView, inspectorClient);
50 WebInspector::WebInspector(WebView* webView, WebInspectorClient* inspectorClient)
53 , m_inspectorClient(inspectorClient)
55 ASSERT_ARG(webView, webView);
58 gClassNameCount.add("WebInspector");
61 WebInspector::~WebInspector()
64 gClassNameCount.remove("WebInspector");
67 WebInspectorFrontendClient* WebInspector::frontendClient()
69 return m_inspectorClient ? m_inspectorClient->frontendClient() : 0;
72 void WebInspector::webViewClosed()
75 m_inspectorClient = 0;
78 HRESULT STDMETHODCALLTYPE WebInspector::QueryInterface(REFIID riid, void** ppvObject)
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);
94 ULONG STDMETHODCALLTYPE WebInspector::AddRef(void)
99 ULONG STDMETHODCALLTYPE WebInspector::Release(void)
101 ULONG newRef = --m_refCount;
108 HRESULT STDMETHODCALLTYPE WebInspector::show()
111 if (Page* page = m_webView->page())
112 page->inspectorController()->show();
117 HRESULT STDMETHODCALLTYPE WebInspector::showConsole()
119 if (frontendClient())
120 frontendClient()->showConsole();
125 HRESULT STDMETHODCALLTYPE WebInspector::unused1()
130 HRESULT STDMETHODCALLTYPE WebInspector::close()
133 if (Page* page = m_webView->page())
134 page->inspectorController()->close();
139 HRESULT STDMETHODCALLTYPE WebInspector::attach()
144 HRESULT STDMETHODCALLTYPE WebInspector::detach()
149 HRESULT STDMETHODCALLTYPE WebInspector::isDebuggingJavaScript(BOOL* isDebugging)
154 *isDebugging = FALSE;
156 if (!frontendClient())
159 *isDebugging = frontendClient()->isDebuggingEnabled();
163 HRESULT STDMETHODCALLTYPE WebInspector::toggleDebuggingJavaScript()
167 if (!frontendClient())
170 if (frontendClient()->isDebuggingEnabled())
171 frontendClient()->setDebuggingEnabled(false);
173 frontendClient()->setDebuggingEnabled(true);
178 HRESULT STDMETHODCALLTYPE WebInspector::isProfilingJavaScript(BOOL* isProfiling)
183 *isProfiling = FALSE;
185 if (!frontendClient())
188 *isProfiling = frontendClient()->isProfilingJavaScript();
193 HRESULT STDMETHODCALLTYPE WebInspector::toggleProfilingJavaScript()
197 if (!frontendClient())
200 if (frontendClient()->isProfilingJavaScript())
201 frontendClient()->stopProfilingJavaScript();
203 frontendClient()->startProfilingJavaScript();
208 HRESULT STDMETHODCALLTYPE WebInspector::isJavaScriptProfilingEnabled(BOOL* isProfilingEnabled)
210 if (!isProfilingEnabled)
213 *isProfilingEnabled = FALSE;
218 Page* page = m_webView->page();
222 *isProfilingEnabled = page->inspectorController()->profilerEnabled();
226 HRESULT STDMETHODCALLTYPE WebInspector::setJavaScriptProfilingEnabled(BOOL enabled)
231 Page* page = m_webView->page();
235 page->inspectorController()->setProfilerEnabled(enabled);
240 HRESULT STDMETHODCALLTYPE WebInspector::evaluateInFrontend(ULONG callId, BSTR bScript)
245 Page* page = m_webView->page();
249 String script(bScript, SysStringLen(bScript));
250 page->inspectorController()->evaluateForTestInFrontend(callId, script);
254 HRESULT STDMETHODCALLTYPE WebInspector::isTimelineProfilingEnabled(BOOL* isEnabled)
261 if (!frontendClient())
264 *isEnabled = frontendClient()->isTimelineProfilingEnabled();
268 HRESULT STDMETHODCALLTYPE WebInspector::setTimelineProfilingEnabled(BOOL enabled)
272 if (!frontendClient())
275 frontendClient()->setTimelineProfilingEnabled(enabled);
279 #endif // ENABLE(INSPECTOR)