Home | History | Annotate | Download | only in ui
      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_
      7 
      8 #include "chrome/browser/ui/browser.h"
      9 #include "chrome/browser/ui/host_desktop.h"
     10 #include "ui/gfx/native_widget_types.h"
     11 
     12 class Profile;
     13 
     14 namespace contents {
     15 class WebContents;
     16 }
     17 
     18 // Collection of functions to find Browsers based on various criteria.
     19 
     20 namespace chrome {
     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.
     28 // |type| refers to the host desktop the returned browser should belong to.
     29 Browser* FindTabbedBrowser(Profile* profile,
     30                            bool match_original_profiles,
     31                            HostDesktopType type);
     32 
     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 
     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,
     42                         HostDesktopType type);
     43 
     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.
     48 Browser* FindBrowserWithProfile(Profile* profile, HostDesktopType type);
     49 
     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 
     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 
     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.
     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.
     70 Browser* FindLastActiveWithProfile(Profile* profile, HostDesktopType type);
     71 
     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.
     80 Browser* FindLastActiveWithHostDesktopType(HostDesktopType type);
     81 
     82 // Returns the number of browsers across all profiles and desktops.
     83 size_t GetTotalBrowserCount();
     84 
     85 // Returns the number of browsers with the Profile |profile| accross all
     86 // desktops.
     87 size_t GetTotalBrowserCountForProfile(Profile* profile);
     88 
     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);
     96 
     97 }  // namespace chrome
     98 
     99 #endif  // CHROME_BROWSER_UI_BROWSER_FINDER_H_
    100