15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_BROWSER_FINDER_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_BROWSER_FINDER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/host_desktop.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/native_widget_types.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile;
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace contents {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents;
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Collection of functions to find Browsers based on various criteria.
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace chrome {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Retrieve the last active tabbed browser with a profile matching |profile|.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If |match_original_profiles| is true, matching is done based on the
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// original profile, eg profile->GetOriginalProfile() ==
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// browser->profile()->GetOriginalProfile(). This has the effect of matching
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// against both non-incognito and incognito profiles. If
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |match_original_profiles| is false, only an exact match may be returned.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |type| refers to the host desktop the returned browser should belong to.
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Browser* FindTabbedBrowser(Profile* profile,
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           bool match_original_profiles,
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           HostDesktopType type);
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the first tabbed browser matching |profile|. If there is no tabbed
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// browser a new one is created and returned for the desktop specified by
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |type|. If a new browser is created it is not made visible.
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)Browser* FindOrCreateTabbedBrowser(Profile* profile, HostDesktopType type);
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Finds an existing browser window of any kind.
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// |type| refers to the host desktop the returned browser should belong to.
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)Browser* FindAnyBrowser(Profile* profile,
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                        bool match_original_profiles,
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                        HostDesktopType type);
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Find an existing browser window with the provided profile and hosted in the
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// given desktop. Searches in the order of last activation. Only browsers that
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// have been active can be returned. Returns NULL if no such browser currently
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// exists.
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)Browser* FindBrowserWithProfile(Profile* profile, HostDesktopType type);
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Find an existing browser with the provided ID. Returns NULL if no such
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// browser currently exists.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Browser* FindBrowserWithID(SessionID::id_type desired_id);
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Find the browser represented by |window| or NULL if not found.
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Browser* FindBrowserWithWindow(gfx::NativeWindow window);
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Find the browser containing |web_contents| or NULL if none is found.
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |web_contents| must not be NULL.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Browser* FindBrowserWithWebContents(const content::WebContents* web_contents);
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the Browser object owned by |profile| on the given desktop type
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// whose window was most recently active. If no such Browsers exist, returns
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// NULL.
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// WARNING: this is NULL until a browser becomes active. If during startup
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// a browser does not become active (perhaps the user launches Chrome, then
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// clicks on another app before the first browser window appears) then this
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// returns NULL.
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// WARNING #2: this will always be NULL in unit tests run on the bots.
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)Browser* FindLastActiveWithProfile(Profile* profile, HostDesktopType type);
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the Browser object on the given desktop type whose window was most
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// recently active. If no such Browsers exist, returns NULL.
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// WARNING: this is NULL until a browser becomes active. If during startup
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// a browser does not become active (perhaps the user launches Chrome, then
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// clicks on another app before the first browser window appears) then this
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// returns NULL.
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// WARNING #2: this will always be NULL in unit tests run on the bots.
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)Browser* FindLastActiveWithHostDesktopType(HostDesktopType type);
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the number of browsers across all profiles and desktops.
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)size_t GetTotalBrowserCount();
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the number of browsers with the Profile |profile| accross all
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// desktops.
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)size_t GetTotalBrowserCountForProfile(Profile* profile);
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the number of browsers with the Profile |profile| on the desktop
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// defined by |type|.
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)size_t GetBrowserCount(Profile* profile, HostDesktopType type);
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the number of tabbed browsers with the Profile |profile| on the
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// desktop defined by |type|.
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type);
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace chrome
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_UI_BROWSER_FINDER_H_
100