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 "../../../Platform/chromium/public/WebColor.h"
35 #include "../../../Platform/chromium/public/WebGraphicsContext3D.h"
36 #include "../../../Platform/chromium/public/WebString.h"
37 #include "WebAccessibilityNotification.h"
38 #include "WebContentDetectionResult.h"
39 #include "WebDragOperation.h"
40 #include "WebEditingAction.h"
41 #include "WebFileChooserCompletion.h"
42 #include "WebFileChooserParams.h"
43 #include "WebPageVisibilityState.h"
44 #include "WebPopupType.h"
45 #include "WebTextAffinity.h"
46 #include "WebTextDirection.h"
47 #include "WebWidgetClient.h"
51 class WebAccessibilityObject;
52 class WebBatteryStatusClient;
53 class WebColorChooser;
54 class WebColorChooserClient;
55 class WebCompositorOutputSurface;
56 class WebDateTimeChooserCompletion;
57 class WebDeviceOrientationClient;
60 class WebExternalPopupMenu;
61 class WebExternalPopupMenuClient;
62 class WebFileChooserCompletion;
64 class WebGeolocationClient;
65 class WebGeolocationService;
66 class WebGestureEvent;
67 class WebHelperPlugin;
68 class WebHitTestResult;
69 class WebIconLoadingCompletion;
71 class WebInputElement;
72 class WebKeyboardEvent;
74 class WebNotificationPresenter;
76 class WebSpeechInputController;
77 class WebSpeechInputListener;
78 class WebSpeechRecognizer;
79 class WebStorageNamespace;
82 class WebUserMediaClient;
85 struct WebConsoleMessage;
86 struct WebContextMenuData;
87 struct WebDateTimeChooserParams;
89 struct WebPopupMenuInfo;
92 struct WebWindowFeatures;
94 // Since a WebView is a WebWidget, a WebViewClient is a WebWidgetClient.
95 // Virtual inheritance allows an implementation of WebWidgetClient to be
96 // easily reused as part of an implementation of WebViewClient.
97 class WebViewClient : virtual public WebWidgetClient {
99 // Factory methods -----------------------------------------------------
101 // Create a new related WebView. This method must clone its session storage
102 // so any subsequent calls to createSessionStorageNamespace conform to the
103 // WebStorage specification.
104 // The request parameter is only for the client to check if the request
105 // could be fulfilled. The client should not load the request.
106 // The policy parameter indicates how the new view will be displayed in
107 // WebWidgetClient::show.
108 virtual WebView* createView(WebFrame* creator,
109 const WebURLRequest& request,
110 const WebWindowFeatures& features,
111 const WebString& name,
112 WebNavigationPolicy policy) {
116 // Create a new WebPopupMenu. In the second form, the client is
117 // responsible for rendering the contents of the popup menu.
118 virtual WebWidget* createPopupMenu(WebPopupType) { return 0; }
119 virtual WebWidget* createPopupMenu(const WebPopupMenuInfo&) { return 0; }
120 virtual WebExternalPopupMenu* createExternalPopupMenu(
121 const WebPopupMenuInfo&, WebExternalPopupMenuClient*) { return 0; }
123 // Create a session storage namespace object associated with this WebView.
124 virtual WebStorageNamespace* createSessionStorageNamespace(unsigned quota) { return 0; }
126 // DEPRECATED: Creates a graphics context that renders to the client's WebView.
127 virtual WebGraphicsContext3D* createGraphicsContext3D(const WebGraphicsContext3D::Attributes&) { return 0; }
129 // Creates the output surface that renders to the client's WebView.
130 virtual WebCompositorOutputSurface* createOutputSurface() { return 0; }
132 // Misc ----------------------------------------------------------------
134 // A new message was added to the console.
135 virtual void didAddMessageToConsole(
136 const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLine) { }
138 // Called when script in the page calls window.print(). If frame is
139 // non-null, then it selects a particular frame, including its
140 // children, to print. Otherwise, the main frame and its children
141 // should be printed.
142 virtual void printPage(WebFrame*) { }
144 // Called to retrieve the provider of desktop notifications.
145 virtual WebNotificationPresenter* notificationPresenter() { return 0; }
147 // Called to request an icon for the specified filenames.
148 // The icon is shown in a file upload control.
149 virtual bool queryIconForFiles(const WebVector<WebString>& filenames, WebIconLoadingCompletion*) { return false; }
151 // This method enumerates all the files in the path. It returns immediately
152 // and asynchronously invokes the WebFileChooserCompletion with all the
153 // files in the directory. Returns false if the WebFileChooserCompletion
154 // will never be called.
155 virtual bool enumerateChosenDirectory(const WebString& path, WebFileChooserCompletion*) { return false; }
157 // Creates the main WebFrame for the specified WebHelperPlugin.
158 // Called by WebHelperPlugin to provide the WebFrameClient interface for the WebFrame.
159 virtual void initializeHelperPluginWebFrame(WebHelperPlugin*) { }
162 // Navigational --------------------------------------------------------
164 // These notifications bracket any loading that occurs in the WebView.
165 virtual void didStartLoading() { }
166 virtual void didStopLoading() { }
168 // Notification that some progress was made loading the current page.
169 // loadProgress is a value between 0 (nothing loaded) and 1.0 (frame fully
171 virtual void didChangeLoadProgress(WebFrame*, double loadProgress) { }
173 // Editing -------------------------------------------------------------
175 // These methods allow the client to intercept and overrule editing
177 virtual bool shouldBeginEditing(const WebRange&) { return true; }
178 virtual bool shouldEndEditing(const WebRange&) { return true; }
179 virtual bool shouldInsertNode(
180 const WebNode&, const WebRange&, WebEditingAction) { return true; }
181 virtual bool shouldInsertText(
182 const WebString&, const WebRange&, WebEditingAction) { return true; }
183 virtual bool shouldChangeSelectedRange(
184 const WebRange& from, const WebRange& to, WebTextAffinity,
185 bool stillSelecting) { return true; }
186 virtual bool shouldDeleteRange(const WebRange&) { return true; }
187 virtual bool shouldApplyStyle(const WebString& style, const WebRange&) { return true; }
189 virtual bool isSmartInsertDeleteEnabled() { return true; }
190 virtual bool isSelectTrailingWhitespaceEnabled() { return true; }
192 virtual void didBeginEditing() { }
193 virtual void didCancelCompositionOnSelectionChange() { }
194 virtual void didChangeSelection(bool isSelectionEmpty) { }
195 virtual void didChangeContents() { }
196 virtual void didExecuteCommand(const WebString& commandName) { }
197 virtual void didEndEditing() { }
198 virtual void didChangeFormState(const WebNode&) { }
200 // This method is called in response to WebView's handleInputEvent()
201 // when the default action for the current keyboard event is not
202 // suppressed by the page, to give the embedder a chance to handle
203 // the keyboard event specially.
205 // Returns true if the keyboard event was handled by the embedder,
206 // indicating that the default action should be suppressed.
207 virtual bool handleCurrentKeyboardEvent() { return false; }
209 // Dialogs -------------------------------------------------------------
211 // This method opens the color chooser and returns a new WebColorChooser
212 // instance. If there is a WebColorChooser already from the last time this
213 // was called, it ends the color chooser by calling endChooser, and replaces
214 // it with the new one.
215 virtual WebColorChooser* createColorChooser(WebColorChooserClient*,
216 const WebColor&) { return 0; }
218 // This method returns immediately after showing the dialog. When the
219 // dialog is closed, it should call the WebFileChooserCompletion to
220 // pass the results of the dialog. Returns false if
221 // WebFileChooseCompletion will never be called.
222 virtual bool runFileChooser(const WebFileChooserParams&,
223 WebFileChooserCompletion*) { return false; }
225 // Ask users to choose date/time for the specified parameters. When a user
226 // chooses a value, an implementation of this function should call
227 // WebDateTimeChooserCompletion::didChooseValue or didCancelChooser. If the
228 // implementation opened date/time chooser UI successfully, it should return
229 // true. This function is used only if ExternalDateTimeChooser is used.
230 virtual bool openDateTimeChooser(const WebDateTimeChooserParams&, WebDateTimeChooserCompletion*) { return false; }
232 // Displays a modal alert dialog containing the given message. Returns
233 // once the user dismisses the dialog.
234 virtual void runModalAlertDialog(
235 WebFrame*, const WebString& message) { }
237 // Displays a modal confirmation dialog with the given message as
238 // description and OK/Cancel choices. Returns true if the user selects
239 // 'OK' or false otherwise.
240 virtual bool runModalConfirmDialog(
241 WebFrame*, const WebString& message) { return false; }
243 // Displays a modal input dialog with the given message as description
244 // and OK/Cancel choices. The input field is pre-filled with
245 // defaultValue. Returns true if the user selects 'OK' or false
246 // otherwise. Upon returning true, actualValue contains the value of
248 virtual bool runModalPromptDialog(
249 WebFrame*, const WebString& message, const WebString& defaultValue,
250 WebString* actualValue) { return false; }
252 // Displays a modal confirmation dialog containing the given message as
253 // description and OK/Cancel choices, where 'OK' means that it is okay
254 // to proceed with closing the view. Returns true if the user selects
255 // 'OK' or false otherwise.
256 virtual bool runModalBeforeUnloadDialog(
257 WebFrame*, const WebString& message) { return true; }
260 // UI ------------------------------------------------------------------
262 // Called when script modifies window.status
263 virtual void setStatusText(const WebString&) { }
265 // Called when hovering over an anchor with the given URL.
266 virtual void setMouseOverURL(const WebURL&) { }
268 // Called when keyboard focus switches to an anchor with the given URL.
269 virtual void setKeyboardFocusURL(const WebURL&) { }
271 // Shows a context menu with commands relevant to a specific element on
272 // the given frame. Additional context data is supplied.
273 virtual void showContextMenu(WebFrame*, const WebContextMenuData&) { }
275 // Called when a drag-n-drop operation should begin.
276 virtual void startDragging(WebFrame*, const WebDragData&, WebDragOperationsMask, const WebImage&, const WebPoint& dragImageOffset) { }
278 // Called to determine if drag-n-drop operations may initiate a page
280 virtual bool acceptsLoadDrops() { return true; }
282 // Take focus away from the WebView by focusing an adjacent UI element
283 // in the containing window.
284 virtual void focusNext() { }
285 virtual void focusPrevious() { }
287 // Called when a new node gets focused.
288 virtual void focusedNodeChanged(const WebNode&) { }
290 virtual void numberOfWheelEventHandlersChanged(unsigned) { }
291 virtual void hasTouchEventHandlers(bool) { }
293 // Indicates two things:
294 // 1) This view may have a new layout now.
295 // 2) Calling layout() is a no-op.
296 // After calling WebWidget::layout(), expect to get this notification
297 // unless the view did not need a layout.
298 virtual void didUpdateLayout() { }
300 // Return true to swallow the input event if the embedder will start a disambiguation popup
301 virtual bool didTapMultipleTargets(const WebGestureEvent&, const WebVector<WebRect>& targetRects) { return false; }
303 // Show a notification popup for the specified form vaidation messages
304 // besides the anchor rectangle. An implementation of this function should
305 // not hide the popup until hideValidationMessage call.
306 virtual void showValidationMessage(const WebRect& anchorInScreen, const WebString& mainText, const WebString& supplementalText, WebTextDirection hint) { }
307 // Hide notifation popup for form validation messages.
308 virtual void hideValidationMessage() { }
310 // Session history -----------------------------------------------------
312 // Tells the embedder to navigate back or forward in session history by
313 // the given offset (relative to the current position in session
315 virtual void navigateBackForwardSoon(int offset) { }
317 // Returns the number of history items before/after the current
319 virtual int historyBackListCount() { return 0; }
320 virtual int historyForwardListCount() { return 0; }
322 // Called to notify the embedder when a new history item is added.
323 virtual void didAddHistoryItem() { }
326 // Accessibility -------------------------------------------------------
328 // Notifies embedder about an accessibility notification.
329 virtual void postAccessibilityNotification(const WebAccessibilityObject&, WebAccessibilityNotification) { }
332 // Developer tools -----------------------------------------------------
334 // Called to notify the client that the inspector's settings were
335 // changed and should be saved. See WebView::inspectorSettings.
336 virtual void didUpdateInspectorSettings() { }
338 virtual void didUpdateInspectorSetting(const WebString& key, const WebString& value) { }
340 // Geolocation ---------------------------------------------------------
342 // Access the embedder API for (client-based) geolocation client .
343 virtual WebGeolocationClient* geolocationClient() { return 0; }
344 // Access the embedder API for (non-client-based) geolocation services.
345 virtual WebGeolocationService* geolocationService() { return 0; }
347 // Speech --------------------------------------------------------------
349 // Access the embedder API for speech input services.
350 virtual WebSpeechInputController* speechInputController(
351 WebSpeechInputListener*) { return 0; }
353 // Access the embedder API for speech recognition services.
354 virtual WebSpeechRecognizer* speechRecognizer() { return 0; }
356 // Device Orientation --------------------------------------------------
358 // Access the embedder API for device orientation services.
359 virtual WebDeviceOrientationClient* deviceOrientationClient() { return 0; }
361 // Battery Status ------------------------------------------------------
363 // Access the embedder API for battery status services.
364 virtual WebBatteryStatusClient* batteryStatusClient() { return 0; }
366 // Zoom ----------------------------------------------------------------
368 // Informs the browser that the zoom levels for this frame have changed from
369 // the default values.
370 virtual void zoomLimitsChanged(double minimumLevel, double maximumLevel) { }
372 // Informs the browser that the zoom level has changed as a result of an
373 // action that wasn't initiated by the client.
374 virtual void zoomLevelChanged() { }
376 // Registers a new URL handler for the given protocol.
377 virtual void registerProtocolHandler(const WebString& scheme,
378 const WebString& baseUrl,
379 const WebString& url,
380 const WebString& title) { }
382 // Visibility -----------------------------------------------------------
384 // Returns the current visibility of the WebView.
385 virtual WebPageVisibilityState visibilityState() const
387 return WebPageVisibilityStateVisible;
390 // Media Streams -------------------------------------------------------
392 virtual WebUserMediaClient* userMediaClient() { return 0; }
395 // Content detection ----------------------------------------------------
397 // Retrieves detectable content (e.g., email addresses, phone numbers)
398 // around a hit test result. The embedder should use platform-specific
399 // content detectors to analyze the region around the hit test result.
400 virtual WebContentDetectionResult detectContentAround(const WebHitTestResult&) { return WebContentDetectionResult(); }
402 // Schedules a new content intent with the provided url.
403 virtual void scheduleContentIntent(const WebURL&) { }
405 // Cancels any previously scheduled content intents that have not yet launched.
406 virtual void cancelScheduledContentIntents() { }
408 // Draggable regions ----------------------------------------------------
410 // Informs the browser that the draggable regions have been updated.
411 virtual void draggableRegionsChanged() { }
417 } // namespace WebKit