[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ |
| 6 | #define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ |
| 7 | #pragma once |
| 8 | |
| 9 | #include <string> |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 10 | |
| 11 | #include "base/basictypes.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 12 | #include "chrome/common/content_settings_types.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 13 | #include "content/browser/tab_contents/navigation_entry.h" |
[email protected] | 4dd5793 | 2011-03-17 06:06:12 | [diff] [blame] | 14 | #include "content/common/navigation_types.h" |
| 15 | #include "content/common/page_transition_types.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 16 | #include "ui/gfx/native_widget_types.h" |
| 17 | #include "webkit/glue/window_open_disposition.h" |
| 18 | |
| 19 | namespace gfx { |
| 20 | class Point; |
| 21 | class Rect; |
| 22 | class Size; |
| 23 | } |
| 24 | |
| 25 | namespace history { |
| 26 | class HistoryAddPageArgs; |
| 27 | } |
| 28 | |
| 29 | struct ContextMenuParams; |
| 30 | class DownloadItem; |
| 31 | class GURL; |
| 32 | class HtmlDialogUIDelegate; |
| 33 | struct NativeWebKeyboardEvent; |
| 34 | class Profile; |
| 35 | class RenderViewHost; |
| 36 | class TabContents; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 37 | |
| 38 | // Objects implement this interface to get notified about changes in the |
| 39 | // TabContents and to provide necessary functionality. |
[email protected] | cce03ee5 | 2011-05-02 18:51:18 | [diff] [blame] | 40 | class TabContentsDelegate { |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 41 | public: |
| 42 | // Opens a new URL inside the passed in TabContents (if source is 0 open |
| 43 | // in the current front-most tab), unless |disposition| indicates the url |
| 44 | // should be opened in a new tab or window. |
| 45 | // |
| 46 | // A NULL source indicates the current tab (callers should probably use |
| 47 | // OpenURL() for these cases which does it for you). |
| 48 | virtual void OpenURLFromTab(TabContents* source, |
| 49 | const GURL& url, const GURL& referrer, |
| 50 | WindowOpenDisposition disposition, |
| 51 | PageTransition::Type transition) = 0; |
| 52 | |
| 53 | // Called to inform the delegate that the tab content's navigation state |
| 54 | // changed. The |changed_flags| indicates the parts of the navigation state |
| 55 | // that have been updated, and is any combination of the |
| 56 | // |TabContents::InvalidateTypes| bits. |
| 57 | virtual void NavigationStateChanged(const TabContents* source, |
| 58 | unsigned changed_flags) = 0; |
| 59 | |
| 60 | // Returns the set of headers to add to the navigation request. Use |
| 61 | // net::HttpUtil::AppendHeaderIfMissing to build the set of headers. |
| 62 | virtual std::string GetNavigationHeaders(const GURL& url); |
| 63 | |
| 64 | // Creates a new tab with the already-created TabContents 'new_contents'. |
| 65 | // The window for the added contents should be reparented correctly when this |
| 66 | // method returns. If |disposition| is NEW_POPUP, |pos| should hold the |
| 67 | // initial position. |
| 68 | virtual void AddNewContents(TabContents* source, |
| 69 | TabContents* new_contents, |
| 70 | WindowOpenDisposition disposition, |
| 71 | const gfx::Rect& initial_pos, |
| 72 | bool user_gesture) = 0; |
| 73 | |
| 74 | // Selects the specified contents, bringing its container to the front. |
| 75 | virtual void ActivateContents(TabContents* contents) = 0; |
| 76 | |
| 77 | // Deactivates the specified contents by deactivating its container and |
| 78 | // potentialy moving it to the back of the Z order. |
| 79 | virtual void DeactivateContents(TabContents* contents) = 0; |
| 80 | |
| 81 | // Notifies the delegate that this contents is starting or is done loading |
| 82 | // some resource. The delegate should use this notification to represent |
| 83 | // loading feedback. See TabContents::is_loading() |
| 84 | virtual void LoadingStateChanged(TabContents* source) = 0; |
| 85 | |
| 86 | // Notifies the delegate that the page has made some progress loading. |
| 87 | // |progress| is a value between 0.0 (nothing loaded) to 1.0 (page fully |
| 88 | // loaded). |
| 89 | // Note that to receive this notification, you must have called |
| 90 | // SetReportLoadProgressEnabled(true) in the render view. |
| 91 | virtual void LoadProgressChanged(double progress); |
| 92 | |
| 93 | // Request the delegate to close this tab contents, and do whatever cleanup |
| 94 | // it needs to do. |
| 95 | virtual void CloseContents(TabContents* source) = 0; |
| 96 | |
| 97 | // Request the delegate to move this tab contents to the specified position |
| 98 | // in screen coordinates. |
| 99 | virtual void MoveContents(TabContents* source, const gfx::Rect& pos) = 0; |
| 100 | |
| 101 | // Causes the delegate to detach |source| and clean up any internal data |
| 102 | // pointing to it. After this call ownership of |source| passes to the |
| 103 | // caller, and it is safe to call "source->set_delegate(someone_else);". |
| 104 | virtual void DetachContents(TabContents* source); |
| 105 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame^] | 106 | // Called to determine if the TabContents is contained in a popup window |
| 107 | // or a panel window. |
| 108 | virtual bool IsPopupOrPanel(const TabContents* source) const; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 109 | |
| 110 | // If |source| is constrained, returns the tab containing it. Otherwise |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 111 | // returns |source|. TODO(avi): Remove in favor of GetConstrainingContents on |
| 112 | // ContentSettingsTabHelperDelegate once uses of it in TabContents are |
| 113 | // removed. |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 114 | virtual TabContents* GetConstrainingContents(TabContents* source); |
| 115 | |
| 116 | // Returns true if constrained windows should be focused. Default is true. |
| 117 | virtual bool ShouldFocusConstrainedWindow(); |
| 118 | |
| 119 | // Invoked prior to the TabContents showing a constrained window. |
| 120 | virtual void WillShowConstrainedWindow(TabContents* source); |
| 121 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 122 | // Notification that the target URL has changed. |
| 123 | virtual void UpdateTargetURL(TabContents* source, const GURL& url) = 0; |
| 124 | |
| 125 | // Notification that there was a mouse event, along with the absolute |
| 126 | // coordinates of the mouse pointer and whether it was a normal motion event |
| 127 | // (otherwise, the pointer left the contents area). |
| 128 | virtual void ContentsMouseEvent( |
| 129 | TabContents* source, const gfx::Point& location, bool motion); |
| 130 | |
| 131 | // Request the delegate to change the zoom level of the current tab. |
| 132 | virtual void ContentsZoomChange(bool zoom_in); |
| 133 | |
| 134 | // Notifies the delegate that something has changed about what content the |
| 135 | // TabContents is blocking. Interested parties should call |
| 136 | // TabContents::IsContentBlocked() to see if something they care about has |
| 137 | // changed. |
| 138 | virtual void OnContentSettingsChange(TabContents* source); |
| 139 | |
| 140 | // Check whether this contents is inside a window dedicated to running a web |
| 141 | // application. |
| 142 | virtual bool IsApplication() const; |
| 143 | |
| 144 | // Detach the given tab and convert it to a "webapp" view. The tab must be |
| 145 | // a TabContents with a valid WebApp set. |
| 146 | virtual void ConvertContentsToApplication(TabContents* source); |
| 147 | |
| 148 | // Whether the specified tab can be reloaded. |
| 149 | // Reloading can be disabled e. g. for the DevTools window. |
| 150 | virtual bool CanReloadContents(TabContents* source) const; |
| 151 | |
| 152 | // Show a dialog with HTML content. |delegate| contains a pointer to the |
| 153 | // delegate who knows how to display the dialog (which file URL and JSON |
| 154 | // string input to use during initialization). |parent_window| is the window |
| 155 | // that should be parent of the dialog, or NULL for the default. |
| 156 | virtual void ShowHtmlDialog(HtmlDialogUIDelegate* delegate, |
| 157 | gfx::NativeWindow parent_window); |
| 158 | |
| 159 | // Invoked prior to showing before unload handler confirmation dialog. |
| 160 | virtual void WillRunBeforeUnloadConfirm(); |
| 161 | |
| 162 | // Returns true if javascript dialogs and unload alerts are suppressed. |
| 163 | // Default is false. |
| 164 | virtual bool ShouldSuppressDialogs(); |
| 165 | |
| 166 | // Tells us that we've finished firing this tab's beforeunload event. |
| 167 | // The proceed bool tells us whether the user chose to proceed closing the |
| 168 | // tab. Returns true if the tab can continue on firing it's unload event. |
| 169 | // If we're closing the entire browser, then we'll want to delay firing |
| 170 | // unload events until all the beforeunload events have fired. |
| 171 | virtual void BeforeUnloadFired(TabContents* tab, |
| 172 | bool proceed, |
| 173 | bool* proceed_to_fire_unload); |
| 174 | |
| 175 | // Send IPC to external host. Default implementation is do nothing. |
| 176 | virtual void ForwardMessageToExternalHost(const std::string& message, |
| 177 | const std::string& origin, |
| 178 | const std::string& target); |
| 179 | |
| 180 | // If the delegate is hosting tabs externally. |
| 181 | virtual bool IsExternalTabContainer() const; |
| 182 | |
| 183 | // Sets focus to the location bar or some other place that is appropriate. |
| 184 | // This is called when the tab wants to encourage user input, like for the |
| 185 | // new tab page. |
| 186 | virtual void SetFocusToLocationBar(bool select_all); |
| 187 | |
| 188 | // Returns whether the page should be focused when transitioning from crashed |
| 189 | // to live. Default is true. |
| 190 | virtual bool ShouldFocusPageAfterCrash(); |
| 191 | |
| 192 | // Called when a popup select is about to be displayed. The delegate can use |
| 193 | // this to disable inactive rendering for the frame in the window the select |
| 194 | // is opened within if necessary. |
| 195 | virtual void RenderWidgetShowing(); |
| 196 | |
| 197 | // This is called when WebKit tells us that it is done tabbing through |
| 198 | // controls on the page. Provides a way for TabContentsDelegates to handle |
| 199 | // this. Returns true if the delegate successfully handled it. |
| 200 | virtual bool TakeFocus(bool reverse); |
| 201 | |
| 202 | // Invoked when the page loses mouse capture. |
| 203 | virtual void LostCapture(); |
| 204 | |
| 205 | // Changes the blocked state of the tab at |index|. TabContents are |
| 206 | // considered blocked while displaying a tab modal dialog. During that time |
| 207 | // renderer host will ignore any UI interaction within TabContent outside of |
| 208 | // the currently displaying dialog. |
| 209 | virtual void SetTabContentBlocked(TabContents* contents, bool blocked); |
| 210 | |
| 211 | // Notification that |tab_contents| has gained focus. |
| 212 | virtual void TabContentsFocused(TabContents* tab_content); |
| 213 | |
| 214 | // Return much extra vertical space should be allotted to the |
| 215 | // render view widget during various animations (e.g. infobar closing). |
| 216 | // This is used to make painting look smoother. |
| 217 | virtual int GetExtraRenderViewHeight() const; |
| 218 | |
| 219 | virtual bool CanDownload(int request_id); |
| 220 | |
| 221 | virtual void OnStartDownload(DownloadItem* download, TabContents* tab); |
| 222 | |
| 223 | // Returns true if the context menu operation was handled by the delegate. |
| 224 | virtual bool HandleContextMenu(const ContextMenuParams& params); |
| 225 | |
| 226 | // Returns true if the context menu command was handled |
| 227 | virtual bool ExecuteContextMenuCommand(int command); |
| 228 | |
| 229 | // Shows the page info using the specified information. |
| 230 | // |url| is the url of the page/frame the info applies to, |ssl| is the SSL |
| 231 | // information for that page/frame. If |show_history| is true, a section |
| 232 | // showing how many times that URL has been visited is added to the page info. |
| 233 | virtual void ShowPageInfo(Profile* profile, |
| 234 | const GURL& url, |
| 235 | const NavigationEntry::SSLStatus& ssl, |
| 236 | bool show_history); |
| 237 | |
| 238 | // Opens source view for given tab contents that is navigated to the given |
| 239 | // page url. |
| 240 | virtual void ViewSourceForTab(TabContents* source, const GURL& page_url); |
| 241 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 242 | // Opens source view for the given subframe. |
| 243 | virtual void ViewSourceForFrame(TabContents* source, |
| 244 | const GURL& url, |
| 245 | const std::string& content_state); |
| 246 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 247 | // Allows delegates to handle keyboard events before sending to the renderer. |
| 248 | // Returns true if the |event| was handled. Otherwise, if the |event| would be |
| 249 | // handled in HandleKeyboardEvent() method as a normal keyboard shortcut, |
| 250 | // |*is_keyboard_shortcut| should be set to true. |
| 251 | virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 252 | bool* is_keyboard_shortcut); |
| 253 | |
| 254 | // Allows delegates to handle unhandled keyboard messages coming back from |
| 255 | // the renderer. |
| 256 | virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); |
| 257 | |
| 258 | virtual void HandleMouseUp(); |
| 259 | virtual void HandleMouseActivate(); |
| 260 | |
| 261 | // Render view drag n drop ended. |
| 262 | virtual void DragEnded(); |
| 263 | |
| 264 | // Shows the repost form confirmation dialog box. |
| 265 | virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); |
| 266 | |
[email protected] | 579e319 | 2011-03-11 22:37:45 | [diff] [blame] | 267 | // Shows the Content Settings page for a given content type. |
| 268 | virtual void ShowContentSettingsPage(ContentSettingsType content_type); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 269 | |
| 270 | // Shows the cookies collected in the tab contents. |
| 271 | virtual void ShowCollectedCookiesDialog(TabContents* tab_contents); |
| 272 | |
| 273 | // Allows delegate to override navigation to the history entries. |
| 274 | // Returns true to allow TabContents to continue with the default processing. |
| 275 | virtual bool OnGoToEntryOffset(int offset); |
| 276 | |
| 277 | // Returns whether this tab contents should add the specified navigation to |
| 278 | // history. |
| 279 | virtual bool ShouldAddNavigationToHistory( |
| 280 | const history::HistoryAddPageArgs& add_page_args, |
| 281 | NavigationType::Type navigation_type); |
| 282 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 283 | // Returns the native window framing the view containing the tab contents. |
| 284 | virtual gfx::NativeWindow GetFrameNativeWindow(); |
| 285 | |
| 286 | // Notifies the delegate about the creation of a new TabContents. This |
| 287 | // typically happens when popups are created. |
| 288 | virtual void TabContentsCreated(TabContents* new_contents); |
| 289 | |
| 290 | // Returns whether infobars are enabled. Overrideable by child classes. |
| 291 | virtual bool infobars_enabled(); |
| 292 | |
| 293 | // Whether the renderer should report its preferred size when it changes by |
| 294 | // calling UpdatePreferredSize(). |
| 295 | // Note that this is set when the RenderViewHost is created and cannot be |
| 296 | // changed after that. |
| 297 | virtual bool ShouldEnablePreferredSizeNotifications(); |
| 298 | |
| 299 | // Notification that the preferred size of the contents has changed. |
| 300 | // Only called if ShouldEnablePreferredSizeNotifications() returns true. |
| 301 | virtual void UpdatePreferredSize(const gfx::Size& pref_size); |
| 302 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 303 | // Notifies the delegate that the content restrictions for this tab has |
| 304 | // changed. |
| 305 | virtual void ContentRestrictionsChanged(TabContents* source); |
| 306 | |
| 307 | // Returns true if the hung renderer dialog should be shown. Default is true. |
| 308 | virtual bool ShouldShowHungRendererDialog(); |
| 309 | |
| 310 | // Notification that a worker associated with this tab has crashed. |
| 311 | virtual void WorkerCrashed(); |
| 312 | |
| 313 | protected: |
| 314 | virtual ~TabContentsDelegate(); |
| 315 | }; |
| 316 | |
| 317 | #endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ |