/
tabs_api.h
122 lines (86 loc) · 3.16 KB
/
tabs_api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// 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.
#ifndef ELECTRON_SHELL_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_
#define ELECTRON_SHELL_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_
#include <string>
#include "extensions/browser/api/execute_code_function.h"
#include "extensions/browser/extension_function.h"
#include "extensions/common/extension_resource.h"
class GURL;
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;
bool ShouldRemoveCSS() const override;
private:
~TabsExecuteScriptFunction() override {}
DECLARE_EXTENSION_FUNCTION("tabs.executeScript", TABS_EXECUTESCRIPT)
};
class TabsReloadFunction : public ExtensionFunction {
~TabsReloadFunction() override {}
ResponseAction Run() override;
DECLARE_EXTENSION_FUNCTION("tabs.reload", TABS_RELOAD)
};
class TabsGetFunction : public ExtensionFunction {
~TabsGetFunction() override {}
ResponseAction Run() override;
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)
};
class TabsUpdateFunction : public ExtensionFunction {
public:
TabsUpdateFunction();
protected:
~TabsUpdateFunction() override {}
bool UpdateURL(const std::string& url, int tab_id, std::string* error);
ResponseValue GetResult();
content::WebContents* web_contents_;
private:
ResponseAction Run() override;
void OnExecuteCodeFinished(const std::string& error,
const GURL& on_url,
const base::ListValue& script_result);
DECLARE_EXTENSION_FUNCTION("tabs.update", TABS_UPDATE)
};
} // namespace extensions
#endif // ELECTRON_SHELL_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_