OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_BROWSER_H_ | 5 #ifndef CHROME_BROWSER_UI_BROWSER_H_ |
6 #define CHROME_BROWSER_UI_BROWSER_H_ | 6 #define CHROME_BROWSER_UI_BROWSER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // TabStripModel pass-thrus ///////////////////////////////////////////////// | 318 // TabStripModel pass-thrus ///////////////////////////////////////////////// |
319 | 319 |
320 TabStripModel* tabstrip_model() const { | 320 TabStripModel* tabstrip_model() const { |
321 // TODO(beng): remove this accessor. It violates google style. | 321 // TODO(beng): remove this accessor. It violates google style. |
322 return tab_handler_->GetTabStripModel(); | 322 return tab_handler_->GetTabStripModel(); |
323 } | 323 } |
324 | 324 |
325 int tab_count() const; | 325 int tab_count() const; |
326 int selected_index() const; | 326 int selected_index() const; |
327 int GetIndexOfController(const NavigationController* controller) const; | 327 int GetIndexOfController(const NavigationController* controller) const; |
| 328 TabContentsWrapper* GetSelectedTabContentsWrapper() const; |
| 329 TabContentsWrapper* GetTabContentsWrapperAt(int index) const; |
| 330 // Same as above but correctly handles if GetSelectedTabContents() is NULL |
| 331 // in the model before dereferencing to get the raw TabContents. |
| 332 // TODO(pinkerton): These should really be returning TabContentsWrapper |
| 333 // objects, but that would require changing about 50+ other files. In order |
| 334 // to keep changes localized, the default is to return a TabContents. Note |
| 335 // this differs from the TabStripModel because it has far fewer clients. |
| 336 TabContents* GetSelectedTabContents() const; |
328 TabContents* GetTabContentsAt(int index) const; | 337 TabContents* GetTabContentsAt(int index) const; |
329 TabContents* GetSelectedTabContents() const; | |
330 void SelectTabContentsAt(int index, bool user_gesture); | 338 void SelectTabContentsAt(int index, bool user_gesture); |
331 void CloseAllTabs(); | 339 void CloseAllTabs(); |
332 | 340 |
333 // Tab adding/showing functions ///////////////////////////////////////////// | 341 // Tab adding/showing functions ///////////////////////////////////////////// |
334 | 342 |
335 // Returns the index to insert a tab at during session restore and startup. | 343 // Returns the index to insert a tab at during session restore and startup. |
336 // |relative_index| gives the index of the url into the number of tabs that | 344 // |relative_index| gives the index of the url into the number of tabs that |
337 // are going to be opened. For example, if three urls are passed in on the | 345 // are going to be opened. For example, if three urls are passed in on the |
338 // command line this is invoked three times with the values 0, 1 and 2. | 346 // command line this is invoked three times with the values 0, 1 and 2. |
339 int GetIndexForInsertionDuringRestore(int relative_index); | 347 int GetIndexForInsertionDuringRestore(int relative_index); |
340 | 348 |
341 // Adds a selected tab with the specified URL and transition, returns the | 349 // Adds a selected tab with the specified URL and transition, returns the |
342 // created TabContents. | 350 // created TabContents. |
343 TabContents* AddSelectedTabWithURL(const GURL& url, | 351 TabContentsWrapper* AddSelectedTabWithURL( |
344 PageTransition::Type transition); | 352 const GURL& url, |
| 353 PageTransition::Type transition); |
345 | 354 |
346 // Add a new tab, given a TabContents. A TabContents appropriate to | 355 // Add a new tab, given a TabContents. A TabContents appropriate to |
347 // display the last committed entry is created and returned. | 356 // display the last committed entry is created and returned. |
348 TabContents* AddTab(TabContents* tab_contents, PageTransition::Type type); | 357 TabContents* AddTab(TabContentsWrapper* tab_contents, |
| 358 PageTransition::Type type); |
349 | 359 |
350 // Add a tab with its session history restored from the SessionRestore | 360 // Add a tab with its session history restored from the SessionRestore |
351 // system. If select is true, the tab is selected. |tab_index| gives the index | 361 // system. If select is true, the tab is selected. |tab_index| gives the index |
352 // to insert the tab at. |selected_navigation| is the index of the | 362 // to insert the tab at. |selected_navigation| is the index of the |
353 // TabNavigation in |navigations| to select. If |extension_app_id| is | 363 // TabNavigation in |navigations| to select. If |extension_app_id| is |
354 // non-empty the tab is an app tab and |extension_app_id| is the id of the | 364 // non-empty the tab is an app tab and |extension_app_id| is the id of the |
355 // extension. If |pin| is true and |tab_index|/ is the last pinned tab, then | 365 // extension. If |pin| is true and |tab_index|/ is the last pinned tab, then |
356 // the newly created tab is pinned. If |from_last_session| is true, | 366 // the newly created tab is pinned. If |from_last_session| is true, |
357 // |navigations| are from the previous session. | 367 // |navigations| are from the previous session. |
358 TabContents* AddRestoredTab(const std::vector<TabNavigation>& navigations, | 368 TabContents* AddRestoredTab(const std::vector<TabNavigation>& navigations, |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 void SetBlockCommandExecution(bool block); | 599 void SetBlockCommandExecution(bool block); |
590 | 600 |
591 // Gets the last blocked command after calling SetBlockCommandExecution(true). | 601 // Gets the last blocked command after calling SetBlockCommandExecution(true). |
592 // Returns the command id or -1 if there is no command blocked. The | 602 // Returns the command id or -1 if there is no command blocked. The |
593 // disposition type of the command will be stored in |*disposition| if it's | 603 // disposition type of the command will be stored in |*disposition| if it's |
594 // not null. | 604 // not null. |
595 int GetLastBlockedCommand(WindowOpenDisposition* disposition); | 605 int GetLastBlockedCommand(WindowOpenDisposition* disposition); |
596 | 606 |
597 // Called by browser::Navigate() when a navigation has occurred in a tab in | 607 // Called by browser::Navigate() when a navigation has occurred in a tab in |
598 // this Browser. Updates the UI for the start of this navigation. | 608 // this Browser. Updates the UI for the start of this navigation. |
599 void UpdateUIForNavigationInTab(TabContents* contents, | 609 void UpdateUIForNavigationInTab(TabContentsWrapper* contents, |
600 PageTransition::Type transition, | 610 PageTransition::Type transition, |
601 bool user_initiated); | 611 bool user_initiated); |
602 | 612 |
603 // Called by browser::Navigate() to retrieve the home page if no URL is | 613 // Called by browser::Navigate() to retrieve the home page if no URL is |
604 // specified. | 614 // specified. |
605 GURL GetHomePage() const; | 615 GURL GetHomePage() const; |
606 | 616 |
607 // Interface implementations //////////////////////////////////////////////// | 617 // Interface implementations //////////////////////////////////////////////// |
608 | 618 |
609 // Overridden from PageNavigator: | 619 // Overridden from PageNavigator: |
610 virtual void OpenURL(const GURL& url, const GURL& referrer, | 620 virtual void OpenURL(const GURL& url, const GURL& referrer, |
611 WindowOpenDisposition disposition, | 621 WindowOpenDisposition disposition, |
612 PageTransition::Type transition); | 622 PageTransition::Type transition); |
613 | 623 |
614 // Overridden from CommandUpdater::CommandUpdaterDelegate: | 624 // Overridden from CommandUpdater::CommandUpdaterDelegate: |
615 virtual void ExecuteCommand(int id); | 625 virtual void ExecuteCommand(int id); |
616 | 626 |
617 // Overridden from TabRestoreServiceObserver: | 627 // Overridden from TabRestoreServiceObserver: |
618 virtual void TabRestoreServiceChanged(TabRestoreService* service); | 628 virtual void TabRestoreServiceChanged(TabRestoreService* service); |
619 virtual void TabRestoreServiceDestroyed(TabRestoreService* service); | 629 virtual void TabRestoreServiceDestroyed(TabRestoreService* service); |
620 | 630 |
| 631 // Centralized method for creating a TabContents, configuring and installing |
| 632 // all its supporting objects and observers. |
| 633 static TabContentsWrapper* |
| 634 TabContentsFactory(Profile* profile, |
| 635 SiteInstance* site_instance, |
| 636 int routing_id, |
| 637 const TabContents* base_tab_contents, |
| 638 SessionStorageNamespace* session_storage_namespace); |
621 | 639 |
622 // Overridden from TabHandlerDelegate: | 640 // Overridden from TabHandlerDelegate: |
623 virtual Profile* GetProfile() const; | 641 virtual Profile* GetProfile() const; |
624 virtual Browser* AsBrowser(); | 642 virtual Browser* AsBrowser(); |
625 | 643 |
626 // Overridden from TabStripModelDelegate: | 644 // Overridden from TabStripModelDelegate: |
627 virtual TabContents* AddBlankTab(bool foreground); | 645 virtual TabContentsWrapper* AddBlankTab(bool foreground); |
628 virtual TabContents* AddBlankTabAt(int index, bool foreground); | 646 virtual TabContentsWrapper* AddBlankTabAt(int index, bool foreground); |
629 virtual Browser* CreateNewStripWithContents(TabContents* detached_contents, | 647 virtual Browser* CreateNewStripWithContents( |
630 const gfx::Rect& window_bounds, | 648 TabContentsWrapper* detached_contents, |
631 const DockInfo& dock_info, | 649 const gfx::Rect& window_bounds, |
632 bool maximize); | 650 const DockInfo& dock_info, |
633 virtual void ContinueDraggingDetachedTab(TabContents* contents, | 651 bool maximize); |
| 652 virtual void ContinueDraggingDetachedTab(TabContentsWrapper* contents, |
634 const gfx::Rect& window_bounds, | 653 const gfx::Rect& window_bounds, |
635 const gfx::Rect& tab_bounds); | 654 const gfx::Rect& tab_bounds); |
636 virtual int GetDragActions() const; | 655 virtual int GetDragActions() const; |
637 // Construct a TabContents for a given URL, profile and transition type. | 656 // Construct a TabContents for a given URL, profile and transition type. |
638 // If instance is not null, its process will be used to render the tab. | 657 // If instance is not null, its process will be used to render the tab. |
639 virtual TabContents* CreateTabContentsForURL(const GURL& url, | 658 virtual TabContentsWrapper* CreateTabContentsForURL(const GURL& url, |
640 const GURL& referrer, | 659 const GURL& referrer, |
641 Profile* profile, | 660 Profile* profile, |
642 PageTransition::Type transition, | 661 PageTransition::Type transition, |
643 bool defer_load, | 662 bool defer_load, |
644 SiteInstance* instance) const; | 663 SiteInstance* instance) const; |
645 virtual bool CanDuplicateContentsAt(int index); | 664 virtual bool CanDuplicateContentsAt(int index); |
646 virtual void DuplicateContentsAt(int index); | 665 virtual void DuplicateContentsAt(int index); |
647 virtual void CloseFrameAfterDragSession(); | 666 virtual void CloseFrameAfterDragSession(); |
648 virtual void CreateHistoricalTab(TabContents* contents); | 667 virtual void CreateHistoricalTab(TabContentsWrapper* contents); |
649 virtual bool RunUnloadListenerBeforeClosing(TabContents* contents); | 668 virtual bool RunUnloadListenerBeforeClosing(TabContentsWrapper* contents); |
650 virtual bool CanCloseContentsAt(int index); | 669 virtual bool CanCloseContentsAt(int index); |
651 virtual bool CanBookmarkAllTabs() const; | 670 virtual bool CanBookmarkAllTabs() const; |
652 virtual void BookmarkAllTabs(); | 671 virtual void BookmarkAllTabs(); |
653 virtual bool CanCloseTab() const; | 672 virtual bool CanCloseTab() const; |
654 virtual void ToggleUseVerticalTabs(); | 673 virtual void ToggleUseVerticalTabs(); |
655 virtual bool CanRestoreTab(); | 674 virtual bool CanRestoreTab(); |
656 virtual void RestoreTab(); | 675 virtual void RestoreTab(); |
657 virtual bool LargeIconsPermitted() const; | 676 virtual bool LargeIconsPermitted() const; |
658 | 677 |
659 // Overridden from TabStripModelObserver: | 678 // Overridden from TabStripModelObserver: |
660 virtual void TabInsertedAt(TabContents* contents, | 679 virtual void TabInsertedAt(TabContentsWrapper* contents, |
661 int index, | 680 int index, |
662 bool foreground); | 681 bool foreground); |
663 virtual void TabClosingAt(TabStripModel* tab_strip_model, | 682 virtual void TabClosingAt(TabStripModel* tab_strip_model, |
664 TabContents* contents, | 683 TabContentsWrapper* contents, |
665 int index); | 684 int index); |
666 virtual void TabDetachedAt(TabContents* contents, int index); | 685 virtual void TabDetachedAt(TabContentsWrapper* contents, int index); |
667 virtual void TabDeselectedAt(TabContents* contents, int index); | 686 virtual void TabDeselectedAt(TabContentsWrapper* contents, int index); |
668 virtual void TabSelectedAt(TabContents* old_contents, | 687 virtual void TabSelectedAt(TabContentsWrapper* old_contents, |
669 TabContents* new_contents, | 688 TabContentsWrapper* new_contents, |
670 int index, | 689 int index, |
671 bool user_gesture); | 690 bool user_gesture); |
672 virtual void TabMoved(TabContents* contents, | 691 virtual void TabMoved(TabContentsWrapper* contents, |
673 int from_index, | 692 int from_index, |
674 int to_index); | 693 int to_index); |
675 virtual void TabReplacedAt(TabContents* old_contents, | 694 virtual void TabReplacedAt(TabContentsWrapper* old_contents, |
676 TabContents* new_contents, | 695 TabContentsWrapper* new_contents, |
677 int index); | 696 int index); |
678 virtual void TabPinnedStateChanged(TabContents* contents, int index); | 697 virtual void TabPinnedStateChanged(TabContentsWrapper* contents, int index); |
679 virtual void TabStripEmpty(); | 698 virtual void TabStripEmpty(); |
680 | 699 |
681 private: | 700 private: |
682 FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups); | 701 FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups); |
683 | 702 |
684 // Used to describe why a tab is being detached. This is used by | 703 // Used to describe why a tab is being detached. This is used by |
685 // TabDetachedAtImpl. | 704 // TabDetachedAtImpl. |
686 enum DetachType { | 705 enum DetachType { |
687 // Result of TabDetachedAt. | 706 // Result of TabDetachedAt. |
688 DETACH_TYPE_DETACH, | 707 DETACH_TYPE_DETACH, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 // Overridden from NotificationObserver: | 785 // Overridden from NotificationObserver: |
767 virtual void Observe(NotificationType type, | 786 virtual void Observe(NotificationType type, |
768 const NotificationSource& source, | 787 const NotificationSource& source, |
769 const NotificationDetails& details); | 788 const NotificationDetails& details); |
770 | 789 |
771 // Overridden from ProfileSyncServiceObserver: | 790 // Overridden from ProfileSyncServiceObserver: |
772 virtual void OnStateChanged(); | 791 virtual void OnStateChanged(); |
773 | 792 |
774 // Overriden from InstantDelegate: | 793 // Overriden from InstantDelegate: |
775 virtual void PrepareForInstant(); | 794 virtual void PrepareForInstant(); |
776 virtual void ShowInstant(TabContents* preview_contents); | 795 virtual void ShowInstant(TabContentsWrapper* preview_contents); |
777 virtual void HideInstant(); | 796 virtual void HideInstant(); |
778 virtual void CommitInstant(TabContents* preview_contents); | 797 virtual void CommitInstant(TabContentsWrapper* preview_contents); |
779 virtual void SetSuggestedText(const string16& text); | 798 virtual void SetSuggestedText(const string16& text); |
780 virtual gfx::Rect GetInstantBounds(); | 799 virtual gfx::Rect GetInstantBounds(); |
781 | 800 |
782 // Command and state updating /////////////////////////////////////////////// | 801 // Command and state updating /////////////////////////////////////////////// |
783 | 802 |
784 // Initialize state for all browser commands. | 803 // Initialize state for all browser commands. |
785 void InitCommandState(); | 804 void InitCommandState(); |
786 | 805 |
787 // Update commands whose state depends on the tab's state. | 806 // Update commands whose state depends on the tab's state. |
788 void UpdateCommandsForTabState(); | 807 void UpdateCommandsForTabState(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 // Shows the Find Bar, optionally selecting the next entry that matches the | 917 // Shows the Find Bar, optionally selecting the next entry that matches the |
899 // existing search string for that Tab. |forward_direction| controls the | 918 // existing search string for that Tab. |forward_direction| controls the |
900 // search direction. | 919 // search direction. |
901 void FindInPage(bool find_next, bool forward_direction); | 920 void FindInPage(bool find_next, bool forward_direction); |
902 | 921 |
903 // Closes the frame. | 922 // Closes the frame. |
904 // TODO(beng): figure out if we need this now that the frame itself closes | 923 // TODO(beng): figure out if we need this now that the frame itself closes |
905 // after a return to the message loop. | 924 // after a return to the message loop. |
906 void CloseFrame(); | 925 void CloseFrame(); |
907 | 926 |
908 void TabDetachedAtImpl(TabContents* contents, int index, DetachType type); | 927 void TabDetachedAtImpl(TabContentsWrapper* contents, |
| 928 int index, DetachType type); |
909 | 929 |
910 // Create a preference dictionary for the provided application name. This is | 930 // Create a preference dictionary for the provided application name. This is |
911 // done only once per application name / per session. | 931 // done only once per application name / per session. |
912 static void RegisterAppPrefs(const std::string& app_name); | 932 static void RegisterAppPrefs(const std::string& app_name); |
913 | 933 |
914 // Shared code between Reload() and ReloadIgnoringCache(). | 934 // Shared code between Reload() and ReloadIgnoringCache(). |
915 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache); | 935 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache); |
916 | 936 |
917 // Return true if the window dispositions means opening a new tab. | 937 // Return true if the window dispositions means opening a new tab. |
918 bool ShouldOpenNewTabForWindowDisposition(WindowOpenDisposition disposition); | 938 bool ShouldOpenNewTabForWindowDisposition(WindowOpenDisposition disposition); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 // The profile's tab restore service. The service is owned by the profile, | 1105 // The profile's tab restore service. The service is owned by the profile, |
1086 // and we install ourselves as an observer. | 1106 // and we install ourselves as an observer. |
1087 TabRestoreService* tab_restore_service_; | 1107 TabRestoreService* tab_restore_service_; |
1088 | 1108 |
1089 scoped_ptr<InstantController> instant_; | 1109 scoped_ptr<InstantController> instant_; |
1090 | 1110 |
1091 DISALLOW_COPY_AND_ASSIGN(Browser); | 1111 DISALLOW_COPY_AND_ASSIGN(Browser); |
1092 }; | 1112 }; |
1093 | 1113 |
1094 #endif // CHROME_BROWSER_UI_BROWSER_H_ | 1114 #endif // CHROME_BROWSER_UI_BROWSER_H_ |
OLD | NEW |