Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 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_SINGLETON_TABS_H_ |
| 6 | #define CHROME_BROWSER_UI_SINGLETON_TABS_H_ |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 7 | |
thestig | e8082124 | 2015-09-30 23:46:08 | [diff] [blame] | 8 | #include "chrome/browser/ui/browser_navigator_params.h" |
| 9 | |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 10 | class Browser; |
| 11 | class GURL; |
| 12 | |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 13 | // Methods for opening "singleton tabs". Tabs are guaranteed unique by varying |
| 14 | // metrics within a particular Browser window. |
| 15 | |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 16 | // Core singleton tab API: |
| 17 | |
Georg Neis | b037e337 | 2023-06-20 01:44:56 | [diff] [blame] | 18 | // Shows a given a URL. If a tab with the same URL (ignoring the ref) is already |
| 19 | // visible in this browser, it becomes selected. Otherwise a new tab is created. |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 20 | void ShowSingletonTab(Browser* browser, const GURL& url); |
| 21 | |
Georg Neis | b037e337 | 2023-06-20 01:44:56 | [diff] [blame] | 22 | // Like above, but uses the last active tabbed browser or creates a new one if |
| 23 | // possible. |
| 24 | void ShowSingletonTab(Profile* profile, const GURL& url); |
| 25 | |
| 26 | // Like ShowSingletonTab, but if the current tab is the new tab page or |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 27 | // about:blank, then overwrite it with the passed contents. |
Georg Neis | b037e337 | 2023-06-20 01:44:56 | [diff] [blame] | 28 | void ShowSingletonTabOverwritingNTP( |
| 29 | Profile* profile, |
| 30 | const GURL& url, |
| 31 | NavigateParams::PathBehavior path_behavior = NavigateParams::RESPECT); |
| 32 | void ShowSingletonTabOverwritingNTP( |
| 33 | Browser* browser, |
| 34 | const GURL& url, |
| 35 | NavigateParams::PathBehavior path_behavior = NavigateParams::RESPECT); |
| 36 | void ShowSingletonTabOverwritingNTP(NavigateParams* params); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 37 | |
| 38 | // Creates a NavigateParams struct for a singleton tab navigation. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 39 | NavigateParams GetSingletonTabNavigateParams(Browser* browser, const GURL& url); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 40 | |
Kevin Bailey | c8f9ef32 | 2018-01-05 17:19:55 | [diff] [blame] | 41 | // If the given navigational URL is already open in |browser|, return |
| 42 | // the tab and tab index for it. Otherwise, returns -1. |
| 43 | int GetIndexOfExistingTab(Browser* browser, const NavigateParams& params); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 44 | |
Kevin Bailey | 2934342 | 2019-10-04 00:22:51 | [diff] [blame] | 45 | // This simply calls GetIndexOfExistingTab() for each browser that |
| 46 | // matches the passed |profile|, and returns the first found tab. |
| 47 | std::pair<Browser*, int> GetIndexAndBrowserOfExistingTab( |
| 48 | Profile* profile, |
| 49 | const NavigateParams& params); |
| 50 | |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 51 | #endif // CHROME_BROWSER_UI_SINGLETON_TABS_H_ |