| 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/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/thread_task_runner_handle.h" | 24 #include "base/thread_task_runner_handle.h" |
| 24 #include "chrome/browser/apps/scoped_keep_alive.h" | 25 #include "chrome/browser/apps/scoped_keep_alive.h" |
| 25 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
| 26 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 27 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 27 #include "chrome/browser/extensions/api/tabs/windows_util.h" | 28 #include "chrome/browser/extensions/api/tabs/windows_util.h" |
| 28 #include "chrome/browser/extensions/extension_service.h" | 29 #include "chrome/browser/extensions/extension_service.h" |
| 29 #include "chrome/browser/extensions/extension_tab_util.h" | 30 #include "chrome/browser/extensions/extension_tab_util.h" |
| 30 #include "chrome/browser/extensions/tab_helper.h" | 31 #include "chrome/browser/extensions/tab_helper.h" |
| 31 #include "chrome/browser/extensions/window_controller.h" | 32 #include "chrome/browser/extensions/window_controller.h" |
| 32 #include "chrome/browser/extensions/window_controller_list.h" | 33 #include "chrome/browser/extensions/window_controller_list.h" |
| 33 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 34 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 34 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| 35 #include "chrome/browser/sessions/session_tab_helper.h" | 36 #include "chrome/browser/sessions/session_tab_helper.h" |
| 36 #include "chrome/browser/translate/chrome_translate_client.h" | 37 #include "chrome/browser/translate/chrome_translate_client.h" |
| 37 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 38 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
| 38 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
| 39 #include "chrome/browser/ui/browser_commands.h" | 40 #include "chrome/browser/ui/browser_commands.h" |
| 40 #include "chrome/browser/ui/browser_finder.h" | 41 #include "chrome/browser/ui/browser_finder.h" |
| 41 #include "chrome/browser/ui/browser_iterator.h" | 42 #include "chrome/browser/ui/browser_iterator.h" |
| 42 #include "chrome/browser/ui/browser_navigator.h" | 43 #include "chrome/browser/ui/browser_navigator.h" |
| 43 #include "chrome/browser/ui/browser_tabstrip.h" | 44 #include "chrome/browser/ui/browser_tabstrip.h" |
| 44 #include "chrome/browser/ui/browser_window.h" | 45 #include "chrome/browser/ui/browser_window.h" |
| 45 #include "chrome/browser/ui/host_desktop.h" | 46 #include "chrome/browser/ui/host_desktop.h" |
| 46 #include "chrome/browser/ui/panels/panel_manager.h" | 47 #include "chrome/browser/ui/panels/panel_manager.h" |
| 47 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 48 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 49 #include "chrome/browser/ui/tabs/tab_utils.h" |
| 48 #include "chrome/browser/ui/window_sizer/window_sizer.h" | 50 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
| 49 #include "chrome/browser/web_applications/web_app.h" | 51 #include "chrome/browser/web_applications/web_app.h" |
| 50 #include "chrome/common/chrome_switches.h" | 52 #include "chrome/common/chrome_switches.h" |
| 51 #include "chrome/common/extensions/api/tabs.h" | 53 #include "chrome/common/extensions/api/tabs.h" |
| 52 #include "chrome/common/extensions/api/windows.h" | 54 #include "chrome/common/extensions/api/windows.h" |
| 53 #include "chrome/common/extensions/extension_constants.h" | 55 #include "chrome/common/extensions/extension_constants.h" |
| 54 #include "chrome/common/pref_names.h" | 56 #include "chrome/common/pref_names.h" |
| 55 #include "chrome/common/url_constants.h" | 57 #include "chrome/common/url_constants.h" |
| 56 #include "components/pref_registry/pref_registry_syncable.h" | 58 #include "components/pref_registry/pref_registry_syncable.h" |
| 57 #include "components/translate/core/browser/language_state.h" | 59 #include "components/translate/core/browser/language_state.h" |
| (...skipping 887 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() && !MatchPattern(web_contents->GetTitle(), | 967 if (!title.empty() && !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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 } | 1234 } |
| 1223 | 1235 |
| 1224 if (params->update_properties.pinned.get()) { | 1236 if (params->update_properties.pinned.get()) { |
| 1225 bool pinned = *params->update_properties.pinned; | 1237 bool pinned = *params->update_properties.pinned; |
| 1226 tab_strip->SetTabPinned(tab_index, pinned); | 1238 tab_strip->SetTabPinned(tab_index, pinned); |
| 1227 | 1239 |
| 1228 // Update the tab index because it may move when being pinned. | 1240 // Update the tab index because it may move when being pinned. |
| 1229 tab_index = tab_strip->GetIndexOfWebContents(contents); | 1241 tab_index = tab_strip->GetIndexOfWebContents(contents); |
| 1230 } | 1242 } |
| 1231 | 1243 |
| 1244 if (params->update_properties.muted.get()) { |
| 1245 if (chrome::IsTabAudioMutingFeatureEnabled()) { |
| 1246 if (!chrome::CanToggleAudioMute(contents)) { |
| 1247 WriteToConsole( |
| 1248 content::CONSOLE_MESSAGE_LEVEL_WARNING, |
| 1249 base::StringPrintf( |
| 1250 "Cannot update mute state for tab %d, tab has audio or video " |
| 1251 "currently being captured", |
| 1252 tab_id)); |
| 1253 } else { |
| 1254 chrome::SetTabAudioMuted(contents, *params->update_properties.muted, |
| 1255 extension()->id()); |
| 1256 } |
| 1257 } else { |
| 1258 WriteToConsole(content::CONSOLE_MESSAGE_LEVEL_WARNING, |
| 1259 base::StringPrintf( |
| 1260 "Failed to update mute state, --%s must be enabled", |
| 1261 switches::kEnableTabAudioMuting)); |
| 1262 } |
| 1263 } |
| 1264 |
| 1232 if (params->update_properties.opener_tab_id.get()) { | 1265 if (params->update_properties.opener_tab_id.get()) { |
| 1233 int opener_id = *params->update_properties.opener_tab_id; | 1266 int opener_id = *params->update_properties.opener_tab_id; |
| 1234 | 1267 |
| 1235 WebContents* opener_contents = NULL; | 1268 WebContents* opener_contents = NULL; |
| 1236 if (!ExtensionTabUtil::GetTabById(opener_id, | 1269 if (!ExtensionTabUtil::GetTabById(opener_id, |
| 1237 GetProfile(), | 1270 GetProfile(), |
| 1238 include_incognito(), | 1271 include_incognito(), |
| 1239 NULL, | 1272 NULL, |
| 1240 NULL, | 1273 NULL, |
| 1241 &opener_contents, | 1274 &opener_contents, |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1994 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 2027 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
| 1995 zoom_settings.default_zoom_factor.reset(new double( | 2028 zoom_settings.default_zoom_factor.reset(new double( |
| 1996 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); | 2029 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); |
| 1997 | 2030 |
| 1998 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 2031 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
| 1999 SendResponse(true); | 2032 SendResponse(true); |
| 2000 return true; | 2033 return true; |
| 2001 } | 2034 } |
| 2002 | 2035 |
| 2003 } // namespace extensions | 2036 } // namespace extensions |
| OLD | NEW |