Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / public / web / WebViewClient.h
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 #ifndef WebViewClient_h
32 #define WebViewClient_h
33
34 #include "../platform/WebGraphicsContext3D.h"
35 #include "../platform/WebString.h"
36 #include "WebAXEnums.h"
37 #include "WebContentDetectionResult.h"
38 #include "WebDragOperation.h"
39 #include "WebFileChooserCompletion.h"
40 #include "WebFileChooserParams.h"
41 #include "WebFrame.h"
42 #include "WebNavigatorContentUtilsClient.h"
43 #include "WebPageVisibilityState.h"
44 #include "WebPopupType.h"
45 #include "WebTextAffinity.h"
46 #include "WebTextDirection.h"
47 #include "WebWidgetClient.h"
48
49 namespace blink {
50
51 class WebAXObject;
52 class WebCompositorOutputSurface;
53 class WebDateTimeChooserCompletion;
54 class WebDragData;
55 class WebElement;
56 class WebExternalPopupMenu;
57 class WebExternalPopupMenuClient;
58 class WebFileChooserCompletion;
59 class WebGestureEvent;
60 class WebHitTestResult;
61 class WebImage;
62 class WebInputElement;
63 class WebKeyboardEvent;
64 class WebNode;
65 class WebPushClient;
66 class WebRange;
67 class WebSpeechRecognizer;
68 class WebStorageNamespace;
69 class WebURL;
70 class WebURLRequest;
71 class WebView;
72 class WebWidget;
73 struct WebConsoleMessage;
74 struct WebDateTimeChooserParams;
75 struct WebPoint;
76 struct WebPopupMenuInfo;
77 struct WebRect;
78 struct WebSize;
79 struct WebWindowFeatures;
80
81 // Since a WebView is a WebWidget, a WebViewClient is a WebWidgetClient.
82 // Virtual inheritance allows an implementation of WebWidgetClient to be
83 // easily reused as part of an implementation of WebViewClient.
84 class WebViewClient : virtual public WebWidgetClient {
85 public:
86     // Factory methods -----------------------------------------------------
87
88     // Create a new related WebView.  This method must clone its session storage
89     // so any subsequent calls to createSessionStorageNamespace conform to the
90     // WebStorage specification.
91     // The request parameter is only for the client to check if the request
92     // could be fulfilled.  The client should not load the request.
93     // The policy parameter indicates how the new view will be displayed in
94     // WebWidgetClient::show.
95     virtual WebView* createView(WebLocalFrame* creator,
96                                 const WebURLRequest& request,
97                                 const WebWindowFeatures& features,
98                                 const WebString& name,
99                                 WebNavigationPolicy policy,
100                                 bool suppressOpener) {
101         return 0;
102     }
103
104     // Create a new WebPopupMenu.  In the second form, the client is
105     // responsible for rendering the contents of the popup menu.
106     virtual WebWidget* createPopupMenu(WebPopupType) { return 0; }
107     virtual WebWidget* createPopupMenu(const WebPopupMenuInfo&) { return 0; }
108     virtual WebExternalPopupMenu* createExternalPopupMenu(
109         const WebPopupMenuInfo&, WebExternalPopupMenuClient*) { return 0; }
110
111     // Create a session storage namespace object associated with this WebView.
112     virtual WebStorageNamespace* createSessionStorageNamespace() { return 0; }
113
114
115     // Misc ----------------------------------------------------------------
116
117     // Called when script in the page calls window.print().  If frame is
118     // non-null, then it selects a particular frame, including its
119     // children, to print.  Otherwise, the main frame and its children
120     // should be printed.
121     virtual void printPage(WebLocalFrame*) { }
122
123     // This method enumerates all the files in the path. It returns immediately
124     // and asynchronously invokes the WebFileChooserCompletion with all the
125     // files in the directory. Returns false if the WebFileChooserCompletion
126     // will never be called.
127     virtual bool enumerateChosenDirectory(const WebString& path, WebFileChooserCompletion*) { return false; }
128
129
130     // Editing -------------------------------------------------------------
131
132     // These methods allow the client to intercept and overrule editing
133     // operations.
134     virtual void didCancelCompositionOnSelectionChange() { }
135     virtual void didChangeContents() { }
136
137     // This method is called in response to WebView's handleInputEvent()
138     // when the default action for the current keyboard event is not
139     // suppressed by the page, to give the embedder a chance to handle
140     // the keyboard event specially.
141     //
142     // Returns true if the keyboard event was handled by the embedder,
143     // indicating that the default action should be suppressed.
144     virtual bool handleCurrentKeyboardEvent() { return false; }
145
146
147     // Dialogs -------------------------------------------------------------
148
149     // This method returns immediately after showing the dialog. When the
150     // dialog is closed, it should call the WebFileChooserCompletion to
151     // pass the results of the dialog. Returns false if
152     // WebFileChooseCompletion will never be called.
153     virtual bool runFileChooser(const WebFileChooserParams&,
154                                 WebFileChooserCompletion*) { return false; }
155
156     // Ask users to choose date/time for the specified parameters. When a user
157     // chooses a value, an implementation of this function should call
158     // WebDateTimeChooserCompletion::didChooseValue or didCancelChooser. If the
159     // implementation opened date/time chooser UI successfully, it should return
160     // true. This function is used only if ExternalDateTimeChooser is used.
161     virtual bool openDateTimeChooser(const WebDateTimeChooserParams&, WebDateTimeChooserCompletion*) { return false; }
162
163     // Show a notification popup for the specified form vaidation messages
164     // besides the anchor rectangle. An implementation of this function should
165     // not hide the popup until hideValidationMessage call.
166     virtual void showValidationMessage(const WebRect& anchorInRootView, const WebString& mainText, WebTextDirection mainTextDir, const WebString& supplementalText, WebTextDirection supplementalTextDir) { }
167     // FIXME: BUG91638, when landed on chrome side, this will be removed.
168     virtual void showValidationMessage(const WebRect& anchorInRootView, const WebString& mainText, const WebString& supplementalText, WebTextDirection hint) { }
169
170     // Hide notifation popup for form validation messages.
171     virtual void hideValidationMessage() { }
172
173     // Move the existing notifation popup to the new anchor position.
174     virtual void moveValidationMessage(const WebRect& anchorInRootView) { }
175
176
177     // UI ------------------------------------------------------------------
178
179     // Called when script modifies window.status
180     virtual void setStatusText(const WebString&) { }
181
182     // Called when hovering over an anchor with the given URL.
183     virtual void setMouseOverURL(const WebURL&) { }
184
185     // Called when keyboard focus switches to an anchor with the given URL.
186     virtual void setKeyboardFocusURL(const WebURL&) { }
187
188     // Called when a drag-n-drop operation should begin.
189     virtual void startDragging(WebLocalFrame*, const WebDragData&, WebDragOperationsMask, const WebImage&, const WebPoint& dragImageOffset) { }
190
191     // Called to determine if drag-n-drop operations may initiate a page
192     // navigation.
193     virtual bool acceptsLoadDrops() { return true; }
194
195     // Take focus away from the WebView by focusing an adjacent UI element
196     // in the containing window.
197     virtual void focusNext() { }
198     virtual void focusPrevious() { }
199
200     // Called when a new node gets focused.
201     virtual void focusedNodeChanged(const WebNode&) { }
202
203     // Indicates two things:
204     //   1) This view may have a new layout now.
205     //   2) Calling layout() is a no-op.
206     // After calling WebWidget::layout(), expect to get this notification
207     // unless the view did not need a layout.
208     virtual void didUpdateLayout() { }
209
210     // Return true to swallow the input event if the embedder will start a disambiguation popup
211     virtual bool didTapMultipleTargets(const WebGestureEvent&, const WebVector<WebRect>& targetRects) { return false; }
212
213     // Returns comma separated list of accept languages.
214     virtual WebString acceptLanguages() { return WebString(); }
215
216
217     // Session history -----------------------------------------------------
218
219     // Tells the embedder to navigate back or forward in session history by
220     // the given offset (relative to the current position in session
221     // history).
222     virtual void navigateBackForwardSoon(int offset) { }
223
224     // Returns the number of history items before/after the current
225     // history item.
226     virtual int historyBackListCount() { return 0; }
227     virtual int historyForwardListCount() { return 0; }
228
229
230     // Accessibility -------------------------------------------------------
231
232     // Notifies embedder about an accessibility event.
233     virtual void postAccessibilityEvent(const WebAXObject&, WebAXEvent) { }
234
235
236     // Developer tools -----------------------------------------------------
237
238     // Called to notify the client that the inspector's settings were
239     // changed and should be saved.  See WebView::inspectorSettings.
240     virtual void didUpdateInspectorSettings() { }
241
242     virtual void didUpdateInspectorSetting(const WebString& key, const WebString& value) { }
243
244
245     // Speech --------------------------------------------------------------
246
247     // Access the embedder API for speech recognition services.
248     virtual WebSpeechRecognizer* speechRecognizer() { return 0; }
249
250
251     // Zoom ----------------------------------------------------------------
252
253     // Informs the browser that the zoom levels for this frame have changed from
254     // the default values.
255     virtual void zoomLimitsChanged(double minimumLevel, double maximumLevel) { }
256
257     // Informs the browser that the zoom level has changed as a result of an
258     // action that wasn't initiated by the client.
259     virtual void zoomLevelChanged() { }
260
261
262     // Navigator Content Utils  --------------------------------------------
263
264     // Registers a new URL handler for the given protocol.
265     virtual void registerProtocolHandler(const WebString& scheme,
266         const WebURL& baseUrl,
267         const WebURL& url,
268         const WebString& title) { }
269
270     // Unregisters a given URL handler for the given protocol.
271     virtual void unregisterProtocolHandler(const WebString& scheme, const WebURL& baseUrl, const WebURL& url) { }
272
273     // Check if a given URL handler is registered for the given protocol.
274     virtual WebCustomHandlersState isProtocolHandlerRegistered(const WebString& scheme, const WebURL& baseUrl, const WebURL& url)
275     {
276         return WebCustomHandlersNew;
277     }
278
279
280     // Visibility -----------------------------------------------------------
281
282     // Returns the current visibility of the WebView.
283     virtual WebPageVisibilityState visibilityState() const
284     {
285         return WebPageVisibilityStateVisible;
286     }
287
288
289     // Push Messaging -------------------------------------------------------
290
291     virtual WebPushClient* webPushClient() { return 0; }
292
293
294     // Content detection ----------------------------------------------------
295
296     // Retrieves detectable content (e.g., email addresses, phone numbers)
297     // around a hit test result. The embedder should use platform-specific
298     // content detectors to analyze the region around the hit test result.
299     virtual WebContentDetectionResult detectContentAround(const WebHitTestResult&) { return WebContentDetectionResult(); }
300
301     // Schedules a new content intent with the provided url.
302     virtual void scheduleContentIntent(const WebURL&) { }
303
304     // Cancels any previously scheduled content intents that have not yet launched.
305     virtual void cancelScheduledContentIntents() { }
306
307
308     // Draggable regions ----------------------------------------------------
309
310     // Informs the browser that the draggable regions have been updated.
311     virtual void draggableRegionsChanged() { }
312
313 protected:
314     ~WebViewClient() { }
315 };
316
317 } // namespace blink
318
319 #endif