Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 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 "InspectorClientImpl.h" |
| 33 | |
| 34 | #include "WebDevToolsAgentImpl.h" |
| 35 | #include "WebViewClient.h" |
| 36 | #include "WebViewImpl.h" |
| 37 | #include "core/inspector/InspectorInstrumentation.h" |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 38 | #include "core/frame/DOMWindow.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 39 | #include "core/page/Page.h" |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 40 | #include "core/frame/Settings.h" |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 41 | #include "platform/JSONValues.h" |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 42 | #include "platform/geometry/FloatRect.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 43 | #include "public/platform/WebRect.h" |
| 44 | #include "public/platform/WebURL.h" |
| 45 | #include "public/platform/WebURLRequest.h" |
| 46 | #include "wtf/Vector.h" |
| 47 | |
| 48 | using namespace WebCore; |
| 49 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 50 | namespace blink { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 51 | |
| 52 | InspectorClientImpl::InspectorClientImpl(WebViewImpl* webView) |
| 53 | : m_inspectedWebView(webView) |
| 54 | { |
| 55 | ASSERT(m_inspectedWebView); |
| 56 | } |
| 57 | |
| 58 | InspectorClientImpl::~InspectorClientImpl() |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | void InspectorClientImpl::highlight() |
| 63 | { |
| 64 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 65 | agent->highlight(); |
| 66 | } |
| 67 | |
| 68 | void InspectorClientImpl::hideHighlight() |
| 69 | { |
| 70 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 71 | agent->hideHighlight(); |
| 72 | } |
| 73 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 74 | void InspectorClientImpl::sendMessageToFrontend(PassRefPtr<WebCore::JSONObject> message) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 75 | { |
| 76 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 77 | agent->sendMessageToFrontend(message); |
| 78 | } |
| 79 | |
| 80 | void InspectorClientImpl::flush() |
| 81 | { |
| 82 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 83 | agent->flush(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void InspectorClientImpl::updateInspectorStateCookie(const WTF::String& inspectorState) |
| 87 | { |
| 88 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 89 | agent->updateInspectorStateCookie(inspectorState); |
| 90 | } |
| 91 | |
| 92 | void InspectorClientImpl::clearBrowserCache() |
| 93 | { |
| 94 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 95 | agent->clearBrowserCache(); |
| 96 | } |
| 97 | |
| 98 | void InspectorClientImpl::clearBrowserCookies() |
| 99 | { |
| 100 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 101 | agent->clearBrowserCookies(); |
| 102 | } |
| 103 | |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 104 | void InspectorClientImpl::overrideDeviceMetrics(int width, int height, float deviceScaleFactor, bool emulateViewport, bool fitWindow) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 105 | { |
| 106 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 107 | agent->overrideDeviceMetrics(width, height, deviceScaleFactor, emulateViewport, fitWindow); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | bool InspectorClientImpl::overridesShowPaintRects() |
| 111 | { |
| 112 | return m_inspectedWebView->isAcceleratedCompositingActive(); |
| 113 | } |
| 114 | |
| 115 | void InspectorClientImpl::setShowPaintRects(bool show) |
| 116 | { |
| 117 | m_inspectedWebView->setShowPaintRects(show); |
| 118 | } |
| 119 | |
| 120 | void InspectorClientImpl::setShowDebugBorders(bool show) |
| 121 | { |
| 122 | m_inspectedWebView->setShowDebugBorders(show); |
| 123 | } |
| 124 | |
| 125 | void InspectorClientImpl::setShowFPSCounter(bool show) |
| 126 | { |
| 127 | m_inspectedWebView->setShowFPSCounter(show); |
| 128 | } |
| 129 | |
| 130 | void InspectorClientImpl::setContinuousPaintingEnabled(bool enabled) |
| 131 | { |
| 132 | m_inspectedWebView->setContinuousPaintingEnabled(enabled); |
| 133 | } |
| 134 | |
| 135 | void InspectorClientImpl::setShowScrollBottleneckRects(bool show) |
| 136 | { |
| 137 | m_inspectedWebView->setShowScrollBottleneckRects(show); |
| 138 | } |
| 139 | |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 140 | void InspectorClientImpl::requestPageScaleFactor(float scale, const IntPoint& origin) |
| 141 | { |
| 142 | m_inspectedWebView->setPageScaleFactor(scale, origin); |
| 143 | } |
| 144 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 145 | void InspectorClientImpl::getAllocatedObjects(HashSet<const void*>& set) |
| 146 | { |
| 147 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 148 | agent->getAllocatedObjects(set); |
| 149 | } |
| 150 | |
| 151 | void InspectorClientImpl::dumpUncountedAllocatedObjects(const HashMap<const void*, size_t>& map) |
| 152 | { |
| 153 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 154 | agent->dumpUncountedAllocatedObjects(map); |
| 155 | } |
| 156 | |
| 157 | void InspectorClientImpl::dispatchKeyEvent(const PlatformKeyboardEvent& event) |
| 158 | { |
| 159 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 160 | agent->dispatchKeyEvent(event); |
| 161 | } |
| 162 | |
| 163 | void InspectorClientImpl::dispatchMouseEvent(const PlatformMouseEvent& event) |
| 164 | { |
| 165 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 166 | agent->dispatchMouseEvent(event); |
| 167 | } |
| 168 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 169 | void InspectorClientImpl::setTraceEventCallback(const String& categoryFilter, TraceEventCallback callback) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 170 | { |
| 171 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 172 | agent->setTraceEventCallback(categoryFilter, callback); |
| 173 | } |
| 174 | |
| 175 | void InspectorClientImpl::resetTraceEventCallback() |
| 176 | { |
| 177 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 178 | agent->resetTraceEventCallback(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 179 | } |
| 180 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 181 | void InspectorClientImpl::startGPUEventsRecording() |
| 182 | { |
| 183 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 184 | agent->startGPUEventsRecording(); |
| 185 | } |
| 186 | |
| 187 | void InspectorClientImpl::stopGPUEventsRecording() |
| 188 | { |
| 189 | if (WebDevToolsAgentImpl* agent = devToolsAgent()) |
| 190 | agent->stopGPUEventsRecording(); |
| 191 | } |
| 192 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 193 | WebDevToolsAgentImpl* InspectorClientImpl::devToolsAgent() |
| 194 | { |
| 195 | return static_cast<WebDevToolsAgentImpl*>(m_inspectedWebView->devToolsAgent()); |
| 196 | } |
| 197 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 198 | } // namespace blink |