Chromium Code Reviews| 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 <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/browser_shutdown.h" | 14 #include "chrome/browser/browser_shutdown.h" |
| 15 #include "chrome/browser/defaults.h" | 15 #include "chrome/browser/defaults.h" |
| 16 #include "chrome/browser/extensions/tab_helper.h" | 16 #include "chrome/browser/extensions/tab_helper.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 18 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 19 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" | 19 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h" |
| 22 #include "chrome/browser/ui/tabs/tab_utils.h" | |
| 22 #include "chrome/browser/ui/web_contents_sizer.h" | 23 #include "chrome/browser/ui/web_contents_sizer.h" |
| 23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 24 #include "components/web_modal/popup_manager.h" | 25 #include "components/web_modal/popup_manager.h" |
| 25 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
| 27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/browser/web_contents_observer.h" | 29 #include "content/public/browser/web_contents_observer.h" |
| 29 using base::UserMetricsAction; | 30 using base::UserMetricsAction; |
| 30 using content::WebContents; | 31 using content::WebContents; |
| 31 | 32 |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 694 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, | 695 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, |
| 695 TabPinnedStateChanged(contents_data_[index]->web_contents(), | 696 TabPinnedStateChanged(contents_data_[index]->web_contents(), |
| 696 index)); | 697 index)); |
| 697 } | 698 } |
| 698 | 699 |
| 699 bool TabStripModel::IsTabPinned(int index) const { | 700 bool TabStripModel::IsTabPinned(int index) const { |
| 700 DCHECK(ContainsIndex(index)); | 701 DCHECK(ContainsIndex(index)); |
| 701 return contents_data_[index]->pinned(); | 702 return contents_data_[index]->pinned(); |
| 702 } | 703 } |
| 703 | 704 |
| 705 void TabStripModel::SetTabAudioMuted(int index, bool mute) { | |
|
sky
2014/09/23 22:58:17
Move this and IsTabAudioMuted into tab_util. My ra
miu
2014/09/24 22:34:15
Done. Agreed; I wasn't encapsulating this functio
sky
2014/09/25 19:25:04
Can you also move the setters? Long term TabStripM
miu
2014/09/25 22:49:36
Done.
| |
| 706 content::WebContents* const contents = GetWebContentsAt(index); | |
| 707 if (!contents || !chrome::CanToggleAudioMute(contents)) | |
| 708 return; | |
| 709 contents->SetAudioMuted(mute); | |
| 710 } | |
| 711 | |
| 712 bool TabStripModel::IsTabAudioMuted(int index) const { | |
| 713 content::WebContents* const contents = GetWebContentsAt(index); | |
| 714 return contents && contents->IsAudioMuted(); | |
| 715 } | |
| 716 | |
| 704 bool TabStripModel::IsMiniTab(int index) const { | 717 bool TabStripModel::IsMiniTab(int index) const { |
| 705 return IsTabPinned(index) || IsAppTab(index); | 718 return IsTabPinned(index) || IsAppTab(index); |
| 706 } | 719 } |
| 707 | 720 |
| 708 bool TabStripModel::IsAppTab(int index) const { | 721 bool TabStripModel::IsAppTab(int index) const { |
| 709 WebContents* contents = GetWebContentsAt(index); | 722 WebContents* contents = GetWebContentsAt(index); |
| 710 return contents && extensions::TabHelper::FromWebContents(contents)->is_app(); | 723 return contents && extensions::TabHelper::FromWebContents(contents)->is_app(); |
| 711 } | 724 } |
| 712 | 725 |
| 713 bool TabStripModel::IsTabBlocked(int index) const { | 726 bool TabStripModel::IsTabBlocked(int index) const { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 | 925 |
| 913 case CommandTogglePinned: { | 926 case CommandTogglePinned: { |
| 914 std::vector<int> indices = GetIndicesForCommand(context_index); | 927 std::vector<int> indices = GetIndicesForCommand(context_index); |
| 915 for (size_t i = 0; i < indices.size(); ++i) { | 928 for (size_t i = 0; i < indices.size(); ++i) { |
| 916 if (!IsAppTab(indices[i])) | 929 if (!IsAppTab(indices[i])) |
| 917 return true; | 930 return true; |
| 918 } | 931 } |
| 919 return false; | 932 return false; |
| 920 } | 933 } |
| 921 | 934 |
| 935 case CommandToggleTabAudioMuted: { | |
| 936 if (!chrome::IsTabAudioMutingFeatureEnabled()) | |
|
sky
2014/09/23 22:58:17
Does this check matter here?
miu
2014/09/24 22:34:15
Done since the CanToggleAudioMute() should return
| |
| 937 return false; | |
| 938 std::vector<int> indices = GetIndicesForCommand(context_index); | |
| 939 for (size_t i = 0; i < indices.size(); ++i) { | |
| 940 WebContents* const tab = GetWebContentsAt(indices[i]); | |
| 941 if (!tab || !chrome::CanToggleAudioMute(tab)) | |
|
sky
2014/09/23 22:58:17
You shouldn't need the !tab here, at which point y
miu
2014/09/24 22:34:15
Done.
| |
| 942 return false; | |
| 943 } | |
| 944 return true; | |
| 945 } | |
| 946 | |
| 922 case CommandBookmarkAllTabs: | 947 case CommandBookmarkAllTabs: |
| 923 return browser_defaults::bookmarks_enabled && | 948 return browser_defaults::bookmarks_enabled && |
| 924 delegate_->CanBookmarkAllTabs(); | 949 delegate_->CanBookmarkAllTabs(); |
| 925 | 950 |
| 926 case CommandSelectByDomain: | 951 case CommandSelectByDomain: |
| 927 case CommandSelectByOpener: | 952 case CommandSelectByOpener: |
| 928 return true; | 953 return true; |
| 929 | 954 |
| 930 default: | 955 default: |
| 931 NOTREACHED(); | 956 NOTREACHED(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1019 // Unpin from the back so that the order is maintained (unpinning can | 1044 // Unpin from the back so that the order is maintained (unpinning can |
| 1020 // trigger moving a tab). | 1045 // trigger moving a tab). |
| 1021 for (size_t i = indices.size(); i > 0; --i) { | 1046 for (size_t i = indices.size(); i > 0; --i) { |
| 1022 if (!IsAppTab(indices[i - 1])) | 1047 if (!IsAppTab(indices[i - 1])) |
| 1023 SetTabPinned(indices[i - 1], false); | 1048 SetTabPinned(indices[i - 1], false); |
| 1024 } | 1049 } |
| 1025 } | 1050 } |
| 1026 break; | 1051 break; |
| 1027 } | 1052 } |
| 1028 | 1053 |
| 1054 case CommandToggleTabAudioMuted: { | |
| 1055 const bool mute = WillContextMenuMute(context_index); | |
| 1056 if (mute) | |
| 1057 content::RecordAction(UserMetricsAction("TabContextMenu_MuteTabs")); | |
| 1058 else | |
| 1059 content::RecordAction(UserMetricsAction("TabContextMenu_UnmuteTabs")); | |
| 1060 std::vector<int> indices = GetIndicesForCommand(context_index); | |
| 1061 for (size_t i = 0; i < indices.size(); ++i) | |
| 1062 SetTabAudioMuted(indices[i], mute); | |
| 1063 break; | |
| 1064 } | |
| 1065 | |
| 1029 case CommandBookmarkAllTabs: { | 1066 case CommandBookmarkAllTabs: { |
| 1030 content::RecordAction( | 1067 content::RecordAction( |
| 1031 UserMetricsAction("TabContextMenu_BookmarkAllTabs")); | 1068 UserMetricsAction("TabContextMenu_BookmarkAllTabs")); |
| 1032 | 1069 |
| 1033 delegate_->BookmarkAllTabs(); | 1070 delegate_->BookmarkAllTabs(); |
| 1034 break; | 1071 break; |
| 1035 } | 1072 } |
| 1036 | 1073 |
| 1037 case CommandSelectByDomain: | 1074 case CommandSelectByDomain: |
| 1038 case CommandSelectByOpener: { | 1075 case CommandSelectByOpener: { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1084 std::vector<int> indices = GetIndicesForCommand(index); | 1121 std::vector<int> indices = GetIndicesForCommand(index); |
| 1085 // If all tabs are pinned, then we unpin, otherwise we pin. | 1122 // If all tabs are pinned, then we unpin, otherwise we pin. |
| 1086 bool all_pinned = true; | 1123 bool all_pinned = true; |
| 1087 for (size_t i = 0; i < indices.size() && all_pinned; ++i) { | 1124 for (size_t i = 0; i < indices.size() && all_pinned; ++i) { |
| 1088 if (!IsAppTab(index)) // We never change app tabs. | 1125 if (!IsAppTab(index)) // We never change app tabs. |
| 1089 all_pinned = IsTabPinned(indices[i]); | 1126 all_pinned = IsTabPinned(indices[i]); |
| 1090 } | 1127 } |
| 1091 return !all_pinned; | 1128 return !all_pinned; |
| 1092 } | 1129 } |
| 1093 | 1130 |
| 1131 bool TabStripModel::WillContextMenuMute(int index) { | |
|
sky
2014/09/23 22:58:17
Move this to tab_util and make it take a const std
miu
2014/09/24 22:34:15
Done.
| |
| 1132 std::vector<int> indices = GetIndicesForCommand(index); | |
| 1133 // If all tabs are muted, then we unmute, otherwise we mute. | |
| 1134 for (size_t i = 0; i < indices.size(); ++i) { | |
| 1135 if (!IsTabAudioMuted(indices[i])) | |
| 1136 return true; | |
| 1137 } | |
| 1138 return false; | |
| 1139 } | |
| 1140 | |
| 1094 // static | 1141 // static |
| 1095 bool TabStripModel::ContextMenuCommandToBrowserCommand(int cmd_id, | 1142 bool TabStripModel::ContextMenuCommandToBrowserCommand(int cmd_id, |
| 1096 int* browser_cmd) { | 1143 int* browser_cmd) { |
| 1097 switch (cmd_id) { | 1144 switch (cmd_id) { |
| 1098 case CommandNewTab: | 1145 case CommandNewTab: |
| 1099 *browser_cmd = IDC_NEW_TAB; | 1146 *browser_cmd = IDC_NEW_TAB; |
| 1100 break; | 1147 break; |
| 1101 case CommandReload: | 1148 case CommandReload: |
| 1102 *browser_cmd = IDC_RELOAD; | 1149 *browser_cmd = IDC_RELOAD; |
| 1103 break; | 1150 break; |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1405 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1452 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
| 1406 const WebContents* tab) { | 1453 const WebContents* tab) { |
| 1407 for (WebContentsDataVector::const_iterator i = contents_data_.begin(); | 1454 for (WebContentsDataVector::const_iterator i = contents_data_.begin(); |
| 1408 i != contents_data_.end(); ++i) { | 1455 i != contents_data_.end(); ++i) { |
| 1409 if ((*i)->group() == tab) | 1456 if ((*i)->group() == tab) |
| 1410 (*i)->set_group(NULL); | 1457 (*i)->set_group(NULL); |
| 1411 if ((*i)->opener() == tab) | 1458 if ((*i)->opener() == tab) |
| 1412 (*i)->set_opener(NULL); | 1459 (*i)->set_opener(NULL); |
| 1413 } | 1460 } |
| 1414 } | 1461 } |
| OLD | NEW |