|
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 |
|
42 WebInspector* WebInspector::createInstance(WebView* webView) |
|
43 { |
|
44 WebInspector* inspector = new WebInspector(webView); |
|
45 inspector->AddRef(); |
|
46 return inspector; |
|
47 } |
|
48 |
|
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 |
|
59 WebInspector::~WebInspector() |
|
60 { |
|
61 gClassCount--; |
|
62 gClassNameCount.remove("WebInspector"); |
|
63 } |
|
64 |
|
65 void WebInspector::webViewClosed() |
|
66 { |
|
67 m_webView = 0; |
|
68 } |
|
69 |
|
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_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; |
|
81 |
|
82 AddRef(); |
|
83 return S_OK; |
|
84 } |
|
85 |
|
86 ULONG STDMETHODCALLTYPE WebInspector::AddRef(void) |
|
87 { |
|
88 return ++m_refCount; |
|
89 } |
|
90 |
|
91 ULONG STDMETHODCALLTYPE WebInspector::Release(void) |
|
92 { |
|
93 ULONG newRef = --m_refCount; |
|
94 if (!newRef) |
|
95 delete this; |
|
96 |
|
97 return newRef; |
|
98 } |
|
99 |
|
100 HRESULT STDMETHODCALLTYPE WebInspector::show() |
|
101 { |
|
102 if (m_webView) |
|
103 if (Page* page = m_webView->page()) |
|
104 page->inspectorController()->show(); |
|
105 |
|
106 return S_OK; |
|
107 } |
|
108 |
|
109 HRESULT STDMETHODCALLTYPE WebInspector::showConsole() |
|
110 { |
|
111 if (m_webView) |
|
112 if (Page* page = m_webView->page()) |
|
113 page->inspectorController()->showPanel(InspectorController::ConsolePanel); |
|
114 |
|
115 return S_OK; |
|
116 } |
|
117 |
|
118 HRESULT STDMETHODCALLTYPE WebInspector::unused1() |
|
119 { |
|
120 return S_OK; |
|
121 } |
|
122 |
|
123 HRESULT STDMETHODCALLTYPE WebInspector::close() |
|
124 { |
|
125 if (m_webView) |
|
126 if (Page* page = m_webView->page()) |
|
127 page->inspectorController()->close(); |
|
128 |
|
129 return S_OK; |
|
130 } |
|
131 |
|
132 HRESULT STDMETHODCALLTYPE WebInspector::attach() |
|
133 { |
|
134 return S_OK; |
|
135 } |
|
136 |
|
137 HRESULT STDMETHODCALLTYPE WebInspector::detach() |
|
138 { |
|
139 return S_OK; |
|
140 } |
|
141 |
|
142 HRESULT STDMETHODCALLTYPE WebInspector::isDebuggingJavaScript(BOOL* isDebugging) |
|
143 { |
|
144 if (!isDebugging) |
|
145 return E_POINTER; |
|
146 |
|
147 *isDebugging = FALSE; |
|
148 |
|
149 if (!m_webView) |
|
150 return S_OK; |
|
151 |
|
152 Page* page = m_webView->page(); |
|
153 if (!page) |
|
154 return S_OK; |
|
155 |
|
156 *isDebugging = page->inspectorController()->debuggerEnabled(); |
|
157 return S_OK; |
|
158 } |
|
159 |
|
160 HRESULT STDMETHODCALLTYPE WebInspector::toggleDebuggingJavaScript() |
|
161 { |
|
162 if (!m_webView) |
|
163 return S_OK; |
|
164 |
|
165 Page* page = m_webView->page(); |
|
166 if (!page) |
|
167 return S_OK; |
|
168 |
|
169 InspectorController* inspector = page->inspectorController(); |
|
170 |
|
171 if (inspector->debuggerEnabled()) |
|
172 inspector->disableDebugger(); |
|
173 else { |
|
174 inspector->showPanel(InspectorController::ScriptsPanel); |
|
175 inspector->enableDebugger(); |
|
176 } |
|
177 |
|
178 return S_OK; |
|
179 } |
|
180 |
|
181 HRESULT STDMETHODCALLTYPE WebInspector::isProfilingJavaScript(BOOL* isProfiling) |
|
182 { |
|
183 if (!isProfiling) |
|
184 return E_POINTER; |
|
185 |
|
186 *isProfiling = FALSE; |
|
187 |
|
188 if (!m_webView) |
|
189 return S_OK; |
|
190 |
|
191 Page* page = m_webView->page(); |
|
192 if (!page) |
|
193 return S_OK; |
|
194 |
|
195 *isProfiling = page->inspectorController()->isRecordingUserInitiatedProfile(); |
|
196 return S_OK; |
|
197 } |
|
198 |
|
199 HRESULT STDMETHODCALLTYPE WebInspector::toggleProfilingJavaScript() |
|
200 { |
|
201 if (!m_webView) |
|
202 return S_OK; |
|
203 |
|
204 Page* page = m_webView->page(); |
|
205 if (!page) |
|
206 return S_OK; |
|
207 |
|
208 InspectorController* inspector = page->inspectorController(); |
|
209 |
|
210 if (inspector->isRecordingUserInitiatedProfile()) { |
|
211 inspector->stopUserInitiatedProfiling(); |
|
212 inspector->showPanel(InspectorController::ProfilesPanel); |
|
213 } else |
|
214 inspector->startUserInitiatedProfiling(); |
|
215 |
|
216 return S_OK; |
|
217 } |
|
218 |
|
219 HRESULT STDMETHODCALLTYPE WebInspector::isJavaScriptProfilingEnabled(BOOL* isProfilingEnabled) |
|
220 { |
|
221 if (!isProfilingEnabled) |
|
222 return E_POINTER; |
|
223 |
|
224 *isProfilingEnabled = FALSE; |
|
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 *isProfilingEnabled = page->inspectorController()->profilerEnabled(); |
|
234 return S_OK; |
|
235 } |
|
236 |
|
237 HRESULT STDMETHODCALLTYPE WebInspector::setJavaScriptProfilingEnabled(BOOL enabled) |
|
238 { |
|
239 if (!m_webView) |
|
240 return S_OK; |
|
241 |
|
242 Page* page = m_webView->page(); |
|
243 if (!page) |
|
244 return S_OK; |
|
245 |
|
246 if (enabled) |
|
247 page->inspectorController()->enableProfiler(); |
|
248 else |
|
249 page->inspectorController()->disableProfiler(); |
|
250 |
|
251 return S_OK; |
|
252 } |
|
253 |
|
254 HRESULT STDMETHODCALLTYPE WebInspector::evaluateInFrontend(ULONG callId, BSTR bScript) |
|
255 { |
|
256 if (!m_webView) |
|
257 return S_OK; |
|
258 |
|
259 Page* page = m_webView->page(); |
|
260 if (!page) |
|
261 return S_OK; |
|
262 |
|
263 String script(bScript, SysStringLen(bScript)); |
|
264 page->inspectorController()->evaluateForTestInFrontend(callId, script); |
|
265 return S_OK; |
|
266 } |
|
267 |
|
268 HRESULT STDMETHODCALLTYPE WebInspector::isTimelineProfilingEnabled(BOOL* isEnabled) |
|
269 { |
|
270 if (!isEnabled) |
|
271 return E_POINTER; |
|
272 |
|
273 *isEnabled = FALSE; |
|
274 |
|
275 if (!m_webView) |
|
276 return S_OK; |
|
277 |
|
278 Page* page = m_webView->page(); |
|
279 if (!page) |
|
280 return S_OK; |
|
281 |
|
282 *isEnabled = page->inspectorController()->timelineAgent() != 0; |
|
283 return S_OK; |
|
284 } |
|
285 |
|
286 HRESULT STDMETHODCALLTYPE WebInspector::setTimelineProfilingEnabled(BOOL enabled) |
|
287 { |
|
288 if (!m_webView) |
|
289 return S_OK; |
|
290 |
|
291 Page* page = m_webView->page(); |
|
292 if (!page) |
|
293 return S_OK; |
|
294 |
|
295 if (enabled) |
|
296 page->inspectorController()->startTimelineProfiler(); |
|
297 else |
|
298 page->inspectorController()->stopTimelineProfiler(); |
|
299 |
|
300 return S_OK; |
|
301 } |