1 // Copyright (c) 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_H_ 6 #define CHROME_BROWSER_UI_BROWSER_H_ 7 8 #include <map> 9 #include <set> 10 #include <string> 11 #include <vector> 12 13 #include "base/basictypes.h" 14 #include "base/compiler_specific.h" 15 #include "base/gtest_prod_util.h" 16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/weak_ptr.h" 18 #include "base/prefs/pref_change_registrar.h" 19 #include "base/prefs/pref_member.h" 20 #include "base/strings/string16.h" 21 #include "chrome/browser/devtools/devtools_toggle_action.h" 22 #include "chrome/browser/sessions/session_id.h" 23 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.h" 24 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" 25 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h" 26 #include "chrome/browser/ui/browser_navigator.h" 27 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h" 28 #include "chrome/browser/ui/host_desktop.h" 29 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h" 30 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" 31 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 32 #include "chrome/browser/ui/toolbar/toolbar_model.h" 33 #include "chrome/browser/ui/zoom/zoom_observer.h" 34 #include "chrome/common/content_settings.h" 35 #include "chrome/common/content_settings_types.h" 36 #include "chrome/common/extensions/extension_constants.h" 37 #include "content/public/browser/notification_observer.h" 38 #include "content/public/browser/notification_registrar.h" 39 #include "content/public/browser/page_navigator.h" 40 #include "content/public/browser/web_contents_delegate.h" 41 #include "content/public/common/page_transition_types.h" 42 #include "content/public/common/page_zoom.h" 43 #include "ui/base/ui_base_types.h" 44 #include "ui/base/window_open_disposition.h" 45 #include "ui/gfx/rect.h" 46 #include "ui/shell_dialogs/select_file_dialog.h" 47 48 class BrowserContentSettingBubbleModelDelegate; 49 class BrowserInstantController; 50 class BrowserSyncedWindowDelegate; 51 class BrowserToolbarModelDelegate; 52 class BrowserTabRestoreServiceDelegate; 53 class BrowserWindow; 54 class FindBarController; 55 class FullscreenController; 56 class PrefService; 57 class Profile; 58 class SearchDelegate; 59 class SearchModel; 60 class StatusBubble; 61 class TabStripModel; 62 class TabStripModelDelegate; 63 struct WebApplicationInfo; 64 65 namespace chrome { 66 class BrowserCommandController; 67 class FastUnloadController; 68 class UnloadController; 69 } 70 71 namespace content { 72 class NavigationController; 73 class PageState; 74 class SessionStorageNamespace; 75 } 76 77 namespace extensions { 78 class Extension; 79 class WindowController; 80 } 81 82 namespace gfx { 83 class Image; 84 class Point; 85 } 86 87 namespace ui { 88 struct SelectedFileInfo; 89 class WebDialogDelegate; 90 } 91 92 namespace web_modal { 93 class WebContentsModalDialogHost; 94 } 95 96 class Browser : public TabStripModelObserver, 97 public content::WebContentsDelegate, 98 public CoreTabHelperDelegate, 99 public SearchEngineTabHelperDelegate, 100 public ChromeWebModalDialogManagerDelegate, 101 public BlockedContentTabHelperDelegate, 102 public BookmarkTabHelperDelegate, 103 public ZoomObserver, 104 public content::PageNavigator, 105 public content::NotificationObserver, 106 public ui::SelectFileDialog::Listener { 107 public: 108 // SessionService::WindowType mirrors these values. If you add to this 109 // enum, look at SessionService::WindowType to see if it needs to be 110 // updated. 111 enum Type { 112 // If you add a new type, consider updating the test 113 // BrowserTest.StartMaximized. 114 TYPE_TABBED = 1, 115 TYPE_POPUP = 2 116 }; 117 118 // Distinguishes between browsers that host an app (opened from 119 // ApplicationLauncher::OpenApplication), and child browsers created by an app 120 // from Browser::CreateForApp (e.g. by windows.open or the extension API). 121 enum AppType { 122 APP_TYPE_HOST = 1, 123 APP_TYPE_CHILD = 2 124 }; 125 126 // Possible elements of the Browser window. 127 enum WindowFeature { 128 FEATURE_NONE = 0, 129 FEATURE_TITLEBAR = 1, 130 FEATURE_TABSTRIP = 2, 131 FEATURE_TOOLBAR = 4, 132 FEATURE_LOCATIONBAR = 8, 133 FEATURE_BOOKMARKBAR = 16, 134 FEATURE_INFOBAR = 32, 135 FEATURE_DOWNLOADSHELF = 64 136 }; 137 138 // The context for a download blocked notification from 139 // OkToCloseWithInProgressDownloads. 140 enum DownloadClosePreventionType { 141 // Browser close is not blocked by download state. 142 DOWNLOAD_CLOSE_OK, 143 144 // The browser is shutting down and there are active downloads 145 // that would be cancelled. 146 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN, 147 148 // There are active downloads associated with this incognito profile 149 // that would be canceled. 150 DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE, 151 }; 152 153 struct CreateParams { 154 CreateParams(Profile* profile, chrome::HostDesktopType host_desktop_type); 155 CreateParams(Type type, 156 Profile* profile, 157 chrome::HostDesktopType host_desktop_type); 158 159 static CreateParams CreateForApp(Type type, 160 const std::string& app_name, 161 const gfx::Rect& window_bounds, 162 Profile* profile, 163 chrome::HostDesktopType host_desktop_type); 164 165 static CreateParams CreateForDevTools( 166 Profile* profile, 167 chrome::HostDesktopType host_desktop_type); 168 169 // The browser type. 170 Type type; 171 172 // The associated profile. 173 Profile* profile; 174 175 // The host desktop the browser is created on. 176 chrome::HostDesktopType host_desktop_type; 177 178 // The application name that is also the name of the window to the shell. 179 // This name should be set when: 180 // 1) we launch an application via an application shortcut or extension API. 181 // 2) we launch an undocked devtool window. 182 std::string app_name; 183 184 // Type of app (host or child). See description of AppType. 185 AppType app_type; 186 187 // The bounds of the window to open. 188 gfx::Rect initial_bounds; 189 190 ui::WindowShowState initial_show_state; 191 192 bool is_session_restore; 193 194 // Supply a custom BrowserWindow implementation, to be used instead of the 195 // default. Intended for testing. 196 BrowserWindow* window; 197 }; 198 199 // Constructors, Creation, Showing ////////////////////////////////////////// 200 201 explicit Browser(const CreateParams& params); 202 virtual ~Browser(); 203 204 // Set overrides for the initial window bounds and maximized state. 205 void set_override_bounds(const gfx::Rect& bounds) { 206 override_bounds_ = bounds; 207 } 208 ui::WindowShowState initial_show_state() const { return initial_show_state_; } 209 void set_initial_show_state(ui::WindowShowState initial_show_state) { 210 initial_show_state_ = initial_show_state; 211 } 212 // Return true if the initial window bounds have been overridden. 213 bool bounds_overridden() const { 214 return !override_bounds_.IsEmpty(); 215 } 216 // Set indicator that this browser is being created via session restore. 217 // This is used on the Mac (only) to determine animation style when the 218 // browser window is shown. 219 void set_is_session_restore(bool is_session_restore) { 220 is_session_restore_ = is_session_restore; 221 } 222 bool is_session_restore() const { 223 return is_session_restore_; 224 } 225 chrome::HostDesktopType host_desktop_type() const { 226 return host_desktop_type_; 227 } 228 229 // Accessors //////////////////////////////////////////////////////////////// 230 231 Type type() const { return type_; } 232 const std::string& app_name() const { return app_name_; } 233 AppType app_type() const { return app_type_; } 234 Profile* profile() const { return profile_; } 235 gfx::Rect override_bounds() const { return override_bounds_; } 236 237 // |window()| will return NULL if called before |CreateBrowserWindow()| 238 // is done. 239 BrowserWindow* window() const { return window_; } 240 ToolbarModel* toolbar_model() { return toolbar_model_.get(); } 241 const ToolbarModel* toolbar_model() const { return toolbar_model_.get(); } 242 TabStripModel* tab_strip_model() const { return tab_strip_model_.get(); } 243 chrome::BrowserCommandController* command_controller() { 244 return command_controller_.get(); 245 } 246 SearchModel* search_model() { return search_model_.get(); } 247 const SearchModel* search_model() const { 248 return search_model_.get(); 249 } 250 SearchDelegate* search_delegate() { 251 return search_delegate_.get(); 252 } 253 const SessionID& session_id() const { return session_id_; } 254 BrowserContentSettingBubbleModelDelegate* 255 content_setting_bubble_model_delegate() { 256 return content_setting_bubble_model_delegate_.get(); 257 } 258 BrowserTabRestoreServiceDelegate* tab_restore_service_delegate() { 259 return tab_restore_service_delegate_.get(); 260 } 261 BrowserSyncedWindowDelegate* synced_window_delegate() { 262 return synced_window_delegate_.get(); 263 } 264 BrowserInstantController* instant_controller() { 265 return instant_controller_.get(); 266 } 267 268 // Get the FindBarController for this browser, creating it if it does not 269 // yet exist. 270 FindBarController* GetFindBarController(); 271 272 // Returns true if a FindBarController exists for this browser. 273 bool HasFindBarController() const; 274 275 // Returns the state of the bookmark bar. 276 BookmarkBar::State bookmark_bar_state() const { return bookmark_bar_state_; } 277 278 // State Storage and Retrieval for UI /////////////////////////////////////// 279 280 // Gets the Favicon of the page in the selected tab. 281 gfx::Image GetCurrentPageIcon() const; 282 283 // Gets the title of the window based on the selected tab's title. 284 string16 GetWindowTitleForCurrentTab() const; 285 286 // Prepares a title string for display (removes embedded newlines, etc). 287 static void FormatTitleForDisplay(string16* title); 288 289 // OnBeforeUnload handling ////////////////////////////////////////////////// 290 291 // Gives beforeunload handlers the chance to cancel the close. 292 bool ShouldCloseWindow(); 293 294 // Figure out if there are tabs that have beforeunload handlers. 295 // It starts beforeunload/unload processing as a side-effect. 296 bool TabsNeedBeforeUnloadFired(); 297 298 // Returns true if all tabs' beforeunload/unload events have fired. 299 bool HasCompletedUnloadProcessing() const; 300 301 bool IsAttemptingToCloseBrowser() const; 302 303 // Invoked when the window containing us is closing. Performs the necessary 304 // cleanup. 305 void OnWindowClosing(); 306 307 // In-progress download termination handling ///////////////////////////////// 308 309 // Called when the user has decided whether to proceed or not with the browser 310 // closure. |cancel_downloads| is true if the downloads should be canceled 311 // and the browser closed, false if the browser should stay open and the 312 // downloads running. 313 void InProgressDownloadResponse(bool cancel_downloads); 314 315 // Indicates whether or not this browser window can be closed, or 316 // would be blocked by in-progress downloads. 317 // If executing downloads would be cancelled by this window close, 318 // then |*num_downloads_blocking| is updated with how many downloads 319 // would be canceled if the close continued. 320 DownloadClosePreventionType OkToCloseWithInProgressDownloads( 321 int* num_downloads_blocking) const; 322 323 // External state change handling //////////////////////////////////////////// 324 325 // Invoked when the fullscreen state of the window changes. 326 // BrowserWindow::EnterFullscreen invokes this after the window has become 327 // fullscreen. 328 void WindowFullscreenStateChanged(); 329 330 // Invoked when visible SSL state (as defined by SSLStatus) changes. 331 void VisibleSSLStateChanged(content::WebContents* web_contents); 332 333 // Invoked when the |web_contents| no longer supports Instant. Refreshes the 334 // omnibox so it no longer shows search terms. 335 void OnWebContentsInstantSupportDisabled( 336 const content::WebContents* web_contents); 337 338 // Assorted browser commands //////////////////////////////////////////////// 339 340 // NOTE: Within each of the following sections, the IDs are ordered roughly by 341 // how they appear in the GUI/menus (left to right, top to bottom, etc.). 342 343 // See the description of 344 // FullscreenController::ToggleFullscreenModeWithExtension. 345 void ToggleFullscreenModeWithExtension(const GURL& extension_url); 346 #if defined(OS_WIN) 347 // See the description of FullscreenController::ToggleMetroSnapMode. 348 void SetMetroSnapMode(bool enable); 349 #endif 350 351 // Returns true if the Browser supports the specified feature. The value of 352 // this varies during the lifetime of the browser. For example, if the window 353 // is fullscreen this may return a different value. If you only care about 354 // whether or not it's possible for the browser to support a particular 355 // feature use |CanSupportWindowFeature|. 356 bool SupportsWindowFeature(WindowFeature feature) const; 357 358 // Returns true if the Browser can support the specified feature. See comment 359 // in |SupportsWindowFeature| for details on this. 360 bool CanSupportWindowFeature(WindowFeature feature) const; 361 362 // TODO(port): port these, and re-merge the two function declaration lists. 363 // Page-related commands. 364 void ToggleEncodingAutoDetect(); 365 void OverrideEncoding(int encoding_id); 366 367 // Show various bits of UI 368 void OpenFile(); 369 370 void UpdateDownloadShelfVisibility(bool visible); 371 372 ///////////////////////////////////////////////////////////////////////////// 373 374 // Helper function to run unload listeners on a WebContents. 375 static bool RunUnloadEventsHelper(content::WebContents* contents); 376 377 // Helper function to handle JS out of memory notifications 378 static void JSOutOfMemoryHelper(content::WebContents* web_contents); 379 380 // Helper function to register a protocol handler. 381 static void RegisterProtocolHandlerHelper(content::WebContents* web_contents, 382 const std::string& protocol, 383 const GURL& url, 384 const string16& title, 385 bool user_gesture, 386 BrowserWindow* window); 387 388 // Helper function to handle find results. 389 static void FindReplyHelper(content::WebContents* web_contents, 390 int request_id, 391 int number_of_matches, 392 const gfx::Rect& selection_rect, 393 int active_match_ordinal, 394 bool final_update); 395 396 // Called by chrome::Navigate() when a navigation has occurred in a tab in 397 // this Browser. Updates the UI for the start of this navigation. 398 void UpdateUIForNavigationInTab(content::WebContents* contents, 399 content::PageTransition transition, 400 bool user_initiated); 401 402 // Interface implementations //////////////////////////////////////////////// 403 404 // Overridden from content::PageNavigator: 405 virtual content::WebContents* OpenURL( 406 const content::OpenURLParams& params) OVERRIDE; 407 408 // Overridden from TabStripModelObserver: 409 virtual void TabInsertedAt(content::WebContents* contents, 410 int index, 411 bool foreground) OVERRIDE; 412 virtual void TabClosingAt(TabStripModel* tab_strip_model, 413 content::WebContents* contents, 414 int index) OVERRIDE; 415 virtual void TabDetachedAt(content::WebContents* contents, 416 int index) OVERRIDE; 417 virtual void TabDeactivated(content::WebContents* contents) OVERRIDE; 418 virtual void ActiveTabChanged(content::WebContents* old_contents, 419 content::WebContents* new_contents, 420 int index, 421 int reason) OVERRIDE; 422 virtual void TabMoved(content::WebContents* contents, 423 int from_index, 424 int to_index) OVERRIDE; 425 virtual void TabReplacedAt(TabStripModel* tab_strip_model, 426 content::WebContents* old_contents, 427 content::WebContents* new_contents, 428 int index) OVERRIDE; 429 virtual void TabPinnedStateChanged(content::WebContents* contents, 430 int index) OVERRIDE; 431 virtual void TabStripEmpty() OVERRIDE; 432 433 // Overridden from content::WebContentsDelegate: 434 virtual bool CanOverscrollContent() const OVERRIDE; 435 virtual bool PreHandleKeyboardEvent( 436 content::WebContents* source, 437 const content::NativeWebKeyboardEvent& event, 438 bool* is_keyboard_shortcut) OVERRIDE; 439 virtual void HandleKeyboardEvent( 440 content::WebContents* source, 441 const content::NativeWebKeyboardEvent& event) OVERRIDE; 442 virtual void OverscrollUpdate(int delta_y) OVERRIDE; 443 444 bool is_type_tabbed() const { return type_ == TYPE_TABBED; } 445 bool is_type_popup() const { return type_ == TYPE_POPUP; } 446 447 bool is_app() const; 448 bool is_devtools() const; 449 450 // True when the mouse cursor is locked. 451 bool IsMouseLocked() const; 452 453 // Called each time the browser window is shown. 454 void OnWindowDidShow(); 455 456 // Show the first run search engine bubble on the location bar. 457 void ShowFirstRunBubble(); 458 459 // Show a download on the download shelf. 460 void ShowDownload(content::DownloadItem* download); 461 462 FullscreenController* fullscreen_controller() const { 463 return fullscreen_controller_.get(); 464 } 465 466 extensions::WindowController* extension_window_controller() const { 467 return extension_window_controller_.get(); 468 } 469 470 private: 471 friend class BrowserTest; 472 friend class FullscreenControllerInteractiveTest; 473 friend class FullscreenControllerTest; 474 FRIEND_TEST_ALL_PREFIXES(AppModeTest, EnableAppModeTest); 475 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest, 476 IsReservedCommandOrKeyIsApp); 477 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest, AppFullScreen); 478 FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups); 479 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ConvertTabToAppShortcut); 480 FRIEND_TEST_ALL_PREFIXES(BrowserTest, OpenAppWindowLikeNtp); 481 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch); 482 FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest, 483 TabEntersPresentationModeFromWindowed); 484 FRIEND_TEST_ALL_PREFIXES(FullscreenExitBubbleControllerTest, 485 DenyExitsFullscreen); 486 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref); 487 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, 488 OpenAppShortcutWindowPref); 489 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref); 490 491 class InterstitialObserver; 492 493 // Used to describe why a tab is being detached. This is used by 494 // TabDetachedAtImpl. 495 enum DetachType { 496 // Result of TabDetachedAt. 497 DETACH_TYPE_DETACH, 498 499 // Result of TabReplacedAt. 500 DETACH_TYPE_REPLACE, 501 502 // Result of the tab strip not having any significant tabs. 503 DETACH_TYPE_EMPTY 504 }; 505 506 // Describes where the bookmark bar state change originated from. 507 enum BookmarkBarStateChangeReason { 508 // From the constructor. 509 BOOKMARK_BAR_STATE_CHANGE_INIT, 510 511 // Change is the result of the active tab changing. 512 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH, 513 514 // Change is the result of the bookmark bar pref changing. 515 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE, 516 517 // Change is the result of a state change in the active tab. 518 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE, 519 520 // Change is the result of window toggling in/out of fullscreen mode. 521 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN, 522 }; 523 524 // Overridden from content::WebContentsDelegate: 525 virtual content::WebContents* OpenURLFromTab( 526 content::WebContents* source, 527 const content::OpenURLParams& params) OVERRIDE; 528 virtual void NavigationStateChanged(const content::WebContents* source, 529 unsigned changed_flags) OVERRIDE; 530 virtual void AddNewContents(content::WebContents* source, 531 content::WebContents* new_contents, 532 WindowOpenDisposition disposition, 533 const gfx::Rect& initial_pos, 534 bool user_gesture, 535 bool* was_blocked) OVERRIDE; 536 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; 537 virtual void DeactivateContents(content::WebContents* contents) OVERRIDE; 538 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; 539 virtual void CloseContents(content::WebContents* source) OVERRIDE; 540 virtual void MoveContents(content::WebContents* source, 541 const gfx::Rect& pos) OVERRIDE; 542 virtual bool IsPopupOrPanel( 543 const content::WebContents* source) const OVERRIDE; 544 virtual void UpdateTargetURL(content::WebContents* source, int32 page_id, 545 const GURL& url) OVERRIDE; 546 virtual void ContentsMouseEvent(content::WebContents* source, 547 const gfx::Point& location, 548 bool motion) OVERRIDE; 549 virtual void ContentsZoomChange(bool zoom_in) OVERRIDE; 550 virtual void WebContentsFocused(content::WebContents* content) OVERRIDE; 551 virtual bool TakeFocus(content::WebContents* source, bool reverse) OVERRIDE; 552 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; 553 virtual void BeforeUnloadFired(content::WebContents* source, 554 bool proceed, 555 bool* proceed_to_fire_unload) OVERRIDE; 556 virtual bool ShouldFocusLocationBarByDefault( 557 content::WebContents* source) OVERRIDE; 558 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; 559 virtual void RenderWidgetShowing() OVERRIDE; 560 virtual int GetExtraRenderViewHeight() const OVERRIDE; 561 virtual void ViewSourceForTab(content::WebContents* source, 562 const GURL& page_url) OVERRIDE; 563 virtual void ViewSourceForFrame( 564 content::WebContents* source, 565 const GURL& frame_url, 566 const content::PageState& frame_page_state) OVERRIDE; 567 virtual void ShowRepostFormWarningDialog( 568 content::WebContents* source) OVERRIDE; 569 virtual bool ShouldCreateWebContents( 570 content::WebContents* web_contents, 571 int route_id, 572 WindowContainerType window_container_type, 573 const string16& frame_name, 574 const GURL& target_url, 575 const content::Referrer& referrer, 576 WindowOpenDisposition disposition, 577 const WebKit::WebWindowFeatures& features, 578 bool user_action, 579 bool opener_suppressed) OVERRIDE; 580 virtual void WebContentsCreated(content::WebContents* source_contents, 581 int64 source_frame_id, 582 const string16& frame_name, 583 const GURL& target_url, 584 content::WebContents* new_contents) OVERRIDE; 585 virtual void RendererUnresponsive(content::WebContents* source) OVERRIDE; 586 virtual void RendererResponsive(content::WebContents* source) OVERRIDE; 587 virtual void WorkerCrashed(content::WebContents* source) OVERRIDE; 588 virtual void DidNavigateMainFramePostCommit( 589 content::WebContents* web_contents) OVERRIDE; 590 virtual void DidNavigateToPendingEntry( 591 content::WebContents* web_contents) OVERRIDE; 592 virtual content::JavaScriptDialogManager* 593 GetJavaScriptDialogManager() OVERRIDE; 594 virtual content::ColorChooser* OpenColorChooser( 595 content::WebContents* web_contents, SkColor color) OVERRIDE; 596 virtual void RunFileChooser( 597 content::WebContents* web_contents, 598 const content::FileChooserParams& params) OVERRIDE; 599 virtual void EnumerateDirectory(content::WebContents* web_contents, 600 int request_id, 601 const base::FilePath& path) OVERRIDE; 602 virtual void ToggleFullscreenModeForTab(content::WebContents* web_contents, 603 bool enter_fullscreen) OVERRIDE; 604 virtual bool IsFullscreenForTabOrPending( 605 const content::WebContents* web_contents) const OVERRIDE; 606 virtual void JSOutOfMemory(content::WebContents* web_contents) OVERRIDE; 607 virtual void RegisterProtocolHandler(content::WebContents* web_contents, 608 const std::string& protocol, 609 const GURL& url, 610 const string16& title, 611 bool user_gesture) OVERRIDE; 612 virtual void UpdatePreferredSize(content::WebContents* source, 613 const gfx::Size& pref_size) OVERRIDE; 614 virtual void ResizeDueToAutoResize(content::WebContents* source, 615 const gfx::Size& new_size) OVERRIDE; 616 virtual void FindReply(content::WebContents* web_contents, 617 int request_id, 618 int number_of_matches, 619 const gfx::Rect& selection_rect, 620 int active_match_ordinal, 621 bool final_update) OVERRIDE; 622 virtual void RequestToLockMouse(content::WebContents* web_contents, 623 bool user_gesture, 624 bool last_unlocked_by_target) OVERRIDE; 625 virtual void LostMouseLock() OVERRIDE; 626 virtual void RequestMediaAccessPermission( 627 content::WebContents* web_contents, 628 const content::MediaStreamRequest& request, 629 const content::MediaResponseCallback& callback) OVERRIDE; 630 virtual bool RequestPpapiBrokerPermission( 631 content::WebContents* web_contents, 632 const GURL& url, 633 const base::FilePath& plugin_path, 634 const base::Callback<void(bool)>& callback) OVERRIDE; 635 636 // Overridden from CoreTabHelperDelegate: 637 // Note that the caller is responsible for deleting |old_contents|. 638 virtual void SwapTabContents(content::WebContents* old_contents, 639 content::WebContents* new_contents) OVERRIDE; 640 virtual bool CanReloadContents( 641 content::WebContents* web_contents) const OVERRIDE; 642 virtual bool CanSaveContents( 643 content::WebContents* web_contents) const OVERRIDE; 644 645 // Overridden from SearchEngineTabHelperDelegate: 646 virtual void ConfirmAddSearchProvider(TemplateURL* template_url, 647 Profile* profile) OVERRIDE; 648 649 // Overridden from WebContentsModalDialogManagerDelegate: 650 virtual void SetWebContentsBlocked(content::WebContents* web_contents, 651 bool blocked) OVERRIDE; 652 virtual web_modal::WebContentsModalDialogHost* 653 GetWebContentsModalDialogHost() OVERRIDE; 654 655 // Overridden from BlockedContentTabHelperDelegate: 656 virtual content::WebContents* GetConstrainingWebContents( 657 content::WebContents* source) OVERRIDE; 658 659 // Overridden from BookmarkTabHelperDelegate: 660 virtual void URLStarredChanged(content::WebContents* web_contents, 661 bool starred) OVERRIDE; 662 663 // Overridden from ZoomObserver: 664 virtual void OnZoomChanged(content::WebContents* source, 665 bool can_show_bubble) OVERRIDE; 666 667 // Overridden from SelectFileDialog::Listener: 668 virtual void FileSelected(const base::FilePath& path, 669 int index, 670 void* params) OVERRIDE; 671 virtual void FileSelectedWithExtraInfo( 672 const ui::SelectedFileInfo& file_info, 673 int index, 674 void* params) OVERRIDE; 675 676 // Overridden from content::NotificationObserver: 677 virtual void Observe(int type, 678 const content::NotificationSource& source, 679 const content::NotificationDetails& details) OVERRIDE; 680 681 // Command and state updating /////////////////////////////////////////////// 682 683 // Handle changes to kDevTools preference. 684 void OnDevToolsDisabledChanged(); 685 686 // UI update coalescing and handling //////////////////////////////////////// 687 688 // Asks the toolbar (and as such the location bar) to update its state to 689 // reflect the current tab's current URL, security state, etc. 690 // If |should_restore_state| is true, we're switching (back?) to this tab and 691 // should restore any previous location bar state (such as user editing) as 692 // well. 693 void UpdateToolbar(bool should_restore_state); 694 695 // Updates the browser's search model with the tab's search model. 696 void UpdateSearchState(content::WebContents* contents); 697 698 // Does one or both of the following for each bit in |changed_flags|: 699 // . If the update should be processed immediately, it is. 700 // . If the update should processed asynchronously (to avoid lots of ui 701 // updates), then scheduled_updates_ is updated for the |source| and update 702 // pair and a task is scheduled (assuming it isn't running already) 703 // that invokes ProcessPendingUIUpdates. 704 void ScheduleUIUpdate(const content::WebContents* source, 705 unsigned changed_flags); 706 707 // Processes all pending updates to the UI that have been scheduled by 708 // ScheduleUIUpdate in scheduled_updates_. 709 void ProcessPendingUIUpdates(); 710 711 // Removes all entries from scheduled_updates_ whose source is contents. 712 void RemoveScheduledUpdatesFor(content::WebContents* contents); 713 714 // Getters for UI /////////////////////////////////////////////////////////// 715 716 // TODO(beng): remove, and provide AutomationProvider a better way to access 717 // the LocationBarView's edit. 718 friend class AutomationProvider; 719 friend class BrowserProxy; 720 friend class TestingAutomationProvider; 721 722 // Returns the StatusBubble from the current toolbar. It is possible for 723 // this to return NULL if called before the toolbar has initialized. 724 // TODO(beng): remove this. 725 StatusBubble* GetStatusBubble(); 726 727 // Session restore functions //////////////////////////////////////////////// 728 729 // Notifies the history database of the index for all tabs whose index is 730 // >= index. 731 void SyncHistoryWithTabs(int index); 732 733 // In-progress download termination handling ///////////////////////////////// 734 735 // Called when the window is closing to check if potential in-progress 736 // downloads should prevent it from closing. 737 // Returns true if the window can close, false otherwise. 738 bool CanCloseWithInProgressDownloads(); 739 740 // Assorted utility functions /////////////////////////////////////////////// 741 742 // Sets the specified browser as the delegate of the WebContents and all the 743 // associated tab helpers that are needed. 744 void SetAsDelegate(content::WebContents* web_contents, Browser* delegate); 745 746 // Shows the Find Bar, optionally selecting the next entry that matches the 747 // existing search string for that Tab. |forward_direction| controls the 748 // search direction. 749 void FindInPage(bool find_next, bool forward_direction); 750 751 // Closes the frame. 752 // TODO(beng): figure out if we need this now that the frame itself closes 753 // after a return to the message loop. 754 void CloseFrame(); 755 756 void TabDetachedAtImpl(content::WebContents* contents, 757 int index, 758 DetachType type); 759 760 // Shared code between Reload() and ReloadIgnoringCache(). 761 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache); 762 763 // Depending on the disposition, return the current tab or a clone of the 764 // current tab. 765 content::WebContents* GetOrCloneTabForDisposition( 766 WindowOpenDisposition disposition); 767 768 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If 769 // |check_fullscreen| is true, the set of features reflect the actual state of 770 // the browser, otherwise the set of features reflect the possible state of 771 // the browser. 772 bool SupportsWindowFeatureImpl(WindowFeature feature, 773 bool check_fullscreen) const; 774 775 // Resets |bookmark_bar_state_| based on the active tab. Notifies the 776 // BrowserWindow if necessary. 777 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason); 778 779 bool ShouldHideUIForFullscreen() const; 780 781 // Creates a BackgroundContents if appropriate; return true if one was 782 // created. 783 bool MaybeCreateBackgroundContents(int route_id, 784 content::WebContents* opener_web_contents, 785 const string16& frame_name, 786 const GURL& target_url); 787 788 // Data members ///////////////////////////////////////////////////////////// 789 790 std::vector<InterstitialObserver*> interstitial_observers_; 791 792 content::NotificationRegistrar registrar_; 793 794 PrefChangeRegistrar profile_pref_registrar_; 795 796 // This Browser's type. 797 const Type type_; 798 799 // This Browser's profile. 800 Profile* const profile_; 801 802 // This Browser's window. 803 BrowserWindow* window_; 804 805 scoped_ptr<TabStripModelDelegate> tab_strip_model_delegate_; 806 scoped_ptr<TabStripModel> tab_strip_model_; 807 808 // The application name that is also the name of the window to the shell. 809 // This name should be set when: 810 // 1) we launch an application via an application shortcut or extension API. 811 // 2) we launch an undocked devtool window. 812 std::string app_name_; 813 814 // Type of app (host or child). See description of AppType. 815 AppType app_type_; 816 817 // Unique identifier of this browser for session restore. This id is only 818 // unique within the current session, and is not guaranteed to be unique 819 // across sessions. 820 const SessionID session_id_; 821 822 // The model for the toolbar view. 823 scoped_ptr<ToolbarModel> toolbar_model_; 824 825 // The model for the "active" search state. There are per-tab search models 826 // as well. When a tab is active its model is kept in sync with this one. 827 // When a new tab is activated its model state is propagated to this active 828 // model. This way, observers only have to attach to this single model for 829 // updates, and don't have to worry about active tab changes directly. 830 scoped_ptr<SearchModel> search_model_; 831 832 // UI update coalescing and handling //////////////////////////////////////// 833 834 typedef std::map<const content::WebContents*, int> UpdateMap; 835 836 // Maps from WebContents to pending UI updates that need to be processed. 837 // We don't update things like the URL or tab title right away to avoid 838 // flickering and extra painting. 839 // See ScheduleUIUpdate and ProcessPendingUIUpdates. 840 UpdateMap scheduled_updates_; 841 842 // The following factory is used for chrome update coalescing. 843 base::WeakPtrFactory<Browser> chrome_updater_factory_; 844 845 // In-progress download termination handling ///////////////////////////////// 846 847 enum CancelDownloadConfirmationState { 848 NOT_PROMPTED, // We have not asked the user. 849 WAITING_FOR_RESPONSE, // We have asked the user and have not received a 850 // reponse yet. 851 RESPONSE_RECEIVED // The user was prompted and made a decision already. 852 }; 853 854 // State used to figure-out whether we should prompt the user for confirmation 855 // when the browser is closed with in-progress downloads. 856 CancelDownloadConfirmationState cancel_download_confirmation_state_; 857 858 ///////////////////////////////////////////////////////////////////////////// 859 860 // Override values for the bounds of the window and its maximized or minimized 861 // state. 862 // These are supplied by callers that don't want to use the default values. 863 // The default values are typically loaded from local state (last session), 864 // obtained from the last window of the same type, or obtained from the 865 // shell shortcut's startup info. 866 gfx::Rect override_bounds_; 867 ui::WindowShowState initial_show_state_; 868 869 // Tracks when this browser is being created by session restore. 870 bool is_session_restore_; 871 872 const chrome::HostDesktopType host_desktop_type_; 873 874 scoped_ptr<chrome::UnloadController> unload_controller_; 875 scoped_ptr<chrome::FastUnloadController> fast_unload_controller_; 876 877 // The following factory is used to close the frame at a later time. 878 base::WeakPtrFactory<Browser> weak_factory_; 879 880 // The Find Bar. This may be NULL if there is no Find Bar, and if it is 881 // non-NULL, it may or may not be visible. 882 scoped_ptr<FindBarController> find_bar_controller_; 883 884 // Dialog box used for opening and saving files. 885 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; 886 887 // Keep track of the encoding auto detect pref. 888 BooleanPrefMember encoding_auto_detect_; 889 890 // Helper which implements the ContentSettingBubbleModel interface. 891 scoped_ptr<BrowserContentSettingBubbleModelDelegate> 892 content_setting_bubble_model_delegate_; 893 894 // Helper which implements the ToolbarModelDelegate interface. 895 scoped_ptr<BrowserToolbarModelDelegate> toolbar_model_delegate_; 896 897 // A delegate that handles the details of updating the "active" 898 // |search_model_| state with the tab's state. 899 scoped_ptr<SearchDelegate> search_delegate_; 900 901 // Helper which implements the TabRestoreServiceDelegate interface. 902 scoped_ptr<BrowserTabRestoreServiceDelegate> tab_restore_service_delegate_; 903 904 // Helper which implements the SyncedWindowDelegate interface. 905 scoped_ptr<BrowserSyncedWindowDelegate> synced_window_delegate_; 906 907 scoped_ptr<BrowserInstantController> instant_controller_; 908 909 BookmarkBar::State bookmark_bar_state_; 910 911 scoped_ptr<FullscreenController> fullscreen_controller_; 912 913 scoped_ptr<extensions::WindowController> extension_window_controller_; 914 915 scoped_ptr<chrome::BrowserCommandController> command_controller_; 916 917 // True if the browser window has been shown at least once. 918 bool window_has_shown_; 919 920 DISALLOW_COPY_AND_ASSIGN(Browser); 921 }; 922 923 #endif // CHROME_BROWSER_UI_BROWSER_H_ 924