blob: edeb6003589c9bfdf03e7b7bfa9464d1a1e52f08 [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]8d128d62011-09-13 22:11:5714#include "content/common/content_export.h"
[email protected]610cbb82011-10-18 16:35:0815#include "content/public/browser/navigation_types.h"
[email protected]2905f742011-10-13 03:51:5816#include "content/public/common/page_transition_types.h"
[email protected]0dd3a0ab2011-02-18 08:17:4417#include "ui/gfx/native_widget_types.h"
18#include "webkit/glue/window_open_disposition.h"
19
[email protected]3ab9cb82011-06-03 18:02:0720namespace content {
[email protected]3d7474ff2011-07-27 17:47:3721class BrowserContext;
[email protected]3ab9cb82011-06-03 18:02:0722class JavaScriptDialogCreator;
23}
24
[email protected]0dd3a0ab2011-02-18 08:17:4425namespace gfx {
26class Point;
27class Rect;
28class Size;
29}
30
31namespace history {
32class HistoryAddPageArgs;
33}
34
[email protected]ce9751942011-09-21 01:57:2435namespace webkit_glue {
36struct WebIntentData;
37}
38
[email protected]0dd3a0ab2011-02-18 08:17:4439struct ContextMenuParams;
[email protected]00c37fc2011-08-02 00:22:5040struct OpenURLParams;
[email protected]686493142011-07-15 21:47:2241class DownloadItem;
[email protected]0dd3a0ab2011-02-18 08:17:4442class GURL;
43class HtmlDialogUIDelegate;
44struct NativeWebKeyboardEvent;
[email protected]0dd3a0ab2011-02-18 08:17:4445class RenderViewHost;
46class TabContents;
[email protected]3a29a6e2011-08-24 18:26:2147struct ViewHostMsg_RunFileChooser_Params;
48class FilePath;
[email protected]0dd3a0ab2011-02-18 08:17:4449
50// Objects implement this interface to get notified about changes in the
51// TabContents and to provide necessary functionality.
[email protected]8d128d62011-09-13 22:11:5752class CONTENT_EXPORT TabContentsDelegate {
[email protected]0dd3a0ab2011-02-18 08:17:4453 public:
[email protected]1de2b8b2011-06-29 19:38:4654 TabContentsDelegate();
55
[email protected]0dd3a0ab2011-02-18 08:17:4456 // Opens a new URL inside the passed in TabContents (if source is 0 open
57 // in the current front-most tab), unless |disposition| indicates the url
58 // should be opened in a new tab or window.
59 //
60 // A NULL source indicates the current tab (callers should probably use
61 // OpenURL() for these cases which does it for you).
[email protected]00c37fc2011-08-02 00:22:5062
[email protected]992e4542011-07-20 23:09:2563 // Returns the TabContents the URL is opened in, or NULL if the URL wasn't
64 // opened immediately.
[email protected]00c37fc2011-08-02 00:22:5065 // Deprecated. Please use the two-arguments method instead.
66 // TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:2567 virtual TabContents* OpenURLFromTab(TabContents* source,
68 const GURL& url,
69 const GURL& referrer,
70 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:5871 content::PageTransition transition);
[email protected]0dd3a0ab2011-02-18 08:17:4472
[email protected]00c37fc2011-08-02 00:22:5073 virtual TabContents* OpenURLFromTab(TabContents* source,
74 const OpenURLParams& params);
75
[email protected]0dd3a0ab2011-02-18 08:17:4476 // Called to inform the delegate that the tab content's navigation state
77 // changed. The |changed_flags| indicates the parts of the navigation state
78 // that have been updated, and is any combination of the
79 // |TabContents::InvalidateTypes| bits.
80 virtual void NavigationStateChanged(const TabContents* source,
[email protected]bd021ddd22011-07-01 19:45:5481 unsigned changed_flags);
[email protected]0dd3a0ab2011-02-18 08:17:4482
[email protected]6c6b02d2011-09-02 03:36:4783 // Adds the navigation request headers to |headers|. Use
[email protected]0dd3a0ab2011-02-18 08:17:4484 // net::HttpUtil::AppendHeaderIfMissing to build the set of headers.
[email protected]6c6b02d2011-09-02 03:36:4785 virtual void AddNavigationHeaders(const GURL& url, std::string* headers);
[email protected]0dd3a0ab2011-02-18 08:17:4486
87 // Creates a new tab with the already-created TabContents 'new_contents'.
88 // The window for the added contents should be reparented correctly when this
89 // method returns. If |disposition| is NEW_POPUP, |pos| should hold the
90 // initial position.
91 virtual void AddNewContents(TabContents* source,
92 TabContents* new_contents,
93 WindowOpenDisposition disposition,
94 const gfx::Rect& initial_pos,
[email protected]bd021ddd22011-07-01 19:45:5495 bool user_gesture);
[email protected]0dd3a0ab2011-02-18 08:17:4496
97 // Selects the specified contents, bringing its container to the front.
[email protected]bd021ddd22011-07-01 19:45:5498 virtual void ActivateContents(TabContents* contents);
[email protected]0dd3a0ab2011-02-18 08:17:4499
100 // Deactivates the specified contents by deactivating its container and
101 // potentialy moving it to the back of the Z order.
[email protected]bd021ddd22011-07-01 19:45:54102 virtual void DeactivateContents(TabContents* contents);
[email protected]0dd3a0ab2011-02-18 08:17:44103
104 // Notifies the delegate that this contents is starting or is done loading
105 // some resource. The delegate should use this notification to represent
[email protected]f5d978c2011-07-21 14:43:51106 // loading feedback. See TabContents::IsLoading()
[email protected]bd021ddd22011-07-01 19:45:54107 virtual void LoadingStateChanged(TabContents* source);
[email protected]0dd3a0ab2011-02-18 08:17:44108
109 // Notifies the delegate that the page has made some progress loading.
110 // |progress| is a value between 0.0 (nothing loaded) to 1.0 (page fully
111 // loaded).
112 // Note that to receive this notification, you must have called
113 // SetReportLoadProgressEnabled(true) in the render view.
114 virtual void LoadProgressChanged(double progress);
115
116 // Request the delegate to close this tab contents, and do whatever cleanup
117 // it needs to do.
[email protected]bd021ddd22011-07-01 19:45:54118 virtual void CloseContents(TabContents* source);
[email protected]0dd3a0ab2011-02-18 08:17:44119
120 // Request the delegate to move this tab contents to the specified position
121 // in screen coordinates.
[email protected]bd021ddd22011-07-01 19:45:54122 virtual void MoveContents(TabContents* source, const gfx::Rect& pos);
[email protected]0dd3a0ab2011-02-18 08:17:44123
124 // Causes the delegate to detach |source| and clean up any internal data
125 // pointing to it. After this call ownership of |source| passes to the
126 // caller, and it is safe to call "source->set_delegate(someone_else);".
127 virtual void DetachContents(TabContents* source);
128
[email protected]b35b26b32011-05-05 20:35:14129 // Called to determine if the TabContents is contained in a popup window
130 // or a panel window.
131 virtual bool IsPopupOrPanel(const TabContents* source) const;
[email protected]0dd3a0ab2011-02-18 08:17:44132
[email protected]0dd3a0ab2011-02-18 08:17:44133 // Notification that the target URL has changed.
[email protected]d952a052011-09-06 18:42:45134 virtual void UpdateTargetURL(TabContents* source, int32 page_id,
135 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
[email protected]0dd3a0ab2011-02-18 08:17:44196 // Notification that |tab_contents| has gained focus.
197 virtual void TabContentsFocused(TabContents* tab_content);
198
[email protected]686493142011-07-15 21:47:22199 // Asks the delegate if the given tab can download.
200 virtual bool CanDownload(TabContents* source, int request_id);
201
202 // Notifies the delegate that a download is starting.
203 virtual void OnStartDownload(TabContents* source, DownloadItem* download);
204
[email protected]0dd3a0ab2011-02-18 08:17:44205 // Return much extra vertical space should be allotted to the
206 // render view widget during various animations (e.g. infobar closing).
207 // This is used to make painting look smoother.
208 virtual int GetExtraRenderViewHeight() const;
209
[email protected]0dd3a0ab2011-02-18 08:17:44210 // Returns true if the context menu operation was handled by the delegate.
211 virtual bool HandleContextMenu(const ContextMenuParams& params);
212
213 // Returns true if the context menu command was handled
214 virtual bool ExecuteContextMenuCommand(int command);
215
216 // Shows the page info using the specified information.
217 // |url| is the url of the page/frame the info applies to, |ssl| is the SSL
218 // information for that page/frame. If |show_history| is true, a section
219 // showing how many times that URL has been visited is added to the page info.
[email protected]3d7474ff2011-07-27 17:47:37220 virtual void ShowPageInfo(content::BrowserContext* browser_context,
[email protected]0dd3a0ab2011-02-18 08:17:44221 const GURL& url,
222 const NavigationEntry::SSLStatus& ssl,
223 bool show_history);
224
225 // Opens source view for given tab contents that is navigated to the given
226 // page url.
227 virtual void ViewSourceForTab(TabContents* source, const GURL& page_url);
228
[email protected]932b7a12011-03-09 12:50:27229 // Opens source view for the given subframe.
230 virtual void ViewSourceForFrame(TabContents* source,
231 const GURL& url,
232 const std::string& content_state);
233
[email protected]0dd3a0ab2011-02-18 08:17:44234 // Allows delegates to handle keyboard events before sending to the renderer.
235 // Returns true if the |event| was handled. Otherwise, if the |event| would be
236 // handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
237 // |*is_keyboard_shortcut| should be set to true.
238 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
239 bool* is_keyboard_shortcut);
240
241 // Allows delegates to handle unhandled keyboard messages coming back from
242 // the renderer.
243 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
244
245 virtual void HandleMouseUp();
246 virtual void HandleMouseActivate();
247
248 // Render view drag n drop ended.
249 virtual void DragEnded();
250
251 // Shows the repost form confirmation dialog box.
252 virtual void ShowRepostFormWarningDialog(TabContents* tab_contents);
253
[email protected]0dd3a0ab2011-02-18 08:17:44254 // Allows delegate to override navigation to the history entries.
255 // Returns true to allow TabContents to continue with the default processing.
256 virtual bool OnGoToEntryOffset(int offset);
257
258 // Returns whether this tab contents should add the specified navigation to
259 // history.
260 virtual bool ShouldAddNavigationToHistory(
261 const history::HistoryAddPageArgs& add_page_args,
[email protected]610cbb82011-10-18 16:35:08262 content::NavigationType navigation_type);
[email protected]0dd3a0ab2011-02-18 08:17:44263
[email protected]0dd3a0ab2011-02-18 08:17:44264 // Returns the native window framing the view containing the tab contents.
265 virtual gfx::NativeWindow GetFrameNativeWindow();
266
267 // Notifies the delegate about the creation of a new TabContents. This
268 // typically happens when popups are created.
269 virtual void TabContentsCreated(TabContents* new_contents);
270
[email protected]0dd3a0ab2011-02-18 08:17:44271 // Notifies the delegate that the content restrictions for this tab has
272 // changed.
273 virtual void ContentRestrictionsChanged(TabContents* source);
274
[email protected]55452902011-06-01 21:57:47275 // Notification that the tab is hung.
276 virtual void RendererUnresponsive(TabContents* source);
277
278 // Notification that the tab is no longer hung.
279 virtual void RendererResponsive(TabContents* source);
[email protected]0dd3a0ab2011-02-18 08:17:44280
281 // Notification that a worker associated with this tab has crashed.
[email protected]55452902011-06-01 21:57:47282 virtual void WorkerCrashed(TabContents* source);
[email protected]0dd3a0ab2011-02-18 08:17:44283
[email protected]09b29342011-06-24 19:18:48284 // Invoked when a main fram navigation occurs.
285 virtual void DidNavigateMainFramePostCommit(TabContents* tab);
[email protected]93f230e02011-06-01 14:40:00286
[email protected]09b29342011-06-24 19:18:48287 // Invoked when navigating to a pending entry. When invoked the
288 // NavigationController has configured its pending entry, but it has not yet
289 // been committed.
290 virtual void DidNavigateToPendingEntry(TabContents* tab);
[email protected]93f230e02011-06-01 14:40:00291
[email protected]3ab9cb82011-06-03 18:02:07292 // Returns a pointer to a service to create JavaScript dialogs. The default
293 // pointer returned is to a stub service that marks all dialogs as suppressed
294 // and displays nothing.
295 virtual content::JavaScriptDialogCreator* GetJavaScriptDialogCreator();
296
[email protected]3a29a6e2011-08-24 18:26:21297 // Called when a file selection is to be done.
298 virtual void RunFileChooser(TabContents* tab,
299 const ViewHostMsg_RunFileChooser_Params& params);
300
301 // Request to enumerate a directory. This is equivalent to running the file
302 // chooser in directory-enumeration mode and having the user select the given
303 // directory.
304 virtual void EnumerateDirectory(TabContents* tab, int request_id,
305 const FilePath& path);
306
[email protected]8a5e0ca2011-08-25 06:30:47307 // Called when the renderer puts a tab into or out of fullscreen mode.
308 virtual void ToggleFullscreenModeForTab(TabContents* tab,
309 bool enter_fullscreen);
[email protected]5d5f7af2011-10-01 01:38:12310 virtual bool IsFullscreenForTab(const TabContents* tab) const;
[email protected]8a5e0ca2011-08-25 06:30:47311
[email protected]7d189022011-08-25 22:54:20312 // Called when a Javascript out of memory notification is received.
313 virtual void JSOutOfMemory(TabContents* tab);
314
315 // Register a new handler for URL requests with the given scheme.
316 virtual void RegisterProtocolHandler(TabContents* tab,
317 const std::string& protocol,
318 const GURL& url,
319 const string16& title);
320
321 // Register a new handler for Intents with the given action and type filter.
322 virtual void RegisterIntentHandler(TabContents* tab,
323 const string16& action,
324 const string16& type,
325 const string16& href,
[email protected]63c239322011-10-31 23:56:30326 const string16& title,
327 const string16& disposition);
[email protected]7d189022011-08-25 22:54:20328
329 // WebIntent notification handler.
330 virtual void WebIntentDispatch(TabContents* tab,
331 int routing_id,
[email protected]ce9751942011-09-21 01:57:24332 const webkit_glue::WebIntentData& intent,
[email protected]7d189022011-08-25 22:54:20333 int intent_id);
334
[email protected]b888919c2011-09-02 00:32:16335 // Result of string search in the page. This includes the number of matches
336 // found and the selection rect (in screen coordinates) for the string found.
337 // If |final_update| is false, it indicates that more results follow.
338 virtual void FindReply(TabContents* tab,
339 int request_id,
340 int number_of_matches,
341 const gfx::Rect& selection_rect,
342 int active_match_ordinal,
343 bool final_update);
344
[email protected]d952a052011-09-06 18:42:45345 // Notification that a plugin has crashed.
346 virtual void CrashedPlugin(TabContents* tab, const FilePath& plugin_path);
347
[email protected]0548c5352011-09-07 00:33:33348 // Invoked when the preferred size of the contents has been changed.
349 virtual void UpdatePreferredSize(TabContents* source,
350 const gfx::Size& pref_size);
351
[email protected]e9621112011-10-17 05:38:37352 // Requests to lock the mouse. Once the request is approved or rejected,
353 // GotResponseToLockMouseRequest() will be called on the requesting tab
354 // contents.
355 virtual void RequestToLockMouse(TabContents* tab);
356
357 // Notification that the page has lost the mouse lock.
358 virtual void LostMouseLock();
359
[email protected]0dd3a0ab2011-02-18 08:17:44360 protected:
361 virtual ~TabContentsDelegate();
[email protected]1de2b8b2011-06-29 19:38:46362
363 private:
364 friend class TabContents;
365
366 // Called when |this| becomes the TabContentsDelegate for |source|.
367 void Attach(TabContents* source);
368
369 // Called when |this| is no longer the TabContentsDelegate for |source|.
370 void Detach(TabContents* source);
371
372 // The TabContents that this is currently a delegate for.
373 std::set<TabContents*> attached_contents_;
[email protected]0dd3a0ab2011-02-18 08:17:44374};
375
376#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_