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/ui/bookmarks/bookmark_bar.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h"
13 #include "chrome/browser/ui/host_desktop.h"
14 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
15 #include "chrome/browser/ui/translate/translate_bubble_model.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"
23 class BrowserWindowTesting
;
31 #if !defined(OS_MACOSX)
36 class PasswordGenerator
;
41 struct NativeWebKeyboardEvent
;
45 namespace extensions
{
55 class WebContentsModalDialogHost
;
58 ////////////////////////////////////////////////////////////////////////////////
59 // BrowserWindow interface
60 // An interface implemented by the "view" of the Browser window.
61 // This interface includes ui::BaseWindow methods as well as Browser window
64 // NOTE: All getters may return NULL.
66 class BrowserWindow
: public ui::BaseWindow
{
68 virtual ~BrowserWindow() {}
70 //////////////////////////////////////////////////////////////////////////////
71 // ui::BaseWindow interface notes:
73 // Closes the window as soon as possible. If the window is not in a drag
74 // session, it will close immediately; otherwise, it will move offscreen (so
75 // events are still fired) until the drag ends, then close. This assumes
76 // that the Browser is not immediately destroyed, but will be eventually
77 // destroyed by other means (eg, the tab strip going to zero elements).
78 // Bad things happen if the Browser dtor is called directly as a result of
79 // invoking this method.
80 // virtual void Close() = 0;
82 // Browser::OnWindowDidShow should be called after showing the window.
83 // virtual void Show() = 0;
85 //////////////////////////////////////////////////////////////////////////////
86 // Browser specific methods:
88 // Returns a pointer to the testing interface to the Browser window, or NULL
90 virtual BrowserWindowTesting
* GetBrowserWindowTesting() = 0;
92 // Return the status bubble associated with the frame
93 virtual StatusBubble
* GetStatusBubble() = 0;
95 // Inform the frame that the selected tab favicon or title has changed. Some
96 // frames may need to refresh their title bar.
97 virtual void UpdateTitleBar() = 0;
99 // Invoked when the state of the bookmark bar changes. This is only invoked if
100 // the state changes for the current tab, it is not sent when switching tabs.
101 virtual void BookmarkBarStateChanged(
102 BookmarkBar::AnimateChangeType change_type
) = 0;
104 // Inform the frame that the dev tools window for the selected tab has
106 virtual void UpdateDevTools() = 0;
108 // Update any loading animations running in the window. |should_animate| is
109 // true if there are tabs loading and the animations should continue, false
110 // if there are no active loads and the animations should end.
111 virtual void UpdateLoadingAnimations(bool should_animate
) = 0;
113 // Sets the starred state for the current tab.
114 virtual void SetStarredState(bool is_starred
) = 0;
116 // Sets whether the translate icon is lit for the current tab.
117 virtual void SetTranslateIconToggled(bool is_lit
) = 0;
119 // Called when the active tab changes. Subclasses which implement
120 // TabStripModelObserver should implement this instead of ActiveTabChanged();
121 // the Browser will call this method while processing that one.
122 virtual void OnActiveTabChanged(content::WebContents
* old_contents
,
123 content::WebContents
* new_contents
,
127 // Called to force the zoom state to for the active tab to be recalculated.
128 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
129 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
130 // + or - in the wrench menu to change zoom).
131 virtual void ZoomChangedForActiveTab(bool can_show_bubble
) = 0;
133 // Accessors for fullscreen mode state.
134 virtual void EnterFullscreen(const GURL
& url
,
135 FullscreenExitBubbleType bubble_type
) = 0;
136 virtual void ExitFullscreen() = 0;
137 virtual void UpdateFullscreenExitBubbleContent(
139 FullscreenExitBubbleType 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;
149 // Sets state for entering or exiting Win8 Metro snap mode.
150 virtual void SetMetroSnapMode(bool enable
) = 0;
152 // Returns whether the window is currently in Win8 Metro snap mode.
153 virtual bool IsInMetroSnapMode() const = 0;
156 // Returns the location bar.
157 virtual LocationBar
* GetLocationBar() const = 0;
159 // Tries to focus the location bar. Clears the window focus (to avoid
160 // inconsistent state) if this fails.
161 virtual void SetFocusToLocationBar(bool select_all
) = 0;
163 // Informs the view whether or not a load is in progress for the current tab.
164 // The view can use this notification to update the reload/stop button.
165 virtual void UpdateReloadStopState(bool is_loading
, bool force
) = 0;
167 // Updates the toolbar with the state for the specified |contents|.
168 virtual void UpdateToolbar(content::WebContents
* contents
) = 0;
170 // Focuses the toolbar (for accessibility).
171 virtual void FocusToolbar() = 0;
173 // Focuses the app menu like it was a menu bar.
175 // Not used on the Mac, which has a "normal" menu bar.
176 virtual void FocusAppMenu() = 0;
178 // Focuses the bookmarks toolbar (for accessibility).
179 virtual void FocusBookmarksToolbar() = 0;
181 // Focuses an infobar, if shown (for accessibility).
182 virtual void FocusInfobars() = 0;
184 // Moves keyboard focus to the next pane.
185 virtual void RotatePaneFocus(bool forwards
) = 0;
187 // Returns whether the bookmark bar is visible or not.
188 virtual bool IsBookmarkBarVisible() const = 0;
190 // Returns whether the bookmark bar is animating or not.
191 virtual bool IsBookmarkBarAnimating() const = 0;
193 // Returns whether the tab strip is editable (for extensions).
194 virtual bool IsTabStripEditable() const = 0;
196 // Returns whether the tool bar is visible or not.
197 virtual bool IsToolbarVisible() const = 0;
199 // Returns the rect where the resize corner should be drawn by the render
200 // widget host view (on top of what the renderer returns). We return an empty
201 // rect to identify that there shouldn't be a resize corner (in the cases
202 // where we take care of it ourselves at the browser level).
203 virtual gfx::Rect
GetRootWindowResizerRect() const = 0;
205 // Shows a confirmation dialog box for adding a search engine described by
206 // |template_url|. Takes ownership of |template_url|.
207 virtual void ConfirmAddSearchProvider(TemplateURL
* template_url
,
208 Profile
* profile
) = 0;
210 // Shows the Update Recommended dialog box.
211 virtual void ShowUpdateChromeDialog() = 0;
213 // Shows the Bookmark bubble. |url| is the URL being bookmarked,
214 // |already_bookmarked| is true if the url is already bookmarked.
215 virtual void ShowBookmarkBubble(const GURL
& url
, bool already_bookmarked
) = 0;
217 // Shows the bookmark prompt.
218 // TODO(yosin): Make ShowBookmarkPrompt pure virtual.
219 virtual void ShowBookmarkPrompt() {}
221 // Shows the translate bubble.
222 virtual void ShowTranslateBubble(
223 content::WebContents
* contents
,
224 TranslateBubbleModel::ViewState view_state
,
225 TranslateErrors::Type error_type
) = 0;
227 #if defined(ENABLE_ONE_CLICK_SIGNIN)
228 enum OneClickSigninBubbleType
{
229 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE
,
230 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG
,
231 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
234 // Callback type used with the ShowOneClickSigninBubble() method. If the
235 // user chooses to accept the sign in, the callback is called to start the
237 typedef base::Callback
<void(OneClickSigninSyncStarter::StartSyncMode
)>
240 // Shows the one-click sign in bubble. |email| holds the full email address
241 // of the account that has signed in.
242 virtual void ShowOneClickSigninBubble(
243 OneClickSigninBubbleType type
,
244 const base::string16
& email
,
245 const base::string16
& error_message
,
246 const StartSyncCallback
& start_sync_callback
) = 0;
249 // Whether or not the shelf view is visible.
250 virtual bool IsDownloadShelfVisible() const = 0;
252 // Returns the DownloadShelf.
253 virtual DownloadShelf
* GetDownloadShelf() = 0;
255 // Shows the confirmation dialog box warning that the browser is closing with
256 // in-progress downloads.
257 // This method should call |callback| with the user's response.
258 virtual void ConfirmBrowserCloseWithPendingDownloads(
260 Browser::DownloadClosePreventionType dialog_type
,
262 const base::Callback
<void(bool)>& callback
) = 0;
264 // ThemeService calls this when a user has changed his or her theme,
265 // indicating that it's time to redraw everything.
266 virtual void UserChangedTheme() = 0;
268 // Get extra vertical height that the render view should add to its requests
269 // to webkit. This can help prevent sending extraneous layout/repaint requests
270 // when the delegate is in the process of resizing the tab contents view (e.g.
271 // during infobar animations).
272 virtual int GetExtraRenderViewHeight() const = 0;
274 // Notification that |contents| got the focus through user action (click
276 virtual void WebContentsFocused(content::WebContents
* contents
) = 0;
278 // Shows the website settings using the specified information. |url| is the
279 // url of the page/frame the info applies to, |ssl| is the SSL information for
280 // that page/frame. If |show_history| is true, a section showing how many
281 // times that URL has been visited is added to the page info.
282 virtual void ShowWebsiteSettings(Profile
* profile
,
283 content::WebContents
* web_contents
,
285 const content::SSLStatus
& ssl
) = 0;
287 // Shows the app menu (for accessibility).
288 virtual void ShowAppMenu() = 0;
290 // Allows the BrowserWindow object to handle the specified keyboard event
291 // before sending it to the renderer.
292 // Returns true if the |event| was handled. Otherwise, if the |event| would
293 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
294 // |*is_keyboard_shortcut| should be set to true.
295 virtual bool PreHandleKeyboardEvent(
296 const content::NativeWebKeyboardEvent
& event
,
297 bool* is_keyboard_shortcut
) = 0;
299 // Allows the BrowserWindow object to handle the specified keyboard event,
300 // if the renderer did not process it.
301 virtual void HandleKeyboardEvent(
302 const content::NativeWebKeyboardEvent
& event
) = 0;
304 // Clipboard commands applied to the whole browser window.
305 virtual void Cut() = 0;
306 virtual void Copy() = 0;
307 virtual void Paste() = 0;
309 #if defined(OS_MACOSX)
310 // Opens the tabpose view.
311 virtual void OpenTabpose() = 0;
313 // Enters Mac specific fullscreen mode with chrome displayed (e.g. omnibox)
314 // on OSX 10.7+, a.k.a. Lion Fullscreen mode.
315 // Invalid to call on OSX earlier than 10.7.
316 // Enters either from non fullscreen, or from fullscreen without chrome.
317 // Exit to normal fullscreen with EnterFullscreen().
318 virtual void EnterFullscreenWithChrome() = 0;
319 virtual bool IsFullscreenWithChrome() = 0;
320 virtual bool IsFullscreenWithoutChrome() = 0;
323 // Return the correct disposition for a popup window based on |bounds|.
324 virtual WindowOpenDisposition
GetDispositionForPopupBounds(
325 const gfx::Rect
& bounds
) = 0;
327 // Construct a FindBar implementation for the |browser|.
328 virtual FindBar
* CreateFindBar() = 0;
330 // Return the WebContentsModalDialogHost for use in positioning web contents
331 // modal dialogs within the browser window. This can sometimes be NULL (for
332 // instance during tab drag on Views/Win32).
333 virtual web_modal::WebContentsModalDialogHost
*
334 GetWebContentsModalDialogHost() = 0;
336 // Invoked when the preferred size of the contents in current tab has been
337 // changed. We might choose to update the window size to accomodate this
339 // Note that this won't be fired if we change tabs.
340 virtual void UpdatePreferredSize(content::WebContents
* web_contents
,
341 const gfx::Size
& pref_size
) {}
343 // Invoked when the contents auto-resized and the container should match it.
344 virtual void ResizeDueToAutoResize(content::WebContents
* web_contents
,
345 const gfx::Size
& new_size
) {}
347 // Construct a BrowserWindow implementation for the specified |browser|.
348 static BrowserWindow
* CreateBrowserWindow(Browser
* browser
);
350 // Returns a HostDesktopType that is compatible with the current Chrome window
351 // configuration. On Windows with Ash, this is always HOST_DESKTOP_TYPE_ASH
352 // while Chrome is running in Metro mode. Otherwise returns |desktop_type|.
353 static chrome::HostDesktopType
AdjustHostDesktopType(
354 chrome::HostDesktopType desktop_type
);
356 // Shows the avatar bubble inside |web_contents|. The bubble is positioned
357 // relative to |rect|. |rect| should be in the |web_contents| coordinate
359 virtual void ShowAvatarBubble(content::WebContents
* web_contents
,
360 const gfx::Rect
& rect
) = 0;
362 // Shows the avatar bubble on the window frame off of the avatar button.
363 virtual void ShowAvatarBubbleFromAvatarButton() = 0;
365 // Show bubble for password generation positioned relative to |rect|. The
366 // subclasses implementing this interface do not own the |password_generator|
367 // object which is passed to generate the password. |form| is the form that
368 // contains the password field that the bubble will be associated with.
369 virtual void ShowPasswordGenerationBubble(
370 const gfx::Rect
& rect
,
371 const autofill::PasswordForm
& form
,
372 autofill::PasswordGenerator
* password_generator
) = 0;
374 // Invoked when the amount of vertical overscroll changes. |delta_y| is the
375 // amount of overscroll that has occured in the y-direction.
376 virtual void OverscrollUpdate(int delta_y
) {}
378 // Returns the height inset for RenderView when detached bookmark bar is
379 // shown. Invoked when a new RenderHostView is created for a non-NTP
380 // navigation entry and the bookmark bar is detached.
381 virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
384 friend class BrowserCloseManager
;
385 friend class BrowserView
;
386 virtual void DestroyBrowser() = 0;
389 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
390 class BookmarkBarView
;
391 class LocationBarView
;
396 #endif // defined(OS_WIN)
398 // A BrowserWindow utility interface used for accessing elements of the browser
399 // UI used only by UI test automation.
400 class BrowserWindowTesting
{
402 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
403 // Returns the BookmarkBarView.
404 virtual BookmarkBarView
* GetBookmarkBarView() const = 0;
406 // Returns the LocationBarView.
407 virtual LocationBarView
* GetLocationBarView() const = 0;
409 // Returns the TabContentsContainer.
410 virtual views::View
* GetTabContentsContainerView() const = 0;
412 // Returns the ToolbarView.
413 virtual ToolbarView
* GetToolbarView() const = 0;
417 virtual ~BrowserWindowTesting() {}
420 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_