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/application_lifetime.h" 10 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" 11 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h" 12 #include "chrome/browser/ui/host_desktop.h" 13 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" 14 #include "chrome/common/content_settings_types.h" 15 #include "ui/base/base_window.h" 16 #include "ui/base/window_open_disposition.h" 17 #include "ui/gfx/native_widget_types.h" 18 19 class Browser; 20 class BrowserWindowTesting; 21 class DownloadShelf; 22 class FindBar; 23 class GURL; 24 class LocationBar; 25 class Profile; 26 class StatusBubble; 27 class TemplateURL; 28 #if !defined(OS_MACOSX) 29 class ToolbarView; 30 #endif 31 32 namespace autofill { 33 class PasswordGenerator; 34 } 35 namespace content { 36 class WebContents; 37 struct NativeWebKeyboardEvent; 38 struct PasswordForm; 39 struct SSLStatus; 40 } 41 42 namespace extensions { 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: 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 // Called to force the zoom state to for the active tab to be recalculated. 114 // |can_show_bubble| is true when a user presses the zoom up or down keyboard 115 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking" 116 // + or - in the wrench menu to change zoom). 117 virtual void ZoomChangedForActiveTab(bool can_show_bubble) = 0; 118 119 // Accessors for fullscreen mode state. 120 virtual void EnterFullscreen(const GURL& url, 121 FullscreenExitBubbleType bubble_type) = 0; 122 virtual void ExitFullscreen() = 0; 123 virtual void UpdateFullscreenExitBubbleContent( 124 const GURL& url, 125 FullscreenExitBubbleType bubble_type) = 0; 126 127 // Windows and GTK remove the top controls in fullscreen, but Mac and Ash 128 // keep the controls in a slide-down panel. 129 virtual bool ShouldHideUIForFullscreen() const = 0; 130 131 // Returns true if the fullscreen bubble is visible. 132 virtual bool IsFullscreenBubbleVisible() const = 0; 133 134 #if defined(OS_WIN) 135 // Sets state for entering or exiting Win8 Metro snap mode. 136 virtual void SetMetroSnapMode(bool enable) = 0; 137 138 // Returns whether the window is currently in Win8 Metro snap mode. 139 virtual bool IsInMetroSnapMode() const = 0; 140 #endif 141 142 // Returns the location bar. 143 virtual LocationBar* GetLocationBar() const = 0; 144 145 // Tries to focus the location bar. Clears the window focus (to avoid 146 // inconsistent state) if this fails. 147 virtual void SetFocusToLocationBar(bool select_all) = 0; 148 149 // Informs the view whether or not a load is in progress for the current tab. 150 // The view can use this notification to update the reload/stop button. 151 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0; 152 153 // Updates the toolbar with the state for the specified |contents|. 154 virtual void UpdateToolbar(content::WebContents* contents, 155 bool should_restore_state) = 0; 156 157 // Focuses the toolbar (for accessibility). 158 virtual void FocusToolbar() = 0; 159 160 // Focuses the app menu like it was a menu bar. 161 // 162 // Not used on the Mac, which has a "normal" menu bar. 163 virtual void FocusAppMenu() = 0; 164 165 // Focuses the bookmarks toolbar (for accessibility). 166 virtual void FocusBookmarksToolbar() = 0; 167 168 // Focuses an infobar, if shown (for accessibility). 169 virtual void FocusInfobars() = 0; 170 171 // Moves keyboard focus to the next pane. 172 virtual void RotatePaneFocus(bool forwards) = 0; 173 174 // Returns whether the bookmark bar is visible or not. 175 virtual bool IsBookmarkBarVisible() const = 0; 176 177 // Returns whether the bookmark bar is animating or not. 178 virtual bool IsBookmarkBarAnimating() const = 0; 179 180 // Returns whether the tab strip is editable (for extensions). 181 virtual bool IsTabStripEditable() const = 0; 182 183 // Returns whether the tool bar is visible or not. 184 virtual bool IsToolbarVisible() const = 0; 185 186 // Returns the rect where the resize corner should be drawn by the render 187 // widget host view (on top of what the renderer returns). We return an empty 188 // rect to identify that there shouldn't be a resize corner (in the cases 189 // where we take care of it ourselves at the browser level). 190 virtual gfx::Rect GetRootWindowResizerRect() const = 0; 191 192 // Tells the frame not to render as inactive until the next activation change. 193 // This is required on Windows when dropdown selects are shown to prevent the 194 // select from deactivating the browser frame. A stub implementation is 195 // provided here since the functionality is Windows-specific. 196 virtual void DisableInactiveFrame() {} 197 198 // Shows a confirmation dialog box for adding a search engine described by 199 // |template_url|. Takes ownership of |template_url|. 200 virtual void ConfirmAddSearchProvider(TemplateURL* template_url, 201 Profile* profile) = 0; 202 203 // Shows or hides the bookmark bar depending on its current visibility. 204 virtual void ToggleBookmarkBar() = 0; 205 206 // Shows the Update Recommended dialog box. 207 virtual void ShowUpdateChromeDialog() = 0; 208 209 // Shows the Bookmark bubble. |url| is the URL being bookmarked, 210 // |already_bookmarked| is true if the url is already bookmarked. 211 virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0; 212 213 // Shows the bookmark prompt. 214 // TODO(yosin): Make ShowBookmarkPrompt pure virtual. 215 virtual void ShowBookmarkPrompt() {} 216 217 #if defined(ENABLE_ONE_CLICK_SIGNIN) 218 enum OneClickSigninBubbleType { 219 ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, 220 ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG, 221 ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG 222 }; 223 224 // Callback type used with the ShowOneClickSigninBubble() method. If the 225 // user chooses to accept the sign in, the callback is called to start the 226 // sync process. 227 typedef base::Callback<void(OneClickSigninSyncStarter::StartSyncMode)> 228 StartSyncCallback; 229 230 // Shows the one-click sign in bubble. |email| holds the full email address 231 // of the account that has signed in. 232 virtual void ShowOneClickSigninBubble( 233 OneClickSigninBubbleType type, 234 const string16& email, 235 const string16& error_message, 236 const StartSyncCallback& start_sync_callback) = 0; 237 #endif 238 239 // Whether or not the shelf view is visible. 240 virtual bool IsDownloadShelfVisible() const = 0; 241 242 // Returns the DownloadShelf. 243 virtual DownloadShelf* GetDownloadShelf() = 0; 244 245 // Shows the confirmation dialog box warning that the browser is closing with 246 // in-progress downloads. 247 // This method should call Browser::InProgressDownloadResponse once the user 248 // has confirmed. 249 virtual void ConfirmBrowserCloseWithPendingDownloads() = 0; 250 251 // ThemeService calls this when a user has changed his or her theme, 252 // indicating that it's time to redraw everything. 253 virtual void UserChangedTheme() = 0; 254 255 // Get extra vertical height that the render view should add to its requests 256 // to webkit. This can help prevent sending extraneous layout/repaint requests 257 // when the delegate is in the process of resizing the tab contents view (e.g. 258 // during infobar animations). 259 virtual int GetExtraRenderViewHeight() const = 0; 260 261 // Notification that |contents| got the focus through user action (click 262 // on the page). 263 virtual void WebContentsFocused(content::WebContents* contents) = 0; 264 265 // Shows the website settings using the specified information. |url| is the 266 // url of the page/frame the info applies to, |ssl| is the SSL information for 267 // that page/frame. If |show_history| is true, a section showing how many 268 // times that URL has been visited is added to the page info. 269 virtual void ShowWebsiteSettings(Profile* profile, 270 content::WebContents* web_contents, 271 const GURL& url, 272 const content::SSLStatus& ssl) = 0; 273 274 // Shows the app menu (for accessibility). 275 virtual void ShowAppMenu() = 0; 276 277 // Allows the BrowserWindow object to handle the specified keyboard event 278 // before sending it to the renderer. 279 // Returns true if the |event| was handled. Otherwise, if the |event| would 280 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut, 281 // |*is_keyboard_shortcut| should be set to true. 282 virtual bool PreHandleKeyboardEvent( 283 const content::NativeWebKeyboardEvent& event, 284 bool* is_keyboard_shortcut) = 0; 285 286 // Allows the BrowserWindow object to handle the specified keyboard event, 287 // if the renderer did not process it. 288 virtual void HandleKeyboardEvent( 289 const content::NativeWebKeyboardEvent& event) = 0; 290 291 // Shows the create chrome app shortcut dialog box. 292 virtual void ShowCreateChromeAppShortcutsDialog(Profile* profile, 293 const extensions::Extension* app) = 0; 294 295 // Clipboard commands applied to the whole browser window. 296 virtual void Cut() = 0; 297 virtual void Copy() = 0; 298 virtual void Paste() = 0; 299 300 #if defined(OS_MACOSX) 301 // Opens the tabpose view. 302 virtual void OpenTabpose() = 0; 303 304 // Enters Mac specific fullscreen mode with chrome displayed (e.g. omnibox) 305 // on OSX 10.7+, a.k.a. Lion Fullscreen mode. 306 // Invalid to call on OSX earlier than 10.7. 307 // Enters either from non fullscreen, or from fullscreen without chrome. 308 // Exit to normal fullscreen with EnterFullscreen(). 309 virtual void EnterFullscreenWithChrome() = 0; 310 virtual bool IsFullscreenWithChrome() = 0; 311 virtual bool IsFullscreenWithoutChrome() = 0; 312 #endif 313 314 // Return the correct disposition for a popup window based on |bounds|. 315 virtual WindowOpenDisposition GetDispositionForPopupBounds( 316 const gfx::Rect& bounds) = 0; 317 318 // Construct a FindBar implementation for the |browser|. 319 virtual FindBar* CreateFindBar() = 0; 320 321 // Return the WebContentsModalDialogHost for use in positioning web contents 322 // modal dialogs within the browser window. 323 virtual web_modal::WebContentsModalDialogHost* 324 GetWebContentsModalDialogHost() = 0; 325 326 // Invoked when the preferred size of the contents in current tab has been 327 // changed. We might choose to update the window size to accomodate this 328 // change. 329 // Note that this won't be fired if we change tabs. 330 virtual void UpdatePreferredSize(content::WebContents* web_contents, 331 const gfx::Size& pref_size) {} 332 333 // Invoked when the contents auto-resized and the container should match it. 334 virtual void ResizeDueToAutoResize(content::WebContents* web_contents, 335 const gfx::Size& new_size) {} 336 337 // Construct a BrowserWindow implementation for the specified |browser|. 338 static BrowserWindow* CreateBrowserWindow(Browser* browser); 339 340 // Shows the avatar bubble inside |web_contents|. The bubble is positioned 341 // relative to |rect|. |rect| should be in the |web_contents| coordinate 342 // system. 343 virtual void ShowAvatarBubble(content::WebContents* web_contents, 344 const gfx::Rect& rect) = 0; 345 346 // Shows the avatar bubble on the window frame off of the avatar button. 347 virtual void ShowAvatarBubbleFromAvatarButton() = 0; 348 349 // Show bubble for password generation positioned relative to |rect|. The 350 // subclasses implementing this interface do not own the |password_generator| 351 // object which is passed to generate the password. |form| is the form that 352 // contains the password field that the bubble will be associated with. 353 virtual void ShowPasswordGenerationBubble( 354 const gfx::Rect& rect, 355 const content::PasswordForm& form, 356 autofill::PasswordGenerator* password_generator) = 0; 357 358 // Invoked when the amount of vertical overscroll changes. |delta_y| is the 359 // amount of overscroll that has occured in the y-direction. 360 virtual void OverscrollUpdate(int delta_y) {} 361 362 protected: 363 friend void chrome::CloseAllBrowsers(); 364 friend class BrowserView; 365 virtual void DestroyBrowser() = 0; 366 }; 367 368 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) 369 class BookmarkBarView; 370 class LocationBarView; 371 372 namespace views { 373 class View; 374 } 375 #endif // defined(OS_WIN) 376 377 // A BrowserWindow utility interface used for accessing elements of the browser 378 // UI used only by UI test automation. 379 class BrowserWindowTesting { 380 public: 381 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) 382 // Returns the BookmarkBarView. 383 virtual BookmarkBarView* GetBookmarkBarView() const = 0; 384 385 // Returns the LocationBarView. 386 virtual LocationBarView* GetLocationBarView() const = 0; 387 388 // Returns the TabContentsContainer. 389 virtual views::View* GetTabContentsContainerView() const = 0; 390 391 // Returns the ToolbarView. 392 virtual ToolbarView* GetToolbarView() const = 0; 393 #endif 394 395 protected: 396 virtual ~BrowserWindowTesting() {} 397 }; 398 399 #endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_ 400