OLD | NEW |
| (Empty) |
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/WebColor.h" | |
35 #include "../platform/WebGraphicsContext3D.h" | |
36 #include "../platform/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" | |
48 | |
49 namespace WebKit { | |
50 | |
51 class WebAccessibilityObject; | |
52 class WebBatteryStatusClient; | |
53 class WebColorChooser; | |
54 class WebColorChooserClient; | |
55 class WebCompositorOutputSurface; | |
56 class WebDateTimeChooserCompletion; | |
57 class WebDeviceOrientationClient; | |
58 class WebDragData; | |
59 class WebElement; | |
60 class WebExternalPopupMenu; | |
61 class WebExternalPopupMenuClient; | |
62 class WebFileChooserCompletion; | |
63 class WebFrame; | |
64 class WebGeolocationClient; | |
65 class WebGeolocationService; | |
66 class WebGestureEvent; | |
67 class WebHelperPlugin; | |
68 class WebHitTestResult; | |
69 class WebIconLoadingCompletion; | |
70 class WebImage; | |
71 class WebInputElement; | |
72 class WebKeyboardEvent; | |
73 class WebNode; | |
74 class WebNotificationPresenter; | |
75 class WebRange; | |
76 class WebSpeechInputController; | |
77 class WebSpeechInputListener; | |
78 class WebSpeechRecognizer; | |
79 class WebStorageNamespace; | |
80 class WebURL; | |
81 class WebURLRequest; | |
82 class WebUserMediaClient; | |
83 class WebView; | |
84 class WebWidget; | |
85 struct WebConsoleMessage; | |
86 struct WebContextMenuData; | |
87 struct WebDateTimeChooserParams; | |
88 struct WebPoint; | |
89 struct WebPopupMenuInfo; | |
90 struct WebRect; | |
91 struct WebSize; | |
92 struct WebWindowFeatures; | |
93 | |
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 { | |
98 public: | |
99 // Factory methods ----------------------------------------------------- | |
100 | |
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) { | |
113 return 0; | |
114 } | |
115 | |
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; } | |
122 | |
123 // Create a session storage namespace object associated with this WebView. | |
124 virtual WebStorageNamespace* createSessionStorageNamespace(unsigned quota) {
return 0; } | |
125 | |
126 | |
127 // Misc ---------------------------------------------------------------- | |
128 | |
129 // A new message was added to the console. | |
130 virtual void didAddMessageToConsole( | |
131 const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLi
ne) { } | |
132 | |
133 // Called when script in the page calls window.print(). If frame is | |
134 // non-null, then it selects a particular frame, including its | |
135 // children, to print. Otherwise, the main frame and its children | |
136 // should be printed. | |
137 virtual void printPage(WebFrame*) { } | |
138 | |
139 // Called to retrieve the provider of desktop notifications. | |
140 virtual WebNotificationPresenter* notificationPresenter() { return 0; } | |
141 | |
142 // Called to request an icon for the specified filenames. | |
143 // The icon is shown in a file upload control. | |
144 virtual bool queryIconForFiles(const WebVector<WebString>& filenames, WebIco
nLoadingCompletion*) { return false; } | |
145 | |
146 // This method enumerates all the files in the path. It returns immediately | |
147 // and asynchronously invokes the WebFileChooserCompletion with all the | |
148 // files in the directory. Returns false if the WebFileChooserCompletion | |
149 // will never be called. | |
150 virtual bool enumerateChosenDirectory(const WebString& path, WebFileChooserC
ompletion*) { return false; } | |
151 | |
152 // Creates the main WebFrame for the specified WebHelperPlugin. | |
153 // Called by WebHelperPlugin to provide the WebFrameClient interface for the
WebFrame. | |
154 virtual void initializeHelperPluginWebFrame(WebHelperPlugin*) { } | |
155 | |
156 | |
157 // Navigational -------------------------------------------------------- | |
158 | |
159 // These notifications bracket any loading that occurs in the WebView. | |
160 virtual void didStartLoading() { } | |
161 virtual void didStopLoading() { } | |
162 | |
163 // Notification that some progress was made loading the current page. | |
164 // loadProgress is a value between 0 (nothing loaded) and 1.0 (frame fully | |
165 // loaded). | |
166 virtual void didChangeLoadProgress(WebFrame*, double loadProgress) { } | |
167 | |
168 // Editing ------------------------------------------------------------- | |
169 | |
170 // These methods allow the client to intercept and overrule editing | |
171 // operations. | |
172 virtual bool shouldBeginEditing(const WebRange&) { return true; } | |
173 virtual bool shouldEndEditing(const WebRange&) { return true; } | |
174 virtual bool shouldInsertNode( | |
175 const WebNode&, const WebRange&, WebEditingAction) { return true; } | |
176 virtual bool shouldInsertText( | |
177 const WebString&, const WebRange&, WebEditingAction) { return true; } | |
178 virtual bool shouldChangeSelectedRange( | |
179 const WebRange& from, const WebRange& to, WebTextAffinity, | |
180 bool stillSelecting) { return true; } | |
181 virtual bool shouldDeleteRange(const WebRange&) { return true; } | |
182 virtual bool shouldApplyStyle(const WebString& style, const WebRange&) { ret
urn true; } | |
183 | |
184 virtual void didBeginEditing() { } | |
185 virtual void didCancelCompositionOnSelectionChange() { } | |
186 virtual void didChangeSelection(bool isSelectionEmpty) { } | |
187 virtual void didChangeContents() { } | |
188 virtual void didExecuteCommand(const WebString& commandName) { } | |
189 virtual void didEndEditing() { } | |
190 virtual void didChangeFormState(const WebNode&) { } | |
191 | |
192 // This method is called in response to WebView's handleInputEvent() | |
193 // when the default action for the current keyboard event is not | |
194 // suppressed by the page, to give the embedder a chance to handle | |
195 // the keyboard event specially. | |
196 // | |
197 // Returns true if the keyboard event was handled by the embedder, | |
198 // indicating that the default action should be suppressed. | |
199 virtual bool handleCurrentKeyboardEvent() { return false; } | |
200 | |
201 // Dialogs ------------------------------------------------------------- | |
202 | |
203 // This method opens the color chooser and returns a new WebColorChooser | |
204 // instance. If there is a WebColorChooser already from the last time this | |
205 // was called, it ends the color chooser by calling endChooser, and replaces | |
206 // it with the new one. | |
207 virtual WebColorChooser* createColorChooser(WebColorChooserClient*, | |
208 const WebColor&) { return 0; } | |
209 | |
210 // This method returns immediately after showing the dialog. When the | |
211 // dialog is closed, it should call the WebFileChooserCompletion to | |
212 // pass the results of the dialog. Returns false if | |
213 // WebFileChooseCompletion will never be called. | |
214 virtual bool runFileChooser(const WebFileChooserParams&, | |
215 WebFileChooserCompletion*) { return false; } | |
216 | |
217 // Ask users to choose date/time for the specified parameters. When a user | |
218 // chooses a value, an implementation of this function should call | |
219 // WebDateTimeChooserCompletion::didChooseValue or didCancelChooser. If the | |
220 // implementation opened date/time chooser UI successfully, it should return | |
221 // true. This function is used only if ExternalDateTimeChooser is used. | |
222 virtual bool openDateTimeChooser(const WebDateTimeChooserParams&, WebDateTim
eChooserCompletion*) { return false; } | |
223 | |
224 // Displays a modal alert dialog containing the given message. Returns | |
225 // once the user dismisses the dialog. | |
226 virtual void runModalAlertDialog( | |
227 WebFrame*, const WebString& message) { } | |
228 | |
229 // Displays a modal confirmation dialog with the given message as | |
230 // description and OK/Cancel choices. Returns true if the user selects | |
231 // 'OK' or false otherwise. | |
232 virtual bool runModalConfirmDialog( | |
233 WebFrame*, const WebString& message) { return false; } | |
234 | |
235 // Displays a modal input dialog with the given message as description | |
236 // and OK/Cancel choices. The input field is pre-filled with | |
237 // defaultValue. Returns true if the user selects 'OK' or false | |
238 // otherwise. Upon returning true, actualValue contains the value of | |
239 // the input field. | |
240 virtual bool runModalPromptDialog( | |
241 WebFrame*, const WebString& message, const WebString& defaultValue, | |
242 WebString* actualValue) { return false; } | |
243 | |
244 // Displays a modal confirmation dialog containing the given message as | |
245 // description and OK/Cancel choices, where 'OK' means that it is okay | |
246 // to proceed with closing the view. Returns true if the user selects | |
247 // 'OK' or false otherwise. | |
248 virtual bool runModalBeforeUnloadDialog( | |
249 WebFrame*, const WebString& message) { return true; } | |
250 | |
251 | |
252 // UI ------------------------------------------------------------------ | |
253 | |
254 // Called when script modifies window.status | |
255 virtual void setStatusText(const WebString&) { } | |
256 | |
257 // Called when hovering over an anchor with the given URL. | |
258 virtual void setMouseOverURL(const WebURL&) { } | |
259 | |
260 // Called when keyboard focus switches to an anchor with the given URL. | |
261 virtual void setKeyboardFocusURL(const WebURL&) { } | |
262 | |
263 // Shows a context menu with commands relevant to a specific element on | |
264 // the given frame. Additional context data is supplied. | |
265 virtual void showContextMenu(WebFrame*, const WebContextMenuData&) { } | |
266 | |
267 // Called when a drag-n-drop operation should begin. | |
268 virtual void startDragging(WebFrame*, const WebDragData&, WebDragOperationsM
ask, const WebImage&, const WebPoint& dragImageOffset) { } | |
269 | |
270 // Called to determine if drag-n-drop operations may initiate a page | |
271 // navigation. | |
272 virtual bool acceptsLoadDrops() { return true; } | |
273 | |
274 // Take focus away from the WebView by focusing an adjacent UI element | |
275 // in the containing window. | |
276 virtual void focusNext() { } | |
277 virtual void focusPrevious() { } | |
278 | |
279 // Called when a new node gets focused. | |
280 virtual void focusedNodeChanged(const WebNode&) { } | |
281 | |
282 virtual void numberOfWheelEventHandlersChanged(unsigned) { } | |
283 | |
284 // Indicates two things: | |
285 // 1) This view may have a new layout now. | |
286 // 2) Calling layout() is a no-op. | |
287 // After calling WebWidget::layout(), expect to get this notification | |
288 // unless the view did not need a layout. | |
289 virtual void didUpdateLayout() { } | |
290 | |
291 // Return true to swallow the input event if the embedder will start a disam
biguation popup | |
292 virtual bool didTapMultipleTargets(const WebGestureEvent&, const WebVector<W
ebRect>& targetRects) { return false; } | |
293 | |
294 // Session history ----------------------------------------------------- | |
295 | |
296 // Tells the embedder to navigate back or forward in session history by | |
297 // the given offset (relative to the current position in session | |
298 // history). | |
299 virtual void navigateBackForwardSoon(int offset) { } | |
300 | |
301 // Returns the number of history items before/after the current | |
302 // history item. | |
303 virtual int historyBackListCount() { return 0; } | |
304 virtual int historyForwardListCount() { return 0; } | |
305 | |
306 // Called to notify the embedder when a new history item is added. | |
307 virtual void didAddHistoryItem() { } | |
308 | |
309 | |
310 // Accessibility ------------------------------------------------------- | |
311 | |
312 // Notifies embedder about an accessibility notification. | |
313 virtual void postAccessibilityNotification(const WebAccessibilityObject&, We
bAccessibilityNotification) { } | |
314 | |
315 | |
316 // Developer tools ----------------------------------------------------- | |
317 | |
318 // Called to notify the client that the inspector's settings were | |
319 // changed and should be saved. See WebView::inspectorSettings. | |
320 virtual void didUpdateInspectorSettings() { } | |
321 | |
322 virtual void didUpdateInspectorSetting(const WebString& key, const WebString
& value) { } | |
323 | |
324 // Geolocation --------------------------------------------------------- | |
325 | |
326 // Access the embedder API for (client-based) geolocation client . | |
327 virtual WebGeolocationClient* geolocationClient() { return 0; } | |
328 // Access the embedder API for (non-client-based) geolocation services. | |
329 virtual WebGeolocationService* geolocationService() { return 0; } | |
330 | |
331 // Speech -------------------------------------------------------------- | |
332 | |
333 // Access the embedder API for speech input services. | |
334 virtual WebSpeechInputController* speechInputController( | |
335 WebSpeechInputListener*) { return 0; } | |
336 | |
337 // Access the embedder API for speech recognition services. | |
338 virtual WebSpeechRecognizer* speechRecognizer() { return 0; } | |
339 | |
340 // Device Orientation -------------------------------------------------- | |
341 | |
342 // Access the embedder API for device orientation services. | |
343 virtual WebDeviceOrientationClient* deviceOrientationClient() { return 0; } | |
344 | |
345 // Battery Status ------------------------------------------------------ | |
346 | |
347 // Access the embedder API for battery status services. | |
348 virtual WebBatteryStatusClient* batteryStatusClient() { return 0; } | |
349 | |
350 // Zoom ---------------------------------------------------------------- | |
351 | |
352 // Informs the browser that the zoom levels for this frame have changed from | |
353 // the default values. | |
354 virtual void zoomLimitsChanged(double minimumLevel, double maximumLevel) { } | |
355 | |
356 // Informs the browser that the zoom level has changed as a result of an | |
357 // action that wasn't initiated by the client. | |
358 virtual void zoomLevelChanged() { } | |
359 | |
360 // Registers a new URL handler for the given protocol. | |
361 virtual void registerProtocolHandler(const WebString& scheme, | |
362 const WebString& baseUrl, | |
363 const WebString& url, | |
364 const WebString& title) { } | |
365 | |
366 // Visibility ----------------------------------------------------------- | |
367 | |
368 // Returns the current visibility of the WebView. | |
369 virtual WebPageVisibilityState visibilityState() const | |
370 { | |
371 return WebPageVisibilityStateVisible; | |
372 } | |
373 | |
374 // Media Streams ------------------------------------------------------- | |
375 | |
376 virtual WebUserMediaClient* userMediaClient() { return 0; } | |
377 | |
378 | |
379 // Content detection ---------------------------------------------------- | |
380 | |
381 // Retrieves detectable content (e.g., email addresses, phone numbers) | |
382 // around a hit test result. The embedder should use platform-specific | |
383 // content detectors to analyze the region around the hit test result. | |
384 virtual WebContentDetectionResult detectContentAround(const WebHitTestResult
&) { return WebContentDetectionResult(); } | |
385 | |
386 // Schedules a new content intent with the provided url. | |
387 virtual void scheduleContentIntent(const WebURL&) { } | |
388 | |
389 // Cancels any previously scheduled content intents that have not yet launch
ed. | |
390 virtual void cancelScheduledContentIntents() { } | |
391 | |
392 // Draggable regions ---------------------------------------------------- | |
393 | |
394 // Informs the browser that the draggable regions have been updated. | |
395 virtual void draggableRegionsChanged() { } | |
396 | |
397 protected: | |
398 ~WebViewClient() { } | |
399 }; | |
400 | |
401 } // namespace WebKit | |
402 | |
403 #endif | |
OLD | NEW |