blob: 3a8aa22139ddb83949bd5cb34134ecb96c83c7f2 [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]44e329a2012-07-14 01:13:0610#include "base/callback.h"
[email protected]73c1a6842012-07-13 17:39:0411#include "webkit/glue/window_open_disposition.h"
12
[email protected]ac84431b2011-09-27 17:26:1113class Browser;
[email protected]45c75e62012-03-21 19:56:3514class GURL;
[email protected]ac84431b2011-09-27 17:26:1115class Profile;
[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;
[email protected]e9570fdf2012-07-18 20:01:2129class WindowController;
[email protected]1c321ee2012-05-21 03:02:3430}
31
[email protected]73c1a6842012-07-13 17:39:0432namespace gfx {
33class Rect;
34}
35
[email protected]ac84431b2011-09-27 17:26:1136// Provides various utility functions that help manipulate tabs.
37class ExtensionTabUtil {
38 public:
39 static int GetWindowId(const Browser* browser);
[email protected]8c3495c2011-09-28 03:32:3040 static int GetWindowIdOfTabStripModel(const TabStripModel* tab_strip_model);
[email protected]26b5e322011-12-23 01:36:4741 static int GetTabId(const content::WebContents* web_contents);
[email protected]ac84431b2011-09-27 17:26:1142 static std::string GetTabStatusText(bool is_loading);
[email protected]ea049a02011-12-25 21:37:0943 static int GetWindowIdOfTab(const content::WebContents* web_contents);
[email protected]f34706be2012-09-04 07:32:0944 static base::ListValue* CreateTabList(
45 const Browser* browser,
46 const extensions::Extension* extension);
[email protected]0c9f3262012-09-17 05:59:0647
[email protected]304fd152013-01-12 16:54:4448 // Creates a Tab object (see chrome/common/extensions/api/tabs.json) with
49 // information about the state of a browser tab. Depending on the
50 // permissions of the extension, the object may or may not include sensitive
51 // data such as the tab's URL.
[email protected]ac84431b2011-09-27 17:26:1152 static base::DictionaryValue* CreateTabValue(
[email protected]f34706be2012-09-04 07:32:0953 const content::WebContents* web_contents,
[email protected]0c9f3262012-09-17 05:59:0654 const extensions::Extension* extension) {
55 return CreateTabValue(web_contents, NULL, -1, extension);
56 }
[email protected]ea049a02011-12-25 21:37:0957 static base::DictionaryValue* CreateTabValue(
58 const content::WebContents* web_contents,
59 TabStripModel* tab_strip,
[email protected]f34706be2012-09-04 07:32:0960 int tab_index,
61 const extensions::Extension* extension);
[email protected]0c9f3262012-09-17 05:59:0662
[email protected]304fd152013-01-12 16:54:4463 // Creates a Tab object but performs no extension permissions checks; the
64 // returned object will contain privacy-sensitive data.
[email protected]0c9f3262012-09-17 05:59:0665 static base::DictionaryValue* CreateTabValue(
[email protected]304fd152013-01-12 16:54:4466 const content::WebContents* web_contents) {
67 return CreateTabValue(web_contents, NULL, -1);
[email protected]0c9f3262012-09-17 05:59:0668 }
69 static base::DictionaryValue* CreateTabValue(
70 const content::WebContents* web_contents,
71 TabStripModel* tab_strip,
[email protected]304fd152013-01-12 16:54:4472 int tab_index);
73
74 // Removes any privacy-sensitive fields from a Tab object if appropriate,
75 // given the permissions of the extension and the tab in question. The
76 // tab_info object is modified in place.
77 static void ScrubTabValueForExtension(const content::WebContents* contents,
78 const extensions::Extension* extension,
79 base::DictionaryValue* tab_info);
[email protected]41d9faf2012-02-28 23:46:0280
[email protected]ea049a02011-12-25 21:37:0981 // Gets the |tab_strip_model| and |tab_index| for the given |web_contents|.
82 static bool GetTabStripModel(const content::WebContents* web_contents,
[email protected]ac84431b2011-09-27 17:26:1183 TabStripModel** tab_strip_model,
84 int* tab_index);
85 static bool GetDefaultTab(Browser* browser,
[email protected]72f67972012-10-30 18:53:2886 content::WebContents** contents,
[email protected]ac84431b2011-09-27 17:26:1187 int* tab_id);
88 // Any out parameter (|browser|, |tab_strip|, |contents|, & |tab_index|) may
89 // be NULL and will not be set within the function.
90 static bool GetTabById(int tab_id, Profile* profile, bool incognito_enabled,
91 Browser** browser,
92 TabStripModel** tab_strip,
[email protected]72f67972012-10-30 18:53:2893 content::WebContents** contents,
[email protected]ac84431b2011-09-27 17:26:1194 int* tab_index);
[email protected]45c75e62012-03-21 19:56:3595
96 // Takes |url_string| and returns a GURL which is either valid and absolute
97 // or invalid. If |url_string| is not directly interpretable as a valid (it is
98 // likely a relative URL) an attempt is made to resolve it. |extension| is
99 // provided so it can be resolved relative to its extension base
100 // (chrome-extension://<id>/). Using the source frame url would be more
101 // correct, but because the api shipped with urls resolved relative to their
102 // extension base, we decided it wasn't worth breaking existing extensions to
103 // fix.
104 static GURL ResolvePossiblyRelativeURL(const std::string& url_string,
[email protected]1c321ee2012-05-21 03:02:34105 const extensions::Extension* extension);
[email protected]45c75e62012-03-21 19:56:35106
107 // Returns true if |url| is used for testing crashes.
108 static bool IsCrashURL(const GURL& url);
[email protected]73c1a6842012-07-13 17:39:04109
110 // Opens a tab for the specified |web_contents|.
111 static void CreateTab(content::WebContents* web_contents,
112 const std::string& extension_id,
113 WindowOpenDisposition disposition,
114 const gfx::Rect& initial_pos,
115 bool user_gesture);
[email protected]44e329a2012-07-14 01:13:06116
117 // Executes the specified callback for all tabs in all browser windows.
118 static void ForEachTab(
119 const base::Callback<void(content::WebContents*)>& callback);
[email protected]e9570fdf2012-07-18 20:01:21120
121 static extensions::WindowController* GetWindowControllerOfTab(
122 const content::WebContents* web_contents);
[email protected]ac84431b2011-09-27 17:26:11123};
124
125#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_UTIL_H__