forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsafari-extension.d.ts
457 lines (380 loc) · 13.5 KB
/
safari-extension.d.ts
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
// Type definitions for Safari extension development
// Project: https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009977-CH1-SW1
// Definitions by: Luuk <https://github.com/luukd>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface Window {
safari: typeof safari;
}
declare namespace safari {
export var application: SafariApplication;
export var extension: SafariExtension;
export var self: SafariExtensionGlobalPage | SafariExtensionBar;
}
interface SafariEvent {
/**
* The type of the event.
* The string used to identify a particular type of event is documented in the reference for that class.
*/
type: string;
/**
* The target of the event.
* This attribute stays the same as the event moves through the event-dispatch hierarchy. Its value is the same as the object that the event is sent to during the targeting phase.
*/
target: SafariEventTarget;
/**
* The object that the event is currently being sent to.
* This attribute varies as the event progresses through the phases, changing as the event moves through the event-dispatch hierarchy.
*/
currentTarget: SafariEventTarget;
/**
* The time and date that the event was created.
*/
timestamp: number;
/**
* The event-handling phase that the event is in.
* The values for this property are the same as the values used by Webkit to identify the event-handling phases.
*/
eventPhase: number;
/**
* A Boolean value that indicates whether the event goes through the bubbling phase.
*/
bubbles: boolean;
/**
* A Boolean value that indicates whether the event can be canceled.
*/
cancelable: boolean;
/**
* A Boolean value that indicates whether the event’s default action has been prevented.
*/
defaultPrevented: boolean;
/**
* Prevents the event from any further propagation.
* Propagation can be stopped only fon cancelable events. After propagation is stopped, the event is not sent to any other targets.
*/
stopPropagation() : void;
/**
* Prevents the browser from performing the default action for an event.
* Use this method to indicate that your extension has already fully handled the event; you don’t want the browser to do anything. Note that preventing the default action does not stop an event from propagating.
*/
preventDefault(): void;
}
interface SafariEventListener extends Function {
(event: SafariEvent): any;
}
interface SafariEventTarget {
addEventListener(type: string, listener: SafariEventListener, useCapture?: boolean): void;
removeEventListener(type: string, listener: SafariEventListener, useCapture?: boolean): void;
}
interface SafariBrowserWindow extends SafariEventTarget {
tabs: Array<SafariBrowserTab>;
visible: boolean;
activeTab: SafariBrowserTab;
activate(): void;
close(): void;
/**
* Opens a new tab in the window.
* Available in Safari 5.0 and later.
* @param visibility Either foreground if the tab should be opened in the foreground, or background if it should be opened in the background.
* @param index The desired location of the new tab.
* @returns A new tab.
*/
openTab (visibility?: string, index?: number): SafariBrowserTab;
insertTab(tab: SafariBrowserTab, index: number): SafariBrowserTab;
}
interface SafariBrowserTab extends SafariEventTarget {
browserWindow: SafariBrowserWindow;
reader: SafariReader;
/**
* The tab’s current title.
* The tab’s title is the same as the title of the webpage in most cases. For example, the title of the webpage may be truncated for display, but the value of this property is not truncated.
* Available in Safari 5.0 and later.
*/
title: string;
page: SafariWebPageProxy;
/**
* The URL loaded in this tab.
* Setting this attribute to a new value loads the page at the new URL in the tab.
* Available in Safari 5.0 and later.
*/
url: string;
visibleContentsAsDataURL(): string;
activate(): void;
close(): void;
}
interface SafariReader extends SafariEventTarget {
available: boolean;
tab: SafariBrowserTab;
visible: boolean;
enter(): void;
exit(): void;
dispatchMessage (name: string, message?: any): void;
}
interface SafariWebPageProxy {
dispatchMessage (name: string, message?: any): void;
}
interface SafariExtensionGlobalPage {
contentWindow: Window;
}
interface SafariExtensionPopover extends SafariEventTarget {
identifier: string;
visible: boolean;
contentWindow: Window;
height: number;
width: number;
hide(): void;
}
interface SafariExtensionMenu {
identifier: string;
menuItems: Array<SafariExtensionMenuItem>;
visible: boolean;
appendMenuItem (identifier: string, title: string, command?: string): SafariExtensionMenuItem;
appendSeparator (identifier: string): SafariExtensionMenuItem;
insertMenuItem (index: number, identifier: string, title: string, command?: string): SafariExtensionMenuItem;
insertSeparator (index: number, identifier: string): SafariExtensionMenuItem;
removeMenuItem (index: number): void;
}
interface SafariExtensionMenuItem extends SafariEventTarget {
command: string;
identifier: string;
separator: boolean;
title: string;
image: string;
submenu: SafariExtensionMenu;
visible: boolean;
disabled: boolean;
checkedState: number;
}
interface SafariExtensionSettings extends SafariEventTarget {
[index: string]: any;
[index: number]: any;
getItem(key: string): any;
setItem(key: string, value: any): void;
removeItem(key: string): void;
clear(): void;
}
interface SafariExtensionSecureSettings extends SafariEventTarget {
[index: string]: any;
getItem(key: string): any;
setItem(key: string, value: any): void;
removeItem(key: string): void;
clear(): void;
}
interface SafariExtensionBar extends SafariEventTarget {
identifier: string;
label: string;
visible: boolean;
browserWindow: SafariBrowserWindow;
contentWindow: Window;
hide(doNotRemember?: boolean): void;
show(doNotRemember?: boolean): void;
}
interface SafariExtensionToolbarItem extends SafariEventTarget {
/**
* The current badge number.
*/
badge: number;
/**
* The URL of the current image.
*/
image: string;
/**
* The label of the toolbar item, as shown in the toolbar’s overflow menu.
*/
label: string;
/**
* The label of the toolbar item, as shown in the Customize palette.
* This attribute is optional; its value defaults to the value of label.
*/
paletteLabel: string;
/**
* The tooltip (help tag) of the toolbar item.
* This attribute is optional; its value defaults to the value of label.
*/
toolTip: string;
menu: SafariExtensionMenu;
popover: SafariExtensionPopover;
browserWindow: SafariBrowserWindow;
command: string;
disabled: boolean;
identifier: string;
showMenu(): void;
showPopover(): void;
validate(): void;
}
interface SafariPrivateBrowsing {
enabled: boolean;
}
interface SafariExtension {
bars: Array<SafariExtensionBar>;
baseURI: string;
globalPage: SafariExtensionGlobalPage;
toolbarItems: Array<SafariExtensionToolbarItem>;
displayVersion: string;
bundleVersion: string;
menus: Array<SafariExtensionMenu>;
createMenu (identifier: string): SafariExtensionMenu;
removeMenu (identifier: string): void;
popovers: Array<SafariExtensionPopover>;
createPopover(identifier: string, url: string, width?: number, height?: number): SafariExtensionPopover;
removePopover(identifier: string): void;
addContentScript (source: string, whitelist: Array<string>, blacklist: Array<string>, runAtEnd: boolean): string;
addContentScriptFromURL (url: string, whitelist: Array<string>, blacklist: Array<string>, runAtEnd: boolean): string;
addContentStyleSheet (source: string, whitelist: Array<string>, blacklist: Array<string>): string;
addContentStyleSheetFromURL (url: string, whitelist: Array<string>, blacklist: Array<string>): string;
removeContentScript(url: string): void;
removeContentScripts(): void;
removeContentStyleSheet(url: string): void;
removeContentStyleSheets(): void;
settings: SafariExtensionSettings;
secureSettings: SafariExtensionSecureSettings;
}
interface SafariApplication extends SafariEventTarget {
activeBrowserWindow: SafariBrowserWindow;
browserWindows: Array<SafariBrowserWindow>;
privateBrowsing: SafariPrivateBrowsing;
openBrowserWindow(): SafariBrowserWindow;
}
interface SafariExtensionContextMenuEvent extends SafariEvent {
/**
* The target of the event.
* This attribute stays the same as the event moves through the event-dispatch hierarchy. Its value is the same as the object that the event is sent to during the targeting phase.
*/
target: SafariExtensionContextMenuItem;
/**
* The object that the event is currently being sent to.
* This attribute varies as the event progresses through the phases, changing as the event moves through the event-dispatch hierarchy.
*/
currentTarget: SafariExtensionContextMenuItem;
/**
* Information about the current context menu event.
*/
userInfo: any;
/**
* The context menu being built up.
*/
contextMenu: SafariExtensionContextMenu;
}
interface SafariExtensionContextMenu {
/**
* Returns a list of the context menu items from this extension.
* Only menu items from your extension are returned.
*/
contextMenuItems: any[];
/**
* Appends a menu item to the contextual menu.
* If another menu item with the same identifier already exists, it is removed before appending the menu item. If command is not supplied, identifier is used as the command identifier.
* @param identifier The unique identifier of the menu item.
* @param title The title of the menu item.
* @param command The command identifier that the context menu item sends when activated.
* @returns The context menu item that was appended.
*/
appendContextMenuItem (identifier: string, title: string, command?: string) : SafariExtensionContextMenuItem;
/**
* Inserts a menu item at a specific index in the contextual menu.
* If another menu item with the same identifier already exists, it is removed before appending the menu item. If command is not supplied, identifier is used as the command identifier.
* @param index The index where the menu item is being inserted.
* @param identifier The unique identifier of the menu item.
* @param title The title of the menu item.
* @param command The command identifier that the context menu item sends when activated.
* @returns The context menu item that was inserted.
*/
insertContextMenuItem (index: number, identifier: string, title: string, command?: string): SafariExtensionContextMenuItem;
}
interface SafariExtensionContextMenuItem extends SafariEventTarget {
/**
* The command identifier that the context menu item sends when activated.
* Setting an empty string, null, or undefined has no effect.
*/
command: string;
/**
* A Boolean value that indicates whether a context menu item is disabled.
* Disabled menu items are not displayed in the context menu.
*/
disabled: boolean;
/**
* The unique identifier of the context menu item.
*/
identifier: string;
/**
* The title displayed in the context menu.
*/
title: string;
}
interface SafariValidateEvent extends SafariEvent {
/**
* The command identifier of the target being validated.
*/
command: string;
}
interface SafariExtensionContextMenuItemValidateEvent {
/**
* The target of the event.
* This attribute stays the same as the event moves through the event-dispatch hierarchy. Its value is the same as the object that the event is sent to during the targeting phase.
*/
target: SafariExtensionContextMenuItem;
/**
* The object that the event is currently being sent to.
* This attribute varies as the event progresses through the phases, changing as the event moves through the event-dispatch hierarchy.
*/
currentTarget: SafariExtensionContextMenuItem;
/**
* Information about the current context menu event.
*/
userInfo: any;
}
interface SafariCommandEvent extends SafariEvent {
/**
* The command identifier of the target being dispatched.
*/
command: string;
}
interface SafariExtensionContextMenuItemCommandEvent extends SafariCommandEvent {
/**
* The target of the event.
* This attribute stays the same as the event moves through the event-dispatch hierarchy. Its value is the same as the object that the event is sent to during the targeting phase.
*/
target: SafariExtensionContextMenuItem;
/**
* The object that the event is currently being sent to.
* This attribute varies as the event progresses through the phases, changing as the event moves through the event-dispatch hierarchy.
*/
currentTarget: SafariExtensionContextMenuItem;
/**
* The user info object for this context menu event.
*/
userInfo: any;
}
interface SafariExtensionSettingsChangeEvent extends SafariEvent {
/**
* The target of the event.
* This attribute stays the same as the event moves through the event-dispatch hierarchy. Its value is the same as the object that the event is sent to during the targeting phase.
*/
target: SafariExtensionSettings|SafariExtensionSecureSettings;
/**
* The object that the event is currently being sent to.
* This attribute varies as the event progresses through the phases, changing as the event moves through the event-dispatch hierarchy.
*/
currentTarget: SafariExtensionSettings|SafariExtensionSecureSettings;
/**
* The key identifier of the setting that was changed.
*/
key: string;
/**
* The value before the settings change.
*/
oldValue: any;
/**
* The value after the settings change.
*/
newValue: any;
}
interface SafariExtensionMessageEvent extends SafariEvent {
/**
* The name of the message.
*/
name: string;
/**
* The message data.
*/
message: any;
}