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.
5 #ifndef CHROME_BROWSER_UI_BROWSER_H_
6 #define CHROME_BROWSER_UI_BROWSER_H_
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/scoped_observer.h"
21 #include "base/strings/string16.h"
22 #include "chrome/browser/devtools/devtools_toggle_action.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/search_tab_helper_delegate.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 "components/content_settings/core/common/content_settings.h"
35 #include "components/content_settings/core/common/content_settings_types.h"
36 #include "components/sessions/session_id.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_zoom.h"
42 #include "ui/base/page_transition_types.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"
48 #if defined(ENABLE_EXTENSIONS)
49 #include "extensions/browser/extension_registry_observer.h"
52 class BrowserContentSettingBubbleModelDelegate;
53 class BrowserContentTranslateDriverObserver;
54 class BrowserInstantController;
55 class BrowserSyncedWindowDelegate;
56 class BrowserToolbarModelDelegate;
57 class BrowserTabRestoreServiceDelegate;
59 class FindBarController;
60 class FullscreenController;
67 class TabStripModelDelegate;
68 struct WebApplicationInfo;
71 class BrowserCommandController;
72 class FastUnloadController;
73 class UnloadController;
74 class ValidationMessageBubble;
78 class NavigationController;
80 class SessionStorageNamespace;
83 namespace extensions {
85 class ExtensionRegistry;
86 class WindowController;
95 struct SelectedFileInfo;
96 class WebDialogDelegate;
101 class WebContentsModalDialogHost;
104 class Browser : public TabStripModelObserver,
105 public content::WebContentsDelegate,
106 public CoreTabHelperDelegate,
107 public SearchEngineTabHelperDelegate,
108 public SearchTabHelperDelegate,
109 public ChromeWebModalDialogManagerDelegate,
110 public BookmarkTabHelperDelegate,
112 public content::PageNavigator,
113 public content::NotificationObserver,
114 #if defined(ENABLE_EXTENSIONS)
115 public extensions::ExtensionRegistryObserver,
117 public ui::SelectFileDialog::Listener {
119 // SessionService::WindowType mirrors these values. If you add to this
120 // enum, look at SessionService::WindowType to see if it needs to be
123 // If you add a new type, consider updating the test
124 // BrowserTest.StartMaximized.
129 // Possible elements of the Browser window.
132 FEATURE_TITLEBAR = 1,
133 FEATURE_TABSTRIP = 2,
135 FEATURE_LOCATIONBAR = 8,
136 FEATURE_BOOKMARKBAR = 16,
137 FEATURE_INFOBAR = 32,
138 FEATURE_DOWNLOADSHELF = 64
141 // The context for a download blocked notification from
142 // OkToCloseWithInProgressDownloads.
143 enum DownloadClosePreventionType {
144 // Browser close is not blocked by download state.
147 // The browser is shutting down and there are active downloads
148 // that would be cancelled.
149 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN,
151 // There are active downloads associated with this incognito profile
152 // that would be canceled.
153 DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE,
156 struct CreateParams {
157 CreateParams(Profile* profile, chrome::HostDesktopType host_desktop_type);
158 CreateParams(Type type,
160 chrome::HostDesktopType host_desktop_type);
162 static CreateParams CreateForApp(const std::string& app_name,
164 const gfx::Rect& window_bounds,
166 chrome::HostDesktopType host_desktop_type);
168 static CreateParams CreateForDevTools(
170 chrome::HostDesktopType host_desktop_type);
175 // The associated profile.
178 // The host desktop the browser is created on.
179 chrome::HostDesktopType host_desktop_type;
181 // Specifies the browser is_trusted_source_ value.
184 // The bounds of the window to open.
185 gfx::Rect initial_bounds;
187 ui::WindowShowState initial_show_state;
189 bool is_session_restore;
191 // Supply a custom BrowserWindow implementation, to be used instead of the
192 // default. Intended for testing.
193 BrowserWindow* window;
196 friend class Browser;
198 // The application name that is also the name of the window to the shell.
199 // Do not set this value directly, use CreateForApp.
200 // This name will be set for:
201 // 1) v1 applications launched via an application shortcut or extension API.
202 // 2) undocked devtool windows.
203 // 3) popup windows spawned from v1 applications.
204 std::string app_name;
207 // Constructors, Creation, Showing //////////////////////////////////////////
209 explicit Browser(const CreateParams& params);
212 // Set overrides for the initial window bounds and maximized state.
213 void set_override_bounds(const gfx::Rect& bounds) {
214 override_bounds_ = bounds;
216 ui::WindowShowState initial_show_state() const { return initial_show_state_; }
217 void set_initial_show_state(ui::WindowShowState initial_show_state) {
218 initial_show_state_ = initial_show_state;
220 // Return true if the initial window bounds have been overridden.
221 bool bounds_overridden() const {
222 return !override_bounds_.IsEmpty();
224 // Set indicator that this browser is being created via session restore.
225 // This is used on the Mac (only) to determine animation style when the
226 // browser window is shown.
227 void set_is_session_restore(bool is_session_restore) {
228 is_session_restore_ = is_session_restore;
230 bool is_session_restore() const {
231 return is_session_restore_;
233 chrome::HostDesktopType host_desktop_type() const {
234 return host_desktop_type_;
237 // Accessors ////////////////////////////////////////////////////////////////
239 Type type() const { return type_; }
240 const std::string& app_name() const { return app_name_; }
241 bool is_trusted_source() const { return is_trusted_source_; }
242 Profile* profile() const { return profile_; }
243 gfx::Rect override_bounds() const { return override_bounds_; }
245 // |window()| will return NULL if called before |CreateBrowserWindow()|
247 BrowserWindow* window() const { return window_; }
248 ToolbarModel* toolbar_model() { return toolbar_model_.get(); }
249 const ToolbarModel* toolbar_model() const { return toolbar_model_.get(); }
250 #if defined(UNIT_TEST)
251 void swap_toolbar_models(scoped_ptr<ToolbarModel>* toolbar_model) {
252 toolbar_model->swap(toolbar_model_);
255 web_modal::PopupManager* popup_manager() {
256 return popup_manager_.get();
258 TabStripModel* tab_strip_model() const { return tab_strip_model_.get(); }
259 chrome::BrowserCommandController* command_controller() {
260 return command_controller_.get();
262 SearchModel* search_model() { return search_model_.get(); }
263 const SearchModel* search_model() const {
264 return search_model_.get();
266 SearchDelegate* search_delegate() {
267 return search_delegate_.get();
269 const SessionID& session_id() const { return session_id_; }
270 BrowserContentSettingBubbleModelDelegate*
271 content_setting_bubble_model_delegate() {
272 return content_setting_bubble_model_delegate_.get();
274 BrowserTabRestoreServiceDelegate* tab_restore_service_delegate() {
275 return tab_restore_service_delegate_.get();
277 BrowserSyncedWindowDelegate* synced_window_delegate() {
278 return synced_window_delegate_.get();
280 BrowserInstantController* instant_controller() {
281 return instant_controller_.get();
284 // Get the FindBarController for this browser, creating it if it does not
286 FindBarController* GetFindBarController();
288 // Returns true if a FindBarController exists for this browser.
289 bool HasFindBarController() const;
291 // Returns the state of the bookmark bar.
292 BookmarkBar::State bookmark_bar_state() const { return bookmark_bar_state_; }
294 // State Storage and Retrieval for UI ///////////////////////////////////////
296 // Gets the Favicon of the page in the selected tab.
297 gfx::Image GetCurrentPageIcon() const;
299 // Gets the title of the window based on the selected tab's title.
300 base::string16 GetWindowTitleForCurrentTab() const;
302 // Prepares a title string for display (removes embedded newlines, etc).
303 static void FormatTitleForDisplay(base::string16* title);
305 // OnBeforeUnload handling //////////////////////////////////////////////////
307 // Gives beforeunload handlers the chance to cancel the close. Returns whether
308 // to proceed with the close. If called while the process begun by
309 // CallBeforeUnloadHandlers is in progress, returns false without taking
311 bool ShouldCloseWindow();
313 // Begins the process of confirming whether the associated browser can be
314 // closed. If there are no tabs with beforeunload handlers it will immediately
315 // return false. Otherwise, it starts prompting the user, returns true and
316 // will call |on_close_confirmed| with the result of the user's decision.
317 // After calling this function, if the window will not be closed, call
318 // ResetBeforeUnloadHandlers() to reset all beforeunload handlers; calling
319 // this function multiple times without an intervening call to
320 // ResetBeforeUnloadHandlers() will run only the beforeunload handlers
321 // registered since the previous call.
322 bool CallBeforeUnloadHandlers(
323 const base::Callback<void(bool)>& on_close_confirmed);
325 // Clears the results of any beforeunload confirmation dialogs triggered by a
326 // CallBeforeUnloadHandlers call.
327 void ResetBeforeUnloadHandlers();
329 // Figure out if there are tabs that have beforeunload handlers.
330 // It starts beforeunload/unload processing as a side-effect.
331 bool TabsNeedBeforeUnloadFired();
333 // Returns true if all tabs' beforeunload/unload events have fired.
334 bool HasCompletedUnloadProcessing() const;
336 bool IsAttemptingToCloseBrowser() const;
338 // Invoked when the window containing us is closing. Performs the necessary
340 void OnWindowClosing();
342 // In-progress download termination handling /////////////////////////////////
344 // Called when the user has decided whether to proceed or not with the browser
345 // closure. |cancel_downloads| is true if the downloads should be canceled
346 // and the browser closed, false if the browser should stay open and the
347 // downloads running.
348 void InProgressDownloadResponse(bool cancel_downloads);
350 // Indicates whether or not this browser window can be closed, or
351 // would be blocked by in-progress downloads.
352 // If executing downloads would be cancelled by this window close,
353 // then |*num_downloads_blocking| is updated with how many downloads
354 // would be canceled if the close continued.
355 DownloadClosePreventionType OkToCloseWithInProgressDownloads(
356 int* num_downloads_blocking) const;
358 // External state change handling ////////////////////////////////////////////
360 // Invoked when the fullscreen state of the window changes.
361 // BrowserWindow::EnterFullscreen invokes this after the window has become
363 void WindowFullscreenStateChanged();
365 // Assorted browser commands ////////////////////////////////////////////////
367 // NOTE: Within each of the following sections, the IDs are ordered roughly by
368 // how they appear in the GUI/menus (left to right, top to bottom, etc.).
370 // See the description of
371 // FullscreenController::ToggleFullscreenModeWithExtension.
372 void ToggleFullscreenModeWithExtension(const GURL& extension_url);
375 // See the description of FullscreenController::ToggleMetroSnapMode.
376 void SetMetroSnapMode(bool enable);
379 // Returns true if the Browser supports the specified feature. The value of
380 // this varies during the lifetime of the browser. For example, if the window
381 // is fullscreen this may return a different value. If you only care about
382 // whether or not it's possible for the browser to support a particular
383 // feature use |CanSupportWindowFeature|.
384 bool SupportsWindowFeature(WindowFeature feature) const;
386 // Returns true if the Browser can support the specified feature. See comment
387 // in |SupportsWindowFeature| for details on this.
388 bool CanSupportWindowFeature(WindowFeature feature) const;
390 // TODO(port): port these, and re-merge the two function declaration lists.
391 // Page-related commands.
392 void ToggleEncodingAutoDetect();
393 void OverrideEncoding(int encoding_id);
395 // Show various bits of UI
398 void UpdateDownloadShelfVisibility(bool visible);
400 /////////////////////////////////////////////////////////////////////////////
402 // Called by chrome::Navigate() when a navigation has occurred in a tab in
403 // this Browser. Updates the UI for the start of this navigation.
404 void UpdateUIForNavigationInTab(content::WebContents* contents,
405 ui::PageTransition transition,
406 bool user_initiated);
408 // Interface implementations ////////////////////////////////////////////////
410 // Overridden from content::PageNavigator:
411 content::WebContents* OpenURL(const content::OpenURLParams& params) override;
413 // Overridden from TabStripModelObserver:
414 void TabInsertedAt(content::WebContents* contents,
416 bool foreground) override;
417 void TabClosingAt(TabStripModel* tab_strip_model,
418 content::WebContents* contents,
420 void TabDetachedAt(content::WebContents* contents, int index) override;
421 void TabDeactivated(content::WebContents* contents) override;
422 void ActiveTabChanged(content::WebContents* old_contents,
423 content::WebContents* new_contents,
425 int reason) override;
426 void TabMoved(content::WebContents* contents,
428 int to_index) override;
429 void TabReplacedAt(TabStripModel* tab_strip_model,
430 content::WebContents* old_contents,
431 content::WebContents* new_contents,
433 void TabPinnedStateChanged(content::WebContents* contents,
435 void TabStripEmpty() override;
437 // Overridden from content::WebContentsDelegate:
438 bool CanOverscrollContent() const override;
439 bool ShouldPreserveAbortedURLs(content::WebContents* source) override;
440 bool PreHandleKeyboardEvent(content::WebContents* source,
441 const content::NativeWebKeyboardEvent& event,
442 bool* is_keyboard_shortcut) override;
443 void HandleKeyboardEvent(
444 content::WebContents* source,
445 const content::NativeWebKeyboardEvent& event) override;
446 void ShowValidationMessage(content::WebContents* web_contents,
447 const gfx::Rect& anchor_in_root_view,
448 const base::string16& main_text,
449 const base::string16& sub_text) override;
450 void HideValidationMessage(content::WebContents* web_contents) override;
451 void MoveValidationMessage(content::WebContents* web_contents,
452 const gfx::Rect& anchor_in_root_view) override;
453 bool PreHandleGestureEvent(content::WebContents* source,
454 const blink::WebGestureEvent& event) override;
455 bool CanDragEnter(content::WebContents* source,
456 const content::DropData& data,
457 blink::WebDragOperationsMask operations_allowed) override;
459 bool is_type_tabbed() const { return type_ == TYPE_TABBED; }
460 bool is_type_popup() const { return type_ == TYPE_POPUP; }
463 bool is_devtools() const;
465 // True when the mouse cursor is locked.
466 bool IsMouseLocked() const;
468 // Called each time the browser window is shown.
469 void OnWindowDidShow();
471 // Show the first run search engine bubble on the location bar.
472 void ShowFirstRunBubble();
474 // Show a download on the download shelf.
475 void ShowDownload(content::DownloadItem* download);
477 FullscreenController* fullscreen_controller() const {
478 return fullscreen_controller_.get();
481 extensions::WindowController* extension_window_controller() const {
482 return extension_window_controller_.get();
486 friend class BrowserTest;
487 friend class FullscreenControllerInteractiveTest;
488 friend class FullscreenControllerTest;
489 FRIEND_TEST_ALL_PREFIXES(AppModeTest, EnableAppModeTest);
490 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest,
491 IsReservedCommandOrKeyIsApp);
492 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest, AppFullScreen);
493 FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups);
494 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ConvertTabToAppShortcut);
495 FRIEND_TEST_ALL_PREFIXES(BrowserTest, OpenAppWindowLikeNtp);
496 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch);
497 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ShouldShowLocationBar);
498 FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest,
499 TabEntersPresentationModeFromWindowed);
500 FRIEND_TEST_ALL_PREFIXES(FullscreenExitBubbleControllerTest,
501 DenyExitsFullscreen);
502 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref);
503 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
504 OpenAppShortcutWindowPref);
505 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref);
507 class InterstitialObserver;
509 // Used to describe why a tab is being detached. This is used by
510 // TabDetachedAtImpl.
512 // Result of TabDetachedAt.
515 // Result of TabReplacedAt.
518 // Result of the tab strip not having any significant tabs.
522 // Describes where the bookmark bar state change originated from.
523 enum BookmarkBarStateChangeReason {
524 // From the constructor.
525 BOOKMARK_BAR_STATE_CHANGE_INIT,
527 // Change is the result of the active tab changing.
528 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH,
530 // Change is the result of the bookmark bar pref changing.
531 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE,
533 // Change is the result of a state change in the active tab.
534 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE,
536 // Change is the result of window toggling in/out of fullscreen mode.
537 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN,
540 // Overridden from content::WebContentsDelegate:
541 content::WebContents* OpenURLFromTab(
542 content::WebContents* source,
543 const content::OpenURLParams& params) override;
544 void NavigationStateChanged(const content::WebContents* source,
545 content::InvalidateTypes changed_flags) override;
546 void VisibleSSLStateChanged(const content::WebContents* source) override;
547 void AddNewContents(content::WebContents* source,
548 content::WebContents* new_contents,
549 WindowOpenDisposition disposition,
550 const gfx::Rect& initial_pos,
552 bool* was_blocked) override;
553 void ActivateContents(content::WebContents* contents) override;
554 void DeactivateContents(content::WebContents* contents) override;
555 void LoadingStateChanged(content::WebContents* source,
556 bool to_different_document) override;
557 void CloseContents(content::WebContents* source) override;
558 void MoveContents(content::WebContents* source,
559 const gfx::Rect& pos) override;
560 bool IsPopupOrPanel(const content::WebContents* source) const override;
561 void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
562 void ContentsMouseEvent(content::WebContents* source,
563 const gfx::Point& location,
564 bool motion) override;
565 void ContentsZoomChange(bool zoom_in) override;
566 void WebContentsFocused(content::WebContents* content) override;
567 bool TakeFocus(content::WebContents* source, bool reverse) override;
568 gfx::Rect GetRootWindowResizerRect() const override;
569 void BeforeUnloadFired(content::WebContents* source,
571 bool* proceed_to_fire_unload) override;
572 bool ShouldFocusLocationBarByDefault(content::WebContents* source) override;
573 void SetFocusToLocationBar(bool select_all) override;
574 int GetExtraRenderViewHeight() const override;
575 void ViewSourceForTab(content::WebContents* source,
576 const GURL& page_url) override;
577 void ViewSourceForFrame(content::WebContents* source,
578 const GURL& frame_url,
579 const content::PageState& frame_page_state) override;
580 void ShowRepostFormWarningDialog(content::WebContents* source) override;
581 bool ShouldCreateWebContents(
582 content::WebContents* web_contents,
584 WindowContainerType window_container_type,
585 const base::string16& frame_name,
586 const GURL& target_url,
587 const std::string& partition_id,
588 content::SessionStorageNamespace* session_storage_namespace) override;
589 void WebContentsCreated(content::WebContents* source_contents,
590 int opener_render_frame_id,
591 const base::string16& frame_name,
592 const GURL& target_url,
593 content::WebContents* new_contents) override;
594 void RendererUnresponsive(content::WebContents* source) override;
595 void RendererResponsive(content::WebContents* source) override;
596 void WorkerCrashed(content::WebContents* source) override;
597 void DidNavigateMainFramePostCommit(
598 content::WebContents* web_contents) override;
599 void DidNavigateToPendingEntry(content::WebContents* web_contents) override;
600 content::JavaScriptDialogManager* GetJavaScriptDialogManager() override;
601 content::ColorChooser* OpenColorChooser(
602 content::WebContents* web_contents,
604 const std::vector<content::ColorSuggestion>& suggestions) override;
605 void RunFileChooser(content::WebContents* web_contents,
606 const content::FileChooserParams& params) override;
607 void EnumerateDirectory(content::WebContents* web_contents,
609 const base::FilePath& path) override;
610 bool EmbedsFullscreenWidget() const override;
611 void ToggleFullscreenModeForTab(content::WebContents* web_contents,
612 bool enter_fullscreen) override;
613 bool IsFullscreenForTabOrPending(
614 const content::WebContents* web_contents) const override;
615 void RegisterProtocolHandler(content::WebContents* web_contents,
616 const std::string& protocol,
618 bool user_gesture) override;
619 void UnregisterProtocolHandler(content::WebContents* web_contents,
620 const std::string& protocol,
622 bool user_gesture) override;
623 void UpdatePreferredSize(content::WebContents* source,
624 const gfx::Size& pref_size) override;
625 void ResizeDueToAutoResize(content::WebContents* source,
626 const gfx::Size& new_size) override;
627 void FindReply(content::WebContents* web_contents,
629 int number_of_matches,
630 const gfx::Rect& selection_rect,
631 int active_match_ordinal,
632 bool final_update) override;
633 void RequestToLockMouse(content::WebContents* web_contents,
635 bool last_unlocked_by_target) override;
636 void LostMouseLock() override;
637 void RequestMediaAccessPermission(
638 content::WebContents* web_contents,
639 const content::MediaStreamRequest& request,
640 const content::MediaResponseCallback& callback) override;
641 bool CheckMediaAccessPermission(content::WebContents* web_contents,
642 const GURL& security_origin,
643 content::MediaStreamType type) override;
644 bool RequestPpapiBrokerPermission(
645 content::WebContents* web_contents,
647 const base::FilePath& plugin_path,
648 const base::Callback<void(bool)>& callback) override;
649 gfx::Size GetSizeForNewRenderView(
650 content::WebContents* web_contents) const override;
652 // Overridden from CoreTabHelperDelegate:
653 // Note that the caller is responsible for deleting |old_contents|.
654 void SwapTabContents(content::WebContents* old_contents,
655 content::WebContents* new_contents,
657 bool did_finish_load) override;
658 bool CanReloadContents(content::WebContents* web_contents) const override;
659 bool CanSaveContents(content::WebContents* web_contents) const override;
661 // Overridden from SearchEngineTabHelperDelegate:
662 void ConfirmAddSearchProvider(TemplateURL* template_url,
663 Profile* profile) override;
665 // Overridden from SearchTabHelperDelegate:
666 void NavigateOnThumbnailClick(const GURL& url,
667 WindowOpenDisposition disposition,
668 content::WebContents* source_contents) override;
669 void OnWebContentsInstantSupportDisabled(
670 const content::WebContents* web_contents) override;
671 OmniboxView* GetOmniboxView() override;
672 std::set<std::string> GetOpenUrls() override;
674 // Overridden from WebContentsModalDialogManagerDelegate:
675 void SetWebContentsBlocked(content::WebContents* web_contents,
676 bool blocked) override;
677 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()
680 // Overridden from BookmarkTabHelperDelegate:
681 void URLStarredChanged(content::WebContents* web_contents,
682 bool starred) override;
684 // Overridden from ZoomObserver:
685 void OnZoomChanged(const ZoomController::ZoomChangedEventData& data) override;
687 // Overridden from SelectFileDialog::Listener:
688 void FileSelected(const base::FilePath& path,
690 void* params) override;
691 void FileSelectedWithExtraInfo(const ui::SelectedFileInfo& file_info,
693 void* params) override;
695 // Overridden from content::NotificationObserver:
696 void Observe(int type,
697 const content::NotificationSource& source,
698 const content::NotificationDetails& details) override;
700 #if defined(ENABLE_EXTENSIONS)
701 // Overridden from extensions::ExtensionRegistryObserver:
702 void OnExtensionUninstalled(content::BrowserContext* browser_context,
703 const extensions::Extension* extension,
704 extensions::UninstallReason reason) override;
705 void OnExtensionLoaded(content::BrowserContext* browser_context,
706 const extensions::Extension* extension) override;
707 void OnExtensionUnloaded(
708 content::BrowserContext* browser_context,
709 const extensions::Extension* extension,
710 extensions::UnloadedExtensionInfo::Reason reason) override;
713 // Command and state updating ///////////////////////////////////////////////
715 // Handle changes to kDevTools preference.
716 void OnDevToolsDisabledChanged();
718 // UI update coalescing and handling ////////////////////////////////////////
720 // Asks the toolbar (and as such the location bar) to update its state to
721 // reflect the current tab's current URL, security state, etc.
722 // If |should_restore_state| is true, we're switching (back?) to this tab and
723 // should restore any previous location bar state (such as user editing) as
725 void UpdateToolbar(bool should_restore_state);
727 // Does one or both of the following for each bit in |changed_flags|:
728 // . If the update should be processed immediately, it is.
729 // . If the update should processed asynchronously (to avoid lots of ui
730 // updates), then scheduled_updates_ is updated for the |source| and update
731 // pair and a task is scheduled (assuming it isn't running already)
732 // that invokes ProcessPendingUIUpdates.
733 void ScheduleUIUpdate(const content::WebContents* source,
734 unsigned changed_flags);
736 // Processes all pending updates to the UI that have been scheduled by
737 // ScheduleUIUpdate in scheduled_updates_.
738 void ProcessPendingUIUpdates();
740 // Removes all entries from scheduled_updates_ whose source is contents.
741 void RemoveScheduledUpdatesFor(content::WebContents* contents);
743 // Getters for UI ///////////////////////////////////////////////////////////
745 // TODO(beng): remove, and provide AutomationProvider a better way to access
746 // the LocationBarView's edit.
747 friend class AutomationProvider;
748 friend class BrowserProxy;
750 // Returns the StatusBubble from the current toolbar. It is possible for
751 // this to return NULL if called before the toolbar has initialized.
752 // TODO(beng): remove this.
753 StatusBubble* GetStatusBubble();
755 // Session restore functions ////////////////////////////////////////////////
757 // Notifies the history database of the index for all tabs whose index is
759 void SyncHistoryWithTabs(int index);
761 // In-progress download termination handling /////////////////////////////////
763 // Called when the window is closing to check if potential in-progress
764 // downloads should prevent it from closing.
765 // Returns true if the window can close, false otherwise.
766 bool CanCloseWithInProgressDownloads();
768 // Assorted utility functions ///////////////////////////////////////////////
770 // Sets the specified browser as the delegate of the WebContents and all the
771 // associated tab helpers that are needed. If |set_delegate| is true, this
772 // browser object is set as a delegate for |web_contents| components, else
773 // is is removed as a delegate.
774 void SetAsDelegate(content::WebContents* web_contents, bool set_delegate);
776 // Shows the Find Bar, optionally selecting the next entry that matches the
777 // existing search string for that Tab. |forward_direction| controls the
779 void FindInPage(bool find_next, bool forward_direction);
782 // TODO(beng): figure out if we need this now that the frame itself closes
783 // after a return to the message loop.
786 void TabDetachedAtImpl(content::WebContents* contents,
790 // Shared code between Reload() and ReloadIgnoringCache().
791 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache);
793 // Returns true if the Browser window should show the location bar.
794 bool ShouldShowLocationBar() const;
796 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
797 // |check_fullscreen| is true, the set of features reflect the actual state of
798 // the browser, otherwise the set of features reflect the possible state of
800 bool SupportsWindowFeatureImpl(WindowFeature feature,
801 bool check_fullscreen) const;
803 // Resets |bookmark_bar_state_| based on the active tab. Notifies the
804 // BrowserWindow if necessary.
805 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason);
807 bool ShouldHideUIForFullscreen() const;
809 // Creates a BackgroundContents if appropriate; return true if one was
811 bool MaybeCreateBackgroundContents(
813 content::WebContents* opener_web_contents,
814 const base::string16& frame_name,
815 const GURL& target_url,
816 const std::string& partition_id,
817 content::SessionStorageNamespace* session_storage_namespace);
819 // Data members /////////////////////////////////////////////////////////////
821 std::vector<InterstitialObserver*> interstitial_observers_;
823 content::NotificationRegistrar registrar_;
825 #if defined(ENABLE_EXTENSIONS)
826 ScopedObserver<extensions::ExtensionRegistry,
827 extensions::ExtensionRegistryObserver>
828 extension_registry_observer_;
831 PrefChangeRegistrar profile_pref_registrar_;
833 // This Browser's type.
836 // This Browser's profile.
837 Profile* const profile_;
839 // This Browser's window.
840 BrowserWindow* window_;
842 // Manages popup windows (bubbles, tab-modals) visible overlapping this
843 // window. JS alerts are not handled by this manager.
844 scoped_ptr<web_modal::PopupManager> popup_manager_;
846 scoped_ptr<TabStripModelDelegate> tab_strip_model_delegate_;
847 scoped_ptr<TabStripModel> tab_strip_model_;
849 // The application name that is also the name of the window to the shell.
850 // This name should be set when:
851 // 1) we launch an application via an application shortcut or extension API.
852 // 2) we launch an undocked devtool window.
853 std::string app_name_;
855 // True if the source is trusted (i.e. we do not need to show the URL in a
856 // a popup window). Also used to determine which app windows to save and
857 // restore on Chrome OS.
858 bool is_trusted_source_;
860 // Unique identifier of this browser for session restore. This id is only
861 // unique within the current session, and is not guaranteed to be unique
863 const SessionID session_id_;
865 // The model for the toolbar view.
866 scoped_ptr<ToolbarModel> toolbar_model_;
868 // The model for the "active" search state. There are per-tab search models
869 // as well. When a tab is active its model is kept in sync with this one.
870 // When a new tab is activated its model state is propagated to this active
871 // model. This way, observers only have to attach to this single model for
872 // updates, and don't have to worry about active tab changes directly.
873 scoped_ptr<SearchModel> search_model_;
875 // UI update coalescing and handling ////////////////////////////////////////
877 typedef std::map<const content::WebContents*, int> UpdateMap;
879 // Maps from WebContents to pending UI updates that need to be processed.
880 // We don't update things like the URL or tab title right away to avoid
881 // flickering and extra painting.
882 // See ScheduleUIUpdate and ProcessPendingUIUpdates.
883 UpdateMap scheduled_updates_;
885 // In-progress download termination handling /////////////////////////////////
887 enum CancelDownloadConfirmationState {
888 NOT_PROMPTED, // We have not asked the user.
889 WAITING_FOR_RESPONSE, // We have asked the user and have not received a
891 RESPONSE_RECEIVED // The user was prompted and made a decision already.
894 // State used to figure-out whether we should prompt the user for confirmation
895 // when the browser is closed with in-progress downloads.
896 CancelDownloadConfirmationState cancel_download_confirmation_state_;
898 /////////////////////////////////////////////////////////////////////////////
900 // Override values for the bounds of the window and its maximized or minimized
902 // These are supplied by callers that don't want to use the default values.
903 // The default values are typically loaded from local state (last session),
904 // obtained from the last window of the same type, or obtained from the
905 // shell shortcut's startup info.
906 gfx::Rect override_bounds_;
907 ui::WindowShowState initial_show_state_;
909 // Tracks when this browser is being created by session restore.
910 bool is_session_restore_;
912 const chrome::HostDesktopType host_desktop_type_;
914 scoped_ptr<chrome::UnloadController> unload_controller_;
915 scoped_ptr<chrome::FastUnloadController> fast_unload_controller_;
917 // The Find Bar. This may be NULL if there is no Find Bar, and if it is
918 // non-NULL, it may or may not be visible.
919 scoped_ptr<FindBarController> find_bar_controller_;
921 // Dialog box used for opening and saving files.
922 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
924 // Keep track of the encoding auto detect pref.
925 BooleanPrefMember encoding_auto_detect_;
927 // Helper which implements the ContentSettingBubbleModel interface.
928 scoped_ptr<BrowserContentSettingBubbleModelDelegate>
929 content_setting_bubble_model_delegate_;
931 // Helper which implements the ToolbarModelDelegate interface.
932 scoped_ptr<BrowserToolbarModelDelegate> toolbar_model_delegate_;
934 // A delegate that handles the details of updating the "active"
935 // |search_model_| state with the tab's state.
936 scoped_ptr<SearchDelegate> search_delegate_;
938 // Helper which implements the TabRestoreServiceDelegate interface.
939 scoped_ptr<BrowserTabRestoreServiceDelegate> tab_restore_service_delegate_;
941 // Helper which implements the SyncedWindowDelegate interface.
942 scoped_ptr<BrowserSyncedWindowDelegate> synced_window_delegate_;
944 scoped_ptr<BrowserInstantController> instant_controller_;
946 BookmarkBar::State bookmark_bar_state_;
948 scoped_ptr<FullscreenController> fullscreen_controller_;
950 scoped_ptr<extensions::WindowController> extension_window_controller_;
952 scoped_ptr<chrome::BrowserCommandController> command_controller_;
954 // True if the browser window has been shown at least once.
955 bool window_has_shown_;
957 // The following factory is used for chrome update coalescing.
958 base::WeakPtrFactory<Browser> chrome_updater_factory_;
960 scoped_ptr<BrowserContentTranslateDriverObserver> translate_driver_observer_;
962 scoped_ptr<chrome::ValidationMessageBubble> validation_message_bubble_;
964 // The following factory is used to close the frame at a later time.
965 base::WeakPtrFactory<Browser> weak_factory_;
967 DISALLOW_COPY_AND_ASSIGN(Browser);
970 #endif // CHROME_BROWSER_UI_BROWSER_H_