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