1/*
2 * Copyright (C) 2009 Google 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 are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "config.h"
32#include "web/InspectorClientImpl.h"
33
34#include "core/frame/LocalDOMWindow.h"
35#include "core/frame/LocalFrame.h"
36#include "core/frame/Settings.h"
37#include "core/inspector/InspectorInstrumentation.h"
38#include "core/page/Page.h"
39#include "platform/JSONValues.h"
40#include "platform/geometry/FloatRect.h"
41#include "public/platform/WebRect.h"
42#include "public/platform/WebURL.h"
43#include "public/platform/WebURLRequest.h"
44#include "public/web/WebViewClient.h"
45#include "web/WebDevToolsAgentImpl.h"
46#include "web/WebViewImpl.h"
47
48namespace blink {
49
50InspectorClientImpl::InspectorClientImpl(WebViewImpl* webView)
51    : m_inspectedWebView(webView)
52{
53    ASSERT(m_inspectedWebView);
54}
55
56InspectorClientImpl::~InspectorClientImpl()
57{
58}
59
60void InspectorClientImpl::highlight()
61{
62    if (WebDevToolsAgentImpl* agent = devToolsAgent())
63        agent->highlight();
64}
65
66void InspectorClientImpl::hideHighlight()
67{
68    if (WebDevToolsAgentImpl* agent = devToolsAgent())
69        agent->hideHighlight();
70}
71
72void InspectorClientImpl::sendMessageToFrontend(PassRefPtr<JSONObject> message)
73{
74    if (WebDevToolsAgentImpl* agent = devToolsAgent())
75        agent->sendMessageToFrontend(message);
76}
77
78void InspectorClientImpl::flush()
79{
80    if (WebDevToolsAgentImpl* agent = devToolsAgent())
81        agent->flush();
82}
83
84void InspectorClientImpl::updateInspectorStateCookie(const WTF::String& inspectorState)
85{
86    if (WebDevToolsAgentImpl* agent = devToolsAgent())
87        agent->updateInspectorStateCookie(inspectorState);
88}
89
90void InspectorClientImpl::setDeviceMetricsOverride(int width, int height, float deviceScaleFactor, bool mobile, bool fitWindow, float scale, float offsetX, float offsetY)
91{
92    if (WebDevToolsAgentImpl* agent = devToolsAgent())
93        agent->setDeviceMetricsOverride(width, height, deviceScaleFactor, mobile, fitWindow, scale, offsetX, offsetY);
94}
95
96void InspectorClientImpl::clearDeviceMetricsOverride()
97{
98    if (WebDevToolsAgentImpl* agent = devToolsAgent())
99        agent->clearDeviceMetricsOverride();
100}
101
102void InspectorClientImpl::setTouchEventEmulationEnabled(bool enabled)
103{
104    if (WebDevToolsAgentImpl* agent = devToolsAgent())
105        agent->setTouchEventEmulationEnabled(enabled);
106}
107
108bool InspectorClientImpl::overridesShowPaintRects()
109{
110    return m_inspectedWebView->isAcceleratedCompositingActive();
111}
112
113void InspectorClientImpl::setShowPaintRects(bool show)
114{
115    m_inspectedWebView->setShowPaintRects(show);
116}
117
118void InspectorClientImpl::setShowDebugBorders(bool show)
119{
120    m_inspectedWebView->setShowDebugBorders(show);
121}
122
123void InspectorClientImpl::setShowFPSCounter(bool show)
124{
125    m_inspectedWebView->setShowFPSCounter(show);
126}
127
128void InspectorClientImpl::setContinuousPaintingEnabled(bool enabled)
129{
130    m_inspectedWebView->setContinuousPaintingEnabled(enabled);
131}
132
133void InspectorClientImpl::setShowScrollBottleneckRects(bool show)
134{
135    m_inspectedWebView->setShowScrollBottleneckRects(show);
136}
137
138void InspectorClientImpl::resetScrollAndPageScaleFactor()
139{
140    m_inspectedWebView->resetScrollAndScaleState();
141}
142
143float InspectorClientImpl::minimumPageScaleFactor()
144{
145    return m_inspectedWebView->minimumPageScaleFactor();
146}
147
148float InspectorClientImpl::maximumPageScaleFactor()
149{
150    return m_inspectedWebView->maximumPageScaleFactor();
151}
152
153void InspectorClientImpl::setPageScaleFactor(float pageScaleFactor)
154{
155    m_inspectedWebView->setPageScaleFactor(pageScaleFactor);
156}
157
158void InspectorClientImpl::showContextMenu(float x, float y, PassRefPtr<ContextMenuProvider> menuProvider)
159{
160    m_inspectedWebView->showContextMenuAtPoint(x, y, menuProvider);
161}
162
163void InspectorClientImpl::dispatchKeyEvent(const PlatformKeyboardEvent& event)
164{
165    if (WebDevToolsAgentImpl* agent = devToolsAgent())
166        agent->dispatchKeyEvent(event);
167}
168
169void InspectorClientImpl::dispatchMouseEvent(const PlatformMouseEvent& event)
170{
171    if (WebDevToolsAgentImpl* agent = devToolsAgent())
172        agent->dispatchMouseEvent(event);
173}
174
175void InspectorClientImpl::setTraceEventCallback(const String& categoryFilter, TraceEventCallback callback)
176{
177    if (WebDevToolsAgentImpl* agent = devToolsAgent())
178        agent->setTraceEventCallback(categoryFilter, callback);
179}
180
181void InspectorClientImpl::enableTracing(const String& categoryFilter)
182{
183    if (WebDevToolsAgentImpl* agent = devToolsAgent())
184        agent->enableTracing(categoryFilter);
185}
186
187void InspectorClientImpl::disableTracing()
188{
189    if (WebDevToolsAgentImpl* agent = devToolsAgent())
190        agent->disableTracing();
191}
192
193void InspectorClientImpl::resetTraceEventCallback()
194{
195    if (WebDevToolsAgentImpl* agent = devToolsAgent())
196        agent->resetTraceEventCallback();
197}
198
199void InspectorClientImpl::startGPUEventsRecording()
200{
201    if (WebDevToolsAgentImpl* agent = devToolsAgent())
202        agent->startGPUEventsRecording();
203}
204
205void InspectorClientImpl::stopGPUEventsRecording()
206{
207    if (WebDevToolsAgentImpl* agent = devToolsAgent())
208        agent->stopGPUEventsRecording();
209}
210
211void InspectorClientImpl::resumeStartup()
212{
213    if (WebDevToolsAgentImpl* agent = devToolsAgent())
214        agent->resumeStartup();
215}
216
217WebDevToolsAgentImpl* InspectorClientImpl::devToolsAgent()
218{
219    return static_cast<WebDevToolsAgentImpl*>(m_inspectedWebView->devToolsAgent());
220}
221
222} // namespace blink
223