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"
32 #include "WebInspectorClient.h"
33 #include "WebKitDLL.h"
35 #include <WebCore/InspectorController.h>
36 #include <WebCore/Page.h>
37 #include <wtf/Assertions.h>
39 using namespace WebCore;
41 WebInspector* WebInspector::createInstance(WebView* webView, WebInspectorClient* inspectorClient)
43 WebInspector* inspector = new WebInspector(webView, inspectorClient);
48 WebInspector::WebInspector(WebView* webView, WebInspectorClient* inspectorClient)
51 , m_inspectorClient(inspectorClient)
53 ASSERT_ARG(webView, webView);
56 gClassNameCount.add("WebInspector");
59 WebInspector::~WebInspector()
62 gClassNameCount.remove("WebInspector");
65 WebInspectorFrontendClient* WebInspector::frontendClient()
67 return m_inspectorClient ? m_inspectorClient->frontendClient() : 0;
70 void WebInspector::webViewClosed()
73 m_inspectorClient = 0;
76 HRESULT STDMETHODCALLTYPE WebInspector::QueryInterface(REFIID riid, void** ppvObject)
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);
92 ULONG STDMETHODCALLTYPE WebInspector::AddRef(void)
97 ULONG STDMETHODCALLTYPE WebInspector::Release(void)
99 ULONG newRef = --m_refCount;
106 HRESULT STDMETHODCALLTYPE WebInspector::show()
109 if (Page* page = m_webView->page())
110 page->inspectorController()->show();
115 HRESULT STDMETHODCALLTYPE WebInspector::showConsole()
117 if (frontendClient())
118 frontendClient()->showConsole();
123 HRESULT STDMETHODCALLTYPE WebInspector::unused1()
128 HRESULT STDMETHODCALLTYPE WebInspector::close()
131 if (Page* page = m_webView->page())
132 page->inspectorController()->close();
137 HRESULT STDMETHODCALLTYPE WebInspector::attach()
142 HRESULT STDMETHODCALLTYPE WebInspector::detach()
147 HRESULT STDMETHODCALLTYPE WebInspector::isDebuggingJavaScript(BOOL* isDebugging)
152 *isDebugging = FALSE;
154 if (!frontendClient())
157 *isDebugging = frontendClient()->isDebuggingEnabled();
161 HRESULT STDMETHODCALLTYPE WebInspector::toggleDebuggingJavaScript()
165 if (!frontendClient())
168 if (frontendClient()->isDebuggingEnabled())
169 frontendClient()->setDebuggingEnabled(false);
171 frontendClient()->setDebuggingEnabled(true);
176 HRESULT STDMETHODCALLTYPE WebInspector::isProfilingJavaScript(BOOL* isProfiling)
181 *isProfiling = FALSE;
183 if (!frontendClient())
186 *isProfiling = frontendClient()->isProfilingJavaScript();
191 HRESULT STDMETHODCALLTYPE WebInspector::toggleProfilingJavaScript()
195 if (!frontendClient())
198 if (frontendClient()->isProfilingJavaScript())
199 frontendClient()->stopProfilingJavaScript();
201 frontendClient()->startProfilingJavaScript();
206 HRESULT STDMETHODCALLTYPE WebInspector::isJavaScriptProfilingEnabled(BOOL* isProfilingEnabled)
208 if (!isProfilingEnabled)
211 *isProfilingEnabled = FALSE;
216 Page* page = m_webView->page();
220 *isProfilingEnabled = page->inspectorController()->profilerEnabled();
224 HRESULT STDMETHODCALLTYPE WebInspector::setJavaScriptProfilingEnabled(BOOL enabled)
229 Page* page = m_webView->page();
234 page->inspectorController()->enableProfiler();
236 page->inspectorController()->disableProfiler();
241 HRESULT STDMETHODCALLTYPE WebInspector::evaluateInFrontend(ULONG callId, BSTR bScript)
246 Page* page = m_webView->page();
250 String script(bScript, SysStringLen(bScript));
251 page->inspectorController()->evaluateForTestInFrontend(callId, script);
255 HRESULT STDMETHODCALLTYPE WebInspector::isTimelineProfilingEnabled(BOOL* isEnabled)
262 if (!frontendClient())
265 *isEnabled = frontendClient()->isTimelineProfilingEnabled();
269 HRESULT STDMETHODCALLTYPE WebInspector::setTimelineProfilingEnabled(BOOL enabled)
273 if (!frontendClient())
276 frontendClient()->setTimelineProfilingEnabled(enabled);