| 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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 NOTREACHED(); | 825 NOTREACHED(); |
| 824 } | 826 } |
| 825 return false; | 827 return false; |
| 826 } | 828 } |
| 827 | 829 |
| 828 void TabStripModel::ExecuteContextMenuCommand( | 830 void TabStripModel::ExecuteContextMenuCommand( |
| 829 int context_index, ContextMenuCommand command_id) { | 831 int context_index, ContextMenuCommand command_id) { |
| 830 DCHECK(command_id > CommandFirst && command_id < CommandLast); | 832 DCHECK(command_id > CommandFirst && command_id < CommandLast); |
| 831 switch (command_id) { | 833 switch (command_id) { |
| 832 case CommandNewTab: | 834 case CommandNewTab: |
| 833 UserMetrics::RecordAction(UserMetricsAction("TabContextMenu_NewTab")); | 835 content::RecordAction(UserMetricsAction("TabContextMenu_NewTab")); |
| 834 delegate()->AddBlankTabAt(context_index + 1, true); | 836 delegate()->AddBlankTabAt(context_index + 1, true); |
| 835 break; | 837 break; |
| 836 | 838 |
| 837 case CommandReload: { | 839 case CommandReload: { |
| 838 UserMetrics::RecordAction(UserMetricsAction("TabContextMenu_Reload")); | 840 content::RecordAction(UserMetricsAction("TabContextMenu_Reload")); |
| 839 std::vector<int> indices = GetIndicesForCommand(context_index); | 841 std::vector<int> indices = GetIndicesForCommand(context_index); |
| 840 for (size_t i = 0; i < indices.size(); ++i) { | 842 for (size_t i = 0; i < indices.size(); ++i) { |
| 841 TabContentsWrapper* tab = GetTabContentsAt(indices[i]); | 843 TabContentsWrapper* tab = GetTabContentsAt(indices[i]); |
| 842 if (tab && tab->tab_contents()->delegate()->CanReloadContents( | 844 if (tab && tab->tab_contents()->delegate()->CanReloadContents( |
| 843 tab->tab_contents())) { | 845 tab->tab_contents())) { |
| 844 tab->controller().Reload(true); | 846 tab->controller().Reload(true); |
| 845 } | 847 } |
| 846 } | 848 } |
| 847 break; | 849 break; |
| 848 } | 850 } |
| 849 | 851 |
| 850 case CommandDuplicate: { | 852 case CommandDuplicate: { |
| 851 UserMetrics::RecordAction(UserMetricsAction("TabContextMenu_Duplicate")); | 853 content::RecordAction(UserMetricsAction("TabContextMenu_Duplicate")); |
| 852 std::vector<int> indices = GetIndicesForCommand(context_index); | 854 std::vector<int> indices = GetIndicesForCommand(context_index); |
| 853 // Copy the TabContents off as the indices will change as tabs are | 855 // Copy the TabContents off as the indices will change as tabs are |
| 854 // duplicated. | 856 // duplicated. |
| 855 std::vector<TabContentsWrapper*> tabs; | 857 std::vector<TabContentsWrapper*> tabs; |
| 856 for (size_t i = 0; i < indices.size(); ++i) | 858 for (size_t i = 0; i < indices.size(); ++i) |
| 857 tabs.push_back(GetTabContentsAt(indices[i])); | 859 tabs.push_back(GetTabContentsAt(indices[i])); |
| 858 for (size_t i = 0; i < tabs.size(); ++i) { | 860 for (size_t i = 0; i < tabs.size(); ++i) { |
| 859 int index = GetIndexOfTabContents(tabs[i]); | 861 int index = GetIndexOfTabContents(tabs[i]); |
| 860 if (index != -1 && delegate_->CanDuplicateContentsAt(index)) | 862 if (index != -1 && delegate_->CanDuplicateContentsAt(index)) |
| 861 delegate_->DuplicateContentsAt(index); | 863 delegate_->DuplicateContentsAt(index); |
| 862 } | 864 } |
| 863 break; | 865 break; |
| 864 } | 866 } |
| 865 | 867 |
| 866 case CommandCloseTab: { | 868 case CommandCloseTab: { |
| 867 UserMetrics::RecordAction(UserMetricsAction("TabContextMenu_CloseTab")); | 869 content::RecordAction(UserMetricsAction("TabContextMenu_CloseTab")); |
| 868 std::vector<int> indices = GetIndicesForCommand(context_index); | 870 std::vector<int> indices = GetIndicesForCommand(context_index); |
| 869 // Copy the TabContents off as the indices will change as we remove | 871 // Copy the TabContents off as the indices will change as we remove |
| 870 // things. | 872 // things. |
| 871 std::vector<TabContentsWrapper*> tabs; | 873 std::vector<TabContentsWrapper*> tabs; |
| 872 for (size_t i = 0; i < indices.size(); ++i) | 874 for (size_t i = 0; i < indices.size(); ++i) |
| 873 tabs.push_back(GetTabContentsAt(indices[i])); | 875 tabs.push_back(GetTabContentsAt(indices[i])); |
| 874 for (size_t i = 0; i < tabs.size() && delegate_->CanCloseTab(); ++i) { | 876 for (size_t i = 0; i < tabs.size() && delegate_->CanCloseTab(); ++i) { |
| 875 int index = GetIndexOfTabContents(tabs[i]); | 877 int index = GetIndexOfTabContents(tabs[i]); |
| 876 if (index != -1) { | 878 if (index != -1) { |
| 877 CloseTabContentsAt(index, | 879 CloseTabContentsAt(index, |
| 878 CLOSE_CREATE_HISTORICAL_TAB | CLOSE_USER_GESTURE); | 880 CLOSE_CREATE_HISTORICAL_TAB | CLOSE_USER_GESTURE); |
| 879 } | 881 } |
| 880 } | 882 } |
| 881 break; | 883 break; |
| 882 } | 884 } |
| 883 | 885 |
| 884 case CommandCloseOtherTabs: { | 886 case CommandCloseOtherTabs: { |
| 885 UserMetrics::RecordAction( | 887 content::RecordAction( |
| 886 UserMetricsAction("TabContextMenu_CloseOtherTabs")); | 888 UserMetricsAction("TabContextMenu_CloseOtherTabs")); |
| 887 InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), | 889 InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), |
| 888 CLOSE_CREATE_HISTORICAL_TAB); | 890 CLOSE_CREATE_HISTORICAL_TAB); |
| 889 break; | 891 break; |
| 890 } | 892 } |
| 891 | 893 |
| 892 case CommandCloseTabsToRight: { | 894 case CommandCloseTabsToRight: { |
| 893 UserMetrics::RecordAction( | 895 content::RecordAction( |
| 894 UserMetricsAction("TabContextMenu_CloseTabsToRight")); | 896 UserMetricsAction("TabContextMenu_CloseTabsToRight")); |
| 895 InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), | 897 InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), |
| 896 CLOSE_CREATE_HISTORICAL_TAB); | 898 CLOSE_CREATE_HISTORICAL_TAB); |
| 897 break; | 899 break; |
| 898 } | 900 } |
| 899 | 901 |
| 900 case CommandRestoreTab: { | 902 case CommandRestoreTab: { |
| 901 UserMetrics::RecordAction(UserMetricsAction("TabContextMenu_RestoreTab")); | 903 content::RecordAction(UserMetricsAction("TabContextMenu_RestoreTab")); |
| 902 delegate_->RestoreTab(); | 904 delegate_->RestoreTab(); |
| 903 break; | 905 break; |
| 904 } | 906 } |
| 905 | 907 |
| 906 case CommandTogglePinned: { | 908 case CommandTogglePinned: { |
| 907 UserMetrics::RecordAction( | 909 content::RecordAction( |
| 908 UserMetricsAction("TabContextMenu_TogglePinned")); | 910 UserMetricsAction("TabContextMenu_TogglePinned")); |
| 909 std::vector<int> indices = GetIndicesForCommand(context_index); | 911 std::vector<int> indices = GetIndicesForCommand(context_index); |
| 910 bool pin = WillContextMenuPin(context_index); | 912 bool pin = WillContextMenuPin(context_index); |
| 911 if (pin) { | 913 if (pin) { |
| 912 for (size_t i = 0; i < indices.size(); ++i) { | 914 for (size_t i = 0; i < indices.size(); ++i) { |
| 913 if (!IsAppTab(indices[i])) | 915 if (!IsAppTab(indices[i])) |
| 914 SetTabPinned(indices[i], true); | 916 SetTabPinned(indices[i], true); |
| 915 } | 917 } |
| 916 } else { | 918 } else { |
| 917 // Unpin from the back so that the order is maintained (unpinning can | 919 // Unpin from the back so that the order is maintained (unpinning can |
| 918 // trigger moving a tab). | 920 // trigger moving a tab). |
| 919 for (size_t i = indices.size(); i > 0; --i) { | 921 for (size_t i = indices.size(); i > 0; --i) { |
| 920 if (!IsAppTab(indices[i - 1])) | 922 if (!IsAppTab(indices[i - 1])) |
| 921 SetTabPinned(indices[i - 1], false); | 923 SetTabPinned(indices[i - 1], false); |
| 922 } | 924 } |
| 923 } | 925 } |
| 924 break; | 926 break; |
| 925 } | 927 } |
| 926 | 928 |
| 927 case CommandBookmarkAllTabs: { | 929 case CommandBookmarkAllTabs: { |
| 928 UserMetrics::RecordAction( | 930 content::RecordAction( |
| 929 UserMetricsAction("TabContextMenu_BookmarkAllTabs")); | 931 UserMetricsAction("TabContextMenu_BookmarkAllTabs")); |
| 930 | 932 |
| 931 delegate_->BookmarkAllTabs(); | 933 delegate_->BookmarkAllTabs(); |
| 932 break; | 934 break; |
| 933 } | 935 } |
| 934 | 936 |
| 935 case CommandSelectByDomain: | 937 case CommandSelectByDomain: |
| 936 case CommandSelectByOpener: { | 938 case CommandSelectByOpener: { |
| 937 std::vector<int> indices; | 939 std::vector<int> indices; |
| 938 if (command_id == CommandSelectByDomain) | 940 if (command_id == CommandSelectByDomain) |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1320 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
| 1319 const NavigationController* tab) { | 1321 const NavigationController* tab) { |
| 1320 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); | 1322 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); |
| 1321 i != contents_data_.end(); ++i) { | 1323 i != contents_data_.end(); ++i) { |
| 1322 if ((*i)->group == tab) | 1324 if ((*i)->group == tab) |
| 1323 (*i)->group = NULL; | 1325 (*i)->group = NULL; |
| 1324 if ((*i)->opener == tab) | 1326 if ((*i)->opener == tab) |
| 1325 (*i)->opener = NULL; | 1327 (*i)->opener = NULL; |
| 1326 } | 1328 } |
| 1327 } | 1329 } |
| OLD | NEW |