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/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 "chrome/common/translate/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" 21 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 34 35 namespace autofill { 36 class PasswordGenerator; 37 struct PasswordForm; 38 } 39 namespace content { 40 class WebContents; 41 struct NativeWebKeyboardEvent; 42 struct SSLStatus; 43 } 44 45 namespace extensions { 46 class Extension; 47 } 48 49 namespace gfx { 50 class Rect; 51 class Size; 52 } 53 54 namespace web_modal { 55 class WebContentsModalDialogHost; 56 } 57 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 62 // specific methods. 63 // 64 // NOTE: All getters may return NULL. 65 // 66 class BrowserWindow : public ui::BaseWindow { 67 public: 68 virtual ~BrowserWindow() {} 69 70 ////////////////////////////////////////////////////////////////////////////// 71 // ui::BaseWindow interface notes: 72 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; 81 82 // Browser::OnWindowDidShow should be called after showing the window. 83 // virtual void Show() = 0; 84 85 ////////////////////////////////////////////////////////////////////////////// 86 // Browser specific methods: 87 88 // Returns a pointer to the testing interface to the Browser window, or NULL 89 // if there is none. 90 virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0; 91 92 // Return the status bubble associated with the frame 93 virtual StatusBubble* GetStatusBubble() = 0; 94 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; 98 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; 103 104 // Inform the frame that the dev tools window for the selected tab has 105 // changed. 106 virtual void UpdateDevTools() = 0; 107 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; 112 113 // Sets the starred state for the current tab. 114 virtual void SetStarredState(bool is_starred) = 0; 115 116 // Sets whether the translate icon is lit for the current tab. 117 virtual void SetTranslateIconToggled(bool is_lit) = 0; 118 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, 124 int index, 125 int reason) = 0; 126 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; 132 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( 138 const GURL& url, 139 FullscreenExitBubbleType bubble_type) = 0; 140 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; 144 145 // Returns true if the fullscreen bubble is visible. 146 virtual bool IsFullscreenBubbleVisible() const = 0; 147 148 #if defined(OS_WIN) 149 // Sets state for entering or exiting Win8 Metro snap mode. 150 virtual void SetMetroSnapMode(bool enable) = 0; 151 152 // Returns whether the window is currently in Win8 Metro snap mode. 153 virtual bool IsInMetroSnapMode() const = 0; 154 #endif 155 156 // Returns the location bar. 157 virtual LocationBar* GetLocationBar() const = 0; 158 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; 162 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; 166 167 // Updates the toolbar with the state for the specified |contents|. 168 virtual void UpdateToolbar(content::WebContents* contents) = 0; 169 170 // Focuses the toolbar (for accessibility). 171 virtual void FocusToolbar() = 0; 172 173 // Focuses the app menu like it was a menu bar. 174 // 175 // Not used on the Mac, which has a "normal" menu bar. 176 virtual void FocusAppMenu() = 0; 177 178 // Focuses the bookmarks toolbar (for accessibility). 179 virtual void FocusBookmarksToolbar() = 0; 180 181 // Focuses an infobar, if shown (for accessibility). 182 virtual void FocusInfobars() = 0; 183 184 // Moves keyboard focus to the next pane. 185 virtual void RotatePaneFocus(bool forwards) = 0; 186 187 // Returns whether the bookmark bar is visible or not. 188 virtual bool IsBookmarkBarVisible() const = 0; 189 190 // Returns whether the bookmark bar is animating or not. 191 virtual bool IsBookmarkBarAnimating() const = 0; 192 193 // Returns whether the tab strip is editable (for extensions). 194 virtual bool IsTabStripEditable() const = 0; 195 196 // Returns whether the tool bar is visible or not. 197 virtual bool IsToolbarVisible() const = 0; 198 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; 204 205 // Tells the frame not to render as inactive until the next activation change. 206 // This is required on Windows when dropdown selects are shown to prevent the 207 // select from deactivating the browser frame. A stub implementation is 208 // provided here since the functionality is Windows-specific. 209 virtual void DisableInactiveFrame() {} 210 211 // Shows a confirmation dialog box for adding a search engine described by 212 // |template_url|. Takes ownership of |template_url|. 213 virtual void ConfirmAddSearchProvider(TemplateURL* template_url, 214 Profile* profile) = 0; 215 216 // Shows the Update Recommended dialog box. 217 virtual void ShowUpdateChromeDialog() = 0; 218 219 // Shows the Bookmark bubble. |url| is the URL being bookmarked, 220 // |already_bookmarked| is true if the url is already bookmarked. 221 virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0; 222 223 // Shows the bookmark prompt. 224 // TODO(yosin): Make ShowBookmarkPrompt pure virtual. 225 virtual void ShowBookmarkPrompt() {} 226 227 // Shows the translate bubble. 228 virtual void ShowTranslateBubble( 229 content::WebContents* contents, 230 TranslateBubbleModel::ViewState view_state, 231 TranslateErrors::Type error_type) = 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 // Opens the tabpose view. 317 virtual void OpenTabpose() = 0; 318 319 // Enters Mac specific fullscreen mode with chrome displayed (e.g. omnibox) 320 // on OSX 10.7+, a.k.a. Lion Fullscreen mode. 321 // Invalid to call on OSX earlier than 10.7. 322 // Enters either from non fullscreen, or from fullscreen without chrome. 323 // Exit to normal fullscreen with EnterFullscreen(). 324 virtual void EnterFullscreenWithChrome() = 0; 325 virtual bool IsFullscreenWithChrome() = 0; 326 virtual bool IsFullscreenWithoutChrome() = 0; 327 #endif 328 329 // Return the correct disposition for a popup window based on |bounds|. 330 virtual WindowOpenDisposition GetDispositionForPopupBounds( 331 const gfx::Rect& bounds) = 0; 332 333 // Construct a FindBar implementation for the |browser|. 334 virtual FindBar* CreateFindBar() = 0; 335 336 // Return the WebContentsModalDialogHost for use in positioning web contents 337 // modal dialogs within the browser window. This can sometimes be NULL (for 338 // instance during tab drag on Views/Win32). 339 virtual web_modal::WebContentsModalDialogHost* 340 GetWebContentsModalDialogHost() = 0; 341 342 // Invoked when the preferred size of the contents in current tab has been 343 // changed. We might choose to update the window size to accomodate this 344 // change. 345 // Note that this won't be fired if we change tabs. 346 virtual void UpdatePreferredSize(content::WebContents* web_contents, 347 const gfx::Size& pref_size) {} 348 349 // Invoked when the contents auto-resized and the container should match it. 350 virtual void ResizeDueToAutoResize(content::WebContents* web_contents, 351 const gfx::Size& new_size) {} 352 353 // Construct a BrowserWindow implementation for the specified |browser|. 354 static BrowserWindow* CreateBrowserWindow(Browser* browser); 355 356 // Returns a HostDesktopType that is compatible with the current Chrome window 357 // configuration. On Windows with Ash, this is always HOST_DESKTOP_TYPE_ASH 358 // while Chrome is running in Metro mode. Otherwise returns |desktop_type|. 359 static chrome::HostDesktopType AdjustHostDesktopType( 360 chrome::HostDesktopType desktop_type); 361 362 // Shows the avatar bubble inside |web_contents|. The bubble is positioned 363 // relative to |rect|. |rect| should be in the |web_contents| coordinate 364 // system. 365 virtual void ShowAvatarBubble(content::WebContents* web_contents, 366 const gfx::Rect& rect) = 0; 367 368 // Shows the avatar bubble on the window frame off of the avatar button. 369 virtual void ShowAvatarBubbleFromAvatarButton() = 0; 370 371 // Show bubble for password generation positioned relative to |rect|. The 372 // subclasses implementing this interface do not own the |password_generator| 373 // object which is passed to generate the password. |form| is the form that 374 // contains the password field that the bubble will be associated with. 375 virtual void ShowPasswordGenerationBubble( 376 const gfx::Rect& rect, 377 const autofill::PasswordForm& form, 378 autofill::PasswordGenerator* password_generator) = 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. 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 protected: 390 friend class BrowserCloseManager; 391 friend class BrowserView; 392 virtual void DestroyBrowser() = 0; 393 }; 394 395 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) 396 class BookmarkBarView; 397 class LocationBarView; 398 399 namespace views { 400 class View; 401 } 402 #endif // defined(OS_WIN) 403 404 // A BrowserWindow utility interface used for accessing elements of the browser 405 // UI used only by UI test automation. 406 class BrowserWindowTesting { 407 public: 408 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) 409 // Returns the BookmarkBarView. 410 virtual BookmarkBarView* GetBookmarkBarView() const = 0; 411 412 // Returns the LocationBarView. 413 virtual LocationBarView* GetLocationBarView() const = 0; 414 415 // Returns the TabContentsContainer. 416 virtual views::View* GetTabContentsContainerView() const = 0; 417 418 // Returns the ToolbarView. 419 virtual ToolbarView* GetToolbarView() const = 0; 420 #endif 421 422 protected: 423 virtual ~BrowserWindowTesting() {} 424 }; 425 426 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_ 427