Attempt to fix the Windows build after r195799
[WebKit-https.git] / Source / WebKit / win / WebInspector.cpp
1 /*
2  * Copyright (C) 2007, 2015 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 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 "WebInspector.h"
30
31 #include "WebInspectorClient.h"
32 #include "WebKitDLL.h"
33 #include "WebView.h"
34 #include <WebCore/InspectorController.h>
35 #include <WebCore/Page.h>
36 #include <wtf/Assertions.h>
37
38 using namespace WebCore;
39
40 WebInspector* WebInspector::createInstance(WebView* inspectedWebView, WebInspectorClient* inspectorClient)
41 {
42     WebInspector* inspector = new WebInspector(inspectedWebView, inspectorClient);
43     inspector->AddRef();
44     return inspector;
45 }
46
47 WebInspector::WebInspector(WebView* inspectedWebView, WebInspectorClient* inspectorClient)
48     : m_inspectedWebView(inspectedWebView)
49     , m_inspectorClient(inspectorClient)
50 {
51     ASSERT_ARG(inspectedWebView, inspectedWebView);
52
53     gClassCount++;
54     gClassNameCount().add("WebInspector");
55 }
56
57 WebInspector::~WebInspector()
58 {
59     gClassCount--;
60     gClassNameCount().remove("WebInspector");
61 }
62
63 WebInspectorFrontendClient* WebInspector::frontendClient()
64 {
65     return m_inspectorClient ? m_inspectorClient->frontendClient() : nullptr;
66 }
67
68 void WebInspector::inspectedWebViewClosed()
69 {
70     m_inspectedWebView = nullptr;
71     m_inspectorClient = nullptr;
72 }
73
74 HRESULT WebInspector::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
75 {
76     if (!ppvObject)
77         return E_POINTER;
78     *ppvObject = nullptr;
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);
85     else
86         return E_NOINTERFACE;
87
88     AddRef();
89     return S_OK;
90 }
91
92 ULONG WebInspector::AddRef()
93 {
94     return ++m_refCount;
95 }
96
97 ULONG WebInspector::Release()
98 {
99     ULONG newRef = --m_refCount;
100     if (!newRef)
101         delete this;
102
103     return newRef;
104 }
105
106 HRESULT WebInspector::show()
107 {
108     if (m_inspectedWebView)
109         if (Page* page = m_inspectedWebView->page())
110             page->inspectorController().show();
111
112     return S_OK;
113 }
114
115 HRESULT WebInspector::showConsole()
116 {
117     if (frontendClient())
118         frontendClient()->showConsole();
119
120     return S_OK;
121 }
122
123 HRESULT WebInspector::unused1()
124 {
125     return S_OK;
126 }
127
128 HRESULT WebInspector::close()
129 {
130     if (frontendClient())
131         frontendClient()->closeWindow();
132
133     return S_OK;
134 }
135
136 HRESULT WebInspector::attach()
137 {
138     return S_OK;
139 }
140
141 HRESULT WebInspector::detach()
142 {
143     return S_OK;
144 }
145
146 HRESULT WebInspector::isDebuggingJavaScript(_Out_ BOOL* isDebugging)
147 {
148     if (!isDebugging)
149         return E_POINTER;
150
151     *isDebugging = FALSE;
152
153     if (!frontendClient())
154         return S_OK;
155
156     *isDebugging = frontendClient()->isDebuggingEnabled();
157     return S_OK;
158 }
159
160 HRESULT WebInspector::toggleDebuggingJavaScript()
161 {
162     show();
163
164     if (!frontendClient())
165         return S_OK;
166
167     if (frontendClient()->isDebuggingEnabled())
168         frontendClient()->setDebuggingEnabled(false);
169     else
170         frontendClient()->setDebuggingEnabled(true);
171
172     return S_OK;
173 }
174
175 HRESULT WebInspector::isProfilingJavaScript(_Out_ BOOL* isProfiling)
176 {
177     if (!isProfiling)
178         return E_POINTER;
179
180     *isProfiling = FALSE;
181
182     if (!frontendClient())
183         return S_OK;
184
185     *isProfiling = frontendClient()->isProfilingJavaScript();
186
187     return S_OK;
188 }
189
190 HRESULT WebInspector::toggleProfilingJavaScript()
191 {
192     show();
193
194     if (!frontendClient())
195         return S_OK;
196
197     if (frontendClient()->isProfilingJavaScript())
198         frontendClient()->stopProfilingJavaScript();
199     else
200         frontendClient()->startProfilingJavaScript();
201
202     return S_OK;
203 }
204
205 HRESULT WebInspector::isJavaScriptProfilingEnabled(_Out_ BOOL* isProfilingEnabled)
206 {
207     if (!isProfilingEnabled)
208         return E_POINTER;
209
210     *isProfilingEnabled = FALSE;
211
212     if (!m_inspectedWebView)
213         return S_OK;
214
215     Page* inspectedPage = m_inspectedWebView->page();
216     if (!inspectedPage)
217         return S_OK;
218
219     *isProfilingEnabled = inspectedPage->inspectorController().legacyProfilerEnabled();
220     return S_OK;
221 }
222
223 HRESULT WebInspector::setJavaScriptProfilingEnabled(BOOL enabled)
224 {
225     if (!m_inspectedWebView)
226         return S_OK;
227
228     Page* inspectedPage = m_inspectedWebView->page();
229     if (!inspectedPage)
230         return S_OK;
231
232     inspectedPage->inspectorController().setLegacyProfilerEnabled(enabled);
233
234     return S_OK;
235 }
236
237 HRESULT WebInspector::evaluateInFrontend(_In_ BSTR bScript)
238 {
239     if (!m_inspectedWebView)
240         return S_OK;
241
242     Page* inspectedPage = m_inspectedWebView->page();
243     if (!inspectedPage)
244         return S_OK;
245
246     String script(bScript, SysStringLen(bScript));
247     inspectedPage->inspectorController().evaluateForTestInFrontend(script);
248     return S_OK;
249 }
250
251 HRESULT WebInspector::isTimelineProfilingEnabled(_Out_ BOOL* isEnabled)
252 {
253     if (!isEnabled)
254         return E_POINTER;
255
256     *isEnabled = FALSE;
257
258     if (!frontendClient())
259         return S_OK;
260
261     *isEnabled = frontendClient()->isTimelineProfilingEnabled();
262     return S_OK;
263 }
264
265 HRESULT WebInspector::setTimelineProfilingEnabled(BOOL enabled)
266 {
267     show();
268
269     if (!frontendClient())
270         return S_OK;
271
272     frontendClient()->setTimelineProfilingEnabled(enabled);
273     return S_OK;
274 }