Chromium Code Reviews| Index: chrome/browser/ui/browser_finder.cc |
| diff --git a/chrome/browser/ui/browser_finder.cc b/chrome/browser/ui/browser_finder.cc |
| index 66d11e97d38380b4e7716b39bd592ed3b78bfe48..8070ec68a6563ed746f210502087322f4451876d 100644 |
| --- a/chrome/browser/ui/browser_finder.cc |
| +++ b/chrome/browser/ui/browser_finder.cc |
| @@ -32,6 +32,7 @@ const int kMatchAny = 0; |
| const int kMatchOriginalProfile = 1 << 0; |
| const int kMatchCanSupportWindowFeature = 1 << 1; |
| const int kMatchTabbed = 1 << 2; |
| +const int kMatchRootWindow = 1 << 3; |
|
stevenjb
2017/05/22 17:55:29
Align '= 1 << 3' with lines above.
|
| // Returns true if the specified |browser| matches the specified arguments. |
| // |match_types| is a bitmask dictating what parameters to match: |
| @@ -44,7 +45,8 @@ const int kMatchTabbed = 1 << 2; |
| bool BrowserMatches(Browser* browser, |
| Profile* profile, |
| Browser::WindowFeature window_feature, |
| - uint32_t match_types) { |
| + uint32_t match_types, |
| + const aura::Window* root_window) { |
| if ((match_types & kMatchCanSupportWindowFeature) && |
| !browser->CanSupportWindowFeature(window_feature)) { |
| return false; |
| @@ -85,8 +87,11 @@ bool BrowserMatches(Browser* browser, |
| #endif |
| } |
| - if (match_types & kMatchTabbed) |
| - return browser->is_type_tabbed(); |
| + if ((match_types & kMatchTabbed) && !browser->is_type_tabbed()) |
| + return false; |
| + |
| + if (match_types & kMatchRootWindow) |
| + return browser->window()->GetNativeWindow()->GetRootWindow() == root_window; |
| return true; |
| } |
| @@ -99,9 +104,10 @@ Browser* FindBrowserMatching(const T& begin, |
| const T& end, |
| Profile* profile, |
| Browser::WindowFeature window_feature, |
| - uint32_t match_types) { |
| + uint32_t match_types, |
| + const aura::Window* root_window) { |
| for (T i = begin; i != end; ++i) { |
| - if (BrowserMatches(*i, profile, window_feature, match_types)) |
| + if (BrowserMatches(*i, profile, window_feature, match_types, root_window)) |
| return *i; |
| } |
| return NULL; |
| @@ -109,7 +115,9 @@ Browser* FindBrowserMatching(const T& begin, |
| Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, |
| bool match_tabbed, |
| - bool match_original_profiles) { |
| + bool match_original_profiles, |
| + bool match_root_window, |
| + const aura::Window* root_window) { |
|
stevenjb
2017/05/22 17:55:29
|match_root_window| seems redundant, can we just t
weidongg
2017/05/23 16:37:46
Done
|
| BrowserList* browser_list_impl = BrowserList::GetInstance(); |
| if (!browser_list_impl) |
| return NULL; |
| @@ -118,27 +126,30 @@ Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, |
| match_types |= kMatchTabbed; |
| if (match_original_profiles) |
| match_types |= kMatchOriginalProfile; |
| - Browser* browser = FindBrowserMatching(browser_list_impl->begin_last_active(), |
| - browser_list_impl->end_last_active(), |
| - profile, |
| - Browser::FEATURE_NONE, |
| - match_types); |
| + if (match_root_window) |
| + match_types |= kMatchRootWindow; |
| + Browser* browser = |
| + FindBrowserMatching(browser_list_impl->begin_last_active(), |
| + browser_list_impl->end_last_active(), profile, |
| + Browser::FEATURE_NONE, match_types, root_window); |
| // Fall back to a forward scan of all Browsers if no active one was found. |
| - return browser ? browser : FindBrowserMatching(browser_list_impl->begin(), |
| - browser_list_impl->end(), |
| - profile, |
| - Browser::FEATURE_NONE, |
| - match_types); |
| + return browser |
| + ? browser |
| + : FindBrowserMatching( |
| + browser_list_impl->begin(), browser_list_impl->end(), |
| + profile, Browser::FEATURE_NONE, match_types, root_window); |
| } |
| size_t GetBrowserCountImpl(Profile* profile, |
| - uint32_t match_types) { |
| + uint32_t match_types, |
| + const aura::Window* root_window) { |
| BrowserList* browser_list_impl = BrowserList::GetInstance(); |
| size_t count = 0; |
| if (browser_list_impl) { |
| for (BrowserList::const_iterator i = browser_list_impl->begin(); |
| i != browser_list_impl->end(); ++i) { |
| - if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types)) |
| + if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types, |
| + root_window)) |
| count++; |
| } |
| } |
| @@ -151,18 +162,25 @@ namespace chrome { |
| Browser* FindTabbedBrowser(Profile* profile, |
| bool match_original_profiles) { |
| - return FindBrowserWithTabbedOrAnyType(profile, true, match_original_profiles); |
| + return FindBrowserWithTabbedOrAnyType(profile, true, match_original_profiles, |
| + false, NULL); |
|
stevenjb
2017/05/22 17:55:29
nullptr throughout
|
| +} |
| + |
| +Browser* FindTabbedBrowserInRootWindow(Profile* profile, |
| + bool match_original_profiles, |
| + const aura::Window* root_window) { |
| + return FindBrowserWithTabbedOrAnyType(profile, true, match_original_profiles, |
| + true, root_window); |
| } |
| Browser* FindAnyBrowser(Profile* profile, |
| bool match_original_profiles) { |
| - return FindBrowserWithTabbedOrAnyType(profile, |
| - false, |
| - match_original_profiles); |
| + return FindBrowserWithTabbedOrAnyType(profile, false, match_original_profiles, |
| + false, NULL); |
| } |
| Browser* FindBrowserWithProfile(Profile* profile) { |
| - return FindBrowserWithTabbedOrAnyType(profile, false, false); |
| + return FindBrowserWithTabbedOrAnyType(profile, false, false, false, NULL); |
| } |
| Browser* FindBrowserWithID(SessionID::id_type desired_id) { |
| @@ -197,7 +215,7 @@ Browser* FindLastActiveWithProfile(Profile* profile) { |
| // We are only interested in last active browsers, so we don't fall back to |
| // all browsers like FindBrowserWith* do. |
| return FindBrowserMatching(list->begin_last_active(), list->end_last_active(), |
| - profile, Browser::FEATURE_NONE, kMatchAny); |
| + profile, Browser::FEATURE_NONE, kMatchAny, NULL); |
| } |
| Browser* FindLastActive() { |
| @@ -212,11 +230,11 @@ size_t GetTotalBrowserCount() { |
| } |
| size_t GetBrowserCount(Profile* profile) { |
| - return GetBrowserCountImpl(profile, kMatchAny); |
| + return GetBrowserCountImpl(profile, kMatchAny, NULL); |
| } |
| size_t GetTabbedBrowserCount(Profile* profile) { |
| - return GetBrowserCountImpl(profile, kMatchTabbed); |
| + return GetBrowserCountImpl(profile, kMatchTabbed, NULL); |
| } |
| } // namespace chrome |