initial import
[vuplus_webkit] / Source / WebKit / chromium / public / 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 "WebAccessibilityNotification.h"
35 #include "WebDragOperation.h"
36 #include "WebEditingAction.h"
37 #include "WebFileChooserCompletion.h"
38 #include "WebFileChooserParams.h"
39 #include "WebPageVisibilityState.h"
40 #include "WebPopupType.h"
41 #include "WebString.h"
42 #include "WebTextAffinity.h"
43 #include "WebTextDirection.h"
44 #include "WebWidgetClient.h"
45
46 namespace WebKit {
47
48 class WebAccessibilityObject;
49 class WebDeviceOrientationClient;
50 class WebDragData;
51 class WebElement;
52 class WebExternalPopupMenu;
53 class WebExternalPopupMenuClient;
54 class WebFileChooserCompletion;
55 class WebFrame;
56 class WebGeolocationClient;
57 class WebGeolocationService;
58 class WebIconLoadingCompletion;
59 class WebImage;
60 class WebInputElement;
61 class WebKeyboardEvent;
62 class WebNode;
63 class WebNotificationPresenter;
64 class WebRange;
65 class WebSpeechInputController;
66 class WebSpeechInputListener;
67 class WebStorageNamespace;
68 class WebURL;
69 class WebURLRequest;
70 class WebView;
71 class WebWidget;
72 struct WebConsoleMessage;
73 struct WebContextMenuData;
74 struct WebPoint;
75 struct WebPopupMenuInfo;
76 struct WebWindowFeatures;
77
78 // Since a WebView is a WebWidget, a WebViewClient is a WebWidgetClient.
79 // Virtual inheritance allows an implementation of WebWidgetClient to be
80 // easily reused as part of an implementation of WebViewClient.
81 class WebViewClient : virtual public WebWidgetClient {
82 public:
83     // Factory methods -----------------------------------------------------
84
85     // Create a new related WebView.  This method must clone its session storage
86     // so any subsequent calls to createSessionStorageNamespace conform to the
87     // WebStorage specification.
88     // The request parameter is only for the client to check if the request
89     // could be fulfilled.  The client should not load the request.
90     virtual WebView* createView(WebFrame* creator,
91                                 const WebURLRequest& request,
92                                 const WebWindowFeatures& features,
93                                 const WebString& name) {
94         return 0;
95     }
96
97     // Create a new WebPopupMenu.  In the second form, the client is
98     // responsible for rendering the contents of the popup menu.
99     virtual WebWidget* createPopupMenu(WebPopupType) { return 0; }
100     virtual WebWidget* createPopupMenu(const WebPopupMenuInfo&) { return 0; }
101     virtual WebExternalPopupMenu* createExternalPopupMenu(
102         const WebPopupMenuInfo&, WebExternalPopupMenuClient*) { return 0; }
103
104     // Create a session storage namespace object associated with this WebView.
105     virtual WebStorageNamespace* createSessionStorageNamespace(unsigned quota) { return 0; }
106
107     // Misc ----------------------------------------------------------------
108
109     // A new message was added to the console.
110     virtual void didAddMessageToConsole(
111         const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLine) { }
112
113     // Called when script in the page calls window.print().  If frame is
114     // non-null, then it selects a particular frame, including its
115     // children, to print.  Otherwise, the main frame and its children
116     // should be printed.
117     virtual void printPage(WebFrame*) { }
118
119     // Called to retrieve the provider of desktop notifications.
120     virtual WebNotificationPresenter* notificationPresenter() { return 0; }
121
122     // Called to request an icon for the specified filenames.
123     // The icon is shown in a file upload control.
124     virtual bool queryIconForFiles(const WebVector<WebString>& filenames, WebIconLoadingCompletion*) { return false; }
125
126     // This method enumerates all the files in the path. It returns immediately
127     // and asynchronously invokes the WebFileChooserCompletion with all the
128     // files in the directory. Returns false if the WebFileChooserCompletion
129     // will never be called.
130     virtual bool enumerateChosenDirectory(const WebString& path, WebFileChooserCompletion*) { return false; }
131
132
133     // Navigational --------------------------------------------------------
134
135     // These notifications bracket any loading that occurs in the WebView.
136     virtual void didStartLoading() { }
137     virtual void didStopLoading() { }
138
139     // Notification that some progress was made loading the current page.
140     // loadProgress is a value between 0 (nothing loaded) and 1.0 (frame fully
141     // loaded).
142     virtual void didChangeLoadProgress(WebFrame*, double loadProgress) { }
143
144     // Editing -------------------------------------------------------------
145
146     // These methods allow the client to intercept and overrule editing
147     // operations.
148     virtual bool shouldBeginEditing(const WebRange&) { return true; }
149     virtual bool shouldEndEditing(const WebRange&) { return true; }
150     virtual bool shouldInsertNode(
151         const WebNode&, const WebRange&, WebEditingAction) { return true; }
152     virtual bool shouldInsertText(
153         const WebString&, const WebRange&, WebEditingAction) { return true; }
154     virtual bool shouldChangeSelectedRange(
155         const WebRange& from, const WebRange& to, WebTextAffinity,
156         bool stillSelecting) { return true; }
157     virtual bool shouldDeleteRange(const WebRange&) { return true; }
158     virtual bool shouldApplyStyle(const WebString& style, const WebRange&) { return true; }
159
160     virtual bool isSmartInsertDeleteEnabled() { return true; }
161     virtual bool isSelectTrailingWhitespaceEnabled() { return true; }
162
163     virtual void didBeginEditing() { }
164     virtual void didChangeSelection(bool isSelectionEmpty) { }
165     virtual void didChangeContents() { }
166     virtual void didExecuteCommand(const WebString& commandName) { }
167     virtual void didEndEditing() { }
168
169     // This method is called in response to WebView's handleInputEvent()
170     // when the default action for the current keyboard event is not
171     // suppressed by the page, to give the embedder a chance to handle
172     // the keyboard event specially.
173     //
174     // Returns true if the keyboard event was handled by the embedder,
175     // indicating that the default action should be suppressed.
176     virtual bool handleCurrentKeyboardEvent() { return false; }
177
178
179     // Dialogs -------------------------------------------------------------
180
181     // This method returns immediately after showing the dialog. When the
182     // dialog is closed, it should call the WebFileChooserCompletion to
183     // pass the results of the dialog. Returns false if
184     // WebFileChooseCompletion will never be called.
185     virtual bool runFileChooser(const WebFileChooserParams&,
186                                 WebFileChooserCompletion*) { return false; }
187
188     // Displays a modal alert dialog containing the given message.  Returns
189     // once the user dismisses the dialog.
190     virtual void runModalAlertDialog(
191         WebFrame*, const WebString& message) { }
192
193     // Displays a modal confirmation dialog with the given message as
194     // description and OK/Cancel choices.  Returns true if the user selects
195     // 'OK' or false otherwise.
196     virtual bool runModalConfirmDialog(
197         WebFrame*, const WebString& message) { return false; }
198
199     // Displays a modal input dialog with the given message as description
200     // and OK/Cancel choices.  The input field is pre-filled with
201     // defaultValue.  Returns true if the user selects 'OK' or false
202     // otherwise.  Upon returning true, actualValue contains the value of
203     // the input field.
204     virtual bool runModalPromptDialog(
205         WebFrame*, const WebString& message, const WebString& defaultValue,
206         WebString* actualValue) { return false; }
207
208     // Displays a modal confirmation dialog containing the given message as
209     // description and OK/Cancel choices, where 'OK' means that it is okay
210     // to proceed with closing the view.  Returns true if the user selects
211     // 'OK' or false otherwise.
212     virtual bool runModalBeforeUnloadDialog(
213         WebFrame*, const WebString& message) { return true; }
214
215     virtual bool supportsFullscreen() { return false; }
216     virtual void enterFullscreenForNode(const WebNode&) { }
217     virtual void exitFullscreenForNode(const WebNode&) { }
218     virtual void enterFullscreen() { }
219     virtual void exitFullscreen() { }
220
221     // UI ------------------------------------------------------------------
222
223     // Called when script modifies window.status
224     virtual void setStatusText(const WebString&) { }
225
226     // Called when hovering over an anchor with the given URL.
227     virtual void setMouseOverURL(const WebURL&) { }
228
229     // Called when keyboard focus switches to an anchor with the given URL.
230     virtual void setKeyboardFocusURL(const WebURL&) { }
231
232     // Shows a context menu with commands relevant to a specific element on
233     // the given frame. Additional context data is supplied.
234     virtual void showContextMenu(WebFrame*, const WebContextMenuData&) { }
235
236     // Called when a drag-n-drop operation should begin.
237     virtual void startDragging(
238         const WebDragData&, WebDragOperationsMask, const WebImage&, const WebPoint&) { }
239
240     // Called to determine if drag-n-drop operations may initiate a page
241     // navigation.
242     virtual bool acceptsLoadDrops() { return true; }
243
244     // Take focus away from the WebView by focusing an adjacent UI element
245     // in the containing window.
246     virtual void focusNext() { }
247     virtual void focusPrevious() { }
248
249     // Called when a new node gets focused.
250     virtual void focusedNodeChanged(const WebNode&) { }
251
252     virtual void numberOfWheelEventHandlersChanged(unsigned) { }
253
254     // Session history -----------------------------------------------------
255
256     // Tells the embedder to navigate back or forward in session history by
257     // the given offset (relative to the current position in session
258     // history).
259     virtual void navigateBackForwardSoon(int offset) { }
260
261     // Returns the number of history items before/after the current
262     // history item.
263     virtual int historyBackListCount() { return 0; }
264     virtual int historyForwardListCount() { return 0; }
265
266     // Called to notify the embedder when a new history item is added.
267     virtual void didAddHistoryItem() { }
268
269
270     // Accessibility -------------------------------------------------------
271
272     // Notifies embedder about an accessibility notification.
273     virtual void postAccessibilityNotification(const WebAccessibilityObject&, WebAccessibilityNotification) { }
274
275
276     // Developer tools -----------------------------------------------------
277
278     // Called to notify the client that the inspector's settings were
279     // changed and should be saved.  See WebView::inspectorSettings.
280     virtual void didUpdateInspectorSettings() { }
281
282     virtual void didUpdateInspectorSetting(const WebString& key, const WebString& value) { }
283
284     // Geolocation ---------------------------------------------------------
285
286     // Access the embedder API for (client-based) geolocation client .
287     virtual WebGeolocationClient* geolocationClient() { return 0; }
288     // Access the embedder API for (non-client-based) geolocation services.
289     virtual WebGeolocationService* geolocationService() { return 0; }
290
291     // Speech --------------------------------------------------------------
292
293     // Access the embedder API for speech input services.
294     virtual WebSpeechInputController* speechInputController(
295         WebSpeechInputListener*) { return 0; }
296
297     // Device Orientation --------------------------------------------------
298
299     // Access the embedder API for device orientation services.
300     virtual WebDeviceOrientationClient* deviceOrientationClient() { return 0; }
301
302
303     // Zoom ----------------------------------------------------------------
304
305     // Informs the browser that the zoom levels for this frame have changed from
306     // the default values.
307     virtual void zoomLimitsChanged(double minimumLevel, double maximumLevel) { }
308
309     // Informs the browser that the zoom level has changed as a result of an
310     // action that wasn't initiated by the client.
311     virtual void zoomLevelChanged() { }
312
313     // Registers a new URL handler for the given protocol.
314     virtual void registerProtocolHandler(const WebString& scheme,
315                                          const WebString& baseUrl,
316                                          const WebString& url,
317                                          const WebString& title) { }
318
319     // Visibility -----------------------------------------------------------
320
321     // Returns the current visibility of the WebView.
322     virtual WebPageVisibilityState visibilityState() const
323     {
324         return WebPageVisibilityStateVisible;
325     }
326
327 protected:
328     ~WebViewClient() { }
329 };
330
331 } // namespace WebKit
332
333 #endif