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/extensions/api/tabs/tabs_api.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/memory/ref_counted_memory.h" | 19 #include "base/memory/ref_counted_memory.h" |
| 20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 21 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
| 22 #include "base/strings/pattern.h" | 22 #include "base/strings/pattern.h" |
| 23 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
| 24 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 26 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
| 27 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 28 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 29 #include "chrome/browser/browser_process.h" | |
| 29 #include "chrome/browser/chrome_notification_types.h" | 30 #include "chrome/browser/chrome_notification_types.h" |
| 30 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 31 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 31 #include "chrome/browser/extensions/api/tabs/windows_util.h" | 32 #include "chrome/browser/extensions/api/tabs/windows_util.h" |
| 32 #include "chrome/browser/extensions/extension_service.h" | 33 #include "chrome/browser/extensions/extension_service.h" |
| 33 #include "chrome/browser/extensions/extension_tab_util.h" | 34 #include "chrome/browser/extensions/extension_tab_util.h" |
| 34 #include "chrome/browser/extensions/tab_helper.h" | 35 #include "chrome/browser/extensions/tab_helper.h" |
| 35 #include "chrome/browser/extensions/window_controller.h" | 36 #include "chrome/browser/extensions/window_controller.h" |
| 36 #include "chrome/browser/extensions/window_controller_list.h" | 37 #include "chrome/browser/extensions/window_controller_list.h" |
| 38 #include "chrome/browser/memory/tab_manager.h" | |
| 37 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 39 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 38 #include "chrome/browser/profiles/profile.h" | 40 #include "chrome/browser/profiles/profile.h" |
| 39 #include "chrome/browser/sessions/session_tab_helper.h" | 41 #include "chrome/browser/sessions/session_tab_helper.h" |
| 40 #include "chrome/browser/translate/chrome_translate_client.h" | 42 #include "chrome/browser/translate/chrome_translate_client.h" |
| 41 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 43 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
| 42 #include "chrome/browser/ui/browser.h" | 44 #include "chrome/browser/ui/browser.h" |
| 43 #include "chrome/browser/ui/browser_commands.h" | 45 #include "chrome/browser/ui/browser_commands.h" |
| 44 #include "chrome/browser/ui/browser_finder.h" | 46 #include "chrome/browser/ui/browser_finder.h" |
| 45 #include "chrome/browser/ui/browser_list.h" | 47 #include "chrome/browser/ui/browser_list.h" |
| 46 #include "chrome/browser/ui/browser_navigator.h" | 48 #include "chrome/browser/ui/browser_navigator.h" |
| (...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 | 961 |
| 960 if (!window_type.empty() && | 962 if (!window_type.empty() && |
| 961 window_type != | 963 window_type != |
| 962 browser->extension_window_controller()->GetWindowTypeText()) { | 964 browser->extension_window_controller()->GetWindowTypeText()) { |
| 963 continue; | 965 continue; |
| 964 } | 966 } |
| 965 | 967 |
| 966 TabStripModel* tab_strip = browser->tab_strip_model(); | 968 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 967 for (int i = 0; i < tab_strip->count(); ++i) { | 969 for (int i = 0; i < tab_strip->count(); ++i) { |
| 968 WebContents* web_contents = tab_strip->GetWebContentsAt(i); | 970 WebContents* web_contents = tab_strip->GetWebContentsAt(i); |
| 971 memory::TabManager* tab_manager = g_browser_process->GetTabManager(); | |
| 969 | 972 |
| 970 if (index > -1 && i != index) | 973 if (index > -1 && i != index) |
| 971 continue; | 974 continue; |
| 972 | 975 |
| 973 if (!MatchesBool(params->query_info.highlighted.get(), | 976 if (!MatchesBool(params->query_info.highlighted.get(), |
| 974 tab_strip->IsTabSelected(i))) { | 977 tab_strip->IsTabSelected(i))) { |
| 975 continue; | 978 continue; |
| 976 } | 979 } |
| 977 | 980 |
| 978 if (!MatchesBool(params->query_info.active.get(), | 981 if (!MatchesBool(params->query_info.active.get(), |
| 979 i == tab_strip->active_index())) { | 982 i == tab_strip->active_index())) { |
| 980 continue; | 983 continue; |
| 981 } | 984 } |
| 982 | 985 |
| 983 if (!MatchesBool(params->query_info.pinned.get(), | 986 if (!MatchesBool(params->query_info.pinned.get(), |
| 984 tab_strip->IsTabPinned(i))) { | 987 tab_strip->IsTabPinned(i))) { |
| 985 continue; | 988 continue; |
| 986 } | 989 } |
| 987 | 990 |
| 988 if (!MatchesBool(params->query_info.audible.get(), | 991 if (!MatchesBool(params->query_info.audible.get(), |
| 989 web_contents->WasRecentlyAudible())) { | 992 web_contents->WasRecentlyAudible())) { |
| 990 continue; | 993 continue; |
| 991 } | 994 } |
| 992 | 995 |
| 996 // If tab_manager is not present, no tabs are discarded and therefore | |
| 997 // the tab is returned only if query_info.discarded is false. Otherwise | |
| 998 // check the matching of the parameter and the status on tab_manager. | |
| 999 bool discarded = false; | |
| 1000 if (tab_manager) | |
|
Georges Khalil
2016/06/16 20:22:13
nit: bool discarded = tab_manager && tab_manager->
Anderson Silva
2016/06/16 21:53:08
Done.
It's less intuitive thought in this case, th
| |
| 1001 discarded = tab_manager->IsTabDiscarded(web_contents); | |
| 1002 if (!MatchesBool(params->query_info.discarded.get(), discarded)) | |
| 1003 continue; | |
| 1004 | |
| 993 if (!MatchesBool(params->query_info.muted.get(), | 1005 if (!MatchesBool(params->query_info.muted.get(), |
| 994 web_contents->IsAudioMuted())) { | 1006 web_contents->IsAudioMuted())) { |
| 995 continue; | 1007 continue; |
| 996 } | 1008 } |
| 997 | 1009 |
| 998 if (!title.empty() || !url_patterns.is_empty()) { | 1010 if (!title.empty() || !url_patterns.is_empty()) { |
| 999 // "title" and "url" properties are considered privileged data and can | 1011 // "title" and "url" properties are considered privileged data and can |
| 1000 // only be checked if the extension has the "tabs" permission or it has | 1012 // only be checked if the extension has the "tabs" permission or it has |
| 1001 // access to the WebContents's origin. Otherwise, this tab is considered | 1013 // access to the WebContents's origin. Otherwise, this tab is considered |
| 1002 // not matched. | 1014 // not matched. |
| (...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2157 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 2169 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
| 2158 zoom_settings.default_zoom_factor.reset(new double( | 2170 zoom_settings.default_zoom_factor.reset(new double( |
| 2159 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); | 2171 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); |
| 2160 | 2172 |
| 2161 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 2173 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
| 2162 SendResponse(true); | 2174 SendResponse(true); |
| 2163 return true; | 2175 return true; |
| 2164 } | 2176 } |
| 2165 | 2177 |
| 2166 } // namespace extensions | 2178 } // namespace extensions |
| OLD | NEW |