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 <stdint.h> 9 10 #include <map> 11 #include <memory> 12 #include <string> 13 #include <vector> 14 15 #include "base/callback.h" 16 #include "base/compiler_specific.h" 17 #include "base/gtest_prod_util.h" 18 #include "base/macros.h" 19 #include "base/memory/weak_ptr.h" 20 #include "base/scoped_observer.h" 21 #include "base/strings/string16.h" 22 #include "base/timer/elapsed_timer.h" 23 #include "build/build_config.h" 24 #include "chrome/browser/devtools/devtools_toggle_action.h" 25 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" 26 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_observer.h" 27 #include "chrome/browser/ui/browser_navigator.h" 28 #include "chrome/browser/ui/browser_navigator_params.h" 29 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h" 30 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" 31 #include "chrome/browser/ui/profile_chooser_constants.h" 32 #include "chrome/browser/ui/signin_view_controller.h" 33 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 34 #include "chrome/browser/ui/unload_controller.h" 35 #include "chrome/browser/ui/web_applications/app_browser_controller.h" 36 #include "components/content_settings/core/common/content_settings.h" 37 #include "components/content_settings/core/common/content_settings_types.h" 38 #include "components/omnibox/browser/location_bar_model.h" 39 #include "components/paint_preview/buildflags/buildflags.h" 40 #include "components/prefs/pref_change_registrar.h" 41 #include "components/sessions/core/session_id.h" 42 #include "components/translate/content/browser/content_translate_driver.h" 43 #include "components/zoom/zoom_observer.h" 44 #include "content/public/browser/notification_observer.h" 45 #include "content/public/browser/notification_registrar.h" 46 #include "content/public/browser/page_navigator.h" 47 #include "content/public/browser/web_contents.h" 48 #include "content/public/browser/web_contents_delegate.h" 49 #include "content/public/common/page_zoom.h" 50 #include "extensions/buildflags/buildflags.h" 51 #include "printing/buildflags/buildflags.h" 52 #include "third_party/blink/public/mojom/frame/blocked_navigation_types.mojom.h" 53 #include "ui/base/page_transition_types.h" 54 #include "ui/base/ui_base_types.h" 55 #include "ui/base/window_open_disposition.h" 56 #include "ui/gfx/geometry/rect.h" 57 #include "ui/shell_dialogs/select_file_dialog.h" 58 59 #if defined(OS_ANDROID) 60 #error This file should only be included on desktop. 61 #endif 62 63 class BackgroundContents; 64 class BrowserContentSettingBubbleModelDelegate; 65 class BrowserInstantController; 66 class BrowserSyncedWindowDelegate; 67 class BrowserLocationBarModelDelegate; 68 class BrowserLiveTabContext; 69 class BrowserWindow; 70 class FindBarController; 71 class Profile; 72 class ScopedKeepAlive; 73 class StatusBubble; 74 class TabStripModel; 75 class TabStripModelDelegate; 76 77 namespace blink { 78 enum class ProtocolHandlerSecurityLevel; 79 } 80 81 namespace chrome { 82 class BrowserCommandController; 83 } 84 85 namespace content { 86 class SessionStorageNamespace; 87 } 88 89 namespace extensions { 90 class BrowserExtensionWindowController; 91 class ExtensionBrowserWindowHelper; 92 } // namespace extensions 93 94 namespace gfx { 95 class Image; 96 } 97 98 namespace ui { 99 struct SelectedFileInfo; 100 } 101 102 namespace web_modal { 103 class WebContentsModalDialogHost; 104 } 105 106 namespace viz { 107 class SurfaceId; 108 } 109 110 namespace web_app { 111 class AppBrowserController; 112 } 113 114 class Browser : public TabStripModelObserver, 115 public content::WebContentsDelegate, 116 public ChromeWebModalDialogManagerDelegate, 117 public BookmarkTabHelperObserver, 118 public zoom::ZoomObserver, 119 public content::PageNavigator, 120 public content::NotificationObserver, 121 public translate::ContentTranslateDriver::Observer, 122 public ui::SelectFileDialog::Listener { 123 public: 124 // SessionService::WindowType mirrors these values. If you add to this 125 // enum, look at SessionService::WindowType to see if it needs to be 126 // updated. 127 enum Type { 128 // Normal tabbed non-app browser (previously TYPE_TABBED). 129 TYPE_NORMAL, 130 // Popup browser. 131 TYPE_POPUP, 132 // App browser. 133 TYPE_APP, 134 // Devtools browser. 135 TYPE_DEVTOOLS, 136 // App popup browser. It behaves like an app browser (e.g. it should have an 137 // AppBrowserController) but looks like a popup (e.g. it never has a tab 138 // strip). 139 TYPE_APP_POPUP, 140 #if defined(OS_CHROMEOS) 141 // Browser for ARC++ Chrome custom tabs. 142 // It's an enhanced version of TYPE_POPUP, and is used to show the Chrome 143 // Custom Tab toolbar for ARC++ apps. It has UI customizations like using 144 // the Android app's theme color, and the three dot menu in 145 // CustomTabToolbarview. 146 TYPE_CUSTOM_TAB, 147 #endif 148 // If you add a new type, consider updating the test 149 // BrowserTest.StartMaximized. 150 }; 151 152 // Possible elements of the Browser window. 153 enum WindowFeature { 154 FEATURE_NONE = 0, 155 FEATURE_TITLEBAR = 1 << 0, 156 FEATURE_TABSTRIP = 1 << 1, 157 FEATURE_TOOLBAR = 1 << 2, 158 FEATURE_LOCATIONBAR = 1 << 3, 159 FEATURE_BOOKMARKBAR = 1 << 4, 160 // TODO(crbug.com/992834): Add FEATURE_PAGECONTROLS to describe the presence 161 // of per-page controls such as Content Settings Icons, which should be 162 // decoupled from FEATURE_LOCATIONBAR as they have independent presence in 163 // Web App browsers. 164 }; 165 166 // The context for a download blocked notification from 167 // OkToCloseWithInProgressDownloads. 168 enum class DownloadCloseType { 169 // Browser close is not blocked by download state. 170 kOk, 171 172 // The browser is shutting down and there are active downloads 173 // that would be cancelled. 174 kBrowserShutdown, 175 176 // There are active downloads associated with this incognito profile 177 // that would be canceled. 178 kLastWindowInIncognitoProfile, 179 180 // There are active downloads associated with this guest session 181 // that would be canceled. 182 kLastWindowInGuestSession, 183 }; 184 185 // Represents the result of the user being warned before closing the browser. 186 // See WarnBeforeClosingCallback and WarnBeforeClosing() below. 187 enum class WarnBeforeClosingResult { kOkToClose, kDoNotClose }; 188 189 // Represents the result of a browser creation request. 190 enum class BrowserCreationStatus { 191 kOk, 192 kErrorNoProcess, 193 kErrorProfileUnsuitable, 194 kErrorLoadingKiosk, 195 }; 196 197 // Callback that receives the result of a user being warned about closing a 198 // browser window (for example, if closing the window would interrupt a 199 // download). The parameter is whether the close should proceed. 200 using WarnBeforeClosingCallback = 201 base::OnceCallback<void(WarnBeforeClosingResult)>; 202 203 struct CreateParams { 204 explicit CreateParams(Profile* profile, bool user_gesture); 205 CreateParams(Type type, Profile* profile, bool user_gesture); 206 CreateParams(const CreateParams& other); 207 208 static CreateParams CreateForApp(const std::string& app_name, 209 bool trusted_source, 210 const gfx::Rect& window_bounds, 211 Profile* profile, 212 bool user_gesture); 213 214 static CreateParams CreateForAppPopup(const std::string& app_name, 215 bool trusted_source, 216 const gfx::Rect& window_bounds, 217 Profile* profile, 218 bool user_gesture); 219 220 static CreateParams CreateForDevTools(Profile* profile); 221 222 // The browser type. 223 Type type; 224 225 // The associated profile. 226 Profile* profile; 227 228 // Specifies the browser is_trusted_source_ value. 229 bool trusted_source = false; 230 231 // The bounds of the window to open. 232 gfx::Rect initial_bounds; 233 234 // The workspace the window should open in, if the platform supports it. 235 std::string initial_workspace; 236 237 ui::WindowShowState initial_show_state = ui::SHOW_STATE_DEFAULT; 238 239 bool is_session_restore = false; 240 241 bool is_focus_mode = false; 242 243 // Whether this browser was created by a user gesture. We track this 244 // specifically for the multi-user case in chromeos where we can place 245 // windows generated by user gestures differently from ones 246 // programmatically created. 247 bool user_gesture; 248 249 // True if the app is resizeable. 250 bool can_resize; 251 252 // Whether this browser was created specifically for dragged tab(s). 253 bool in_tab_dragging = false; 254 255 // Supply a custom BrowserWindow implementation, to be used instead of the 256 // default. Intended for testing. 257 BrowserWindow* window = nullptr; 258 259 // User-set title of this browser window, if there is one. 260 std::string user_title; 261 262 private: 263 friend class Browser; 264 friend class WindowSizerChromeOSTest; 265 266 static CreateParams CreateForAppBase(bool is_popup, 267 const std::string& app_name, 268 bool trusted_source, 269 const gfx::Rect& window_bounds, 270 Profile* profile, 271 bool user_gesture); 272 273 // The application name that is also the name of the window to the shell. 274 // Do not set this value directly, use CreateForApp/CreateForAppPopup. 275 // This name will be set for: 276 // 1) v1 applications launched via an application shortcut or extension API. 277 // 2) undocked devtool windows. 278 // 3) popup windows spawned from v1 applications. 279 std::string app_name; 280 281 // When set to true, skip initializing |window_| and everything that depends 282 // on it. 283 bool skip_window_init_for_testing = false; 284 }; 285 286 // Constructors, Creation, Showing ////////////////////////////////////////// 287 288 // Creates a browser instance with the provided params. 289 // Crashes if the requested browser creation is not allowed. 290 // For example, browser creation will not be allowed for profiles that 291 // disallow browsing (like sign-in profile on Chrome OS). 292 // 293 // Unless |params->window| is specified, a new BrowserWindow will be created 294 // for the browser - the created BrowserWindow will take the ownership of the 295 // created Browser instance. 296 // 297 // If |params.window| or |params.skip_window_init_for_testing| are set, the 298 // caller is expected to take the ownership of the created Browser instance. 299 static Browser* Create(const CreateParams& params); 300 301 // Returns whether a browser window can be created for the specified profile. 302 static BrowserCreationStatus GetBrowserCreationStatusForProfile( 303 Profile* profile); 304 305 ~Browser() override; 306 307 // Set overrides for the initial window bounds and maximized state. set_override_bounds(const gfx::Rect & bounds)308 void set_override_bounds(const gfx::Rect& bounds) { 309 override_bounds_ = bounds; 310 } initial_show_state()311 ui::WindowShowState initial_show_state() const { return initial_show_state_; } set_initial_show_state(ui::WindowShowState initial_show_state)312 void set_initial_show_state(ui::WindowShowState initial_show_state) { 313 initial_show_state_ = initial_show_state; 314 } 315 // Return true if the initial window bounds have been overridden. bounds_overridden()316 bool bounds_overridden() const { return !override_bounds_.IsEmpty(); } 317 // Set indicator that this browser is being created via session restore. 318 // This is used on the Mac (only) to determine animation style when the 319 // browser window is shown. set_is_session_restore(bool is_session_restore)320 void set_is_session_restore(bool is_session_restore) { 321 is_session_restore_ = is_session_restore; 322 } is_session_restore()323 bool is_session_restore() const { return is_session_restore_; } 324 is_focus_mode()325 bool is_focus_mode() const { return is_focus_mode_; } 326 327 // Accessors //////////////////////////////////////////////////////////////// 328 create_params()329 const CreateParams& create_params() const { return create_params_; } type()330 Type type() const { return type_; } app_name()331 const std::string& app_name() const { return app_name_; } user_title()332 const std::string& user_title() const { return user_title_; } is_trusted_source()333 bool is_trusted_source() const { return is_trusted_source_; } profile()334 Profile* profile() const { return profile_; } override_bounds()335 gfx::Rect override_bounds() const { return override_bounds_; } initial_workspace()336 const std::string& initial_workspace() const { return initial_workspace_; } 337 338 // |window()| will return NULL if called before |CreateBrowserWindow()| 339 // is done. window()340 BrowserWindow* window() const { return window_; } location_bar_model()341 LocationBarModel* location_bar_model() { return location_bar_model_.get(); } location_bar_model()342 const LocationBarModel* location_bar_model() const { 343 return location_bar_model_.get(); 344 } 345 #if defined(UNIT_TEST) swap_location_bar_models(std::unique_ptr<LocationBarModel> * location_bar_model)346 void swap_location_bar_models( 347 std::unique_ptr<LocationBarModel>* location_bar_model) { 348 location_bar_model->swap(location_bar_model_); 349 } 350 #endif 351 352 // Never nullptr. tab_strip_model()353 TabStripModel* tab_strip_model() const { return tab_strip_model_.get(); } 354 command_controller()355 chrome::BrowserCommandController* command_controller() { 356 return command_controller_.get(); 357 } session_id()358 const SessionID& session_id() const { return session_id_; } 359 BrowserContentSettingBubbleModelDelegate* content_setting_bubble_model_delegate()360 content_setting_bubble_model_delegate() { 361 return content_setting_bubble_model_delegate_.get(); 362 } live_tab_context()363 BrowserLiveTabContext* live_tab_context() { return live_tab_context_.get(); } synced_window_delegate()364 BrowserSyncedWindowDelegate* synced_window_delegate() { 365 return synced_window_delegate_.get(); 366 } instant_controller()367 BrowserInstantController* instant_controller() { 368 return instant_controller_.get(); 369 } app_controller()370 const web_app::AppBrowserController* app_controller() const { 371 return app_controller_.get(); 372 } app_controller()373 web_app::AppBrowserController* app_controller() { 374 return app_controller_.get(); 375 } signin_view_controller()376 SigninViewController* signin_view_controller() { 377 return &signin_view_controller_; 378 } 379 380 // Get the FindBarController for this browser, creating it if it does not 381 // yet exist. 382 FindBarController* GetFindBarController(); 383 384 // Returns true if a FindBarController exists for this browser. 385 bool HasFindBarController() const; 386 387 // Returns the state of the bookmark bar. bookmark_bar_state()388 BookmarkBar::State bookmark_bar_state() const { return bookmark_bar_state_; } 389 390 // State Storage and Retrieval for UI /////////////////////////////////////// 391 392 GURL GetNewTabURL() const; 393 394 // Gets the Favicon of the page in the selected tab. 395 gfx::Image GetCurrentPageIcon() const; 396 397 // Gets the title of the window based on the selected tab's title. 398 // Disables additional formatting when |include_app_name| is false or if the 399 // window is an app window. 400 base::string16 GetWindowTitleForCurrentTab(bool include_app_name) const; 401 402 // Gets the window title of the tab at |index|. 403 // Disables additional formatting when |include_app_name| is false or if the 404 // window is an app window. 405 base::string16 GetWindowTitleForTab(bool include_app_name, int index) const; 406 407 // Gets a list of window titles for the "Move to another window" menu. 408 std::vector<base::string16> GetExistingWindowsForMoveMenu(); 409 410 // Gets the window title from the provided WebContents. 411 // Disables additional formatting when |include_app_name| is false or if the 412 // window is an app window. 413 base::string16 GetWindowTitleFromWebContents( 414 bool include_app_name, 415 content::WebContents* contents) const; 416 417 // Prepares a title string for display (removes embedded newlines, etc). 418 static base::string16 FormatTitleForDisplay(base::string16 title); 419 420 // OnBeforeUnload handling ////////////////////////////////////////////////// 421 422 // Displays any necessary warnings to the user on taking an action that might 423 // close the browser (for example, warning if there are downloads in progress 424 // that would be interrupted). 425 // 426 // Distinct from ShouldCloseWindow() (which calls this method) because this 427 // method does not consider beforeunload handler, only things the user should 428 // be prompted about. 429 // 430 // If no warnings are needed, the method returns kOkToClose, indicating that 431 // the close can proceed immediately, and the callback is not called. If the 432 // method returns kDoNotClose, closing should be handled by |warn_callback| 433 // (and then only if the callback receives the kOkToClose value). 434 WarnBeforeClosingResult MaybeWarnBeforeClosing( 435 WarnBeforeClosingCallback warn_callback); 436 437 // Gives beforeunload handlers the chance to cancel the close. Returns whether 438 // to proceed with the close. If called while the process begun by 439 // TryToCloseWindow is in progress, returns false without taking action. 440 // 441 // If you don't care about beforeunload handlers and just want to prompt the 442 // user that they might lose an in-progress operation, call 443 // MaybeWarnBeforeClosing() instead (ShouldCloseWindow() also calls this 444 // method). 445 bool ShouldCloseWindow(); 446 447 // Begins the process of confirming whether the associated browser can be 448 // closed. If there are no tabs with beforeunload handlers it will immediately 449 // return false. If |skip_beforeunload| is true, all beforeunload 450 // handlers will be skipped and window closing will be confirmed without 451 // showing the prompt, the function will return false as well. 452 // Otherwise, it starts prompting the user, returns true and will call 453 // |on_close_confirmed| with the result of the user's decision. 454 // After calling this function, if the window will not be closed, call 455 // ResetBeforeUnloadHandlers() to reset all beforeunload handlers; calling 456 // this function multiple times without an intervening call to 457 // ResetTryToCloseWindow() will run only the beforeunload handlers 458 // registered since the previous call. 459 // Note that if the browser window has been used before, users should always 460 // have a chance to save their work before the window is closed without 461 // triggering beforeunload event. 462 bool TryToCloseWindow(bool skip_beforeunload, 463 const base::Callback<void(bool)>& on_close_confirmed); 464 465 // Clears the results of any beforeunload confirmation dialogs triggered by a 466 // TryToCloseWindow call. 467 void ResetTryToCloseWindow(); 468 469 // Figure out if there are tabs that have beforeunload handlers. 470 // It starts beforeunload/unload processing as a side-effect. 471 bool TabsNeedBeforeUnloadFired(); 472 473 bool IsAttemptingToCloseBrowser() const; 474 475 // Invoked when the window containing us is closing. Performs the necessary 476 // cleanup. 477 void OnWindowClosing(); 478 479 // In-progress download termination handling ///////////////////////////////// 480 481 // Indicates whether or not this browser window can be closed, or 482 // would be blocked by in-progress downloads. 483 // If executing downloads would be cancelled by this window close, 484 // then |*num_downloads_blocking| is updated with how many downloads 485 // would be canceled if the close continued. 486 DownloadCloseType OkToCloseWithInProgressDownloads( 487 int* num_downloads_blocking) const; 488 489 // External state change handling //////////////////////////////////////////// 490 491 // Invoked at the end of a fullscreen transition. 492 void WindowFullscreenStateChanged(); 493 494 // Only used on Mac. Called when the top ui style has been changed since this 495 // may trigger bookmark bar state change. 496 void FullscreenTopUIStateChanged(); 497 498 void OnFindBarVisibilityChanged(); 499 500 // Assorted browser commands //////////////////////////////////////////////// 501 502 // NOTE: Within each of the following sections, the IDs are ordered roughly by 503 // how they appear in the GUI/menus (left to right, top to bottom, etc.). 504 505 // See the description of 506 // FullscreenController::ToggleFullscreenModeWithExtension. 507 void ToggleFullscreenModeWithExtension(const GURL& extension_url); 508 509 // Returns true if the Browser supports the specified feature. The value of 510 // this varies during the lifetime of the browser. For example, if the window 511 // is fullscreen this may return a different value. If you only care about 512 // whether or not it's possible for the browser to support a particular 513 // feature use |CanSupportWindowFeature|. 514 bool SupportsWindowFeature(WindowFeature feature) const; 515 516 // Returns true if the Browser can support the specified feature. See comment 517 // in |SupportsWindowFeature| for details on this. 518 bool CanSupportWindowFeature(WindowFeature feature) const; 519 520 // Show various bits of UI 521 void OpenFile(); 522 523 void UpdateDownloadShelfVisibility(bool visible); 524 525 // Whether the specified WebContents can be reloaded. 526 // Reloading can be disabled e.g. for the DevTools window. 527 bool CanReloadContents(content::WebContents* web_contents) const; 528 529 // Whether the specified WebContents can be saved. 530 // Saving can be disabled e.g. for the DevTools window. 531 bool CanSaveContents(content::WebContents* web_contents) const; 532 533 std::unique_ptr<content::WebContents> SwapWebContents( 534 content::WebContents* old_contents, 535 std::unique_ptr<content::WebContents> new_contents); 536 537 // Move tabs to the browser at an index in the list previously returned by 538 // GetExistingWindowsForMoveMenu. 539 void MoveTabsToExistingWindow(const std::vector<int> tab_indices, 540 int browser_index); 541 542 // Returns whether favicon should be shown. 543 bool ShouldDisplayFavicon(content::WebContents* web_contents) const; 544 545 ///////////////////////////////////////////////////////////////////////////// 546 547 // Called by Navigate() when a navigation has occurred in a tab in 548 // this Browser. Updates the UI for the start of this navigation. 549 void UpdateUIForNavigationInTab(content::WebContents* contents, 550 ui::PageTransition transition, 551 NavigateParams::WindowAction action, 552 bool user_initiated); 553 554 // Used to register a KeepAlive to affect the Chrome lifetime. The KeepAlive 555 // is registered when the browser is added to the browser list, and unregisted 556 // when it is removed from it. 557 void RegisterKeepAlive(); 558 void UnregisterKeepAlive(); 559 560 // Interface implementations //////////////////////////////////////////////// 561 562 // Overridden from content::PageNavigator: 563 content::WebContents* OpenURL(const content::OpenURLParams& params) override; 564 565 // Overridden from TabStripModelObserver: 566 void OnTabStripModelChanged( 567 TabStripModel* tab_strip_model, 568 const TabStripModelChange& change, 569 const TabStripSelectionChange& selection) override; 570 void OnTabGroupChanged(const TabGroupChange& change) override; 571 void TabPinnedStateChanged(TabStripModel* tab_strip_model, 572 content::WebContents* contents, 573 int index) override; 574 void TabGroupedStateChanged(base::Optional<tab_groups::TabGroupId> group, 575 content::WebContents* contents, 576 int index) override; 577 void TabStripEmpty() override; 578 579 // Overridden from content::WebContentsDelegate: 580 void SetTopControlsShownRatio(content::WebContents* web_contents, 581 float ratio) override; 582 int GetTopControlsHeight() override; 583 bool DoBrowserControlsShrinkRendererSize( 584 content::WebContents* contents) override; 585 void SetTopControlsGestureScrollInProgress(bool in_progress) override; 586 bool CanOverscrollContent() override; 587 bool ShouldPreserveAbortedURLs(content::WebContents* source) override; 588 void SetFocusToLocationBar() override; 589 content::KeyboardEventProcessingResult PreHandleKeyboardEvent( 590 content::WebContents* source, 591 const content::NativeWebKeyboardEvent& event) override; 592 bool HandleKeyboardEvent( 593 content::WebContents* source, 594 const content::NativeWebKeyboardEvent& event) override; 595 bool PreHandleGestureEvent(content::WebContents* source, 596 const blink::WebGestureEvent& event) override; 597 bool CanDragEnter(content::WebContents* source, 598 const content::DropData& data, 599 blink::DragOperationsMask operations_allowed) override; 600 blink::SecurityStyle GetSecurityStyle( 601 content::WebContents* web_contents, 602 content::SecurityStyleExplanations* security_style_explanations) override; 603 void CreateSmsPrompt(content::RenderFrameHost*, 604 const url::Origin&, 605 const std::string& one_time_code, 606 base::OnceClosure on_confirm, 607 base::OnceClosure on_cancel) override; 608 void PassiveInsecureContentFound(const GURL& resource_url) override; 609 bool ShouldAllowRunningInsecureContent(content::WebContents* web_contents, 610 bool allowed_per_prefs, 611 const url::Origin& origin, 612 const GURL& resource_url) override; 613 void OnDidBlockNavigation( 614 content::WebContents* web_contents, 615 const GURL& blocked_url, 616 const GURL& initiator_url, 617 blink::mojom::NavigationBlockedReason reason) override; 618 content::PictureInPictureResult EnterPictureInPicture( 619 content::WebContents* web_contents, 620 const viz::SurfaceId&, 621 const gfx::Size&) override; 622 void ExitPictureInPicture() override; 623 std::unique_ptr<content::WebContents> ActivatePortalWebContents( 624 content::WebContents* predecessor_contents, 625 std::unique_ptr<content::WebContents> portal_contents) override; 626 void UpdateInspectedWebContentsIfNecessary( 627 content::WebContents* old_contents, 628 content::WebContents* new_contents, 629 base::OnceCallback<void()> callback) override; 630 bool ShouldShowStaleContentOnEviction(content::WebContents* source) override; 631 bool IsFrameLowPriority( 632 const content::WebContents* web_contents, 633 const content::RenderFrameHost* render_frame_host) override; 634 void MediaWatchTimeChanged( 635 const content::MediaPlayerWatchTime& watch_time) override; 636 base::WeakPtr<content::WebContentsDelegate> GetDelegateWeakPtr() override; 637 is_type_normal()638 bool is_type_normal() const { return type_ == TYPE_NORMAL; } is_type_popup()639 bool is_type_popup() const { return type_ == TYPE_POPUP; } is_type_app()640 bool is_type_app() const { return type_ == TYPE_APP; } is_type_app_popup()641 bool is_type_app_popup() const { return type_ == TYPE_APP_POPUP; } is_type_devtools()642 bool is_type_devtools() const { return type_ == TYPE_DEVTOOLS; } 643 #if defined(OS_CHROMEOS) is_type_custom_tab()644 bool is_type_custom_tab() const { return type_ == TYPE_CUSTOM_TAB; } 645 #endif 646 // TODO(crbug.com/990158): |deprecated_is_app()| is added for backwards 647 // compatibility for previous callers to |is_app()| which returned true when 648 // |app_name_| is non-empty. This includes TYPE_APP, TYPE_DEVTOOLS and 649 // TYPE_APP_POPUP. Existing callers should change to use the appropriate 650 // is_type_* functions. deprecated_is_app()651 bool deprecated_is_app() const { 652 return type_ == TYPE_APP || type_ == TYPE_DEVTOOLS || 653 type_ == TYPE_APP_POPUP; 654 } 655 656 // True if the browser is resizeable. can_resize()657 bool can_resize() const { return create_params_.can_resize; } 658 659 // True when the mouse cursor is locked. 660 bool IsMouseLocked() const; 661 662 // Called each time the browser window is shown. 663 void OnWindowDidShow(); 664 exclusive_access_manager()665 ExclusiveAccessManager* exclusive_access_manager() { 666 return exclusive_access_manager_.get(); 667 } 668 extension_window_controller()669 extensions::BrowserExtensionWindowController* extension_window_controller() 670 const { 671 return extension_window_controller_.get(); 672 } 673 674 bool ShouldRunUnloadListenerBeforeClosing(content::WebContents* web_contents); 675 bool RunUnloadListenerBeforeClosing(content::WebContents* web_contents); 676 677 // Set if the browser is currently participating in a tab dragging process. 678 // This information is used to decide if fast resize will be used during 679 // dragging. 680 void SetIsInTabDragging(bool is_in_tab_dragging); 681 682 // Sets the browser's user title. Setting it to an empty string clears it. 683 void SetWindowUserTitle(const std::string& user_title); 684 685 private: 686 friend class BrowserTest; 687 friend class ExclusiveAccessTest; 688 friend class FullscreenControllerInteractiveTest; 689 FRIEND_TEST_ALL_PREFIXES(AppModeTest, EnableAppModeTest); 690 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest, 691 IsReservedCommandOrKeyIsApp); 692 FRIEND_TEST_ALL_PREFIXES(BrowserCloseTest, LastIncognito); 693 FRIEND_TEST_ALL_PREFIXES(BrowserCloseTest, LastRegular); 694 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest, AppFullScreen); 695 FRIEND_TEST_ALL_PREFIXES(BrowserTest, OpenAppWindowLikeNtp); 696 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch); 697 FRIEND_TEST_ALL_PREFIXES(ExclusiveAccessBubbleWindowControllerTest, 698 DenyExitsFullscreen); 699 FRIEND_TEST_ALL_PREFIXES(ExclusiveAccessTest, 700 TabEntersPresentationModeFromWindowed); 701 FRIEND_TEST_ALL_PREFIXES(GuestBrowserCloseTest, LastGuest); 702 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref); 703 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, 704 OpenAppShortcutWindowPref); 705 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref); 706 707 // Used to describe why a tab is being detached. This is used by 708 // TabDetachedAtImpl. 709 enum DetachType { 710 // Result of TabDetachedAt. 711 DETACH_TYPE_DETACH, 712 713 // Result of TabReplacedAt. 714 DETACH_TYPE_REPLACE, 715 716 // Result of the tab strip not having any significant tabs. 717 DETACH_TYPE_EMPTY 718 }; 719 720 // Describes where the bookmark bar state change originated from. 721 enum BookmarkBarStateChangeReason { 722 // From the constructor. 723 BOOKMARK_BAR_STATE_CHANGE_INIT, 724 725 // Change is the result of the active tab changing. 726 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH, 727 728 // Change is the result of the bookmark bar pref changing. 729 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE, 730 731 // Change is the result of a state change in the active tab. 732 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE, 733 734 // Change is the result of window toggling in/out of fullscreen mode. 735 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN, 736 737 // Change is the result of switching the option of showing toolbar in full 738 // screen. Only used on Mac. 739 BOOKMARK_BAR_STATE_CHANGE_TOOLBAR_OPTION_CHANGE, 740 }; 741 742 explicit Browser(const CreateParams& params); 743 744 // Overridden from content::WebContentsDelegate: 745 content::WebContents* OpenURLFromTab( 746 content::WebContents* source, 747 const content::OpenURLParams& params) override; 748 void NavigationStateChanged(content::WebContents* source, 749 content::InvalidateTypes changed_flags) override; 750 void VisibleSecurityStateChanged(content::WebContents* source) override; 751 void AddNewContents(content::WebContents* source, 752 std::unique_ptr<content::WebContents> new_contents, 753 const GURL& target_url, 754 WindowOpenDisposition disposition, 755 const gfx::Rect& initial_rect, 756 bool user_gesture, 757 bool* was_blocked) override; 758 void ActivateContents(content::WebContents* contents) override; 759 void LoadingStateChanged(content::WebContents* source, 760 bool to_different_document) override; 761 void CloseContents(content::WebContents* source) override; 762 void SetContentsBounds(content::WebContents* source, 763 const gfx::Rect& bounds) override; 764 void UpdateTargetURL(content::WebContents* source, const GURL& url) override; 765 void ContentsMouseEvent(content::WebContents* source, 766 bool motion, 767 bool exited) override; 768 void ContentsZoomChange(bool zoom_in) override; 769 bool TakeFocus(content::WebContents* source, bool reverse) override; 770 void BeforeUnloadFired(content::WebContents* source, 771 bool proceed, 772 bool* proceed_to_fire_unload) override; 773 bool ShouldFocusLocationBarByDefault(content::WebContents* source) override; 774 void ShowRepostFormWarningDialog(content::WebContents* source) override; 775 bool IsWebContentsCreationOverridden( 776 content::SiteInstance* source_site_instance, 777 content::mojom::WindowContainerType window_container_type, 778 const GURL& opener_url, 779 const std::string& frame_name, 780 const GURL& target_url) override; 781 content::WebContents* CreateCustomWebContents( 782 content::RenderFrameHost* opener, 783 content::SiteInstance* source_site_instance, 784 bool is_new_browsing_instance, 785 const GURL& opener_url, 786 const std::string& frame_name, 787 const GURL& target_url, 788 const std::string& partition_id, 789 content::SessionStorageNamespace* session_storage_namespace) override; 790 void WebContentsCreated(content::WebContents* source_contents, 791 int opener_render_process_id, 792 int opener_render_frame_id, 793 const std::string& frame_name, 794 const GURL& target_url, 795 content::WebContents* new_contents) override; 796 void PortalWebContentsCreated( 797 content::WebContents* portal_web_contents) override; 798 void WebContentsBecamePortal( 799 content::WebContents* portal_web_contents) override; 800 void RendererUnresponsive( 801 content::WebContents* source, 802 content::RenderWidgetHost* render_widget_host, 803 base::RepeatingClosure hang_monitor_restarter) override; 804 void RendererResponsive( 805 content::WebContents* source, 806 content::RenderWidgetHost* render_widget_host) override; 807 void DidNavigateMainFramePostCommit( 808 content::WebContents* web_contents) override; 809 content::JavaScriptDialogManager* GetJavaScriptDialogManager( 810 content::WebContents* source) override; 811 bool GuestSaveFrame(content::WebContents* guest_web_contents) override; 812 content::ColorChooser* OpenColorChooser( 813 content::WebContents* web_contents, 814 SkColor color, 815 const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions) 816 override; 817 std::unique_ptr<content::EyeDropper> OpenEyeDropper( 818 content::RenderFrameHost* frame, 819 content::EyeDropperListener* listener) override; 820 void RunFileChooser(content::RenderFrameHost* render_frame_host, 821 scoped_refptr<content::FileSelectListener> listener, 822 const blink::mojom::FileChooserParams& params) override; 823 void EnumerateDirectory(content::WebContents* web_contents, 824 scoped_refptr<content::FileSelectListener> listener, 825 const base::FilePath& path) override; 826 void EnterFullscreenModeForTab( 827 content::RenderFrameHost* requesting_frame, 828 const blink::mojom::FullscreenOptions& options) override; 829 void ExitFullscreenModeForTab(content::WebContents* web_contents) override; 830 bool IsFullscreenForTabOrPending( 831 const content::WebContents* web_contents) override; 832 blink::mojom::DisplayMode GetDisplayMode( 833 const content::WebContents* web_contents) override; 834 blink::ProtocolHandlerSecurityLevel GetProtocolHandlerSecurityLevel( 835 content::RenderFrameHost* requesting_frame) override; 836 void RegisterProtocolHandler(content::RenderFrameHost* requesting_frame, 837 const std::string& protocol, 838 const GURL& url, 839 bool user_gesture) override; 840 void UnregisterProtocolHandler(content::RenderFrameHost* requesting_frame, 841 const std::string& protocol, 842 const GURL& url, 843 bool user_gesture) override; 844 void FindReply(content::WebContents* web_contents, 845 int request_id, 846 int number_of_matches, 847 const gfx::Rect& selection_rect, 848 int active_match_ordinal, 849 bool final_update) override; 850 void RequestToLockMouse(content::WebContents* web_contents, 851 bool user_gesture, 852 bool last_unlocked_by_target) override; 853 void LostMouseLock() override; 854 void RequestKeyboardLock(content::WebContents* web_contents, 855 bool esc_key_locked) override; 856 void CancelKeyboardLockRequest(content::WebContents* web_contents) override; 857 void RequestMediaAccessPermission( 858 content::WebContents* web_contents, 859 const content::MediaStreamRequest& request, 860 content::MediaResponseCallback callback) override; 861 bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host, 862 const GURL& security_origin, 863 blink::mojom::MediaStreamType type) override; 864 std::string GetDefaultMediaDeviceID( 865 content::WebContents* web_contents, 866 blink::mojom::MediaStreamType type) override; 867 void RequestPpapiBrokerPermission( 868 content::WebContents* web_contents, 869 const GURL& url, 870 const base::FilePath& plugin_path, 871 base::OnceCallback<void(bool)> callback) override; 872 873 #if BUILDFLAG(ENABLE_PRINTING) 874 void PrintCrossProcessSubframe( 875 content::WebContents* web_contents, 876 const gfx::Rect& rect, 877 int document_cookie, 878 content::RenderFrameHost* subframe_host) const override; 879 #endif 880 881 #if BUILDFLAG(ENABLE_PAINT_PREVIEW) 882 void CapturePaintPreviewOfSubframe( 883 content::WebContents* web_contents, 884 const gfx::Rect& rect, 885 const base::UnguessableToken& guid, 886 content::RenderFrameHost* render_frame_host) override; 887 #endif 888 889 // Overridden from WebContentsModalDialogManagerDelegate: 890 void SetWebContentsBlocked(content::WebContents* web_contents, 891 bool blocked) override; 892 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost() 893 override; 894 895 // Overridden from BookmarkTabHelperObserver: 896 void URLStarredChanged(content::WebContents* web_contents, 897 bool starred) override; 898 899 // Overridden from ZoomObserver: 900 void OnZoomChanged( 901 const zoom::ZoomController::ZoomChangedEventData& data) override; 902 903 // Overridden from SelectFileDialog::Listener: 904 void FileSelected(const base::FilePath& path, 905 int index, 906 void* params) override; 907 void FileSelectedWithExtraInfo(const ui::SelectedFileInfo& file_info, 908 int index, 909 void* params) override; 910 void FileSelectionCanceled(void* params) override; 911 912 // Overridden from content::NotificationObserver: 913 void Observe(int type, 914 const content::NotificationSource& source, 915 const content::NotificationDetails& details) override; 916 917 // Overridden from translate::ContentTranslateDriver::Observer: 918 void OnIsPageTranslatedChanged(content::WebContents* source) override; 919 void OnTranslateEnabledChanged(content::WebContents* source) override; 920 921 // Command and state updating /////////////////////////////////////////////// 922 923 // Handle changes to tab strip model. 924 void OnTabInsertedAt(content::WebContents* contents, int index); 925 void OnTabClosing(content::WebContents* contents); 926 void OnTabDetached(content::WebContents* contents, bool was_active); 927 void OnTabDeactivated(content::WebContents* contents); 928 void OnActiveTabChanged(content::WebContents* old_contents, 929 content::WebContents* new_contents, 930 int index, 931 int reason); 932 void OnTabMoved(int from_index, int to_index); 933 void OnTabReplacedAt(content::WebContents* old_contents, 934 content::WebContents* new_contents, 935 int index); 936 937 // Handle changes to kDevToolsAvailability preference. 938 void OnDevToolsAvailabilityChanged(); 939 940 // UI update coalescing and handling //////////////////////////////////////// 941 942 // Asks the toolbar (and as such the location bar) to update its state to 943 // reflect the current tab's current URL, security state, etc. 944 // If |should_restore_state| is true, we're switching (back?) to this tab and 945 // should restore any previous location bar state (such as user editing) as 946 // well. 947 void UpdateToolbar(bool should_restore_state); 948 949 // Does one or both of the following for each bit in |changed_flags|: 950 // . If the update should be processed immediately, it is. 951 // . If the update should processed asynchronously (to avoid lots of ui 952 // updates), then scheduled_updates_ is updated for the |source| and update 953 // pair and a task is scheduled (assuming it isn't running already) 954 // that invokes ProcessPendingUIUpdates. 955 void ScheduleUIUpdate(content::WebContents* source, unsigned changed_flags); 956 957 // Processes all pending updates to the UI that have been scheduled by 958 // ScheduleUIUpdate in scheduled_updates_. 959 void ProcessPendingUIUpdates(); 960 961 // Removes all entries from scheduled_updates_ whose source is contents. 962 void RemoveScheduledUpdatesFor(content::WebContents* contents); 963 964 // Getters for UI /////////////////////////////////////////////////////////// 965 966 // TODO(beng): remove, and provide AutomationProvider a better way to access 967 // the LocationBarView's edit. 968 friend class AutomationProvider; 969 friend class BrowserProxy; 970 971 // Returns the StatusBubble from the current toolbar. It is possible for 972 // this to return NULL if called before the toolbar has initialized. 973 // TODO(beng): remove this. 974 StatusBubble* GetStatusBubble(); 975 976 // Session restore functions //////////////////////////////////////////////// 977 978 // Notifies the history database of the index for all tabs whose index is 979 // >= index. 980 void SyncHistoryWithTabs(int index); 981 982 // In-progress download termination handling ///////////////////////////////// 983 984 // Called when the window is closing to check if potential in-progress 985 // downloads should prevent it from closing. 986 // Returns true if the window can close, false otherwise. 987 bool CanCloseWithInProgressDownloads(); 988 989 // Called when the user has decided whether to proceed or not with the browser 990 // closure. |cancel_downloads| is true if the downloads should be canceled 991 // and the browser closed, false if the browser should stay open and the 992 // downloads running. 993 void InProgressDownloadResponse(bool cancel_downloads); 994 995 // Called when all warnings have completed when attempting to close the 996 // browser directly (e.g. via hotkey, close button, terminate signal, etc.) 997 // Used as a WarnBeforeClosingCallback by ShouldCloseWindow(). 998 void FinishWarnBeforeClosing(WarnBeforeClosingResult result); 999 1000 // Assorted utility functions /////////////////////////////////////////////// 1001 1002 // Sets the specified browser as the delegate of the WebContents and all the 1003 // associated tab helpers that are needed. If |set_delegate| is true, this 1004 // browser object is set as a delegate for |web_contents| components, else 1005 // is is removed as a delegate. 1006 void SetAsDelegate(content::WebContents* web_contents, bool set_delegate); 1007 1008 // Shows the Find Bar, optionally selecting the next entry that matches the 1009 // existing search string for that Tab. |forward_direction| controls the 1010 // search direction. 1011 void FindInPage(bool find_next, bool forward_direction); 1012 1013 // Closes the frame. 1014 // TODO(beng): figure out if we need this now that the frame itself closes 1015 // after a return to the message loop. 1016 void CloseFrame(); 1017 1018 void TabDetachedAtImpl(content::WebContents* contents, 1019 bool was_active, 1020 DetachType type); 1021 1022 // Updates the loading state for the window and tabstrip. 1023 void UpdateWindowForLoadingStateChanged(content::WebContents* source, 1024 bool to_different_document); 1025 1026 // Shared code between Reload() and ReloadBypassingCache(). 1027 void ReloadInternal(WindowOpenDisposition disposition, bool bypass_cache); 1028 1029 bool NormalBrowserSupportsWindowFeature(WindowFeature feature, 1030 bool check_can_support) const; 1031 1032 bool PopupBrowserSupportsWindowFeature(WindowFeature feature, 1033 bool check_can_support) const; 1034 1035 bool AppPopupBrowserSupportsWindowFeature(WindowFeature feature, 1036 bool check_can_support) const; 1037 1038 bool AppBrowserSupportsWindowFeature(WindowFeature feature, 1039 bool check_can_support) const; 1040 1041 #if defined(OS_CHROMEOS) 1042 bool CustomTabBrowserSupportsWindowFeature(WindowFeature feature) const; 1043 #endif 1044 1045 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If 1046 // |check_fullscreen| is true, the set of features reflect the actual state of 1047 // the browser, otherwise the set of features reflect the possible state of 1048 // the browser. 1049 bool SupportsWindowFeatureImpl(WindowFeature feature, 1050 bool check_fullscreen) const; 1051 1052 // Resets |bookmark_bar_state_| based on the active tab. Notifies the 1053 // BrowserWindow if necessary. 1054 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason); 1055 1056 bool ShouldShowBookmarkBar() const; 1057 1058 bool ShouldHideUIForFullscreen() const; 1059 1060 // Indicates if we have called BrowserList::NotifyBrowserCloseStarted for the 1061 // browser. 1062 bool IsBrowserClosing() const; 1063 1064 // Returns true if we can start the shutdown sequence for the browser, i.e. 1065 // the last browser window is being closed. 1066 bool ShouldStartShutdown() const; 1067 1068 // Returns true if a BackgroundContents should be created in response to a 1069 // WebContents::CreateNewWindow() call. 1070 bool ShouldCreateBackgroundContents( 1071 content::SiteInstance* source_site_instance, 1072 const GURL& opener_url, 1073 const std::string& frame_name); 1074 1075 // Creates a BackgroundContents. This should only be called when 1076 // ShouldCreateBackgroundContents() is true. 1077 BackgroundContents* CreateBackgroundContents( 1078 content::SiteInstance* source_site_instance, 1079 content::RenderFrameHost* opener, 1080 const GURL& opener_url, 1081 bool is_new_browsing_instance, 1082 const std::string& frame_name, 1083 const GURL& target_url, 1084 const std::string& partition_id, 1085 content::SessionStorageNamespace* session_storage_namespace); 1086 1087 // Gets the window title for the current tab, to display in a menu. If the 1088 // title is too long to fit in the required space, 1089 // the tab title will be elided. The result title might still be a larger 1090 // width than specified, as at least a few characters of the title are always 1091 // shown. 1092 base::string16 GetWindowTitleForMenu() const; 1093 1094 // Data members ///////////////////////////////////////////////////////////// 1095 1096 content::NotificationRegistrar registrar_; 1097 1098 PrefChangeRegistrar profile_pref_registrar_; 1099 1100 // This Browser's create params. 1101 const CreateParams create_params_; 1102 1103 // This Browser's type. 1104 const Type type_; 1105 1106 // This Browser's profile. 1107 Profile* const profile_; 1108 1109 // This Browser's window. 1110 BrowserWindow* window_; 1111 1112 std::unique_ptr<TabStripModelDelegate> const tab_strip_model_delegate_; 1113 std::unique_ptr<TabStripModel> const tab_strip_model_; 1114 1115 // The application name that is also the name of the window to the shell. 1116 // This name should be set when: 1117 // 1) we launch an application via an application shortcut or extension API. 1118 // 2) we launch an undocked devtool window. 1119 const std::string app_name_; 1120 1121 // True if the source is trusted (i.e. we do not need to show the URL in a 1122 // a popup window). Also used to determine which app windows to save and 1123 // restore on Chrome OS. 1124 bool is_trusted_source_; 1125 1126 // Whether this browser was created for focus mode. See https://crbug/932814. 1127 const bool is_focus_mode_; 1128 1129 // Unique identifier of this browser for session restore. This id is only 1130 // unique within the current session, and is not guaranteed to be unique 1131 // across sessions. 1132 const SessionID session_id_; 1133 1134 // The model for the toolbar view. 1135 std::unique_ptr<LocationBarModel> location_bar_model_; 1136 1137 // UI update coalescing and handling //////////////////////////////////////// 1138 1139 typedef std::map<const content::WebContents*, int> UpdateMap; 1140 1141 // Maps from WebContents to pending UI updates that need to be processed. 1142 // We don't update things like the URL or tab title right away to avoid 1143 // flickering and extra painting. 1144 // See ScheduleUIUpdate and ProcessPendingUIUpdates. 1145 UpdateMap scheduled_updates_; 1146 1147 // In-progress download termination handling ///////////////////////////////// 1148 1149 enum CancelDownloadConfirmationState { 1150 NOT_PROMPTED, // We have not asked the user. 1151 WAITING_FOR_RESPONSE, // We have asked the user and have not received a 1152 // reponse yet. 1153 RESPONSE_RECEIVED // The user was prompted and made a decision already. 1154 }; 1155 1156 // State used to figure-out whether we should prompt the user for confirmation 1157 // when the browser is closed with in-progress downloads. 1158 CancelDownloadConfirmationState cancel_download_confirmation_state_; 1159 1160 ///////////////////////////////////////////////////////////////////////////// 1161 1162 // Override values for the bounds of the window and its maximized or minimized 1163 // state. 1164 // These are supplied by callers that don't want to use the default values. 1165 // The default values are typically loaded from local state (last session), 1166 // obtained from the last window of the same type, or obtained from the 1167 // shell shortcut's startup info. 1168 gfx::Rect override_bounds_; 1169 ui::WindowShowState initial_show_state_; 1170 const std::string initial_workspace_; 1171 1172 // Tracks when this browser is being created by session restore. 1173 bool is_session_restore_; 1174 1175 base::TimeTicks focus_mode_start_time_; 1176 1177 UnloadController unload_controller_; 1178 1179 // The Find Bar. This may be NULL if there is no Find Bar, and if it is 1180 // non-NULL, it may or may not be visible. 1181 std::unique_ptr<FindBarController> find_bar_controller_; 1182 1183 // Dialog box used for opening and saving files. 1184 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; 1185 1186 // Helper which implements the ContentSettingBubbleModel interface. 1187 std::unique_ptr<BrowserContentSettingBubbleModelDelegate> 1188 content_setting_bubble_model_delegate_; 1189 1190 // Helper which implements the LocationBarModelDelegate interface. 1191 std::unique_ptr<BrowserLocationBarModelDelegate> location_bar_model_delegate_; 1192 1193 // Helper which implements the LiveTabContext interface. 1194 std::unique_ptr<BrowserLiveTabContext> live_tab_context_; 1195 1196 // Helper which implements the SyncedWindowDelegate interface. 1197 std::unique_ptr<BrowserSyncedWindowDelegate> synced_window_delegate_; 1198 1199 std::unique_ptr<BrowserInstantController> instant_controller_; 1200 1201 // Helper which handles bookmark app specific browser configuration. 1202 // This must be initialized before |command_controller_| to ensure the correct 1203 // set of commands are enabled. 1204 std::unique_ptr<web_app::AppBrowserController> app_controller_; 1205 1206 BookmarkBar::State bookmark_bar_state_; 1207 1208 std::unique_ptr<ExclusiveAccessManager> exclusive_access_manager_; 1209 1210 std::unique_ptr<extensions::BrowserExtensionWindowController> 1211 extension_window_controller_; 1212 1213 std::unique_ptr<chrome::BrowserCommandController> command_controller_; 1214 1215 // True if the browser window has been shown at least once. 1216 bool window_has_shown_; 1217 1218 std::string user_title_; 1219 1220 // Controls both signin and sync consent. 1221 SigninViewController signin_view_controller_; 1222 1223 std::unique_ptr<ScopedKeepAlive> keep_alive_; 1224 1225 WarnBeforeClosingCallback warn_before_closing_callback_; 1226 1227 #if BUILDFLAG(ENABLE_EXTENSIONS) 1228 std::unique_ptr<extensions::ExtensionBrowserWindowHelper> 1229 extension_browser_window_helper_; 1230 #endif 1231 1232 const base::ElapsedTimer creation_timer_; 1233 1234 // Stores the list of browser windows showing via a menu. 1235 std::vector<base::WeakPtr<Browser>> existing_browsers_for_menu_list_; 1236 1237 // The following factory is used for chrome update coalescing. 1238 base::WeakPtrFactory<Browser> chrome_updater_factory_{this}; 1239 1240 // The following factory is used to close the frame at a later time. 1241 base::WeakPtrFactory<Browser> weak_factory_{this}; 1242 1243 DISALLOW_COPY_AND_ASSIGN(Browser); 1244 }; 1245 1246 #endif // CHROME_BROWSER_UI_BROWSER_H_ 1247