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 #include "chrome/browser/tabs/tab_strip_model.h" | 5 #include "chrome/browser/tabs/tab_strip_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 profile_(profile), | 114 profile_(profile), |
115 closing_all_(false), | 115 closing_all_(false), |
116 order_controller_(NULL) { | 116 order_controller_(NULL) { |
117 DCHECK(delegate_); | 117 DCHECK(delegate_); |
118 registrar_.Add(this, | 118 registrar_.Add(this, |
119 NotificationType::TAB_CONTENTS_DESTROYED, | 119 NotificationType::TAB_CONTENTS_DESTROYED, |
120 NotificationService::AllSources()); | 120 NotificationService::AllSources()); |
121 registrar_.Add(this, | 121 registrar_.Add(this, |
122 NotificationType::EXTENSION_UNLOADED, | 122 NotificationType::EXTENSION_UNLOADED, |
123 Source<Profile>(profile_)); | 123 Source<Profile>(profile_)); |
124 registrar_.Add(this, | |
125 NotificationType::EXTENSION_APP_TOOLBAR_VISIBILITY_CHANGED, | |
126 NotificationService::AllSources()); | |
127 order_controller_ = new TabStripModelOrderController(this); | 124 order_controller_ = new TabStripModelOrderController(this); |
128 } | 125 } |
129 | 126 |
130 TabStripModel::~TabStripModel() { | 127 TabStripModel::~TabStripModel() { |
131 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, | 128 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, |
132 TabStripModelDeleted()); | 129 TabStripModelDeleted()); |
133 | 130 |
134 // Before deleting any phantom tabs remove our notification observers so that | 131 // Before deleting any phantom tabs remove our notification observers so that |
135 // we don't attempt to notify our delegate or do any processing. | 132 // we don't attempt to notify our delegate or do any processing. |
136 registrar_.RemoveAll(); | 133 registrar_.RemoveAll(); |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 | 518 |
522 bool TabStripModel::IsMiniTab(int index) const { | 519 bool TabStripModel::IsMiniTab(int index) const { |
523 return IsTabPinned(index) || IsAppTab(index); | 520 return IsTabPinned(index) || IsAppTab(index); |
524 } | 521 } |
525 | 522 |
526 bool TabStripModel::IsAppTab(int index) const { | 523 bool TabStripModel::IsAppTab(int index) const { |
527 TabContents* contents = GetTabContentsAt(index); | 524 TabContents* contents = GetTabContentsAt(index); |
528 return contents && contents->is_app(); | 525 return contents && contents->is_app(); |
529 } | 526 } |
530 | 527 |
531 bool TabStripModel::IsToolbarVisible(int index) const { | |
532 Extension* extension_app = GetTabContentsAt(index)->extension_app(); | |
533 if (!extension_app) | |
534 return true; | |
535 | |
536 ExtensionsService* service = profile()->GetExtensionsService(); | |
537 ExtensionPrefs* prefs = service->extension_prefs(); | |
538 return prefs->AreAppTabToolbarsVisible(extension_app->id()); | |
539 } | |
540 | |
541 bool TabStripModel::IsPhantomTab(int index) const { | 528 bool TabStripModel::IsPhantomTab(int index) const { |
542 return IsTabPinned(index) && | 529 return IsTabPinned(index) && |
543 GetTabContentsAt(index)->controller().needs_reload(); | 530 GetTabContentsAt(index)->controller().needs_reload(); |
544 } | 531 } |
545 | 532 |
546 bool TabStripModel::IsTabBlocked(int index) const { | 533 bool TabStripModel::IsTabBlocked(int index) const { |
547 return contents_data_[index]->blocked; | 534 return contents_data_[index]->blocked; |
548 } | 535 } |
549 | 536 |
550 int TabStripModel::IndexOfFirstNonMiniTab() const { | 537 int TabStripModel::IndexOfFirstNonMiniTab() const { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 case CommandCloseTabsToRight: | 688 case CommandCloseTabsToRight: |
702 // Close doesn't effect mini-tabs. | 689 // Close doesn't effect mini-tabs. |
703 return count() != IndexOfFirstNonMiniTab() && | 690 return count() != IndexOfFirstNonMiniTab() && |
704 context_index < (count() - 1); | 691 context_index < (count() - 1); |
705 case CommandDuplicate: | 692 case CommandDuplicate: |
706 return delegate_->CanDuplicateContentsAt(context_index); | 693 return delegate_->CanDuplicateContentsAt(context_index); |
707 case CommandRestoreTab: | 694 case CommandRestoreTab: |
708 return delegate_->CanRestoreTab(); | 695 return delegate_->CanRestoreTab(); |
709 case CommandTogglePinned: | 696 case CommandTogglePinned: |
710 return true; | 697 return true; |
711 case CommandToggleToolbar: | |
712 return true; | |
713 case CommandBookmarkAllTabs: | 698 case CommandBookmarkAllTabs: |
714 return delegate_->CanBookmarkAllTabs(); | 699 return delegate_->CanBookmarkAllTabs(); |
715 case CommandUseVerticalTabs: | 700 case CommandUseVerticalTabs: |
716 return true; | 701 return true; |
717 default: | 702 default: |
718 NOTREACHED(); | 703 NOTREACHED(); |
719 } | 704 } |
720 return false; | 705 return false; |
721 } | 706 } |
722 | 707 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 if (IsPhantomTab(context_index)) { | 773 if (IsPhantomTab(context_index)) { |
789 // The tab is a phantom tab, close it. | 774 // The tab is a phantom tab, close it. |
790 CloseTabContentsAt(context_index, | 775 CloseTabContentsAt(context_index, |
791 CLOSE_USER_GESTURE | CLOSE_CREATE_HISTORICAL_TAB); | 776 CLOSE_USER_GESTURE | CLOSE_CREATE_HISTORICAL_TAB); |
792 } else { | 777 } else { |
793 SelectTabContentsAt(context_index, true); | 778 SelectTabContentsAt(context_index, true); |
794 SetTabPinned(context_index, !IsTabPinned(context_index)); | 779 SetTabPinned(context_index, !IsTabPinned(context_index)); |
795 } | 780 } |
796 break; | 781 break; |
797 } | 782 } |
798 case CommandToggleToolbar: { | |
799 UserMetrics::RecordAction( | |
800 UserMetricsAction("TabContextMenu_ToggleToolbar"), | |
801 profile_); | |
802 | |
803 SelectTabContentsAt(context_index, true); | |
804 | |
805 Extension* extension_app = | |
806 GetTabContentsAt(context_index)->extension_app(); | |
807 if (!extension_app) | |
808 break; | |
809 | |
810 ExtensionsService* service = profile()->GetExtensionsService(); | |
811 ExtensionPrefs* prefs = service->extension_prefs(); | |
812 bool new_val = !prefs->AreAppTabToolbarsVisible(extension_app->id()); | |
813 prefs->SetAppTabToolbarVisibility(extension_app->id(), new_val); | |
814 | |
815 // There might be multiple browsers displaying this app, so we send a | |
816 // notification to update them all. | |
817 NotificationService::current()->Notify( | |
818 NotificationType::EXTENSION_APP_TOOLBAR_VISIBILITY_CHANGED, | |
819 Source<Extension>(extension_app), | |
820 Details<bool>(&new_val)); | |
821 | |
822 break; | |
823 } | |
824 | 783 |
825 case CommandBookmarkAllTabs: { | 784 case CommandBookmarkAllTabs: { |
826 UserMetrics::RecordAction( | 785 UserMetrics::RecordAction( |
827 UserMetricsAction("TabContextMenu_BookmarkAllTabs"), | 786 UserMetricsAction("TabContextMenu_BookmarkAllTabs"), |
828 profile_); | 787 profile_); |
829 | 788 |
830 delegate_->BookmarkAllTabs(); | 789 delegate_->BookmarkAllTabs(); |
831 break; | 790 break; |
832 } | 791 } |
833 | 792 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 // the TabContents. Deleting a TabContents results in a notification | 859 // the TabContents. Deleting a TabContents results in a notification |
901 // of type TAB_CONTENTS_DESTROYED; we do the necessary cleanup in | 860 // of type TAB_CONTENTS_DESTROYED; we do the necessary cleanup in |
902 // handling that notification. | 861 // handling that notification. |
903 | 862 |
904 InternalCloseTab(contents, i, false); | 863 InternalCloseTab(contents, i, false); |
905 } | 864 } |
906 } | 865 } |
907 break; | 866 break; |
908 } | 867 } |
909 | 868 |
910 case NotificationType::EXTENSION_APP_TOOLBAR_VISIBILITY_CHANGED: { | |
911 Extension* extension = Source<Extension>(source).ptr(); | |
912 bool* value = Details<bool>(details).ptr(); | |
913 TabContents* selected = GetSelectedTabContents(); | |
914 | |
915 if (selected && selected->extension_app() == extension) | |
916 delegate_->SetToolbarVisibility(*value); | |
917 | |
918 break; | |
919 } | |
920 | |
921 default: | 869 default: |
922 NOTREACHED(); | 870 NOTREACHED(); |
923 } | 871 } |
924 } | 872 } |
925 | 873 |
926 /////////////////////////////////////////////////////////////////////////////// | 874 /////////////////////////////////////////////////////////////////////////////// |
927 // TabStripModel, private: | 875 // TabStripModel, private: |
928 | 876 |
929 bool TabStripModel::IsNewTabAtEndOfTabStrip(TabContents* contents) const { | 877 bool TabStripModel::IsNewTabAtEndOfTabStrip(TabContents* contents) const { |
930 return LowerCaseEqualsASCII(contents->GetURL().spec(), | 878 return LowerCaseEqualsASCII(contents->GetURL().spec(), |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, | 1090 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, |
1143 TabMoved(moved_data->contents, index, to_position)); | 1091 TabMoved(moved_data->contents, index, to_position)); |
1144 } | 1092 } |
1145 | 1093 |
1146 // static | 1094 // static |
1147 bool TabStripModel::OpenerMatches(const TabContentsData* data, | 1095 bool TabStripModel::OpenerMatches(const TabContentsData* data, |
1148 const NavigationController* opener, | 1096 const NavigationController* opener, |
1149 bool use_group) { | 1097 bool use_group) { |
1150 return data->opener == opener || (use_group && data->group == opener); | 1098 return data->opener == opener || (use_group && data->group == opener); |
1151 } | 1099 } |
OLD | NEW |