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 "WebDevToolsAgentPrivate.h"
38#include "WebPageOverlay.h"
39#include "public/platform/WebSize.h"
40#include "public/platform/WebThread.h"
41#include "wtf/Forward.h"
42#include "wtf/OwnPtr.h"
43
44namespace WebCore {
45class Document;
46class Frame;
47class FrameView;
48class GraphicsContext;
49class InspectorClient;
50class InspectorController;
51class Node;
52class PlatformKeyboardEvent;
53}
54
55namespace WebKit {
56
57class DeviceMetricsSupport;
58class WebDevToolsAgentClient;
59class WebFrame;
60class WebFrameImpl;
61class WebString;
62class WebURLRequest;
63class WebURLResponse;
64class WebViewImpl;
65struct WebMemoryUsageInfo;
66struct WebURLError;
67struct WebDevToolsMessageData;
68
69class WebDevToolsAgentImpl : public WebDevToolsAgentPrivate,
70                             public WebCore::InspectorClient,
71                             public WebCore::InspectorFrontendChannel,
72                             public WebPageOverlay,
73                             private WebThread::TaskObserver {
74public:
75    WebDevToolsAgentImpl(WebViewImpl* webViewImpl, WebDevToolsAgentClient* client);
76    virtual ~WebDevToolsAgentImpl();
77
78    // WebDevToolsAgentPrivate implementation.
79    virtual void didCreateScriptContext(WebFrameImpl*, int worldId);
80    virtual void mainFrameViewCreated(WebFrameImpl*);
81    virtual bool metricsOverridden();
82    virtual void webViewResized(const WebSize&);
83    virtual bool handleInputEvent(WebCore::Page*, const WebInputEvent&);
84
85    // WebDevToolsAgent implementation.
86    virtual void attach();
87    virtual void reattach(const WebString& savedState);
88    virtual void detach();
89    virtual void didNavigate();
90    virtual void didBeginFrame();
91    virtual void didCancelFrame();
92    virtual void willComposite();
93    virtual void didComposite();
94    virtual void dispatchOnInspectorBackend(const WebString& message);
95    virtual void inspectElementAt(const WebPoint& point);
96    virtual void evaluateInWebInspector(long callId, const WebString& script);
97    virtual void setProcessId(long);
98    virtual void setLayerTreeId(int);
99
100    // InspectorClient implementation.
101    virtual void highlight();
102    virtual void hideHighlight();
103    virtual void updateInspectorStateCookie(const WTF::String&);
104    virtual bool sendMessageToFrontend(const WTF::String&);
105
106    virtual void clearBrowserCache();
107    virtual void clearBrowserCookies();
108
109    virtual void overrideDeviceMetrics(int width, int height, float fontScaleFactor, bool fitWindow);
110    virtual void autoZoomPageToFitWidth();
111
112    virtual void getAllocatedObjects(HashSet<const void*>&);
113    virtual void dumpUncountedAllocatedObjects(const HashMap<const void*, size_t>&);
114    virtual void setTraceEventCallback(TraceEventCallback);
115
116    virtual void dispatchKeyEvent(const WebCore::PlatformKeyboardEvent&);
117    virtual void dispatchMouseEvent(const WebCore::PlatformMouseEvent&);
118
119    int hostId() { return m_hostId; }
120
121    // WebPageOverlay
122    virtual void paintPageOverlay(WebCanvas*);
123
124private:
125    // WebThread::TaskObserver
126    virtual void willProcessTask();
127    virtual void didProcessTask();
128
129    WebCore::InspectorController* inspectorController();
130    WebCore::Frame* mainFrame();
131
132    int m_hostId;
133    WebDevToolsAgentClient* m_client;
134    WebViewImpl* m_webViewImpl;
135    bool m_attached;
136    OwnPtr<DeviceMetricsSupport> m_metricsSupport;
137};
138
139} // namespace WebKit
140
141#endif
142