Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / web / WebViewClient.h
blob2e8e4ab1bc9aaf8397301ff7ef00b1b1e679c1d9
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
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.
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.
31 #ifndef WebViewClient_h
32 #define WebViewClient_h
34 #include "../platform/WebGraphicsContext3D.h"
35 #include "../platform/WebPageVisibilityState.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 "WebFrame.h"
43 #include "WebPopupType.h"
44 #include "WebTextAffinity.h"
45 #include "WebTextDirection.h"
46 #include "WebWidgetClient.h"
48 namespace blink {
50 class WebAXObject;
51 class WebDateTimeChooserCompletion;
52 class WebDragData;
53 class WebFileChooserCompletion;
54 class WebHitTestResult;
55 class WebImage;
56 class WebNode;
57 class WebSpeechRecognizer;
58 class WebStorageNamespace;
59 class WebURL;
60 class WebURLRequest;
61 class WebView;
62 class WebWidget;
63 struct WebDateTimeChooserParams;
64 struct WebPoint;
65 struct WebPopupMenuInfo;
66 struct WebRect;
67 struct WebSize;
68 struct WebWindowFeatures;
70 // Since a WebView is a WebWidget, a WebViewClient is a WebWidgetClient.
71 // Virtual inheritance allows an implementation of WebWidgetClient to be
72 // easily reused as part of an implementation of WebViewClient.
73 class WebViewClient : virtual public WebWidgetClient {
74 public:
75 // Factory methods -----------------------------------------------------
77 // Create a new related WebView. This method must clone its session storage
78 // so any subsequent calls to createSessionStorageNamespace conform to the
79 // WebStorage specification.
80 // The request parameter is only for the client to check if the request
81 // could be fulfilled. The client should not load the request.
82 // The policy parameter indicates how the new view will be displayed in
83 // WebWidgetClient::show.
84 virtual WebView* createView(WebLocalFrame* creator,
85 const WebURLRequest& request,
86 const WebWindowFeatures& features,
87 const WebString& name,
88 WebNavigationPolicy policy,
89 bool suppressOpener) {
90 return 0;
93 // Create a new popup WebWidget.
94 virtual WebWidget* createPopupMenu(WebPopupType) { return 0; }
96 // Create a session storage namespace object associated with this WebView.
97 virtual WebStorageNamespace* createSessionStorageNamespace() { return 0; }
100 // Misc ----------------------------------------------------------------
102 // Called when script in the page calls window.print(). If frame is
103 // non-null, then it selects a particular frame, including its
104 // children, to print. Otherwise, the main frame and its children
105 // should be printed.
106 virtual void printPage(WebLocalFrame*) { }
108 // This method enumerates all the files in the path. It returns immediately
109 // and asynchronously invokes the WebFileChooserCompletion with all the
110 // files in the directory. Returns false if the WebFileChooserCompletion
111 // will never be called.
112 virtual bool enumerateChosenDirectory(const WebString& path, WebFileChooserCompletion*) { return false; }
114 // This method is called in response to WebView's saveImageAt(x, y).
115 // A data url from <canvas> or <img> is passed to the method's argument.
116 virtual void saveImageFromDataURL(const WebString&) { }
118 // Called when PageImportanceSignals for the WebView is updated.
119 virtual void pageImportanceSignalsChanged() { }
121 // Editing -------------------------------------------------------------
123 // These methods allow the client to intercept and overrule editing
124 // operations.
125 virtual void didCancelCompositionOnSelectionChange() { }
126 virtual void didChangeContents() { }
128 // This method is called in response to WebView's handleInputEvent()
129 // when the default action for the current keyboard event is not
130 // suppressed by the page, to give the embedder a chance to handle
131 // the keyboard event specially.
133 // Returns true if the keyboard event was handled by the embedder,
134 // indicating that the default action should be suppressed.
135 virtual bool handleCurrentKeyboardEvent() { return false; }
137 // Dialogs -------------------------------------------------------------
139 // This method returns immediately after showing the dialog. When the
140 // dialog is closed, it should call the WebFileChooserCompletion to
141 // pass the results of the dialog. Returns false if
142 // WebFileChooseCompletion will never be called.
143 virtual bool runFileChooser(const WebFileChooserParams&,
144 WebFileChooserCompletion*) { return false; }
146 // Ask users to choose date/time for the specified parameters. When a user
147 // chooses a value, an implementation of this function should call
148 // WebDateTimeChooserCompletion::didChooseValue or didCancelChooser. If the
149 // implementation opened date/time chooser UI successfully, it should return
150 // true. This function is used only if ExternalDateTimeChooser is used.
151 virtual bool openDateTimeChooser(const WebDateTimeChooserParams&, WebDateTimeChooserCompletion*) { return false; }
153 // Show a notification popup for the specified form validation messages
154 // besides the anchor rectangle. An implementation of this function should
155 // not hide the popup until hideValidationMessage call.
156 // FIXME: Clarify anchor coordinates in variable name on Chromium-side.
157 virtual void showValidationMessage(const WebRect& anchorInViewport, const WebString& mainText, WebTextDirection mainTextDir, const WebString& supplementalText, WebTextDirection supplementalTextDir) { }
159 // Hide notifation popup for form validation messages.
160 virtual void hideValidationMessage() { }
162 // Move the existing notifation popup to the new anchor position.
163 // FIXME: Clarify anchor coordinates in variable name on Chromium-side.
164 virtual void moveValidationMessage(const WebRect& anchorInViewport) { }
167 // UI ------------------------------------------------------------------
169 // Called when script modifies window.status
170 virtual void setStatusText(const WebString&) { }
172 // Called when hovering over an anchor with the given URL.
173 virtual void setMouseOverURL(const WebURL&) { }
175 // Called when keyboard focus switches to an anchor with the given URL.
176 virtual void setKeyboardFocusURL(const WebURL&) { }
178 // Called when a drag-n-drop operation should begin.
179 virtual void startDragging(WebLocalFrame*, const WebDragData&, WebDragOperationsMask, const WebImage&, const WebPoint& dragImageOffset) { }
181 // Called to determine if drag-n-drop operations may initiate a page
182 // navigation.
183 virtual bool acceptsLoadDrops() { return true; }
185 // Take focus away from the WebView by focusing an adjacent UI element
186 // in the containing window.
187 virtual void focusNext() { }
188 virtual void focusPrevious() { }
190 // Called when a new node gets focused. |fromNode| is the previously focused node, |toNode|
191 // is the newly focused node. Either can be null.
192 virtual void focusedNodeChanged(const WebNode& fromNode, const WebNode& toNode) { }
194 // Indicates two things:
195 // 1) This view may have a new layout now.
196 // 2) Calling layout() is a no-op.
197 // After calling WebWidget::layout(), expect to get this notification
198 // unless the view did not need a layout.
199 virtual void didUpdateLayout() { }
201 // Return true to swallow the input event if the embedder will start a disambiguation popup
202 virtual bool didTapMultipleTargets(const WebSize& pinchViewportOffset, const WebRect& touchRect, const WebVector<WebRect>& targetRects) { return false; }
204 // Returns comma separated list of accept languages.
205 virtual WebString acceptLanguages() { return WebString(); }
208 // Session history -----------------------------------------------------
210 // Tells the embedder to navigate back or forward in session history by
211 // the given offset (relative to the current position in session
212 // history).
213 virtual void navigateBackForwardSoon(int offset) { }
215 // Returns the number of history items before/after the current
216 // history item.
217 virtual int historyBackListCount() { return 0; }
218 virtual int historyForwardListCount() { return 0; }
221 // Developer tools -----------------------------------------------------
223 // Called to notify the client that the inspector's settings were
224 // changed and should be saved. See WebView::inspectorSettings.
225 virtual void didUpdateInspectorSettings() { }
227 virtual void didUpdateInspectorSetting(const WebString& key, const WebString& value) { }
230 // Speech --------------------------------------------------------------
232 // Access the embedder API for speech recognition services.
233 virtual WebSpeechRecognizer* speechRecognizer() { return 0; }
236 // Zoom ----------------------------------------------------------------
238 // Informs the browser that the zoom levels for this frame have changed from
239 // the default values.
240 virtual void zoomLimitsChanged(double minimumLevel, double maximumLevel) { }
242 // Informs the browser that the page scale has changed.
243 virtual void pageScaleFactorChanged() { }
246 // Visibility -----------------------------------------------------------
248 // Returns the current visibility of the WebView.
249 virtual WebPageVisibilityState visibilityState() const
251 return WebPageVisibilityStateVisible;
255 // Content detection ----------------------------------------------------
257 // Retrieves detectable content (e.g., email addresses, phone numbers)
258 // around a hit test result. The embedder should use platform-specific
259 // content detectors to analyze the region around the hit test result.
260 virtual WebContentDetectionResult detectContentAround(const WebHitTestResult&) { return WebContentDetectionResult(); }
262 // Schedules a new content intent with the provided url.
263 virtual void scheduleContentIntent(const WebURL&) { }
265 // Cancels any previously scheduled content intents that have not yet launched.
266 virtual void cancelScheduledContentIntents() { }
269 // Draggable regions ----------------------------------------------------
271 // Informs the browser that the draggable regions have been updated.
272 virtual void draggableRegionsChanged() { }
274 protected:
275 ~WebViewClient() { }
278 } // namespace blink
280 #endif