blob: 963877517bb380b361c4ded3db41499fe4f04dcf [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
[email protected]1de2b8b2011-06-29 19:38:469#include <set>
[email protected]0dd3a0ab2011-02-18 08:17:4410#include <string>
[email protected]0dd3a0ab2011-02-18 08:17:4411
12#include "base/basictypes.h"
[email protected]0dd3a0ab2011-02-18 08:17:4413#include "content/browser/tab_contents/navigation_entry.h"
[email protected]4dd57932011-03-17 06:06:1214#include "content/common/navigation_types.h"
15#include "content/common/page_transition_types.h"
[email protected]0dd3a0ab2011-02-18 08:17:4416#include "ui/gfx/native_widget_types.h"
17#include "webkit/glue/window_open_disposition.h"
18
[email protected]3ab9cb82011-06-03 18:02:0719namespace content {
[email protected]3d7474ff2011-07-27 17:47:3720class BrowserContext;
[email protected]3ab9cb82011-06-03 18:02:0721class JavaScriptDialogCreator;
22}
23
[email protected]0dd3a0ab2011-02-18 08:17:4424namespace gfx {
25class Point;
26class Rect;
27class Size;
28}
29
30namespace history {
31class HistoryAddPageArgs;
32}
33
34struct ContextMenuParams;
[email protected]00c37fc2011-08-02 00:22:5035struct OpenURLParams;
[email protected]686493142011-07-15 21:47:2236class DownloadItem;
[email protected]0dd3a0ab2011-02-18 08:17:4437class GURL;
38class HtmlDialogUIDelegate;
39struct NativeWebKeyboardEvent;
[email protected]0dd3a0ab2011-02-18 08:17:4440class RenderViewHost;
41class TabContents;
[email protected]3a29a6e2011-08-24 18:26:2142struct ViewHostMsg_RunFileChooser_Params;
43class FilePath;
[email protected]0dd3a0ab2011-02-18 08:17:4444
45// Objects implement this interface to get notified about changes in the
46// TabContents and to provide necessary functionality.
[email protected]cce03ee52011-05-02 18:51:1847class TabContentsDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4448 public:
[email protected]1de2b8b2011-06-29 19:38:4649 TabContentsDelegate();
50
[email protected]0dd3a0ab2011-02-18 08:17:4451 // Opens a new URL inside the passed in TabContents (if source is 0 open
52 // in the current front-most tab), unless |disposition| indicates the url
53 // should be opened in a new tab or window.
54 //
55 // A NULL source indicates the current tab (callers should probably use
56 // OpenURL() for these cases which does it for you).
[email protected]00c37fc2011-08-02 00:22:5057
[email protected]992e4542011-07-20 23:09:2558 // Returns the TabContents the URL is opened in, or NULL if the URL wasn't
59 // opened immediately.
[email protected]00c37fc2011-08-02 00:22:5060 // Deprecated. Please use the two-arguments method instead.
61 // TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:2562 virtual TabContents* OpenURLFromTab(TabContents* source,
63 const GURL& url,
64 const GURL& referrer,
65 WindowOpenDisposition disposition,
66 PageTransition::Type transition);
[email protected]0dd3a0ab2011-02-18 08:17:4467
[email protected]00c37fc2011-08-02 00:22:5068 virtual TabContents* OpenURLFromTab(TabContents* source,
69 const OpenURLParams& params);
70
[email protected]0dd3a0ab2011-02-18 08:17:4471 // Called to inform the delegate that the tab content's navigation state
72 // changed. The |changed_flags| indicates the parts of the navigation state
73 // that have been updated, and is any combination of the
74 // |TabContents::InvalidateTypes| bits.
75 virtual void NavigationStateChanged(const TabContents* source,
[email protected]bd021ddd22011-07-01 19:45:5476 unsigned changed_flags);
[email protected]0dd3a0ab2011-02-18 08:17:4477
78 // Returns the set of headers to add to the navigation request. Use
79 // net::HttpUtil::AppendHeaderIfMissing to build the set of headers.
80 virtual std::string GetNavigationHeaders(const GURL& url);
81
82 // Creates a new tab with the already-created TabContents 'new_contents'.
83 // The window for the added contents should be reparented correctly when this
84 // method returns. If |disposition| is NEW_POPUP, |pos| should hold the
85 // initial position.
86 virtual void AddNewContents(TabContents* source,
87 TabContents* new_contents,
88 WindowOpenDisposition disposition,
89 const gfx::Rect& initial_pos,
[email protected]bd021ddd22011-07-01 19:45:5490 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:4491
92 // Selects the specified contents, bringing its container to the front.
[email protected]bd021ddd22011-07-01 19:45:5493 virtual void ActivateContents(TabContents* contents);
[email protected]0dd3a0ab2011-02-18 08:17:4494
95 // Deactivates the specified contents by deactivating its container and
96 // potentialy moving it to the back of the Z order.
[email protected]bd021ddd22011-07-01 19:45:5497 virtual void DeactivateContents(TabContents* contents);
[email protected]0dd3a0ab2011-02-18 08:17:4498
99 // Notifies the delegate that this contents is starting or is done loading
100 // some resource. The delegate should use this notification to represent
[email protected]f5d978c2011-07-21 14:43:51101 // loading feedback. See TabContents::IsLoading()
[email protected]bd021ddd22011-07-01 19:45:54102 virtual void LoadingStateChanged(TabContents* source);
[email protected]0dd3a0ab2011-02-18 08:17:44103
104 // Notifies the delegate that the page has made some progress loading.
105 // |progress| is a value between 0.0 (nothing loaded) to 1.0 (page fully
106 // loaded).
107 // Note that to receive this notification, you must have called
108 // SetReportLoadProgressEnabled(true) in the render view.
109 virtual void LoadProgressChanged(double progress);
110
111 // Request the delegate to close this tab contents, and do whatever cleanup
112 // it needs to do.
[email protected]bd021ddd22011-07-01 19:45:54113 virtual void CloseContents(TabContents* source);
[email protected]0dd3a0ab2011-02-18 08:17:44114
115 // Request the delegate to move this tab contents to the specified position
116 // in screen coordinates.
[email protected]bd021ddd22011-07-01 19:45:54117 virtual void MoveContents(TabContents* source, const gfx::Rect& pos);
[email protected]0dd3a0ab2011-02-18 08:17:44118
119 // Causes the delegate to detach |source| and clean up any internal data
120 // pointing to it. After this call ownership of |source| passes to the
121 // caller, and it is safe to call "source->set_delegate(someone_else);".
122 virtual void DetachContents(TabContents* source);
123
[email protected]b35b26b32011-05-05 20:35:14124 // Called to determine if the TabContents is contained in a popup window
125 // or a panel window.
126 virtual bool IsPopupOrPanel(const TabContents* source) const;
[email protected]0dd3a0ab2011-02-18 08:17:44127
[email protected]0dd3a0ab2011-02-18 08:17:44128 // Returns true if constrained windows should be focused. Default is true.
129 virtual bool ShouldFocusConstrainedWindow();
130
131 // Invoked prior to the TabContents showing a constrained window.
132 virtual void WillShowConstrainedWindow(TabContents* source);
133
[email protected]0dd3a0ab2011-02-18 08:17:44134 // Notification that the target URL has changed.
[email protected]bd021ddd22011-07-01 19:45:54135 virtual void UpdateTargetURL(TabContents* source, const GURL& url);
[email protected]0dd3a0ab2011-02-18 08:17:44136
137 // Notification that there was a mouse event, along with the absolute
138 // coordinates of the mouse pointer and whether it was a normal motion event
139 // (otherwise, the pointer left the contents area).
140 virtual void ContentsMouseEvent(
141 TabContents* source, const gfx::Point& location, bool motion);
142
143 // Request the delegate to change the zoom level of the current tab.
144 virtual void ContentsZoomChange(bool zoom_in);
145
[email protected]0dd3a0ab2011-02-18 08:17:44146 // Check whether this contents is inside a window dedicated to running a web
147 // application.
148 virtual bool IsApplication() const;
149
150 // Detach the given tab and convert it to a "webapp" view. The tab must be
151 // a TabContents with a valid WebApp set.
152 virtual void ConvertContentsToApplication(TabContents* source);
153
154 // Whether the specified tab can be reloaded.
155 // Reloading can be disabled e. g. for the DevTools window.
156 virtual bool CanReloadContents(TabContents* source) const;
157
[email protected]0dd3a0ab2011-02-18 08:17:44158 // Invoked prior to showing before unload handler confirmation dialog.
159 virtual void WillRunBeforeUnloadConfirm();
160
161 // Returns true if javascript dialogs and unload alerts are suppressed.
162 // Default is false.
163 virtual bool ShouldSuppressDialogs();
164
165 // Tells us that we've finished firing this tab's beforeunload event.
166 // The proceed bool tells us whether the user chose to proceed closing the
167 // tab. Returns true if the tab can continue on firing it's unload event.
168 // If we're closing the entire browser, then we'll want to delay firing
169 // unload events until all the beforeunload events have fired.
170 virtual void BeforeUnloadFired(TabContents* tab,
171 bool proceed,
172 bool* proceed_to_fire_unload);
173
[email protected]0dd3a0ab2011-02-18 08:17:44174 // Sets focus to the location bar or some other place that is appropriate.
175 // This is called when the tab wants to encourage user input, like for the
176 // new tab page.
177 virtual void SetFocusToLocationBar(bool select_all);
178
179 // Returns whether the page should be focused when transitioning from crashed
180 // to live. Default is true.
181 virtual bool ShouldFocusPageAfterCrash();
182
183 // Called when a popup select is about to be displayed. The delegate can use
184 // this to disable inactive rendering for the frame in the window the select
185 // is opened within if necessary.
186 virtual void RenderWidgetShowing();
187
188 // This is called when WebKit tells us that it is done tabbing through
189 // controls on the page. Provides a way for TabContentsDelegates to handle
190 // this. Returns true if the delegate successfully handled it.
191 virtual bool TakeFocus(bool reverse);
192
193 // Invoked when the page loses mouse capture.
194 virtual void LostCapture();
195
196 // Changes the blocked state of the tab at |index|. TabContents are
197 // considered blocked while displaying a tab modal dialog. During that time
198 // renderer host will ignore any UI interaction within TabContent outside of
199 // the currently displaying dialog.
200 virtual void SetTabContentBlocked(TabContents* contents, bool blocked);
201
202 // Notification that |tab_contents| has gained focus.
203 virtual void TabContentsFocused(TabContents* tab_content);
204
[email protected]686493142011-07-15 21:47:22205 // Asks the delegate if the given tab can download.
206 virtual bool CanDownload(TabContents* source, int request_id);
207
208 // Notifies the delegate that a download is starting.
209 virtual void OnStartDownload(TabContents* source, DownloadItem* download);
210
[email protected]0dd3a0ab2011-02-18 08:17:44211 // Return much extra vertical space should be allotted to the
212 // render view widget during various animations (e.g. infobar closing).
213 // This is used to make painting look smoother.
214 virtual int GetExtraRenderViewHeight() const;
215
[email protected]0dd3a0ab2011-02-18 08:17:44216 // Returns true if the context menu operation was handled by the delegate.
217 virtual bool HandleContextMenu(const ContextMenuParams& params);
218
219 // Returns true if the context menu command was handled
220 virtual bool ExecuteContextMenuCommand(int command);
221
222 // Shows the page info using the specified information.
223 // |url| is the url of the page/frame the info applies to, |ssl| is the SSL
224 // information for that page/frame. If |show_history| is true, a section
225 // showing how many times that URL has been visited is added to the page info.
[email protected]3d7474ff2011-07-27 17:47:37226 virtual void ShowPageInfo(content::BrowserContext* browser_context,
[email protected]0dd3a0ab2011-02-18 08:17:44227 const GURL& url,
228 const NavigationEntry::SSLStatus& ssl,
229 bool show_history);
230
231 // Opens source view for given tab contents that is navigated to the given
232 // page url.
233 virtual void ViewSourceForTab(TabContents* source, const GURL& page_url);
234
[email protected]932b7a12011-03-09 12:50:27235 // Opens source view for the given subframe.
236 virtual void ViewSourceForFrame(TabContents* source,
237 const GURL& url,
238 const std::string& content_state);
239
[email protected]0dd3a0ab2011-02-18 08:17:44240 // Allows delegates to handle keyboard events before sending to the renderer.
241 // Returns true if the |event| was handled. Otherwise, if the |event| would be
242 // handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
243 // |*is_keyboard_shortcut| should be set to true.
244 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
245 bool* is_keyboard_shortcut);
246
247 // Allows delegates to handle unhandled keyboard messages coming back from
248 // the renderer.
249 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
250
251 virtual void HandleMouseUp();
252 virtual void HandleMouseActivate();
253
254 // Render view drag n drop ended.
255 virtual void DragEnded();
256
257 // Shows the repost form confirmation dialog box.
258 virtual void ShowRepostFormWarningDialog(TabContents* tab_contents);
259
[email protected]0dd3a0ab2011-02-18 08:17:44260 // Allows delegate to override navigation to the history entries.
261 // Returns true to allow TabContents to continue with the default processing.
262 virtual bool OnGoToEntryOffset(int offset);
263
264 // Returns whether this tab contents should add the specified navigation to
265 // history.
266 virtual bool ShouldAddNavigationToHistory(
267 const history::HistoryAddPageArgs& add_page_args,
268 NavigationType::Type navigation_type);
269
[email protected]0dd3a0ab2011-02-18 08:17:44270 // Returns the native window framing the view containing the tab contents.
271 virtual gfx::NativeWindow GetFrameNativeWindow();
272
273 // Notifies the delegate about the creation of a new TabContents. This
274 // typically happens when popups are created.
275 virtual void TabContentsCreated(TabContents* new_contents);
276
[email protected]0dd3a0ab2011-02-18 08:17:44277 // Notifies the delegate that the content restrictions for this tab has
278 // changed.
279 virtual void ContentRestrictionsChanged(TabContents* source);
280
[email protected]55452902011-06-01 21:57:47281 // Notification that the tab is hung.
282 virtual void RendererUnresponsive(TabContents* source);
283
284 // Notification that the tab is no longer hung.
285 virtual void RendererResponsive(TabContents* source);
[email protected]0dd3a0ab2011-02-18 08:17:44286
287 // Notification that a worker associated with this tab has crashed.
[email protected]55452902011-06-01 21:57:47288 virtual void WorkerCrashed(TabContents* source);
[email protected]0dd3a0ab2011-02-18 08:17:44289
[email protected]09b29342011-06-24 19:18:48290 // Invoked when a main fram navigation occurs.
291 virtual void DidNavigateMainFramePostCommit(TabContents* tab);
[email protected]93f230e02011-06-01 14:40:00292
[email protected]09b29342011-06-24 19:18:48293 // Invoked when navigating to a pending entry. When invoked the
294 // NavigationController has configured its pending entry, but it has not yet
295 // been committed.
296 virtual void DidNavigateToPendingEntry(TabContents* tab);
[email protected]93f230e02011-06-01 14:40:00297
[email protected]3ab9cb82011-06-03 18:02:07298 // Returns a pointer to a service to create JavaScript dialogs. The default
299 // pointer returned is to a stub service that marks all dialogs as suppressed
300 // and displays nothing.
301 virtual content::JavaScriptDialogCreator* GetJavaScriptDialogCreator();
302
[email protected]3a29a6e2011-08-24 18:26:21303 // Called when a file selection is to be done.
304 virtual void RunFileChooser(TabContents* tab,
305 const ViewHostMsg_RunFileChooser_Params& params);
306
307 // Request to enumerate a directory. This is equivalent to running the file
308 // chooser in directory-enumeration mode and having the user select the given
309 // directory.
310 virtual void EnumerateDirectory(TabContents* tab, int request_id,
311 const FilePath& path);
312
[email protected]8a5e0ca2011-08-25 06:30:47313 // Called when the renderer puts a tab into or out of fullscreen mode.
314 virtual void ToggleFullscreenModeForTab(TabContents* tab,
315 bool enter_fullscreen);
316
[email protected]7d189022011-08-25 22:54:20317 // Called when a Javascript out of memory notification is received.
318 virtual void JSOutOfMemory(TabContents* tab);
319
320 // Register a new handler for URL requests with the given scheme.
321 virtual void RegisterProtocolHandler(TabContents* tab,
322 const std::string& protocol,
323 const GURL& url,
324 const string16& title);
325
326 // Register a new handler for Intents with the given action and type filter.
327 virtual void RegisterIntentHandler(TabContents* tab,
328 const string16& action,
329 const string16& type,
330 const string16& href,
331 const string16& title);
332
333 // WebIntent notification handler.
334 virtual void WebIntentDispatch(TabContents* tab,
335 int routing_id,
336 const string16& action,
337 const string16& type,
338 const string16& data,
339 int intent_id);
340
[email protected]b888919c2011-09-02 00:32:16341 // Result of string search in the page. This includes the number of matches
342 // found and the selection rect (in screen coordinates) for the string found.
343 // If |final_update| is false, it indicates that more results follow.
344 virtual void FindReply(TabContents* tab,
345 int request_id,
346 int number_of_matches,
347 const gfx::Rect& selection_rect,
348 int active_match_ordinal,
349 bool final_update);
350
[email protected]0dd3a0ab2011-02-18 08:17:44351 protected:
352 virtual ~TabContentsDelegate();
[email protected]1de2b8b2011-06-29 19:38:46353
354 private:
355 friend class TabContents;
356
357 // Called when |this| becomes the TabContentsDelegate for |source|.
358 void Attach(TabContents* source);
359
360 // Called when |this| is no longer the TabContentsDelegate for |source|.
361 void Detach(TabContents* source);
362
363 // The TabContents that this is currently a delegate for.
364 std::set<TabContents*> attached_contents_;
[email protected]0dd3a0ab2011-02-18 08:17:44365};
366
367#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_