tizen beta release
[framework/web/webkit-efl.git] / Tools / DumpRenderTree / chromium / WebViewHost.h
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 WebViewHost_h
32 #define WebViewHost_h
33
34 #include "MockSpellCheck.h"
35 #include "Task.h"
36 #include "TestNavigationController.h"
37 #include "WebAccessibilityNotification.h"
38 #include "WebCursorInfo.h"
39 #include "WebFrameClient.h"
40 #include "WebSpellCheckClient.h"
41 #include "WebViewClient.h"
42 #include <wtf/HashMap.h>
43 #include <wtf/HashSet.h>
44 #include <wtf/Vector.h>
45 #include <wtf/text/WTFString.h>
46
47 class LayoutTestController;
48 class SkCanvas;
49 class TestShell;
50
51 namespace WebKit {
52 class WebFrame;
53 class WebDeviceOrientationClient;
54 class WebDeviceOrientationClientMock;
55 class WebGeolocationClient;
56 class WebGeolocationClientMock;
57 class WebGeolocationServiceMock;
58 class WebSpeechInputController;
59 class WebSpeechInputControllerMock;
60 class WebSpeechInputListener;
61 class WebThread;
62 class WebURL;
63 struct WebRect;
64 struct WebURLError;
65 struct WebWindowFeatures;
66 }
67
68 class WebViewHost : public WebKit::WebSpellCheckClient, public WebKit::WebViewClient, public WebKit::WebFrameClient, public NavigationHost {
69  public:
70     WebViewHost(TestShell*);
71     virtual ~WebViewHost();
72     void setWebWidget(WebKit::WebWidget*);
73     WebKit::WebView* webView() const;
74     WebKit::WebWidget* webWidget() const;
75     void reset();
76     void setSelectTrailingWhitespaceEnabled(bool);
77     void setSmartInsertDeleteEnabled(bool);
78     void setLogConsoleOutput(bool);
79     void waitForPolicyDelegate();
80     void setCustomPolicyDelegate(bool, bool);
81     WebKit::WebFrame* topLoadingFrame() { return m_topLoadingFrame; }
82     void setBlockRedirects(bool block) { m_blocksRedirects = block; }
83     void setRequestReturnNull(bool returnNull) { m_requestReturnNull = returnNull; }
84     void setEditCommand(const std::string& name, const std::string& value);
85     void clearEditCommand();
86     void setPendingExtraData(PassOwnPtr<TestShellExtraData>);
87
88     void paintRect(const WebKit::WebRect&);
89     void updatePaintRect(const WebKit::WebRect&);
90     void paintInvalidatedRegion();
91     void paintPagesWithBoundaries();
92     SkCanvas* canvas();
93     void displayRepaintMask();
94
95     void loadURLForFrame(const WebKit::WebURL&, const WebKit::WebString& frameName);
96     TestNavigationController* navigationController() { return m_navigationController.get(); }
97
98     void addClearHeader(const WTF::String& header) { m_clearHeaders.add(header); }
99     const HashSet<WTF::String>& clearHeaders() const { return m_clearHeaders; }
100     void closeWidget();
101
102     WebKit::WebContextMenuData* lastContextMenuData() const;
103     void clearContextMenuData();
104
105     WebKit::WebSpeechInputControllerMock* speechInputControllerMock() { return m_speechInputControllerMock.get(); }
106
107     // NavigationHost
108     virtual bool navigate(const TestNavigationEntry&, bool reload);
109
110     // WebKit::WebSpellCheckClient
111     virtual void spellCheck(const WebKit::WebString&, int& offset, int& length, WebKit::WebVector<WebKit::WebString>* optionalSuggestions);
112     virtual void requestCheckingOfText(const WebKit::WebString&, WebKit::WebTextCheckingCompletion*);
113     virtual WebKit::WebString autoCorrectWord(const WebKit::WebString&);
114
115     // WebKit::WebViewClient
116     virtual WebKit::WebView* createView(WebKit::WebFrame*, const WebKit::WebURLRequest&, const WebKit::WebWindowFeatures&, const WebKit::WebString&);
117     virtual WebKit::WebWidget* createPopupMenu(WebKit::WebPopupType);
118     virtual WebKit::WebWidget* createPopupMenu(const WebKit::WebPopupMenuInfo&);
119     virtual WebKit::WebStorageNamespace* createSessionStorageNamespace(unsigned quota);
120     virtual void didAddMessageToConsole(const WebKit::WebConsoleMessage&, const WebKit::WebString& sourceName, unsigned sourceLine);
121     virtual void didStartLoading();
122     virtual void didStopLoading();
123     virtual bool shouldBeginEditing(const WebKit::WebRange&);
124     virtual bool shouldEndEditing(const WebKit::WebRange&);
125     virtual bool shouldInsertNode(const WebKit::WebNode&, const WebKit::WebRange&, WebKit::WebEditingAction);
126     virtual bool shouldInsertText(const WebKit::WebString&, const WebKit::WebRange&, WebKit::WebEditingAction);
127     virtual bool shouldChangeSelectedRange(const WebKit::WebRange& from, const WebKit::WebRange& to, WebKit::WebTextAffinity, bool stillSelecting);
128     virtual bool shouldDeleteRange(const WebKit::WebRange&);
129     virtual bool shouldApplyStyle(const WebKit::WebString& style, const WebKit::WebRange&);
130     virtual bool isSmartInsertDeleteEnabled();
131     virtual bool isSelectTrailingWhitespaceEnabled();
132     virtual void didBeginEditing();
133     virtual void didChangeSelection(bool isSelectionEmpty);
134     virtual void didChangeContents();
135     virtual void didEndEditing();
136     virtual bool handleCurrentKeyboardEvent();
137     virtual void runModalAlertDialog(WebKit::WebFrame*, const WebKit::WebString&);
138     virtual bool runModalConfirmDialog(WebKit::WebFrame*, const WebKit::WebString&);
139     virtual bool runModalPromptDialog(WebKit::WebFrame*, const WebKit::WebString& message, const WebKit::WebString& defaultValue, WebKit::WebString* actualValue);
140     virtual bool runModalBeforeUnloadDialog(WebKit::WebFrame*, const WebKit::WebString&);
141     virtual void showContextMenu(WebKit::WebFrame*, const WebKit::WebContextMenuData&);
142     virtual void setStatusText(const WebKit::WebString&);
143     virtual void startDragging(const WebKit::WebDragData&, WebKit::WebDragOperationsMask, const WebKit::WebImage&, const WebKit::WebPoint&);
144     virtual void navigateBackForwardSoon(int offset);
145     virtual int historyBackListCount();
146     virtual int historyForwardListCount();
147     virtual void postAccessibilityNotification(const WebKit::WebAccessibilityObject&, WebKit::WebAccessibilityNotification);
148     virtual WebKit::WebNotificationPresenter* notificationPresenter();
149     virtual WebKit::WebGeolocationClient* geolocationClient();
150     virtual WebKit::WebSpeechInputController* speechInputController(WebKit::WebSpeechInputListener*);
151     virtual WebKit::WebDeviceOrientationClient* deviceOrientationClient();
152
153     // WebKit::WebWidgetClient
154     virtual void didInvalidateRect(const WebKit::WebRect&);
155     virtual void didScrollRect(int dx, int dy, const WebKit::WebRect&);
156     virtual void scheduleComposite();
157 #if ENABLE(REQUEST_ANIMATION_FRAME)
158     virtual void scheduleAnimation();
159 #endif
160     virtual void didFocus();
161     virtual void didBlur();
162     virtual void didChangeCursor(const WebKit::WebCursorInfo&);
163     virtual void closeWidgetSoon();
164     virtual void show(WebKit::WebNavigationPolicy);
165     virtual void runModal();
166     virtual bool enterFullScreen();
167     virtual void exitFullScreen();
168     virtual WebKit::WebRect windowRect();
169     virtual void setWindowRect(const WebKit::WebRect&);
170     virtual WebKit::WebRect rootWindowRect();
171     virtual WebKit::WebRect windowResizerRect();
172     virtual WebKit::WebScreenInfo screenInfo();
173
174     // WebKit::WebFrameClient
175     virtual WebKit::WebPlugin* createPlugin(WebKit::WebFrame*, const WebKit::WebPluginParams&);
176     virtual WebKit::WebWorker* createWorker(WebKit::WebFrame*, WebKit::WebWorkerClient*);
177     virtual WebKit::WebMediaPlayer* createMediaPlayer(WebKit::WebFrame*, WebKit::WebMediaPlayerClient*);
178     virtual WebKit::WebApplicationCacheHost* createApplicationCacheHost(WebKit::WebFrame*, WebKit::WebApplicationCacheHostClient*);
179     virtual void didUpdateLayout(WebKit::WebFrame*);
180     virtual void loadURLExternally(WebKit::WebFrame*, const WebKit::WebURLRequest&, WebKit::WebNavigationPolicy);
181     virtual void loadURLExternally(WebKit::WebFrame*, const WebKit::WebURLRequest&, WebKit::WebNavigationPolicy, const WebKit::WebString& downloadName);
182     virtual WebKit::WebNavigationPolicy decidePolicyForNavigation(
183         WebKit::WebFrame*, const WebKit::WebURLRequest&,
184         WebKit::WebNavigationType, const WebKit::WebNode&,
185         WebKit::WebNavigationPolicy, bool isRedirect);
186     virtual bool canHandleRequest(WebKit::WebFrame*, const WebKit::WebURLRequest&);
187     virtual WebKit::WebURLError cannotHandleRequestError(WebKit::WebFrame*, const WebKit::WebURLRequest&);
188     virtual WebKit::WebURLError cancelledError(WebKit::WebFrame*, const WebKit::WebURLRequest&);
189     virtual void unableToImplementPolicyWithError(WebKit::WebFrame*, const WebKit::WebURLError&);
190     virtual void willPerformClientRedirect(
191         WebKit::WebFrame*, const WebKit::WebURL& from, const WebKit::WebURL& to,
192         double interval, double fireTime);
193     virtual void didCancelClientRedirect(WebKit::WebFrame*);
194     virtual void didCreateDataSource(WebKit::WebFrame*, WebKit::WebDataSource*);
195     virtual void didStartProvisionalLoad(WebKit::WebFrame*);
196     virtual void didReceiveServerRedirectForProvisionalLoad(WebKit::WebFrame*);
197     virtual void didFailProvisionalLoad(WebKit::WebFrame*, const WebKit::WebURLError&);
198     virtual void didCommitProvisionalLoad(WebKit::WebFrame*, bool isNewNavigation);
199     virtual void didClearWindowObject(WebKit::WebFrame*);
200     virtual void didReceiveTitle(WebKit::WebFrame*, const WebKit::WebString&, WebKit::WebTextDirection);
201     virtual void didFinishDocumentLoad(WebKit::WebFrame*);
202     virtual void didHandleOnloadEvents(WebKit::WebFrame*);
203     virtual void didFailLoad(WebKit::WebFrame*, const WebKit::WebURLError&);
204     virtual void didFinishLoad(WebKit::WebFrame*);
205     virtual void didNavigateWithinPage(WebKit::WebFrame*, bool isNewNavigation);
206     virtual void didChangeLocationWithinPage(WebKit::WebFrame*);
207     virtual void assignIdentifierToRequest(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLRequest&);
208     virtual void removeIdentifierForRequest(unsigned identifier);
209     virtual void willSendRequest(WebKit::WebFrame*, unsigned identifier, WebKit::WebURLRequest&, const WebKit::WebURLResponse&);
210     virtual void didReceiveResponse(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLResponse&);
211     virtual void didFinishResourceLoad(WebKit::WebFrame*, unsigned identifier);
212     virtual void didFailResourceLoad(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLError&);
213     virtual void didDisplayInsecureContent(WebKit::WebFrame*);
214     virtual void didRunInsecureContent(WebKit::WebFrame*, const WebKit::WebSecurityOrigin&, const WebKit::WebURL&);
215     virtual void didDetectXSS(WebKit::WebFrame*, const WebKit::WebURL&, bool didBlockEntirePage);
216     virtual void openFileSystem(WebKit::WebFrame*, WebKit::WebFileSystem::Type, long long size, bool create, WebKit::WebFileSystemCallbacks*);
217
218     WebKit::WebDeviceOrientationClientMock* deviceOrientationClientMock();
219     
220     // Spellcheck related helper APIs
221     MockSpellCheck* mockSpellCheck();
222     void finishLastTextCheck();
223
224     // Geolocation client mocks for LayoutTestController
225     WebKit::WebGeolocationClientMock* geolocationClientMock();
226
227     // Pending task list, Note taht the method is referred from MethodTask class.
228     TaskList* taskList() { return &m_taskList; }
229
230 private:
231
232     class HostMethodTask : public MethodTask<WebViewHost> {
233     public:
234         typedef void (WebViewHost::*CallbackMethodType)();
235         HostMethodTask(WebViewHost* object, CallbackMethodType callback)
236             : MethodTask<WebViewHost>(object)
237             , m_callback(callback)
238         { }
239
240         virtual void runIfValid() { (m_object->*m_callback)(); }
241
242     private:
243         CallbackMethodType m_callback;
244     };
245
246     LayoutTestController* layoutTestController() const;
247
248     // Called the title of the page changes.
249     // Can be used to update the title of the window.
250     void setPageTitle(const WebKit::WebString&);
251
252     // Called when the URL of the page changes.
253     // Extracts the URL and forwards on to SetAddressBarURL().
254     void updateAddressBar(WebKit::WebView*);
255
256     // Called when the URL of the page changes.
257     // Should be used to update the text of the URL bar.
258     void setAddressBarURL(const WebKit::WebURL&);
259
260     void enterFullScreenNow();
261     void exitFullScreenNow();
262
263     // In the Mac code, this is called to trigger the end of a test after the
264     // page has finished loading. From here, we can generate the dump for the
265     // test.
266     void locationChangeDone(WebKit::WebFrame*);
267
268     void updateForCommittedLoad(WebKit::WebFrame*, bool isNewNavigation);
269     void updateURL(WebKit::WebFrame*);
270     void updateSessionHistory(WebKit::WebFrame*);
271
272     // Dumping a frame to the console.
273     void printFrameDescription(WebKit::WebFrame*);
274
275     // Dumping the user gesture status to the console.
276     void printFrameUserGestureStatus(WebKit::WebFrame*, const char*);
277
278     bool hasWindow() const { return m_hasWindow; }
279     void resetScrollRect();
280     void discardBackingStore();
281
282     // Causes navigation actions just printout the intended navigation instead
283     // of taking you to the page. This is used for cases like mailto, where you
284     // don't actually want to open the mail program.
285     bool m_policyDelegateEnabled;
286
287     // Toggles the behavior of the policy delegate. If true, then navigations
288     // will be allowed. Otherwise, they will be ignored (dropped).
289     bool m_policyDelegateIsPermissive;
290
291     // If true, the policy delegate will signal layout test completion.
292     bool m_policyDelegateShouldNotifyDone;
293
294     // Non-owning pointer. The WebViewHost instance is owned by this TestShell instance.
295     TestShell* m_shell;
296
297     // This delegate works for the following widget.
298     WebKit::WebWidget* m_webWidget;
299
300     // This is non-0 IFF a load is in progress.
301     WebKit::WebFrame* m_topLoadingFrame;
302
303     // For tracking session history. See RenderView.
304     int m_pageId;
305     int m_lastPageIdUpdated;
306
307     OwnPtr<TestShellExtraData> m_pendingExtraData;
308
309     // Maps resource identifiers to a descriptive string.
310     typedef HashMap<unsigned, std::string> ResourceMap;
311     ResourceMap m_resourceIdentifierMap;
312     void printResourceDescription(unsigned identifier);
313
314     WebKit::WebCursorInfo m_currentCursor;
315
316     bool m_hasWindow;
317     bool m_inModalLoop;
318     WebKit::WebRect m_windowRect;
319
320     // true if we want to enable smart insert/delete.
321     bool m_smartInsertDeleteEnabled;
322
323     // true if we want to enable selection of trailing whitespaces
324     bool m_selectTrailingWhitespaceEnabled;
325
326     // true if whatever is sent to the console should be logged to stdout.
327     bool m_logConsoleOutput;
328
329     // Set of headers to clear in willSendRequest.
330     HashSet<WTF::String> m_clearHeaders;
331
332     // true if we should block any redirects
333     bool m_blocksRedirects;
334
335     // true if we should block (set an empty request for) any requests
336     bool m_requestReturnNull;
337
338     // Edit command associated to the current keyboard event.
339     std::string m_editCommandName;
340     std::string m_editCommandValue;
341
342     // The mock spellchecker used in spellCheck().
343     MockSpellCheck m_spellcheck;
344
345     // Painting.
346     OwnPtr<SkCanvas> m_canvas;
347     WebKit::WebRect m_paintRect;
348     bool m_isPainting;
349
350     OwnPtr<WebKit::WebContextMenuData> m_lastContextMenuData;
351
352     // Geolocation
353     OwnPtr<WebKit::WebGeolocationClientMock> m_geolocationClientMock;
354
355     OwnPtr<WebKit::WebDeviceOrientationClientMock> m_deviceOrientationClientMock;
356     OwnPtr<WebKit::WebSpeechInputControllerMock> m_speechInputControllerMock;
357
358     OwnPtr<TestNavigationController> m_navigationController;
359
360     WebKit::WebString m_lastRequestedTextCheckString;
361     WebKit::WebTextCheckingCompletion* m_lastRequestedTextCheckingCompletion;
362
363     OwnPtr<WebKit::WebThread> m_compositorThread;
364
365     TaskList m_taskList;
366     Vector<WebKit::WebWidget*> m_popupmenus;
367 };
368
369 #endif // WebViewHost_h