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