blob: 15717f2fe4d133df9fd2fdaeaf740ab44a922667 [file] [log] [blame]
[email protected]e41982a72012-11-20 07:16:511// Copyright 2012 The Chromium Authors. All rights reserved.
[email protected]69b04b92010-11-08 22:12:182// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_BROWSER_WINDOW_H_
6#define CHROME_BROWSER_UI_BROWSER_WINDOW_H_
[email protected]69b04b92010-11-08 22:12:187
[email protected]fe54b4a2012-03-28 16:11:048#include "base/callback_forward.h"
[email protected]2e6389f2012-05-18 19:41:259#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]41d9faf2012-02-28 23:46:0210#include "chrome/browser/ui/base_window.h"
[email protected]09b29342011-06-24 19:18:4811#include "chrome/browser/ui/bookmarks/bookmark_bar.h"
[email protected]9d5c059a82012-06-29 20:13:0712#include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h"
[email protected]e4b66bf2012-05-29 20:39:5113#include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
[email protected]69b04b92010-11-08 22:12:1814#include "chrome/common/content_settings_types.h"
[email protected]08397d52011-02-05 01:53:3815#include "ui/gfx/native_widget_types.h"
[email protected]588300d2011-04-28 21:06:3516#include "webkit/glue/window_open_disposition.h"
[email protected]69b04b92010-11-08 22:12:1817
18class Browser;
19class BrowserWindowTesting;
20class DownloadShelf;
21class FindBar;
22class GURL;
[email protected]69b04b92010-11-08 22:12:1823class LocationBar;
24class Profile;
25class StatusBubble;
[email protected]c36a9e1d2012-06-05 14:31:0226class TabContents;
[email protected]69b04b92010-11-08 22:12:1827class TemplateURL;
[email protected]69b04b92010-11-08 22:12:1828#if !defined(OS_MACOSX)
29class ToolbarView;
30#endif
[email protected]69b04b92010-11-08 22:12:1831
[email protected]e0f90fc2012-06-06 19:30:1032namespace autofill {
33class PasswordGenerator;
34}
[email protected]ea049a02011-12-25 21:37:0935namespace content {
36class WebContents;
[email protected]b87ee522012-05-18 15:16:5437struct NativeWebKeyboardEvent;
[email protected]1ecbe862012-10-05 01:29:1438struct PasswordForm;
[email protected]d583e3f22011-12-27 21:38:1739struct SSLStatus;
[email protected]ea049a02011-12-25 21:37:0940}
41
[email protected]1c321ee2012-05-21 03:02:3442namespace extensions {
43class Extension;
44}
45
[email protected]69b04b92010-11-08 22:12:1846namespace gfx {
47class Rect;
[email protected]0548c5352011-09-07 00:33:3348class Size;
[email protected]69b04b92010-11-08 22:12:1849}
50
[email protected]69b04b92010-11-08 22:12:1851////////////////////////////////////////////////////////////////////////////////
52// BrowserWindow interface
53// An interface implemented by the "view" of the Browser window.
[email protected]41d9faf2012-02-28 23:46:0254// This interface includes BaseWindow methods as well as Browser window
55// specific methods.
[email protected]69b04b92010-11-08 22:12:1856//
57// NOTE: All getters may return NULL.
[email protected]41d9faf2012-02-28 23:46:0258//
59class BrowserWindow : public BaseWindow {
[email protected]69b04b92010-11-08 22:12:1860 public:
[email protected]ed2f27132011-04-04 17:19:5761 virtual ~BrowserWindow() {}
62
[email protected]41d9faf2012-02-28 23:46:0263 //////////////////////////////////////////////////////////////////////////////
64 // BaseWindow interface notes:
[email protected]69b04b92010-11-08 22:12:1865
[email protected]41d9faf2012-02-28 23:46:0266 // Closes the window as soon as possible. If the window is not in a drag
[email protected]69b04b92010-11-08 22:12:1867 // session, it will close immediately; otherwise, it will move offscreen (so
68 // events are still fired) until the drag ends, then close. This assumes
69 // that the Browser is not immediately destroyed, but will be eventually
70 // destroyed by other means (eg, the tab strip going to zero elements).
71 // Bad things happen if the Browser dtor is called directly as a result of
72 // invoking this method.
[email protected]41d9faf2012-02-28 23:46:0273 // virtual void Close() = 0;
[email protected]69b04b92010-11-08 22:12:1874
[email protected]41d9faf2012-02-28 23:46:0275 // Browser::OnWindowDidShow should be called after showing the window.
76 // virtual void Show() = 0;
[email protected]69b04b92010-11-08 22:12:1877
[email protected]41d9faf2012-02-28 23:46:0278 //////////////////////////////////////////////////////////////////////////////
79 // Browser specific methods:
[email protected]69b04b92010-11-08 22:12:1880
[email protected]69b04b92010-11-08 22:12:1881 // Returns a pointer to the testing interface to the Browser window, or NULL
82 // if there is none.
83 virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0;
84
85 // Return the status bubble associated with the frame
86 virtual StatusBubble* GetStatusBubble() = 0;
87
[email protected]69b04b92010-11-08 22:12:1888 // Inform the frame that the selected tab favicon or title has changed. Some
89 // frames may need to refresh their title bar.
90 virtual void UpdateTitleBar() = 0;
91
[email protected]09b29342011-06-24 19:18:4892 // Invoked when the state of the bookmark bar changes. This is only invoked if
93 // the state changes for the current tab, it is not sent when switching tabs.
94 virtual void BookmarkBarStateChanged(
95 BookmarkBar::AnimateChangeType change_type) = 0;
[email protected]69b04b92010-11-08 22:12:1896
97 // Inform the frame that the dev tools window for the selected tab has
98 // changed.
99 virtual void UpdateDevTools() = 0;
100
101 // Update any loading animations running in the window. |should_animate| is
102 // true if there are tabs loading and the animations should continue, false
103 // if there are no active loads and the animations should end.
104 virtual void UpdateLoadingAnimations(bool should_animate) = 0;
105
106 // Sets the starred state for the current tab.
107 virtual void SetStarredState(bool is_starred) = 0;
108
[email protected]5423c372012-08-22 05:50:16109 // Called to force the zoom state to for the active tab to be recalculated.
110 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
111 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
112 // + or - in the wrench menu to change zoom).
113 virtual void ZoomChangedForActiveTab(bool can_show_bubble) = 0;
[email protected]6f80e932012-06-04 19:00:07114
[email protected]69b04b92010-11-08 22:12:18115 // Accessors for fullscreen mode state.
[email protected]8d944b32011-10-17 06:11:53116 virtual void EnterFullscreen(const GURL& url,
117 FullscreenExitBubbleType bubble_type) = 0;
[email protected]55c87fa2011-10-15 07:28:28118 virtual void ExitFullscreen() = 0;
[email protected]8d944b32011-10-17 06:11:53119 virtual void UpdateFullscreenExitBubbleContent(
120 const GURL& url,
121 FullscreenExitBubbleType bubble_type) = 0;
[email protected]69b04b92010-11-08 22:12:18122
123 // Returns true if the fullscreen bubble is visible.
124 virtual bool IsFullscreenBubbleVisible() const = 0;
125
[email protected]77cbe50e2012-06-14 02:44:38126#if defined(OS_WIN)
127 // Sets state for entering or exiting Win8 Metro snap mode.
128 virtual void SetMetroSnapMode(bool enable) = 0;
129
130 // Returns whether the window is currently in Win8 Metro snap mode.
131 virtual bool IsInMetroSnapMode() const = 0;
132#endif
133
[email protected]69b04b92010-11-08 22:12:18134 // Returns the location bar.
135 virtual LocationBar* GetLocationBar() const = 0;
136
137 // Tries to focus the location bar. Clears the window focus (to avoid
138 // inconsistent state) if this fails.
139 virtual void SetFocusToLocationBar(bool select_all) = 0;
140
141 // Informs the view whether or not a load is in progress for the current tab.
142 // The view can use this notification to update the reload/stop button.
143 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
144
145 // Updates the toolbar with the state for the specified |contents|.
[email protected]4ebab8ee2012-06-11 22:52:01146 virtual void UpdateToolbar(TabContents* contents,
[email protected]69b04b92010-11-08 22:12:18147 bool should_restore_state) = 0;
148
149 // Focuses the toolbar (for accessibility).
150 virtual void FocusToolbar() = 0;
151
152 // Focuses the app menu like it was a menu bar.
153 //
154 // Not used on the Mac, which has a "normal" menu bar.
155 virtual void FocusAppMenu() = 0;
156
157 // Focuses the bookmarks toolbar (for accessibility).
158 virtual void FocusBookmarksToolbar() = 0;
159
[email protected]69b04b92010-11-08 22:12:18160 // Moves keyboard focus to the next pane.
161 virtual void RotatePaneFocus(bool forwards) = 0;
162
163 // Returns whether the bookmark bar is visible or not.
164 virtual bool IsBookmarkBarVisible() const = 0;
165
166 // Returns whether the bookmark bar is animating or not.
167 virtual bool IsBookmarkBarAnimating() const = 0;
168
[email protected]95bf8a5b2010-12-22 16:04:07169 // Returns whether the tab strip is editable (for extensions).
170 virtual bool IsTabStripEditable() const = 0;
171
[email protected]69b04b92010-11-08 22:12:18172 // Returns whether the tool bar is visible or not.
173 virtual bool IsToolbarVisible() const = 0;
174
[email protected]b7a756d42012-01-23 18:08:17175 // Returns the rect where the resize corner should be drawn by the render
176 // widget host view (on top of what the renderer returns). We return an empty
177 // rect to identify that there shouldn't be a resize corner (in the cases
178 // where we take care of it ourselves at the browser level).
179 virtual gfx::Rect GetRootWindowResizerRect() const = 0;
180
[email protected]5f58c2af2012-01-11 17:55:29181 // Returns whether the window is a panel. This is not always synonomous
182 // with the associated browser having type panel since some environments
183 // may draw popups in panel windows.
184 virtual bool IsPanel() const = 0;
185
[email protected]69b04b92010-11-08 22:12:18186 // Tells the frame not to render as inactive until the next activation change.
187 // This is required on Windows when dropdown selects are shown to prevent the
188 // select from deactivating the browser frame. A stub implementation is
189 // provided here since the functionality is Windows-specific.
190 virtual void DisableInactiveFrame() {}
191
[email protected]69b04b92010-11-08 22:12:18192 // Shows a confirmation dialog box for adding a search engine described by
193 // |template_url|. Takes ownership of |template_url|.
[email protected]3613347d2012-04-27 20:27:37194 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
[email protected]69b04b92010-11-08 22:12:18195 Profile* profile) = 0;
196
197 // Shows or hides the bookmark bar depending on its current visibility.
198 virtual void ToggleBookmarkBar() = 0;
199
[email protected]69b04b92010-11-08 22:12:18200 // Shows the Update Recommended dialog box.
201 virtual void ShowUpdateChromeDialog() = 0;
202
203 // Shows the Task manager.
204 virtual void ShowTaskManager() = 0;
205
[email protected]adb6a84d2011-02-07 16:58:40206 // Shows task information related to background pages.
207 virtual void ShowBackgroundPages() = 0;
208
[email protected]69b04b92010-11-08 22:12:18209 // Shows the Bookmark bubble. |url| is the URL being bookmarked,
210 // |already_bookmarked| is true if the url is already bookmarked.
211 virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0;
212
[email protected]195c99c2012-10-31 06:24:51213 // Shows the bookmark prompt.
214 // TODO(yosin): Make ShowBookmarkPrompt pure virtual.
215 virtual void ShowBookmarkPrompt() {}
216
[email protected]b106ca52012-03-13 06:08:46217 // Shows the Chrome To Mobile bubble.
218 virtual void ShowChromeToMobileBubble() = 0;
219
[email protected]235a0562012-03-26 22:22:35220#if defined(ENABLE_ONE_CLICK_SIGNIN)
[email protected]e4b66bf2012-05-29 20:39:51221 // Callback type used with the ShowOneClickSigninBubble() method. If the
222 // user chooses to accept the sign in, the callback is called to start the
223 // sync process.
224 typedef base::Callback<void(OneClickSigninSyncStarter::StartSyncMode)>
225 StartSyncCallback;
226
227 // Shows the one-click sign in bubble.
[email protected]fe54b4a2012-03-28 16:11:04228 virtual void ShowOneClickSigninBubble(
[email protected]e4b66bf2012-05-29 20:39:51229 const StartSyncCallback& start_sync_callback) = 0;
[email protected]235a0562012-03-26 22:22:35230#endif
231
[email protected]69b04b92010-11-08 22:12:18232 // Whether or not the shelf view is visible.
233 virtual bool IsDownloadShelfVisible() const = 0;
234
235 // Returns the DownloadShelf.
236 virtual DownloadShelf* GetDownloadShelf() = 0;
237
[email protected]69b04b92010-11-08 22:12:18238 // Shows the confirmation dialog box warning that the browser is closing with
239 // in-progress downloads.
240 // This method should call Browser::InProgressDownloadResponse once the user
241 // has confirmed.
242 virtual void ConfirmBrowserCloseWithPendingDownloads() = 0;
243
[email protected]a0ea76c2011-03-23 17:36:42244 // ThemeService calls this when a user has changed his or her theme,
[email protected]69b04b92010-11-08 22:12:18245 // indicating that it's time to redraw everything.
246 virtual void UserChangedTheme() = 0;
247
248 // Get extra vertical height that the render view should add to its requests
249 // to webkit. This can help prevent sending extraneous layout/repaint requests
250 // when the delegate is in the process of resizing the tab contents view (e.g.
251 // during infobar animations).
252 virtual int GetExtraRenderViewHeight() const = 0;
253
[email protected]2a6bc3e2011-12-28 23:51:33254 // Notification that |contents| got the focus through user action (click
[email protected]69b04b92010-11-08 22:12:18255 // on the page).
[email protected]2a6bc3e2011-12-28 23:51:33256 virtual void WebContentsFocused(content::WebContents* contents) = 0;
[email protected]69b04b92010-11-08 22:12:18257
258 // Shows the page info using the specified information.
259 // |url| is the url of the page/frame the info applies to, |ssl| is the SSL
260 // information for that page/frame. If |show_history| is true, a section
261 // showing how many times that URL has been visited is added to the page info.
[email protected]4eb4ec02012-06-19 15:54:21262 virtual void ShowPageInfo(content::WebContents* web_contents,
[email protected]69b04b92010-11-08 22:12:18263 const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17264 const content::SSLStatus& ssl,
[email protected]69b04b92010-11-08 22:12:18265 bool show_history) = 0;
266
[email protected]b8e681e82012-02-20 10:18:47267 // Shows the website settings using the specified information. |url| is the
268 // url of the page/frame the info applies to, |ssl| is the SSL information for
269 // that page/frame. If |show_history| is true, a section showing how many
270 // times that URL has been visited is added to the page info.
271 virtual void ShowWebsiteSettings(Profile* profile,
[email protected]4ebab8ee2012-06-11 22:52:01272 TabContents* tab_contents,
[email protected]b8e681e82012-02-20 10:18:47273 const GURL& url,
274 const content::SSLStatus& ssl,
275 bool show_history) = 0;
276
[email protected]69b04b92010-11-08 22:12:18277 // Shows the app menu (for accessibility).
278 virtual void ShowAppMenu() = 0;
279
280 // Allows the BrowserWindow object to handle the specified keyboard event
281 // before sending it to the renderer.
282 // Returns true if the |event| was handled. Otherwise, if the |event| would
283 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
284 // |*is_keyboard_shortcut| should be set to true.
[email protected]b87ee522012-05-18 15:16:54285 virtual bool PreHandleKeyboardEvent(
286 const content::NativeWebKeyboardEvent& event,
287 bool* is_keyboard_shortcut) = 0;
[email protected]69b04b92010-11-08 22:12:18288
289 // Allows the BrowserWindow object to handle the specified keyboard event,
290 // if the renderer did not process it.
[email protected]b87ee522012-05-18 15:16:54291 virtual void HandleKeyboardEvent(
292 const content::NativeWebKeyboardEvent& event) = 0;
[email protected]69b04b92010-11-08 22:12:18293
[email protected]a3b734b2010-11-30 03:17:11294 // Shows the create chrome app shortcut dialog box.
295 virtual void ShowCreateChromeAppShortcutsDialog(Profile* profile,
[email protected]1c321ee2012-05-21 03:02:34296 const extensions::Extension* app) = 0;
297
[email protected]69b04b92010-11-08 22:12:18298 // Clipboard commands applied to the whole browser window.
299 virtual void Cut() = 0;
300 virtual void Copy() = 0;
301 virtual void Paste() = 0;
302
[email protected]69b04b92010-11-08 22:12:18303#if defined(OS_MACOSX)
304 // Opens the tabpose view.
305 virtual void OpenTabpose() = 0;
[email protected]d3766932011-08-04 22:18:23306
307 // Sets the presentation mode for the window. If the window is not already in
308 // fullscreen, also enters fullscreen mode.
[email protected]8d944b32011-10-17 06:11:53309 virtual void EnterPresentationMode(
310 const GURL& url,
311 FullscreenExitBubbleType bubble_type) = 0;
312 virtual void ExitPresentationMode() = 0;
[email protected]d3766932011-08-04 22:18:23313 virtual bool InPresentationMode() = 0;
[email protected]69b04b92010-11-08 22:12:18314#endif
315
[email protected]e41982a72012-11-20 07:16:51316 // Returns the desired bounds for Instant in screen coordinates. Note that if
317 // Instant isn't currently visible this returns the bounds Instant would be
[email protected]69b04b92010-11-08 22:12:18318 // placed at.
319 virtual gfx::Rect GetInstantBounds() = 0;
320
[email protected]e41982a72012-11-20 07:16:51321 // Checks if an Instant's tab contents is being shown.
[email protected]85fd03e2012-09-04 22:50:14322 virtual bool IsInstantTabShowing() = 0;
323
[email protected]588300d2011-04-28 21:06:35324 // Return the correct disposition for a popup window based on |bounds|.
325 virtual WindowOpenDisposition GetDispositionForPopupBounds(
326 const gfx::Rect& bounds) = 0;
327
[email protected]632983f2011-08-08 22:51:24328 // Construct a FindBar implementation for the |browser|.
329 virtual FindBar* CreateFindBar() = 0;
330
[email protected]d3afce92012-10-07 05:47:36331 // Updates the |top_y| where the top of the constrained window should be
[email protected]4cb7d3fc2012-10-09 17:32:10332 // positioned. When implemented, the method returns true and the value of
333 // |top_y| is non-negative. When not implemented, the method returns false and
334 // the value of |top_y| is not defined.
[email protected]d3afce92012-10-07 05:47:36335 virtual bool GetConstrainedWindowTopY(int* top_y) = 0;
[email protected]6a151762012-10-03 22:33:19336
[email protected]0548c5352011-09-07 00:33:33337 // Invoked when the preferred size of the contents in current tab has been
338 // changed. We might choose to update the window size to accomodate this
339 // change.
340 // Note that this won't be fired if we change tabs.
[email protected]2a6bc3e2011-12-28 23:51:33341 virtual void UpdatePreferredSize(content::WebContents* web_contents,
[email protected]0548c5352011-09-07 00:33:33342 const gfx::Size& pref_size) {}
343
[email protected]61e2b3cc2012-03-02 16:13:34344 // Invoked when the contents auto-resized and the container should match it.
345 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
346 const gfx::Size& new_size) {}
347
[email protected]69b04b92010-11-08 22:12:18348 // Construct a BrowserWindow implementation for the specified |browser|.
349 static BrowserWindow* CreateBrowserWindow(Browser* browser);
350
[email protected]0ec4898e2011-12-30 21:09:24351 // Shows the avatar bubble inside |web_contents|. The bubble is positioned
352 // relative to |rect|. |rect| should be in the |web_contents| coordinate
[email protected]2f733a02011-10-06 15:17:34353 // system.
[email protected]0ec4898e2011-12-30 21:09:24354 virtual void ShowAvatarBubble(content::WebContents* web_contents,
[email protected]2f733a02011-10-06 15:17:34355 const gfx::Rect& rect) = 0;
356
[email protected]7d2d08152011-10-25 22:58:47357 // Shows the avatar bubble on the window frame off of the avatar button.
358 virtual void ShowAvatarBubbleFromAvatarButton() = 0;
359
[email protected]e0f90fc2012-06-06 19:30:10360 // Show bubble for password generation positioned relative to |rect|. The
361 // subclasses implementing this interface do not own the |password_generator|
362 // object which is passed to generate the password. |form| is the form that
363 // contains the password field that the bubble will be associated with. A
364 // stub implementation is provided since this feature is currently not
365 // available on mac.
[email protected]4d5ef8692012-05-31 02:28:57366 virtual void ShowPasswordGenerationBubble(
367 const gfx::Rect& rect,
[email protected]1ecbe862012-10-05 01:29:14368 const content::PasswordForm& form,
[email protected]cc5419d2012-08-30 02:29:46369 autofill::PasswordGenerator* password_generator) {}
[email protected]90ee09232012-03-21 02:01:01370
[email protected]69b04b92010-11-08 22:12:18371 protected:
[email protected]2e6389f2012-05-18 19:41:25372 friend void browser::CloseAllBrowsers();
[email protected]69b04b92010-11-08 22:12:18373 friend class BrowserView;
374 virtual void DestroyBrowser() = 0;
[email protected]69b04b92010-11-08 22:12:18375};
376
377#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
378class BookmarkBarView;
379class LocationBarView;
380
381namespace views {
382class View;
383}
384#endif // defined(OS_WIN)
385
386// A BrowserWindow utility interface used for accessing elements of the browser
387// UI used only by UI test automation.
388class BrowserWindowTesting {
389 public:
390#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
391 // Returns the BookmarkBarView.
392 virtual BookmarkBarView* GetBookmarkBarView() const = 0;
393
394 // Returns the LocationBarView.
395 virtual LocationBarView* GetLocationBarView() const = 0;
396
397 // Returns the TabContentsContainer.
398 virtual views::View* GetTabContentsContainerView() const = 0;
399
[email protected]69b04b92010-11-08 22:12:18400 // Returns the ToolbarView.
401 virtual ToolbarView* GetToolbarView() const = 0;
402#endif
403
404 protected:
405 virtual ~BrowserWindowTesting() {}
406};
407
408#endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_