blob: 6039a65536f4927524bdebccb458c2f1c7b15538 [file] [log] [blame]
[email protected]d8748142012-05-16 21:13:431// 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]d8748142012-05-16 21:13:437
8#include "chrome/browser/ui/browser.h"
[email protected]7f4a1d242012-12-05 05:55:579#include "chrome/browser/ui/host_desktop.h"
[email protected]d8748142012-05-16 21:13:4310#include "ui/gfx/native_widget_types.h"
11
12class Profile;
13
14namespace contents {
[email protected]d8748142012-05-16 21:13:4315class WebContents;
16}
17
18// Collection of functions to find Browsers based on various criteria.
19
[email protected]75072732013-01-09 13:39:2520namespace chrome {
[email protected]d8748142012-05-16 21:13:4321
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]3b14b7f22012-10-04 01:29:0928// |type| refers to the host desktop the returned browser should belong to.
29Browser* FindTabbedBrowser(Profile* profile,
30 bool match_original_profiles,
[email protected]75072732013-01-09 13:39:2531 HostDesktopType type);
[email protected]3c6a0952012-12-17 11:56:0932
[email protected]7b0957f2012-12-26 22:23:0833// 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.
36Browser* FindOrCreateTabbedBrowser(Profile* profile, HostDesktopType type);
37
[email protected]7f4a1d242012-12-05 05:55:5738// Finds an existing browser window of any kind.
39// |type| refers to the host desktop the returned browser should belong to.
40Browser* FindAnyBrowser(Profile* profile,
41 bool match_original_profiles,
[email protected]3c6a0952012-12-17 11:56:0942 HostDesktopType type);
[email protected]d8748142012-05-16 21:13:4343
[email protected]323fd7122012-08-24 14:45:1144// 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]3c6a0952012-12-17 11:56:0948Browser* FindBrowserWithProfile(Profile* profile, HostDesktopType type);
[email protected]0da76762012-12-09 09:24:1449
[email protected]d8748142012-05-16 21:13:4350// Find an existing browser with the provided ID. Returns NULL if no such
51// browser currently exists.
52Browser* FindBrowserWithID(SessionID::id_type desired_id);
53
54// Find the browser represented by |window| or NULL if not found.
55Browser* FindBrowserWithWindow(gfx::NativeWindow window);
56
[email protected]f7b4b9e2012-12-02 07:43:1757// Find the browser containing |web_contents| or NULL if none is found.
58// |web_contents| must not be NULL.
59Browser* FindBrowserWithWebContents(const content::WebContents* web_contents);
60
[email protected]694256072012-11-29 13:40:3461// 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]4d900252012-11-20 20:37:1164//
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]694256072012-11-29 13:40:3470Browser* FindLastActiveWithProfile(Profile* profile, HostDesktopType type);
[email protected]d8748142012-05-16 21:13:4371
[email protected]4d900252012-11-20 20:37:1172// 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]53a67332012-11-11 00:29:0980Browser* FindLastActiveWithHostDesktopType(HostDesktopType type);
[email protected]52ff7d932012-10-28 19:46:4681
[email protected]0665ebe2013-02-13 09:53:1982// Returns the number of browsers across all profiles and desktops.
83size_t GetTotalBrowserCount();
84
[email protected]c987a242013-02-28 01:17:4185// Returns the number of browsers with the Profile |profile| accross all
86// desktops.
87size_t GetTotalBrowserCountForProfile(Profile* profile);
[email protected]d8748142012-05-16 21:13:4388
[email protected]c987a242013-02-28 01:17:4189// Returns the number of browsers with the Profile |profile| on the desktop
90// defined by |type|.
91size_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|.
95size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type);
[email protected]d8748142012-05-16 21:13:4396
[email protected]52ff7d932012-10-28 19:46:4697} // namespace chrome
[email protected]d8748142012-05-16 21:13:4398
99#endif // CHROME_BROWSER_UI_BROWSER_FINDER_H_