Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / browser_window.h
blobafbddd2b2dca65eb7c9ba0a31fe371fd2cfaa3c2
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"
24 class Browser;
25 class DownloadShelf;
26 class ExclusiveAccessContext;
27 class FindBar;
28 class GlobalErrorBubbleViewBase;
29 class GURL;
30 class LocationBar;
31 class Profile;
32 class ProfileResetGlobalError;
33 class StatusBubble;
34 class TemplateURL;
35 class ToolbarActionsBar;
37 struct WebApplicationInfo;
39 namespace content {
40 class WebContents;
41 struct NativeWebKeyboardEvent;
42 struct SSLStatus;
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(Profile* profile,
314 content::WebContents* web_contents,
315 const GURL& url,
316 const content::SSLStatus& ssl) = 0;
318 // Shows the app menu (for accessibility).
319 virtual void ShowAppMenu() = 0;
321 // Allows the BrowserWindow object to handle the specified keyboard event
322 // before sending it to the renderer.
323 // Returns true if the |event| was handled. Otherwise, if the |event| would
324 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
325 // |*is_keyboard_shortcut| should be set to true.
326 virtual bool PreHandleKeyboardEvent(
327 const content::NativeWebKeyboardEvent& event,
328 bool* is_keyboard_shortcut) = 0;
330 // Allows the BrowserWindow object to handle the specified keyboard event,
331 // if the renderer did not process it.
332 virtual void HandleKeyboardEvent(
333 const content::NativeWebKeyboardEvent& event) = 0;
335 // Clipboard commands applied to the whole browser window.
336 virtual void CutCopyPaste(int command_id) = 0;
338 // Return the correct disposition for a popup window based on |bounds|.
339 virtual WindowOpenDisposition GetDispositionForPopupBounds(
340 const gfx::Rect& bounds) = 0;
342 // Construct a FindBar implementation for the |browser|.
343 virtual FindBar* CreateFindBar() = 0;
345 // Return the WebContentsModalDialogHost for use in positioning web contents
346 // modal dialogs within the browser window. This can sometimes be NULL (for
347 // instance during tab drag on Views/Win32).
348 virtual web_modal::WebContentsModalDialogHost*
349 GetWebContentsModalDialogHost() = 0;
351 // Invoked when the preferred size of the contents in current tab has been
352 // changed. We might choose to update the window size to accomodate this
353 // change.
354 // Note that this won't be fired if we change tabs.
355 virtual void UpdatePreferredSize(content::WebContents* web_contents,
356 const gfx::Size& pref_size) {}
358 // Invoked when the contents auto-resized and the container should match it.
359 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
360 const gfx::Size& new_size) {}
362 // Construct a BrowserWindow implementation for the specified |browser|.
363 static BrowserWindow* CreateBrowserWindow(Browser* browser);
365 // Returns a HostDesktopType that is compatible with the current Chrome window
366 // configuration. On Windows with Ash, this is always HOST_DESKTOP_TYPE_ASH
367 // while Chrome is running in Metro mode. Otherwise returns |desktop_type|.
368 static chrome::HostDesktopType AdjustHostDesktopType(
369 chrome::HostDesktopType desktop_type);
371 // Shows the avatar bubble on the window frame off of the avatar button with
372 // the given mode. The Service Type specified by GAIA is provided as well.
373 enum AvatarBubbleMode {
374 AVATAR_BUBBLE_MODE_DEFAULT,
375 AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT,
376 AVATAR_BUBBLE_MODE_SIGNIN,
377 AVATAR_BUBBLE_MODE_ADD_ACCOUNT,
378 AVATAR_BUBBLE_MODE_REAUTH,
379 AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN,
380 AVATAR_BUBBLE_MODE_SHOW_ERROR,
381 AVATAR_BUBBLE_MODE_FAST_USER_SWITCH,
383 virtual void ShowAvatarBubbleFromAvatarButton(AvatarBubbleMode mode,
384 const signin::ManageAccountsParams& manage_accounts_params) = 0;
386 // Returns the height inset for RenderView when detached bookmark bar is
387 // shown. Invoked when a new RenderHostView is created for a non-NTP
388 // navigation entry and the bookmark bar is detached.
389 virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
391 // Executes |command| registered by |extension|.
392 virtual void ExecuteExtensionCommand(const extensions::Extension* extension,
393 const extensions::Command& command) = 0;
395 // Returns object implementing ExclusiveAccessContext interface.
396 virtual ExclusiveAccessContext* GetExclusiveAccessContext() = 0;
398 protected:
399 friend class BrowserCloseManager;
400 friend class BrowserView;
401 virtual void DestroyBrowser() = 0;
404 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_