Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / extensions / api / tabs / tabs_api.h
blobb398e70c10d922a5d580e57890fb54a6e511300c
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_
8 #include <string>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/extensions/chrome_extension_function.h"
13 #include "chrome/browser/extensions/chrome_extension_function_details.h"
14 #include "chrome/common/extensions/api/tabs.h"
15 #include "components/ui/zoom/zoom_controller.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
18 #include "extensions/browser/api/capture_web_contents_function.h"
19 #include "extensions/browser/api/execute_code_function.h"
20 #include "extensions/common/extension_resource.h"
21 #include "extensions/common/user_script.h"
22 #include "url/gurl.h"
24 class GURL;
25 class SkBitmap;
26 class TabStripModel;
28 namespace base {
29 class DictionaryValue;
32 namespace content {
33 class WebContents;
36 namespace ui {
37 class ListSelectionModel;
40 namespace user_prefs {
41 class PrefRegistrySyncable;
44 namespace extensions {
46 // Converts a ZoomMode to its ZoomSettings representation.
47 void ZoomModeToZoomSettings(ui_zoom::ZoomController::ZoomMode zoom_mode,
48 api::tabs::ZoomSettings* zoom_settings);
50 // Windows
51 class WindowsGetFunction : public ChromeSyncExtensionFunction {
52 ~WindowsGetFunction() override {}
53 bool RunSync() override;
54 DECLARE_EXTENSION_FUNCTION("windows.get", WINDOWS_GET)
56 class WindowsGetCurrentFunction : public ChromeSyncExtensionFunction {
57 ~WindowsGetCurrentFunction() override {}
58 bool RunSync() override;
59 DECLARE_EXTENSION_FUNCTION("windows.getCurrent", WINDOWS_GETCURRENT)
61 class WindowsGetLastFocusedFunction : public ChromeSyncExtensionFunction {
62 ~WindowsGetLastFocusedFunction() override {}
63 bool RunSync() override;
64 DECLARE_EXTENSION_FUNCTION("windows.getLastFocused", WINDOWS_GETLASTFOCUSED)
66 class WindowsGetAllFunction : public ChromeSyncExtensionFunction {
67 ~WindowsGetAllFunction() override {}
68 bool RunSync() override;
69 DECLARE_EXTENSION_FUNCTION("windows.getAll", WINDOWS_GETALL)
71 class WindowsCreateFunction : public ChromeSyncExtensionFunction {
72 ~WindowsCreateFunction() override {}
73 bool RunSync() override;
74 // Returns whether the window should be created in incognito mode.
75 // |create_data| are the options passed by the extension. It may be NULL.
76 // |urls| is the list of urls to open. If we are creating an incognito window,
77 // the function will remove these urls which may not be opened in incognito
78 // mode. If window creation leads the browser into an erroneous state,
79 // |is_error| is set to true (also, error_ member variable is assigned
80 // the proper error message).
81 bool ShouldOpenIncognitoWindow(
82 const api::windows::Create::Params::CreateData* create_data,
83 std::vector<GURL>* urls,
84 bool* is_error);
85 DECLARE_EXTENSION_FUNCTION("windows.create", WINDOWS_CREATE)
87 class WindowsUpdateFunction : public ChromeSyncExtensionFunction {
88 ~WindowsUpdateFunction() override {}
89 bool RunSync() override;
90 DECLARE_EXTENSION_FUNCTION("windows.update", WINDOWS_UPDATE)
92 class WindowsRemoveFunction : public ChromeSyncExtensionFunction {
93 ~WindowsRemoveFunction() override {}
94 bool RunSync() override;
95 DECLARE_EXTENSION_FUNCTION("windows.remove", WINDOWS_REMOVE)
98 // Tabs
99 class TabsGetFunction : public ChromeSyncExtensionFunction {
100 ~TabsGetFunction() override {}
101 bool RunSync() override;
102 DECLARE_EXTENSION_FUNCTION("tabs.get", TABS_GET)
104 class TabsGetCurrentFunction : public ChromeSyncExtensionFunction {
105 ~TabsGetCurrentFunction() override {}
106 bool RunSync() override;
107 DECLARE_EXTENSION_FUNCTION("tabs.getCurrent", TABS_GETCURRENT)
109 class TabsGetSelectedFunction : public ChromeSyncExtensionFunction {
110 ~TabsGetSelectedFunction() override {}
111 bool RunSync() override;
112 DECLARE_EXTENSION_FUNCTION("tabs.getSelected", TABS_GETSELECTED)
114 class TabsGetAllInWindowFunction : public ChromeSyncExtensionFunction {
115 ~TabsGetAllInWindowFunction() override {}
116 bool RunSync() override;
117 DECLARE_EXTENSION_FUNCTION("tabs.getAllInWindow", TABS_GETALLINWINDOW)
119 class TabsQueryFunction : public ChromeSyncExtensionFunction {
120 ~TabsQueryFunction() override {}
121 bool RunSync() override;
122 DECLARE_EXTENSION_FUNCTION("tabs.query", TABS_QUERY)
124 class TabsCreateFunction : public ChromeSyncExtensionFunction {
125 ~TabsCreateFunction() override {}
126 bool RunSync() override;
127 DECLARE_EXTENSION_FUNCTION("tabs.create", TABS_CREATE)
129 class TabsDuplicateFunction : public ChromeSyncExtensionFunction {
130 ~TabsDuplicateFunction() override {}
131 bool RunSync() override;
132 DECLARE_EXTENSION_FUNCTION("tabs.duplicate", TABS_DUPLICATE)
134 class TabsHighlightFunction : public ChromeSyncExtensionFunction {
135 ~TabsHighlightFunction() override {}
136 bool RunSync() override;
137 bool HighlightTab(TabStripModel* tabstrip,
138 ui::ListSelectionModel* selection,
139 int *active_index,
140 int index);
141 DECLARE_EXTENSION_FUNCTION("tabs.highlight", TABS_HIGHLIGHT)
143 class TabsUpdateFunction : public ChromeAsyncExtensionFunction {
144 public:
145 TabsUpdateFunction();
147 protected:
148 ~TabsUpdateFunction() override {}
149 virtual bool UpdateURL(const std::string& url,
150 int tab_id,
151 bool* is_async);
152 virtual void PopulateResult();
154 content::WebContents* web_contents_;
156 private:
157 bool RunAsync() override;
158 void OnExecuteCodeFinished(const std::string& error,
159 const GURL& on_url,
160 const base::ListValue& script_result);
162 DECLARE_EXTENSION_FUNCTION("tabs.update", TABS_UPDATE)
164 class TabsMoveFunction : public ChromeSyncExtensionFunction {
165 ~TabsMoveFunction() override {}
166 bool RunSync() override;
167 bool MoveTab(int tab_id,
168 int* new_index,
169 int iteration,
170 base::ListValue* tab_values,
171 int* window_id);
172 DECLARE_EXTENSION_FUNCTION("tabs.move", TABS_MOVE)
174 class TabsReloadFunction : public ChromeSyncExtensionFunction {
175 ~TabsReloadFunction() override {}
176 bool RunSync() override;
177 DECLARE_EXTENSION_FUNCTION("tabs.reload", TABS_RELOAD)
179 class TabsRemoveFunction : public ChromeSyncExtensionFunction {
180 ~TabsRemoveFunction() override {}
181 bool RunSync() override;
182 bool RemoveTab(int tab_id);
183 DECLARE_EXTENSION_FUNCTION("tabs.remove", TABS_REMOVE)
185 class TabsDetectLanguageFunction : public ChromeAsyncExtensionFunction,
186 public content::NotificationObserver {
187 private:
188 ~TabsDetectLanguageFunction() override {}
189 bool RunAsync() override;
191 void Observe(int type,
192 const content::NotificationSource& source,
193 const content::NotificationDetails& details) override;
194 void GotLanguage(const std::string& language);
195 content::NotificationRegistrar registrar_;
196 DECLARE_EXTENSION_FUNCTION("tabs.detectLanguage", TABS_DETECTLANGUAGE)
198 class TabsCaptureVisibleTabFunction
199 : public extensions::CaptureWebContentsFunction {
200 public:
201 TabsCaptureVisibleTabFunction();
202 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
204 protected:
205 ~TabsCaptureVisibleTabFunction() override {}
207 private:
208 ChromeExtensionFunctionDetails chrome_details_;
210 // extensions::CaptureWebContentsFunction:
211 bool IsScreenshotEnabled() override;
212 content::WebContents* GetWebContentsForID(int id) override;
213 void OnCaptureFailure(FailureReason reason) override;
215 DECLARE_EXTENSION_FUNCTION("tabs.captureVisibleTab", TABS_CAPTUREVISIBLETAB)
218 // Implement API call tabs.executeScript and tabs.insertCSS.
219 class ExecuteCodeInTabFunction : public ExecuteCodeFunction {
220 public:
221 ExecuteCodeInTabFunction();
223 protected:
224 ~ExecuteCodeInTabFunction() override;
226 // ExtensionFunction:
227 bool HasPermission() override;
229 // Initialize the |execute_tab_id_| and |details_| if they haven't already
230 // been. Returns whether initialization was successful.
231 bool Init() override;
232 bool CanExecuteScriptOnPage() override;
233 ScriptExecutor* GetScriptExecutor() override;
234 bool IsWebView() const override;
235 const GURL& GetWebViewSrc() const override;
237 private:
238 const ChromeExtensionFunctionDetails chrome_details_;
240 // Id of tab which executes code.
241 int execute_tab_id_;
244 class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction {
245 protected:
246 bool ShouldInsertCSS() const override;
248 private:
249 ~TabsExecuteScriptFunction() override {}
251 void OnExecuteCodeFinished(const std::string& error,
252 const GURL& on_url,
253 const base::ListValue& script_result) override;
255 DECLARE_EXTENSION_FUNCTION("tabs.executeScript", TABS_EXECUTESCRIPT)
258 class TabsInsertCSSFunction : public ExecuteCodeInTabFunction {
259 private:
260 ~TabsInsertCSSFunction() override {}
262 bool ShouldInsertCSS() const override;
264 DECLARE_EXTENSION_FUNCTION("tabs.insertCSS", TABS_INSERTCSS)
267 class ZoomAPIFunction : public ChromeAsyncExtensionFunction {
268 protected:
269 ~ZoomAPIFunction() override {}
271 // Gets the WebContents for |tab_id| if it is specified. Otherwise get the
272 // WebContents for the active tab in the current window. Calling this function
273 // may set error_.
275 // TODO(...) many other tabs API functions use similar behavior. There should
276 // be a way to share this implementation somehow.
277 content::WebContents* GetWebContents(int tab_id);
280 class TabsSetZoomFunction : public ZoomAPIFunction {
281 private:
282 ~TabsSetZoomFunction() override {}
284 bool RunAsync() override;
286 DECLARE_EXTENSION_FUNCTION("tabs.setZoom", TABS_SETZOOM)
289 class TabsGetZoomFunction : public ZoomAPIFunction {
290 private:
291 ~TabsGetZoomFunction() override {}
293 bool RunAsync() override;
295 DECLARE_EXTENSION_FUNCTION("tabs.getZoom", TABS_GETZOOM)
298 class TabsSetZoomSettingsFunction : public ZoomAPIFunction {
299 private:
300 ~TabsSetZoomSettingsFunction() override {}
302 bool RunAsync() override;
304 DECLARE_EXTENSION_FUNCTION("tabs.setZoomSettings", TABS_SETZOOMSETTINGS)
307 class TabsGetZoomSettingsFunction : public ZoomAPIFunction {
308 private:
309 ~TabsGetZoomSettingsFunction() override {}
311 bool RunAsync() override;
313 DECLARE_EXTENSION_FUNCTION("tabs.getZoomSettings", TABS_GETZOOMSETTINGS)
316 } // namespace extensions
318 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_