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/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/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"
26 class GlobalErrorBubbleViewBase
;
30 class ProfileResetGlobalError
;
34 struct WebApplicationInfo
;
38 struct NativeWebKeyboardEvent
;
42 namespace extensions
{
53 class WebContentsModalDialogHost
;
56 ////////////////////////////////////////////////////////////////////////////////
57 // BrowserWindow interface
58 // An interface implemented by the "view" of the Browser window.
59 // This interface includes ui::BaseWindow methods as well as Browser window
62 // NOTE: All getters may return NULL.
64 class BrowserWindow
: public ui::BaseWindow
{
66 virtual ~BrowserWindow() {}
68 //////////////////////////////////////////////////////////////////////////////
69 // ui::BaseWindow interface notes:
71 // Closes the window as soon as possible. If the window is not in a drag
72 // 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.
78 // virtual void Close() = 0;
80 // Browser::OnWindowDidShow should be called after showing the window.
81 // virtual void Show() = 0;
83 //////////////////////////////////////////////////////////////////////////////
84 // Browser specific methods:
86 // Return the status bubble associated with the frame
87 virtual StatusBubble
* GetStatusBubble() = 0;
89 // Inform the frame that the selected tab favicon or title has changed. Some
90 // frames may need to refresh their title bar.
91 virtual void UpdateTitleBar() = 0;
93 // Invoked when the state of the bookmark bar changes. This is only invoked if
94 // the state changes for the current tab, it is not sent when switching tabs.
95 virtual void BookmarkBarStateChanged(
96 BookmarkBar::AnimateChangeType change_type
) = 0;
98 // Inform the frame that the dev tools window for the selected tab has
100 virtual void UpdateDevTools() = 0;
102 // Update any loading animations running in the window. |should_animate| is
103 // true if there are tabs loading and the animations should continue, false
104 // if there are no active loads and the animations should end.
105 virtual void UpdateLoadingAnimations(bool should_animate
) = 0;
107 // Sets the starred state for the current tab.
108 virtual void SetStarredState(bool is_starred
) = 0;
110 // Sets whether the translate icon is lit for the current tab.
111 virtual void SetTranslateIconToggled(bool is_lit
) = 0;
113 // Called when the active tab changes. Subclasses which implement
114 // TabStripModelObserver should implement this instead of ActiveTabChanged();
115 // the Browser will call this method while processing that one.
116 virtual void OnActiveTabChanged(content::WebContents
* old_contents
,
117 content::WebContents
* new_contents
,
121 // Called to force the zoom state to for the active tab to be recalculated.
122 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
123 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
124 // + or - in the wrench menu to change zoom).
125 virtual void ZoomChangedForActiveTab(bool can_show_bubble
) = 0;
127 // Methods that change fullscreen state.
128 // On Mac, the tab strip and toolbar will be shown if |with_toolbar| is true,
129 // |with_toolbar| is ignored on other platforms.
130 virtual void EnterFullscreen(const GURL
& url
,
131 ExclusiveAccessBubbleType bubble_type
,
132 bool with_toolbar
) = 0;
133 virtual void ExitFullscreen() = 0;
134 virtual void UpdateFullscreenExitBubbleContent(
136 ExclusiveAccessBubbleType 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;
145 // Show or hide the tab strip, toolbar and bookmark bar when in browser
147 // Currently only supported on Mac.
148 virtual bool SupportsFullscreenWithToolbar() const = 0;
149 virtual void UpdateFullscreenWithToolbar(bool with_toolbar
) = 0;
150 virtual bool IsFullscreenWithToolbar() const = 0;
153 // Sets state for entering or exiting Win8 Metro snap mode.
154 virtual void SetMetroSnapMode(bool enable
) = 0;
156 // Returns whether the window is currently in Win8 Metro snap mode.
157 virtual bool IsInMetroSnapMode() const = 0;
160 // Returns the location bar.
161 virtual LocationBar
* GetLocationBar() const = 0;
163 // Tries to focus the location bar. Clears the window focus (to avoid
164 // inconsistent state) if this fails.
165 virtual void SetFocusToLocationBar(bool select_all
) = 0;
167 // Informs the view whether or not a load is in progress for the current tab.
168 // The view can use this notification to update the reload/stop button.
169 virtual void UpdateReloadStopState(bool is_loading
, bool force
) = 0;
171 // Updates the toolbar with the state for the specified |contents|.
172 virtual void UpdateToolbar(content::WebContents
* contents
) = 0;
174 // Resets the toolbar's tab state for |contents|.
175 virtual void ResetToolbarTabState(content::WebContents
* contents
) = 0;
177 // Focuses the toolbar (for accessibility).
178 virtual void FocusToolbar() = 0;
180 // Focuses the app menu like it was a menu bar.
182 // Not used on the Mac, which has a "normal" menu bar.
183 virtual void FocusAppMenu() = 0;
185 // Focuses the bookmarks toolbar (for accessibility).
186 virtual void FocusBookmarksToolbar() = 0;
188 // Focuses an infobar, if shown (for accessibility).
189 virtual void FocusInfobars() = 0;
191 // Moves keyboard focus to the next pane.
192 virtual void RotatePaneFocus(bool forwards
) = 0;
194 // Returns whether the bookmark bar is visible or not.
195 virtual bool IsBookmarkBarVisible() const = 0;
197 // Returns whether the bookmark bar is animating or not.
198 virtual bool IsBookmarkBarAnimating() const = 0;
200 // Returns whether the tab strip is editable (for extensions).
201 virtual bool IsTabStripEditable() const = 0;
203 // Returns whether the tool bar is visible or not.
204 virtual bool IsToolbarVisible() const = 0;
206 // Returns the rect where the resize corner should be drawn by the render
207 // widget host view (on top of what the renderer returns). We return an empty
208 // rect to identify that there shouldn't be a resize corner (in the cases
209 // where we take care of it ourselves at the browser level).
210 virtual gfx::Rect
GetRootWindowResizerRect() const = 0;
212 // Shows a confirmation dialog box for adding a search engine described by
213 // |template_url|. Takes ownership of |template_url|.
214 virtual void ConfirmAddSearchProvider(TemplateURL
* template_url
,
215 Profile
* profile
) = 0;
217 // Shows the Update Recommended dialog box.
218 virtual void ShowUpdateChromeDialog() = 0;
220 // Shows the Bookmark bubble. |url| is the URL being bookmarked,
221 // |already_bookmarked| is true if the url is already bookmarked.
222 virtual void ShowBookmarkBubble(const GURL
& url
, bool already_bookmarked
) = 0;
224 // Callback type used with the ShowBookmarkAppBubble() method. The boolean
225 // parameter is true when the user accepts the dialog. The WebApplicationInfo
226 // parameter contains the WebApplicationInfo as edited by the user.
227 typedef base::Callback
<void(bool, const WebApplicationInfo
&)>
228 ShowBookmarkAppBubbleCallback
;
230 // Shows the Bookmark App bubble.
231 // See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of
234 // |web_app_info| is the WebApplicationInfo being converted into an app.
235 virtual void ShowBookmarkAppBubble(
236 const WebApplicationInfo
& web_app_info
,
237 const ShowBookmarkAppBubbleCallback
& callback
) = 0;
239 // Shows the translate bubble.
241 // |is_user_gesture| is true when the bubble is shown on the user's deliberate
243 virtual void ShowTranslateBubble(
244 content::WebContents
* contents
,
245 translate::TranslateStep step
,
246 translate::TranslateErrors::Type error_type
,
247 bool is_user_gesture
) = 0;
249 // Create a session recovery bubble if the last session crashed. It also
250 // offers the option to enable metrics reporting if it's not already enabled.
251 // Returns true if a bubble is created, returns false if nothing is created.
252 virtual bool ShowSessionCrashedBubble() = 0;
254 // Shows the profile reset bubble on the platforms that support it.
255 virtual bool IsProfileResetBubbleSupported() const = 0;
256 virtual GlobalErrorBubbleViewBase
* ShowProfileResetBubble(
257 const base::WeakPtr
<ProfileResetGlobalError
>& global_error
) = 0;
259 #if defined(ENABLE_ONE_CLICK_SIGNIN)
260 enum OneClickSigninBubbleType
{
261 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE
,
262 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG
,
263 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
266 // Callback type used with the ShowOneClickSigninBubble() method. If the
267 // user chooses to accept the sign in, the callback is called to start the
269 typedef base::Callback
<void(OneClickSigninSyncStarter::StartSyncMode
)>
272 // Shows the one-click sign in bubble. |email| holds the full email address
273 // of the account that has signed in.
274 virtual void ShowOneClickSigninBubble(
275 OneClickSigninBubbleType type
,
276 const base::string16
& email
,
277 const base::string16
& error_message
,
278 const StartSyncCallback
& start_sync_callback
) = 0;
281 // Whether or not the shelf view is visible.
282 virtual bool IsDownloadShelfVisible() const = 0;
284 // Returns the DownloadShelf.
285 virtual DownloadShelf
* GetDownloadShelf() = 0;
287 // Shows the confirmation dialog box warning that the browser is closing with
288 // in-progress downloads.
289 // This method should call |callback| with the user's response.
290 virtual void ConfirmBrowserCloseWithPendingDownloads(
292 Browser::DownloadClosePreventionType dialog_type
,
294 const base::Callback
<void(bool)>& callback
) = 0;
296 // ThemeService calls this when a user has changed his or her theme,
297 // indicating that it's time to redraw everything.
298 virtual void UserChangedTheme() = 0;
300 // Get extra vertical height that the render view should add to its requests
301 // to webkit. This can help prevent sending extraneous layout/repaint requests
302 // when the delegate is in the process of resizing the tab contents view (e.g.
303 // during infobar animations).
304 virtual int GetExtraRenderViewHeight() const = 0;
306 // Notification that |contents| got the focus through user action (click
308 virtual void WebContentsFocused(content::WebContents
* contents
) = 0;
310 // Shows the website settings using the specified information. |url| is the
311 // url of the page/frame the info applies to, |ssl| is the SSL information for
312 // that page/frame. If |show_history| is true, a section showing how many
313 // times that URL has been visited is added to the page info.
314 virtual void ShowWebsiteSettings(Profile
* profile
,
315 content::WebContents
* web_contents
,
317 const content::SSLStatus
& ssl
) = 0;
319 // Shows the app menu (for accessibility).
320 virtual void ShowAppMenu() = 0;
322 // Allows the BrowserWindow object to handle the specified keyboard event
323 // before sending it to the renderer.
324 // Returns true if the |event| was handled. Otherwise, if the |event| would
325 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
326 // |*is_keyboard_shortcut| should be set to true.
327 virtual bool PreHandleKeyboardEvent(
328 const content::NativeWebKeyboardEvent
& event
,
329 bool* is_keyboard_shortcut
) = 0;
331 // Allows the BrowserWindow object to handle the specified keyboard event,
332 // if the renderer did not process it.
333 virtual void HandleKeyboardEvent(
334 const content::NativeWebKeyboardEvent
& event
) = 0;
336 // Clipboard commands applied to the whole browser window.
337 virtual void Cut() = 0;
338 virtual void Copy() = 0;
339 virtual void Paste() = 0;
341 // Return the correct disposition for a popup window based on |bounds|.
342 virtual WindowOpenDisposition
GetDispositionForPopupBounds(
343 const gfx::Rect
& bounds
) = 0;
345 // Construct a FindBar implementation for the |browser|.
346 virtual FindBar
* CreateFindBar() = 0;
348 // Return the WebContentsModalDialogHost for use in positioning web contents
349 // modal dialogs within the browser window. This can sometimes be NULL (for
350 // instance during tab drag on Views/Win32).
351 virtual web_modal::WebContentsModalDialogHost
*
352 GetWebContentsModalDialogHost() = 0;
354 // Invoked when the preferred size of the contents in current tab has been
355 // changed. We might choose to update the window size to accomodate this
357 // Note that this won't be fired if we change tabs.
358 virtual void UpdatePreferredSize(content::WebContents
* web_contents
,
359 const gfx::Size
& pref_size
) {}
361 // Invoked when the contents auto-resized and the container should match it.
362 virtual void ResizeDueToAutoResize(content::WebContents
* web_contents
,
363 const gfx::Size
& new_size
) {}
365 // Construct a BrowserWindow implementation for the specified |browser|.
366 static BrowserWindow
* CreateBrowserWindow(Browser
* browser
);
368 // Returns a HostDesktopType that is compatible with the current Chrome window
369 // configuration. On Windows with Ash, this is always HOST_DESKTOP_TYPE_ASH
370 // while Chrome is running in Metro mode. Otherwise returns |desktop_type|.
371 static chrome::HostDesktopType
AdjustHostDesktopType(
372 chrome::HostDesktopType desktop_type
);
374 // Shows the avatar bubble on the window frame off of the avatar button with
375 // the given mode. The Service Type specified by GAIA is provided as well.
376 enum AvatarBubbleMode
{
377 AVATAR_BUBBLE_MODE_DEFAULT
,
378 AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT
,
379 AVATAR_BUBBLE_MODE_SIGNIN
,
380 AVATAR_BUBBLE_MODE_ADD_ACCOUNT
,
381 AVATAR_BUBBLE_MODE_REAUTH
,
382 AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN
,
383 AVATAR_BUBBLE_MODE_SHOW_ERROR
,
384 AVATAR_BUBBLE_MODE_FAST_USER_SWITCH
,
386 virtual void ShowAvatarBubbleFromAvatarButton(AvatarBubbleMode mode
,
387 const signin::ManageAccountsParams
& manage_accounts_params
) = 0;
389 // Returns the height inset for RenderView when detached bookmark bar is
390 // shown. Invoked when a new RenderHostView is created for a non-NTP
391 // navigation entry and the bookmark bar is detached.
392 virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
394 // Executes |command| registered by |extension|.
395 virtual void ExecuteExtensionCommand(const extensions::Extension
* extension
,
396 const extensions::Command
& command
) = 0;
399 friend class BrowserCloseManager
;
400 friend class BrowserView
;
401 virtual void DestroyBrowser() = 0;
404 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_