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/chrome_signin_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/exclusive_access/exclusive_access_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/signin/core/browser/signin_header_helper.h"
19 #include "components/translate/core/common/translate_errors.h"
20 #include "ui/base/base_window.h"
21 #include "ui/base/window_open_disposition.h"
22 #include "ui/gfx/native_widget_types.h"
26 class ExclusiveAccessContext
;
28 class GlobalErrorBubbleViewBase
;
32 class ProfileResetGlobalError
;
36 struct WebApplicationInfo
;
40 struct NativeWebKeyboardEvent
;
44 namespace extensions
{
55 class WebContentsModalDialogHost
;
58 ////////////////////////////////////////////////////////////////////////////////
59 // BrowserWindow interface
60 // An interface implemented by the "view" of the Browser window.
61 // This interface includes ui::BaseWindow methods as well as Browser window
64 // NOTE: All getters may return NULL.
66 class BrowserWindow
: public ui::BaseWindow
{
68 virtual ~BrowserWindow() {}
70 //////////////////////////////////////////////////////////////////////////////
71 // ui::BaseWindow interface notes:
73 // Closes the window as soon as possible. If the window is not in a drag
74 // session, it will close immediately; otherwise, it will move offscreen (so
75 // events are still fired) until the drag ends, then close. This assumes
76 // that the Browser is not immediately destroyed, but will be eventually
77 // destroyed by other means (eg, the tab strip going to zero elements).
78 // Bad things happen if the Browser dtor is called directly as a result of
79 // invoking this method.
80 // virtual void Close() = 0;
82 // Browser::OnWindowDidShow should be called after showing the window.
83 // virtual void Show() = 0;
85 //////////////////////////////////////////////////////////////////////////////
86 // Browser specific methods:
88 // Return the status bubble associated with the frame
89 virtual StatusBubble
* GetStatusBubble() = 0;
91 // Inform the frame that the selected tab favicon or title has changed. Some
92 // frames may need to refresh their title bar.
93 virtual void UpdateTitleBar() = 0;
95 // Invoked when the state of the bookmark bar changes. This is only invoked if
96 // the state changes for the current tab, it is not sent when switching tabs.
97 virtual void BookmarkBarStateChanged(
98 BookmarkBar::AnimateChangeType change_type
) = 0;
100 // Inform the frame that the dev tools window for the selected tab has
102 virtual void UpdateDevTools() = 0;
104 // Update any loading animations running in the window. |should_animate| is
105 // true if there are tabs loading and the animations should continue, false
106 // if there are no active loads and the animations should end.
107 virtual void UpdateLoadingAnimations(bool should_animate
) = 0;
109 // Sets the starred state for the current tab.
110 virtual void SetStarredState(bool is_starred
) = 0;
112 // Sets whether the translate icon is lit for the current tab.
113 virtual void SetTranslateIconToggled(bool is_lit
) = 0;
115 // Called when the active tab changes. Subclasses which implement
116 // TabStripModelObserver should implement this instead of ActiveTabChanged();
117 // the Browser will call this method while processing that one.
118 virtual void OnActiveTabChanged(content::WebContents
* old_contents
,
119 content::WebContents
* new_contents
,
123 // Called to force the zoom state to for the active tab to be recalculated.
124 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
125 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
126 // + or - in the wrench menu to change zoom).
127 virtual void ZoomChangedForActiveTab(bool can_show_bubble
) = 0;
129 // Methods that change fullscreen state.
130 // On Mac, the tab strip and toolbar will be shown if |with_toolbar| is true,
131 // |with_toolbar| is ignored on other platforms.
132 virtual void EnterFullscreen(const GURL
& url
,
133 ExclusiveAccessBubbleType bubble_type
,
134 bool with_toolbar
) = 0;
135 virtual void ExitFullscreen() = 0;
136 virtual void UpdateExclusiveAccessExitBubbleContent(
138 ExclusiveAccessBubbleType bubble_type
) = 0;
140 // Windows and GTK remove the top controls in fullscreen, but Mac and Ash
141 // keep the controls in a slide-down panel.
142 virtual bool ShouldHideUIForFullscreen() const = 0;
144 // Returns true if the fullscreen bubble is visible.
145 virtual bool IsFullscreenBubbleVisible() const = 0;
147 // Show or hide the tab strip, toolbar and bookmark bar when in browser
149 // Currently only supported on Mac.
150 virtual bool SupportsFullscreenWithToolbar() const = 0;
151 virtual void UpdateFullscreenWithToolbar(bool with_toolbar
) = 0;
152 virtual bool IsFullscreenWithToolbar() const = 0;
155 // Sets state for entering or exiting Win8 Metro snap mode.
156 virtual void SetMetroSnapMode(bool enable
) = 0;
158 // Returns whether the window is currently in Win8 Metro snap mode.
159 virtual bool IsInMetroSnapMode() const = 0;
162 // Returns the location bar.
163 virtual LocationBar
* GetLocationBar() const = 0;
165 // Tries to focus the location bar. Clears the window focus (to avoid
166 // inconsistent state) if this fails.
167 virtual void SetFocusToLocationBar(bool select_all
) = 0;
169 // Informs the view whether or not a load is in progress for the current tab.
170 // The view can use this notification to update the reload/stop button.
171 virtual void UpdateReloadStopState(bool is_loading
, bool force
) = 0;
173 // Updates the toolbar with the state for the specified |contents|.
174 virtual void UpdateToolbar(content::WebContents
* contents
) = 0;
176 // Resets the toolbar's tab state for |contents|.
177 virtual void ResetToolbarTabState(content::WebContents
* contents
) = 0;
179 // Focuses the toolbar (for accessibility).
180 virtual void FocusToolbar() = 0;
182 // Called from toolbar subviews during their show/hide animations.
183 virtual void ToolbarSizeChanged(bool is_animating
) = 0;
185 // Focuses the app menu like it was a menu bar.
187 // Not used on the Mac, which has a "normal" menu bar.
188 virtual void FocusAppMenu() = 0;
190 // Focuses the bookmarks toolbar (for accessibility).
191 virtual void FocusBookmarksToolbar() = 0;
193 // Focuses an infobar, if shown (for accessibility).
194 virtual void FocusInfobars() = 0;
196 // Moves keyboard focus to the next pane.
197 virtual void RotatePaneFocus(bool forwards
) = 0;
199 // Returns whether the bookmark bar is visible or not.
200 virtual bool IsBookmarkBarVisible() const = 0;
202 // Returns whether the bookmark bar is animating or not.
203 virtual bool IsBookmarkBarAnimating() const = 0;
205 // Returns whether the tab strip is editable (for extensions).
206 virtual bool IsTabStripEditable() const = 0;
208 // Returns whether the tool bar is visible or not.
209 virtual bool IsToolbarVisible() const = 0;
211 // Returns the rect where the resize corner should be drawn by the render
212 // widget host view (on top of what the renderer returns). We return an empty
213 // rect to identify that there shouldn't be a resize corner (in the cases
214 // where we take care of it ourselves at the browser level).
215 virtual gfx::Rect
GetRootWindowResizerRect() const = 0;
217 // Shows a confirmation dialog box for adding a search engine described by
218 // |template_url|. Takes ownership of |template_url|.
219 virtual void ConfirmAddSearchProvider(TemplateURL
* template_url
,
220 Profile
* profile
) = 0;
222 // Shows the Update Recommended dialog box.
223 virtual void ShowUpdateChromeDialog() = 0;
225 // Shows the Bookmark bubble. |url| is the URL being bookmarked,
226 // |already_bookmarked| is true if the url is already bookmarked.
227 virtual void ShowBookmarkBubble(const GURL
& url
, bool already_bookmarked
) = 0;
229 // Callback type used with the ShowBookmarkAppBubble() method. The boolean
230 // parameter is true when the user accepts the dialog. The WebApplicationInfo
231 // parameter contains the WebApplicationInfo as edited by the user.
232 typedef base::Callback
<void(bool, const WebApplicationInfo
&)>
233 ShowBookmarkAppBubbleCallback
;
235 // Shows the Bookmark App bubble.
236 // See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of
239 // |web_app_info| is the WebApplicationInfo being converted into an app.
240 virtual void ShowBookmarkAppBubble(
241 const WebApplicationInfo
& web_app_info
,
242 const ShowBookmarkAppBubbleCallback
& callback
) = 0;
244 // Shows the translate bubble.
246 // |is_user_gesture| is true when the bubble is shown on the user's deliberate
248 virtual void ShowTranslateBubble(
249 content::WebContents
* contents
,
250 translate::TranslateStep step
,
251 translate::TranslateErrors::Type error_type
,
252 bool is_user_gesture
) = 0;
254 // Create a session recovery bubble if the last session crashed. It also
255 // offers the option to enable metrics reporting if it's not already enabled.
256 // Returns true if a bubble is created, returns false if nothing is created.
257 virtual bool ShowSessionCrashedBubble() = 0;
259 // Shows the profile reset bubble on the platforms that support it.
260 virtual bool IsProfileResetBubbleSupported() const = 0;
261 virtual GlobalErrorBubbleViewBase
* ShowProfileResetBubble(
262 const base::WeakPtr
<ProfileResetGlobalError
>& global_error
) = 0;
264 #if defined(ENABLE_ONE_CLICK_SIGNIN)
265 enum OneClickSigninBubbleType
{
266 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE
,
267 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG
,
268 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
271 // Callback type used with the ShowOneClickSigninBubble() method. If the
272 // user chooses to accept the sign in, the callback is called to start the
274 typedef base::Callback
<void(OneClickSigninSyncStarter::StartSyncMode
)>
277 // Shows the one-click sign in bubble. |email| holds the full email address
278 // of the account that has signed in.
279 virtual void ShowOneClickSigninBubble(
280 OneClickSigninBubbleType type
,
281 const base::string16
& email
,
282 const base::string16
& error_message
,
283 const StartSyncCallback
& start_sync_callback
) = 0;
286 // Whether or not the shelf view is visible.
287 virtual bool IsDownloadShelfVisible() const = 0;
289 // Returns the DownloadShelf.
290 virtual DownloadShelf
* GetDownloadShelf() = 0;
292 // Shows the confirmation dialog box warning that the browser is closing with
293 // in-progress downloads.
294 // This method should call |callback| with the user's response.
295 virtual void ConfirmBrowserCloseWithPendingDownloads(
297 Browser::DownloadClosePreventionType dialog_type
,
299 const base::Callback
<void(bool)>& callback
) = 0;
301 // ThemeService calls this when a user has changed his or her theme,
302 // indicating that it's time to redraw everything.
303 virtual void UserChangedTheme() = 0;
305 // Shows the website settings using the specified information. |url| is the
306 // url of the page/frame the info applies to, |ssl| is the SSL information for
307 // that page/frame. If |show_history| is true, a section showing how many
308 // times that URL has been visited is added to the page info.
309 virtual void ShowWebsiteSettings(Profile
* profile
,
310 content::WebContents
* web_contents
,
312 const content::SSLStatus
& ssl
) = 0;
314 // Shows the app menu (for accessibility).
315 virtual void ShowAppMenu() = 0;
317 // Allows the BrowserWindow object to handle the specified keyboard event
318 // before sending it to the renderer.
319 // Returns true if the |event| was handled. Otherwise, if the |event| would
320 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
321 // |*is_keyboard_shortcut| should be set to true.
322 virtual bool PreHandleKeyboardEvent(
323 const content::NativeWebKeyboardEvent
& event
,
324 bool* is_keyboard_shortcut
) = 0;
326 // Allows the BrowserWindow object to handle the specified keyboard event,
327 // if the renderer did not process it.
328 virtual void HandleKeyboardEvent(
329 const content::NativeWebKeyboardEvent
& event
) = 0;
331 // Clipboard commands applied to the whole browser window.
332 virtual void CutCopyPaste(int command_id
) = 0;
334 // Return the correct disposition for a popup window based on |bounds|.
335 virtual WindowOpenDisposition
GetDispositionForPopupBounds(
336 const gfx::Rect
& bounds
) = 0;
338 // Construct a FindBar implementation for the |browser|.
339 virtual FindBar
* CreateFindBar() = 0;
341 // Return the WebContentsModalDialogHost for use in positioning web contents
342 // modal dialogs within the browser window. This can sometimes be NULL (for
343 // instance during tab drag on Views/Win32).
344 virtual web_modal::WebContentsModalDialogHost
*
345 GetWebContentsModalDialogHost() = 0;
347 // Invoked when the preferred size of the contents in current tab has been
348 // changed. We might choose to update the window size to accomodate this
350 // Note that this won't be fired if we change tabs.
351 virtual void UpdatePreferredSize(content::WebContents
* web_contents
,
352 const gfx::Size
& pref_size
) {}
354 // Invoked when the contents auto-resized and the container should match it.
355 virtual void ResizeDueToAutoResize(content::WebContents
* web_contents
,
356 const gfx::Size
& new_size
) {}
358 // Construct a BrowserWindow implementation for the specified |browser|.
359 static BrowserWindow
* CreateBrowserWindow(Browser
* browser
);
361 // Returns a HostDesktopType that is compatible with the current Chrome window
362 // configuration. On Windows with Ash, this is always HOST_DESKTOP_TYPE_ASH
363 // while Chrome is running in Metro mode. Otherwise returns |desktop_type|.
364 static chrome::HostDesktopType
AdjustHostDesktopType(
365 chrome::HostDesktopType desktop_type
);
367 // Shows the avatar bubble on the window frame off of the avatar button with
368 // the given mode. The Service Type specified by GAIA is provided as well.
369 enum AvatarBubbleMode
{
370 AVATAR_BUBBLE_MODE_DEFAULT
,
371 AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT
,
372 AVATAR_BUBBLE_MODE_SIGNIN
,
373 AVATAR_BUBBLE_MODE_ADD_ACCOUNT
,
374 AVATAR_BUBBLE_MODE_REAUTH
,
375 AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN
,
376 AVATAR_BUBBLE_MODE_SHOW_ERROR
,
377 AVATAR_BUBBLE_MODE_FAST_USER_SWITCH
,
379 virtual void ShowAvatarBubbleFromAvatarButton(AvatarBubbleMode mode
,
380 const signin::ManageAccountsParams
& manage_accounts_params
) = 0;
382 // Returns the height inset for RenderView when detached bookmark bar is
383 // shown. Invoked when a new RenderHostView is created for a non-NTP
384 // navigation entry and the bookmark bar is detached.
385 virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
387 // Executes |command| registered by |extension|.
388 virtual void ExecuteExtensionCommand(const extensions::Extension
* extension
,
389 const extensions::Command
& command
) = 0;
391 // Returns object implementing ExclusiveAccessContext interface.
392 virtual ExclusiveAccessContext
* GetExclusiveAccessContext() = 0;
395 friend class BrowserCloseManager
;
396 friend class BrowserView
;
397 virtual void DestroyBrowser() = 0;
400 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_