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