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/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"
42 #include "WebNavigatorContentUtilsClient.h"
43 #include "WebPageVisibilityState.h"
44 #include "WebPopupType.h"
45 #include "WebTextAffinity.h"
46 #include "WebTextDirection.h"
47 #include "WebWidgetClient.h"
52 class WebCompositorOutputSurface;
53 class WebDateTimeChooserCompletion;
56 class WebExternalPopupMenu;
57 class WebExternalPopupMenuClient;
58 class WebFileChooserCompletion;
59 class WebGestureEvent;
60 class WebHitTestResult;
62 class WebInputElement;
63 class WebKeyboardEvent;
67 class WebSpeechRecognizer;
68 class WebStorageNamespace;
73 struct WebConsoleMessage;
74 struct WebDateTimeChooserParams;
76 struct WebPopupMenuInfo;
79 struct WebWindowFeatures;
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 {
86 // Factory methods -----------------------------------------------------
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) {
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; }
111 // Create a session storage namespace object associated with this WebView.
112 virtual WebStorageNamespace* createSessionStorageNamespace() { return 0; }
115 // Misc ----------------------------------------------------------------
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*) { }
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; }
130 // Editing -------------------------------------------------------------
132 // These methods allow the client to intercept and overrule editing
134 virtual void didCancelCompositionOnSelectionChange() { }
135 virtual void didChangeContents() { }
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.
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; }
147 // Dialogs -------------------------------------------------------------
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; }
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; }
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) { }
170 // Hide notifation popup for form validation messages.
171 virtual void hideValidationMessage() { }
173 // Move the existing notifation popup to the new anchor position.
174 virtual void moveValidationMessage(const WebRect& anchorInRootView) { }
177 // UI ------------------------------------------------------------------
179 // Called when script modifies window.status
180 virtual void setStatusText(const WebString&) { }
182 // Called when hovering over an anchor with the given URL.
183 virtual void setMouseOverURL(const WebURL&) { }
185 // Called when keyboard focus switches to an anchor with the given URL.
186 virtual void setKeyboardFocusURL(const WebURL&) { }
188 // Called when a drag-n-drop operation should begin.
189 virtual void startDragging(WebLocalFrame*, const WebDragData&, WebDragOperationsMask, const WebImage&, const WebPoint& dragImageOffset) { }
191 // Called to determine if drag-n-drop operations may initiate a page
193 virtual bool acceptsLoadDrops() { return true; }
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() { }
200 // Called when a new node gets focused.
201 virtual void focusedNodeChanged(const WebNode&) { }
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() { }
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; }
213 // Returns comma separated list of accept languages.
214 virtual WebString acceptLanguages() { return WebString(); }
217 // Session history -----------------------------------------------------
219 // Tells the embedder to navigate back or forward in session history by
220 // the given offset (relative to the current position in session
222 virtual void navigateBackForwardSoon(int offset) { }
224 // Returns the number of history items before/after the current
226 virtual int historyBackListCount() { return 0; }
227 virtual int historyForwardListCount() { return 0; }
230 // Accessibility -------------------------------------------------------
232 // Notifies embedder about an accessibility event.
233 virtual void postAccessibilityEvent(const WebAXObject&, WebAXEvent) { }
236 // Developer tools -----------------------------------------------------
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() { }
242 virtual void didUpdateInspectorSetting(const WebString& key, const WebString& value) { }
245 // Speech --------------------------------------------------------------
247 // Access the embedder API for speech recognition services.
248 virtual WebSpeechRecognizer* speechRecognizer() { return 0; }
251 // Zoom ----------------------------------------------------------------
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) { }
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() { }
262 // Navigator Content Utils --------------------------------------------
264 // Registers a new URL handler for the given protocol.
265 virtual void registerProtocolHandler(const WebString& scheme,
266 const WebURL& baseUrl,
268 const WebString& title) { }
270 // Unregisters a given URL handler for the given protocol.
271 virtual void unregisterProtocolHandler(const WebString& scheme, const WebURL& baseUrl, const WebURL& url) { }
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)
276 return WebCustomHandlersNew;
280 // Visibility -----------------------------------------------------------
282 // Returns the current visibility of the WebView.
283 virtual WebPageVisibilityState visibilityState() const
285 return WebPageVisibilityStateVisible;
289 // Push Messaging -------------------------------------------------------
291 virtual WebPushClient* webPushClient() { return 0; }
294 // Content detection ----------------------------------------------------
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(); }
301 // Schedules a new content intent with the provided url.
302 virtual void scheduleContentIntent(const WebURL&) { }
304 // Cancels any previously scheduled content intents that have not yet launched.
305 virtual void cancelScheduledContentIntents() { }
308 // Draggable regions ----------------------------------------------------
310 // Informs the browser that the draggable regions have been updated.
311 virtual void draggableRegionsChanged() { }