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 "ui/base/base_window.h"
18 #include "ui/base/window_open_disposition.h"
19 #include "ui/gfx/native_widget_types.h"
22 class BrowserWindowTesting;
30 #if !defined(OS_MACOSX)
35 class PasswordGenerator;
40 struct NativeWebKeyboardEvent;
44 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 // Returns a pointer to the testing interface to the Browser window, or NULL
89 virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0;
91 // Return the status bubble associated with the frame
92 virtual StatusBubble* GetStatusBubble() = 0;
94 // Inform the frame that the selected tab favicon or title has changed. Some
95 // frames may need to refresh their title bar.
96 virtual void UpdateTitleBar() = 0;
98 // Invoked when the state of the bookmark bar changes. This is only invoked if
99 // the state changes for the current tab, it is not sent when switching tabs.
100 virtual void BookmarkBarStateChanged(
101 BookmarkBar::AnimateChangeType change_type) = 0;
103 // Inform the frame that the dev tools window for the selected tab has
105 virtual void UpdateDevTools() = 0;
107 // Update any loading animations running in the window. |should_animate| is
108 // true if there are tabs loading and the animations should continue, false
109 // if there are no active loads and the animations should end.
110 virtual void UpdateLoadingAnimations(bool should_animate) = 0;
112 // Sets the starred state for the current tab.
113 virtual void SetStarredState(bool is_starred) = 0;
115 // Called when the active tab changes. Subclasses which implement
116 // TabStripModelObserver should implement this instead of ActiveTabChanged();
117 // the Browser will call this method while processing that one.
118 virtual void OnActiveTabChanged(content::WebContents* old_contents,
119 content::WebContents* new_contents,
123 // Called to force the zoom state to for the active tab to be recalculated.
124 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
125 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
126 // + or - in the wrench menu to change zoom).
127 virtual void ZoomChangedForActiveTab(bool can_show_bubble) = 0;
129 // Accessors for fullscreen mode state.
130 virtual void EnterFullscreen(const GURL& url,
131 FullscreenExitBubbleType bubble_type) = 0;
132 virtual void ExitFullscreen() = 0;
133 virtual void UpdateFullscreenExitBubbleContent(
135 FullscreenExitBubbleType bubble_type) = 0;
137 // Windows and GTK remove the top controls in fullscreen, but Mac and Ash
138 // keep the controls in a slide-down panel.
139 virtual bool ShouldHideUIForFullscreen() const = 0;
141 // Returns true if the fullscreen bubble is visible.
142 virtual bool IsFullscreenBubbleVisible() const = 0;
145 // Sets state for entering or exiting Win8 Metro snap mode.
146 virtual void SetMetroSnapMode(bool enable) = 0;
148 // Returns whether the window is currently in Win8 Metro snap mode.
149 virtual bool IsInMetroSnapMode() const = 0;
152 // Returns the location bar.
153 virtual LocationBar* GetLocationBar() const = 0;
155 // Tries to focus the location bar. Clears the window focus (to avoid
156 // inconsistent state) if this fails.
157 virtual void SetFocusToLocationBar(bool select_all) = 0;
159 // Informs the view whether or not a load is in progress for the current tab.
160 // The view can use this notification to update the reload/stop button.
161 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
163 // Updates the toolbar with the state for the specified |contents|.
164 virtual void UpdateToolbar(content::WebContents* contents) = 0;
166 // Focuses the toolbar (for accessibility).
167 virtual void FocusToolbar() = 0;
169 // Focuses the app menu like it was a menu bar.
171 // Not used on the Mac, which has a "normal" menu bar.
172 virtual void FocusAppMenu() = 0;
174 // Focuses the bookmarks toolbar (for accessibility).
175 virtual void FocusBookmarksToolbar() = 0;
177 // Focuses an infobar, if shown (for accessibility).
178 virtual void FocusInfobars() = 0;
180 // Moves keyboard focus to the next pane.
181 virtual void RotatePaneFocus(bool forwards) = 0;
183 // Returns whether the bookmark bar is visible or not.
184 virtual bool IsBookmarkBarVisible() const = 0;
186 // Returns whether the bookmark bar is animating or not.
187 virtual bool IsBookmarkBarAnimating() const = 0;
189 // Returns whether the tab strip is editable (for extensions).
190 virtual bool IsTabStripEditable() const = 0;
192 // Returns whether the tool bar is visible or not.
193 virtual bool IsToolbarVisible() const = 0;
195 // Returns the rect where the resize corner should be drawn by the render
196 // widget host view (on top of what the renderer returns). We return an empty
197 // rect to identify that there shouldn't be a resize corner (in the cases
198 // where we take care of it ourselves at the browser level).
199 virtual gfx::Rect GetRootWindowResizerRect() const = 0;
201 // Tells the frame not to render as inactive until the next activation change.
202 // This is required on Windows when dropdown selects are shown to prevent the
203 // select from deactivating the browser frame. A stub implementation is
204 // provided here since the functionality is Windows-specific.
205 virtual void DisableInactiveFrame() {}
207 // Shows a confirmation dialog box for adding a search engine described by
208 // |template_url|. Takes ownership of |template_url|.
209 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
210 Profile* profile) = 0;
212 // Shows the Update Recommended dialog box.
213 virtual void ShowUpdateChromeDialog() = 0;
215 // Shows the Bookmark bubble. |url| is the URL being bookmarked,
216 // |already_bookmarked| is true if the url is already bookmarked.
217 virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0;
219 // Shows the bookmark prompt.
220 // TODO(yosin): Make ShowBookmarkPrompt pure virtual.
221 virtual void ShowBookmarkPrompt() {}
223 // Shows the translate bubble.
224 virtual void ShowTranslateBubble(
225 content::WebContents* contents,
226 TranslateBubbleModel::ViewState view_state) = 0;
228 #if defined(ENABLE_ONE_CLICK_SIGNIN)
229 enum OneClickSigninBubbleType {
230 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
231 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG,
232 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
235 // Callback type used with the ShowOneClickSigninBubble() method. If the
236 // user chooses to accept the sign in, the callback is called to start the
238 typedef base::Callback<void(OneClickSigninSyncStarter::StartSyncMode)>
241 // Shows the one-click sign in bubble. |email| holds the full email address
242 // of the account that has signed in.
243 virtual void ShowOneClickSigninBubble(
244 OneClickSigninBubbleType type,
245 const string16& email,
246 const string16& error_message,
247 const StartSyncCallback& start_sync_callback) = 0;
250 // Whether or not the shelf view is visible.
251 virtual bool IsDownloadShelfVisible() const = 0;
253 // Returns the DownloadShelf.
254 virtual DownloadShelf* GetDownloadShelf() = 0;
256 // Shows the confirmation dialog box warning that the browser is closing with
257 // in-progress downloads.
258 // This method should call |callback| with the user's response.
259 virtual void ConfirmBrowserCloseWithPendingDownloads(
261 Browser::DownloadClosePreventionType dialog_type,
263 const base::Callback<void(bool)>& callback) = 0;
265 // ThemeService calls this when a user has changed his or her theme,
266 // indicating that it's time to redraw everything.
267 virtual void UserChangedTheme() = 0;
269 // Get extra vertical height that the render view should add to its requests
270 // to webkit. This can help prevent sending extraneous layout/repaint requests
271 // when the delegate is in the process of resizing the tab contents view (e.g.
272 // during infobar animations).
273 virtual int GetExtraRenderViewHeight() const = 0;
275 // Notification that |contents| got the focus through user action (click
277 virtual void WebContentsFocused(content::WebContents* contents) = 0;
279 // Shows the website settings using the specified information. |url| is the
280 // url of the page/frame the info applies to, |ssl| is the SSL information for
281 // that page/frame. If |show_history| is true, a section showing how many
282 // times that URL has been visited is added to the page info.
283 virtual void ShowWebsiteSettings(Profile* profile,
284 content::WebContents* web_contents,
286 const content::SSLStatus& ssl) = 0;
288 // Shows the app menu (for accessibility).
289 virtual void ShowAppMenu() = 0;
291 // Allows the BrowserWindow object to handle the specified keyboard event
292 // before sending it to the renderer.
293 // Returns true if the |event| was handled. Otherwise, if the |event| would
294 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
295 // |*is_keyboard_shortcut| should be set to true.
296 virtual bool PreHandleKeyboardEvent(
297 const content::NativeWebKeyboardEvent& event,
298 bool* is_keyboard_shortcut) = 0;
300 // Allows the BrowserWindow object to handle the specified keyboard event,
301 // if the renderer did not process it.
302 virtual void HandleKeyboardEvent(
303 const content::NativeWebKeyboardEvent& event) = 0;
305 // Clipboard commands applied to the whole browser window.
306 virtual void Cut() = 0;
307 virtual void Copy() = 0;
308 virtual void Paste() = 0;
310 #if defined(OS_MACOSX)
311 // Opens the tabpose view.
312 virtual void OpenTabpose() = 0;
314 // Enters Mac specific fullscreen mode with chrome displayed (e.g. omnibox)
315 // on OSX 10.7+, a.k.a. Lion Fullscreen mode.
316 // Invalid to call on OSX earlier than 10.7.
317 // Enters either from non fullscreen, or from fullscreen without chrome.
318 // Exit to normal fullscreen with EnterFullscreen().
319 virtual void EnterFullscreenWithChrome() = 0;
320 virtual bool IsFullscreenWithChrome() = 0;
321 virtual bool IsFullscreenWithoutChrome() = 0;
324 // Return the correct disposition for a popup window based on |bounds|.
325 virtual WindowOpenDisposition GetDispositionForPopupBounds(
326 const gfx::Rect& bounds) = 0;
328 // Construct a FindBar implementation for the |browser|.
329 virtual FindBar* CreateFindBar() = 0;
331 // Return the WebContentsModalDialogHost for use in positioning web contents
332 // modal dialogs within the browser window. This can sometimes be NULL (for
333 // instance during tab drag on Views/Win32).
334 virtual web_modal::WebContentsModalDialogHost*
335 GetWebContentsModalDialogHost() = 0;
337 // Invoked when the preferred size of the contents in current tab has been
338 // changed. We might choose to update the window size to accomodate this
340 // Note that this won't be fired if we change tabs.
341 virtual void UpdatePreferredSize(content::WebContents* web_contents,
342 const gfx::Size& pref_size) {}
344 // Invoked when the contents auto-resized and the container should match it.
345 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
346 const gfx::Size& new_size) {}
348 // Construct a BrowserWindow implementation for the specified |browser|.
349 static BrowserWindow* CreateBrowserWindow(Browser* browser);
351 // Shows the avatar bubble inside |web_contents|. The bubble is positioned
352 // relative to |rect|. |rect| should be in the |web_contents| coordinate
354 virtual void ShowAvatarBubble(content::WebContents* web_contents,
355 const gfx::Rect& rect) = 0;
357 // Shows the avatar bubble on the window frame off of the avatar button.
358 virtual void ShowAvatarBubbleFromAvatarButton() = 0;
360 // Show bubble for password generation positioned relative to |rect|. The
361 // subclasses implementing this interface do not own the |password_generator|
362 // object which is passed to generate the password. |form| is the form that
363 // contains the password field that the bubble will be associated with.
364 virtual void ShowPasswordGenerationBubble(
365 const gfx::Rect& rect,
366 const autofill::PasswordForm& form,
367 autofill::PasswordGenerator* password_generator) = 0;
369 // Invoked when the amount of vertical overscroll changes. |delta_y| is the
370 // amount of overscroll that has occured in the y-direction.
371 virtual void OverscrollUpdate(int delta_y) {}
373 // Returns the height inset for RenderView when detached bookmark bar is
374 // shown. Invoked when a new RenderHostView is created for a non-NTP
375 // navigation entry and the bookmark bar is detached.
376 virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
379 friend class BrowserCloseManager;
380 friend class BrowserView;
381 virtual void DestroyBrowser() = 0;
384 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
385 class BookmarkBarView;
386 class LocationBarView;
391 #endif // defined(OS_WIN)
393 // A BrowserWindow utility interface used for accessing elements of the browser
394 // UI used only by UI test automation.
395 class BrowserWindowTesting {
397 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
398 // Returns the BookmarkBarView.
399 virtual BookmarkBarView* GetBookmarkBarView() const = 0;
401 // Returns the LocationBarView.
402 virtual LocationBarView* GetLocationBarView() const = 0;
404 // Returns the TabContentsContainer.
405 virtual views::View* GetTabContentsContainerView() const = 0;
407 // Returns the ToolbarView.
408 virtual ToolbarView* GetToolbarView() const = 0;
412 virtual ~BrowserWindowTesting() {}
415 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_