| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/tabs/tab_strip_model_delegate.h" | 22 #include "chrome/browser/tabs/tab_strip_model_delegate.h" |
| 23 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" | 23 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "content/browser/tab_contents/navigation_controller.h" | 28 #include "content/browser/tab_contents/navigation_controller.h" |
| 29 #include "content/browser/tab_contents/tab_contents.h" | 29 #include "content/browser/tab_contents/tab_contents.h" |
| 30 #include "content/browser/tab_contents/tab_contents_delegate.h" | 30 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 31 #include "content/browser/tab_contents/tab_contents_view.h" | 31 #include "content/browser/tab_contents/tab_contents_view.h" |
| 32 #include "content/browser/user_metrics.h" | |
| 33 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
| 34 #include "content/public/browser/user_metrics.h" |
| 35 |
| 36 using content::UserMetricsAction; |
| 35 | 37 |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 38 // Returns true if the specified transition is one of the types that cause the | 40 // Returns true if the specified transition is one of the types that cause the |
| 39 // opener relationships for the tab in which the transition occured to be | 41 // opener relationships for the tab in which the transition occured to be |
| 40 // forgotten. This is generally any navigation that isn't a link click (i.e. | 42 // forgotten. This is generally any navigation that isn't a link click (i.e. |
| 41 // any navigation that can be considered to be the start of a new task distinct | 43 // any navigation that can be considered to be the start of a new task distinct |
| 42 // from what had previously occurred in that tab). | 44 // from what had previously occurred in that tab). |
| 43 bool ShouldForgetOpenersForTransition(content::PageTransition transition) { | 45 bool ShouldForgetOpenersForTransition(content::PageTransition transition) { |
| 44 return transition == content::PAGE_TRANSITION_TYPED || | 46 return transition == content::PAGE_TRANSITION_TYPED || |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 NOTREACHED(); | 828 NOTREACHED(); |
| 827 } | 829 } |
| 828 return false; | 830 return false; |
| 829 } | 831 } |
| 830 | 832 |
| 831 void TabStripModel::ExecuteContextMenuCommand( | 833 void TabStripModel::ExecuteContextMenuCommand( |
| 832 int context_index, ContextMenuCommand command_id) { | 834 int context_index, ContextMenuCommand command_id) { |
| 833 DCHECK(command_id > CommandFirst && command_id < CommandLast); | 835 DCHECK(command_id > CommandFirst && command_id < CommandLast); |
| 834 switch (command_id) { | 836 switch (command_id) { |
| 835 case CommandNewTab: | 837 case CommandNewTab: |
| 836 UserMetrics::RecordAction(UserMetricsAction("TabContextMenu_NewTab")); | 838 content::RecordAction(UserMetricsAction("TabContextMenu_NewTab")); |
| 837 delegate()->AddBlankTabAt(context_index + 1, true); | 839 delegate()->AddBlankTabAt(context_index + 1, true); |
| 838 break; | 840 break; |
| 839 | 841 |
| 840 case CommandReload: { | 842 case CommandReload: { |
| 841 UserMetrics::RecordAction(UserMetricsAction("TabContextMenu_Reload")); | 843 content::RecordAction(UserMetricsAction("TabContextMenu_Reload")); |
| 842 std::vector<int> indices = GetIndicesForCommand(context_index); | 844 std::vector<int> indices = GetIndicesForCommand(context_index); |
| 843 for (size_t i = 0; i < indices.size(); ++i) { | 845 for (size_t i = 0; i < indices.size(); ++i) { |
| 844 TabContentsWrapper* tab = GetTabContentsAt(indices[i]); | 846 TabContentsWrapper* tab = GetTabContentsAt(indices[i]); |
| 845 if (tab && tab->tab_contents()->delegate()->CanReloadContents( | 847 if (tab && tab->tab_contents()->delegate()->CanReloadContents( |
| 846 tab->tab_contents())) { | 848 tab->tab_contents())) { |
| 847 tab->tab_contents()->controller().Reload(true); | 849 tab->tab_contents()->controller().Reload(true); |
| 848 } | 850 } |
| 849 } | 851 } |
| 850 break; | 852 break; |
| 851 } | 853 } |
| 852 | 854 |
| 853 case CommandDuplicate: { | 855 case CommandDuplicate: { |
| 854 UserMetrics::RecordAction(UserMetricsAction("TabContextMenu_Duplicate")); | 856 content::RecordAction(UserMetricsAction("TabContextMenu_Duplicate")); |
| 855 std::vector<int> indices = GetIndicesForCommand(context_index); | 857 std::vector<int> indices = GetIndicesForCommand(context_index); |
| 856 // Copy the TabContents off as the indices will change as tabs are | 858 // Copy the TabContents off as the indices will change as tabs are |
| 857 // duplicated. | 859 // duplicated. |
| 858 std::vector<TabContentsWrapper*> tabs; | 860 std::vector<TabContentsWrapper*> tabs; |
| 859 for (size_t i = 0; i < indices.size(); ++i) | 861 for (size_t i = 0; i < indices.size(); ++i) |
| 860 tabs.push_back(GetTabContentsAt(indices[i])); | 862 tabs.push_back(GetTabContentsAt(indices[i])); |
| 861 for (size_t i = 0; i < tabs.size(); ++i) { | 863 for (size_t i = 0; i < tabs.size(); ++i) { |
| 862 int index = GetIndexOfTabContents(tabs[i]); | 864 int index = GetIndexOfTabContents(tabs[i]); |
| 863 if (index != -1 && delegate_->CanDuplicateContentsAt(index)) | 865 if (index != -1 && delegate_->CanDuplicateContentsAt(index)) |
| 864 delegate_->DuplicateContentsAt(index); | 866 delegate_->DuplicateContentsAt(index); |
| 865 } | 867 } |
| 866 break; | 868 break; |
| 867 } | 869 } |
| 868 | 870 |
| 869 case CommandCloseTab: { | 871 case CommandCloseTab: { |
| 870 UserMetrics::RecordAction(UserMetricsAction("TabContextMenu_CloseTab")); | 872 content::RecordAction(UserMetricsAction("TabContextMenu_CloseTab")); |
| 871 std::vector<int> indices = GetIndicesForCommand(context_index); | 873 std::vector<int> indices = GetIndicesForCommand(context_index); |
| 872 // Copy the TabContents off as the indices will change as we remove | 874 // Copy the TabContents off as the indices will change as we remove |
| 873 // things. | 875 // things. |
| 874 std::vector<TabContentsWrapper*> tabs; | 876 std::vector<TabContentsWrapper*> tabs; |
| 875 for (size_t i = 0; i < indices.size(); ++i) | 877 for (size_t i = 0; i < indices.size(); ++i) |
| 876 tabs.push_back(GetTabContentsAt(indices[i])); | 878 tabs.push_back(GetTabContentsAt(indices[i])); |
| 877 for (size_t i = 0; i < tabs.size() && delegate_->CanCloseTab(); ++i) { | 879 for (size_t i = 0; i < tabs.size() && delegate_->CanCloseTab(); ++i) { |
| 878 int index = GetIndexOfTabContents(tabs[i]); | 880 int index = GetIndexOfTabContents(tabs[i]); |
| 879 if (index != -1) { | 881 if (index != -1) { |
| 880 CloseTabContentsAt(index, | 882 CloseTabContentsAt(index, |
| 881 CLOSE_CREATE_HISTORICAL_TAB | CLOSE_USER_GESTURE); | 883 CLOSE_CREATE_HISTORICAL_TAB | CLOSE_USER_GESTURE); |
| 882 } | 884 } |
| 883 } | 885 } |
| 884 break; | 886 break; |
| 885 } | 887 } |
| 886 | 888 |
| 887 case CommandCloseOtherTabs: { | 889 case CommandCloseOtherTabs: { |
| 888 UserMetrics::RecordAction( | 890 content::RecordAction( |
| 889 UserMetricsAction("TabContextMenu_CloseOtherTabs")); | 891 UserMetricsAction("TabContextMenu_CloseOtherTabs")); |
| 890 InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), | 892 InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), |
| 891 CLOSE_CREATE_HISTORICAL_TAB); | 893 CLOSE_CREATE_HISTORICAL_TAB); |
| 892 break; | 894 break; |
| 893 } | 895 } |
| 894 | 896 |
| 895 case CommandCloseTabsToRight: { | 897 case CommandCloseTabsToRight: { |
| 896 UserMetrics::RecordAction( | 898 content::RecordAction( |
| 897 UserMetricsAction("TabContextMenu_CloseTabsToRight")); | 899 UserMetricsAction("TabContextMenu_CloseTabsToRight")); |
| 898 InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), | 900 InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), |
| 899 CLOSE_CREATE_HISTORICAL_TAB); | 901 CLOSE_CREATE_HISTORICAL_TAB); |
| 900 break; | 902 break; |
| 901 } | 903 } |
| 902 | 904 |
| 903 case CommandRestoreTab: { | 905 case CommandRestoreTab: { |
| 904 UserMetrics::RecordAction(UserMetricsAction("TabContextMenu_RestoreTab")); | 906 content::RecordAction(UserMetricsAction("TabContextMenu_RestoreTab")); |
| 905 delegate_->RestoreTab(); | 907 delegate_->RestoreTab(); |
| 906 break; | 908 break; |
| 907 } | 909 } |
| 908 | 910 |
| 909 case CommandTogglePinned: { | 911 case CommandTogglePinned: { |
| 910 UserMetrics::RecordAction( | 912 content::RecordAction( |
| 911 UserMetricsAction("TabContextMenu_TogglePinned")); | 913 UserMetricsAction("TabContextMenu_TogglePinned")); |
| 912 std::vector<int> indices = GetIndicesForCommand(context_index); | 914 std::vector<int> indices = GetIndicesForCommand(context_index); |
| 913 bool pin = WillContextMenuPin(context_index); | 915 bool pin = WillContextMenuPin(context_index); |
| 914 if (pin) { | 916 if (pin) { |
| 915 for (size_t i = 0; i < indices.size(); ++i) { | 917 for (size_t i = 0; i < indices.size(); ++i) { |
| 916 if (!IsAppTab(indices[i])) | 918 if (!IsAppTab(indices[i])) |
| 917 SetTabPinned(indices[i], true); | 919 SetTabPinned(indices[i], true); |
| 918 } | 920 } |
| 919 } else { | 921 } else { |
| 920 // Unpin from the back so that the order is maintained (unpinning can | 922 // Unpin from the back so that the order is maintained (unpinning can |
| 921 // trigger moving a tab). | 923 // trigger moving a tab). |
| 922 for (size_t i = indices.size(); i > 0; --i) { | 924 for (size_t i = indices.size(); i > 0; --i) { |
| 923 if (!IsAppTab(indices[i - 1])) | 925 if (!IsAppTab(indices[i - 1])) |
| 924 SetTabPinned(indices[i - 1], false); | 926 SetTabPinned(indices[i - 1], false); |
| 925 } | 927 } |
| 926 } | 928 } |
| 927 break; | 929 break; |
| 928 } | 930 } |
| 929 | 931 |
| 930 case CommandBookmarkAllTabs: { | 932 case CommandBookmarkAllTabs: { |
| 931 UserMetrics::RecordAction( | 933 content::RecordAction( |
| 932 UserMetricsAction("TabContextMenu_BookmarkAllTabs")); | 934 UserMetricsAction("TabContextMenu_BookmarkAllTabs")); |
| 933 | 935 |
| 934 delegate_->BookmarkAllTabs(); | 936 delegate_->BookmarkAllTabs(); |
| 935 break; | 937 break; |
| 936 } | 938 } |
| 937 | 939 |
| 938 case CommandSelectByDomain: | 940 case CommandSelectByDomain: |
| 939 case CommandSelectByOpener: { | 941 case CommandSelectByOpener: { |
| 940 std::vector<int> indices; | 942 std::vector<int> indices; |
| 941 if (command_id == CommandSelectByDomain) | 943 if (command_id == CommandSelectByDomain) |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1323 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
| 1322 const NavigationController* tab) { | 1324 const NavigationController* tab) { |
| 1323 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); | 1325 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); |
| 1324 i != contents_data_.end(); ++i) { | 1326 i != contents_data_.end(); ++i) { |
| 1325 if ((*i)->group == tab) | 1327 if ((*i)->group == tab) |
| 1326 (*i)->group = NULL; | 1328 (*i)->group = NULL; |
| 1327 if ((*i)->opener == tab) | 1329 if ((*i)->opener == tab) |
| 1328 (*i)->opener = NULL; | 1330 (*i)->opener = NULL; |
| 1329 } | 1331 } |
| 1330 } | 1332 } |
| OLD | NEW |