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