blob: d6659e6599879a021085b8ff1267add73a86c551 [file] [log] [blame]
[email protected]41d9faf2012-02-28 23:46:021// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ac84431b2011-09-27 17:26:112// 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
11class Browser;
[email protected]45c75e62012-03-21 19:56:3512class GURL;
[email protected]ac84431b2011-09-27 17:26:1113class Profile;
[email protected]ac84431b2011-09-27 17:26:1114class TabContentsWrapper;
15class TabStripModel;
16
17namespace base {
18class DictionaryValue;
19class ListValue;
20}
21
[email protected]26b5e322011-12-23 01:36:4722namespace content {
23class WebContents;
24}
25
[email protected]1c321ee2012-05-21 03:02:3426namespace extensions {
27class Extension;
28}
29
[email protected]ac84431b2011-09-27 17:26:1130// Provides various utility functions that help manipulate tabs.
31class ExtensionTabUtil {
32 public:
33 static int GetWindowId(const Browser* browser);
[email protected]8c3495c2011-09-28 03:32:3034 static int GetWindowIdOfTabStripModel(const TabStripModel* tab_strip_model);
[email protected]26b5e322011-12-23 01:36:4735 static int GetTabId(const content::WebContents* web_contents);
[email protected]ac84431b2011-09-27 17:26:1136 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]ea049a02011-12-25 21:37:0940 static int GetWindowIdOfTab(const content::WebContents* web_contents);
[email protected]ac84431b2011-09-27 17:26:1141 static base::ListValue* CreateTabList(const Browser* browser);
42 static base::DictionaryValue* CreateTabValue(
[email protected]ea049a02011-12-25 21:37:0943 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]ac84431b2011-09-27 17:26:1148 // Create a tab value, overriding its kSelectedKey to the provided boolean.
49 static base::DictionaryValue* CreateTabValueActive(
[email protected]ea049a02011-12-25 21:37:0950 const content::WebContents* web_contents,
[email protected]ac84431b2011-09-27 17:26:1151 bool active);
[email protected]41d9faf2012-02-28 23:46:0252
[email protected]ea049a02011-12-25 21:37:0953 // Gets the |tab_strip_model| and |tab_index| for the given |web_contents|.
54 static bool GetTabStripModel(const content::WebContents* web_contents,
[email protected]ac84431b2011-09-27 17:26:1155 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]45c75e62012-03-21 19:56:3567
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]1c321ee2012-05-21 03:02:3477 const extensions::Extension* extension);
[email protected]45c75e62012-03-21 19:56:3578
79 // Returns true if |url| is used for testing crashes.
80 static bool IsCrashURL(const GURL& url);
[email protected]ac84431b2011-09-27 17:26:1181};
82
83#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_UTIL_H__