• 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 "WebDragOperation.h"
35 #include "WebEditingAction.h"
36 #include "WebFileChooserCompletion.h"
37 #include "WebFileChooserParams.h"
38 #include "WebString.h"
39 #include "WebTextAffinity.h"
40 #include "WebTextDirection.h"
41 #include "WebWidgetClient.h"
42 
43 namespace WebKit {
44 
45 class WebAccessibilityObject;
46 class WebDragData;
47 class WebFileChooserCompletion;
48 class WebFrame;
49 class WebNode;
50 class WebNotificationPresenter;
51 class WebRange;
52 class WebStorageNamespace;
53 class WebURL;
54 class WebView;
55 class WebWidget;
56 struct WebConsoleMessage;
57 struct WebContextMenuData;
58 struct WebPoint;
59 struct WebPopupMenuInfo;
60 
61 // Since a WebView is a WebWidget, a WebViewClient is a WebWidgetClient.
62 // Virtual inheritance allows an implementation of WebWidgetClient to be
63 // easily reused as part of an implementation of WebViewClient.
64 class WebViewClient : virtual public WebWidgetClient {
65 public:
66     // Factory methods -----------------------------------------------------
67 
68     // Create a new related WebView.  This method must clone its session storage
69     // so any subsequent calls to createSessionStorageNamespace conform to the
70     // WebStorage specification.
createView(WebFrame * creator)71     virtual WebView* createView(WebFrame* creator) { return 0; }
72 
73     // Create a new WebPopupMenu.  In the second form, the client is
74     // responsible for rendering the contents of the popup menu.
createPopupMenu(bool activatable)75     virtual WebWidget* createPopupMenu(bool activatable) { return 0; }
createPopupMenu(const WebPopupMenuInfo &)76     virtual WebWidget* createPopupMenu(const WebPopupMenuInfo&) { return 0; }
77 
78     // Create a session storage namespace object associated with this WebView.
createSessionStorageNamespace()79     virtual WebStorageNamespace* createSessionStorageNamespace() { return 0; }
80 
81     // Misc ----------------------------------------------------------------
82 
83     // A new message was added to the console.
didAddMessageToConsole(const WebConsoleMessage &,const WebString & sourceName,unsigned sourceLine)84     virtual void didAddMessageToConsole(
85         const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLine) { }
86 
87     // Called when script in the page calls window.print().  If frame is
88     // non-null, then it selects a particular frame, including its
89     // children, to print.  Otherwise, the main frame and its children
90     // should be printed.
printPage(WebFrame *)91     virtual void printPage(WebFrame*) { }
92 
93     // Called to retrieve the provider of desktop notifications.
notificationPresenter()94     virtual WebNotificationPresenter* notificationPresenter() { return 0; }
95 
96 
97     // Navigational --------------------------------------------------------
98 
99     // These notifications bracket any loading that occurs in the WebView.
didStartLoading()100     virtual void didStartLoading() { }
didStopLoading()101     virtual void didStopLoading() { }
102 
103 
104     // Editing -------------------------------------------------------------
105 
106     // These methods allow the client to intercept and overrule editing
107     // operations.
shouldBeginEditing(const WebRange &)108     virtual bool shouldBeginEditing(const WebRange&) { return true; }
shouldEndEditing(const WebRange &)109     virtual bool shouldEndEditing(const WebRange&) { return true; }
shouldInsertNode(const WebNode &,const WebRange &,WebEditingAction)110     virtual bool shouldInsertNode(
111         const WebNode&, const WebRange&, WebEditingAction) { return true; }
shouldInsertText(const WebString &,const WebRange &,WebEditingAction)112     virtual bool shouldInsertText(
113         const WebString&, const WebRange&, WebEditingAction) { return true; }
shouldChangeSelectedRange(const WebRange & from,const WebRange & to,WebTextAffinity,bool stillSelecting)114     virtual bool shouldChangeSelectedRange(
115         const WebRange& from, const WebRange& to, WebTextAffinity,
116         bool stillSelecting) { return true; }
shouldDeleteRange(const WebRange &)117     virtual bool shouldDeleteRange(const WebRange&) { return true; }
shouldApplyStyle(const WebString & style,const WebRange &)118     virtual bool shouldApplyStyle(const WebString& style, const WebRange&) { return true; }
119 
isSmartInsertDeleteEnabled()120     virtual bool isSmartInsertDeleteEnabled() { return true; }
isSelectTrailingWhitespaceEnabled()121     virtual bool isSelectTrailingWhitespaceEnabled() { return true; }
setInputMethodEnabled(bool enabled)122     virtual void setInputMethodEnabled(bool enabled) { }
123 
didBeginEditing()124     virtual void didBeginEditing() { }
didChangeSelection(bool isSelectionEmpty)125     virtual void didChangeSelection(bool isSelectionEmpty) { }
didChangeContents()126     virtual void didChangeContents() { }
didExecuteCommand(const WebString & commandName)127     virtual void didExecuteCommand(const WebString& commandName) { }
didEndEditing()128     virtual void didEndEditing() { }
129 
130     // This method is called in response to WebView's handleInputEvent()
131     // when the default action for the current keyboard event is not
132     // suppressed by the page, to give the embedder a chance to handle
133     // the keyboard event specially.
134     //
135     // Returns true if the keyboard event was handled by the embedder,
136     // indicating that the default action should be suppressed.
handleCurrentKeyboardEvent()137     virtual bool handleCurrentKeyboardEvent() { return false; }
138 
139 
140     // Spellchecker --------------------------------------------------------
141 
142     // The client should perform spell-checking on the given text.  If the
143     // text contains a misspelled word, then upon return misspelledOffset
144     // will point to the start of the misspelled word, and misspelledLength
145     // will indicates its length.  Otherwise, if there was not a spelling
146     // error, then upon return misspelledLength is 0.
spellCheck(const WebString & text,int & misspelledOffset,int & misspelledLength)147     virtual void spellCheck(
148         const WebString& text, int& misspelledOffset, int& misspelledLength) { }
149 
150     // Computes an auto-corrected replacement for a misspelled word.  If no
151     // replacement is found, then an empty string is returned.
autoCorrectWord(const WebString & misspelledWord)152     virtual WebString autoCorrectWord(const WebString& misspelledWord) { return WebString(); }
153 
154     // Show or hide the spelling UI.
showSpellingUI(bool show)155     virtual void showSpellingUI(bool show) { }
156 
157     // Returns true if the spelling UI is showing.
isShowingSpellingUI()158     virtual bool isShowingSpellingUI() { return false; }
159 
160     // Update the spelling UI with the given word.
updateSpellingUIWithMisspelledWord(const WebString & word)161     virtual void updateSpellingUIWithMisspelledWord(const WebString& word) { }
162 
163 
164     // Dialogs -------------------------------------------------------------
165 
166     // This method returns immediately after showing the dialog. When the
167     // dialog is closed, it should call the WebFileChooserCompletion to
168     // pass the results of the dialog. Returns false if
169     // WebFileChooseCompletion will never be called.
runFileChooser(const WebFileChooserParams &,WebFileChooserCompletion *)170     virtual bool runFileChooser(const WebFileChooserParams&,
171                                 WebFileChooserCompletion*) { return false; }
172 
173     // Displays a modal alert dialog containing the given message.  Returns
174     // once the user dismisses the dialog.
runModalAlertDialog(WebFrame *,const WebString & message)175     virtual void runModalAlertDialog(
176         WebFrame*, const WebString& message) { }
177 
178     // Displays a modal confirmation dialog with the given message as
179     // description and OK/Cancel choices.  Returns true if the user selects
180     // 'OK' or false otherwise.
runModalConfirmDialog(WebFrame *,const WebString & message)181     virtual bool runModalConfirmDialog(
182         WebFrame*, const WebString& message) { return false; }
183 
184     // Displays a modal input dialog with the given message as description
185     // and OK/Cancel choices.  The input field is pre-filled with
186     // defaultValue.  Returns true if the user selects 'OK' or false
187     // otherwise.  Upon returning true, actualValue contains the value of
188     // the input field.
runModalPromptDialog(WebFrame *,const WebString & message,const WebString & defaultValue,WebString * actualValue)189     virtual bool runModalPromptDialog(
190         WebFrame*, const WebString& message, const WebString& defaultValue,
191         WebString* actualValue) { return false; }
192 
193     // Displays a modal confirmation dialog containing the given message as
194     // description and OK/Cancel choices, where 'OK' means that it is okay
195     // to proceed with closing the view.  Returns true if the user selects
196     // 'OK' or false otherwise.
runModalBeforeUnloadDialog(WebFrame *,const WebString & message)197     virtual bool runModalBeforeUnloadDialog(
198         WebFrame*, const WebString& message) { return true; }
199 
200 
201     // UI ------------------------------------------------------------------
202 
203     // Called when script modifies window.status
setStatusText(const WebString &)204     virtual void setStatusText(const WebString&) { }
205 
206     // Called when hovering over an anchor with the given URL.
setMouseOverURL(const WebURL &)207     virtual void setMouseOverURL(const WebURL&) { }
208 
209     // Called when keyboard focus switches to an anchor with the given URL.
setKeyboardFocusURL(const WebURL &)210     virtual void setKeyboardFocusURL(const WebURL&) { }
211 
212     // Called when a tooltip should be shown at the current cursor position.
setToolTipText(const WebString &,WebTextDirection hint)213     virtual void setToolTipText(const WebString&, WebTextDirection hint) { }
214 
215     // Shows a context menu with commands relevant to a specific element on
216     // the given frame. Additional context data is supplied.
showContextMenu(WebFrame *,const WebContextMenuData &)217     virtual void showContextMenu(WebFrame*, const WebContextMenuData&) { }
218 
219     // Called when a drag-n-drop operation should begin.
startDragging(const WebPoint & from,const WebDragData &,WebDragOperationsMask)220     virtual void startDragging(
221         const WebPoint& from, const WebDragData&, WebDragOperationsMask) { }
222 
223     // Called to determine if drag-n-drop operations may initiate a page
224     // navigation.
acceptsLoadDrops()225     virtual bool acceptsLoadDrops() { return true; }
226 
227     // Take focus away from the WebView by focusing an adjacent UI element
228     // in the containing window.
focusNext()229     virtual void focusNext() { }
focusPrevious()230     virtual void focusPrevious() { }
231 
232 
233     // Session history -----------------------------------------------------
234 
235     // Tells the embedder to navigate back or forward in session history by
236     // the given offset (relative to the current position in session
237     // history).
navigateBackForwardSoon(int offset)238     virtual void navigateBackForwardSoon(int offset) { }
239 
240     // Returns the number of history items before/after the current
241     // history item.
historyBackListCount()242     virtual int historyBackListCount() { return 0; }
historyForwardListCount()243     virtual int historyForwardListCount() { return 0; }
244 
245     // Called to notify the embedder when a new history item is added.
didAddHistoryItem()246     virtual void didAddHistoryItem() { }
247 
248 
249     // Accessibility -------------------------------------------------------
250 
251     // Notifies embedder that the focus has changed to the given
252     // accessibility object.
focusAccessibilityObject(const WebAccessibilityObject &)253     virtual void focusAccessibilityObject(const WebAccessibilityObject&) { }
254 
255     // Notifies embedder that the state of an accessibility object has changed.
didChangeAccessibilityObjectState(const WebAccessibilityObject &)256     virtual void didChangeAccessibilityObjectState(const WebAccessibilityObject&) { }
257 
258 
259     // Developer tools -----------------------------------------------------
260 
261     // Called to notify the client that the inspector's settings were
262     // changed and should be saved.  See WebView::inspectorSettings.
didUpdateInspectorSettings()263     virtual void didUpdateInspectorSettings() { }
264 
265 
266     // Autofill ------------------------------------------------------------
267 
268     // Queries the browser for suggestions to be shown for the form text
269     // field named |name|.  |value| is the text entered by the user so
270     // far and the WebNode corresponds to the input field.
queryAutofillSuggestions(const WebNode &,const WebString & name,const WebString & value)271     virtual void queryAutofillSuggestions(const WebNode&,
272                                           const WebString& name,
273                                           const WebString& value) { }
274 
275     // Instructs the browser to remove the autofill entry specified from
276     // its DB.
removeAutofillSuggestions(const WebString & name,const WebString & value)277     virtual void removeAutofillSuggestions(const WebString& name,
278                                            const WebString& value) { }
279 
280 protected:
~WebViewClient()281     ~WebViewClient() { }
282 };
283 
284 } // namespace WebKit
285 
286 #endif
287