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