| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/ui/tabs/tab_strip_model.h" | 5 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <map> | 8 #include <map> | 
| 9 #include <set> | 9 #include <set> | 
| 10 #include <string> | 10 #include <string> | 
| 11 | 11 | 
| 12 #include "base/macros.h" | 12 #include "base/macros.h" | 
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" | 
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" | 
|  | 15 #include "base/metrics/user_metrics.h" | 
| 15 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" | 
| 16 #include "chrome/browser/browser_shutdown.h" | 17 #include "chrome/browser/browser_shutdown.h" | 
| 17 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" | 
| 18 #include "chrome/browser/extensions/tab_helper.h" | 19 #include "chrome/browser/extensions/tab_helper.h" | 
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" | 
| 20 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 21 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 
| 21 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" | 22 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" | 
| 22 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 
| 23 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h" | 
| 24 #include "chrome/browser/ui/tabs/tab_utils.h" | 25 #include "chrome/browser/ui/tabs/tab_utils.h" | 
| 25 #include "chrome/browser/ui/web_contents_sizer.h" | 26 #include "chrome/browser/ui/web_contents_sizer.h" | 
| 26 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" | 
| 27 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 28 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 
| 28 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" | 
| 29 #include "content/public/browser/user_metrics.h" |  | 
| 30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" | 
| 31 #include "content/public/browser/web_contents_observer.h" | 31 #include "content/public/browser/web_contents_observer.h" | 
| 32 using base::UserMetricsAction; | 32 using base::UserMetricsAction; | 
| 33 using content::WebContents; | 33 using content::WebContents; | 
| 34 | 34 | 
| 35 namespace { | 35 namespace { | 
| 36 | 36 | 
| 37 // Returns true if the specified transition is one of the types that cause the | 37 // Returns true if the specified transition is one of the types that cause the | 
| 38 // opener relationships for the tab in which the transition occurred to be | 38 // opener relationships for the tab in which the transition occurred to be | 
| 39 // forgotten. This is generally any navigation that isn't a link click (i.e. | 39 // forgotten. This is generally any navigation that isn't a link click (i.e. | 
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 895       NOTREACHED(); | 895       NOTREACHED(); | 
| 896   } | 896   } | 
| 897   return false; | 897   return false; | 
| 898 } | 898 } | 
| 899 | 899 | 
| 900 void TabStripModel::ExecuteContextMenuCommand( | 900 void TabStripModel::ExecuteContextMenuCommand( | 
| 901     int context_index, ContextMenuCommand command_id) { | 901     int context_index, ContextMenuCommand command_id) { | 
| 902   DCHECK(command_id > CommandFirst && command_id < CommandLast); | 902   DCHECK(command_id > CommandFirst && command_id < CommandLast); | 
| 903   switch (command_id) { | 903   switch (command_id) { | 
| 904     case CommandNewTab: | 904     case CommandNewTab: | 
| 905       content::RecordAction(UserMetricsAction("TabContextMenu_NewTab")); | 905       base::RecordAction(UserMetricsAction("TabContextMenu_NewTab")); | 
| 906       UMA_HISTOGRAM_ENUMERATION("Tab.NewTab", | 906       UMA_HISTOGRAM_ENUMERATION("Tab.NewTab", | 
| 907                                 TabStripModel::NEW_TAB_CONTEXT_MENU, | 907                                 TabStripModel::NEW_TAB_CONTEXT_MENU, | 
| 908                                 TabStripModel::NEW_TAB_ENUM_COUNT); | 908                                 TabStripModel::NEW_TAB_ENUM_COUNT); | 
| 909       delegate()->AddTabAt(GURL(), context_index + 1, true); | 909       delegate()->AddTabAt(GURL(), context_index + 1, true); | 
| 910       break; | 910       break; | 
| 911 | 911 | 
| 912     case CommandReload: { | 912     case CommandReload: { | 
| 913       content::RecordAction(UserMetricsAction("TabContextMenu_Reload")); | 913       base::RecordAction(UserMetricsAction("TabContextMenu_Reload")); | 
| 914       std::vector<int> indices = GetIndicesForCommand(context_index); | 914       std::vector<int> indices = GetIndicesForCommand(context_index); | 
| 915       for (size_t i = 0; i < indices.size(); ++i) { | 915       for (size_t i = 0; i < indices.size(); ++i) { | 
| 916         WebContents* tab = GetWebContentsAt(indices[i]); | 916         WebContents* tab = GetWebContentsAt(indices[i]); | 
| 917         if (tab) { | 917         if (tab) { | 
| 918           CoreTabHelperDelegate* core_delegate = | 918           CoreTabHelperDelegate* core_delegate = | 
| 919               CoreTabHelper::FromWebContents(tab)->delegate(); | 919               CoreTabHelper::FromWebContents(tab)->delegate(); | 
| 920           if (!core_delegate || core_delegate->CanReloadContents(tab)) | 920           if (!core_delegate || core_delegate->CanReloadContents(tab)) | 
| 921             tab->GetController().Reload(content::ReloadType::NORMAL, true); | 921             tab->GetController().Reload(content::ReloadType::NORMAL, true); | 
| 922         } | 922         } | 
| 923       } | 923       } | 
| 924       break; | 924       break; | 
| 925     } | 925     } | 
| 926 | 926 | 
| 927     case CommandDuplicate: { | 927     case CommandDuplicate: { | 
| 928       content::RecordAction(UserMetricsAction("TabContextMenu_Duplicate")); | 928       base::RecordAction(UserMetricsAction("TabContextMenu_Duplicate")); | 
| 929       std::vector<int> indices = GetIndicesForCommand(context_index); | 929       std::vector<int> indices = GetIndicesForCommand(context_index); | 
| 930       // Copy the WebContents off as the indices will change as tabs are | 930       // Copy the WebContents off as the indices will change as tabs are | 
| 931       // duplicated. | 931       // duplicated. | 
| 932       std::vector<WebContents*> tabs; | 932       std::vector<WebContents*> tabs; | 
| 933       for (size_t i = 0; i < indices.size(); ++i) | 933       for (size_t i = 0; i < indices.size(); ++i) | 
| 934         tabs.push_back(GetWebContentsAt(indices[i])); | 934         tabs.push_back(GetWebContentsAt(indices[i])); | 
| 935       for (size_t i = 0; i < tabs.size(); ++i) { | 935       for (size_t i = 0; i < tabs.size(); ++i) { | 
| 936         int index = GetIndexOfWebContents(tabs[i]); | 936         int index = GetIndexOfWebContents(tabs[i]); | 
| 937         if (index != -1 && delegate_->CanDuplicateContentsAt(index)) | 937         if (index != -1 && delegate_->CanDuplicateContentsAt(index)) | 
| 938           delegate_->DuplicateContentsAt(index); | 938           delegate_->DuplicateContentsAt(index); | 
| 939       } | 939       } | 
| 940       break; | 940       break; | 
| 941     } | 941     } | 
| 942 | 942 | 
| 943     case CommandCloseTab: { | 943     case CommandCloseTab: { | 
| 944       content::RecordAction(UserMetricsAction("TabContextMenu_CloseTab")); | 944       base::RecordAction(UserMetricsAction("TabContextMenu_CloseTab")); | 
| 945       InternalCloseTabs(GetIndicesForCommand(context_index), | 945       InternalCloseTabs(GetIndicesForCommand(context_index), | 
| 946                         CLOSE_CREATE_HISTORICAL_TAB | CLOSE_USER_GESTURE); | 946                         CLOSE_CREATE_HISTORICAL_TAB | CLOSE_USER_GESTURE); | 
| 947       break; | 947       break; | 
| 948     } | 948     } | 
| 949 | 949 | 
| 950     case CommandCloseOtherTabs: { | 950     case CommandCloseOtherTabs: { | 
| 951       content::RecordAction( | 951       base::RecordAction(UserMetricsAction("TabContextMenu_CloseOtherTabs")); | 
| 952           UserMetricsAction("TabContextMenu_CloseOtherTabs")); |  | 
| 953       InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), | 952       InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), | 
| 954                         CLOSE_CREATE_HISTORICAL_TAB); | 953                         CLOSE_CREATE_HISTORICAL_TAB); | 
| 955       break; | 954       break; | 
| 956     } | 955     } | 
| 957 | 956 | 
| 958     case CommandCloseTabsToRight: { | 957     case CommandCloseTabsToRight: { | 
| 959       content::RecordAction( | 958       base::RecordAction(UserMetricsAction("TabContextMenu_CloseTabsToRight")); | 
| 960           UserMetricsAction("TabContextMenu_CloseTabsToRight")); |  | 
| 961       InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), | 959       InternalCloseTabs(GetIndicesClosedByCommand(context_index, command_id), | 
| 962                         CLOSE_CREATE_HISTORICAL_TAB); | 960                         CLOSE_CREATE_HISTORICAL_TAB); | 
| 963       break; | 961       break; | 
| 964     } | 962     } | 
| 965 | 963 | 
| 966     case CommandRestoreTab: { | 964     case CommandRestoreTab: { | 
| 967       content::RecordAction(UserMetricsAction("TabContextMenu_RestoreTab")); | 965       base::RecordAction(UserMetricsAction("TabContextMenu_RestoreTab")); | 
| 968       delegate_->RestoreTab(); | 966       delegate_->RestoreTab(); | 
| 969       break; | 967       break; | 
| 970     } | 968     } | 
| 971 | 969 | 
| 972     case CommandTogglePinned: { | 970     case CommandTogglePinned: { | 
| 973       content::RecordAction( | 971       base::RecordAction(UserMetricsAction("TabContextMenu_TogglePinned")); | 
| 974           UserMetricsAction("TabContextMenu_TogglePinned")); |  | 
| 975       std::vector<int> indices = GetIndicesForCommand(context_index); | 972       std::vector<int> indices = GetIndicesForCommand(context_index); | 
| 976       bool pin = WillContextMenuPin(context_index); | 973       bool pin = WillContextMenuPin(context_index); | 
| 977       if (pin) { | 974       if (pin) { | 
| 978         for (size_t i = 0; i < indices.size(); ++i) | 975         for (size_t i = 0; i < indices.size(); ++i) | 
| 979           SetTabPinned(indices[i], true); | 976           SetTabPinned(indices[i], true); | 
| 980       } else { | 977       } else { | 
| 981         // Unpin from the back so that the order is maintained (unpinning can | 978         // Unpin from the back so that the order is maintained (unpinning can | 
| 982         // trigger moving a tab). | 979         // trigger moving a tab). | 
| 983         for (size_t i = indices.size(); i > 0; --i) | 980         for (size_t i = indices.size(); i > 0; --i) | 
| 984           SetTabPinned(indices[i - 1], false); | 981           SetTabPinned(indices[i - 1], false); | 
| 985       } | 982       } | 
| 986       break; | 983       break; | 
| 987     } | 984     } | 
| 988 | 985 | 
| 989     case CommandToggleTabAudioMuted: { | 986     case CommandToggleTabAudioMuted: { | 
| 990       const std::vector<int>& indices = GetIndicesForCommand(context_index); | 987       const std::vector<int>& indices = GetIndicesForCommand(context_index); | 
| 991       const bool mute = !chrome::AreAllTabsMuted(*this, indices); | 988       const bool mute = !chrome::AreAllTabsMuted(*this, indices); | 
| 992       if (mute) | 989       if (mute) | 
| 993         content::RecordAction(UserMetricsAction("TabContextMenu_MuteTabs")); | 990         base::RecordAction(UserMetricsAction("TabContextMenu_MuteTabs")); | 
| 994       else | 991       else | 
| 995         content::RecordAction(UserMetricsAction("TabContextMenu_UnmuteTabs")); | 992         base::RecordAction(UserMetricsAction("TabContextMenu_UnmuteTabs")); | 
| 996       for (std::vector<int>::const_iterator i = indices.begin(); | 993       for (std::vector<int>::const_iterator i = indices.begin(); | 
| 997            i != indices.end(); ++i) { | 994            i != indices.end(); ++i) { | 
| 998         chrome::SetTabAudioMuted(GetWebContentsAt(*i), mute, | 995         chrome::SetTabAudioMuted(GetWebContentsAt(*i), mute, | 
| 999                                  TabMutedReason::CONTEXT_MENU, std::string()); | 996                                  TabMutedReason::CONTEXT_MENU, std::string()); | 
| 1000       } | 997       } | 
| 1001       break; | 998       break; | 
| 1002     } | 999     } | 
| 1003 | 1000 | 
| 1004     case CommandBookmarkAllTabs: { | 1001     case CommandBookmarkAllTabs: { | 
| 1005       content::RecordAction( | 1002       base::RecordAction(UserMetricsAction("TabContextMenu_BookmarkAllTabs")); | 
| 1006           UserMetricsAction("TabContextMenu_BookmarkAllTabs")); |  | 
| 1007 | 1003 | 
| 1008       delegate_->BookmarkAllTabs(); | 1004       delegate_->BookmarkAllTabs(); | 
| 1009       break; | 1005       break; | 
| 1010     } | 1006     } | 
| 1011 | 1007 | 
| 1012     case CommandSelectByDomain: | 1008     case CommandSelectByDomain: | 
| 1013     case CommandSelectByOpener: { | 1009     case CommandSelectByOpener: { | 
| 1014       std::vector<int> indices; | 1010       std::vector<int> indices; | 
| 1015       if (command_id == CommandSelectByDomain) | 1011       if (command_id == CommandSelectByDomain) | 
| 1016         GetIndicesWithSameDomain(context_index, &indices); | 1012         GetIndicesWithSameDomain(context_index, &indices); | 
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1371 | 1367 | 
| 1372 void TabStripModel::FixOpenersAndGroupsReferencing(int index) { | 1368 void TabStripModel::FixOpenersAndGroupsReferencing(int index) { | 
| 1373   WebContents* old_contents = GetWebContentsAtImpl(index); | 1369   WebContents* old_contents = GetWebContentsAtImpl(index); | 
| 1374   for (auto& data : contents_data_) { | 1370   for (auto& data : contents_data_) { | 
| 1375     if (data->group() == old_contents) | 1371     if (data->group() == old_contents) | 
| 1376       data->set_group(contents_data_[index]->group()); | 1372       data->set_group(contents_data_[index]->group()); | 
| 1377     if (data->opener() == old_contents) | 1373     if (data->opener() == old_contents) | 
| 1378       data->set_opener(contents_data_[index]->opener()); | 1374       data->set_opener(contents_data_[index]->opener()); | 
| 1379   } | 1375   } | 
| 1380 } | 1376 } | 
| OLD | NEW | 
|---|