forked from dart-lang/webdev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchrome_api.dart
356 lines (284 loc) · 7.33 KB
/
chrome_api.dart
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:html';
import 'package:js/js.dart';
@JS()
external Chrome get chrome;
@JS()
@anonymous
class Chrome {
external Debugger get debugger;
external Devtools get devtools;
external Notifications get notifications;
external Runtime get runtime;
external Storage get storage;
external Tabs get tabs;
external WebNavigation get webNavigation;
external Windows get windows;
}
/// chrome.debugger APIs:
/// https://developer.chrome.com/docs/extensions/reference/debugger
@JS()
@anonymous
class Debugger {
external void attach(
Debuggee target, String requiredVersion, Function? callback);
external void detach(Debuggee target, Function? callback);
external void sendCommand(Debuggee target, String method,
Object? commandParams, Function? callback);
external OnDetachHandler get onDetach;
external OnEventHandler get onEvent;
}
@JS()
@anonymous
class OnDetachHandler {
external void addListener(
void Function(Debuggee source, String reason) callback);
}
@JS()
@anonymous
class OnEventHandler {
external void addListener(
void Function(Debuggee source, String method, Object? params) callback);
}
@JS()
@anonymous
class Debuggee {
external int get tabId;
external String get extensionId;
external String get targetId;
external factory Debuggee({int tabId, String? extensionId, String? targetId});
}
/// chrome.devtools APIs:
@JS()
@anonymous
class Devtools {
// https://developer.chrome.com/docs/extensions/reference/devtools_inspectedWindow
external InspectedWindow get inspectedWindow;
// https://developer.chrome.com/docs/extensions/reference/devtools_panels/
external Panels get panels;
}
@JS()
@anonymous
class InspectedWindow {
external int get tabId;
}
@JS()
@anonymous
class Panels {
external String get themeName;
external void create(String title, String iconPath, String pagePath,
void Function(ExtensionPanel)? callback);
}
@JS()
@anonymous
class ExtensionPanel {
external OnHiddenHandler get onHidden;
external OnShownHandler get onShown;
}
@JS()
@anonymous
class OnHiddenHandler {
external void addListener(void Function() callback);
}
@JS()
@anonymous
class OnShownHandler {
external void addListener(void Function(Window window) callback);
}
/// chrome.notification APIs:
/// https://developer.chrome.com/docs/extensions/reference/notifications
@JS()
@anonymous
class Notifications {
external void create(
String? notificationId, NotificationOptions options, Function? callback);
}
@JS()
@anonymous
class NotificationOptions {
external factory NotificationOptions({
String title,
String message,
String iconUrl,
String type,
});
}
/// chrome.runtime APIs:
/// https://developer.chrome.com/docs/extensions/reference/runtime
@JS()
@anonymous
class Runtime {
external void connect(String? extensionId, ConnectInfo info);
external void sendMessage(
String? id, Object? message, Object? options, Function? callback);
external Object getManifest();
external String getURL(String path);
// Note: Not checking the lastError when one occurs throws a runtime exception.
external ChromeError? get lastError;
external ConnectionHandler get onConnect;
external OnMessageHandler get onMessage;
external OnMessageHandler get onMessageExternal;
}
@JS()
class ChromeError {
external String get message;
}
@JS()
@anonymous
class ConnectInfo {
external String? get name;
external factory ConnectInfo({String? name});
}
@JS()
@anonymous
class Port {
external String? get name;
external void disconnect();
external ConnectionHandler get onDisconnect;
}
@JS()
@anonymous
class ConnectionHandler {
external void addListener(void Function(Port) callback);
}
@JS()
@anonymous
class OnMessageHandler {
external void addListener(
void Function(dynamic, MessageSender, Function) callback);
}
@JS()
@anonymous
class MessageSender {
external String? get id;
external Tab? get tab;
external String? get url;
external factory MessageSender({String? id, String? url, Tab? tab});
}
@JS()
@anonymous
class Target {
external int get tabId;
external factory Target({int tabId});
}
/// chrome.storage APIs
/// https://developer.chrome.com/docs/extensions/reference/storage
@JS()
@anonymous
class Storage {
external StorageArea get local;
external StorageArea get session;
external OnChangedHandler get onChanged;
}
@JS()
@anonymous
class StorageArea {
external Object get(List<String> keys, void Function(Object result) callback);
external Object set(Object items, void Function()? callback);
external Object remove(List<String> keys, void Function()? callback);
}
@JS()
@anonymous
class OnChangedHandler {
external void addListener(
void Function(Object changes, String areaName) callback,
);
}
/// chrome.tabs APIs
/// https://developer.chrome.com/docs/extensions/reference/tabs
@JS()
@anonymous
class Tabs {
external dynamic query(
QueryInfo queryInfo, void Function(List<Tab>) callback);
external dynamic create(TabInfo tabInfo, void Function(Tab) callback);
external dynamic get(int tabId, void Function(Tab?) callback);
external dynamic remove(int tabId, void Function()? callback);
external OnActivatedHandler get onActivated;
external OnRemovedHandler get onRemoved;
}
@JS()
@anonymous
class OnActivatedHandler {
external void addListener(void Function(ActiveInfo activeInfo) callback);
}
@JS()
@anonymous
class OnRemovedHandler {
external void addListener(void Function(int tabId, dynamic info) callback);
}
@JS()
@anonymous
class ActiveInfo {
external int get tabId;
}
@JS()
@anonymous
class TabInfo {
external bool? get active;
external bool? get pinned;
external String? get url;
external factory TabInfo({bool? active, bool? pinned, String? url});
}
@JS()
@anonymous
class QueryInfo {
external bool get active;
external bool get currentWindow;
external String get url;
external factory QueryInfo({bool? active, bool? currentWindow, String? url});
}
@JS()
@anonymous
class Tab {
external int get id;
external String get url;
}
/// chrome.webNavigation APIs
/// https://developer.chrome.com/docs/extensions/reference/webNavigation
@JS()
@anonymous
class WebNavigation {
// https://developer.chrome.com/docs/extensions/reference/webNavigation/#event-onCommitted
external OnCommittedHandler get onCommitted;
}
@JS()
@anonymous
class OnCommittedHandler {
external void addListener(void Function(NavigationInfo details) callback);
}
@JS()
@anonymous
class NavigationInfo {
external String get transitionType;
external int get tabId;
external String get url;
}
/// chrome.windows APIs
/// https://developer.chrome.com/docs/extensions/reference/windows
@JS()
@anonymous
class Windows {
external dynamic create(WindowInfo? createData, Function(WindowObj) callback);
external OnFocusChangedHandler get onFocusChanged;
}
@JS()
@anonymous
class OnFocusChangedHandler {
external void addListener(void Function(int windowId) callback);
}
@JS()
@anonymous
class WindowInfo {
external bool? get focused;
external String? get url;
external factory WindowInfo({bool? focused, String? url});
}
@JS()
@anonymous
class WindowObj {
external int get id;
external List<Tab> get tabs;
}