blob: 2dd241840288d76d6770dad0ecb30542faab61d8 [file] [log] [blame]
[email protected]4fdf6742012-01-10 20:14:361// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]0dd3a0ab2011-02-18 08:17:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]674bc592011-12-20 23:00:425#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_
6#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_
[email protected]0dd3a0ab2011-02-18 08:17:447
[email protected]1de2b8b2011-06-29 19:38:468#include <set>
[email protected]0dd3a0ab2011-02-18 08:17:449#include <string>
[email protected]0dd3a0ab2011-02-18 08:17:4410
11#include "base/basictypes.h"
[email protected]f13b4202012-06-12 23:53:2312#include "base/callback.h"
[email protected]26dd01c2013-06-12 13:52:1313#include "base/strings/string16.h"
[email protected]8d128d62011-09-13 22:11:5714#include "content/common/content_export.h"
[email protected]e6e646d2011-12-01 00:50:1115#include "content/public/browser/navigation_type.h"
[email protected]f13b4202012-06-12 23:53:2316#include "content/public/common/media_stream_request.h"
[email protected]2905f742011-10-13 03:51:5817#include "content/public/common/page_transition_types.h"
[email protected]4fdf6742012-01-10 20:14:3618#include "content/public/common/window_container_type.h"
[email protected]2255a9332013-06-17 05:12:3119#include "third_party/WebKit/public/web/WebDragOperation.h"
[email protected]da8543762012-03-20 08:52:2020#include "third_party/skia/include/core/SkColor.h"
[email protected]f47621b2013-01-22 20:50:3321#include "ui/base/window_open_disposition.h"
[email protected]0dd3a0ab2011-02-18 08:17:4422#include "ui/gfx/native_widget_types.h"
[email protected]59363fc92012-09-05 03:46:3123#include "ui/gfx/rect_f.h"
[email protected]0dd3a0ab2011-02-18 08:17:4424
[email protected]7dba43dc2011-11-10 01:57:5825class GURL;
[email protected]7dba43dc2011-11-10 01:57:5826
[email protected]32ded2212011-11-10 18:51:4327namespace base {
[email protected]a3ef4832013-02-02 05:12:3328class FilePath;
[email protected]32ded2212011-11-10 18:51:4329class ListValue;
30}
31
[email protected]3ab9cb82011-06-03 18:02:0732namespace content {
[email protected]3d7474ff2011-07-27 17:47:3733class BrowserContext;
[email protected]da8543762012-03-20 08:52:2034class ColorChooser;
[email protected]e582fdd2011-12-20 16:48:1735class DownloadItem;
[email protected]71a88bb2013-02-01 22:05:1536class JavaScriptDialogManager;
[email protected]691aa2f2013-05-28 22:52:0437class PageState;
[email protected]c0c1c622012-03-13 04:51:5438class RenderViewHost;
[email protected]dd6730412013-08-14 15:03:3739class SessionStorageNamespace;
[email protected]a81343d232011-12-27 07:39:2040class WebContents;
[email protected]8ff00d72012-10-23 19:12:2141class WebContentsImpl;
[email protected]8bc5ff02013-11-29 06:34:0342struct ColorSuggestion;
[email protected]35be7ec2012-02-12 20:42:5143struct ContextMenuParams;
[email protected]dc293a72013-07-01 11:11:2244struct DropData;
[email protected]e582fdd2011-12-20 16:48:1745struct FileChooserParams;
[email protected]b87ee522012-05-18 15:16:5446struct NativeWebKeyboardEvent;
[email protected]44e55b012013-07-23 14:21:5647struct Referrer;
[email protected]d583e3f22011-12-27 21:38:1748struct SSLStatus;
[email protected]3ab9cb82011-06-03 18:02:0749}
50
[email protected]0dd3a0ab2011-02-18 08:17:4451namespace gfx {
52class Point;
53class Rect;
54class Size;
55}
56
[email protected]180ef242013-11-07 06:50:4657namespace blink {
[email protected]04bce562014-01-30 05:34:5458class WebGestureEvent;
[email protected]16383382012-09-05 23:57:2659class WebLayer;
[email protected]453c1b22013-07-23 09:31:4860struct WebWindowFeatures;
[email protected]16383382012-09-05 23:57:2661}
62
[email protected]674bc592011-12-20 23:00:4263namespace content {
64
[email protected]e5d549d2011-12-28 01:29:2065struct OpenURLParams;
66
[email protected]0dd3a0ab2011-02-18 08:17:4467// Objects implement this interface to get notified about changes in the
[email protected]2a6bc3e2011-12-28 23:51:3368// WebContents and to provide necessary functionality.
[email protected]674bc592011-12-20 23:00:4269class CONTENT_EXPORT WebContentsDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4470 public:
[email protected]674bc592011-12-20 23:00:4271 WebContentsDelegate();
[email protected]1de2b8b2011-06-29 19:38:4672
[email protected]e5d549d2011-12-28 01:29:2073 // Opens a new URL inside the passed in WebContents (if source is 0 open
[email protected]0dd3a0ab2011-02-18 08:17:4474 // in the current front-most tab), unless |disposition| indicates the url
75 // should be opened in a new tab or window.
76 //
77 // A NULL source indicates the current tab (callers should probably use
78 // OpenURL() for these cases which does it for you).
[email protected]00c37fc2011-08-02 00:22:5079
[email protected]e5d549d2011-12-28 01:29:2080 // Returns the WebContents the URL is opened in, or NULL if the URL wasn't
[email protected]992e4542011-07-20 23:09:2581 // opened immediately.
[email protected]e5d549d2011-12-28 01:29:2082 virtual WebContents* OpenURLFromTab(WebContents* source,
[email protected]00c37fc2011-08-02 00:22:5083 const OpenURLParams& params);
84
[email protected]ca13a442012-04-17 14:00:1285 // Called to inform the delegate that the WebContents's navigation state
[email protected]0dd3a0ab2011-02-18 08:17:4486 // changed. The |changed_flags| indicates the parts of the navigation state
87 // that have been updated, and is any combination of the
[email protected]2a6bc3e2011-12-28 23:51:3388 // |WebContents::InvalidateTypes| bits.
89 virtual void NavigationStateChanged(const WebContents* source,
[email protected]229eb7e2011-12-23 01:04:0890 unsigned changed_flags) {}
[email protected]0dd3a0ab2011-02-18 08:17:4491
[email protected]2a6bc3e2011-12-28 23:51:3392 // Creates a new tab with the already-created WebContents 'new_contents'.
[email protected]0dd3a0ab2011-02-18 08:17:4493 // The window for the added contents should be reparented correctly when this
[email protected]dc0fd432013-08-27 15:29:2194 // method returns. If |disposition| is NEW_POPUP, |initial_pos| should hold
95 // the initial position. If |was_blocked| is non-NULL, then |*was_blocked|
96 // will be set to true if the popup gets blocked, and left unchanged
97 // otherwise.
[email protected]2a6bc3e2011-12-28 23:51:3398 virtual void AddNewContents(WebContents* source,
99 WebContents* new_contents,
[email protected]0dd3a0ab2011-02-18 08:17:44100 WindowOpenDisposition disposition,
101 const gfx::Rect& initial_pos,
[email protected]eda238a12012-09-07 23:44:00102 bool user_gesture,
103 bool* was_blocked) {}
[email protected]0dd3a0ab2011-02-18 08:17:44104
105 // Selects the specified contents, bringing its container to the front.
[email protected]2a6bc3e2011-12-28 23:51:33106 virtual void ActivateContents(WebContents* contents) {}
[email protected]0dd3a0ab2011-02-18 08:17:44107
108 // Deactivates the specified contents by deactivating its container and
109 // potentialy moving it to the back of the Z order.
[email protected]2a6bc3e2011-12-28 23:51:33110 virtual void DeactivateContents(WebContents* contents) {}
[email protected]0dd3a0ab2011-02-18 08:17:44111
112 // Notifies the delegate that this contents is starting or is done loading
113 // some resource. The delegate should use this notification to represent
[email protected]2a6bc3e2011-12-28 23:51:33114 // loading feedback. See WebContents::IsLoading()
115 virtual void LoadingStateChanged(WebContents* source) {}
[email protected]0dd3a0ab2011-02-18 08:17:44116
[email protected]0dd3a0ab2011-02-18 08:17:44117 // Notifies the delegate that the page has made some progress loading.
118 // |progress| is a value between 0.0 (nothing loaded) to 1.0 (page fully
119 // loaded).
[email protected]b3996ba2012-08-08 00:39:13120 virtual void LoadProgressChanged(WebContents* source,
121 double progress) {}
[email protected]0dd3a0ab2011-02-18 08:17:44122
[email protected]2a6bc3e2011-12-28 23:51:33123 // Request the delegate to close this web contents, and do whatever cleanup
[email protected]0dd3a0ab2011-02-18 08:17:44124 // it needs to do.
[email protected]a81343d232011-12-27 07:39:20125 virtual void CloseContents(WebContents* source) {}
[email protected]0dd3a0ab2011-02-18 08:17:44126
[email protected]cd9ed79d2011-11-15 19:22:57127 // Informs the delegate that the underlying RenderViewHost has been swapped
128 // out so it can perform any cleanup necessary.
[email protected]2a6bc3e2011-12-28 23:51:33129 virtual void SwappedOut(WebContents* source) {}
[email protected]cd9ed79d2011-11-15 19:22:57130
[email protected]ca13a442012-04-17 14:00:12131 // Request the delegate to move this WebContents to the specified position
[email protected]0dd3a0ab2011-02-18 08:17:44132 // in screen coordinates.
[email protected]2a6bc3e2011-12-28 23:51:33133 virtual void MoveContents(WebContents* source, const gfx::Rect& pos) {}
[email protected]0dd3a0ab2011-02-18 08:17:44134
[email protected]2a6bc3e2011-12-28 23:51:33135 // Called to determine if the WebContents is contained in a popup window
[email protected]b35b26b32011-05-05 20:35:14136 // or a panel window.
[email protected]2a6bc3e2011-12-28 23:51:33137 virtual bool IsPopupOrPanel(const WebContents* source) const;
[email protected]0dd3a0ab2011-02-18 08:17:44138
[email protected]0dd3a0ab2011-02-18 08:17:44139 // Notification that the target URL has changed.
[email protected]2a6bc3e2011-12-28 23:51:33140 virtual void UpdateTargetURL(WebContents* source,
[email protected]229eb7e2011-12-23 01:04:08141 int32 page_id,
142 const GURL& url) {}
[email protected]0dd3a0ab2011-02-18 08:17:44143
144 // Notification that there was a mouse event, along with the absolute
145 // coordinates of the mouse pointer and whether it was a normal motion event
146 // (otherwise, the pointer left the contents area).
[email protected]2a6bc3e2011-12-28 23:51:33147 virtual void ContentsMouseEvent(WebContents* source,
[email protected]229eb7e2011-12-23 01:04:08148 const gfx::Point& location,
149 bool motion) {}
[email protected]0dd3a0ab2011-02-18 08:17:44150
151 // Request the delegate to change the zoom level of the current tab.
[email protected]229eb7e2011-12-23 01:04:08152 virtual void ContentsZoomChange(bool zoom_in) {}
[email protected]0dd3a0ab2011-02-18 08:17:44153
[email protected]067310262012-11-22 14:30:41154 // Called to determine if the WebContents can be overscrolled with touch/wheel
155 // gestures.
156 virtual bool CanOverscrollContent() const;
157
[email protected]888878e82013-07-24 22:49:40158 // Callback that allows vertical overscroll activies to be communicated to the
159 // delegate.
160 virtual void OverscrollUpdate(int delta_y) {}
161
[email protected]b7a756d42012-01-23 18:08:17162 // Return the rect where to display the resize corner, if any, otherwise
163 // an empty rect.
164 virtual gfx::Rect GetRootWindowResizerRect() const;
165
[email protected]0dd3a0ab2011-02-18 08:17:44166 // Invoked prior to showing before unload handler confirmation dialog.
[email protected]229eb7e2011-12-23 01:04:08167 virtual void WillRunBeforeUnloadConfirm() {}
[email protected]0dd3a0ab2011-02-18 08:17:44168
169 // Returns true if javascript dialogs and unload alerts are suppressed.
170 // Default is false.
171 virtual bool ShouldSuppressDialogs();
172
[email protected]a796f202012-05-30 14:14:25173 // Add a message to the console. Returning true indicates that the delegate
174 // handled the message. If false is returned the default logging mechanism
175 // will be used for the message.
[email protected]0c9406632013-02-08 01:13:33176 virtual bool AddMessageToConsole(WebContents* source,
[email protected]a796f202012-05-30 14:14:25177 int32 level,
[email protected]fcf75d42013-12-03 20:11:26178 const base::string16& message,
[email protected]a796f202012-05-30 14:14:25179 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:26180 const base::string16& source_id);
[email protected]a796f202012-05-30 14:14:25181
[email protected]0dd3a0ab2011-02-18 08:17:44182 // Tells us that we've finished firing this tab's beforeunload event.
183 // The proceed bool tells us whether the user chose to proceed closing the
[email protected]a2c92a1c2012-04-03 12:32:14184 // tab. Returns true if the tab can continue on firing its unload event.
[email protected]0dd3a0ab2011-02-18 08:17:44185 // If we're closing the entire browser, then we'll want to delay firing
186 // unload events until all the beforeunload events have fired.
[email protected]2a6bc3e2011-12-28 23:51:33187 virtual void BeforeUnloadFired(WebContents* tab,
[email protected]0dd3a0ab2011-02-18 08:17:44188 bool proceed,
189 bool* proceed_to_fire_unload);
190
[email protected]0c9406632013-02-08 01:13:33191 // Returns true if the location bar should be focused by default rather than
[email protected]af4b5f92013-03-05 07:48:38192 // the page contents. NOTE: this is only used if WebContents can't determine
193 // for itself whether the location bar should be focused by default. For a
194 // complete check, you should use WebContents::FocusLocationBarByDefault().
[email protected]0c9406632013-02-08 01:13:33195 virtual bool ShouldFocusLocationBarByDefault(WebContents* source);
196
[email protected]0dd3a0ab2011-02-18 08:17:44197 // Sets focus to the location bar or some other place that is appropriate.
198 // This is called when the tab wants to encourage user input, like for the
199 // new tab page.
[email protected]229eb7e2011-12-23 01:04:08200 virtual void SetFocusToLocationBar(bool select_all) {}
[email protected]0dd3a0ab2011-02-18 08:17:44201
202 // Returns whether the page should be focused when transitioning from crashed
203 // to live. Default is true.
204 virtual bool ShouldFocusPageAfterCrash();
205
[email protected]0dd3a0ab2011-02-18 08:17:44206 // This is called when WebKit tells us that it is done tabbing through
[email protected]674bc592011-12-20 23:00:42207 // controls on the page. Provides a way for WebContentsDelegates to handle
[email protected]0dd3a0ab2011-02-18 08:17:44208 // this. Returns true if the delegate successfully handled it.
[email protected]0c9406632013-02-08 01:13:33209 virtual bool TakeFocus(WebContents* source,
[email protected]b3996ba2012-08-08 00:39:13210 bool reverse);
[email protected]0dd3a0ab2011-02-18 08:17:44211
212 // Invoked when the page loses mouse capture.
[email protected]229eb7e2011-12-23 01:04:08213 virtual void LostCapture() {}
[email protected]0dd3a0ab2011-02-18 08:17:44214
[email protected]2a6bc3e2011-12-28 23:51:33215 // Notification that |contents| has gained focus.
216 virtual void WebContentsFocused(WebContents* contents) {}
[email protected]0dd3a0ab2011-02-18 08:17:44217
[email protected]686493142011-07-15 21:47:22218 // Asks the delegate if the given tab can download.
[email protected]f85f5032013-04-03 09:01:54219 // Invoking the |callback| synchronously is OK.
220 virtual void CanDownload(RenderViewHost* render_view_host,
[email protected]c0c1c622012-03-13 04:51:54221 int request_id,
[email protected]f85f5032013-04-03 09:01:54222 const std::string& request_method,
223 const base::Callback<void(bool)>& callback);
[email protected]686493142011-07-15 21:47:22224
[email protected]0dd3a0ab2011-02-18 08:17:44225 // Return much extra vertical space should be allotted to the
226 // render view widget during various animations (e.g. infobar closing).
227 // This is used to make painting look smoother.
228 virtual int GetExtraRenderViewHeight() const;
229
[email protected]0dd3a0ab2011-02-18 08:17:44230 // Returns true if the context menu operation was handled by the delegate.
[email protected]63028f52014-02-10 16:45:40231 virtual bool HandleContextMenu(const content::ContextMenuParams& params);
[email protected]0dd3a0ab2011-02-18 08:17:44232
[email protected]ca13a442012-04-17 14:00:12233 // Opens source view for given WebContents that is navigated to the given
[email protected]0dd3a0ab2011-02-18 08:17:44234 // page url.
[email protected]2a6bc3e2011-12-28 23:51:33235 virtual void ViewSourceForTab(WebContents* source, const GURL& page_url);
[email protected]0dd3a0ab2011-02-18 08:17:44236
[email protected]932b7a12011-03-09 12:50:27237 // Opens source view for the given subframe.
[email protected]2a6bc3e2011-12-28 23:51:33238 virtual void ViewSourceForFrame(WebContents* source,
[email protected]932b7a12011-03-09 12:50:27239 const GURL& url,
[email protected]691aa2f2013-05-28 22:52:04240 const PageState& page_state);
[email protected]932b7a12011-03-09 12:50:27241
[email protected]0dd3a0ab2011-02-18 08:17:44242 // Allows delegates to handle keyboard events before sending to the renderer.
243 // Returns true if the |event| was handled. Otherwise, if the |event| would be
244 // handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
245 // |*is_keyboard_shortcut| should be set to true.
[email protected]b3996ba2012-08-08 00:39:13246 virtual bool PreHandleKeyboardEvent(WebContents* source,
247 const NativeWebKeyboardEvent& event,
[email protected]0dd3a0ab2011-02-18 08:17:44248 bool* is_keyboard_shortcut);
249
250 // Allows delegates to handle unhandled keyboard messages coming back from
251 // the renderer.
[email protected]b3996ba2012-08-08 00:39:13252 virtual void HandleKeyboardEvent(WebContents* source,
253 const NativeWebKeyboardEvent& event) {}
[email protected]0dd3a0ab2011-02-18 08:17:44254
[email protected]229eb7e2011-12-23 01:04:08255 virtual void HandleMouseDown() {}
256 virtual void HandleMouseUp() {}
[email protected]590a634e2012-07-19 16:38:23257
258 // Handles activation resulting from a pointer event (e.g. when mouse is
259 // pressed, or a touch-gesture begins).
260 virtual void HandlePointerActivate() {}
261
[email protected]04bce562014-01-30 05:34:54262 // Allows delegates to handle gesture events before sending to the renderer.
263 // Returns true if the |event| was handled and thus shouldn't be processed
264 // by the renderer's event handler. Note that the touch events that create
265 // the gesture are always passed to the renderer since the gesture is created
266 // and dispatched after the touches return without being "preventDefault()"ed.
267 virtual bool PreHandleGestureEvent(
268 WebContents* source,
269 const blink::WebGestureEvent& event);
270
[email protected]590a634e2012-07-19 16:38:23271 virtual void HandleGestureBegin() {}
272 virtual void HandleGestureEnd() {}
[email protected]0dd3a0ab2011-02-18 08:17:44273
[email protected]090550f2013-06-11 15:04:47274 // Called when an external drag event enters the web contents window. Return
275 // true to allow dragging and dropping on the web contents window or false to
276 // cancel the operation. This method is used by Chromium Embedded Framework.
277 virtual bool CanDragEnter(WebContents* source,
[email protected]dc293a72013-07-01 11:11:22278 const DropData& data,
[email protected]180ef242013-11-07 06:50:46279 blink::WebDragOperationsMask operations_allowed);
[email protected]090550f2013-06-11 15:04:47280
[email protected]0dd3a0ab2011-02-18 08:17:44281 // Render view drag n drop ended.
[email protected]229eb7e2011-12-23 01:04:08282 virtual void DragEnded() {}
[email protected]0dd3a0ab2011-02-18 08:17:44283
284 // Shows the repost form confirmation dialog box.
[email protected]2a6bc3e2011-12-28 23:51:33285 virtual void ShowRepostFormWarningDialog(WebContents* source) {}
[email protected]0dd3a0ab2011-02-18 08:17:44286
[email protected]0dd3a0ab2011-02-18 08:17:44287 // Allows delegate to override navigation to the history entries.
[email protected]2a6bc3e2011-12-28 23:51:33288 // Returns true to allow WebContents to continue with the default processing.
[email protected]0dd3a0ab2011-02-18 08:17:44289 virtual bool OnGoToEntryOffset(int offset);
290
[email protected]4fdf6742012-01-10 20:14:36291 // Allows delegate to control whether a WebContents will be created. Returns
[email protected]03b6d552012-03-29 04:03:01292 // true to allow the creation. Default is to allow it. In cases where the
293 // delegate handles the creation/navigation itself, it will use |target_url|.
[email protected]f1cd3362014-01-07 20:43:01294 // The embedder has to synchronously adopt |route_id| or else the view will
295 // be destroyed.
[email protected]4fdf6742012-01-10 20:14:36296 virtual bool ShouldCreateWebContents(
297 WebContents* web_contents,
298 int route_id,
299 WindowContainerType window_container_type,
[email protected]fcf75d42013-12-03 20:11:26300 const base::string16& frame_name,
[email protected]4543b67c2013-07-11 18:18:36301 const GURL& target_url,
[email protected]dd6730412013-08-14 15:03:37302 const std::string& partition_id,
303 SessionStorageNamespace* session_storage_namespace);
[email protected]4fdf6742012-01-10 20:14:36304
[email protected]2a6bc3e2011-12-28 23:51:33305 // Notifies the delegate about the creation of a new WebContents. This
[email protected]0dd3a0ab2011-02-18 08:17:44306 // typically happens when popups are created.
[email protected]4fdf6742012-01-10 20:14:36307 virtual void WebContentsCreated(WebContents* source_contents,
[email protected]a7531d772014-03-25 16:15:07308 int opener_render_frame_id,
[email protected]fcf75d42013-12-03 20:11:26309 const base::string16& frame_name,
[email protected]4fdf6742012-01-10 20:14:36310 const GURL& target_url,
311 WebContents* new_contents) {}
[email protected]0dd3a0ab2011-02-18 08:17:44312
[email protected]55452902011-06-01 21:57:47313 // Notification that the tab is hung.
[email protected]2a6bc3e2011-12-28 23:51:33314 virtual void RendererUnresponsive(WebContents* source) {}
[email protected]55452902011-06-01 21:57:47315
316 // Notification that the tab is no longer hung.
[email protected]2a6bc3e2011-12-28 23:51:33317 virtual void RendererResponsive(WebContents* source) {}
[email protected]0dd3a0ab2011-02-18 08:17:44318
319 // Notification that a worker associated with this tab has crashed.
[email protected]2a6bc3e2011-12-28 23:51:33320 virtual void WorkerCrashed(WebContents* source) {}
[email protected]0dd3a0ab2011-02-18 08:17:44321
[email protected]09b29342011-06-24 19:18:48322 // Invoked when a main fram navigation occurs.
[email protected]3bbacc5b2012-04-17 17:46:15323 virtual void DidNavigateMainFramePostCommit(WebContents* source) {}
[email protected]93f230e02011-06-01 14:40:00324
[email protected]09b29342011-06-24 19:18:48325 // Invoked when navigating to a pending entry. When invoked the
326 // NavigationController has configured its pending entry, but it has not yet
327 // been committed.
[email protected]3bbacc5b2012-04-17 17:46:15328 virtual void DidNavigateToPendingEntry(WebContents* source) {}
[email protected]93f230e02011-06-01 14:40:00329
[email protected]71a88bb2013-02-01 22:05:15330 // Returns a pointer to a service to manage JavaScript dialogs. May return
[email protected]51da7e32012-01-30 19:24:52331 // NULL in which case dialogs aren't shown.
[email protected]71a88bb2013-02-01 22:05:15332 virtual JavaScriptDialogManager* GetJavaScriptDialogManager();
[email protected]3ab9cb82011-06-03 18:02:07333
[email protected]da8543762012-03-20 08:52:20334 // Called when color chooser should open. Returns the opened color chooser.
[email protected]820957a2014-01-14 14:56:30335 // Returns NULL if we failed to open the color chooser (e.g. when there is a
336 // ColorChooserDialog already open on Windows). Ownership of the returned
337 // pointer is transferred to the caller.
[email protected]8bc5ff02013-11-29 06:34:03338 virtual ColorChooser* OpenColorChooser(
339 WebContents* web_contents,
340 SkColor color,
341 const std::vector<ColorSuggestion>& suggestions);
[email protected]da8543762012-03-20 08:52:20342
[email protected]3a29a6e2011-08-24 18:26:21343 // Called when a file selection is to be done.
[email protected]3bbacc5b2012-04-17 17:46:15344 virtual void RunFileChooser(WebContents* web_contents,
[email protected]229eb7e2011-12-23 01:04:08345 const FileChooserParams& params) {}
[email protected]3a29a6e2011-08-24 18:26:21346
347 // Request to enumerate a directory. This is equivalent to running the file
348 // chooser in directory-enumeration mode and having the user select the given
349 // directory.
[email protected]3bbacc5b2012-04-17 17:46:15350 virtual void EnumerateDirectory(WebContents* web_contents,
[email protected]229eb7e2011-12-23 01:04:08351 int request_id,
[email protected]a3ef4832013-02-02 05:12:33352 const base::FilePath& path) {}
[email protected]3a29a6e2011-08-24 18:26:21353
[email protected]4aebbca2013-09-17 22:26:49354 // Returns true if the delegate will embed a WebContents-owned fullscreen
355 // render widget. In this case, the delegate may access the widget by calling
356 // WebContents::GetFullscreenRenderWidgetHostView(). If false is returned,
357 // WebContents will be responsible for showing the fullscreen widget.
358 virtual bool EmbedsFullscreenWidget() const;
359
[email protected]8a5e0ca2011-08-25 06:30:47360 // Called when the renderer puts a tab into or out of fullscreen mode.
[email protected]3bbacc5b2012-04-17 17:46:15361 virtual void ToggleFullscreenModeForTab(WebContents* web_contents,
[email protected]229eb7e2011-12-23 01:04:08362 bool enter_fullscreen) {}
[email protected]3bbacc5b2012-04-17 17:46:15363 virtual bool IsFullscreenForTabOrPending(
364 const WebContents* web_contents) const;
[email protected]8a5e0ca2011-08-25 06:30:47365
[email protected]7d189022011-08-25 22:54:20366 // Register a new handler for URL requests with the given scheme.
[email protected]3a3b75a2012-06-01 08:38:36367 // |user_gesture| is true if the registration is made in the context of a user
368 // gesture.
[email protected]3bbacc5b2012-04-17 17:46:15369 virtual void RegisterProtocolHandler(WebContents* web_contents,
[email protected]7d189022011-08-25 22:54:20370 const std::string& protocol,
371 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:26372 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:36373 bool user_gesture) {}
[email protected]7d189022011-08-25 22:54:20374
[email protected]b888919c2011-09-02 00:32:16375 // Result of string search in the page. This includes the number of matches
376 // found and the selection rect (in screen coordinates) for the string found.
377 // If |final_update| is false, it indicates that more results follow.
[email protected]3bbacc5b2012-04-17 17:46:15378 virtual void FindReply(WebContents* web_contents,
[email protected]b888919c2011-09-02 00:32:16379 int request_id,
380 int number_of_matches,
381 const gfx::Rect& selection_rect,
382 int active_match_ordinal,
[email protected]229eb7e2011-12-23 01:04:08383 bool final_update) {}
[email protected]b888919c2011-09-02 00:32:16384
[email protected]59363fc92012-09-05 03:46:31385#if defined(OS_ANDROID)
386 // Provides the rects of the current find-in-page matches.
387 // Sent as a reply to RequestFindMatchRects.
388 virtual void FindMatchRectsReply(WebContents* web_contents,
389 int version,
390 const std::vector<gfx::RectF>& rects,
391 const gfx::RectF& active_rect) {}
[email protected]59363fc92012-09-05 03:46:31392#endif
393
[email protected]0548c5352011-09-07 00:33:33394 // Invoked when the preferred size of the contents has been changed.
[email protected]3bbacc5b2012-04-17 17:46:15395 virtual void UpdatePreferredSize(WebContents* web_contents,
[email protected]229eb7e2011-12-23 01:04:08396 const gfx::Size& pref_size) {}
[email protected]0548c5352011-09-07 00:33:33397
[email protected]61e2b3cc2012-03-02 16:13:34398 // Invoked when the contents auto-resized and the container should match it.
[email protected]3bbacc5b2012-04-17 17:46:15399 virtual void ResizeDueToAutoResize(WebContents* web_contents,
[email protected]61e2b3cc2012-03-02 16:13:34400 const gfx::Size& new_size) {}
401
[email protected]32ded2212011-11-10 18:51:43402 // Notification message from HTML UI.
[email protected]3bbacc5b2012-04-17 17:46:15403 virtual void WebUISend(WebContents* web_contents,
[email protected]32ded2212011-11-10 18:51:43404 const GURL& source_url,
405 const std::string& name,
[email protected]229eb7e2011-12-23 01:04:08406 const base::ListValue& args) {}
[email protected]32ded2212011-11-10 18:51:43407
[email protected]e9621112011-10-17 05:38:37408 // Requests to lock the mouse. Once the request is approved or rejected,
409 // GotResponseToLockMouseRequest() will be called on the requesting tab
410 // contents.
[email protected]42252e02012-04-26 16:29:39411 virtual void RequestToLockMouse(WebContents* web_contents,
[email protected]a9c81f02012-06-01 00:15:44412 bool user_gesture,
[email protected]f13b4202012-06-12 23:53:23413 bool last_unlocked_by_target) {}
[email protected]e9621112011-10-17 05:38:37414
415 // Notification that the page has lost the mouse lock.
[email protected]229eb7e2011-12-23 01:04:08416 virtual void LostMouseLock() {}
[email protected]e9621112011-10-17 05:38:37417
[email protected]f13b4202012-06-12 23:53:23418 // Asks permission to use the camera and/or microphone. If permission is
419 // granted, a call should be made to |callback| with the devices. If the
420 // request is denied, a call should be made to |callback| with an empty list
421 // of devices. |request| has the details of the request (e.g. which of audio
422 // and/or video devices are requested, and lists of available devices).
423 virtual void RequestMediaAccessPermission(
424 WebContents* web_contents,
[email protected]33662e52013-01-07 21:31:09425 const MediaStreamRequest& request,
[email protected]db3cd9132013-09-03 17:39:23426 const MediaResponseCallback& callback);
[email protected]f13b4202012-06-12 23:53:23427
[email protected]8c8fc292012-11-23 18:57:16428 // Requests permission to access the PPAPI broker. The delegate should return
429 // true and call the passed in |callback| with the result, or return false
430 // to indicate that it does not support asking for permission.
431 virtual bool RequestPpapiBrokerPermission(
432 WebContents* web_contents,
433 const GURL& url,
[email protected]a3ef4832013-02-02 05:12:33434 const base::FilePath& plugin_path,
[email protected]8c8fc292012-11-23 18:57:16435 const base::Callback<void(bool)>& callback);
436
[email protected]dc0fd432013-08-27 15:29:21437 // Returns the size for the new render view created for the pending entry in
438 // |web_contents|; if there's no size, returns an empty size.
439 // This is optional for implementations of WebContentsDelegate; if the
440 // delegate doesn't provide a size, the current WebContentsView's size will be
441 // used.
442 virtual gfx::Size GetSizeForNewRenderView(
443 const WebContents* web_contents) const;
444
[email protected]edc3af82013-12-12 21:24:07445 // Notification that validation of a form displayed by the |web_contents|
446 // has failed. There can only be one message per |web_contents| at a time.
447 virtual void ShowValidationMessage(WebContents* web_contents,
448 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:29449 const base::string16& main_text,
450 const base::string16& sub_text) {}
[email protected]edc3af82013-12-12 21:24:07451
452 // Notification that the delegate should hide any showing form validation
453 // message.
454 virtual void HideValidationMessage(WebContents* web_contents) {}
455
456 // Notification that the form element that triggered the validation failure
457 // has moved.
458 virtual void MoveValidationMessage(WebContents* web_contents,
459 const gfx::Rect& anchor_in_root_view) {}
460
[email protected]0dd3a0ab2011-02-18 08:17:44461 protected:
[email protected]674bc592011-12-20 23:00:42462 virtual ~WebContentsDelegate();
[email protected]1de2b8b2011-06-29 19:38:46463
464 private:
[email protected]8ff00d72012-10-23 19:12:21465 friend class WebContentsImpl;
[email protected]1de2b8b2011-06-29 19:38:46466
[email protected]674bc592011-12-20 23:00:42467 // Called when |this| becomes the WebContentsDelegate for |source|.
[email protected]2a6bc3e2011-12-28 23:51:33468 void Attach(WebContents* source);
[email protected]1de2b8b2011-06-29 19:38:46469
[email protected]674bc592011-12-20 23:00:42470 // Called when |this| is no longer the WebContentsDelegate for |source|.
[email protected]2a6bc3e2011-12-28 23:51:33471 void Detach(WebContents* source);
[email protected]1de2b8b2011-06-29 19:38:46472
[email protected]2a6bc3e2011-12-28 23:51:33473 // The WebContents that this is currently a delegate for.
474 std::set<WebContents*> attached_contents_;
[email protected]0dd3a0ab2011-02-18 08:17:44475};
476
[email protected]674bc592011-12-20 23:00:42477} // namespace content
478
479#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_