blob: 63245ad5802321ec4c61337579366788de3fde1a [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__
[email protected]ac84431b2011-09-27 17:26:117
8#include <string>
9
[email protected]73c1a6842012-07-13 17:39:0410#include "webkit/glue/window_open_disposition.h"
11
[email protected]ac84431b2011-09-27 17:26:1112class Browser;
[email protected]45c75e62012-03-21 19:56:3513class GURL;
[email protected]ac84431b2011-09-27 17:26:1114class Profile;
[email protected]c36a9e1d2012-06-05 14:31:0215class TabContents;
[email protected]ac84431b2011-09-27 17:26:1116class TabStripModel;
17
18namespace base {
19class DictionaryValue;
20class ListValue;
21}
22
[email protected]26b5e322011-12-23 01:36:4723namespace content {
24class WebContents;
25}
26
[email protected]1c321ee2012-05-21 03:02:3427namespace extensions {
28class Extension;
29}
30
[email protected]73c1a6842012-07-13 17:39:0431namespace gfx {
32class Rect;
33}
34
[email protected]ac84431b2011-09-27 17:26:1135// Provides various utility functions that help manipulate tabs.
36class ExtensionTabUtil {
37 public:
38 static int GetWindowId(const Browser* browser);
[email protected]8c3495c2011-09-28 03:32:3039 static int GetWindowIdOfTabStripModel(const TabStripModel* tab_strip_model);
[email protected]26b5e322011-12-23 01:36:4740 static int GetTabId(const content::WebContents* web_contents);
[email protected]ac84431b2011-09-27 17:26:1141 static std::string GetTabStatusText(bool is_loading);
[email protected]ea049a02011-12-25 21:37:0942 static int GetWindowIdOfTab(const content::WebContents* web_contents);
[email protected]ac84431b2011-09-27 17:26:1143 static base::ListValue* CreateTabList(const Browser* browser);
44 static base::DictionaryValue* CreateTabValue(
[email protected]ea049a02011-12-25 21:37:0945 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]ac84431b2011-09-27 17:26:1150 // Create a tab value, overriding its kSelectedKey to the provided boolean.
51 static base::DictionaryValue* CreateTabValueActive(
[email protected]ea049a02011-12-25 21:37:0952 const content::WebContents* web_contents,
[email protected]ac84431b2011-09-27 17:26:1153 bool active);
[email protected]41d9faf2012-02-28 23:46:0254
[email protected]ea049a02011-12-25 21:37:0955 // Gets the |tab_strip_model| and |tab_index| for the given |web_contents|.
56 static bool GetTabStripModel(const content::WebContents* web_contents,
[email protected]ac84431b2011-09-27 17:26:1157 TabStripModel** tab_strip_model,
58 int* tab_index);
59 static bool GetDefaultTab(Browser* browser,
[email protected]b62084b2012-06-12 01:53:3060 TabContents** contents,
[email protected]ac84431b2011-09-27 17:26:1161 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]b62084b2012-06-12 01:53:3067 TabContents** contents,
[email protected]ac84431b2011-09-27 17:26:1168 int* tab_index);
[email protected]45c75e62012-03-21 19:56:3569
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]1c321ee2012-05-21 03:02:3479 const extensions::Extension* extension);
[email protected]45c75e62012-03-21 19:56:3580
81 // Returns true if |url| is used for testing crashes.
82 static bool IsCrashURL(const GURL& url);
[email protected]73c1a6842012-07-13 17:39:0483
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]ac84431b2011-09-27 17:26:1190};
91
92#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_UTIL_H__