NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / browser_window.h
blob3e2766bd177138e9d6e9bad459dae2ca1ce0ea47
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 Extension;
51 namespace gfx {
52 class Rect;
53 class Size;
56 namespace web_modal {
57 class WebContentsModalDialogHost;
60 ////////////////////////////////////////////////////////////////////////////////
61 // BrowserWindow interface
62 // An interface implemented by the "view" of the Browser window.
63 // This interface includes ui::BaseWindow methods as well as Browser window
64 // specific methods.
66 // NOTE: All getters may return NULL.
68 class BrowserWindow : public ui::BaseWindow {
69 public:
70 virtual ~BrowserWindow() {}
72 //////////////////////////////////////////////////////////////////////////////
73 // ui::BaseWindow interface notes:
75 // Closes the window as soon as possible. If the window is not in a drag
76 // session, it will close immediately; otherwise, it will move offscreen (so
77 // events are still fired) until the drag ends, then close. This assumes
78 // that the Browser is not immediately destroyed, but will be eventually
79 // destroyed by other means (eg, the tab strip going to zero elements).
80 // Bad things happen if the Browser dtor is called directly as a result of
81 // invoking this method.
82 // virtual void Close() = 0;
84 // Browser::OnWindowDidShow should be called after showing the window.
85 // virtual void Show() = 0;
87 //////////////////////////////////////////////////////////////////////////////
88 // Browser specific methods:
90 // Returns a pointer to the testing interface to the Browser window, or NULL
91 // if there is none.
92 virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0;
94 // Return the status bubble associated with the frame
95 virtual StatusBubble* GetStatusBubble() = 0;
97 // Inform the frame that the selected tab favicon or title has changed. Some
98 // frames may need to refresh their title bar.
99 virtual void UpdateTitleBar() = 0;
101 // Invoked when the state of the bookmark bar changes. This is only invoked if
102 // the state changes for the current tab, it is not sent when switching tabs.
103 virtual void BookmarkBarStateChanged(
104 BookmarkBar::AnimateChangeType change_type) = 0;
106 // Inform the frame that the dev tools window for the selected tab has
107 // changed.
108 virtual void UpdateDevTools() = 0;
110 // Update any loading animations running in the window. |should_animate| is
111 // true if there are tabs loading and the animations should continue, false
112 // if there are no active loads and the animations should end.
113 virtual void UpdateLoadingAnimations(bool should_animate) = 0;
115 // Sets the starred state for the current tab.
116 virtual void SetStarredState(bool is_starred) = 0;
118 // Sets whether the translate icon is lit for the current tab.
119 virtual void SetTranslateIconToggled(bool is_lit) = 0;
121 // Called when the active tab changes. Subclasses which implement
122 // TabStripModelObserver should implement this instead of ActiveTabChanged();
123 // the Browser will call this method while processing that one.
124 virtual void OnActiveTabChanged(content::WebContents* old_contents,
125 content::WebContents* new_contents,
126 int index,
127 int reason) = 0;
129 // Called to force the zoom state to for the active tab to be recalculated.
130 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
131 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
132 // + or - in the wrench menu to change zoom).
133 virtual void ZoomChangedForActiveTab(bool can_show_bubble) = 0;
135 // Accessors for fullscreen mode state.
136 virtual void EnterFullscreen(const GURL& url,
137 FullscreenExitBubbleType bubble_type) = 0;
138 virtual void ExitFullscreen() = 0;
139 virtual void UpdateFullscreenExitBubbleContent(
140 const GURL& url,
141 FullscreenExitBubbleType bubble_type) = 0;
143 // Windows and GTK remove the top controls in fullscreen, but Mac and Ash
144 // keep the controls in a slide-down panel.
145 virtual bool ShouldHideUIForFullscreen() const = 0;
147 // Returns true if the fullscreen bubble is visible.
148 virtual bool IsFullscreenBubbleVisible() const = 0;
150 #if defined(OS_WIN)
151 // Sets state for entering or exiting Win8 Metro snap mode.
152 virtual void SetMetroSnapMode(bool enable) = 0;
154 // Returns whether the window is currently in Win8 Metro snap mode.
155 virtual bool IsInMetroSnapMode() const = 0;
156 #endif
158 // Returns the location bar.
159 virtual LocationBar* GetLocationBar() const = 0;
161 // Tries to focus the location bar. Clears the window focus (to avoid
162 // inconsistent state) if this fails.
163 virtual void SetFocusToLocationBar(bool select_all) = 0;
165 // Informs the view whether or not a load is in progress for the current tab.
166 // The view can use this notification to update the reload/stop button.
167 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
169 // Updates the toolbar with the state for the specified |contents|.
170 virtual void UpdateToolbar(content::WebContents* contents) = 0;
172 // Focuses the toolbar (for accessibility).
173 virtual void FocusToolbar() = 0;
175 // Focuses the app menu like it was a menu bar.
177 // Not used on the Mac, which has a "normal" menu bar.
178 virtual void FocusAppMenu() = 0;
180 // Focuses the bookmarks toolbar (for accessibility).
181 virtual void FocusBookmarksToolbar() = 0;
183 // Focuses an infobar, if shown (for accessibility).
184 virtual void FocusInfobars() = 0;
186 // Moves keyboard focus to the next pane.
187 virtual void RotatePaneFocus(bool forwards) = 0;
189 // Returns whether the bookmark bar is visible or not.
190 virtual bool IsBookmarkBarVisible() const = 0;
192 // Returns whether the bookmark bar is animating or not.
193 virtual bool IsBookmarkBarAnimating() const = 0;
195 // Returns whether the tab strip is editable (for extensions).
196 virtual bool IsTabStripEditable() const = 0;
198 // Returns whether the tool bar is visible or not.
199 virtual bool IsToolbarVisible() const = 0;
201 // Returns the rect where the resize corner should be drawn by the render
202 // widget host view (on top of what the renderer returns). We return an empty
203 // rect to identify that there shouldn't be a resize corner (in the cases
204 // where we take care of it ourselves at the browser level).
205 virtual gfx::Rect GetRootWindowResizerRect() const = 0;
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 App bubble.
220 // See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of
221 // bookmark apps.
223 // |web_app_info| is the WebApplicationInfo being converted into an app.
224 // |extension_id| is the id of the bookmark app.
225 virtual void ShowBookmarkAppBubble(const WebApplicationInfo& web_app_info,
226 const std::string& extension_id) = 0;
228 // Shows the bookmark prompt.
229 // TODO(yosin): Make ShowBookmarkPrompt pure virtual.
230 virtual void ShowBookmarkPrompt() {}
232 // Shows the translate bubble.
233 virtual void ShowTranslateBubble(content::WebContents* contents,
234 TranslateTabHelper::TranslateStep step,
235 TranslateErrors::Type error_type) = 0;
237 #if defined(ENABLE_ONE_CLICK_SIGNIN)
238 enum OneClickSigninBubbleType {
239 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
240 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG,
241 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
244 // Callback type used with the ShowOneClickSigninBubble() method. If the
245 // user chooses to accept the sign in, the callback is called to start the
246 // sync process.
247 typedef base::Callback<void(OneClickSigninSyncStarter::StartSyncMode)>
248 StartSyncCallback;
250 // Shows the one-click sign in bubble. |email| holds the full email address
251 // of the account that has signed in.
252 virtual void ShowOneClickSigninBubble(
253 OneClickSigninBubbleType type,
254 const base::string16& email,
255 const base::string16& error_message,
256 const StartSyncCallback& start_sync_callback) = 0;
257 #endif
259 // Whether or not the shelf view is visible.
260 virtual bool IsDownloadShelfVisible() const = 0;
262 // Returns the DownloadShelf.
263 virtual DownloadShelf* GetDownloadShelf() = 0;
265 // Shows the confirmation dialog box warning that the browser is closing with
266 // in-progress downloads.
267 // This method should call |callback| with the user's response.
268 virtual void ConfirmBrowserCloseWithPendingDownloads(
269 int download_count,
270 Browser::DownloadClosePreventionType dialog_type,
271 bool app_modal,
272 const base::Callback<void(bool)>& callback) = 0;
274 // ThemeService calls this when a user has changed his or her theme,
275 // indicating that it's time to redraw everything.
276 virtual void UserChangedTheme() = 0;
278 // Get extra vertical height that the render view should add to its requests
279 // to webkit. This can help prevent sending extraneous layout/repaint requests
280 // when the delegate is in the process of resizing the tab contents view (e.g.
281 // during infobar animations).
282 virtual int GetExtraRenderViewHeight() const = 0;
284 // Notification that |contents| got the focus through user action (click
285 // on the page).
286 virtual void WebContentsFocused(content::WebContents* contents) = 0;
288 // Shows the website settings using the specified information. |url| is the
289 // url of the page/frame the info applies to, |ssl| is the SSL information for
290 // that page/frame. If |show_history| is true, a section showing how many
291 // times that URL has been visited is added to the page info.
292 virtual void ShowWebsiteSettings(Profile* profile,
293 content::WebContents* web_contents,
294 const GURL& url,
295 const content::SSLStatus& ssl) = 0;
297 // Shows the app menu (for accessibility).
298 virtual void ShowAppMenu() = 0;
300 // Allows the BrowserWindow object to handle the specified keyboard event
301 // before sending it to the renderer.
302 // Returns true if the |event| was handled. Otherwise, if the |event| would
303 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
304 // |*is_keyboard_shortcut| should be set to true.
305 virtual bool PreHandleKeyboardEvent(
306 const content::NativeWebKeyboardEvent& event,
307 bool* is_keyboard_shortcut) = 0;
309 // Allows the BrowserWindow object to handle the specified keyboard event,
310 // if the renderer did not process it.
311 virtual void HandleKeyboardEvent(
312 const content::NativeWebKeyboardEvent& event) = 0;
314 // Clipboard commands applied to the whole browser window.
315 virtual void Cut() = 0;
316 virtual void Copy() = 0;
317 virtual void Paste() = 0;
319 #if defined(OS_MACOSX)
320 // Enters Mac specific fullscreen mode with chrome displayed (e.g. omnibox)
321 // on OSX 10.7+, a.k.a. Lion Fullscreen mode.
322 // Invalid to call on OSX earlier than 10.7.
323 // Enters either from non fullscreen, or from fullscreen without chrome.
324 // Exit to normal fullscreen with EnterFullscreen().
325 virtual void EnterFullscreenWithChrome() = 0;
326 virtual bool IsFullscreenWithChrome() = 0;
327 virtual bool IsFullscreenWithoutChrome() = 0;
328 #endif
330 // Return the correct disposition for a popup window based on |bounds|.
331 virtual WindowOpenDisposition GetDispositionForPopupBounds(
332 const gfx::Rect& bounds) = 0;
334 // Construct a FindBar implementation for the |browser|.
335 virtual FindBar* CreateFindBar() = 0;
337 // Return the WebContentsModalDialogHost for use in positioning web contents
338 // modal dialogs within the browser window. This can sometimes be NULL (for
339 // instance during tab drag on Views/Win32).
340 virtual web_modal::WebContentsModalDialogHost*
341 GetWebContentsModalDialogHost() = 0;
343 // Invoked when the preferred size of the contents in current tab has been
344 // changed. We might choose to update the window size to accomodate this
345 // change.
346 // Note that this won't be fired if we change tabs.
347 virtual void UpdatePreferredSize(content::WebContents* web_contents,
348 const gfx::Size& pref_size) {}
350 // Invoked when the contents auto-resized and the container should match it.
351 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
352 const gfx::Size& new_size) {}
354 // Construct a BrowserWindow implementation for the specified |browser|.
355 static BrowserWindow* CreateBrowserWindow(Browser* browser);
357 // Returns a HostDesktopType that is compatible with the current Chrome window
358 // configuration. On Windows with Ash, this is always HOST_DESKTOP_TYPE_ASH
359 // while Chrome is running in Metro mode. Otherwise returns |desktop_type|.
360 static chrome::HostDesktopType AdjustHostDesktopType(
361 chrome::HostDesktopType desktop_type);
363 // Shows the avatar bubble inside |web_contents|. The bubble is positioned
364 // relative to |rect|. |rect| should be in the |web_contents| coordinate
365 // system.
366 virtual void ShowAvatarBubble(content::WebContents* web_contents,
367 const gfx::Rect& rect) = 0;
369 // Shows the avatar bubble on the window frame off of the avatar button.
370 virtual void ShowAvatarBubbleFromAvatarButton() = 0;
372 // Show bubble for password generation positioned relative to |rect|. The
373 // subclasses implementing this interface do not own the |password_generator|
374 // object which is passed to generate the password. |form| is the form that
375 // contains the password field that the bubble will be associated with.
376 virtual void ShowPasswordGenerationBubble(
377 const gfx::Rect& rect,
378 const autofill::PasswordForm& form,
379 autofill::PasswordGenerator* password_generator) = 0;
381 // Invoked when the amount of vertical overscroll changes. |delta_y| is the
382 // amount of overscroll that has occured in the y-direction.
383 virtual void OverscrollUpdate(int delta_y) {}
385 // Returns the height inset for RenderView when detached bookmark bar is
386 // shown. Invoked when a new RenderHostView is created for a non-NTP
387 // navigation entry and the bookmark bar is detached.
388 virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
390 protected:
391 friend class BrowserCloseManager;
392 friend class BrowserView;
393 virtual void DestroyBrowser() = 0;
396 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
397 class BookmarkBarView;
398 class LocationBarView;
400 namespace views {
401 class View;
403 #endif // defined(OS_WIN)
405 // A BrowserWindow utility interface used for accessing elements of the browser
406 // UI used only by UI test automation.
407 class BrowserWindowTesting {
408 public:
409 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
410 // Returns the BookmarkBarView.
411 virtual BookmarkBarView* GetBookmarkBarView() const = 0;
413 // Returns the LocationBarView.
414 virtual LocationBarView* GetLocationBarView() const = 0;
416 // Returns the TabContentsContainer.
417 virtual views::View* GetTabContentsContainerView() const = 0;
419 // Returns the ToolbarView.
420 virtual ToolbarView* GetToolbarView() const = 0;
421 #endif
423 protected:
424 virtual ~BrowserWindowTesting() {}
427 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_