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