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