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) { |
| 706 DCHECK(ContainsIndex(index)); |
| 707 chrome::SetTabAudioMuted(GetWebContentsAt(index), mute); |
| 708 } |
| 709 |
| 710 bool TabStripModel::IsTabAudioMuted(int index) const { |
| 711 DCHECK(ContainsIndex(index)); |
| 712 return chrome::IsTabAudioMuted(GetWebContentsAt(index)); |
| 713 } |
| 714 |
704 bool TabStripModel::IsMiniTab(int index) const { | 715 bool TabStripModel::IsMiniTab(int index) const { |
705 return IsTabPinned(index) || IsAppTab(index); | 716 return IsTabPinned(index) || IsAppTab(index); |
706 } | 717 } |
707 | 718 |
708 bool TabStripModel::IsAppTab(int index) const { | 719 bool TabStripModel::IsAppTab(int index) const { |
709 WebContents* contents = GetWebContentsAt(index); | 720 WebContents* contents = GetWebContentsAt(index); |
710 return contents && extensions::TabHelper::FromWebContents(contents)->is_app(); | 721 return contents && extensions::TabHelper::FromWebContents(contents)->is_app(); |
711 } | 722 } |
712 | 723 |
713 bool TabStripModel::IsTabBlocked(int index) const { | 724 bool TabStripModel::IsTabBlocked(int index) const { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 | 923 |
913 case CommandTogglePinned: { | 924 case CommandTogglePinned: { |
914 std::vector<int> indices = GetIndicesForCommand(context_index); | 925 std::vector<int> indices = GetIndicesForCommand(context_index); |
915 for (size_t i = 0; i < indices.size(); ++i) { | 926 for (size_t i = 0; i < indices.size(); ++i) { |
916 if (!IsAppTab(indices[i])) | 927 if (!IsAppTab(indices[i])) |
917 return true; | 928 return true; |
918 } | 929 } |
919 return false; | 930 return false; |
920 } | 931 } |
921 | 932 |
| 933 case CommandToggleTabAudioMuted: { |
| 934 std::vector<int> indices = GetIndicesForCommand(context_index); |
| 935 for (size_t i = 0; i < indices.size(); ++i) { |
| 936 if (!chrome::CanToggleAudioMute(GetWebContentsAt(indices[i]))) |
| 937 return false; |
| 938 } |
| 939 return true; |
| 940 } |
| 941 |
922 case CommandBookmarkAllTabs: | 942 case CommandBookmarkAllTabs: |
923 return browser_defaults::bookmarks_enabled && | 943 return browser_defaults::bookmarks_enabled && |
924 delegate_->CanBookmarkAllTabs(); | 944 delegate_->CanBookmarkAllTabs(); |
925 | 945 |
926 case CommandSelectByDomain: | 946 case CommandSelectByDomain: |
927 case CommandSelectByOpener: | 947 case CommandSelectByOpener: |
928 return true; | 948 return true; |
929 | 949 |
930 default: | 950 default: |
931 NOTREACHED(); | 951 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 | 1039 // Unpin from the back so that the order is maintained (unpinning can |
1020 // trigger moving a tab). | 1040 // trigger moving a tab). |
1021 for (size_t i = indices.size(); i > 0; --i) { | 1041 for (size_t i = indices.size(); i > 0; --i) { |
1022 if (!IsAppTab(indices[i - 1])) | 1042 if (!IsAppTab(indices[i - 1])) |
1023 SetTabPinned(indices[i - 1], false); | 1043 SetTabPinned(indices[i - 1], false); |
1024 } | 1044 } |
1025 } | 1045 } |
1026 break; | 1046 break; |
1027 } | 1047 } |
1028 | 1048 |
| 1049 case CommandToggleTabAudioMuted: { |
| 1050 const std::vector<int>& indices = GetIndicesForCommand(context_index); |
| 1051 const bool mute = !chrome::AreAllTabsMuted(*this, indices); |
| 1052 if (mute) |
| 1053 content::RecordAction(UserMetricsAction("TabContextMenu_MuteTabs")); |
| 1054 else |
| 1055 content::RecordAction(UserMetricsAction("TabContextMenu_UnmuteTabs")); |
| 1056 for (std::vector<int>::const_iterator i = indices.begin(); |
| 1057 i != indices.end(); ++i) { |
| 1058 SetTabAudioMuted(*i, mute); |
| 1059 } |
| 1060 break; |
| 1061 } |
| 1062 |
1029 case CommandBookmarkAllTabs: { | 1063 case CommandBookmarkAllTabs: { |
1030 content::RecordAction( | 1064 content::RecordAction( |
1031 UserMetricsAction("TabContextMenu_BookmarkAllTabs")); | 1065 UserMetricsAction("TabContextMenu_BookmarkAllTabs")); |
1032 | 1066 |
1033 delegate_->BookmarkAllTabs(); | 1067 delegate_->BookmarkAllTabs(); |
1034 break; | 1068 break; |
1035 } | 1069 } |
1036 | 1070 |
1037 case CommandSelectByDomain: | 1071 case CommandSelectByDomain: |
1038 case CommandSelectByOpener: { | 1072 case CommandSelectByOpener: { |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1439 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
1406 const WebContents* tab) { | 1440 const WebContents* tab) { |
1407 for (WebContentsDataVector::const_iterator i = contents_data_.begin(); | 1441 for (WebContentsDataVector::const_iterator i = contents_data_.begin(); |
1408 i != contents_data_.end(); ++i) { | 1442 i != contents_data_.end(); ++i) { |
1409 if ((*i)->group() == tab) | 1443 if ((*i)->group() == tab) |
1410 (*i)->set_group(NULL); | 1444 (*i)->set_group(NULL); |
1411 if ((*i)->opener() == tab) | 1445 if ((*i)->opener() == tab) |
1412 (*i)->set_opener(NULL); | 1446 (*i)->set_opener(NULL); |
1413 } | 1447 } |
1414 } | 1448 } |
OLD | NEW |