[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [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_EXTENSIONS_EXTENSION_TAB_UTIL_H__ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_UTIL_H__ |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
[email protected] | 73c1a684 | 2012-07-13 17:39:04 | [diff] [blame^] | 10 | #include "webkit/glue/window_open_disposition.h" |
| 11 | |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 12 | class Browser; |
[email protected] | 45c75e6 | 2012-03-21 19:56:35 | [diff] [blame] | 13 | class GURL; |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 14 | class Profile; |
[email protected] | c36a9e1d | 2012-06-05 14:31:02 | [diff] [blame] | 15 | class TabContents; |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 16 | class TabStripModel; |
| 17 | |
| 18 | namespace base { |
| 19 | class DictionaryValue; |
| 20 | class ListValue; |
| 21 | } |
| 22 | |
[email protected] | 26b5e32 | 2011-12-23 01:36:47 | [diff] [blame] | 23 | namespace content { |
| 24 | class WebContents; |
| 25 | } |
| 26 | |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 27 | namespace extensions { |
| 28 | class Extension; |
| 29 | } |
| 30 | |
[email protected] | 73c1a684 | 2012-07-13 17:39:04 | [diff] [blame^] | 31 | namespace gfx { |
| 32 | class Rect; |
| 33 | } |
| 34 | |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 35 | // Provides various utility functions that help manipulate tabs. |
| 36 | class ExtensionTabUtil { |
| 37 | public: |
| 38 | static int GetWindowId(const Browser* browser); |
[email protected] | 8c3495c | 2011-09-28 03:32:30 | [diff] [blame] | 39 | static int GetWindowIdOfTabStripModel(const TabStripModel* tab_strip_model); |
[email protected] | 26b5e32 | 2011-12-23 01:36:47 | [diff] [blame] | 40 | static int GetTabId(const content::WebContents* web_contents); |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 41 | static std::string GetTabStatusText(bool is_loading); |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 42 | static int GetWindowIdOfTab(const content::WebContents* web_contents); |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 43 | static base::ListValue* CreateTabList(const Browser* browser); |
| 44 | static base::DictionaryValue* CreateTabValue( |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 45 | const content::WebContents* web_contents); |
| 46 | static base::DictionaryValue* CreateTabValue( |
| 47 | const content::WebContents* web_contents, |
| 48 | TabStripModel* tab_strip, |
| 49 | int tab_index); |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 50 | // Create a tab value, overriding its kSelectedKey to the provided boolean. |
| 51 | static base::DictionaryValue* CreateTabValueActive( |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 52 | const content::WebContents* web_contents, |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 53 | bool active); |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 54 | |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 55 | // Gets the |tab_strip_model| and |tab_index| for the given |web_contents|. |
| 56 | static bool GetTabStripModel(const content::WebContents* web_contents, |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 57 | TabStripModel** tab_strip_model, |
| 58 | int* tab_index); |
| 59 | static bool GetDefaultTab(Browser* browser, |
[email protected] | b62084b | 2012-06-12 01:53:30 | [diff] [blame] | 60 | TabContents** contents, |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 61 | int* tab_id); |
| 62 | // Any out parameter (|browser|, |tab_strip|, |contents|, & |tab_index|) may |
| 63 | // be NULL and will not be set within the function. |
| 64 | static bool GetTabById(int tab_id, Profile* profile, bool incognito_enabled, |
| 65 | Browser** browser, |
| 66 | TabStripModel** tab_strip, |
[email protected] | b62084b | 2012-06-12 01:53:30 | [diff] [blame] | 67 | TabContents** contents, |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 68 | int* tab_index); |
[email protected] | 45c75e6 | 2012-03-21 19:56:35 | [diff] [blame] | 69 | |
| 70 | // Takes |url_string| and returns a GURL which is either valid and absolute |
| 71 | // or invalid. If |url_string| is not directly interpretable as a valid (it is |
| 72 | // likely a relative URL) an attempt is made to resolve it. |extension| is |
| 73 | // provided so it can be resolved relative to its extension base |
| 74 | // (chrome-extension://<id>/). Using the source frame url would be more |
| 75 | // correct, but because the api shipped with urls resolved relative to their |
| 76 | // extension base, we decided it wasn't worth breaking existing extensions to |
| 77 | // fix. |
| 78 | static GURL ResolvePossiblyRelativeURL(const std::string& url_string, |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 79 | const extensions::Extension* extension); |
[email protected] | 45c75e6 | 2012-03-21 19:56:35 | [diff] [blame] | 80 | |
| 81 | // Returns true if |url| is used for testing crashes. |
| 82 | static bool IsCrashURL(const GURL& url); |
[email protected] | 73c1a684 | 2012-07-13 17:39:04 | [diff] [blame^] | 83 | |
| 84 | // Opens a tab for the specified |web_contents|. |
| 85 | static void CreateTab(content::WebContents* web_contents, |
| 86 | const std::string& extension_id, |
| 87 | WindowOpenDisposition disposition, |
| 88 | const gfx::Rect& initial_pos, |
| 89 | bool user_gesture); |
[email protected] | ac84431b | 2011-09-27 17:26:11 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_UTIL_H__ |