1/*
2 * Copyright (C) 2010 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#ifndef WebDevToolsAgentImpl_h
32#define WebDevToolsAgentImpl_h
33
34#include "core/inspector/InspectorClient.h"
35#include "core/inspector/InspectorFrontendChannel.h"
36
37#include "public/platform/WebSize.h"
38#include "public/platform/WebThread.h"
39#include "public/web/WebPageOverlay.h"
40#include "web/WebDevToolsAgentPrivate.h"
41#include "wtf/Forward.h"
42#include "wtf/OwnPtr.h"
43#include "wtf/Vector.h"
44
45namespace blink {
46
47class Document;
48class LocalFrame;
49class FrameView;
50class GraphicsContext;
51class InspectorClient;
52class InspectorController;
53class Node;
54class Page;
55class PlatformKeyboardEvent;
56class WebDevToolsAgentClient;
57class WebFrame;
58class WebLocalFrameImpl;
59class WebString;
60class WebURLRequest;
61class WebURLResponse;
62class WebViewImpl;
63struct WebMemoryUsageInfo;
64struct WebURLError;
65struct WebDevToolsMessageData;
66
67class WebDevToolsAgentImpl FINAL
68    : public WebDevToolsAgentPrivate
69    , public InspectorClient
70    , public InspectorFrontendChannel
71    , public WebPageOverlay
72    , private WebThread::TaskObserver {
73public:
74    WebDevToolsAgentImpl(WebViewImpl* webViewImpl, WebDevToolsAgentClient* client);
75    virtual ~WebDevToolsAgentImpl();
76
77    WebDevToolsAgentClient* client() { return m_client; }
78
79    // WebDevToolsAgentPrivate implementation.
80    virtual void didCreateScriptContext(WebLocalFrameImpl*, int worldId) OVERRIDE;
81    virtual bool handleInputEvent(Page*, const WebInputEvent&) OVERRIDE;
82    virtual void didLayout() OVERRIDE;
83
84    // WebDevToolsAgent implementation.
85    virtual void attach(const WebString& hostId) OVERRIDE;
86    virtual void reattach(const WebString& hostId, const WebString& savedState) OVERRIDE;
87    virtual void detach() OVERRIDE;
88    virtual void continueProgram() OVERRIDE;
89    virtual void didBeginFrame(int frameId) OVERRIDE;
90    virtual void didCancelFrame() OVERRIDE;
91    virtual void willComposite() OVERRIDE;
92    virtual void didComposite() OVERRIDE;
93    virtual void dispatchOnInspectorBackend(const WebString& message) OVERRIDE;
94    virtual void inspectElementAt(const WebPoint&) OVERRIDE;
95    virtual void evaluateInWebInspector(long callId, const WebString& script) OVERRIDE;
96    virtual void setLayerTreeId(int) OVERRIDE;
97    virtual void processGPUEvent(const GPUEvent&) OVERRIDE;
98
99    // InspectorClient implementation.
100    virtual void highlight() OVERRIDE;
101    virtual void hideHighlight() OVERRIDE;
102    virtual void updateInspectorStateCookie(const WTF::String&) OVERRIDE;
103    virtual void sendMessageToFrontend(PassRefPtr<JSONObject> message) OVERRIDE;
104    virtual void flush() OVERRIDE;
105    virtual void resumeStartup() OVERRIDE;
106
107    virtual void setDeviceMetricsOverride(int width, int height, float deviceScaleFactor, bool mobile, bool fitWindow, float scale, float offsetX, float offsetY) OVERRIDE;
108    virtual void clearDeviceMetricsOverride() OVERRIDE;
109    virtual void setTouchEventEmulationEnabled(bool) OVERRIDE;
110
111    virtual void setTraceEventCallback(const WTF::String& categoryFilter, TraceEventCallback) OVERRIDE;
112    virtual void resetTraceEventCallback() OVERRIDE;
113    virtual void enableTracing(const WTF::String& categoryFilter) OVERRIDE;
114    virtual void disableTracing() OVERRIDE;
115
116    virtual void startGPUEventsRecording() OVERRIDE;
117    virtual void stopGPUEventsRecording() OVERRIDE;
118
119    virtual void dispatchKeyEvent(const PlatformKeyboardEvent&) OVERRIDE;
120    virtual void dispatchMouseEvent(const PlatformMouseEvent&) OVERRIDE;
121
122    // WebPageOverlay
123    virtual void paintPageOverlay(WebCanvas*) OVERRIDE;
124
125    void flushPendingFrontendMessages();
126
127private:
128    // WebThread::TaskObserver
129    virtual void willProcessTask() OVERRIDE;
130    virtual void didProcessTask() OVERRIDE;
131
132    void enableMobileEmulation();
133    void disableMobileEmulation();
134    void updatePageScaleFactorLimits();
135
136    InspectorController* inspectorController();
137    LocalFrame* mainFrame();
138
139    int m_debuggerId;
140    int m_layerTreeId;
141    WebDevToolsAgentClient* m_client;
142    WebViewImpl* m_webViewImpl;
143    bool m_attached;
144    bool m_generatingEvent;
145
146    bool m_webViewDidLayoutOnceAfterLoad;
147
148    bool m_deviceMetricsEnabled;
149    bool m_emulateMobileEnabled;
150    bool m_originalViewportEnabled;
151    bool m_isOverlayScrollbarsEnabled;
152
153    float m_originalMinimumPageScaleFactor;
154    float m_originalMaximumPageScaleFactor;
155    bool m_pageScaleLimitsOverriden;
156
157    bool m_touchEventEmulationEnabled;
158    OwnPtr<IntPoint> m_lastPinchAnchorCss;
159    OwnPtr<IntPoint> m_lastPinchAnchorDip;
160
161    typedef Vector<RefPtr<JSONObject> > FrontendMessageQueue;
162    FrontendMessageQueue m_frontendMessageQueue;
163};
164
165} // namespace blink
166
167#endif
168