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