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