blob: d4381b80d8bf71ad98ef79ebfd851482ccf618f4 [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]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]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]265c9272013-01-25 19:18:45221 enum OneClickSigninBubbleType {
222 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
[email protected]0cf5d282013-04-12 18:33:12223 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG,
224 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
[email protected]265c9272013-01-25 19:18:45225 };
226
[email protected]e4b66bf2012-05-29 20:39:51227 // Callback type used with the ShowOneClickSigninBubble() method. If the
228 // user chooses to accept the sign in, the callback is called to start the
229 // sync process.
230 typedef base::Callback<void(OneClickSigninSyncStarter::StartSyncMode)>
231 StartSyncCallback;
232
[email protected]0cf5d282013-04-12 18:33:12233 // Shows the one-click sign in bubble. |email| holds the full email address
234 // of the account that has signed in.
[email protected]fe54b4a2012-03-28 16:11:04235 virtual void ShowOneClickSigninBubble(
[email protected]265c9272013-01-25 19:18:45236 OneClickSigninBubbleType type,
[email protected]0cf5d282013-04-12 18:33:12237 const string16& email,
[email protected]62e86372013-05-01 15:59:25238 const string16& error_message,
[email protected]e4b66bf2012-05-29 20:39:51239 const StartSyncCallback& start_sync_callback) = 0;
[email protected]62e86372013-05-01 15:59:25240 #endif
[email protected]235a0562012-03-26 22:22:35241
[email protected]69b04b92010-11-08 22:12:18242 // Whether or not the shelf view is visible.
243 virtual bool IsDownloadShelfVisible() const = 0;
244
245 // Returns the DownloadShelf.
246 virtual DownloadShelf* GetDownloadShelf() = 0;
247
[email protected]69b04b92010-11-08 22:12:18248 // Shows the confirmation dialog box warning that the browser is closing with
249 // in-progress downloads.
250 // This method should call Browser::InProgressDownloadResponse once the user
251 // has confirmed.
252 virtual void ConfirmBrowserCloseWithPendingDownloads() = 0;
253
[email protected]a0ea76c2011-03-23 17:36:42254 // ThemeService calls this when a user has changed his or her theme,
[email protected]69b04b92010-11-08 22:12:18255 // indicating that it's time to redraw everything.
256 virtual void UserChangedTheme() = 0;
257
258 // Get extra vertical height that the render view should add to its requests
259 // to webkit. This can help prevent sending extraneous layout/repaint requests
260 // when the delegate is in the process of resizing the tab contents view (e.g.
261 // during infobar animations).
262 virtual int GetExtraRenderViewHeight() const = 0;
263
[email protected]2a6bc3e2011-12-28 23:51:33264 // Notification that |contents| got the focus through user action (click
[email protected]69b04b92010-11-08 22:12:18265 // on the page).
[email protected]2a6bc3e2011-12-28 23:51:33266 virtual void WebContentsFocused(content::WebContents* contents) = 0;
[email protected]69b04b92010-11-08 22:12:18267
[email protected]b8e681e82012-02-20 10:18:47268 // Shows the website settings using the specified information. |url| is the
269 // url of the page/frame the info applies to, |ssl| is the SSL information for
270 // that page/frame. If |show_history| is true, a section showing how many
271 // times that URL has been visited is added to the page info.
272 virtual void ShowWebsiteSettings(Profile* profile,
[email protected]36ad4aa82012-11-21 19:20:48273 content::WebContents* web_contents,
[email protected]b8e681e82012-02-20 10:18:47274 const GURL& url,
[email protected]9fb47a82013-07-05 11:34:02275 const content::SSLStatus& ssl) = 0;
[email protected]b8e681e82012-02-20 10:18:47276
[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
[email protected]34337d32013-01-29 20:29:01307 // Enters Mac specific fullscreen mode with chrome displayed (e.g. omnibox)
308 // on OSX 10.7+, a.k.a. Lion Fullscreen mode.
309 // Invalid to call on OSX earlier than 10.7.
310 // Enters either from non fullscreen, or from fullscreen without chrome.
311 // Exit to normal fullscreen with EnterFullscreen().
312 virtual void EnterFullscreenWithChrome() = 0;
313 virtual bool IsFullscreenWithChrome() = 0;
314 virtual bool IsFullscreenWithoutChrome() = 0;
[email protected]69b04b92010-11-08 22:12:18315#endif
316
[email protected]e41982a72012-11-20 07:16:51317 // Returns the desired bounds for Instant in screen coordinates. Note that if
318 // Instant isn't currently visible this returns the bounds Instant would be
[email protected]69b04b92010-11-08 22:12:18319 // placed at.
320 virtual gfx::Rect GetInstantBounds() = 0;
321
[email protected]588300d2011-04-28 21:06:35322 // Return the correct disposition for a popup window based on |bounds|.
323 virtual WindowOpenDisposition GetDispositionForPopupBounds(
324 const gfx::Rect& bounds) = 0;
325
[email protected]632983f2011-08-08 22:51:24326 // Construct a FindBar implementation for the |browser|.
327 virtual FindBar* CreateFindBar() = 0;
328
[email protected]7519c522013-04-02 01:07:23329 // Return the WebContentsModalDialogHost for use in positioning web contents
330 // modal dialogs within the browser window.
[email protected]e41d0082013-05-16 04:37:54331 virtual web_modal::WebContentsModalDialogHost*
332 GetWebContentsModalDialogHost() = 0;
[email protected]6a151762012-10-03 22:33:19333
[email protected]0548c5352011-09-07 00:33:33334 // Invoked when the preferred size of the contents in current tab has been
335 // changed. We might choose to update the window size to accomodate this
336 // change.
337 // Note that this won't be fired if we change tabs.
[email protected]2a6bc3e2011-12-28 23:51:33338 virtual void UpdatePreferredSize(content::WebContents* web_contents,
[email protected]0548c5352011-09-07 00:33:33339 const gfx::Size& pref_size) {}
340
[email protected]61e2b3cc2012-03-02 16:13:34341 // Invoked when the contents auto-resized and the container should match it.
342 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
343 const gfx::Size& new_size) {}
344
[email protected]69b04b92010-11-08 22:12:18345 // Construct a BrowserWindow implementation for the specified |browser|.
346 static BrowserWindow* CreateBrowserWindow(Browser* browser);
347
[email protected]0ec4898e2011-12-30 21:09:24348 // Shows the avatar bubble inside |web_contents|. The bubble is positioned
349 // relative to |rect|. |rect| should be in the |web_contents| coordinate
[email protected]2f733a02011-10-06 15:17:34350 // system.
[email protected]0ec4898e2011-12-30 21:09:24351 virtual void ShowAvatarBubble(content::WebContents* web_contents,
[email protected]2f733a02011-10-06 15:17:34352 const gfx::Rect& rect) = 0;
353
[email protected]7d2d08152011-10-25 22:58:47354 // Shows the avatar bubble on the window frame off of the avatar button.
355 virtual void ShowAvatarBubbleFromAvatarButton() = 0;
356
[email protected]e0f90fc2012-06-06 19:30:10357 // Show bubble for password generation positioned relative to |rect|. The
358 // subclasses implementing this interface do not own the |password_generator|
359 // object which is passed to generate the password. |form| is the form that
[email protected]f5d230b32012-12-11 02:04:11360 // contains the password field that the bubble will be associated with.
[email protected]4d5ef8692012-05-31 02:28:57361 virtual void ShowPasswordGenerationBubble(
362 const gfx::Rect& rect,
[email protected]1ecbe862012-10-05 01:29:14363 const content::PasswordForm& form,
[email protected]f5d230b32012-12-11 02:04:11364 autofill::PasswordGenerator* password_generator) = 0;
[email protected]90ee09232012-03-21 02:01:01365
[email protected]69b04b92010-11-08 22:12:18366 protected:
[email protected]0c98ab652013-02-18 00:39:37367 friend void chrome::CloseAllBrowsers();
[email protected]69b04b92010-11-08 22:12:18368 friend class BrowserView;
369 virtual void DestroyBrowser() = 0;
[email protected]69b04b92010-11-08 22:12:18370};
371
372#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
373class BookmarkBarView;
374class LocationBarView;
375
376namespace views {
377class View;
378}
379#endif // defined(OS_WIN)
380
381// A BrowserWindow utility interface used for accessing elements of the browser
382// UI used only by UI test automation.
383class BrowserWindowTesting {
384 public:
385#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
386 // Returns the BookmarkBarView.
387 virtual BookmarkBarView* GetBookmarkBarView() const = 0;
388
389 // Returns the LocationBarView.
390 virtual LocationBarView* GetLocationBarView() const = 0;
391
392 // Returns the TabContentsContainer.
393 virtual views::View* GetTabContentsContainerView() const = 0;
394
[email protected]69b04b92010-11-08 22:12:18395 // Returns the ToolbarView.
396 virtual ToolbarView* GetToolbarView() const = 0;
397#endif
398
399 protected:
400 virtual ~BrowserWindowTesting() {}
401};
402
403#endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_