[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_UI_BROWSER_FINDER_H_ |
| 6 | #define CHROME_BROWSER_UI_BROWSER_FINDER_H_ |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 7 | |
| 8 | #include "chrome/browser/ui/browser.h" |
[email protected] | 7f4a1d24 | 2012-12-05 05:55:57 | [diff] [blame] | 9 | #include "chrome/browser/ui/host_desktop.h" |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 10 | #include "ui/gfx/native_widget_types.h" |
| 11 | |
| 12 | class Profile; |
| 13 | |
| 14 | namespace contents { |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 15 | class WebContents; |
| 16 | } |
| 17 | |
| 18 | // Collection of functions to find Browsers based on various criteria. |
| 19 | |
[email protected] | 7507273 | 2013-01-09 13:39:25 | [diff] [blame] | 20 | namespace chrome { |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 21 | |
| 22 | // Retrieve the last active tabbed browser with a profile matching |profile|. |
| 23 | // If |match_original_profiles| is true, matching is done based on the |
| 24 | // original profile, eg profile->GetOriginalProfile() == |
| 25 | // browser->profile()->GetOriginalProfile(). This has the effect of matching |
| 26 | // against both non-incognito and incognito profiles. If |
| 27 | // |match_original_profiles| is false, only an exact match may be returned. |
[email protected] | 3b14b7f2 | 2012-10-04 01:29:09 | [diff] [blame] | 28 | // |type| refers to the host desktop the returned browser should belong to. |
| 29 | Browser* FindTabbedBrowser(Profile* profile, |
| 30 | bool match_original_profiles, |
[email protected] | 7507273 | 2013-01-09 13:39:25 | [diff] [blame] | 31 | HostDesktopType type); |
[email protected] | 3c6a095 | 2012-12-17 11:56:09 | [diff] [blame] | 32 | |
[email protected] | 7b0957f | 2012-12-26 22:23:08 | [diff] [blame] | 33 | // Returns the first tabbed browser matching |profile|. If there is no tabbed |
| 34 | // browser a new one is created and returned for the desktop specified by |
| 35 | // |type|. If a new browser is created it is not made visible. |
| 36 | Browser* FindOrCreateTabbedBrowser(Profile* profile, HostDesktopType type); |
| 37 | |
[email protected] | 7f4a1d24 | 2012-12-05 05:55:57 | [diff] [blame] | 38 | // Finds an existing browser window of any kind. |
| 39 | // |type| refers to the host desktop the returned browser should belong to. |
| 40 | Browser* FindAnyBrowser(Profile* profile, |
| 41 | bool match_original_profiles, |
[email protected] | 3c6a095 | 2012-12-17 11:56:09 | [diff] [blame] | 42 | HostDesktopType type); |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 43 | |
[email protected] | 323fd712 | 2012-08-24 14:45:11 | [diff] [blame] | 44 | // Find an existing browser window with the provided profile and hosted in the |
| 45 | // given desktop. Searches in the order of last activation. Only browsers that |
| 46 | // have been active can be returned. Returns NULL if no such browser currently |
| 47 | // exists. |
[email protected] | 3c6a095 | 2012-12-17 11:56:09 | [diff] [blame] | 48 | Browser* FindBrowserWithProfile(Profile* profile, HostDesktopType type); |
[email protected] | 0da7676 | 2012-12-09 09:24:14 | [diff] [blame] | 49 | |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 50 | // Find an existing browser with the provided ID. Returns NULL if no such |
| 51 | // browser currently exists. |
| 52 | Browser* FindBrowserWithID(SessionID::id_type desired_id); |
| 53 | |
| 54 | // Find the browser represented by |window| or NULL if not found. |
| 55 | Browser* FindBrowserWithWindow(gfx::NativeWindow window); |
| 56 | |
[email protected] | f7b4b9e | 2012-12-02 07:43:17 | [diff] [blame] | 57 | // Find the browser containing |web_contents| or NULL if none is found. |
| 58 | // |web_contents| must not be NULL. |
| 59 | Browser* FindBrowserWithWebContents(const content::WebContents* web_contents); |
| 60 | |
[email protected] | 69425607 | 2012-11-29 13:40:34 | [diff] [blame] | 61 | // Returns the Browser object owned by |profile| on the given desktop type |
| 62 | // whose window was most recently active. If no such Browsers exist, returns |
| 63 | // NULL. |
[email protected] | 4d90025 | 2012-11-20 20:37:11 | [diff] [blame] | 64 | // |
| 65 | // WARNING: this is NULL until a browser becomes active. If during startup |
| 66 | // a browser does not become active (perhaps the user launches Chrome, then |
| 67 | // clicks on another app before the first browser window appears) then this |
| 68 | // returns NULL. |
| 69 | // WARNING #2: this will always be NULL in unit tests run on the bots. |
[email protected] | 69425607 | 2012-11-29 13:40:34 | [diff] [blame] | 70 | Browser* FindLastActiveWithProfile(Profile* profile, HostDesktopType type); |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 71 | |
[email protected] | 4d90025 | 2012-11-20 20:37:11 | [diff] [blame] | 72 | // Returns the Browser object on the given desktop type whose window was most |
| 73 | // recently active. If no such Browsers exist, returns NULL. |
| 74 | // |
| 75 | // WARNING: this is NULL until a browser becomes active. If during startup |
| 76 | // a browser does not become active (perhaps the user launches Chrome, then |
| 77 | // clicks on another app before the first browser window appears) then this |
| 78 | // returns NULL. |
| 79 | // WARNING #2: this will always be NULL in unit tests run on the bots. |
[email protected] | 53a6733 | 2012-11-11 00:29:09 | [diff] [blame] | 80 | Browser* FindLastActiveWithHostDesktopType(HostDesktopType type); |
[email protected] | 52ff7d93 | 2012-10-28 19:46:46 | [diff] [blame] | 81 | |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 82 | // Returns the number of browsers across all profiles and desktops. |
| 83 | size_t GetTotalBrowserCount(); |
| 84 | |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 85 | // Returns the number of browsers with the Profile |profile| accross all |
| 86 | // desktops. |
| 87 | size_t GetTotalBrowserCountForProfile(Profile* profile); |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 88 | |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 89 | // Returns the number of browsers with the Profile |profile| on the desktop |
| 90 | // defined by |type|. |
| 91 | size_t GetBrowserCount(Profile* profile, HostDesktopType type); |
| 92 | |
| 93 | // Returns the number of tabbed browsers with the Profile |profile| on the |
| 94 | // desktop defined by |type|. |
| 95 | size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type); |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 96 | |
[email protected] | 52ff7d93 | 2012-10-28 19:46:46 | [diff] [blame] | 97 | } // namespace chrome |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 98 | |
| 99 | #endif // CHROME_BROWSER_UI_BROWSER_FINDER_H_ |