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"
25 class ExclusiveAccessContext
;
27 class GlobalErrorBubbleViewBase
;
31 class ProfileResetGlobalError
;
35 struct WebApplicationInfo
;
39 struct NativeWebKeyboardEvent
;
43 namespace extensions
{
54 class WebContentsModalDialogHost
;
57 ////////////////////////////////////////////////////////////////////////////////
58 // BrowserWindow interface
59 // An interface implemented by the "view" of the Browser window.
60 // This interface includes ui::BaseWindow methods as well as Browser window
63 // NOTE: All getters may return NULL.
65 class BrowserWindow
: public ui::BaseWindow
{
67 virtual ~BrowserWindow() {}
69 //////////////////////////////////////////////////////////////////////////////
70 // ui::BaseWindow interface notes:
72 // Closes the window as soon as possible. If the window is not in a drag
73 // session, it will close immediately; otherwise, it will move offscreen (so
74 // events are still fired) until the drag ends, then close. This assumes
75 // that the Browser is not immediately destroyed, but will be eventually
76 // destroyed by other means (eg, the tab strip going to zero elements).
77 // Bad things happen if the Browser dtor is called directly as a result of
78 // invoking this method.
79 // virtual void Close() = 0;
81 // Browser::OnWindowDidShow should be called after showing the window.
82 // virtual void Show() = 0;
84 //////////////////////////////////////////////////////////////////////////////
85 // Browser specific methods:
87 // Return the status bubble associated with the frame
88 virtual StatusBubble
* GetStatusBubble() = 0;
90 // Inform the frame that the selected tab favicon or title has changed. Some
91 // frames may need to refresh their title bar.
92 virtual void UpdateTitleBar() = 0;
94 // Invoked when the state of the bookmark bar changes. This is only invoked if
95 // the state changes for the current tab, it is not sent when switching tabs.
96 virtual void BookmarkBarStateChanged(
97 BookmarkBar::AnimateChangeType change_type
) = 0;
99 // Inform the frame that the dev tools window for the selected tab has
101 virtual void UpdateDevTools() = 0;
103 // Update any loading animations running in the window. |should_animate| is
104 // true if there are tabs loading and the animations should continue, false
105 // if there are no active loads and the animations should end.
106 virtual void UpdateLoadingAnimations(bool should_animate
) = 0;
108 // Sets the starred state for the current tab.
109 virtual void SetStarredState(bool is_starred
) = 0;
111 // Sets whether the translate icon is lit for the current tab.
112 virtual void SetTranslateIconToggled(bool is_lit
) = 0;
114 // Called when the active tab changes. Subclasses which implement
115 // TabStripModelObserver should implement this instead of ActiveTabChanged();
116 // the Browser will call this method while processing that one.
117 virtual void OnActiveTabChanged(content::WebContents
* old_contents
,
118 content::WebContents
* new_contents
,
122 // Called to force the zoom state to for the active tab to be recalculated.
123 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
124 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
125 // + or - in the wrench menu to change zoom).
126 virtual void ZoomChangedForActiveTab(bool can_show_bubble
) = 0;
128 // Methods that change fullscreen state.
129 // On Mac, the tab strip and toolbar will be shown if |with_toolbar| is true,
130 // |with_toolbar| is ignored on other platforms.
131 virtual void EnterFullscreen(const GURL
& url
,
132 ExclusiveAccessBubbleType bubble_type
,
133 bool with_toolbar
) = 0;
134 virtual void ExitFullscreen() = 0;
135 virtual void UpdateExclusiveAccessExitBubbleContent(
137 ExclusiveAccessBubbleType bubble_type
) = 0;
139 // Windows and GTK remove the top controls in fullscreen, but Mac and Ash
140 // keep the controls in a slide-down panel.
141 virtual bool ShouldHideUIForFullscreen() const = 0;
143 // Returns true if the fullscreen bubble is visible.
144 virtual bool IsFullscreenBubbleVisible() const = 0;
146 // Show or hide the tab strip, toolbar and bookmark bar when in browser
148 // Currently only supported on Mac.
149 virtual bool SupportsFullscreenWithToolbar() const = 0;
150 virtual void UpdateFullscreenWithToolbar(bool with_toolbar
) = 0;
151 virtual bool IsFullscreenWithToolbar() const = 0;
154 // Sets state for entering or exiting Win8 Metro snap mode.
155 virtual void SetMetroSnapMode(bool enable
) = 0;
157 // Returns whether the window is currently in Win8 Metro snap mode.
158 virtual bool IsInMetroSnapMode() const = 0;
161 // Returns the location bar.
162 virtual LocationBar
* GetLocationBar() const = 0;
164 // Tries to focus the location bar. Clears the window focus (to avoid
165 // inconsistent state) if this fails.
166 virtual void SetFocusToLocationBar(bool select_all
) = 0;
168 // Informs the view whether or not a load is in progress for the current tab.
169 // The view can use this notification to update the reload/stop button.
170 virtual void UpdateReloadStopState(bool is_loading
, bool force
) = 0;
172 // Updates the toolbar with the state for the specified |contents|.
173 virtual void UpdateToolbar(content::WebContents
* contents
) = 0;
175 // Resets the toolbar's tab state for |contents|.
176 virtual void ResetToolbarTabState(content::WebContents
* contents
) = 0;
178 // Focuses the toolbar (for accessibility).
179 virtual void FocusToolbar() = 0;
181 // Focuses the app menu like it was a menu bar.
183 // Not used on the Mac, which has a "normal" menu bar.
184 virtual void FocusAppMenu() = 0;
186 // Focuses the bookmarks toolbar (for accessibility).
187 virtual void FocusBookmarksToolbar() = 0;
189 // Focuses an infobar, if shown (for accessibility).
190 virtual void FocusInfobars() = 0;
192 // Moves keyboard focus to the next pane.
193 virtual void RotatePaneFocus(bool forwards
) = 0;
195 // Returns whether the bookmark bar is visible or not.
196 virtual bool IsBookmarkBarVisible() const = 0;
198 // Returns whether the bookmark bar is animating or not.
199 virtual bool IsBookmarkBarAnimating() const = 0;
201 // Returns whether the tab strip is editable (for extensions).
202 virtual bool IsTabStripEditable() const = 0;
204 // Returns whether the tool bar is visible or not.
205 virtual bool IsToolbarVisible() const = 0;
207 // Returns the rect where the resize corner should be drawn by the render
208 // widget host view (on top of what the renderer returns). We return an empty
209 // rect to identify that there shouldn't be a resize corner (in the cases
210 // where we take care of it ourselves at the browser level).
211 virtual gfx::Rect
GetRootWindowResizerRect() const = 0;
213 // Shows a confirmation dialog box for adding a search engine described by
214 // |template_url|. Takes ownership of |template_url|.
215 virtual void ConfirmAddSearchProvider(TemplateURL
* template_url
,
216 Profile
* profile
) = 0;
218 // Shows the Update Recommended dialog box.
219 virtual void ShowUpdateChromeDialog() = 0;
221 // Shows the Bookmark bubble. |url| is the URL being bookmarked,
222 // |already_bookmarked| is true if the url is already bookmarked.
223 virtual void ShowBookmarkBubble(const GURL
& url
, bool already_bookmarked
) = 0;
225 // Callback type used with the ShowBookmarkAppBubble() method. The boolean
226 // parameter is true when the user accepts the dialog. The WebApplicationInfo
227 // parameter contains the WebApplicationInfo as edited by the user.
228 typedef base::Callback
<void(bool, const WebApplicationInfo
&)>
229 ShowBookmarkAppBubbleCallback
;
231 // Shows the Bookmark App bubble.
232 // See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of
235 // |web_app_info| is the WebApplicationInfo being converted into an app.
236 virtual void ShowBookmarkAppBubble(
237 const WebApplicationInfo
& web_app_info
,
238 const ShowBookmarkAppBubbleCallback
& callback
) = 0;
240 // Shows the translate bubble.
242 // |is_user_gesture| is true when the bubble is shown on the user's deliberate
244 virtual void ShowTranslateBubble(
245 content::WebContents
* contents
,
246 translate::TranslateStep step
,
247 translate::TranslateErrors::Type error_type
,
248 bool is_user_gesture
) = 0;
250 // Create a session recovery bubble if the last session crashed. It also
251 // offers the option to enable metrics reporting if it's not already enabled.
252 // Returns true if a bubble is created, returns false if nothing is created.
253 virtual bool ShowSessionCrashedBubble() = 0;
255 // Shows the profile reset bubble on the platforms that support it.
256 virtual bool IsProfileResetBubbleSupported() const = 0;
257 virtual GlobalErrorBubbleViewBase
* ShowProfileResetBubble(
258 const base::WeakPtr
<ProfileResetGlobalError
>& global_error
) = 0;
260 #if defined(ENABLE_ONE_CLICK_SIGNIN)
261 enum OneClickSigninBubbleType
{
262 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE
,
263 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG
,
264 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
267 // Callback type used with the ShowOneClickSigninBubble() method. If the
268 // user chooses to accept the sign in, the callback is called to start the
270 typedef base::Callback
<void(OneClickSigninSyncStarter::StartSyncMode
)>
273 // Shows the one-click sign in bubble. |email| holds the full email address
274 // of the account that has signed in.
275 virtual void ShowOneClickSigninBubble(
276 OneClickSigninBubbleType type
,
277 const base::string16
& email
,
278 const base::string16
& error_message
,
279 const StartSyncCallback
& start_sync_callback
) = 0;
282 // Whether or not the shelf view is visible.
283 virtual bool IsDownloadShelfVisible() const = 0;
285 // Returns the DownloadShelf.
286 virtual DownloadShelf
* GetDownloadShelf() = 0;
288 // Shows the confirmation dialog box warning that the browser is closing with
289 // in-progress downloads.
290 // This method should call |callback| with the user's response.
291 virtual void ConfirmBrowserCloseWithPendingDownloads(
293 Browser::DownloadClosePreventionType dialog_type
,
295 const base::Callback
<void(bool)>& callback
) = 0;
297 // ThemeService calls this when a user has changed his or her theme,
298 // indicating that it's time to redraw everything.
299 virtual void UserChangedTheme() = 0;
301 // Get extra vertical height that the render view should add to its requests
302 // to webkit. This can help prevent sending extraneous layout/repaint requests
303 // when the delegate is in the process of resizing the tab contents view (e.g.
304 // during infobar animations).
305 virtual int GetExtraRenderViewHeight() const = 0;
307 // Notification that |contents| got the focus through user action (click
309 virtual void WebContentsFocused(content::WebContents
* contents
) = 0;
311 // Shows the website settings using the specified information. |url| is the
312 // url of the page/frame the info applies to, |ssl| is the SSL information for
313 // that page/frame. If |show_history| is true, a section showing how many
314 // times that URL has been visited is added to the page info.
315 virtual void ShowWebsiteSettings(Profile
* profile
,
316 content::WebContents
* web_contents
,
318 const content::SSLStatus
& ssl
) = 0;
320 // Shows the app menu (for accessibility).
321 virtual void ShowAppMenu() = 0;
323 // Allows the BrowserWindow object to handle the specified keyboard event
324 // before sending it to the renderer.
325 // Returns true if the |event| was handled. Otherwise, if the |event| would
326 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
327 // |*is_keyboard_shortcut| should be set to true.
328 virtual bool PreHandleKeyboardEvent(
329 const content::NativeWebKeyboardEvent
& event
,
330 bool* is_keyboard_shortcut
) = 0;
332 // Allows the BrowserWindow object to handle the specified keyboard event,
333 // if the renderer did not process it.
334 virtual void HandleKeyboardEvent(
335 const content::NativeWebKeyboardEvent
& event
) = 0;
337 // Clipboard commands applied to the whole browser window.
338 virtual void Cut() = 0;
339 virtual void Copy() = 0;
340 virtual void Paste() = 0;
342 // Return the correct disposition for a popup window based on |bounds|.
343 virtual WindowOpenDisposition
GetDispositionForPopupBounds(
344 const gfx::Rect
& bounds
) = 0;
346 // Construct a FindBar implementation for the |browser|.
347 virtual FindBar
* CreateFindBar() = 0;
349 // Return the WebContentsModalDialogHost for use in positioning web contents
350 // modal dialogs within the browser window. This can sometimes be NULL (for
351 // instance during tab drag on Views/Win32).
352 virtual web_modal::WebContentsModalDialogHost
*
353 GetWebContentsModalDialogHost() = 0;
355 // Invoked when the preferred size of the contents in current tab has been
356 // changed. We might choose to update the window size to accomodate this
358 // Note that this won't be fired if we change tabs.
359 virtual void UpdatePreferredSize(content::WebContents
* web_contents
,
360 const gfx::Size
& pref_size
) {}
362 // Invoked when the contents auto-resized and the container should match it.
363 virtual void ResizeDueToAutoResize(content::WebContents
* web_contents
,
364 const gfx::Size
& new_size
) {}
366 // Construct a BrowserWindow implementation for the specified |browser|.
367 static BrowserWindow
* CreateBrowserWindow(Browser
* browser
);
369 // Returns a HostDesktopType that is compatible with the current Chrome window
370 // configuration. On Windows with Ash, this is always HOST_DESKTOP_TYPE_ASH
371 // while Chrome is running in Metro mode. Otherwise returns |desktop_type|.
372 static chrome::HostDesktopType
AdjustHostDesktopType(
373 chrome::HostDesktopType desktop_type
);
375 // Shows the avatar bubble on the window frame off of the avatar button with
376 // the given mode. The Service Type specified by GAIA is provided as well.
377 enum AvatarBubbleMode
{
378 AVATAR_BUBBLE_MODE_DEFAULT
,
379 AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT
,
380 AVATAR_BUBBLE_MODE_SIGNIN
,
381 AVATAR_BUBBLE_MODE_ADD_ACCOUNT
,
382 AVATAR_BUBBLE_MODE_REAUTH
,
383 AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN
,
384 AVATAR_BUBBLE_MODE_SHOW_ERROR
,
385 AVATAR_BUBBLE_MODE_FAST_USER_SWITCH
,
387 virtual void ShowAvatarBubbleFromAvatarButton(AvatarBubbleMode mode
,
388 const signin::ManageAccountsParams
& manage_accounts_params
) = 0;
390 // Returns the height inset for RenderView when detached bookmark bar is
391 // shown. Invoked when a new RenderHostView is created for a non-NTP
392 // navigation entry and the bookmark bar is detached.
393 virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
395 // Executes |command| registered by |extension|.
396 virtual void ExecuteExtensionCommand(const extensions::Extension
* extension
,
397 const extensions::Command
& command
) = 0;
399 // Returns object implementing ExclusiveAccessContext interface.
400 virtual ExclusiveAccessContext
* GetExclusiveAccessContext() = 0;
403 friend class BrowserCloseManager
;
404 friend class BrowserView
;
405 virtual void DestroyBrowser() = 0;
408 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_