Componentize AccountReconcilor.
[chromium-blink-merge.git] / chrome / browser / ui / browser_window.h
blob226033be58e6378054e3b007c497b4a1d3116964
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/translate/translate_tab_helper.h"
11 #include "chrome/browser/ui/bookmarks/bookmark_bar.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h"
14 #include "chrome/browser/ui/host_desktop.h"
15 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
16 #include "chrome/common/content_settings_types.h"
17 #include "components/translate/core/common/translate_errors.h"
18 #include "ui/base/base_window.h"
19 #include "ui/base/window_open_disposition.h"
20 #include "ui/gfx/native_widget_types.h"
22 class Browser;
23 class BrowserWindowTesting;
24 class DownloadShelf;
25 class FindBar;
26 class GURL;
27 class LocationBar;
28 class Profile;
29 class StatusBubble;
30 class TemplateURL;
31 #if !defined(OS_MACOSX)
32 class ToolbarView;
33 #endif
35 struct WebApplicationInfo;
37 namespace autofill {
38 class PasswordGenerator;
39 struct PasswordForm;
41 namespace content {
42 class WebContents;
43 struct NativeWebKeyboardEvent;
44 struct SSLStatus;
47 namespace extensions {
48 class Command;
49 class Extension;
52 namespace gfx {
53 class Rect;
54 class Size;
57 namespace web_modal {
58 class WebContentsModalDialogHost;
61 ////////////////////////////////////////////////////////////////////////////////
62 // BrowserWindow interface
63 // An interface implemented by the "view" of the Browser window.
64 // This interface includes ui::BaseWindow methods as well as Browser window
65 // specific methods.
67 // NOTE: All getters may return NULL.
69 class BrowserWindow : public ui::BaseWindow {
70 public:
71 virtual ~BrowserWindow() {}
73 //////////////////////////////////////////////////////////////////////////////
74 // ui::BaseWindow interface notes:
76 // Closes the window as soon as possible. If the window is not in a drag
77 // session, it will close immediately; otherwise, it will move offscreen (so
78 // events are still fired) until the drag ends, then close. This assumes
79 // that the Browser is not immediately destroyed, but will be eventually
80 // destroyed by other means (eg, the tab strip going to zero elements).
81 // Bad things happen if the Browser dtor is called directly as a result of
82 // invoking this method.
83 // virtual void Close() = 0;
85 // Browser::OnWindowDidShow should be called after showing the window.
86 // virtual void Show() = 0;
88 //////////////////////////////////////////////////////////////////////////////
89 // Browser specific methods:
91 // Returns a pointer to the testing interface to the Browser window, or NULL
92 // if there is none.
93 virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0;
95 // Return the status bubble associated with the frame
96 virtual StatusBubble* GetStatusBubble() = 0;
98 // Inform the frame that the selected tab favicon or title has changed. Some
99 // frames may need to refresh their title bar.
100 virtual void UpdateTitleBar() = 0;
102 // Invoked when the state of the bookmark bar changes. This is only invoked if
103 // the state changes for the current tab, it is not sent when switching tabs.
104 virtual void BookmarkBarStateChanged(
105 BookmarkBar::AnimateChangeType change_type) = 0;
107 // Inform the frame that the dev tools window for the selected tab has
108 // changed.
109 virtual void UpdateDevTools() = 0;
111 // Update any loading animations running in the window. |should_animate| is
112 // true if there are tabs loading and the animations should continue, false
113 // if there are no active loads and the animations should end.
114 virtual void UpdateLoadingAnimations(bool should_animate) = 0;
116 // Sets the starred state for the current tab.
117 virtual void SetStarredState(bool is_starred) = 0;
119 // Sets whether the translate icon is lit for the current tab.
120 virtual void SetTranslateIconToggled(bool is_lit) = 0;
122 // Called when the active tab changes. Subclasses which implement
123 // TabStripModelObserver should implement this instead of ActiveTabChanged();
124 // the Browser will call this method while processing that one.
125 virtual void OnActiveTabChanged(content::WebContents* old_contents,
126 content::WebContents* new_contents,
127 int index,
128 int reason) = 0;
130 // Called to force the zoom state to for the active tab to be recalculated.
131 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
132 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
133 // + or - in the wrench menu to change zoom).
134 virtual void ZoomChangedForActiveTab(bool can_show_bubble) = 0;
136 // Accessors for fullscreen mode state.
137 virtual void EnterFullscreen(const GURL& url,
138 FullscreenExitBubbleType bubble_type) = 0;
139 virtual void ExitFullscreen() = 0;
140 virtual void UpdateFullscreenExitBubbleContent(
141 const GURL& url,
142 FullscreenExitBubbleType bubble_type) = 0;
144 // Windows and GTK remove the top controls in fullscreen, but Mac and Ash
145 // keep the controls in a slide-down panel.
146 virtual bool ShouldHideUIForFullscreen() const = 0;
148 // Returns true if the fullscreen bubble is visible.
149 virtual bool IsFullscreenBubbleVisible() const = 0;
151 #if defined(OS_WIN)
152 // Sets state for entering or exiting Win8 Metro snap mode.
153 virtual void SetMetroSnapMode(bool enable) = 0;
155 // Returns whether the window is currently in Win8 Metro snap mode.
156 virtual bool IsInMetroSnapMode() const = 0;
157 #endif
159 // Returns the location bar.
160 virtual LocationBar* GetLocationBar() const = 0;
162 // Tries to focus the location bar. Clears the window focus (to avoid
163 // inconsistent state) if this fails.
164 virtual void SetFocusToLocationBar(bool select_all) = 0;
166 // Informs the view whether or not a load is in progress for the current tab.
167 // The view can use this notification to update the reload/stop button.
168 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
170 // Updates the toolbar with the state for the specified |contents|.
171 virtual void UpdateToolbar(content::WebContents* contents) = 0;
173 // Focuses the toolbar (for accessibility).
174 virtual void FocusToolbar() = 0;
176 // Focuses the app menu like it was a menu bar.
178 // Not used on the Mac, which has a "normal" menu bar.
179 virtual void FocusAppMenu() = 0;
181 // Focuses the bookmarks toolbar (for accessibility).
182 virtual void FocusBookmarksToolbar() = 0;
184 // Focuses an infobar, if shown (for accessibility).
185 virtual void FocusInfobars() = 0;
187 // Moves keyboard focus to the next pane.
188 virtual void RotatePaneFocus(bool forwards) = 0;
190 // Returns whether the bookmark bar is visible or not.
191 virtual bool IsBookmarkBarVisible() const = 0;
193 // Returns whether the bookmark bar is animating or not.
194 virtual bool IsBookmarkBarAnimating() const = 0;
196 // Returns whether the tab strip is editable (for extensions).
197 virtual bool IsTabStripEditable() const = 0;
199 // Returns whether the tool bar is visible or not.
200 virtual bool IsToolbarVisible() const = 0;
202 // Returns the rect where the resize corner should be drawn by the render
203 // widget host view (on top of what the renderer returns). We return an empty
204 // rect to identify that there shouldn't be a resize corner (in the cases
205 // where we take care of it ourselves at the browser level).
206 virtual gfx::Rect GetRootWindowResizerRect() const = 0;
208 // Shows a confirmation dialog box for adding a search engine described by
209 // |template_url|. Takes ownership of |template_url|.
210 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
211 Profile* profile) = 0;
213 // Shows the Update Recommended dialog box.
214 virtual void ShowUpdateChromeDialog() = 0;
216 // Shows the Bookmark bubble. |url| is the URL being bookmarked,
217 // |already_bookmarked| is true if the url is already bookmarked.
218 virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0;
220 // Shows the Bookmark App bubble.
221 // See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of
222 // bookmark apps.
224 // |web_app_info| is the WebApplicationInfo being converted into an app.
225 // |extension_id| is the id of the bookmark app.
226 virtual void ShowBookmarkAppBubble(const WebApplicationInfo& web_app_info,
227 const std::string& extension_id) = 0;
229 // Shows the bookmark prompt.
230 // TODO(yosin): Make ShowBookmarkPrompt pure virtual.
231 virtual void ShowBookmarkPrompt() {}
233 // Shows the translate bubble.
234 virtual void ShowTranslateBubble(content::WebContents* contents,
235 TranslateTabHelper::TranslateStep step,
236 TranslateErrors::Type error_type) = 0;
238 #if defined(ENABLE_ONE_CLICK_SIGNIN)
239 enum OneClickSigninBubbleType {
240 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
241 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG,
242 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
245 // Callback type used with the ShowOneClickSigninBubble() method. If the
246 // user chooses to accept the sign in, the callback is called to start the
247 // sync process.
248 typedef base::Callback<void(OneClickSigninSyncStarter::StartSyncMode)>
249 StartSyncCallback;
251 // Shows the one-click sign in bubble. |email| holds the full email address
252 // of the account that has signed in.
253 virtual void ShowOneClickSigninBubble(
254 OneClickSigninBubbleType type,
255 const base::string16& email,
256 const base::string16& error_message,
257 const StartSyncCallback& start_sync_callback) = 0;
258 #endif
260 // Whether or not the shelf view is visible.
261 virtual bool IsDownloadShelfVisible() const = 0;
263 // Returns the DownloadShelf.
264 virtual DownloadShelf* GetDownloadShelf() = 0;
266 // Shows the confirmation dialog box warning that the browser is closing with
267 // in-progress downloads.
268 // This method should call |callback| with the user's response.
269 virtual void ConfirmBrowserCloseWithPendingDownloads(
270 int download_count,
271 Browser::DownloadClosePreventionType dialog_type,
272 bool app_modal,
273 const base::Callback<void(bool)>& callback) = 0;
275 // ThemeService calls this when a user has changed his or her theme,
276 // indicating that it's time to redraw everything.
277 virtual void UserChangedTheme() = 0;
279 // Get extra vertical height that the render view should add to its requests
280 // to webkit. This can help prevent sending extraneous layout/repaint requests
281 // when the delegate is in the process of resizing the tab contents view (e.g.
282 // during infobar animations).
283 virtual int GetExtraRenderViewHeight() const = 0;
285 // Notification that |contents| got the focus through user action (click
286 // on the page).
287 virtual void WebContentsFocused(content::WebContents* contents) = 0;
289 // Shows the website settings using the specified information. |url| is the
290 // url of the page/frame the info applies to, |ssl| is the SSL information for
291 // that page/frame. If |show_history| is true, a section showing how many
292 // times that URL has been visited is added to the page info.
293 virtual void ShowWebsiteSettings(Profile* profile,
294 content::WebContents* web_contents,
295 const GURL& url,
296 const content::SSLStatus& ssl) = 0;
298 // Shows the app menu (for accessibility).
299 virtual void ShowAppMenu() = 0;
301 // Allows the BrowserWindow object to handle the specified keyboard event
302 // before sending it to the renderer.
303 // Returns true if the |event| was handled. Otherwise, if the |event| would
304 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
305 // |*is_keyboard_shortcut| should be set to true.
306 virtual bool PreHandleKeyboardEvent(
307 const content::NativeWebKeyboardEvent& event,
308 bool* is_keyboard_shortcut) = 0;
310 // Allows the BrowserWindow object to handle the specified keyboard event,
311 // if the renderer did not process it.
312 virtual void HandleKeyboardEvent(
313 const content::NativeWebKeyboardEvent& event) = 0;
315 // Clipboard commands applied to the whole browser window.
316 virtual void Cut() = 0;
317 virtual void Copy() = 0;
318 virtual void Paste() = 0;
320 #if defined(OS_MACOSX)
321 // Enters Mac specific fullscreen mode with chrome displayed (e.g. omnibox)
322 // on OSX 10.7+, a.k.a. Lion Fullscreen mode.
323 // Invalid to call on OSX earlier than 10.7.
324 // Enters either from non fullscreen, or from fullscreen without chrome.
325 // Exit to normal fullscreen with EnterFullscreen().
326 virtual void EnterFullscreenWithChrome() = 0;
327 virtual bool IsFullscreenWithChrome() = 0;
328 virtual bool IsFullscreenWithoutChrome() = 0;
329 #endif
331 // Return the correct disposition for a popup window based on |bounds|.
332 virtual WindowOpenDisposition GetDispositionForPopupBounds(
333 const gfx::Rect& bounds) = 0;
335 // Construct a FindBar implementation for the |browser|.
336 virtual FindBar* CreateFindBar() = 0;
338 // Return the WebContentsModalDialogHost for use in positioning web contents
339 // modal dialogs within the browser window. This can sometimes be NULL (for
340 // instance during tab drag on Views/Win32).
341 virtual web_modal::WebContentsModalDialogHost*
342 GetWebContentsModalDialogHost() = 0;
344 // Invoked when the preferred size of the contents in current tab has been
345 // changed. We might choose to update the window size to accomodate this
346 // change.
347 // Note that this won't be fired if we change tabs.
348 virtual void UpdatePreferredSize(content::WebContents* web_contents,
349 const gfx::Size& pref_size) {}
351 // Invoked when the contents auto-resized and the container should match it.
352 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
353 const gfx::Size& new_size) {}
355 // Construct a BrowserWindow implementation for the specified |browser|.
356 static BrowserWindow* CreateBrowserWindow(Browser* browser);
358 // Returns a HostDesktopType that is compatible with the current Chrome window
359 // configuration. On Windows with Ash, this is always HOST_DESKTOP_TYPE_ASH
360 // while Chrome is running in Metro mode. Otherwise returns |desktop_type|.
361 static chrome::HostDesktopType AdjustHostDesktopType(
362 chrome::HostDesktopType desktop_type);
364 // Shows the avatar bubble inside |web_contents|. The bubble is positioned
365 // relative to |rect|. |rect| should be in the |web_contents| coordinate
366 // system.
367 virtual void ShowAvatarBubble(content::WebContents* web_contents,
368 const gfx::Rect& rect) = 0;
370 // Shows the avatar bubble on the window frame off of the avatar button with
371 // the given mode.
372 enum AvatarBubbleMode {
373 AVATAR_BUBBLE_MODE_DEFAULT,
374 AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT
376 virtual void ShowAvatarBubbleFromAvatarButton(AvatarBubbleMode mode) = 0;
378 // Show bubble for password generation positioned relative to |rect|. The
379 // subclasses implementing this interface do not own the |password_generator|
380 // object which is passed to generate the password. |form| is the form that
381 // contains the password field that the bubble will be associated with.
382 virtual void ShowPasswordGenerationBubble(
383 const gfx::Rect& rect,
384 const autofill::PasswordForm& form,
385 autofill::PasswordGenerator* password_generator) = 0;
387 // Invoked when the amount of vertical overscroll changes. |delta_y| is the
388 // amount of overscroll that has occured in the y-direction.
389 virtual void OverscrollUpdate(int delta_y) {}
391 // Returns the height inset for RenderView when detached bookmark bar is
392 // shown. Invoked when a new RenderHostView is created for a non-NTP
393 // navigation entry and the bookmark bar is detached.
394 virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
396 // Executes |command| registered by |extension|.
397 virtual void ExecuteExtensionCommand(const extensions::Extension* extension,
398 const extensions::Command& command) = 0;
400 // Shows the page action for the extension.
401 virtual void ShowPageActionPopup(const extensions::Extension* extension) = 0;
403 // Shows the browser action for the extension. NOTE(wittman): This function
404 // grants tab permissions to the browser action popup, so it should only be
405 // invoked due to user action, not due to invocation from an extensions API.
406 virtual void ShowBrowserActionPopup(
407 const extensions::Extension* extension) = 0;
409 protected:
410 friend class BrowserCloseManager;
411 friend class BrowserView;
412 virtual void DestroyBrowser() = 0;
415 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
416 class BookmarkBarView;
417 class LocationBarView;
419 namespace views {
420 class View;
422 #endif // defined(OS_WIN)
424 // A BrowserWindow utility interface used for accessing elements of the browser
425 // UI used only by UI test automation.
426 class BrowserWindowTesting {
427 public:
428 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
429 // Returns the BookmarkBarView.
430 virtual BookmarkBarView* GetBookmarkBarView() const = 0;
432 // Returns the LocationBarView.
433 virtual LocationBarView* GetLocationBarView() const = 0;
435 // Returns the TabContentsContainer.
436 virtual views::View* GetTabContentsContainerView() const = 0;
438 // Returns the ToolbarView.
439 virtual ToolbarView* GetToolbarView() const = 0;
440 #endif
442 protected:
443 virtual ~BrowserWindowTesting() {}
446 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_