1 // Copyright 2012 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.
5 #ifndef CHROME_BROWSER_UI_BROWSER_WINDOW_H_
6 #define CHROME_BROWSER_UI_BROWSER_WINDOW_H_
8 #include "base/callback_forward.h"
9 #include "chrome/browser/lifetime/browser_close_manager.h"
10 #include "chrome/browser/signin/signin_header_helper.h"
11 #include "chrome/browser/translate/chrome_translate_client.h"
12 #include "chrome/browser/ui/bookmarks/bookmark_bar.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h"
15 #include "chrome/browser/ui/host_desktop.h"
16 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
17 #include "components/content_settings/core/common/content_settings_types.h"
18 #include "components/translate/core/common/translate_errors.h"
19 #include "ui/base/base_window.h"
20 #include "ui/base/window_open_disposition.h"
21 #include "ui/gfx/native_widget_types.h"
24 class BrowserWindowTesting;
33 struct WebApplicationInfo;
37 struct NativeWebKeyboardEvent;
41 namespace extensions {
52 class WebContentsModalDialogHost;
55 ////////////////////////////////////////////////////////////////////////////////
56 // BrowserWindow interface
57 // An interface implemented by the "view" of the Browser window.
58 // This interface includes ui::BaseWindow methods as well as Browser window
61 // NOTE: All getters may return NULL.
63 class BrowserWindow : public ui::BaseWindow {
65 virtual ~BrowserWindow() {}
67 //////////////////////////////////////////////////////////////////////////////
68 // ui::BaseWindow interface notes:
70 // Closes the window as soon as possible. If the window is not in a drag
71 // 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.
77 // virtual void Close() = 0;
79 // Browser::OnWindowDidShow should be called after showing the window.
80 // virtual void Show() = 0;
82 //////////////////////////////////////////////////////////////////////////////
83 // Browser specific methods:
85 // Returns a pointer to the testing interface to the Browser window, or NULL
87 virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0;
89 // Return the status bubble associated with the frame
90 virtual StatusBubble* GetStatusBubble() = 0;
92 // 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;
96 // 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;
101 // Inform the frame that the dev tools window for the selected tab has
103 virtual void UpdateDevTools() = 0;
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;
110 // Sets the starred state for the current tab.
111 virtual void SetStarredState(bool is_starred) = 0;
113 // Sets whether the translate icon is lit for the current tab.
114 virtual void SetTranslateIconToggled(bool is_lit) = 0;
116 // Called when the active tab changes. Subclasses which implement
117 // TabStripModelObserver should implement this instead of ActiveTabChanged();
118 // the Browser will call this method while processing that one.
119 virtual void OnActiveTabChanged(content::WebContents* old_contents,
120 content::WebContents* new_contents,
124 // Called to force the zoom state to for the active tab to be recalculated.
125 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
126 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
127 // + or - in the wrench menu to change zoom).
128 virtual void ZoomChangedForActiveTab(bool can_show_bubble) = 0;
130 // Accessors for fullscreen mode state.
131 virtual void EnterFullscreen(const GURL& url,
132 FullscreenExitBubbleType bubble_type) = 0;
133 virtual void ExitFullscreen() = 0;
134 virtual void UpdateFullscreenExitBubbleContent(
136 FullscreenExitBubbleType bubble_type) = 0;
138 // Windows and GTK remove the top controls in fullscreen, but Mac and Ash
139 // keep the controls in a slide-down panel.
140 virtual bool ShouldHideUIForFullscreen() const = 0;
142 // Returns true if the fullscreen bubble is visible.
143 virtual bool IsFullscreenBubbleVisible() const = 0;
146 // Sets state for entering or exiting Win8 Metro snap mode.
147 virtual void SetMetroSnapMode(bool enable) = 0;
149 // Returns whether the window is currently in Win8 Metro snap mode.
150 virtual bool IsInMetroSnapMode() const = 0;
153 // Returns the location bar.
154 virtual LocationBar* GetLocationBar() const = 0;
156 // Tries to focus the location bar. Clears the window focus (to avoid
157 // inconsistent state) if this fails.
158 virtual void SetFocusToLocationBar(bool select_all) = 0;
160 // Informs the view whether or not a load is in progress for the current tab.
161 // The view can use this notification to update the reload/stop button.
162 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
164 // Updates the toolbar with the state for the specified |contents|.
165 virtual void UpdateToolbar(content::WebContents* contents) = 0;
167 // Focuses the toolbar (for accessibility).
168 virtual void FocusToolbar() = 0;
170 // Focuses the app menu like it was a menu bar.
172 // Not used on the Mac, which has a "normal" menu bar.
173 virtual void FocusAppMenu() = 0;
175 // Focuses the bookmarks toolbar (for accessibility).
176 virtual void FocusBookmarksToolbar() = 0;
178 // Focuses an infobar, if shown (for accessibility).
179 virtual void FocusInfobars() = 0;
181 // Moves keyboard focus to the next pane.
182 virtual void RotatePaneFocus(bool forwards) = 0;
184 // Returns whether the bookmark bar is visible or not.
185 virtual bool IsBookmarkBarVisible() const = 0;
187 // Returns whether the bookmark bar is animating or not.
188 virtual bool IsBookmarkBarAnimating() const = 0;
190 // Returns whether the tab strip is editable (for extensions).
191 virtual bool IsTabStripEditable() const = 0;
193 // Returns whether the tool bar is visible or not.
194 virtual bool IsToolbarVisible() const = 0;
196 // Returns the rect where the resize corner should be drawn by the render
197 // widget host view (on top of what the renderer returns). We return an empty
198 // rect to identify that there shouldn't be a resize corner (in the cases
199 // where we take care of it ourselves at the browser level).
200 virtual gfx::Rect GetRootWindowResizerRect() const = 0;
202 // Shows a confirmation dialog box for adding a search engine described by
203 // |template_url|. Takes ownership of |template_url|.
204 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
205 Profile* profile) = 0;
207 // Shows the Update Recommended dialog box.
208 virtual void ShowUpdateChromeDialog() = 0;
210 // Shows the Bookmark bubble. |url| is the URL being bookmarked,
211 // |already_bookmarked| is true if the url is already bookmarked.
212 virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0;
214 // Shows the Bookmark App bubble.
215 // See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of
218 // |web_app_info| is the WebApplicationInfo being converted into an app.
219 // |extension_id| is the id of the bookmark app.
220 virtual void ShowBookmarkAppBubble(const WebApplicationInfo& web_app_info,
221 const std::string& extension_id) = 0;
223 // Shows the translate bubble.
225 // |is_user_gesture| is true when the bubble is shown on the user's deliberate
227 virtual void ShowTranslateBubble(
228 content::WebContents* contents,
229 translate::TranslateStep step,
230 translate::TranslateErrors::Type error_type,
231 bool is_user_gesture) = 0;
233 #if defined(ENABLE_ONE_CLICK_SIGNIN)
234 enum OneClickSigninBubbleType {
235 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
236 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG,
237 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
240 // Callback type used with the ShowOneClickSigninBubble() method. If the
241 // user chooses to accept the sign in, the callback is called to start the
243 typedef base::Callback<void(OneClickSigninSyncStarter::StartSyncMode)>
246 // Shows the one-click sign in bubble. |email| holds the full email address
247 // of the account that has signed in.
248 virtual void ShowOneClickSigninBubble(
249 OneClickSigninBubbleType type,
250 const base::string16& email,
251 const base::string16& error_message,
252 const StartSyncCallback& start_sync_callback) = 0;
255 // Whether or not the shelf view is visible.
256 virtual bool IsDownloadShelfVisible() const = 0;
258 // Returns the DownloadShelf.
259 virtual DownloadShelf* GetDownloadShelf() = 0;
261 // Shows the confirmation dialog box warning that the browser is closing with
262 // in-progress downloads.
263 // This method should call |callback| with the user's response.
264 virtual void ConfirmBrowserCloseWithPendingDownloads(
266 Browser::DownloadClosePreventionType dialog_type,
268 const base::Callback<void(bool)>& callback) = 0;
270 // ThemeService calls this when a user has changed his or her theme,
271 // indicating that it's time to redraw everything.
272 virtual void UserChangedTheme() = 0;
274 // Get extra vertical height that the render view should add to its requests
275 // to webkit. This can help prevent sending extraneous layout/repaint requests
276 // when the delegate is in the process of resizing the tab contents view (e.g.
277 // during infobar animations).
278 virtual int GetExtraRenderViewHeight() const = 0;
280 // Notification that |contents| got the focus through user action (click
282 virtual void WebContentsFocused(content::WebContents* contents) = 0;
284 // Shows the website settings using the specified information. |url| is the
285 // url of the page/frame the info applies to, |ssl| is the SSL information for
286 // that page/frame. If |show_history| is true, a section showing how many
287 // times that URL has been visited is added to the page info.
288 virtual void ShowWebsiteSettings(Profile* profile,
289 content::WebContents* web_contents,
291 const content::SSLStatus& ssl) = 0;
293 // Shows the app menu (for accessibility).
294 virtual void ShowAppMenu() = 0;
296 // Allows the BrowserWindow object to handle the specified keyboard event
297 // before sending it to the renderer.
298 // Returns true if the |event| was handled. Otherwise, if the |event| would
299 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
300 // |*is_keyboard_shortcut| should be set to true.
301 virtual bool PreHandleKeyboardEvent(
302 const content::NativeWebKeyboardEvent& event,
303 bool* is_keyboard_shortcut) = 0;
305 // Allows the BrowserWindow object to handle the specified keyboard event,
306 // if the renderer did not process it.
307 virtual void HandleKeyboardEvent(
308 const content::NativeWebKeyboardEvent& event) = 0;
310 // Clipboard commands applied to the whole browser window.
311 virtual void Cut() = 0;
312 virtual void Copy() = 0;
313 virtual void Paste() = 0;
315 #if defined(OS_MACOSX)
316 // Enters Mac specific fullscreen mode with chrome displayed (e.g. omnibox)
317 // on OSX 10.7+, a.k.a. Lion Fullscreen mode.
318 // Invalid to call on OSX earlier than 10.7.
319 // Enters either from non fullscreen, or from fullscreen without chrome.
320 // Exit to normal fullscreen with EnterFullscreen().
321 virtual void EnterFullscreenWithChrome() = 0;
322 virtual bool IsFullscreenWithChrome() = 0;
323 virtual bool IsFullscreenWithoutChrome() = 0;
326 // Return the correct disposition for a popup window based on |bounds|.
327 virtual WindowOpenDisposition GetDispositionForPopupBounds(
328 const gfx::Rect& bounds) = 0;
330 // Construct a FindBar implementation for the |browser|.
331 virtual FindBar* CreateFindBar() = 0;
333 // Return the WebContentsModalDialogHost for use in positioning web contents
334 // modal dialogs within the browser window. This can sometimes be NULL (for
335 // instance during tab drag on Views/Win32).
336 virtual web_modal::WebContentsModalDialogHost*
337 GetWebContentsModalDialogHost() = 0;
339 // Invoked when the preferred size of the contents in current tab has been
340 // changed. We might choose to update the window size to accomodate this
342 // Note that this won't be fired if we change tabs.
343 virtual void UpdatePreferredSize(content::WebContents* web_contents,
344 const gfx::Size& pref_size) {}
346 // Invoked when the contents auto-resized and the container should match it.
347 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
348 const gfx::Size& new_size) {}
350 // Construct a BrowserWindow implementation for the specified |browser|.
351 static BrowserWindow* CreateBrowserWindow(Browser* browser);
353 // Returns a HostDesktopType that is compatible with the current Chrome window
354 // configuration. On Windows with Ash, this is always HOST_DESKTOP_TYPE_ASH
355 // while Chrome is running in Metro mode. Otherwise returns |desktop_type|.
356 static chrome::HostDesktopType AdjustHostDesktopType(
357 chrome::HostDesktopType desktop_type);
359 // Shows the avatar bubble inside |web_contents|. The bubble is positioned
360 // relative to |rect|. |rect| should be in the |web_contents| coordinate
362 virtual void ShowAvatarBubble(content::WebContents* web_contents,
363 const gfx::Rect& rect) = 0;
365 // Shows the avatar bubble on the window frame off of the avatar button with
366 // the given mode. The Service Type specified by GAIA is provided as well.
367 enum AvatarBubbleMode {
368 AVATAR_BUBBLE_MODE_DEFAULT,
369 AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT,
370 AVATAR_BUBBLE_MODE_SIGNIN,
371 AVATAR_BUBBLE_MODE_ADD_ACCOUNT,
372 AVATAR_BUBBLE_MODE_REAUTH,
373 AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN,
374 AVATAR_BUBBLE_MODE_SHOW_ERROR,
376 virtual void ShowAvatarBubbleFromAvatarButton(AvatarBubbleMode mode,
377 const signin::ManageAccountsParams& manage_accounts_params) = 0;
379 // Invoked when the amount of vertical overscroll changes. |delta_y| is the
380 // amount of overscroll that has occured in the y-direction.
381 virtual void OverscrollUpdate(int delta_y) {}
383 // Returns the height inset for RenderView when detached bookmark bar is
384 // shown. Invoked when a new RenderHostView is created for a non-NTP
385 // navigation entry and the bookmark bar is detached.
386 virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
388 // Executes |command| registered by |extension|.
389 virtual void ExecuteExtensionCommand(const extensions::Extension* extension,
390 const extensions::Command& command) = 0;
393 friend class BrowserCloseManager;
394 friend class BrowserView;
395 virtual void DestroyBrowser() = 0;
398 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_