browser_window.h revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
1// Copyright (c) 2010 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#pragma once 8 9#include "chrome/browser/tab_contents/navigation_entry.h" 10#include "chrome/common/content_settings_types.h" 11#include "gfx/native_widget_types.h" 12 13class Browser; 14class BrowserWindowTesting; 15class DownloadShelf; 16class FindBar; 17class GURL; 18class HtmlDialogUIDelegate; 19class LocationBar; 20class Profile; 21class StatusBubble; 22class TabContents; 23class TabContentsWrapper; 24class TemplateURL; 25class TemplateURLModel; 26#if !defined(OS_MACOSX) 27class ToolbarView; 28#endif 29struct NativeWebKeyboardEvent; 30 31namespace gfx { 32class Rect; 33} 34 35namespace views { 36class Window; 37} 38 39class Extension; 40 41//////////////////////////////////////////////////////////////////////////////// 42// BrowserWindow interface 43// An interface implemented by the "view" of the Browser window. 44// 45// NOTE: All getters may return NULL. 46class BrowserWindow { 47 public: 48 // Show the window, or activates it if it's already visible. 49 virtual void Show() = 0; 50 51 // Sets the window's size and position to the specified values. 52 virtual void SetBounds(const gfx::Rect& bounds) = 0; 53 54 // Closes the frame as soon as possible. If the frame is not in a drag 55 // session, it will close immediately; otherwise, it will move offscreen (so 56 // events are still fired) until the drag ends, then close. This assumes 57 // that the Browser is not immediately destroyed, but will be eventually 58 // destroyed by other means (eg, the tab strip going to zero elements). 59 // Bad things happen if the Browser dtor is called directly as a result of 60 // invoking this method. 61 virtual void Close() = 0; 62 63 // Activates (brings to front) the window. Restores the window from minimized 64 // state if necessary. 65 virtual void Activate() = 0; 66 67 // Deactivates the window, making the next window in the Z order the active 68 // window. 69 virtual void Deactivate() = 0; 70 71 // Returns true if the window is currently the active/focused window. 72 virtual bool IsActive() const = 0; 73 74 // Flashes the taskbar item associated with this frame. 75 virtual void FlashFrame() = 0; 76 77 // Return a platform dependent identifier for this frame. On Windows, this 78 // returns an HWND. 79 virtual gfx::NativeWindow GetNativeHandle() = 0; 80 81 // Returns a pointer to the testing interface to the Browser window, or NULL 82 // if there is none. 83 virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0; 84 85 // Return the status bubble associated with the frame 86 virtual StatusBubble* GetStatusBubble() = 0; 87 88 // Inform the receiving frame that an animation has progressed in the 89 // selected tab. 90 // TODO(beng): Remove. Infobars/Boomarks bars should talk directly to 91 // BrowserView. 92 virtual void SelectedTabToolbarSizeChanged(bool is_animating) = 0; 93 94 // Inform the frame that the selected tab favicon or title has changed. Some 95 // frames may need to refresh their title bar. 96 virtual void UpdateTitleBar() = 0; 97 98 // Invoked when the visibility of the bookmark bar. 99 // NOTE: this is NOT sent when the user toggles the visibility of this, 100 // but rather when the user transitions from a page that forces 101 // it to be visibile to one that doesn't have it visible (or 102 // vice-versa). 103 // TODO(sky): see about routing visibility pref changing through here too. 104 virtual void ShelfVisibilityChanged() = 0; 105 106 // Inform the frame that the dev tools window for the selected tab has 107 // changed. 108 virtual void UpdateDevTools() = 0; 109 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; 114 115 // Sets the starred state for the current tab. 116 virtual void SetStarredState(bool is_starred) = 0; 117 118 // Returns the nonmaximized bounds of the frame (even if the frame is 119 // currently maximized or minimized) in terms of the screen coordinates. 120 virtual gfx::Rect GetRestoredBounds() const = 0; 121 122 // TODO(beng): REMOVE? 123 // Returns true if the frame is maximized (aka zoomed). 124 virtual bool IsMaximized() const = 0; 125 126 // Accessors for fullscreen mode state. 127 virtual void SetFullscreen(bool fullscreen) = 0; 128 virtual bool IsFullscreen() const = 0; 129 130 // Returns true if the fullscreen bubble is visible. 131 virtual bool IsFullscreenBubbleVisible() const = 0; 132 133 // Returns the location bar. 134 virtual LocationBar* GetLocationBar() const = 0; 135 136 // Tries to focus the location bar. Clears the window focus (to avoid 137 // inconsistent state) if this fails. 138 virtual void SetFocusToLocationBar(bool select_all) = 0; 139 140 // Informs the view whether or not a load is in progress for the current tab. 141 // The view can use this notification to update the reload/stop button. 142 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0; 143 144 // Updates the toolbar with the state for the specified |contents|. 145 virtual void UpdateToolbar(TabContentsWrapper* contents, 146 bool should_restore_state) = 0; 147 148 // Focuses the toolbar (for accessibility). 149 virtual void FocusToolbar() = 0; 150 151 // Focuses the app menu like it was a menu bar. 152 // 153 // Not used on the Mac, which has a "normal" menu bar. 154 virtual void FocusAppMenu() = 0; 155 156 // Focuses the bookmarks toolbar (for accessibility). 157 virtual void FocusBookmarksToolbar() = 0; 158 159 // Focuses the Chrome OS status view (for accessibility). 160 virtual void FocusChromeOSStatus() = 0; 161 162 // Moves keyboard focus to the next pane. 163 virtual void RotatePaneFocus(bool forwards) = 0; 164 165 // Returns whether the bookmark bar is visible or not. 166 virtual bool IsBookmarkBarVisible() const = 0; 167 168 // Returns whether the bookmark bar is animating or not. 169 virtual bool IsBookmarkBarAnimating() const = 0; 170 171 // Returns whether the tab strip is editable (for extensions). 172 virtual bool IsTabStripEditable() const = 0; 173 174 // Returns whether the tool bar is visible or not. 175 virtual bool IsToolbarVisible() const = 0; 176 177 // Tells the frame not to render as inactive until the next activation change. 178 // This is required on Windows when dropdown selects are shown to prevent the 179 // select from deactivating the browser frame. A stub implementation is 180 // provided here since the functionality is Windows-specific. 181 virtual void DisableInactiveFrame() {} 182 183 // Shows a confirmation dialog box for setting the default search engine 184 // described by |template_url|. Takes ownership of |template_url|. 185 virtual void ConfirmSetDefaultSearchProvider( 186 TabContents* tab_contents, 187 TemplateURL* template_url, 188 TemplateURLModel* template_url_model) { 189 // TODO(levin): Implement this for non-Windows platforms and make it pure. 190 } 191 192 // Shows a confirmation dialog box for adding a search engine described by 193 // |template_url|. Takes ownership of |template_url|. 194 virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, 195 Profile* profile) = 0; 196 197 // Shows or hides the bookmark bar depending on its current visibility. 198 virtual void ToggleBookmarkBar() = 0; 199 200 // Shows the About Chrome dialog box. 201 virtual views::Window* ShowAboutChromeDialog() = 0; 202 203 // Shows the Update Recommended dialog box. 204 virtual void ShowUpdateChromeDialog() = 0; 205 206 // Shows the Task manager. 207 virtual void ShowTaskManager() = 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 // Whether or not the shelf view is visible. 214 virtual bool IsDownloadShelfVisible() const = 0; 215 216 // Returns the DownloadShelf. 217 virtual DownloadShelf* GetDownloadShelf() = 0; 218 219 // Shows the Report a Bug dialog box. 220 virtual void ShowReportBugDialog() = 0; 221 222 // Shows the Clear Browsing Data dialog box. 223 virtual void ShowClearBrowsingDataDialog() = 0; 224 225 // Shows the Import Bookmarks & Settings dialog box. 226 virtual void ShowImportDialog() = 0; 227 228 // Shows the Search Engines dialog box. 229 virtual void ShowSearchEnginesDialog() = 0; 230 231 // Shows the Password Manager dialog box. 232 virtual void ShowPasswordManager() = 0; 233 234 // Shows the repost form confirmation dialog box. 235 virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) = 0; 236 237 // Shows the Content Settings dialog box. 238 virtual void ShowContentSettingsWindow(ContentSettingsType content_type, 239 Profile* profile) = 0; 240 241 // Shows the collected cookies dialog box. 242 virtual void ShowCollectedCookiesDialog(TabContents* tab_contents) = 0; 243 244 // Shows a dialog to the user that something is wrong with the profile. 245 // |message_id| is the ID for a string in the string table which will be 246 // displayed in the dialog. 247 virtual void ShowProfileErrorDialog(int message_id) = 0; 248 249 // Show the bubble that indicates to the user that a theme is being installed. 250 virtual void ShowThemeInstallBubble() = 0; 251 252 // Shows the confirmation dialog box warning that the browser is closing with 253 // in-progress downloads. 254 // This method should call Browser::InProgressDownloadResponse once the user 255 // has confirmed. 256 virtual void ConfirmBrowserCloseWithPendingDownloads() = 0; 257 258 // Shows a dialog box with HTML content, e.g. for Gears. |parent_window| is 259 // the window the dialog should be opened modal to and is a native window 260 // handle. 261 virtual void ShowHTMLDialog(HtmlDialogUIDelegate* delegate, 262 gfx::NativeWindow parent_window) = 0; 263 264 // BrowserThemeProvider calls this when a user has changed his or her theme, 265 // indicating that it's time to redraw everything. 266 virtual void UserChangedTheme() = 0; 267 268 // Get extra vertical height that the render view should add to its requests 269 // to webkit. This can help prevent sending extraneous layout/repaint requests 270 // when the delegate is in the process of resizing the tab contents view (e.g. 271 // during infobar animations). 272 virtual int GetExtraRenderViewHeight() const = 0; 273 274 // Notification that |tab_contents| got the focus through user action (click 275 // on the page). 276 virtual void TabContentsFocused(TabContents* tab_contents) = 0; 277 278 // Shows the page info using the specified information. 279 // |url| is the url of the page/frame the info applies to, |ssl| is the SSL 280 // information for that page/frame. If |show_history| is true, a section 281 // showing how many times that URL has been visited is added to the page info. 282 virtual void ShowPageInfo(Profile* profile, 283 const GURL& url, 284 const NavigationEntry::SSLStatus& ssl, 285 bool show_history) = 0; 286 287 // Shows the app menu (for accessibility). 288 virtual void ShowAppMenu() = 0; 289 290 // Allows the BrowserWindow object to handle the specified keyboard event 291 // before sending it to the renderer. 292 // Returns true if the |event| was handled. Otherwise, if the |event| would 293 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut, 294 // |*is_keyboard_shortcut| should be set to true. 295 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 296 bool* is_keyboard_shortcut) = 0; 297 298 // Allows the BrowserWindow object to handle the specified keyboard event, 299 // if the renderer did not process it. 300 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) = 0; 301 302 // Shows the create web app shortcut dialog box. 303 virtual void ShowCreateWebAppShortcutsDialog(TabContents* tab_contents) = 0; 304 305 // Shows the create chrome app shortcut dialog box. 306 virtual void ShowCreateChromeAppShortcutsDialog(Profile* profile, 307 const Extension* app) = 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 // Switches between available tabstrip display modes. 315 virtual void ToggleTabStripMode() = 0; 316 317#if defined(OS_MACOSX) 318 // Opens the tabpose view. 319 virtual void OpenTabpose() = 0; 320#endif 321 322 // See InstantDelegate for details. 323 virtual void PrepareForInstant() = 0; 324 325 // Invoked when instant's tab contents should be shown. 326 virtual void ShowInstant(TabContents* preview_contents) = 0; 327 328 // Invoked when the instant's tab contents should be hidden. 329 // |instant_is_active| indicates if instant is still active. 330 virtual void HideInstant(bool instant_is_active) = 0; 331 332 // Returns the desired bounds for instant in screen coordinates. Note that if 333 // instant isn't currently visible this returns the bounds instant would be 334 // placed at. 335 virtual gfx::Rect GetInstantBounds() = 0; 336 337#if defined(OS_CHROMEOS) 338 // Shows the keyboard overlay dialog box. 339 virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window) = 0; 340#endif 341 342 // Construct a BrowserWindow implementation for the specified |browser|. 343 static BrowserWindow* CreateBrowserWindow(Browser* browser); 344 345 // Construct a FindBar implementation for the specified |browser|. 346 static FindBar* CreateFindBar(Browser* browser_window); 347 348 protected: 349 friend class BrowserList; 350 friend class BrowserView; 351 virtual void DestroyBrowser() = 0; 352 353 virtual ~BrowserWindow() {} 354}; 355 356#if defined(OS_WIN) || defined(TOOLKIT_VIEWS) 357class BookmarkBarView; 358class LocationBarView; 359 360namespace views { 361class View; 362} 363#endif // defined(OS_WIN) 364 365// A BrowserWindow utility interface used for accessing elements of the browser 366// UI used only by UI test automation. 367class BrowserWindowTesting { 368 public: 369#if defined(OS_WIN) || defined(TOOLKIT_VIEWS) 370 // Returns the BookmarkBarView. 371 virtual BookmarkBarView* GetBookmarkBarView() const = 0; 372 373 // Returns the LocationBarView. 374 virtual LocationBarView* GetLocationBarView() const = 0; 375 376 // Returns the TabContentsContainer. 377 virtual views::View* GetTabContentsContainerView() const = 0; 378 379 // Returns the TabContentsContainer. 380 virtual views::View* GetSidebarContainerView() const = 0; 381 382 // Returns the ToolbarView. 383 virtual ToolbarView* GetToolbarView() const = 0; 384#endif 385 386 protected: 387 virtual ~BrowserWindowTesting() {} 388}; 389 390#endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_ 391