Home | History | Annotate | Download | only in web
      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 #include "wtf/Vector.h"
     48 
     49 using namespace WebCore;
     50 
     51 namespace blink {
     52 
     53 InspectorClientImpl::InspectorClientImpl(WebViewImpl* webView)
     54     : m_inspectedWebView(webView)
     55 {
     56     ASSERT(m_inspectedWebView);
     57 }
     58 
     59 InspectorClientImpl::~InspectorClientImpl()
     60 {
     61 }
     62 
     63 void InspectorClientImpl::highlight()
     64 {
     65     if (WebDevToolsAgentImpl* agent = devToolsAgent())
     66         agent->highlight();
     67 }
     68 
     69 void InspectorClientImpl::hideHighlight()
     70 {
     71     if (WebDevToolsAgentImpl* agent = devToolsAgent())
     72         agent->hideHighlight();
     73 }
     74 
     75 void InspectorClientImpl::sendMessageToFrontend(PassRefPtr<WebCore::JSONObject> message)
     76 {
     77     if (WebDevToolsAgentImpl* agent = devToolsAgent())
     78         agent->sendMessageToFrontend(message);
     79 }
     80 
     81 void InspectorClientImpl::flush()
     82 {
     83     if (WebDevToolsAgentImpl* agent = devToolsAgent())
     84         agent->flush();
     85 }
     86 
     87 void InspectorClientImpl::updateInspectorStateCookie(const WTF::String& inspectorState)
     88 {
     89     if (WebDevToolsAgentImpl* agent = devToolsAgent())
     90         agent->updateInspectorStateCookie(inspectorState);
     91 }
     92 
     93 void InspectorClientImpl::setDeviceMetricsOverride(int width, int height, float deviceScaleFactor, bool emulateViewport, bool fitWindow)
     94 {
     95     if (WebDevToolsAgentImpl* agent = devToolsAgent())
     96         agent->setDeviceMetricsOverride(width, height, deviceScaleFactor, emulateViewport, fitWindow);
     97 }
     98 
     99 void InspectorClientImpl::clearDeviceMetricsOverride()
    100 {
    101     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    102         agent->clearDeviceMetricsOverride();
    103 }
    104 
    105 void InspectorClientImpl::setTouchEventEmulationEnabled(bool enabled)
    106 {
    107     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    108         agent->setTouchEventEmulationEnabled(enabled);
    109 }
    110 
    111 bool InspectorClientImpl::overridesShowPaintRects()
    112 {
    113     return m_inspectedWebView->isAcceleratedCompositingActive();
    114 }
    115 
    116 void InspectorClientImpl::setShowPaintRects(bool show)
    117 {
    118     m_inspectedWebView->setShowPaintRects(show);
    119 }
    120 
    121 void InspectorClientImpl::setShowDebugBorders(bool show)
    122 {
    123     m_inspectedWebView->setShowDebugBorders(show);
    124 }
    125 
    126 void InspectorClientImpl::setShowFPSCounter(bool show)
    127 {
    128     m_inspectedWebView->setShowFPSCounter(show);
    129 }
    130 
    131 void InspectorClientImpl::setContinuousPaintingEnabled(bool enabled)
    132 {
    133     m_inspectedWebView->setContinuousPaintingEnabled(enabled);
    134 }
    135 
    136 void InspectorClientImpl::setShowScrollBottleneckRects(bool show)
    137 {
    138     m_inspectedWebView->setShowScrollBottleneckRects(show);
    139 }
    140 
    141 void InspectorClientImpl::requestPageScaleFactor(float scale, const IntPoint& origin)
    142 {
    143     m_inspectedWebView->setPageScaleFactor(scale);
    144     m_inspectedWebView->setMainFrameScrollOffset(origin);
    145 }
    146 
    147 void InspectorClientImpl::getAllocatedObjects(HashSet<const void*>& set)
    148 {
    149     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    150         agent->getAllocatedObjects(set);
    151 }
    152 
    153 void InspectorClientImpl::dumpUncountedAllocatedObjects(const HashMap<const void*, size_t>& map)
    154 {
    155     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    156         agent->dumpUncountedAllocatedObjects(map);
    157 }
    158 
    159 void InspectorClientImpl::dispatchKeyEvent(const PlatformKeyboardEvent& event)
    160 {
    161     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    162         agent->dispatchKeyEvent(event);
    163 }
    164 
    165 void InspectorClientImpl::dispatchMouseEvent(const PlatformMouseEvent& event)
    166 {
    167     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    168         agent->dispatchMouseEvent(event);
    169 }
    170 
    171 void InspectorClientImpl::setTraceEventCallback(const String& categoryFilter, TraceEventCallback callback)
    172 {
    173     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    174         agent->setTraceEventCallback(categoryFilter, callback);
    175 }
    176 
    177 void InspectorClientImpl::enableTracing(const String& categoryFilter)
    178 {
    179     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    180         agent->enableTracing(categoryFilter);
    181 }
    182 
    183 void InspectorClientImpl::disableTracing()
    184 {
    185     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    186         agent->disableTracing();
    187 }
    188 
    189 void InspectorClientImpl::resetTraceEventCallback()
    190 {
    191     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    192         agent->resetTraceEventCallback();
    193 }
    194 
    195 void InspectorClientImpl::startGPUEventsRecording()
    196 {
    197     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    198         agent->startGPUEventsRecording();
    199 }
    200 
    201 void InspectorClientImpl::stopGPUEventsRecording()
    202 {
    203     if (WebDevToolsAgentImpl* agent = devToolsAgent())
    204         agent->stopGPUEventsRecording();
    205 }
    206 
    207 WebDevToolsAgentImpl* InspectorClientImpl::devToolsAgent()
    208 {
    209     return static_cast<WebDevToolsAgentImpl*>(m_inspectedWebView->devToolsAgent());
    210 }
    211 
    212 } // namespace blink
    213