| 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/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "chrome/browser/apps/scoped_keep_alive.h" | 23 #include "chrome/browser/apps/scoped_keep_alive.h" |
| 23 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
| 24 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 25 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 25 #include "chrome/browser/extensions/api/tabs/windows_util.h" | 26 #include "chrome/browser/extensions/api/tabs/windows_util.h" |
| 26 #include "chrome/browser/extensions/extension_service.h" | 27 #include "chrome/browser/extensions/extension_service.h" |
| 27 #include "chrome/browser/extensions/extension_tab_util.h" | 28 #include "chrome/browser/extensions/extension_tab_util.h" |
| 28 #include "chrome/browser/extensions/tab_helper.h" | 29 #include "chrome/browser/extensions/tab_helper.h" |
| 29 #include "chrome/browser/extensions/window_controller.h" | 30 #include "chrome/browser/extensions/window_controller.h" |
| 30 #include "chrome/browser/extensions/window_controller_list.h" | 31 #include "chrome/browser/extensions/window_controller_list.h" |
| 31 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 32 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 32 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/browser/sessions/session_tab_helper.h" | 34 #include "chrome/browser/sessions/session_tab_helper.h" |
| 34 #include "chrome/browser/translate/chrome_translate_client.h" | 35 #include "chrome/browser/translate/chrome_translate_client.h" |
| 35 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 36 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
| 36 #include "chrome/browser/ui/browser.h" | 37 #include "chrome/browser/ui/browser.h" |
| 37 #include "chrome/browser/ui/browser_commands.h" | 38 #include "chrome/browser/ui/browser_commands.h" |
| 38 #include "chrome/browser/ui/browser_finder.h" | 39 #include "chrome/browser/ui/browser_finder.h" |
| 39 #include "chrome/browser/ui/browser_iterator.h" | 40 #include "chrome/browser/ui/browser_iterator.h" |
| 40 #include "chrome/browser/ui/browser_navigator.h" | 41 #include "chrome/browser/ui/browser_navigator.h" |
| 41 #include "chrome/browser/ui/browser_tabstrip.h" | 42 #include "chrome/browser/ui/browser_tabstrip.h" |
| 42 #include "chrome/browser/ui/browser_window.h" | 43 #include "chrome/browser/ui/browser_window.h" |
| 43 #include "chrome/browser/ui/host_desktop.h" | 44 #include "chrome/browser/ui/host_desktop.h" |
| 44 #include "chrome/browser/ui/panels/panel_manager.h" | 45 #include "chrome/browser/ui/panels/panel_manager.h" |
| 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 46 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 47 #include "chrome/browser/ui/tabs/tab_utils.h" |
| 46 #include "chrome/browser/ui/window_sizer/window_sizer.h" | 48 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
| 47 #include "chrome/browser/web_applications/web_app.h" | 49 #include "chrome/browser/web_applications/web_app.h" |
| 48 #include "chrome/common/chrome_switches.h" | 50 #include "chrome/common/chrome_switches.h" |
| 49 #include "chrome/common/extensions/api/tabs.h" | 51 #include "chrome/common/extensions/api/tabs.h" |
| 50 #include "chrome/common/extensions/api/windows.h" | 52 #include "chrome/common/extensions/api/windows.h" |
| 51 #include "chrome/common/extensions/extension_constants.h" | 53 #include "chrome/common/extensions/extension_constants.h" |
| 52 #include "chrome/common/pref_names.h" | 54 #include "chrome/common/pref_names.h" |
| 53 #include "chrome/common/url_constants.h" | 55 #include "chrome/common/url_constants.h" |
| 54 #include "components/pref_registry/pref_registry_syncable.h" | 56 #include "components/pref_registry/pref_registry_syncable.h" |
| 55 #include "components/translate/core/browser/language_state.h" | 57 #include "components/translate/core/browser/language_state.h" |
| (...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 if (!MatchesBool(params->query_info.active.get(), | 903 if (!MatchesBool(params->query_info.active.get(), |
| 902 i == tab_strip->active_index())) { | 904 i == tab_strip->active_index())) { |
| 903 continue; | 905 continue; |
| 904 } | 906 } |
| 905 | 907 |
| 906 if (!MatchesBool(params->query_info.pinned.get(), | 908 if (!MatchesBool(params->query_info.pinned.get(), |
| 907 tab_strip->IsTabPinned(i))) { | 909 tab_strip->IsTabPinned(i))) { |
| 908 continue; | 910 continue; |
| 909 } | 911 } |
| 910 | 912 |
| 913 if (!MatchesBool(params->query_info.audible.get(), |
| 914 chrome::IsPlayingAudio(web_contents))) { |
| 915 continue; |
| 916 } |
| 917 |
| 918 if (!MatchesBool(params->query_info.muted.get(), |
| 919 chrome::IsTabAudioMuted(web_contents))) { |
| 920 continue; |
| 921 } |
| 922 |
| 911 if (!title.empty() && !MatchPattern(web_contents->GetTitle(), | 923 if (!title.empty() && !MatchPattern(web_contents->GetTitle(), |
| 912 base::UTF8ToUTF16(title))) | 924 base::UTF8ToUTF16(title))) |
| 913 continue; | 925 continue; |
| 914 | 926 |
| 915 if (!url_patterns.is_empty() && | 927 if (!url_patterns.is_empty() && |
| 916 !url_patterns.MatchesURL(web_contents->GetURL())) | 928 !url_patterns.MatchesURL(web_contents->GetURL())) |
| 917 continue; | 929 continue; |
| 918 | 930 |
| 919 if (loading_status_set && loading != web_contents->IsLoading()) | 931 if (loading_status_set && loading != web_contents->IsLoading()) |
| 920 continue; | 932 continue; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 } | 1190 } |
| 1179 | 1191 |
| 1180 if (params->update_properties.pinned.get()) { | 1192 if (params->update_properties.pinned.get()) { |
| 1181 bool pinned = *params->update_properties.pinned; | 1193 bool pinned = *params->update_properties.pinned; |
| 1182 tab_strip->SetTabPinned(tab_index, pinned); | 1194 tab_strip->SetTabPinned(tab_index, pinned); |
| 1183 | 1195 |
| 1184 // Update the tab index because it may move when being pinned. | 1196 // Update the tab index because it may move when being pinned. |
| 1185 tab_index = tab_strip->GetIndexOfWebContents(contents); | 1197 tab_index = tab_strip->GetIndexOfWebContents(contents); |
| 1186 } | 1198 } |
| 1187 | 1199 |
| 1200 if (params->update_properties.muted.get()) { |
| 1201 if (chrome::IsTabAudioMutingFeatureEnabled()) { |
| 1202 if (!chrome::CanToggleAudioMute(contents)) { |
| 1203 WriteToConsole( |
| 1204 content::CONSOLE_MESSAGE_LEVEL_WARNING, |
| 1205 base::StringPrintf( |
| 1206 "Cannot update mute state for tab %d, tab has audio or video " |
| 1207 "currently being captured", |
| 1208 tab_id)); |
| 1209 } else { |
| 1210 chrome::SetTabAudioMuted(contents, *params->update_properties.muted, |
| 1211 extension()->id()); |
| 1212 } |
| 1213 } else { |
| 1214 WriteToConsole(content::CONSOLE_MESSAGE_LEVEL_WARNING, |
| 1215 base::StringPrintf( |
| 1216 "Failed to update mute state, --%s must be enabled", |
| 1217 switches::kEnableTabAudioMuting)); |
| 1218 } |
| 1219 } |
| 1220 |
| 1188 if (params->update_properties.opener_tab_id.get()) { | 1221 if (params->update_properties.opener_tab_id.get()) { |
| 1189 int opener_id = *params->update_properties.opener_tab_id; | 1222 int opener_id = *params->update_properties.opener_tab_id; |
| 1190 | 1223 |
| 1191 WebContents* opener_contents = NULL; | 1224 WebContents* opener_contents = NULL; |
| 1192 if (!ExtensionTabUtil::GetTabById(opener_id, | 1225 if (!ExtensionTabUtil::GetTabById(opener_id, |
| 1193 GetProfile(), | 1226 GetProfile(), |
| 1194 include_incognito(), | 1227 include_incognito(), |
| 1195 NULL, | 1228 NULL, |
| 1196 NULL, | 1229 NULL, |
| 1197 &opener_contents, | 1230 &opener_contents, |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1951 ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode(); | 1984 ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode(); |
| 1952 api::tabs::ZoomSettings zoom_settings; | 1985 api::tabs::ZoomSettings zoom_settings; |
| 1953 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 1986 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
| 1954 | 1987 |
| 1955 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 1988 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
| 1956 SendResponse(true); | 1989 SendResponse(true); |
| 1957 return true; | 1990 return true; |
| 1958 } | 1991 } |
| 1959 | 1992 |
| 1960 } // namespace extensions | 1993 } // namespace extensions |
| OLD | NEW |