| 
									
										
										
										
											2020-01-15 15:11:51 -08:00
										 |  |  | // Copyright (c) 2019 Slack Technologies, Inc.
 | 
					
						
							|  |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							|  |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 08:34:31 +01:00
										 |  |  | #ifndef ELECTRON_SHELL_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_
 | 
					
						
							|  |  |  | #define ELECTRON_SHELL_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_
 | 
					
						
							| 
									
										
										
										
											2020-01-15 15:11:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-11 16:07:39 -04:00
										 |  |  | #include "base/memory/raw_ptr.h"
 | 
					
						
							| 
									
										
										
										
											2020-01-15 15:11:51 -08:00
										 |  |  | #include "extensions/browser/api/execute_code_function.h"
 | 
					
						
							|  |  |  | #include "extensions/browser/extension_function.h"
 | 
					
						
							|  |  |  | #include "extensions/common/extension_resource.h"
 | 
					
						
							| 
									
										
										
										
											2021-07-01 17:51:37 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | class GURL; | 
					
						
							| 
									
										
										
										
											2020-01-15 15:11:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace extensions { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Implement API call tabs.executeScript and tabs.insertCSS.
 | 
					
						
							|  |  |  | class ExecuteCodeInTabFunction : public ExecuteCodeFunction { | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   ExecuteCodeInTabFunction(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  protected: | 
					
						
							|  |  |  |   ~ExecuteCodeInTabFunction() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Initializes |execute_tab_id_| and |details_|.
 | 
					
						
							|  |  |  |   InitResult Init() override; | 
					
						
							|  |  |  |   bool CanExecuteScriptOnPage(std::string* error) override; | 
					
						
							|  |  |  |   ScriptExecutor* GetScriptExecutor(std::string* error) override; | 
					
						
							|  |  |  |   bool IsWebView() const override; | 
					
						
							|  |  |  |   const GURL& GetWebViewSrc() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  private: | 
					
						
							|  |  |  |   // Id of tab which executes code.
 | 
					
						
							|  |  |  |   int execute_tab_id_; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction { | 
					
						
							|  |  |  |  protected: | 
					
						
							|  |  |  |   bool ShouldInsertCSS() const override; | 
					
						
							| 
									
										
										
										
											2020-10-15 18:30:41 -07:00
										 |  |  |   bool ShouldRemoveCSS() const override; | 
					
						
							| 
									
										
										
										
											2020-01-15 15:11:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |  private: | 
					
						
							|  |  |  |   ~TabsExecuteScriptFunction() override {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DECLARE_EXTENSION_FUNCTION("tabs.executeScript", TABS_EXECUTESCRIPT) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-11 22:51:10 +02:00
										 |  |  | class TabsReloadFunction : public ExtensionFunction { | 
					
						
							|  |  |  |   ~TabsReloadFunction() override {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ResponseAction Run() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DECLARE_EXTENSION_FUNCTION("tabs.reload", TABS_RELOAD) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 14:47:19 +02:00
										 |  |  | class TabsQueryFunction : public ExtensionFunction { | 
					
						
							|  |  |  |   ~TabsQueryFunction() override {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ResponseAction Run() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DECLARE_EXTENSION_FUNCTION("tabs.query", TABS_QUERY) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-12 16:39:12 -08:00
										 |  |  | class TabsGetFunction : public ExtensionFunction { | 
					
						
							|  |  |  |   ~TabsGetFunction() override {} | 
					
						
							| 
									
										
										
										
											2022-04-11 22:51:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-12 16:39:12 -08:00
										 |  |  |   ResponseAction Run() override; | 
					
						
							| 
									
										
										
										
											2022-04-11 22:51:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-12 16:39:12 -08:00
										 |  |  |   DECLARE_EXTENSION_FUNCTION("tabs.get", TABS_GET) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TabsSetZoomFunction : public ExtensionFunction { | 
					
						
							|  |  |  |  private: | 
					
						
							|  |  |  |   ~TabsSetZoomFunction() override {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ResponseAction Run() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DECLARE_EXTENSION_FUNCTION("tabs.setZoom", TABS_SETZOOM) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TabsGetZoomFunction : public ExtensionFunction { | 
					
						
							|  |  |  |  private: | 
					
						
							|  |  |  |   ~TabsGetZoomFunction() override {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ResponseAction Run() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DECLARE_EXTENSION_FUNCTION("tabs.getZoom", TABS_GETZOOM) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TabsSetZoomSettingsFunction : public ExtensionFunction { | 
					
						
							|  |  |  |  private: | 
					
						
							|  |  |  |   ~TabsSetZoomSettingsFunction() override {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ResponseAction Run() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DECLARE_EXTENSION_FUNCTION("tabs.setZoomSettings", TABS_SETZOOMSETTINGS) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TabsGetZoomSettingsFunction : public ExtensionFunction { | 
					
						
							|  |  |  |  private: | 
					
						
							|  |  |  |   ~TabsGetZoomSettingsFunction() override {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ResponseAction Run() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DECLARE_EXTENSION_FUNCTION("tabs.getZoomSettings", TABS_GETZOOMSETTINGS) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-27 13:36:22 -07:00
										 |  |  | class TabsUpdateFunction : public ExtensionFunction { | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   TabsUpdateFunction(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  protected: | 
					
						
							|  |  |  |   ~TabsUpdateFunction() override {} | 
					
						
							|  |  |  |   bool UpdateURL(const std::string& url, int tab_id, std::string* error); | 
					
						
							|  |  |  |   ResponseValue GetResult(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-11 16:07:39 -04:00
										 |  |  |   raw_ptr<content::WebContents> web_contents_; | 
					
						
							| 
									
										
										
										
											2021-07-27 13:36:22 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |  private: | 
					
						
							|  |  |  |   ResponseAction Run() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DECLARE_EXTENSION_FUNCTION("tabs.update", TABS_UPDATE) | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-01-15 15:11:51 -08:00
										 |  |  | }  // namespace extensions
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 08:34:31 +01:00
										 |  |  | #endif  // ELECTRON_SHELL_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_
 |