blob: a8f7c30fce9596f47a47c87d90a6f5f302938323 [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]2e9d79f2013-08-16 05:45:569#include "chrome/browser/lifetime/browser_close_manager.h"
[email protected]09b29342011-06-24 19:18:4810#include "chrome/browser/ui/bookmarks/bookmark_bar.h"
[email protected]9d5c059a82012-06-29 20:13:0711#include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h"
[email protected]ddeb0e8432012-12-21 07:27:5412#include "chrome/browser/ui/host_desktop.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]5f39adc2013-05-23 11:50:4615#include "ui/base/base_window.h"
[email protected]f47621b2013-01-22 20:50:3316#include "ui/base/window_open_disposition.h"
[email protected]08397d52011-02-05 01:53:3817#include "ui/gfx/native_widget_types.h"
[email protected]69b04b92010-11-08 22:12:1818
19class Browser;
20class BrowserWindowTesting;
21class DownloadShelf;
22class FindBar;
23class GURL;
[email protected]69b04b92010-11-08 22:12:1824class LocationBar;
25class Profile;
26class StatusBubble;
[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]e41d0082013-05-16 04:37:5451namespace web_modal {
52class WebContentsModalDialogHost;
53}
54
[email protected]69b04b92010-11-08 22:12:1855////////////////////////////////////////////////////////////////////////////////
56// BrowserWindow interface
57// An interface implemented by the "view" of the Browser window.
[email protected]5f39adc2013-05-23 11:50:4658// This interface includes ui::BaseWindow methods as well as Browser window
[email protected]41d9faf2012-02-28 23:46:0259// specific methods.
[email protected]69b04b92010-11-08 22:12:1860//
61// NOTE: All getters may return NULL.
[email protected]41d9faf2012-02-28 23:46:0262//
[email protected]5f39adc2013-05-23 11:50:4663class BrowserWindow : public ui::BaseWindow {
[email protected]69b04b92010-11-08 22:12:1864 public:
[email protected]ed2f27132011-04-04 17:19:5765 virtual ~BrowserWindow() {}
66
[email protected]41d9faf2012-02-28 23:46:0267 //////////////////////////////////////////////////////////////////////////////
[email protected]5f39adc2013-05-23 11:50:4668 // ui::BaseWindow interface notes:
[email protected]69b04b92010-11-08 22:12:1869
[email protected]41d9faf2012-02-28 23:46:0270 // Closes the window as soon as possible. If the window is not in a drag
[email protected]69b04b92010-11-08 22:12:1871 // session, it will close immediately; otherwise, it will move offscreen (so
72 // events are still fired) until the drag ends, then close. This assumes
73 // that the Browser is not immediately destroyed, but will be eventually
74 // destroyed by other means (eg, the tab strip going to zero elements).
75 // Bad things happen if the Browser dtor is called directly as a result of
76 // invoking this method.
[email protected]41d9faf2012-02-28 23:46:0277 // virtual void Close() = 0;
[email protected]69b04b92010-11-08 22:12:1878
[email protected]41d9faf2012-02-28 23:46:0279 // Browser::OnWindowDidShow should be called after showing the window.
80 // virtual void Show() = 0;
[email protected]69b04b92010-11-08 22:12:1881
[email protected]41d9faf2012-02-28 23:46:0282 //////////////////////////////////////////////////////////////////////////////
83 // Browser specific methods:
[email protected]69b04b92010-11-08 22:12:1884
[email protected]69b04b92010-11-08 22:12:1885 // Returns a pointer to the testing interface to the Browser window, or NULL
86 // if there is none.
87 virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0;
88
89 // Return the status bubble associated with the frame
90 virtual StatusBubble* GetStatusBubble() = 0;
91
[email protected]69b04b92010-11-08 22:12:1892 // Inform the frame that the selected tab favicon or title has changed. Some
93 // frames may need to refresh their title bar.
94 virtual void UpdateTitleBar() = 0;
95
[email protected]09b29342011-06-24 19:18:4896 // Invoked when the state of the bookmark bar changes. This is only invoked if
97 // the state changes for the current tab, it is not sent when switching tabs.
98 virtual void BookmarkBarStateChanged(
99 BookmarkBar::AnimateChangeType change_type) = 0;
[email protected]69b04b92010-11-08 22:12:18100
101 // Inform the frame that the dev tools window for the selected tab has
102 // changed.
103 virtual void UpdateDevTools() = 0;
104
105 // Update any loading animations running in the window. |should_animate| is
106 // true if there are tabs loading and the animations should continue, false
107 // if there are no active loads and the animations should end.
108 virtual void UpdateLoadingAnimations(bool should_animate) = 0;
109
110 // Sets the starred state for the current tab.
111 virtual void SetStarredState(bool is_starred) = 0;
112
[email protected]5423c372012-08-22 05:50:16113 // Called to force the zoom state to for the active tab to be recalculated.
114 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
115 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
116 // + or - in the wrench menu to change zoom).
117 virtual void ZoomChangedForActiveTab(bool can_show_bubble) = 0;
[email protected]6f80e932012-06-04 19:00:07118
[email protected]69b04b92010-11-08 22:12:18119 // Accessors for fullscreen mode state.
[email protected]8d944b32011-10-17 06:11:53120 virtual void EnterFullscreen(const GURL& url,
121 FullscreenExitBubbleType bubble_type) = 0;
[email protected]55c87fa2011-10-15 07:28:28122 virtual void ExitFullscreen() = 0;
[email protected]8d944b32011-10-17 06:11:53123 virtual void UpdateFullscreenExitBubbleContent(
124 const GURL& url,
125 FullscreenExitBubbleType bubble_type) = 0;
[email protected]69b04b92010-11-08 22:12:18126
[email protected]6a414ff2013-02-27 08:22:54127 // Windows and GTK remove the top controls in fullscreen, but Mac and Ash
128 // keep the controls in a slide-down panel.
129 virtual bool ShouldHideUIForFullscreen() const = 0;
130
[email protected]69b04b92010-11-08 22:12:18131 // Returns true if the fullscreen bubble is visible.
132 virtual bool IsFullscreenBubbleVisible() const = 0;
133
[email protected]77cbe50e2012-06-14 02:44:38134#if defined(OS_WIN)
135 // Sets state for entering or exiting Win8 Metro snap mode.
136 virtual void SetMetroSnapMode(bool enable) = 0;
137
138 // Returns whether the window is currently in Win8 Metro snap mode.
139 virtual bool IsInMetroSnapMode() const = 0;
140#endif
141
[email protected]69b04b92010-11-08 22:12:18142 // Returns the location bar.
143 virtual LocationBar* GetLocationBar() const = 0;
144
145 // Tries to focus the location bar. Clears the window focus (to avoid
146 // inconsistent state) if this fails.
147 virtual void SetFocusToLocationBar(bool select_all) = 0;
148
149 // Informs the view whether or not a load is in progress for the current tab.
150 // The view can use this notification to update the reload/stop button.
151 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
152
153 // Updates the toolbar with the state for the specified |contents|.
[email protected]36ad4aa82012-11-21 19:20:48154 virtual void UpdateToolbar(content::WebContents* contents,
[email protected]69b04b92010-11-08 22:12:18155 bool should_restore_state) = 0;
156
157 // Focuses the toolbar (for accessibility).
158 virtual void FocusToolbar() = 0;
159
160 // Focuses the app menu like it was a menu bar.
161 //
162 // Not used on the Mac, which has a "normal" menu bar.
163 virtual void FocusAppMenu() = 0;
164
165 // Focuses the bookmarks toolbar (for accessibility).
166 virtual void FocusBookmarksToolbar() = 0;
167
[email protected]822ca8c62013-04-19 00:49:15168 // Focuses an infobar, if shown (for accessibility).
169 virtual void FocusInfobars() = 0;
170
[email protected]69b04b92010-11-08 22:12:18171 // Moves keyboard focus to the next pane.
172 virtual void RotatePaneFocus(bool forwards) = 0;
173
174 // Returns whether the bookmark bar is visible or not.
175 virtual bool IsBookmarkBarVisible() const = 0;
176
177 // Returns whether the bookmark bar is animating or not.
178 virtual bool IsBookmarkBarAnimating() const = 0;
179
[email protected]95bf8a5b2010-12-22 16:04:07180 // Returns whether the tab strip is editable (for extensions).
181 virtual bool IsTabStripEditable() const = 0;
182
[email protected]69b04b92010-11-08 22:12:18183 // Returns whether the tool bar is visible or not.
184 virtual bool IsToolbarVisible() const = 0;
185
[email protected]b7a756d42012-01-23 18:08:17186 // Returns the rect where the resize corner should be drawn by the render
187 // widget host view (on top of what the renderer returns). We return an empty
188 // rect to identify that there shouldn't be a resize corner (in the cases
189 // where we take care of it ourselves at the browser level).
190 virtual gfx::Rect GetRootWindowResizerRect() const = 0;
191
[email protected]69b04b92010-11-08 22:12:18192 // Tells the frame not to render as inactive until the next activation change.
193 // This is required on Windows when dropdown selects are shown to prevent the
194 // select from deactivating the browser frame. A stub implementation is
195 // provided here since the functionality is Windows-specific.
196 virtual void DisableInactiveFrame() {}
197
[email protected]69b04b92010-11-08 22:12:18198 // Shows a confirmation dialog box for adding a search engine described by
199 // |template_url|. Takes ownership of |template_url|.
[email protected]3613347d2012-04-27 20:27:37200 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
[email protected]69b04b92010-11-08 22:12:18201 Profile* profile) = 0;
202
203 // Shows or hides the bookmark bar depending on its current visibility.
204 virtual void ToggleBookmarkBar() = 0;
205
[email protected]69b04b92010-11-08 22:12:18206 // Shows the Update Recommended dialog box.
207 virtual void ShowUpdateChromeDialog() = 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]235a0562012-03-26 22:22:35217#if defined(ENABLE_ONE_CLICK_SIGNIN)
[email protected]265c9272013-01-25 19:18:45218 enum OneClickSigninBubbleType {
219 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
[email protected]0cf5d282013-04-12 18:33:12220 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG,
221 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
[email protected]265c9272013-01-25 19:18:45222 };
223
[email protected]e4b66bf2012-05-29 20:39:51224 // Callback type used with the ShowOneClickSigninBubble() method. If the
225 // user chooses to accept the sign in, the callback is called to start the
226 // sync process.
227 typedef base::Callback<void(OneClickSigninSyncStarter::StartSyncMode)>
228 StartSyncCallback;
229
[email protected]0cf5d282013-04-12 18:33:12230 // Shows the one-click sign in bubble. |email| holds the full email address
231 // of the account that has signed in.
[email protected]fe54b4a2012-03-28 16:11:04232 virtual void ShowOneClickSigninBubble(
[email protected]265c9272013-01-25 19:18:45233 OneClickSigninBubbleType type,
[email protected]0cf5d282013-04-12 18:33:12234 const string16& email,
[email protected]62e86372013-05-01 15:59:25235 const string16& error_message,
[email protected]e4b66bf2012-05-29 20:39:51236 const StartSyncCallback& start_sync_callback) = 0;
[email protected]62e86372013-05-01 15:59:25237 #endif
[email protected]235a0562012-03-26 22:22:35238
[email protected]69b04b92010-11-08 22:12:18239 // Whether or not the shelf view is visible.
240 virtual bool IsDownloadShelfVisible() const = 0;
241
242 // Returns the DownloadShelf.
243 virtual DownloadShelf* GetDownloadShelf() = 0;
244
[email protected]69b04b92010-11-08 22:12:18245 // Shows the confirmation dialog box warning that the browser is closing with
246 // in-progress downloads.
247 // This method should call Browser::InProgressDownloadResponse once the user
248 // has confirmed.
249 virtual void ConfirmBrowserCloseWithPendingDownloads() = 0;
250
[email protected]a0ea76c2011-03-23 17:36:42251 // ThemeService calls this when a user has changed his or her theme,
[email protected]69b04b92010-11-08 22:12:18252 // indicating that it's time to redraw everything.
253 virtual void UserChangedTheme() = 0;
254
255 // Get extra vertical height that the render view should add to its requests
256 // to webkit. This can help prevent sending extraneous layout/repaint requests
257 // when the delegate is in the process of resizing the tab contents view (e.g.
258 // during infobar animations).
259 virtual int GetExtraRenderViewHeight() const = 0;
260
[email protected]2a6bc3e2011-12-28 23:51:33261 // Notification that |contents| got the focus through user action (click
[email protected]69b04b92010-11-08 22:12:18262 // on the page).
[email protected]2a6bc3e2011-12-28 23:51:33263 virtual void WebContentsFocused(content::WebContents* contents) = 0;
[email protected]69b04b92010-11-08 22:12:18264
[email protected]b8e681e82012-02-20 10:18:47265 // Shows the website settings using the specified information. |url| is the
266 // url of the page/frame the info applies to, |ssl| is the SSL information for
267 // that page/frame. If |show_history| is true, a section showing how many
268 // times that URL has been visited is added to the page info.
269 virtual void ShowWebsiteSettings(Profile* profile,
[email protected]36ad4aa82012-11-21 19:20:48270 content::WebContents* web_contents,
[email protected]b8e681e82012-02-20 10:18:47271 const GURL& url,
[email protected]9fb47a82013-07-05 11:34:02272 const content::SSLStatus& ssl) = 0;
[email protected]b8e681e82012-02-20 10:18:47273
[email protected]69b04b92010-11-08 22:12:18274 // Shows the app menu (for accessibility).
275 virtual void ShowAppMenu() = 0;
276
277 // Allows the BrowserWindow object to handle the specified keyboard event
278 // before sending it to the renderer.
279 // Returns true if the |event| was handled. Otherwise, if the |event| would
280 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
281 // |*is_keyboard_shortcut| should be set to true.
[email protected]b87ee522012-05-18 15:16:54282 virtual bool PreHandleKeyboardEvent(
283 const content::NativeWebKeyboardEvent& event,
284 bool* is_keyboard_shortcut) = 0;
[email protected]69b04b92010-11-08 22:12:18285
286 // Allows the BrowserWindow object to handle the specified keyboard event,
287 // if the renderer did not process it.
[email protected]b87ee522012-05-18 15:16:54288 virtual void HandleKeyboardEvent(
289 const content::NativeWebKeyboardEvent& event) = 0;
[email protected]69b04b92010-11-08 22:12:18290
[email protected]a3b734b2010-11-30 03:17:11291 // Shows the create chrome app shortcut dialog box.
292 virtual void ShowCreateChromeAppShortcutsDialog(Profile* profile,
[email protected]1c321ee2012-05-21 03:02:34293 const extensions::Extension* app) = 0;
294
[email protected]69b04b92010-11-08 22:12:18295 // Clipboard commands applied to the whole browser window.
296 virtual void Cut() = 0;
297 virtual void Copy() = 0;
298 virtual void Paste() = 0;
299
[email protected]69b04b92010-11-08 22:12:18300#if defined(OS_MACOSX)
301 // Opens the tabpose view.
302 virtual void OpenTabpose() = 0;
[email protected]d3766932011-08-04 22:18:23303
[email protected]34337d32013-01-29 20:29:01304 // Enters Mac specific fullscreen mode with chrome displayed (e.g. omnibox)
305 // on OSX 10.7+, a.k.a. Lion Fullscreen mode.
306 // Invalid to call on OSX earlier than 10.7.
307 // Enters either from non fullscreen, or from fullscreen without chrome.
308 // Exit to normal fullscreen with EnterFullscreen().
309 virtual void EnterFullscreenWithChrome() = 0;
310 virtual bool IsFullscreenWithChrome() = 0;
311 virtual bool IsFullscreenWithoutChrome() = 0;
[email protected]69b04b92010-11-08 22:12:18312#endif
313
[email protected]588300d2011-04-28 21:06:35314 // Return the correct disposition for a popup window based on |bounds|.
315 virtual WindowOpenDisposition GetDispositionForPopupBounds(
316 const gfx::Rect& bounds) = 0;
317
[email protected]632983f2011-08-08 22:51:24318 // Construct a FindBar implementation for the |browser|.
319 virtual FindBar* CreateFindBar() = 0;
320
[email protected]7519c522013-04-02 01:07:23321 // Return the WebContentsModalDialogHost for use in positioning web contents
322 // modal dialogs within the browser window.
[email protected]e41d0082013-05-16 04:37:54323 virtual web_modal::WebContentsModalDialogHost*
324 GetWebContentsModalDialogHost() = 0;
[email protected]6a151762012-10-03 22:33:19325
[email protected]0548c5352011-09-07 00:33:33326 // Invoked when the preferred size of the contents in current tab has been
327 // changed. We might choose to update the window size to accomodate this
328 // change.
329 // Note that this won't be fired if we change tabs.
[email protected]2a6bc3e2011-12-28 23:51:33330 virtual void UpdatePreferredSize(content::WebContents* web_contents,
[email protected]0548c5352011-09-07 00:33:33331 const gfx::Size& pref_size) {}
332
[email protected]61e2b3cc2012-03-02 16:13:34333 // Invoked when the contents auto-resized and the container should match it.
334 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
335 const gfx::Size& new_size) {}
336
[email protected]69b04b92010-11-08 22:12:18337 // Construct a BrowserWindow implementation for the specified |browser|.
338 static BrowserWindow* CreateBrowserWindow(Browser* browser);
339
[email protected]0ec4898e2011-12-30 21:09:24340 // Shows the avatar bubble inside |web_contents|. The bubble is positioned
341 // relative to |rect|. |rect| should be in the |web_contents| coordinate
[email protected]2f733a02011-10-06 15:17:34342 // system.
[email protected]0ec4898e2011-12-30 21:09:24343 virtual void ShowAvatarBubble(content::WebContents* web_contents,
[email protected]2f733a02011-10-06 15:17:34344 const gfx::Rect& rect) = 0;
345
[email protected]7d2d08152011-10-25 22:58:47346 // Shows the avatar bubble on the window frame off of the avatar button.
347 virtual void ShowAvatarBubbleFromAvatarButton() = 0;
348
[email protected]e0f90fc2012-06-06 19:30:10349 // Show bubble for password generation positioned relative to |rect|. The
350 // subclasses implementing this interface do not own the |password_generator|
351 // object which is passed to generate the password. |form| is the form that
[email protected]f5d230b32012-12-11 02:04:11352 // contains the password field that the bubble will be associated with.
[email protected]4d5ef8692012-05-31 02:28:57353 virtual void ShowPasswordGenerationBubble(
354 const gfx::Rect& rect,
[email protected]1ecbe862012-10-05 01:29:14355 const content::PasswordForm& form,
[email protected]f5d230b32012-12-11 02:04:11356 autofill::PasswordGenerator* password_generator) = 0;
[email protected]90ee09232012-03-21 02:01:01357
[email protected]888878e82013-07-24 22:49:40358 // Invoked when the amount of vertical overscroll changes. |delta_y| is the
359 // amount of overscroll that has occured in the y-direction.
360 virtual void OverscrollUpdate(int delta_y) {}
361
[email protected]69b04b92010-11-08 22:12:18362 protected:
[email protected]2e9d79f2013-08-16 05:45:56363 friend class BrowserCloseManager;
[email protected]69b04b92010-11-08 22:12:18364 friend class BrowserView;
365 virtual void DestroyBrowser() = 0;
[email protected]69b04b92010-11-08 22:12:18366};
367
368#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
369class BookmarkBarView;
370class LocationBarView;
371
372namespace views {
373class View;
374}
375#endif // defined(OS_WIN)
376
377// A BrowserWindow utility interface used for accessing elements of the browser
378// UI used only by UI test automation.
379class BrowserWindowTesting {
380 public:
381#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
382 // Returns the BookmarkBarView.
383 virtual BookmarkBarView* GetBookmarkBarView() const = 0;
384
385 // Returns the LocationBarView.
386 virtual LocationBarView* GetLocationBarView() const = 0;
387
388 // Returns the TabContentsContainer.
389 virtual views::View* GetTabContentsContainerView() const = 0;
390
[email protected]69b04b92010-11-08 22:12:18391 // Returns the ToolbarView.
392 virtual ToolbarView* GetToolbarView() const = 0;
393#endif
394
395 protected:
396 virtual ~BrowserWindowTesting() {}
397};
398
399#endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_