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

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

Issue 12114034: Swap BrowserList::const_iterator for the multi-desktop aware BrowserIterator in many scenarios. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "chrome/browser/extensions/tab_helper.h" 31 #include "chrome/browser/extensions/tab_helper.h"
32 #include "chrome/browser/extensions/window_controller.h" 32 #include "chrome/browser/extensions/window_controller.h"
33 #include "chrome/browser/extensions/window_controller_list.h" 33 #include "chrome/browser/extensions/window_controller_list.h"
34 #include "chrome/browser/prefs/incognito_mode_prefs.h" 34 #include "chrome/browser/prefs/incognito_mode_prefs.h"
35 #include "chrome/browser/prefs/pref_service.h" 35 #include "chrome/browser/prefs/pref_service.h"
36 #include "chrome/browser/profiles/profile.h" 36 #include "chrome/browser/profiles/profile.h"
37 #include "chrome/browser/translate/translate_tab_helper.h" 37 #include "chrome/browser/translate/translate_tab_helper.h"
38 #include "chrome/browser/ui/browser.h" 38 #include "chrome/browser/ui/browser.h"
39 #include "chrome/browser/ui/browser_commands.h" 39 #include "chrome/browser/ui/browser_commands.h"
40 #include "chrome/browser/ui/browser_finder.h" 40 #include "chrome/browser/ui/browser_finder.h"
41 #include "chrome/browser/ui/browser_list.h" 41 #include "chrome/browser/ui/browser_iterator.h"
42 #include "chrome/browser/ui/browser_navigator.h" 42 #include "chrome/browser/ui/browser_navigator.h"
43 #include "chrome/browser/ui/browser_tabstrip.h" 43 #include "chrome/browser/ui/browser_tabstrip.h"
44 #include "chrome/browser/ui/browser_window.h" 44 #include "chrome/browser/ui/browser_window.h"
45 #include "chrome/browser/ui/extensions/shell_window.h" 45 #include "chrome/browser/ui/extensions/shell_window.h"
46 #include "chrome/browser/ui/host_desktop.h" 46 #include "chrome/browser/ui/host_desktop.h"
47 #include "chrome/browser/ui/panels/panel_manager.h" 47 #include "chrome/browser/ui/panels/panel_manager.h"
48 #include "chrome/browser/ui/snapshot_tab_helper.h" 48 #include "chrome/browser/ui/snapshot_tab_helper.h"
49 #include "chrome/browser/ui/tabs/tab_strip_model.h" 49 #include "chrome/browser/ui/tabs/tab_strip_model.h"
50 #include "chrome/browser/ui/window_sizer/window_sizer.h" 50 #include "chrome/browser/ui/window_sizer/window_sizer.h"
51 #include "chrome/browser/web_applications/web_app.h" 51 #include "chrome/browser/web_applications/web_app.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 // |error_message| can optionally be passed in a will be set with an appropriate 114 // |error_message| can optionally be passed in a will be set with an appropriate
115 // message if the window cannot be found by id. 115 // message if the window cannot be found by id.
116 Browser* GetBrowserInProfileWithId(Profile* profile, 116 Browser* GetBrowserInProfileWithId(Profile* profile,
117 const int window_id, 117 const int window_id,
118 bool include_incognito, 118 bool include_incognito,
119 std::string* error_message) { 119 std::string* error_message) {
120 Profile* incognito_profile = 120 Profile* incognito_profile =
121 include_incognito && profile->HasOffTheRecordProfile() ? 121 include_incognito && profile->HasOffTheRecordProfile() ?
122 profile->GetOffTheRecordProfile() : NULL; 122 profile->GetOffTheRecordProfile() : NULL;
123 for (BrowserList::const_iterator browser = BrowserList::begin(); 123 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
124 browser != BrowserList::end(); ++browser) { 124 Browser* browser = *it;
125 if (((*browser)->profile() == profile || 125 if ((browser->profile() == profile ||
126 (*browser)->profile() == incognito_profile) && 126 browser->profile() == incognito_profile) &&
127 ExtensionTabUtil::GetWindowId(*browser) == window_id && 127 ExtensionTabUtil::GetWindowId(browser) == window_id &&
128 ((*browser)->window())) 128 browser->window()) {
129 return *browser; 129 return browser;
130 }
130 } 131 }
131 132
132 if (error_message) 133 if (error_message)
133 *error_message = ErrorUtils::FormatErrorMessage( 134 *error_message = ErrorUtils::FormatErrorMessage(
134 keys::kWindowNotFoundError, base::IntToString(window_id)); 135 keys::kWindowNotFoundError, base::IntToString(window_id));
135 136
136 return NULL; 137 return NULL;
137 } 138 }
138 139
139 bool GetBrowserFromWindowID( 140 bool GetBrowserFromWindowID(
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 if (query->HasKey(keys::kIndexKey)) 922 if (query->HasKey(keys::kIndexKey))
922 EXTENSION_FUNCTION_VALIDATE( 923 EXTENSION_FUNCTION_VALIDATE(
923 query->GetInteger(keys::kIndexKey, &index)); 924 query->GetInteger(keys::kIndexKey, &index));
924 925
925 std::string window_type; 926 std::string window_type;
926 if (query->HasKey(keys::kWindowTypeLongKey)) 927 if (query->HasKey(keys::kWindowTypeLongKey))
927 EXTENSION_FUNCTION_VALIDATE( 928 EXTENSION_FUNCTION_VALIDATE(
928 query->GetString(keys::kWindowTypeLongKey, &window_type)); 929 query->GetString(keys::kWindowTypeLongKey, &window_type));
929 930
930 ListValue* result = new ListValue(); 931 ListValue* result = new ListValue();
931 for (BrowserList::const_iterator browser = BrowserList::begin(); 932 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
932 browser != BrowserList::end(); ++browser) { 933 Browser* browser = *it;
933 if (!profile()->IsSameProfile((*browser)->profile())) 934 if (!profile()->IsSameProfile(browser->profile()))
934 continue; 935 continue;
935 936
936 if (!(*browser)->window()) 937 if (!browser->window())
937 continue; 938 continue;
938 939
939 if (!include_incognito() && profile() != (*browser)->profile()) 940 if (!include_incognito() && profile() != browser->profile())
940 continue; 941 continue;
941 942
942 if (window_id >= 0 && window_id != ExtensionTabUtil::GetWindowId(*browser)) 943 if (window_id >= 0 && window_id != ExtensionTabUtil::GetWindowId(browser))
943 continue; 944 continue;
944 945
945 if (window_id == extension_misc::kCurrentWindowId && 946 if (window_id == extension_misc::kCurrentWindowId &&
946 *browser != GetCurrentBrowser()) 947 browser != GetCurrentBrowser())
947 continue; 948 continue;
948 949
949 if (!MatchesQueryArg(current_window, *browser == GetCurrentBrowser())) 950 if (!MatchesQueryArg(current_window, browser == GetCurrentBrowser()))
950 continue; 951 continue;
951 952
952 if (!MatchesQueryArg(focused_window, (*browser)->window()->IsActive())) 953 if (!MatchesQueryArg(focused_window, browser->window()->IsActive()))
953 continue; 954 continue;
954 955
955 if (!window_type.empty() && 956 if (!window_type.empty() &&
956 window_type != 957 window_type !=
957 (*browser)->extension_window_controller()->GetWindowTypeText()) 958 browser->extension_window_controller()->GetWindowTypeText())
958 continue; 959 continue;
959 960
960 TabStripModel* tab_strip = (*browser)->tab_strip_model(); 961 TabStripModel* tab_strip = browser->tab_strip_model();
961 for (int i = 0; i < tab_strip->count(); ++i) { 962 for (int i = 0; i < tab_strip->count(); ++i) {
962 const WebContents* web_contents = tab_strip->GetWebContentsAt(i); 963 const WebContents* web_contents = tab_strip->GetWebContentsAt(i);
963 964
964 if (index > -1 && i != index) 965 if (index > -1 && i != index)
965 continue; 966 continue;
966 967
967 if (!MatchesQueryArg(selected, tab_strip->IsTabSelected(i))) 968 if (!MatchesQueryArg(selected, tab_strip->IsTabSelected(i)))
968 continue; 969 continue;
969 970
970 if (!MatchesQueryArg(active, i == tab_strip->active_index())) 971 if (!MatchesQueryArg(active, i == tab_strip->active_index()))
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 extension->id(), 2130 extension->id(),
2130 script_type, 2131 script_type,
2131 code_string, 2132 code_string,
2132 frame_scope, 2133 frame_scope,
2133 run_at, 2134 run_at,
2134 ScriptExecutor::ISOLATED_WORLD, 2135 ScriptExecutor::ISOLATED_WORLD,
2135 false /* is_web_view */, 2136 false /* is_web_view */,
2136 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); 2137 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this));
2137 return true; 2138 return true;
2138 } 2139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698