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

Side by Side Diff: chrome/browser/extensions/extension_tab_util.cc

Issue 1644773003: Remove BrowserIterator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@host-desktop-1
Patch Set: . Created 4 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
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/extension_tab_util.h" 5 #include "chrome/browser/extensions/extension_tab_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
13 #include "chrome/browser/extensions/chrome_extension_function.h" 13 #include "chrome/browser/extensions/chrome_extension_function.h"
14 #include "chrome/browser/extensions/chrome_extension_function_details.h" 14 #include "chrome/browser/extensions/chrome_extension_function_details.h"
15 #include "chrome/browser/extensions/tab_helper.h" 15 #include "chrome/browser/extensions/tab_helper.h"
16 #include "chrome/browser/extensions/window_controller.h" 16 #include "chrome/browser/extensions/window_controller.h"
17 #include "chrome/browser/extensions/window_controller_list.h" 17 #include "chrome/browser/extensions/window_controller_list.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/sessions/session_tab_helper.h" 19 #include "chrome/browser/sessions/session_tab_helper.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_finder.h" 21 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/browser_iterator.h"
23 #include "chrome/browser/ui/browser_navigator_params.h" 22 #include "chrome/browser/ui/browser_navigator_params.h"
24 #include "chrome/browser/ui/browser_window.h" 23 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 24 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
26 #include "chrome/browser/ui/singleton_tabs.h" 25 #include "chrome/browser/ui/singleton_tabs.h"
27 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 26 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h" 27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/browser/ui/tabs/tab_utils.h" 28 #include "chrome/browser/ui/tabs/tab_utils.h"
30 #include "chrome/common/extensions/api/tabs.h" 29 #include "chrome/common/extensions/api/tabs.h"
31 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
32 #include "components/url_formatter/url_fixer.h" 31 #include "components/url_formatter/url_fixer.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // |error_message| can optionally be passed in and will be set with an 69 // |error_message| can optionally be passed in and will be set with an
71 // appropriate message if the window cannot be found by id. 70 // appropriate message if the window cannot be found by id.
72 Browser* GetBrowserInProfileWithId(Profile* profile, 71 Browser* GetBrowserInProfileWithId(Profile* profile,
73 const int window_id, 72 const int window_id,
74 bool include_incognito, 73 bool include_incognito,
75 std::string* error_message) { 74 std::string* error_message) {
76 Profile* incognito_profile = 75 Profile* incognito_profile =
77 include_incognito && profile->HasOffTheRecordProfile() 76 include_incognito && profile->HasOffTheRecordProfile()
78 ? profile->GetOffTheRecordProfile() 77 ? profile->GetOffTheRecordProfile()
79 : NULL; 78 : NULL;
80 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 79 for (auto* browser : *BrowserList::GetInstance()) {
81 Browser* browser = *it;
82 if ((browser->profile() == profile || 80 if ((browser->profile() == profile ||
83 browser->profile() == incognito_profile) && 81 browser->profile() == incognito_profile) &&
84 ExtensionTabUtil::GetWindowId(browser) == window_id && 82 ExtensionTabUtil::GetWindowId(browser) == window_id &&
85 browser->window()) { 83 browser->window()) {
86 return browser; 84 return browser;
87 } 85 }
88 } 86 }
89 87
90 if (error_message) 88 if (error_message)
91 *error_message = ErrorUtils::FormatErrorMessage( 89 *error_message = ErrorUtils::FormatErrorMessage(
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 error); 312 error);
315 } 313 }
316 } 314 }
317 315
318 int ExtensionTabUtil::GetWindowId(const Browser* browser) { 316 int ExtensionTabUtil::GetWindowId(const Browser* browser) {
319 return browser->session_id().id(); 317 return browser->session_id().id();
320 } 318 }
321 319
322 int ExtensionTabUtil::GetWindowIdOfTabStripModel( 320 int ExtensionTabUtil::GetWindowIdOfTabStripModel(
323 const TabStripModel* tab_strip_model) { 321 const TabStripModel* tab_strip_model) {
324 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 322 for (auto* browser : *BrowserList::GetInstance()) {
325 if (it->tab_strip_model() == tab_strip_model) 323 if (browser->tab_strip_model() == tab_strip_model)
326 return GetWindowId(*it); 324 return GetWindowId(browser);
327 } 325 }
328 return -1; 326 return -1;
329 } 327 }
330 328
331 int ExtensionTabUtil::GetTabId(const WebContents* web_contents) { 329 int ExtensionTabUtil::GetTabId(const WebContents* web_contents) {
332 return SessionTabHelper::IdForTab(web_contents); 330 return SessionTabHelper::IdForTab(web_contents);
333 } 331 }
334 332
335 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) { 333 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) {
336 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete; 334 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } 480 }
483 } 481 }
484 482
485 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, 483 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents,
486 TabStripModel** tab_strip_model, 484 TabStripModel** tab_strip_model,
487 int* tab_index) { 485 int* tab_index) {
488 DCHECK(web_contents); 486 DCHECK(web_contents);
489 DCHECK(tab_strip_model); 487 DCHECK(tab_strip_model);
490 DCHECK(tab_index); 488 DCHECK(tab_index);
491 489
492 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 490 for (auto* browser : *BrowserList::GetInstance()) {
493 TabStripModel* tab_strip = it->tab_strip_model(); 491 TabStripModel* tab_strip = browser->tab_strip_model();
494 int index = tab_strip->GetIndexOfWebContents(web_contents); 492 int index = tab_strip->GetIndexOfWebContents(web_contents);
495 if (index != -1) { 493 if (index != -1) {
496 *tab_strip_model = tab_strip; 494 *tab_strip_model = tab_strip;
497 *tab_index = index; 495 *tab_index = index;
498 return true; 496 return true;
499 } 497 }
500 } 498 }
501 499
502 return false; 500 return false;
503 } 501 }
(...skipping 20 matching lines...) Expand all
524 Browser** browser, 522 Browser** browser,
525 TabStripModel** tab_strip, 523 TabStripModel** tab_strip,
526 WebContents** contents, 524 WebContents** contents,
527 int* tab_index) { 525 int* tab_index) {
528 if (tab_id == api::tabs::TAB_ID_NONE) 526 if (tab_id == api::tabs::TAB_ID_NONE)
529 return false; 527 return false;
530 Profile* profile = Profile::FromBrowserContext(browser_context); 528 Profile* profile = Profile::FromBrowserContext(browser_context);
531 Profile* incognito_profile = 529 Profile* incognito_profile =
532 include_incognito && profile->HasOffTheRecordProfile() ? 530 include_incognito && profile->HasOffTheRecordProfile() ?
533 profile->GetOffTheRecordProfile() : NULL; 531 profile->GetOffTheRecordProfile() : NULL;
534 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 532 for (auto* target_browser : *BrowserList::GetInstance()) {
535 Browser* target_browser = *it;
536 if (target_browser->profile() == profile || 533 if (target_browser->profile() == profile ||
537 target_browser->profile() == incognito_profile) { 534 target_browser->profile() == incognito_profile) {
538 TabStripModel* target_tab_strip = target_browser->tab_strip_model(); 535 TabStripModel* target_tab_strip = target_browser->tab_strip_model();
539 for (int i = 0; i < target_tab_strip->count(); ++i) { 536 for (int i = 0; i < target_tab_strip->count(); ++i) {
540 WebContents* target_contents = target_tab_strip->GetWebContentsAt(i); 537 WebContents* target_contents = target_tab_strip->GetWebContentsAt(i);
541 if (SessionTabHelper::IdForTab(target_contents) == tab_id) { 538 if (SessionTabHelper::IdForTab(target_contents) == tab_id) {
542 if (browser) 539 if (browser)
543 *browser = target_browser; 540 *browser = target_browser;
544 if (tab_strip) 541 if (tab_strip)
545 *tab_strip = target_tab_strip; 542 *tab_strip = target_tab_strip;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 chrome::ShowSingletonTabOverwritingNTP(browser, params); 673 chrome::ShowSingletonTabOverwritingNTP(browser, params);
677 return true; 674 return true;
678 } 675 }
679 676
680 // static 677 // static
681 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) { 678 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) {
682 return browser && browser->tab_strip_model() && !browser->is_devtools(); 679 return browser && browser->tab_strip_model() && !browser->is_devtools();
683 } 680 }
684 681
685 } // namespace extensions 682 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/web_navigation/web_navigation_api.cc ('k') | chrome/browser/extensions/window_open_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698