• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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>
39 
40 using namespace WebCore;
41 
createInstance(WebView * webView)42 WebInspector* WebInspector::createInstance(WebView* webView)
43 {
44     WebInspector* inspector = new WebInspector(webView);
45     inspector->AddRef();
46     return inspector;
47 }
48 
WebInspector(WebView * webView)49 WebInspector::WebInspector(WebView* webView)
50     : m_refCount(0)
51     , m_webView(webView)
52 {
53     ASSERT_ARG(webView, webView);
54 
55     gClassCount++;
56     gClassNameCount.add("WebInspector");
57 }
58 
~WebInspector()59 WebInspector::~WebInspector()
60 {
61     gClassCount--;
62     gClassNameCount.remove("WebInspector");
63 }
64 
webViewClosed()65 void WebInspector::webViewClosed()
66 {
67     m_webView = 0;
68 }
69 
QueryInterface(REFIID riid,void ** ppvObject)70 HRESULT STDMETHODCALLTYPE WebInspector::QueryInterface(REFIID riid, void** ppvObject)
71 {
72     *ppvObject = 0;
73     if (IsEqualGUID(riid, IID_IWebInspector))
74         *ppvObject = static_cast<IWebInspector*>(this);
75     else if (IsEqualGUID(riid, IID_IUnknown))
76         *ppvObject = static_cast<IWebInspector*>(this);
77     else
78         return E_NOINTERFACE;
79 
80     AddRef();
81     return S_OK;
82 }
83 
AddRef(void)84 ULONG STDMETHODCALLTYPE WebInspector::AddRef(void)
85 {
86     return ++m_refCount;
87 }
88 
Release(void)89 ULONG STDMETHODCALLTYPE WebInspector::Release(void)
90 {
91     ULONG newRef = --m_refCount;
92     if (!newRef)
93         delete this;
94 
95     return newRef;
96 }
97 
show()98 HRESULT STDMETHODCALLTYPE WebInspector::show()
99 {
100     if (m_webView)
101         if (Page* page = m_webView->page())
102             page->inspectorController()->show();
103 
104     return S_OK;
105 }
106 
showConsole()107 HRESULT STDMETHODCALLTYPE WebInspector::showConsole()
108 {
109     if (m_webView)
110         if (Page* page = m_webView->page())
111             page->inspectorController()->showPanel(InspectorController::ConsolePanel);
112 
113     return S_OK;
114 }
115 
unused1()116 HRESULT STDMETHODCALLTYPE WebInspector::unused1()
117 {
118     return S_OK;
119 }
120 
close()121 HRESULT STDMETHODCALLTYPE WebInspector::close()
122 {
123     if (m_webView)
124         if (Page* page = m_webView->page())
125             page->inspectorController()->close();
126 
127     return S_OK;
128 }
129 
attach()130 HRESULT STDMETHODCALLTYPE WebInspector::attach()
131 {
132     if (m_webView)
133         if (Page* page = m_webView->page())
134             page->inspectorController()->attachWindow();
135 
136     return S_OK;
137 }
138 
detach()139 HRESULT STDMETHODCALLTYPE WebInspector::detach()
140 {
141     if (m_webView)
142         if (Page* page = m_webView->page())
143             page->inspectorController()->detachWindow();
144 
145     return S_OK;
146 }
147 
isDebuggingJavaScript(BOOL * isDebugging)148 HRESULT STDMETHODCALLTYPE WebInspector::isDebuggingJavaScript(BOOL* isDebugging)
149 {
150     if (!isDebugging)
151         return E_POINTER;
152 
153     *isDebugging = FALSE;
154 
155     if (!m_webView)
156         return S_OK;
157 
158     Page* page = m_webView->page();
159     if (!page)
160         return S_OK;
161 
162     *isDebugging = page->inspectorController()->debuggerEnabled();
163     return S_OK;
164 }
165 
toggleDebuggingJavaScript()166 HRESULT STDMETHODCALLTYPE WebInspector::toggleDebuggingJavaScript()
167 {
168     if (!m_webView)
169         return S_OK;
170 
171     Page* page = m_webView->page();
172     if (!page)
173         return S_OK;
174 
175     InspectorController* inspector = page->inspectorController();
176 
177     if (inspector->debuggerEnabled())
178         inspector->disableDebugger();
179     else {
180         inspector->showPanel(InspectorController::ScriptsPanel);
181         inspector->enableDebugger();
182     }
183 
184     return S_OK;
185 }
186 
isProfilingJavaScript(BOOL * isProfiling)187 HRESULT STDMETHODCALLTYPE WebInspector::isProfilingJavaScript(BOOL* isProfiling)
188 {
189     if (!isProfiling)
190         return E_POINTER;
191 
192     *isProfiling = FALSE;
193 
194     if (!m_webView)
195         return S_OK;
196 
197     Page* page = m_webView->page();
198     if (!page)
199         return S_OK;
200 
201     *isProfiling = page->inspectorController()->isRecordingUserInitiatedProfile();
202     return S_OK;
203 }
204 
toggleProfilingJavaScript()205 HRESULT STDMETHODCALLTYPE WebInspector::toggleProfilingJavaScript()
206 {
207     if (!m_webView)
208         return S_OK;
209 
210     Page* page = m_webView->page();
211     if (!page)
212         return S_OK;
213 
214     InspectorController* inspector = page->inspectorController();
215 
216     if (inspector->isRecordingUserInitiatedProfile()) {
217         inspector->stopUserInitiatedProfiling();
218         inspector->showPanel(InspectorController::ProfilesPanel);
219     } else
220         inspector->startUserInitiatedProfiling();
221 
222     return S_OK;
223 }
224 
isJavaScriptProfilingEnabled(BOOL * isProfilingEnabled)225 HRESULT STDMETHODCALLTYPE WebInspector::isJavaScriptProfilingEnabled(BOOL* isProfilingEnabled)
226 {
227     if (!isProfilingEnabled)
228         return E_POINTER;
229 
230     *isProfilingEnabled = FALSE;
231 
232     if (!m_webView)
233         return S_OK;
234 
235     Page* page = m_webView->page();
236     if (!page)
237         return S_OK;
238 
239     *isProfilingEnabled = page->inspectorController()->profilerEnabled();
240     return S_OK;
241 }
242 
setJavaScriptProfilingEnabled(BOOL enabled)243 HRESULT STDMETHODCALLTYPE WebInspector::setJavaScriptProfilingEnabled(BOOL enabled)
244 {
245     if (!m_webView)
246         return S_OK;
247 
248     Page* page = m_webView->page();
249     if (!page)
250         return S_OK;
251 
252     if (enabled)
253         page->inspectorController()->enableProfiler();
254     else
255         page->inspectorController()->disableProfiler();
256 
257     return S_OK;
258 }
259