2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef WebViewClient_h
32 #define WebViewClient_h
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"
48 class WebAccessibilityObject;
49 class WebDeviceOrientationClient;
52 class WebExternalPopupMenu;
53 class WebExternalPopupMenuClient;
54 class WebFileChooserCompletion;
56 class WebGeolocationClient;
57 class WebGeolocationService;
58 class WebIconLoadingCompletion;
60 class WebInputElement;
61 class WebKeyboardEvent;
63 class WebNotificationPresenter;
65 class WebSpeechInputController;
66 class WebSpeechInputListener;
67 class WebStorageNamespace;
72 struct WebConsoleMessage;
73 struct WebContextMenuData;
75 struct WebPopupMenuInfo;
76 struct WebWindowFeatures;
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 {
83 // Factory methods -----------------------------------------------------
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) {
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; }
104 // Create a session storage namespace object associated with this WebView.
105 virtual WebStorageNamespace* createSessionStorageNamespace(unsigned quota) { return 0; }
107 // Misc ----------------------------------------------------------------
109 // A new message was added to the console.
110 virtual void didAddMessageToConsole(
111 const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLine) { }
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*) { }
119 // Called to retrieve the provider of desktop notifications.
120 virtual WebNotificationPresenter* notificationPresenter() { return 0; }
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; }
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; }
133 // Navigational --------------------------------------------------------
135 // These notifications bracket any loading that occurs in the WebView.
136 virtual void didStartLoading() { }
137 virtual void didStopLoading() { }
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
142 virtual void didChangeLoadProgress(WebFrame*, double loadProgress) { }
144 // Editing -------------------------------------------------------------
146 // These methods allow the client to intercept and overrule editing
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; }
160 virtual bool isSmartInsertDeleteEnabled() { return true; }
161 virtual bool isSelectTrailingWhitespaceEnabled() { return true; }
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() { }
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.
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; }
179 // Dialogs -------------------------------------------------------------
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; }
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) { }
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; }
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
204 virtual bool runModalPromptDialog(
205 WebFrame*, const WebString& message, const WebString& defaultValue,
206 WebString* actualValue) { return false; }
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; }
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() { }
221 // UI ------------------------------------------------------------------
223 // Called when script modifies window.status
224 virtual void setStatusText(const WebString&) { }
226 // Called when hovering over an anchor with the given URL.
227 virtual void setMouseOverURL(const WebURL&) { }
229 // Called when keyboard focus switches to an anchor with the given URL.
230 virtual void setKeyboardFocusURL(const WebURL&) { }
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&) { }
236 // Called when a drag-n-drop operation should begin.
237 virtual void startDragging(
238 const WebDragData&, WebDragOperationsMask, const WebImage&, const WebPoint&) { }
240 // Called to determine if drag-n-drop operations may initiate a page
242 virtual bool acceptsLoadDrops() { return true; }
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() { }
249 // Called when a new node gets focused.
250 virtual void focusedNodeChanged(const WebNode&) { }
252 virtual void numberOfWheelEventHandlersChanged(unsigned) { }
254 // Session history -----------------------------------------------------
256 // Tells the embedder to navigate back or forward in session history by
257 // the given offset (relative to the current position in session
259 virtual void navigateBackForwardSoon(int offset) { }
261 // Returns the number of history items before/after the current
263 virtual int historyBackListCount() { return 0; }
264 virtual int historyForwardListCount() { return 0; }
266 // Called to notify the embedder when a new history item is added.
267 virtual void didAddHistoryItem() { }
270 // Accessibility -------------------------------------------------------
272 // Notifies embedder about an accessibility notification.
273 virtual void postAccessibilityNotification(const WebAccessibilityObject&, WebAccessibilityNotification) { }
276 // Developer tools -----------------------------------------------------
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() { }
282 virtual void didUpdateInspectorSetting(const WebString& key, const WebString& value) { }
284 // Geolocation ---------------------------------------------------------
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; }
291 // Speech --------------------------------------------------------------
293 // Access the embedder API for speech input services.
294 virtual WebSpeechInputController* speechInputController(
295 WebSpeechInputListener*) { return 0; }
297 // Device Orientation --------------------------------------------------
299 // Access the embedder API for device orientation services.
300 virtual WebDeviceOrientationClient* deviceOrientationClient() { return 0; }
303 // Zoom ----------------------------------------------------------------
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) { }
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() { }
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) { }
319 // Visibility -----------------------------------------------------------
321 // Returns the current visibility of the WebView.
322 virtual WebPageVisibilityState visibilityState() const
324 return WebPageVisibilityStateVisible;
331 } // namespace WebKit