initial import
[vuplus_webkit] / Source / WebKit2 / UIProcess / WebInspectorProxy.h
1 /*
2  * Copyright (C) 2010 Apple 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
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef WebInspectorProxy_h
27 #define WebInspectorProxy_h
28
29 #if ENABLE(INSPECTOR)
30
31 #include "APIObject.h"
32 #include "Connection.h"
33 #include <wtf/Forward.h>
34 #include <wtf/PassRefPtr.h>
35 #include <wtf/RefPtr.h>
36
37 #if PLATFORM(MAC)
38 #include <wtf/RetainPtr.h>
39
40 OBJC_CLASS NSWindow;
41 OBJC_CLASS WebInspectorProxyObjCAdapter;
42 OBJC_CLASS WebInspectorWKView;
43 #endif
44
45 #if PLATFORM(WIN)
46 #include <WebCore/WindowMessageListener.h>
47 #endif
48
49 namespace WebKit {
50
51 class WebPageGroup;
52 class WebPageProxy;
53 struct WebPageCreationParameters;
54
55 #if PLATFORM(WIN)
56 class WebView;
57 #endif
58
59 class WebInspectorProxy : public APIObject
60 #if PLATFORM(WIN)
61     , public WebCore::WindowMessageListener
62 #endif
63 {
64 public:
65     static const Type APIType = TypeInspector;
66
67     static PassRefPtr<WebInspectorProxy> create(WebPageProxy* page)
68     {
69         return adoptRef(new WebInspectorProxy(page));
70     }
71
72     ~WebInspectorProxy();
73
74     void invalidate();
75
76     // Public APIs
77     WebPageProxy* page() const { return m_page; }
78
79     bool isVisible() const { return m_isVisible; }
80     void show();
81     void close();
82     
83 #if PLATFORM(MAC)
84     void inspectedViewFrameDidChange();
85 #endif
86
87     void showConsole();
88
89     bool isAttached() const { return m_isAttached; }
90     void attach();
91     void detach();
92     void setAttachedWindowHeight(unsigned);
93
94     bool isDebuggingJavaScript() const { return m_isDebuggingJavaScript; }
95     void toggleJavaScriptDebugging();
96
97     bool isProfilingJavaScript() const { return m_isProfilingJavaScript; }
98     void toggleJavaScriptProfiling();
99
100     bool isProfilingPage() const { return m_isProfilingPage; }
101     void togglePageProfiling();
102
103 #if ENABLE(INSPECTOR)
104     // Implemented in generated WebInspectorProxyMessageReceiver.cpp
105     void didReceiveWebInspectorProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
106     void didReceiveSyncWebInspectorProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&);
107 #endif
108
109     static bool isInspectorPage(WebPageProxy*);
110
111 private:
112     WebInspectorProxy(WebPageProxy* page);
113
114     virtual Type type() const { return APIType; }
115
116     WebPageProxy* platformCreateInspectorPage();
117     void platformOpen();
118     void platformDidClose();
119     void platformBringToFront();
120     void platformInspectedURLChanged(const String&);
121     unsigned platformInspectedWindowHeight();
122     void platformAttach();
123     void platformDetach();
124     void platformSetAttachedWindowHeight(unsigned);
125
126     // Implemented the platform WebInspectorProxy file
127     String inspectorPageURL() const;
128
129     // Called by WebInspectorProxy messages
130     void createInspectorPage(uint64_t& inspectorPageID, WebPageCreationParameters&);
131     void didLoadInspectorPage();
132     void didClose();
133     void bringToFront();
134     void inspectedURLChanged(const String&);
135
136     bool canAttach();
137     bool shouldOpenAttached();
138
139     static WebPageGroup* inspectorPageGroup();
140
141 #if PLATFORM(WIN)
142     static bool registerInspectorViewWindowClass();
143     static LRESULT CALLBACK InspectorViewWndProc(HWND, UINT, WPARAM, LPARAM);
144     LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
145
146     LRESULT onSizeEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
147     LRESULT onMinMaxInfoEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
148     LRESULT onSetFocusEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
149     LRESULT onCloseEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
150
151     void onWebViewWindowPosChangingEvent(WPARAM, LPARAM);
152     virtual void windowReceivedMessage(HWND, UINT message, WPARAM, LPARAM);
153 #endif
154
155     static const unsigned minimumWindowWidth = 500;
156     static const unsigned minimumWindowHeight = 400;
157
158     static const unsigned initialWindowWidth = 750;
159     static const unsigned initialWindowHeight = 650;
160     static const unsigned minimumAttachedHeight = 250;
161
162     WebPageProxy* m_page;
163
164     bool m_isVisible;
165     bool m_isAttached;
166     bool m_isDebuggingJavaScript;
167     bool m_isProfilingJavaScript;
168     bool m_isProfilingPage;
169
170 #if PLATFORM(MAC)
171     RetainPtr<WebInspectorWKView> m_inspectorView;
172     RetainPtr<NSWindow> m_inspectorWindow;
173     RetainPtr<WebInspectorProxyObjCAdapter> m_inspectorProxyObjCAdapter;
174 #elif PLATFORM(WIN)
175     HWND m_inspectorWindow;
176     RefPtr<WebView> m_inspectorView;
177 #endif
178 };
179
180 } // namespace WebKit
181
182 #endif // ENABLE(INSPECTOR)
183
184 #endif // WebInspectorProxy_h