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