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