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