Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 2067033002: Discarded property on chrome.tabs.Tab and chrome.tabs.query() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 =
972 g_browser_process ? g_browser_process->GetTabManager() : nullptr;
969 973
970 if (index > -1 && i != index) 974 if (index > -1 && i != index)
971 continue; 975 continue;
972 976
973 if (!MatchesBool(params->query_info.highlighted.get(), 977 if (!MatchesBool(params->query_info.highlighted.get(),
974 tab_strip->IsTabSelected(i))) { 978 tab_strip->IsTabSelected(i))) {
975 continue; 979 continue;
976 } 980 }
977 981
978 if (!MatchesBool(params->query_info.active.get(), 982 if (!MatchesBool(params->query_info.active.get(),
979 i == tab_strip->active_index())) { 983 i == tab_strip->active_index())) {
980 continue; 984 continue;
981 } 985 }
982 986
983 if (!MatchesBool(params->query_info.pinned.get(), 987 if (!MatchesBool(params->query_info.pinned.get(),
984 tab_strip->IsTabPinned(i))) { 988 tab_strip->IsTabPinned(i))) {
985 continue; 989 continue;
986 } 990 }
987 991
988 if (!MatchesBool(params->query_info.audible.get(), 992 if (!MatchesBool(params->query_info.audible.get(),
989 web_contents->WasRecentlyAudible())) { 993 web_contents->WasRecentlyAudible())) {
990 continue; 994 continue;
991 } 995 }
992 996
993 if (!MatchesBool(params->query_info.muted.get(), 997 if (!MatchesBool(params->query_info.muted.get(),
994 web_contents->IsAudioMuted())) { 998 web_contents->IsAudioMuted())) {
995 continue; 999 continue;
996 } 1000 }
997 1001
1002 // If tab_manager is not present, none tabs are discarded and therefore
chrisha 2016/06/15 15:56:12 ... no* tabs...
Anderson Silva 2016/06/16 14:04:51 Acknowledged.
1003 // the tab is returned only if query_info.discarded is false. Otherwise
1004 // check the matching of the parameter and the status on tab_manager.
chrisha 2016/06/15 15:56:12 Maybe slightly clearer as follows, less lines, and
Anderson Silva 2016/06/16 14:04:51 Acknowledged.
1005 if (!tab_manager &&
1006 !MatchesBool(params->query_info.discarded.get(), false)) {
1007 continue;
1008 }
1009 if (tab_manager &&
1010 !MatchesBool(params->query_info.discarded.get(),
1011 tab_manager->IsTabDiscarded(web_contents))) {
1012 continue;
1013 }
1014
998 if (!title.empty() || !url_patterns.is_empty()) { 1015 if (!title.empty() || !url_patterns.is_empty()) {
999 // "title" and "url" properties are considered privileged data and can 1016 // "title" and "url" properties are considered privileged data and can
1000 // only be checked if the extension has the "tabs" permission or it has 1017 // 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 1018 // access to the WebContents's origin. Otherwise, this tab is considered
1002 // not matched. 1019 // not matched.
1003 if (!extension_->permissions_data()->HasAPIPermissionForTab( 1020 if (!extension_->permissions_data()->HasAPIPermissionForTab(
1004 ExtensionTabUtil::GetTabId(web_contents), 1021 ExtensionTabUtil::GetTabId(web_contents),
1005 APIPermission::kTab) && 1022 APIPermission::kTab) &&
1006 !extension_->permissions_data()->HasHostPermission( 1023 !extension_->permissions_data()->HasHostPermission(
1007 web_contents->GetURL())) { 1024 web_contents->GetURL())) {
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2157 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); 2174 ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
2158 zoom_settings.default_zoom_factor.reset(new double( 2175 zoom_settings.default_zoom_factor.reset(new double(
2159 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); 2176 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel())));
2160 2177
2161 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); 2178 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings);
2162 SendResponse(true); 2179 SendResponse(true);
2163 return true; 2180 return true;
2164 } 2181 }
2165 2182
2166 } // namespace extensions 2183 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_tab_util.cc » ('j') | chrome/browser/extensions/extension_tab_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698