Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / browser_window.h
blobe5755f4c3bb95449c4695151707d5d552b7f3e49
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/ssl/security_state_model.h"
12 #include "chrome/browser/translate/chrome_translate_client.h"
13 #include "chrome/browser/ui/bookmarks/bookmark_bar.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/exclusive_access/exclusive_access_bubble_type.h"
16 #include "chrome/browser/ui/host_desktop.h"
17 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
18 #include "components/content_settings/core/common/content_settings_types.h"
19 #include "components/signin/core/browser/signin_header_helper.h"
20 #include "components/translate/core/common/translate_errors.h"
21 #include "ui/base/base_window.h"
22 #include "ui/base/window_open_disposition.h"
23 #include "ui/gfx/native_widget_types.h"
25 class Browser;
26 class DownloadShelf;
27 class ExclusiveAccessContext;
28 class FindBar;
29 class GlobalErrorBubbleViewBase;
30 class GURL;
31 class LocationBar;
32 class Profile;
33 class ProfileResetGlobalError;
34 class StatusBubble;
35 class TemplateURL;
36 class ToolbarActionsBar;
38 struct WebApplicationInfo;
40 namespace content {
41 class WebContents;
42 struct NativeWebKeyboardEvent;
45 namespace extensions {
46 class Command;
47 class Extension;
50 namespace gfx {
51 class Rect;
52 class Size;
55 namespace web_modal {
56 class WebContentsModalDialogHost;
59 ////////////////////////////////////////////////////////////////////////////////
60 // BrowserWindow interface
61 // An interface implemented by the "view" of the Browser window.
62 // This interface includes ui::BaseWindow methods as well as Browser window
63 // specific methods.
65 // NOTE: All getters may return NULL.
67 class BrowserWindow : public ui::BaseWindow {
68 public:
69 virtual ~BrowserWindow() {}
71 //////////////////////////////////////////////////////////////////////////////
72 // ui::BaseWindow interface notes:
74 // Closes the window as soon as possible. If the window is not in a drag
75 // session, it will close immediately; otherwise, it will move offscreen (so
76 // events are still fired) until the drag ends, then close. This assumes
77 // that the Browser is not immediately destroyed, but will be eventually
78 // destroyed by other means (eg, the tab strip going to zero elements).
79 // Bad things happen if the Browser dtor is called directly as a result of
80 // invoking this method.
81 // virtual void Close() = 0;
83 // Browser::OnWindowDidShow should be called after showing the window.
84 // virtual void Show() = 0;
86 //////////////////////////////////////////////////////////////////////////////
87 // Browser specific methods:
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
102 // changed.
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,
121 int index,
122 int reason) = 0;
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 // Methods that change fullscreen state.
131 // On Mac, the tab strip and toolbar will be shown if |with_toolbar| is true,
132 // |with_toolbar| is ignored on other platforms.
133 virtual void EnterFullscreen(const GURL& url,
134 ExclusiveAccessBubbleType bubble_type,
135 bool with_toolbar) = 0;
136 virtual void ExitFullscreen() = 0;
137 virtual void UpdateExclusiveAccessExitBubbleContent(
138 const GURL& url,
139 ExclusiveAccessBubbleType bubble_type) = 0;
141 // Windows and GTK remove the top controls in fullscreen, but Mac and Ash
142 // keep the controls in a slide-down panel.
143 virtual bool ShouldHideUIForFullscreen() const = 0;
145 // Returns true if the fullscreen bubble is visible.
146 virtual bool IsFullscreenBubbleVisible() const = 0;
148 // Show or hide the tab strip, toolbar and bookmark bar when in browser
149 // fullscreen.
150 // Currently only supported on Mac.
151 virtual bool SupportsFullscreenWithToolbar() const = 0;
152 virtual void UpdateFullscreenWithToolbar(bool with_toolbar) = 0;
153 virtual bool IsFullscreenWithToolbar() const = 0;
155 #if defined(OS_WIN)
156 // Sets state for entering or exiting Win8 Metro snap mode.
157 virtual void SetMetroSnapMode(bool enable) = 0;
159 // Returns whether the window is currently in Win8 Metro snap mode.
160 virtual bool IsInMetroSnapMode() const = 0;
161 #endif
163 // Returns the location bar.
164 virtual LocationBar* GetLocationBar() const = 0;
166 // Tries to focus the location bar. Clears the window focus (to avoid
167 // inconsistent state) if this fails.
168 virtual void SetFocusToLocationBar(bool select_all) = 0;
170 // Informs the view whether or not a load is in progress for the current tab.
171 // The view can use this notification to update the reload/stop button.
172 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
174 // Updates the toolbar with the state for the specified |contents|.
175 virtual void UpdateToolbar(content::WebContents* contents) = 0;
177 // Resets the toolbar's tab state for |contents|.
178 virtual void ResetToolbarTabState(content::WebContents* contents) = 0;
180 // Focuses the toolbar (for accessibility).
181 virtual void FocusToolbar() = 0;
183 // Returns the ToolbarActionsBar associated with the window, if any.
184 virtual ToolbarActionsBar* GetToolbarActionsBar() = 0;
186 // Called from toolbar subviews during their show/hide animations.
187 virtual void ToolbarSizeChanged(bool is_animating) = 0;
189 // Focuses the app menu like it was a menu bar.
191 // Not used on the Mac, which has a "normal" menu bar.
192 virtual void FocusAppMenu() = 0;
194 // Focuses the bookmarks toolbar (for accessibility).
195 virtual void FocusBookmarksToolbar() = 0;
197 // Focuses an infobar, if shown (for accessibility).
198 virtual void FocusInfobars() = 0;
200 // Moves keyboard focus to the next pane.
201 virtual void RotatePaneFocus(bool forwards) = 0;
203 // Returns whether the bookmark bar is visible or not.
204 virtual bool IsBookmarkBarVisible() const = 0;
206 // Returns whether the bookmark bar is animating or not.
207 virtual bool IsBookmarkBarAnimating() const = 0;
209 // Returns whether the tab strip is editable (for extensions).
210 virtual bool IsTabStripEditable() const = 0;
212 // Returns whether the tool bar is visible or not.
213 virtual bool IsToolbarVisible() const = 0;
215 // Returns the rect where the resize corner should be drawn by the render
216 // widget host view (on top of what the renderer returns). We return an empty
217 // rect to identify that there shouldn't be a resize corner (in the cases
218 // where we take care of it ourselves at the browser level).
219 virtual gfx::Rect GetRootWindowResizerRect() const = 0;
221 // Shows a confirmation dialog box for adding a search engine described by
222 // |template_url|. Takes ownership of |template_url|.
223 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
224 Profile* profile) = 0;
226 // Shows the Update Recommended dialog box.
227 virtual void ShowUpdateChromeDialog() = 0;
229 // Shows the Bookmark bubble. |url| is the URL being bookmarked,
230 // |already_bookmarked| is true if the url is already bookmarked.
231 virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0;
233 // Callback type used with the ShowBookmarkAppBubble() method. The boolean
234 // parameter is true when the user accepts the dialog. The WebApplicationInfo
235 // parameter contains the WebApplicationInfo as edited by the user.
236 typedef base::Callback<void(bool, const WebApplicationInfo&)>
237 ShowBookmarkAppBubbleCallback;
239 // Shows the Bookmark App bubble.
240 // See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of
241 // bookmark apps.
243 // |web_app_info| is the WebApplicationInfo being converted into an app.
244 virtual void ShowBookmarkAppBubble(
245 const WebApplicationInfo& web_app_info,
246 const ShowBookmarkAppBubbleCallback& callback) = 0;
248 // Shows the translate bubble.
250 // |is_user_gesture| is true when the bubble is shown on the user's deliberate
251 // action.
252 virtual void ShowTranslateBubble(
253 content::WebContents* contents,
254 translate::TranslateStep step,
255 translate::TranslateErrors::Type error_type,
256 bool is_user_gesture) = 0;
258 // Create a session recovery bubble if the last session crashed. It also
259 // offers the option to enable metrics reporting if it's not already enabled.
260 // Returns true if a bubble is created, returns false if nothing is created.
261 virtual bool ShowSessionCrashedBubble() = 0;
263 // Shows the profile reset bubble on the platforms that support it.
264 virtual bool IsProfileResetBubbleSupported() const = 0;
265 virtual GlobalErrorBubbleViewBase* ShowProfileResetBubble(
266 const base::WeakPtr<ProfileResetGlobalError>& global_error) = 0;
268 #if defined(ENABLE_ONE_CLICK_SIGNIN)
269 enum OneClickSigninBubbleType {
270 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
271 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG,
272 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
275 // Callback type used with the ShowOneClickSigninBubble() method. If the
276 // user chooses to accept the sign in, the callback is called to start the
277 // sync process.
278 typedef base::Callback<void(OneClickSigninSyncStarter::StartSyncMode)>
279 StartSyncCallback;
281 // Shows the one-click sign in bubble. |email| holds the full email address
282 // of the account that has signed in.
283 virtual void ShowOneClickSigninBubble(
284 OneClickSigninBubbleType type,
285 const base::string16& email,
286 const base::string16& error_message,
287 const StartSyncCallback& start_sync_callback) = 0;
288 #endif
290 // Whether or not the shelf view is visible.
291 virtual bool IsDownloadShelfVisible() const = 0;
293 // Returns the DownloadShelf.
294 virtual DownloadShelf* GetDownloadShelf() = 0;
296 // Shows the confirmation dialog box warning that the browser is closing with
297 // in-progress downloads.
298 // This method should call |callback| with the user's response.
299 virtual void ConfirmBrowserCloseWithPendingDownloads(
300 int download_count,
301 Browser::DownloadClosePreventionType dialog_type,
302 bool app_modal,
303 const base::Callback<void(bool)>& callback) = 0;
305 // ThemeService calls this when a user has changed his or her theme,
306 // indicating that it's time to redraw everything.
307 virtual void UserChangedTheme() = 0;
309 // Shows the website settings using the specified information. |url| is the
310 // url of the page/frame the info applies to, |ssl| is the SSL information for
311 // that page/frame. If |show_history| is true, a section showing how many
312 // times that URL has been visited is added to the page info.
313 virtual void ShowWebsiteSettings(
314 Profile* profile,
315 content::WebContents* web_contents,
316 const GURL& url,
317 const SecurityStateModel::SecurityInfo& security_info) = 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 CutCopyPaste(int command_id) = 0;
339 // Return the correct disposition for a popup window based on |bounds|.
340 virtual WindowOpenDisposition GetDispositionForPopupBounds(
341 const gfx::Rect& bounds) = 0;
343 // Construct a FindBar implementation for the |browser|.
344 virtual FindBar* CreateFindBar() = 0;
346 // Return the WebContentsModalDialogHost for use in positioning web contents
347 // modal dialogs within the browser window. This can sometimes be NULL (for
348 // instance during tab drag on Views/Win32).
349 virtual web_modal::WebContentsModalDialogHost*
350 GetWebContentsModalDialogHost() = 0;
352 // Invoked when the preferred size of the contents in current tab has been
353 // changed. We might choose to update the window size to accomodate this
354 // change.
355 // Note that this won't be fired if we change tabs.
356 virtual void UpdatePreferredSize(content::WebContents* web_contents,
357 const gfx::Size& pref_size) {}
359 // Invoked when the contents auto-resized and the container should match it.
360 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
361 const gfx::Size& new_size) {}
363 // Construct a BrowserWindow implementation for the specified |browser|.
364 static BrowserWindow* CreateBrowserWindow(Browser* browser);
366 // Returns a HostDesktopType that is compatible with the current Chrome window
367 // configuration. On Windows with Ash, this is always HOST_DESKTOP_TYPE_ASH
368 // while Chrome is running in Metro mode. Otherwise returns |desktop_type|.
369 static chrome::HostDesktopType AdjustHostDesktopType(
370 chrome::HostDesktopType desktop_type);
372 // Shows the avatar bubble on the window frame off of the avatar button with
373 // the given mode. The Service Type specified by GAIA is provided as well.
374 enum AvatarBubbleMode {
375 AVATAR_BUBBLE_MODE_DEFAULT,
376 AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT,
377 AVATAR_BUBBLE_MODE_SIGNIN,
378 AVATAR_BUBBLE_MODE_ADD_ACCOUNT,
379 AVATAR_BUBBLE_MODE_REAUTH,
380 AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN,
381 AVATAR_BUBBLE_MODE_SHOW_ERROR,
382 AVATAR_BUBBLE_MODE_FAST_USER_SWITCH,
384 virtual void ShowAvatarBubbleFromAvatarButton(AvatarBubbleMode mode,
385 const signin::ManageAccountsParams& manage_accounts_params) = 0;
387 // Returns the height inset for RenderView when detached bookmark bar is
388 // shown. Invoked when a new RenderHostView is created for a non-NTP
389 // navigation entry and the bookmark bar is detached.
390 virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
392 // Executes |command| registered by |extension|.
393 virtual void ExecuteExtensionCommand(const extensions::Extension* extension,
394 const extensions::Command& command) = 0;
396 // Returns object implementing ExclusiveAccessContext interface.
397 virtual ExclusiveAccessContext* GetExclusiveAccessContext() = 0;
399 protected:
400 friend class BrowserCloseManager;
401 friend class BrowserView;
402 virtual void DestroyBrowser() = 0;
405 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_