[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 5 | #ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_ |
| 6 | #define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_ |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 7 | #pragma once |
| 8 | |
[email protected] | 1de2b8b | 2011-06-29 19:38:46 | [diff] [blame] | 9 | #include <set> |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 10 | #include <string> |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 11 | |
| 12 | #include "base/basictypes.h" |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 13 | #include "base/string16.h" |
[email protected] | 8d128d6 | 2011-09-13 22:11:57 | [diff] [blame] | 14 | #include "content/common/content_export.h" |
[email protected] | e6e646d | 2011-12-01 00:50:11 | [diff] [blame] | 15 | #include "content/public/browser/navigation_type.h" |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 16 | #include "content/public/common/page_transition_types.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 17 | #include "content/public/common/window_container_type.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 18 | #include "third_party/skia/include/core/SkColor.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 19 | #include "ui/gfx/native_widget_types.h" |
| 20 | #include "webkit/glue/window_open_disposition.h" |
| 21 | |
[email protected] | 7dba43dc | 2011-11-10 01:57:58 | [diff] [blame] | 22 | class FilePath; |
| 23 | class GURL; |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 24 | class WebContentsImpl; |
[email protected] | 7dba43dc | 2011-11-10 01:57:58 | [diff] [blame] | 25 | struct NativeWebKeyboardEvent; |
[email protected] | 7dba43dc | 2011-11-10 01:57:58 | [diff] [blame] | 26 | |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 27 | namespace base { |
| 28 | class ListValue; |
| 29 | } |
| 30 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 31 | namespace content { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 32 | class BrowserContext; |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 33 | class ColorChooser; |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 34 | class DownloadItem; |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 35 | class JavaScriptDialogCreator; |
[email protected] | c0c1c62 | 2012-03-13 04:51:54 | [diff] [blame] | 36 | class RenderViewHost; |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 37 | class WebContents; |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 38 | class WebIntentsDispatcher; |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 39 | struct ContextMenuParams; |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 40 | struct FileChooserParams; |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 41 | struct SSLStatus; |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 42 | } |
| 43 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 44 | namespace gfx { |
| 45 | class Point; |
| 46 | class Rect; |
| 47 | class Size; |
| 48 | } |
| 49 | |
| 50 | namespace history { |
| 51 | class HistoryAddPageArgs; |
| 52 | } |
| 53 | |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 54 | namespace webkit_glue { |
| 55 | struct WebIntentData; |
| 56 | } |
| 57 | |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 58 | namespace content { |
| 59 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 60 | struct OpenURLParams; |
| 61 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 62 | // Objects implement this interface to get notified about changes in the |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 63 | // WebContents and to provide necessary functionality. |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 64 | class CONTENT_EXPORT WebContentsDelegate { |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 65 | public: |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 66 | WebContentsDelegate(); |
[email protected] | 1de2b8b | 2011-06-29 19:38:46 | [diff] [blame] | 67 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 68 | // Opens a new URL inside the passed in WebContents (if source is 0 open |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 69 | // in the current front-most tab), unless |disposition| indicates the url |
| 70 | // should be opened in a new tab or window. |
| 71 | // |
| 72 | // A NULL source indicates the current tab (callers should probably use |
| 73 | // OpenURL() for these cases which does it for you). |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 74 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 75 | // Returns the WebContents the URL is opened in, or NULL if the URL wasn't |
[email protected] | 992e454 | 2011-07-20 23:09:25 | [diff] [blame] | 76 | // opened immediately. |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 77 | virtual WebContents* OpenURLFromTab(WebContents* source, |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 78 | const OpenURLParams& params); |
| 79 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame^] | 80 | // Called to inform the delegate that the WebContents's navigation state |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 81 | // changed. The |changed_flags| indicates the parts of the navigation state |
| 82 | // that have been updated, and is any combination of the |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 83 | // |WebContents::InvalidateTypes| bits. |
| 84 | virtual void NavigationStateChanged(const WebContents* source, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 85 | unsigned changed_flags) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 86 | |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 87 | // Adds the navigation request headers to |headers|. Use |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 88 | // net::HttpUtil::AppendHeaderIfMissing to build the set of headers. |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 89 | virtual void AddNavigationHeaders(const GURL& url, std::string* headers) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 90 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 91 | // Creates a new tab with the already-created WebContents 'new_contents'. |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 92 | // The window for the added contents should be reparented correctly when this |
| 93 | // method returns. If |disposition| is NEW_POPUP, |pos| should hold the |
| 94 | // initial position. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 95 | virtual void AddNewContents(WebContents* source, |
| 96 | WebContents* new_contents, |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 97 | WindowOpenDisposition disposition, |
| 98 | const gfx::Rect& initial_pos, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 99 | bool user_gesture) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 100 | |
| 101 | // Selects the specified contents, bringing its container to the front. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 102 | virtual void ActivateContents(WebContents* contents) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 103 | |
| 104 | // Deactivates the specified contents by deactivating its container and |
| 105 | // potentialy moving it to the back of the Z order. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 106 | virtual void DeactivateContents(WebContents* contents) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 107 | |
| 108 | // Notifies the delegate that this contents is starting or is done loading |
| 109 | // some resource. The delegate should use this notification to represent |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 110 | // loading feedback. See WebContents::IsLoading() |
| 111 | virtual void LoadingStateChanged(WebContents* source) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 112 | |
| 113 | // Notifies the delegate that the page has made some progress loading. |
| 114 | // |progress| is a value between 0.0 (nothing loaded) to 1.0 (page fully |
| 115 | // loaded). |
| 116 | // Note that to receive this notification, you must have called |
| 117 | // SetReportLoadProgressEnabled(true) in the render view. |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 118 | virtual void LoadProgressChanged(double progress) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 119 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 120 | // Request the delegate to close this web contents, and do whatever cleanup |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 121 | // it needs to do. |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 122 | virtual void CloseContents(WebContents* source) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 123 | |
[email protected] | cd9ed79d | 2011-11-15 19:22:57 | [diff] [blame] | 124 | // Informs the delegate that the underlying RenderViewHost has been swapped |
| 125 | // out so it can perform any cleanup necessary. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 126 | virtual void SwappedOut(WebContents* source) {} |
[email protected] | cd9ed79d | 2011-11-15 19:22:57 | [diff] [blame] | 127 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame^] | 128 | // Request the delegate to move this WebContents to the specified position |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 129 | // in screen coordinates. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 130 | virtual void MoveContents(WebContents* source, const gfx::Rect& pos) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 131 | |
| 132 | // Causes the delegate to detach |source| and clean up any internal data |
| 133 | // pointing to it. After this call ownership of |source| passes to the |
| 134 | // caller, and it is safe to call "source->set_delegate(someone_else);". |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 135 | virtual void DetachContents(WebContents* source) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 136 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 137 | // Called to determine if the WebContents is contained in a popup window |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 138 | // or a panel window. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 139 | virtual bool IsPopupOrPanel(const WebContents* source) const; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 140 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 141 | // Notification that the target URL has changed. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 142 | virtual void UpdateTargetURL(WebContents* source, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 143 | int32 page_id, |
| 144 | const GURL& url) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 145 | |
| 146 | // Notification that there was a mouse event, along with the absolute |
| 147 | // coordinates of the mouse pointer and whether it was a normal motion event |
| 148 | // (otherwise, the pointer left the contents area). |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 149 | virtual void ContentsMouseEvent(WebContents* source, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 150 | const gfx::Point& location, |
| 151 | bool motion) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 152 | |
| 153 | // Request the delegate to change the zoom level of the current tab. |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 154 | virtual void ContentsZoomChange(bool zoom_in) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 155 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 156 | // Check whether this contents is inside a window dedicated to running a web |
| 157 | // application. |
| 158 | virtual bool IsApplication() const; |
| 159 | |
[email protected] | 24e1825 | 2012-04-16 21:26:27 | [diff] [blame] | 160 | // Check whether this contents is permitted to load data URLs in WebUI mode. |
| 161 | // This is normally disallowed for security. |
| 162 | virtual bool CanLoadDataURLsInWebUI() const; |
| 163 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 164 | // Detach the given tab and convert it to a "webapp" view. The tab must be |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 165 | // a WebContents with a valid WebApp set. |
| 166 | virtual void ConvertContentsToApplication(WebContents* source) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 167 | |
| 168 | // Whether the specified tab can be reloaded. |
| 169 | // Reloading can be disabled e. g. for the DevTools window. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 170 | virtual bool CanReloadContents(WebContents* source) const; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 171 | |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 172 | // Return the rect where to display the resize corner, if any, otherwise |
| 173 | // an empty rect. |
| 174 | virtual gfx::Rect GetRootWindowResizerRect() const; |
| 175 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 176 | // Invoked prior to showing before unload handler confirmation dialog. |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 177 | virtual void WillRunBeforeUnloadConfirm() {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 178 | |
| 179 | // Returns true if javascript dialogs and unload alerts are suppressed. |
| 180 | // Default is false. |
| 181 | virtual bool ShouldSuppressDialogs(); |
| 182 | |
| 183 | // Tells us that we've finished firing this tab's beforeunload event. |
| 184 | // The proceed bool tells us whether the user chose to proceed closing the |
[email protected] | a2c92a1c | 2012-04-03 12:32:14 | [diff] [blame] | 185 | // tab. Returns true if the tab can continue on firing its unload event. |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 186 | // If we're closing the entire browser, then we'll want to delay firing |
| 187 | // unload events until all the beforeunload events have fired. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 188 | virtual void BeforeUnloadFired(WebContents* tab, |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 189 | bool proceed, |
| 190 | bool* proceed_to_fire_unload); |
| 191 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 192 | // Sets focus to the location bar or some other place that is appropriate. |
| 193 | // This is called when the tab wants to encourage user input, like for the |
| 194 | // new tab page. |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 195 | virtual void SetFocusToLocationBar(bool select_all) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 196 | |
| 197 | // Returns whether the page should be focused when transitioning from crashed |
| 198 | // to live. Default is true. |
| 199 | virtual bool ShouldFocusPageAfterCrash(); |
| 200 | |
| 201 | // Called when a popup select is about to be displayed. The delegate can use |
| 202 | // this to disable inactive rendering for the frame in the window the select |
| 203 | // is opened within if necessary. |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 204 | virtual void RenderWidgetShowing() {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 205 | |
| 206 | // This is called when WebKit tells us that it is done tabbing through |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 207 | // controls on the page. Provides a way for WebContentsDelegates to handle |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 208 | // this. Returns true if the delegate successfully handled it. |
| 209 | virtual bool TakeFocus(bool reverse); |
| 210 | |
| 211 | // Invoked when the page loses mouse capture. |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 212 | virtual void LostCapture() {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 213 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 214 | // Notification that |contents| has gained focus. |
| 215 | virtual void WebContentsFocused(WebContents* contents) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 216 | |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 217 | // Asks the delegate if the given tab can download. |
[email protected] | c0c1c62 | 2012-03-13 04:51:54 | [diff] [blame] | 218 | virtual bool CanDownload(RenderViewHost* render_view_host, |
| 219 | int request_id, |
| 220 | const std::string& request_method); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 221 | |
| 222 | // Notifies the delegate that a download is starting. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 223 | virtual void OnStartDownload(WebContents* source, DownloadItem* download) {} |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 224 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 225 | // 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] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 230 | // Returns true if the context menu operation was handled by the delegate. |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 231 | virtual bool HandleContextMenu(const content::ContextMenuParams& params); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 232 | |
| 233 | // Returns true if the context menu command was handled |
| 234 | virtual bool ExecuteContextMenuCommand(int command); |
| 235 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame^] | 236 | // Opens source view for given WebContents that is navigated to the given |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 237 | // page url. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 238 | virtual void ViewSourceForTab(WebContents* source, const GURL& page_url); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 239 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 240 | // Opens source view for the given subframe. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 241 | virtual void ViewSourceForFrame(WebContents* source, |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 242 | const GURL& url, |
| 243 | const std::string& content_state); |
| 244 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 245 | // Allows delegates to handle keyboard events before sending to the renderer. |
| 246 | // Returns true if the |event| was handled. Otherwise, if the |event| would be |
| 247 | // handled in HandleKeyboardEvent() method as a normal keyboard shortcut, |
| 248 | // |*is_keyboard_shortcut| should be set to true. |
| 249 | virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 250 | bool* is_keyboard_shortcut); |
| 251 | |
| 252 | // Allows delegates to handle unhandled keyboard messages coming back from |
| 253 | // the renderer. |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 254 | virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 255 | |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 256 | virtual void HandleMouseDown() {} |
| 257 | virtual void HandleMouseUp() {} |
| 258 | virtual void HandleMouseActivate() {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 259 | |
| 260 | // Render view drag n drop ended. |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 261 | virtual void DragEnded() {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 262 | |
| 263 | // Shows the repost form confirmation dialog box. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 264 | virtual void ShowRepostFormWarningDialog(WebContents* source) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 265 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 266 | // Allows delegate to override navigation to the history entries. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 267 | // Returns true to allow WebContents to continue with the default processing. |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 268 | virtual bool OnGoToEntryOffset(int offset); |
| 269 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame^] | 270 | // Returns whether this WebContents should add the specified navigation to |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 271 | // history. |
| 272 | virtual bool ShouldAddNavigationToHistory( |
| 273 | const history::HistoryAddPageArgs& add_page_args, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 274 | NavigationType navigation_type); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 275 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame^] | 276 | // Returns the native window framing the view containing the WebContents. |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 277 | virtual gfx::NativeWindow GetFrameNativeWindow(); |
| 278 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 279 | // Allows delegate to control whether a WebContents will be created. Returns |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 280 | // true to allow the creation. Default is to allow it. In cases where the |
| 281 | // delegate handles the creation/navigation itself, it will use |target_url|. |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 282 | virtual bool ShouldCreateWebContents( |
| 283 | WebContents* web_contents, |
| 284 | int route_id, |
| 285 | WindowContainerType window_container_type, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 286 | const string16& frame_name, |
| 287 | const GURL& target_url); |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 288 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 289 | // Notifies the delegate about the creation of a new WebContents. This |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 290 | // typically happens when popups are created. |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 291 | virtual void WebContentsCreated(WebContents* source_contents, |
| 292 | int64 source_frame_id, |
| 293 | const GURL& target_url, |
| 294 | WebContents* new_contents) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 295 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 296 | // Notifies the delegate that the content restrictions for this tab has |
| 297 | // changed. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 298 | virtual void ContentRestrictionsChanged(WebContents* source) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 299 | |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 300 | // Notification that the tab is hung. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 301 | virtual void RendererUnresponsive(WebContents* source) {} |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 302 | |
| 303 | // Notification that the tab is no longer hung. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 304 | virtual void RendererResponsive(WebContents* source) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 305 | |
| 306 | // Notification that a worker associated with this tab has crashed. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 307 | virtual void WorkerCrashed(WebContents* source) {} |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 308 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 309 | // Invoked when a main fram navigation occurs. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 310 | virtual void DidNavigateMainFramePostCommit(WebContents* tab) {} |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 311 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 312 | // Invoked when navigating to a pending entry. When invoked the |
| 313 | // NavigationController has configured its pending entry, but it has not yet |
| 314 | // been committed. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 315 | virtual void DidNavigateToPendingEntry(WebContents* tab) {} |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 316 | |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 317 | // Returns a pointer to a service to create JavaScript dialogs. May return |
| 318 | // NULL in which case dialogs aren't shown. |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 319 | virtual JavaScriptDialogCreator* GetJavaScriptDialogCreator(); |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 320 | |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 321 | // Called when color chooser should open. Returns the opened color chooser. |
| 322 | virtual content::ColorChooser* OpenColorChooser(WebContents* tab, |
| 323 | int color_chooser_id, |
| 324 | const SkColor& color); |
| 325 | |
| 326 | virtual void DidEndColorChooser() {} |
| 327 | |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 328 | // Called when a file selection is to be done. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 329 | virtual void RunFileChooser(WebContents* tab, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 330 | const FileChooserParams& params) {} |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 331 | |
| 332 | // Request to enumerate a directory. This is equivalent to running the file |
| 333 | // chooser in directory-enumeration mode and having the user select the given |
| 334 | // directory. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 335 | virtual void EnumerateDirectory(WebContents* tab, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 336 | int request_id, |
| 337 | const FilePath& path) {} |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 338 | |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 339 | // Called when the renderer puts a tab into or out of fullscreen mode. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 340 | virtual void ToggleFullscreenModeForTab(WebContents* tab, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 341 | bool enter_fullscreen) {} |
[email protected] | 199bba6e | 2012-04-04 16:19:38 | [diff] [blame] | 342 | virtual bool IsFullscreenForTabOrPending(const WebContents* tab) const; |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 343 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 344 | // Called when a Javascript out of memory notification is received. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 345 | virtual void JSOutOfMemory(WebContents* tab) {} |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 346 | |
| 347 | // Register a new handler for URL requests with the given scheme. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 348 | virtual void RegisterProtocolHandler(WebContents* tab, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 349 | const std::string& protocol, |
| 350 | const GURL& url, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 351 | const string16& title) {} |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 352 | |
| 353 | // Register a new handler for Intents with the given action and type filter. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 354 | virtual void RegisterIntentHandler(WebContents* tab, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 355 | const string16& action, |
| 356 | const string16& type, |
| 357 | const string16& href, |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 358 | const string16& title, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 359 | const string16& disposition) {} |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 360 | |
[email protected] | 0b5af6f | 2012-02-03 23:14:16 | [diff] [blame] | 361 | // Web Intents notification handler. See WebIntentsDispatcher for |
| 362 | // documentation of callee responsibility for the dispatcher. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 363 | virtual void WebIntentDispatch(WebContents* tab, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 364 | WebIntentsDispatcher* intents_dispatcher); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 365 | |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 366 | // Result of string search in the page. This includes the number of matches |
| 367 | // found and the selection rect (in screen coordinates) for the string found. |
| 368 | // If |final_update| is false, it indicates that more results follow. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 369 | virtual void FindReply(WebContents* tab, |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 370 | int request_id, |
| 371 | int number_of_matches, |
| 372 | const gfx::Rect& selection_rect, |
| 373 | int active_match_ordinal, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 374 | bool final_update) {} |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 375 | |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 376 | // Notification that a plugin has crashed. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 377 | virtual void CrashedPlugin(WebContents* tab, const FilePath& plugin_path) {} |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 378 | |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 379 | // Notication that the given plugin has hung or become unhung. This |
| 380 | // notification is only for Pepper plugins. |
| 381 | // |
| 382 | // The plugin_child_id is the unique child process ID from the plugin. Note |
| 383 | // that this ID is supplied by the renderer, so should be validated before |
| 384 | // it's used for anything in case there's an exploited renderer. |
| 385 | virtual void PluginHungStatusChanged(WebContents* tab, |
| 386 | int plugin_child_id, |
| 387 | const FilePath& plugin_path, |
| 388 | bool is_hung) {} |
| 389 | |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 390 | // Invoked when the preferred size of the contents has been changed. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 391 | virtual void UpdatePreferredSize(WebContents* tab, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 392 | const gfx::Size& pref_size) {} |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 393 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 394 | // Invoked when the contents auto-resized and the container should match it. |
| 395 | virtual void ResizeDueToAutoResize(WebContents* tab, |
| 396 | const gfx::Size& new_size) {} |
| 397 | |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 398 | // Notification message from HTML UI. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 399 | virtual void WebUISend(WebContents* tab, |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 400 | const GURL& source_url, |
| 401 | const std::string& name, |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 402 | const base::ListValue& args) {} |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 403 | |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 404 | // Requests to lock the mouse. Once the request is approved or rejected, |
| 405 | // GotResponseToLockMouseRequest() will be called on the requesting tab |
| 406 | // contents. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 407 | virtual void RequestToLockMouse(WebContents* tab) {} |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 408 | |
| 409 | // Notification that the page has lost the mouse lock. |
[email protected] | 229eb7e | 2011-12-23 01:04:08 | [diff] [blame] | 410 | virtual void LostMouseLock() {} |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 411 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 412 | protected: |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 413 | virtual ~WebContentsDelegate(); |
[email protected] | 1de2b8b | 2011-06-29 19:38:46 | [diff] [blame] | 414 | |
| 415 | private: |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 416 | friend class ::WebContentsImpl; |
[email protected] | 1de2b8b | 2011-06-29 19:38:46 | [diff] [blame] | 417 | |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 418 | // Called when |this| becomes the WebContentsDelegate for |source|. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 419 | void Attach(WebContents* source); |
[email protected] | 1de2b8b | 2011-06-29 19:38:46 | [diff] [blame] | 420 | |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 421 | // Called when |this| is no longer the WebContentsDelegate for |source|. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 422 | void Detach(WebContents* source); |
[email protected] | 1de2b8b | 2011-06-29 19:38:46 | [diff] [blame] | 423 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 424 | // The WebContents that this is currently a delegate for. |
| 425 | std::set<WebContents*> attached_contents_; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 426 | }; |
| 427 | |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 428 | } // namespace content |
| 429 | |
| 430 | #endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_ |