blob: 39c2650cab9d5d961277d50f2e69b59c989a1f0f [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]edfca702013-08-16 08:58:1411#include "chrome/browser/ui/browser.h"
[email protected]9d5c059a82012-06-29 20:13:0712#include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h"
[email protected]ddeb0e8432012-12-21 07:27:5413#include "chrome/browser/ui/host_desktop.h"
[email protected]e4b66bf2012-05-29 20:39:5114#include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
[email protected]69b04b92010-11-08 22:12:1815#include "chrome/common/content_settings_types.h"
[email protected]5f39adc2013-05-23 11:50:4616#include "ui/base/base_window.h"
[email protected]f47621b2013-01-22 20:50:3317#include "ui/base/window_open_disposition.h"
[email protected]08397d52011-02-05 01:53:3818#include "ui/gfx/native_widget_types.h"
[email protected]69b04b92010-11-08 22:12:1819
20class Browser;
21class BrowserWindowTesting;
22class DownloadShelf;
23class FindBar;
24class GURL;
[email protected]69b04b92010-11-08 22:12:1825class LocationBar;
26class Profile;
27class StatusBubble;
[email protected]69b04b92010-11-08 22:12:1828class TemplateURL;
[email protected]69b04b92010-11-08 22:12:1829#if !defined(OS_MACOSX)
30class ToolbarView;
31#endif
[email protected]69b04b92010-11-08 22:12:1832
[email protected]e0f90fc2012-06-06 19:30:1033namespace autofill {
34class PasswordGenerator;
35}
[email protected]ea049a02011-12-25 21:37:0936namespace content {
37class WebContents;
[email protected]b87ee522012-05-18 15:16:5438struct NativeWebKeyboardEvent;
[email protected]1ecbe862012-10-05 01:29:1439struct PasswordForm;
[email protected]d583e3f22011-12-27 21:38:1740struct SSLStatus;
[email protected]ea049a02011-12-25 21:37:0941}
42
[email protected]1c321ee2012-05-21 03:02:3443namespace extensions {
44class Extension;
45}
46
[email protected]69b04b92010-11-08 22:12:1847namespace gfx {
48class Rect;
[email protected]0548c5352011-09-07 00:33:3349class Size;
[email protected]69b04b92010-11-08 22:12:1850}
51
[email protected]e41d0082013-05-16 04:37:5452namespace web_modal {
53class WebContentsModalDialogHost;
54}
55
[email protected]69b04b92010-11-08 22:12:1856////////////////////////////////////////////////////////////////////////////////
57// BrowserWindow interface
58// An interface implemented by the "view" of the Browser window.
[email protected]5f39adc2013-05-23 11:50:4659// This interface includes ui::BaseWindow methods as well as Browser window
[email protected]41d9faf2012-02-28 23:46:0260// specific methods.
[email protected]69b04b92010-11-08 22:12:1861//
62// NOTE: All getters may return NULL.
[email protected]41d9faf2012-02-28 23:46:0263//
[email protected]5f39adc2013-05-23 11:50:4664class BrowserWindow : public ui::BaseWindow {
[email protected]69b04b92010-11-08 22:12:1865 public:
[email protected]ed2f27132011-04-04 17:19:5766 virtual ~BrowserWindow() {}
67
[email protected]41d9faf2012-02-28 23:46:0268 //////////////////////////////////////////////////////////////////////////////
[email protected]5f39adc2013-05-23 11:50:4669 // ui::BaseWindow interface notes:
[email protected]69b04b92010-11-08 22:12:1870
[email protected]41d9faf2012-02-28 23:46:0271 // Closes the window as soon as possible. If the window is not in a drag
[email protected]69b04b92010-11-08 22:12:1872 // session, it will close immediately; otherwise, it will move offscreen (so
73 // events are still fired) until the drag ends, then close. This assumes
74 // that the Browser is not immediately destroyed, but will be eventually
75 // destroyed by other means (eg, the tab strip going to zero elements).
76 // Bad things happen if the Browser dtor is called directly as a result of
77 // invoking this method.
[email protected]41d9faf2012-02-28 23:46:0278 // virtual void Close() = 0;
[email protected]69b04b92010-11-08 22:12:1879
[email protected]41d9faf2012-02-28 23:46:0280 // Browser::OnWindowDidShow should be called after showing the window.
81 // virtual void Show() = 0;
[email protected]69b04b92010-11-08 22:12:1882
[email protected]41d9faf2012-02-28 23:46:0283 //////////////////////////////////////////////////////////////////////////////
84 // Browser specific methods:
[email protected]69b04b92010-11-08 22:12:1885
[email protected]69b04b92010-11-08 22:12:1886 // Returns a pointer to the testing interface to the Browser window, or NULL
87 // if there is none.
88 virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0;
89
90 // Return the status bubble associated with the frame
91 virtual StatusBubble* GetStatusBubble() = 0;
92
[email protected]69b04b92010-11-08 22:12:1893 // Inform the frame that the selected tab favicon or title has changed. Some
94 // frames may need to refresh their title bar.
95 virtual void UpdateTitleBar() = 0;
96
[email protected]09b29342011-06-24 19:18:4897 // Invoked when the state of the bookmark bar changes. This is only invoked if
98 // the state changes for the current tab, it is not sent when switching tabs.
99 virtual void BookmarkBarStateChanged(
100 BookmarkBar::AnimateChangeType change_type) = 0;
[email protected]69b04b92010-11-08 22:12:18101
102 // Inform the frame that the dev tools window for the selected tab has
103 // changed.
104 virtual void UpdateDevTools() = 0;
105
106 // Update any loading animations running in the window. |should_animate| is
107 // true if there are tabs loading and the animations should continue, false
108 // if there are no active loads and the animations should end.
109 virtual void UpdateLoadingAnimations(bool should_animate) = 0;
110
111 // Sets the starred state for the current tab.
112 virtual void SetStarredState(bool is_starred) = 0;
113
[email protected]5423c372012-08-22 05:50:16114 // Called to force the zoom state to for the active tab to be recalculated.
115 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
116 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
117 // + or - in the wrench menu to change zoom).
118 virtual void ZoomChangedForActiveTab(bool can_show_bubble) = 0;
[email protected]6f80e932012-06-04 19:00:07119
[email protected]69b04b92010-11-08 22:12:18120 // Accessors for fullscreen mode state.
[email protected]8d944b32011-10-17 06:11:53121 virtual void EnterFullscreen(const GURL& url,
122 FullscreenExitBubbleType bubble_type) = 0;
[email protected]55c87fa2011-10-15 07:28:28123 virtual void ExitFullscreen() = 0;
[email protected]8d944b32011-10-17 06:11:53124 virtual void UpdateFullscreenExitBubbleContent(
125 const GURL& url,
126 FullscreenExitBubbleType bubble_type) = 0;
[email protected]69b04b92010-11-08 22:12:18127
[email protected]6a414ff2013-02-27 08:22:54128 // Windows and GTK remove the top controls in fullscreen, but Mac and Ash
129 // keep the controls in a slide-down panel.
130 virtual bool ShouldHideUIForFullscreen() const = 0;
131
[email protected]69b04b92010-11-08 22:12:18132 // Returns true if the fullscreen bubble is visible.
133 virtual bool IsFullscreenBubbleVisible() const = 0;
134
[email protected]77cbe50e2012-06-14 02:44:38135#if defined(OS_WIN)
136 // Sets state for entering or exiting Win8 Metro snap mode.
137 virtual void SetMetroSnapMode(bool enable) = 0;
138
139 // Returns whether the window is currently in Win8 Metro snap mode.
140 virtual bool IsInMetroSnapMode() const = 0;
141#endif
142
[email protected]69b04b92010-11-08 22:12:18143 // Returns the location bar.
144 virtual LocationBar* GetLocationBar() const = 0;
145
146 // Tries to focus the location bar. Clears the window focus (to avoid
147 // inconsistent state) if this fails.
148 virtual void SetFocusToLocationBar(bool select_all) = 0;
149
150 // Informs the view whether or not a load is in progress for the current tab.
151 // The view can use this notification to update the reload/stop button.
152 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
153
154 // Updates the toolbar with the state for the specified |contents|.
[email protected]2e7fe4312013-08-21 17:19:48155 virtual void UpdateToolbar(content::WebContents* contents) = 0;
[email protected]69b04b92010-11-08 22:12:18156
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.
[email protected]edfca702013-08-16 08:58:14247 // This method should call |callback| with the user's response.
248 virtual void ConfirmBrowserCloseWithPendingDownloads(
249 int download_count,
250 Browser::DownloadClosePreventionType dialog_type,
251 bool app_modal,
252 const base::Callback<void(bool)>& callback) = 0;
[email protected]69b04b92010-11-08 22:12:18253
[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]588300d2011-04-28 21:06:35317 // Return the correct disposition for a popup window based on |bounds|.
318 virtual WindowOpenDisposition GetDispositionForPopupBounds(
319 const gfx::Rect& bounds) = 0;
320
[email protected]632983f2011-08-08 22:51:24321 // Construct a FindBar implementation for the |browser|.
322 virtual FindBar* CreateFindBar() = 0;
323
[email protected]7519c522013-04-02 01:07:23324 // Return the WebContentsModalDialogHost for use in positioning web contents
325 // modal dialogs within the browser window.
[email protected]e41d0082013-05-16 04:37:54326 virtual web_modal::WebContentsModalDialogHost*
327 GetWebContentsModalDialogHost() = 0;
[email protected]6a151762012-10-03 22:33:19328
[email protected]0548c5352011-09-07 00:33:33329 // Invoked when the preferred size of the contents in current tab has been
330 // changed. We might choose to update the window size to accomodate this
331 // change.
332 // Note that this won't be fired if we change tabs.
[email protected]2a6bc3e2011-12-28 23:51:33333 virtual void UpdatePreferredSize(content::WebContents* web_contents,
[email protected]0548c5352011-09-07 00:33:33334 const gfx::Size& pref_size) {}
335
[email protected]61e2b3cc2012-03-02 16:13:34336 // Invoked when the contents auto-resized and the container should match it.
337 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
338 const gfx::Size& new_size) {}
339
[email protected]69b04b92010-11-08 22:12:18340 // Construct a BrowserWindow implementation for the specified |browser|.
341 static BrowserWindow* CreateBrowserWindow(Browser* browser);
342
[email protected]0ec4898e2011-12-30 21:09:24343 // Shows the avatar bubble inside |web_contents|. The bubble is positioned
344 // relative to |rect|. |rect| should be in the |web_contents| coordinate
[email protected]2f733a02011-10-06 15:17:34345 // system.
[email protected]0ec4898e2011-12-30 21:09:24346 virtual void ShowAvatarBubble(content::WebContents* web_contents,
[email protected]2f733a02011-10-06 15:17:34347 const gfx::Rect& rect) = 0;
348
[email protected]7d2d08152011-10-25 22:58:47349 // Shows the avatar bubble on the window frame off of the avatar button.
350 virtual void ShowAvatarBubbleFromAvatarButton() = 0;
351
[email protected]e0f90fc2012-06-06 19:30:10352 // Show bubble for password generation positioned relative to |rect|. The
353 // subclasses implementing this interface do not own the |password_generator|
354 // object which is passed to generate the password. |form| is the form that
[email protected]f5d230b32012-12-11 02:04:11355 // contains the password field that the bubble will be associated with.
[email protected]4d5ef8692012-05-31 02:28:57356 virtual void ShowPasswordGenerationBubble(
357 const gfx::Rect& rect,
[email protected]1ecbe862012-10-05 01:29:14358 const content::PasswordForm& form,
[email protected]f5d230b32012-12-11 02:04:11359 autofill::PasswordGenerator* password_generator) = 0;
[email protected]90ee09232012-03-21 02:01:01360
[email protected]888878e82013-07-24 22:49:40361 // Invoked when the amount of vertical overscroll changes. |delta_y| is the
362 // amount of overscroll that has occured in the y-direction.
363 virtual void OverscrollUpdate(int delta_y) {}
364
[email protected]dc0fd432013-08-27 15:29:21365 // Returns the height inset for RenderView when detached bookmark bar is
366 // shown. Invoked when a new RenderHostView is created for a non-NTP
367 // navigation entry and the bookmark bar is detached.
368 virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
369
[email protected]69b04b92010-11-08 22:12:18370 protected:
[email protected]2e9d79f2013-08-16 05:45:56371 friend class BrowserCloseManager;
[email protected]69b04b92010-11-08 22:12:18372 friend class BrowserView;
373 virtual void DestroyBrowser() = 0;
[email protected]69b04b92010-11-08 22:12:18374};
375
376#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
377class BookmarkBarView;
378class LocationBarView;
379
380namespace views {
381class View;
382}
383#endif // defined(OS_WIN)
384
385// A BrowserWindow utility interface used for accessing elements of the browser
386// UI used only by UI test automation.
387class BrowserWindowTesting {
388 public:
389#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
390 // Returns the BookmarkBarView.
391 virtual BookmarkBarView* GetBookmarkBarView() const = 0;
392
393 // Returns the LocationBarView.
394 virtual LocationBarView* GetLocationBarView() const = 0;
395
396 // Returns the TabContentsContainer.
397 virtual views::View* GetTabContentsContainerView() const = 0;
398
[email protected]69b04b92010-11-08 22:12:18399 // Returns the ToolbarView.
400 virtual ToolbarView* GetToolbarView() const = 0;
401#endif
402
403 protected:
404 virtual ~BrowserWindowTesting() {}
405};
406
407#endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_