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/extensions/api/tabs/tabs_api.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/strings/pattern.h" | 19 #include "base/strings/pattern.h" |
20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 23 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
24 #include "base/thread_task_runner_handle.h" | 25 #include "base/thread_task_runner_handle.h" |
25 #include "chrome/browser/apps/scoped_keep_alive.h" | 26 #include "chrome/browser/apps/scoped_keep_alive.h" |
26 #include "chrome/browser/chrome_notification_types.h" | 27 #include "chrome/browser/chrome_notification_types.h" |
27 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 28 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
28 #include "chrome/browser/extensions/api/tabs/windows_util.h" | 29 #include "chrome/browser/extensions/api/tabs/windows_util.h" |
29 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
30 #include "chrome/browser/extensions/extension_tab_util.h" | 31 #include "chrome/browser/extensions/extension_tab_util.h" |
31 #include "chrome/browser/extensions/tab_helper.h" | 32 #include "chrome/browser/extensions/tab_helper.h" |
32 #include "chrome/browser/extensions/window_controller.h" | 33 #include "chrome/browser/extensions/window_controller.h" |
33 #include "chrome/browser/extensions/window_controller_list.h" | 34 #include "chrome/browser/extensions/window_controller_list.h" |
34 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 35 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
35 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
36 #include "chrome/browser/sessions/session_tab_helper.h" | 37 #include "chrome/browser/sessions/session_tab_helper.h" |
37 #include "chrome/browser/translate/chrome_translate_client.h" | 38 #include "chrome/browser/translate/chrome_translate_client.h" |
38 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 39 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
39 #include "chrome/browser/ui/browser.h" | 40 #include "chrome/browser/ui/browser.h" |
40 #include "chrome/browser/ui/browser_commands.h" | 41 #include "chrome/browser/ui/browser_commands.h" |
41 #include "chrome/browser/ui/browser_finder.h" | 42 #include "chrome/browser/ui/browser_finder.h" |
42 #include "chrome/browser/ui/browser_iterator.h" | 43 #include "chrome/browser/ui/browser_iterator.h" |
43 #include "chrome/browser/ui/browser_navigator.h" | 44 #include "chrome/browser/ui/browser_navigator.h" |
44 #include "chrome/browser/ui/browser_tabstrip.h" | 45 #include "chrome/browser/ui/browser_tabstrip.h" |
45 #include "chrome/browser/ui/browser_window.h" | 46 #include "chrome/browser/ui/browser_window.h" |
46 #include "chrome/browser/ui/host_desktop.h" | 47 #include "chrome/browser/ui/host_desktop.h" |
47 #include "chrome/browser/ui/panels/panel_manager.h" | 48 #include "chrome/browser/ui/panels/panel_manager.h" |
48 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 49 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 50 #include "chrome/browser/ui/tabs/tab_utils.h" |
49 #include "chrome/browser/ui/window_sizer/window_sizer.h" | 51 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
50 #include "chrome/browser/web_applications/web_app.h" | 52 #include "chrome/browser/web_applications/web_app.h" |
51 #include "chrome/common/chrome_switches.h" | 53 #include "chrome/common/chrome_switches.h" |
52 #include "chrome/common/extensions/api/tabs.h" | 54 #include "chrome/common/extensions/api/tabs.h" |
53 #include "chrome/common/extensions/api/windows.h" | 55 #include "chrome/common/extensions/api/windows.h" |
54 #include "chrome/common/extensions/extension_constants.h" | 56 #include "chrome/common/extensions/extension_constants.h" |
55 #include "chrome/common/pref_names.h" | 57 #include "chrome/common/pref_names.h" |
56 #include "chrome/common/url_constants.h" | 58 #include "chrome/common/url_constants.h" |
57 #include "components/pref_registry/pref_registry_syncable.h" | 59 #include "components/pref_registry/pref_registry_syncable.h" |
58 #include "components/translate/core/browser/language_state.h" | 60 #include "components/translate/core/browser/language_state.h" |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 if (!MatchesBool(params->query_info.active.get(), | 947 if (!MatchesBool(params->query_info.active.get(), |
946 i == tab_strip->active_index())) { | 948 i == tab_strip->active_index())) { |
947 continue; | 949 continue; |
948 } | 950 } |
949 | 951 |
950 if (!MatchesBool(params->query_info.pinned.get(), | 952 if (!MatchesBool(params->query_info.pinned.get(), |
951 tab_strip->IsTabPinned(i))) { | 953 tab_strip->IsTabPinned(i))) { |
952 continue; | 954 continue; |
953 } | 955 } |
954 | 956 |
| 957 if (!MatchesBool(params->query_info.audible.get(), |
| 958 chrome::IsPlayingAudio(web_contents))) { |
| 959 continue; |
| 960 } |
| 961 |
| 962 if (!MatchesBool(params->query_info.muted.get(), |
| 963 chrome::IsTabAudioMuted(web_contents))) { |
| 964 continue; |
| 965 } |
| 966 |
955 if (!title.empty() && !base::MatchPattern(web_contents->GetTitle(), | 967 if (!title.empty() && !base::MatchPattern(web_contents->GetTitle(), |
956 base::UTF8ToUTF16(title))) | 968 base::UTF8ToUTF16(title))) |
957 continue; | 969 continue; |
958 | 970 |
959 if (!url_patterns.is_empty() && | 971 if (!url_patterns.is_empty() && |
960 !url_patterns.MatchesURL(web_contents->GetURL())) | 972 !url_patterns.MatchesURL(web_contents->GetURL())) |
961 continue; | 973 continue; |
962 | 974 |
963 if (loading_status_set && loading != web_contents->IsLoading()) | 975 if (loading_status_set && loading != web_contents->IsLoading()) |
964 continue; | 976 continue; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 } | 1233 } |
1222 | 1234 |
1223 if (params->update_properties.pinned.get()) { | 1235 if (params->update_properties.pinned.get()) { |
1224 bool pinned = *params->update_properties.pinned; | 1236 bool pinned = *params->update_properties.pinned; |
1225 tab_strip->SetTabPinned(tab_index, pinned); | 1237 tab_strip->SetTabPinned(tab_index, pinned); |
1226 | 1238 |
1227 // Update the tab index because it may move when being pinned. | 1239 // Update the tab index because it may move when being pinned. |
1228 tab_index = tab_strip->GetIndexOfWebContents(contents); | 1240 tab_index = tab_strip->GetIndexOfWebContents(contents); |
1229 } | 1241 } |
1230 | 1242 |
| 1243 if (params->update_properties.muted.get()) { |
| 1244 if (chrome::IsTabAudioMutingFeatureEnabled()) { |
| 1245 if (!chrome::CanToggleAudioMute(contents)) { |
| 1246 WriteToConsole( |
| 1247 content::CONSOLE_MESSAGE_LEVEL_WARNING, |
| 1248 base::StringPrintf( |
| 1249 "Cannot update mute state for tab %d, tab has audio or video " |
| 1250 "currently being captured", |
| 1251 tab_id)); |
| 1252 } else { |
| 1253 chrome::SetTabAudioMuted(contents, *params->update_properties.muted, |
| 1254 extension()->id()); |
| 1255 } |
| 1256 } else { |
| 1257 WriteToConsole(content::CONSOLE_MESSAGE_LEVEL_WARNING, |
| 1258 base::StringPrintf( |
| 1259 "Failed to update mute state, --%s must be enabled", |
| 1260 switches::kEnableTabAudioMuting)); |
| 1261 } |
| 1262 } |
| 1263 |
1231 if (params->update_properties.opener_tab_id.get()) { | 1264 if (params->update_properties.opener_tab_id.get()) { |
1232 int opener_id = *params->update_properties.opener_tab_id; | 1265 int opener_id = *params->update_properties.opener_tab_id; |
1233 | 1266 |
1234 WebContents* opener_contents = NULL; | 1267 WebContents* opener_contents = NULL; |
1235 if (!ExtensionTabUtil::GetTabById(opener_id, | 1268 if (!ExtensionTabUtil::GetTabById(opener_id, |
1236 GetProfile(), | 1269 GetProfile(), |
1237 include_incognito(), | 1270 include_incognito(), |
1238 NULL, | 1271 NULL, |
1239 NULL, | 1272 NULL, |
1240 &opener_contents, | 1273 &opener_contents, |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1993 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 2026 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
1994 zoom_settings.default_zoom_factor.reset(new double( | 2027 zoom_settings.default_zoom_factor.reset(new double( |
1995 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); | 2028 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); |
1996 | 2029 |
1997 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 2030 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
1998 SendResponse(true); | 2031 SendResponse(true); |
1999 return true; | 2032 return true; |
2000 } | 2033 } |
2001 | 2034 |
2002 } // namespace extensions | 2035 } // namespace extensions |
OLD | NEW |