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..559bfbe2382a922cf4d1e24d6f5fba913c291120 100644 |
| --- a/chrome/browser/ui/browser_finder.cc |
| +++ b/chrome/browser/ui/browser_finder.cc |
| @@ -13,6 +13,9 @@ |
| #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "content/public/browser/navigation_controller.h" |
| +#include "ui/display/display.h" |
| +#include "ui/display/screen.h" |
| +#include "ui/display/types/display_constants.h" |
| #if defined(OS_CHROMEOS) |
| #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| @@ -32,6 +35,7 @@ const int kMatchAny = 0; |
| const int kMatchOriginalProfile = 1 << 0; |
| const int kMatchCanSupportWindowFeature = 1 << 1; |
| const int kMatchTabbed = 1 << 2; |
| +const int kMatchDisplayId = 1 << 3; |
| // Returns true if the specified |browser| matches the specified arguments. |
| // |match_types| is a bitmask dictating what parameters to match: |
| @@ -44,7 +48,8 @@ const int kMatchTabbed = 1 << 2; |
| bool BrowserMatches(Browser* browser, |
| Profile* profile, |
| Browser::WindowFeature window_feature, |
| - uint32_t match_types) { |
| + uint32_t match_types, |
| + int64_t display_id) { |
| if ((match_types & kMatchCanSupportWindowFeature) && |
| !browser->CanSupportWindowFeature(window_feature)) { |
| return false; |
| @@ -85,8 +90,13 @@ 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 & kMatchDisplayId) |
| + return display::Screen::GetScreen() |
| + ->GetDisplayNearestWindow(browser->window()->GetNativeWindow()) |
| + .id() == display_id; |
|
stevenjb
2017/05/23 21:56:43
{}
weidongg
2017/05/24 17:49:40
Done.
|
| return true; |
| } |
| @@ -99,9 +109,10 @@ Browser* FindBrowserMatching(const T& begin, |
| const T& end, |
| Profile* profile, |
| Browser::WindowFeature window_feature, |
| - uint32_t match_types) { |
| + uint32_t match_types, |
| + int64_t display_id) { |
| for (T i = begin; i != end; ++i) { |
| - if (BrowserMatches(*i, profile, window_feature, match_types)) |
| + if (BrowserMatches(*i, profile, window_feature, match_types, display_id)) |
| return *i; |
| } |
| return NULL; |
| @@ -109,7 +120,8 @@ Browser* FindBrowserMatching(const T& begin, |
| Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, |
| bool match_tabbed, |
| - bool match_original_profiles) { |
| + bool match_original_profiles, |
| + int64_t display_id) { |
| BrowserList* browser_list_impl = BrowserList::GetInstance(); |
| if (!browser_list_impl) |
| return NULL; |
| @@ -118,27 +130,29 @@ 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 (display_id != display::kInvalidDisplayId) |
| + match_types |= kMatchDisplayId; |
| + Browser* browser = |
| + FindBrowserMatching(browser_list_impl->begin_last_active(), |
| + browser_list_impl->end_last_active(), profile, |
| + Browser::FEATURE_NONE, match_types, display_id); |
| // 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, display_id); |
| } |
| size_t GetBrowserCountImpl(Profile* profile, |
| - uint32_t match_types) { |
| + uint32_t match_types, |
| + int64_t display_id) { |
| 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, |
| + display_id)) |
| count++; |
| } |
| } |
| @@ -151,18 +165,26 @@ namespace chrome { |
| Browser* FindTabbedBrowser(Profile* profile, |
| bool match_original_profiles) { |
| - return FindBrowserWithTabbedOrAnyType(profile, true, match_original_profiles); |
| + return FindBrowserWithTabbedOrAnyType(profile, true, match_original_profiles, |
| + display::kInvalidDisplayId); |
| +} |
| + |
| +Browser* FindTabbedBrowserOnDisplay(Profile* profile, |
| + bool match_original_profiles, |
| + int64_t display_id) { |
| + return FindBrowserWithTabbedOrAnyType(profile, true, match_original_profiles, |
| + display_id); |
| } |
| Browser* FindAnyBrowser(Profile* profile, |
| bool match_original_profiles) { |
| - return FindBrowserWithTabbedOrAnyType(profile, |
| - false, |
| - match_original_profiles); |
| + return FindBrowserWithTabbedOrAnyType(profile, false, match_original_profiles, |
| + display::kInvalidDisplayId); |
| } |
| Browser* FindBrowserWithProfile(Profile* profile) { |
| - return FindBrowserWithTabbedOrAnyType(profile, false, false); |
| + return FindBrowserWithTabbedOrAnyType(profile, false, false, |
| + display::kInvalidDisplayId); |
| } |
| Browser* FindBrowserWithID(SessionID::id_type desired_id) { |
| @@ -197,7 +219,8 @@ 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, |
| + display::kInvalidDisplayId); |
| } |
| Browser* FindLastActive() { |
| @@ -212,11 +235,11 @@ size_t GetTotalBrowserCount() { |
| } |
| size_t GetBrowserCount(Profile* profile) { |
| - return GetBrowserCountImpl(profile, kMatchAny); |
| + return GetBrowserCountImpl(profile, kMatchAny, display::kInvalidDisplayId); |
| } |
| size_t GetTabbedBrowserCount(Profile* profile) { |
| - return GetBrowserCountImpl(profile, kMatchTabbed); |
| + return GetBrowserCountImpl(profile, kMatchTabbed, display::kInvalidDisplayId); |
| } |
| } // namespace chrome |