forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownloads.idl
569 lines (468 loc) · 22.8 KB
/
downloads.idl
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Use the <code>chrome.downloads</code> API to programmatically initiate,
// monitor, manipulate, and search for downloads.
[permissions=downloads]
namespace downloads {
[inline_doc] dictionary HeaderNameValuePair {
// Name of the HTTP header.
DOMString name;
// Value of the HTTP header.
DOMString value;
};
// <dl><dt>uniquify</dt>
// <dd>To avoid duplication, the <code>filename</code> is changed to
// include a counter before the filename extension.</dd>
// <dt>overwrite</dt>
// <dd>The existing file will be overwritten with the new file.</dd>
// <dt>prompt</dt>
// <dd>The user will be prompted with a file chooser dialog.</dd>
// </dl>
enum FilenameConflictAction {uniquify, overwrite, prompt};
[inline_doc] dictionary FilenameSuggestion {
// The $(ref:DownloadItem)'s new target $(ref:DownloadItem.filename), as a path
// relative to the user's default Downloads directory, possibly containing
// subdirectories. Absolute paths, empty paths, and paths containing
// back-references ".." will be ignored.
DOMString filename;
// The action to take if <code>filename</code> already exists.
FilenameConflictAction? conflictAction;
};
[inline_doc] enum HttpMethod {GET, POST};
enum InterruptReason {
FILE_FAILED,
FILE_ACCESS_DENIED,
FILE_NO_SPACE,
FILE_NAME_TOO_LONG,
FILE_TOO_LARGE,
FILE_VIRUS_INFECTED,
FILE_TRANSIENT_ERROR,
FILE_BLOCKED,
FILE_SECURITY_CHECK_FAILED,
FILE_TOO_SHORT,
FILE_HASH_MISMATCH,
FILE_SAME_AS_SOURCE,
NETWORK_FAILED,
NETWORK_TIMEOUT,
NETWORK_DISCONNECTED,
NETWORK_SERVER_DOWN,
NETWORK_INVALID_REQUEST,
SERVER_FAILED,
SERVER_NO_RANGE,
SERVER_BAD_CONTENT,
SERVER_UNAUTHORIZED,
SERVER_CERT_PROBLEM,
SERVER_FORBIDDEN,
SERVER_UNREACHABLE,
SERVER_CONTENT_LENGTH_MISMATCH,
SERVER_CROSS_ORIGIN_REDIRECT,
USER_CANCELED,
USER_SHUTDOWN,
CRASH};
[inline_doc] dictionary DownloadOptions {
// The URL to download.
DOMString url;
// A file path relative to the Downloads directory to contain the downloaded
// file, possibly containing subdirectories. Absolute paths, empty paths,
// and paths containing back-references ".." will cause an error.
// $(ref:onDeterminingFilename) allows suggesting a filename after the file's
// MIME type and a tentative filename have been determined.
DOMString? filename;
// The action to take if <code>filename</code> already exists.
FilenameConflictAction? conflictAction;
// Use a file-chooser to allow the user to select a filename regardless of
// whether <code>filename</code> is set or already exists.
boolean? saveAs;
// The HTTP method to use if the URL uses the HTTP[S] protocol.
HttpMethod? method;
// Extra HTTP headers to send with the request if the URL uses the HTTP[s]
// protocol. Each header is represented as a dictionary containing the keys
// <code>name</code> and either <code>value</code> or
// <code>binaryValue</code>, restricted to those allowed by XMLHttpRequest.
HeaderNameValuePair[]? headers;
// Post body.
DOMString? body;
};
// <dl><dt>file</dt>
// <dd>The download's filename is suspicious.</dd>
// <dt>url</dt>
// <dd>The download's URL is known to be malicious.</dd>
// <dt>content</dt>
// <dd>The downloaded file is known to be malicious.</dd>
// <dt>uncommon</dt>
// <dd>The download's URL is not commonly downloaded and could be
// dangerous.</dd>
// <dt>host</dt>
// <dd>The download came from a host known to distribute malicious
// binaries and is likely dangerous.</dd>
// <dt>unwanted</dt>
// <dd>The download is potentially unwanted or unsafe. E.g. it could make
// changes to browser or computer settings.</dd>
// <dt>safe</dt>
// <dd>The download presents no known danger to the user's computer.</dd>
// <dt>accepted</dt>
// <dd>The user has accepted the dangerous download.</dd>
// </dl>
enum DangerType {
file, url, content, uncommon, host, unwanted, safe, accepted
};
// <dl><dt>in_progress</dt>
// <dd>The download is currently receiving data from the server.</dd>
// <dt>interrupted</dt>
// <dd>An error broke the connection with the file host.</dd>
// <dt>complete</dt>
// <dd>The download completed successfully.</dd>
// </dl>
enum State {in_progress, interrupted, complete};
// The state of the process of downloading a file.
dictionary DownloadItem {
// An identifier that is persistent across browser sessions.
long id;
// The absolute URL that this download initiated from, before any
// redirects.
DOMString url;
// The absolute URL that this download is being made from, after all
// redirects.
DOMString finalUrl;
// Absolute URL.
DOMString referrer;
// Absolute local path.
DOMString filename;
// False if this download is recorded in the history, true if it is not
// recorded.
boolean incognito;
// Indication of whether this download is thought to be safe or known to be
// suspicious.
DangerType danger;
// The file's MIME type.
DOMString mime;
// The time when the download began in ISO 8601 format. May be passed
// directly to the Date constructor: <code>chrome.downloads.search({},
// function(items){items.forEach(function(item){console.log(new
// Date(item.startTime))})})</code>
DOMString startTime;
// The time when the download ended in ISO 8601 format. May be passed
// directly to the Date constructor: <code>chrome.downloads.search({},
// function(items){items.forEach(function(item){if (item.endTime)
// console.log(new Date(item.endTime))})})</code>
DOMString? endTime;
// Estimated time when the download will complete in ISO 8601 format. May be
// passed directly to the Date constructor:
// <code>chrome.downloads.search({},
// function(items){items.forEach(function(item){if (item.estimatedEndTime)
// console.log(new Date(item.estimatedEndTime))})})</code>
DOMString? estimatedEndTime;
// Indicates whether the download is progressing, interrupted, or complete.
State state;
// True if the download has stopped reading data from the host, but kept the
// connection open.
boolean paused;
// True if the download is in progress and paused, or else if it is
// interrupted and can be resumed starting from where it was interrupted.
boolean canResume;
// Why the download was interrupted. Several kinds of HTTP errors may be
// grouped under one of the errors beginning with <code>SERVER_</code>.
// Errors relating to the network begin with <code>NETWORK_</code>, errors
// relating to the process of writing the file to the file system begin with
// <code>FILE_</code>, and interruptions initiated by the user begin with
// <code>USER_</code>.
InterruptReason? error;
// Number of bytes received so far from the host, without considering file
// compression.
double bytesReceived;
// Number of bytes in the whole file, without considering file compression,
// or -1 if unknown.
double totalBytes;
// Number of bytes in the whole file post-decompression, or -1 if unknown.
double fileSize;
// Whether the downloaded file still exists. This information may be out of
// date because Chrome does not automatically watch for file removal. Call
// $(ref:search)() in order to trigger the check for file existence. When the
// existence check completes, if the file has been deleted, then an
// $(ref:onChanged) event will fire. Note that $(ref:search)() does not wait
// for the existence check to finish before returning, so results from
// $(ref:search)() may not accurately reflect the file system. Also,
// $(ref:search)() may be called as often as necessary, but will not check for
// file existence any more frequently than once every 10 seconds.
boolean exists;
// The identifier for the extension that initiated this download if this
// download was initiated by an extension. Does not change once it is set.
DOMString? byExtensionId;
// The localized name of the extension that initiated this download if this
// download was initiated by an extension. May change if the extension
// changes its name or if the user changes their locale.
DOMString? byExtensionName;
};
[inline_doc] dictionary DownloadQuery {
// This array of search terms limits results to $(ref:DownloadItem) whose
// <code>filename</code> or <code>url</code> or <code>finalUrl</code>
// contain all of the search terms that do not begin with a dash '-' and
// none of the search terms that do begin with a dash.
DOMString[]? query;
// Limits results to $(ref:DownloadItem) that
// started before the given ms since the epoch.
DOMString? startedBefore;
// Limits results to $(ref:DownloadItem) that
// started after the given ms since the epoch.
DOMString? startedAfter;
// Limits results to $(ref:DownloadItem) that ended before the given ms since the
// epoch.
DOMString? endedBefore;
// Limits results to $(ref:DownloadItem) that ended after the given ms since the
// epoch.
DOMString? endedAfter;
// Limits results to $(ref:DownloadItem) whose
// <code>totalBytes</code> is greater than the given integer.
double? totalBytesGreater;
// Limits results to $(ref:DownloadItem) whose
// <code>totalBytes</code> is less than the given integer.
double? totalBytesLess;
// Limits results to $(ref:DownloadItem) whose
// <code>filename</code> matches the given regular expression.
DOMString? filenameRegex;
// Limits results to $(ref:DownloadItem) whose
// <code>url</code> matches the given regular expression.
DOMString? urlRegex;
// Limits results to $(ref:DownloadItem) whose
// <code>finalUrl</code> matches the given regular expression.
DOMString? finalUrlRegex;
// The maximum number of matching $(ref:DownloadItem) returned. Defaults to
// 1000. Set to 0 in order to return all matching $(ref:DownloadItem). See
// $(ref:search) for how to page through results.
long? limit;
// Set elements of this array to $(ref:DownloadItem) properties in order to
// sort search results. For example, setting
// <code>orderBy=['startTime']</code> sorts the $(ref:DownloadItem) by their
// start time in ascending order. To specify descending order, prefix with a
// hyphen: '-startTime'.
DOMString[]? orderBy;
// The <code>id</code> of the $(ref:DownloadItem) to query.
long? id;
// The absolute URL that this download initiated from, before any
// redirects.
DOMString? url;
// The absolute URL that this download is being made from, after all
// redirects.
DOMString? finalUrl;
// Absolute local path.
DOMString? filename;
// Indication of whether this download is thought to be safe or known to be
// suspicious.
DangerType? danger;
// The file's MIME type.
DOMString? mime;
// The time when the download began in ISO 8601 format.
DOMString? startTime;
// The time when the download ended in ISO 8601 format.
DOMString? endTime;
// Indicates whether the download is progressing, interrupted, or complete.
State? state;
// True if the download has stopped reading data from the host, but kept the
// connection open.
boolean? paused;
// Why a download was interrupted.
InterruptReason? error;
// Number of bytes received so far from the host, without considering file
// compression.
double? bytesReceived;
// Number of bytes in the whole file, without considering file compression,
// or -1 if unknown.
double? totalBytes;
// Number of bytes in the whole file post-decompression, or -1 if unknown.
double? fileSize;
// Whether the downloaded file exists;
boolean? exists;
};
dictionary StringDelta {
DOMString? previous;
DOMString? current;
};
dictionary DoubleDelta {
double? previous;
double? current;
};
dictionary BooleanDelta {
boolean? previous;
boolean? current;
};
// Encapsulates a change in a DownloadItem.
[inline_doc] dictionary DownloadDelta {
// The <code>id</code> of the $(ref:DownloadItem)
// that changed.
long id;
// The change in <code>url</code>, if any.
StringDelta? url;
// The change in <code>finalUrl</code>, if any.
StringDelta? finalUrl;
// The change in <code>filename</code>, if any.
StringDelta? filename;
// The change in <code>danger</code>, if any.
StringDelta? danger;
// The change in <code>mime</code>, if any.
StringDelta? mime;
// The change in <code>startTime</code>, if any.
StringDelta? startTime;
// The change in <code>endTime</code>, if any.
StringDelta? endTime;
// The change in <code>state</code>, if any.
StringDelta? state;
// The change in <code>canResume</code>, if any.
BooleanDelta? canResume;
// The change in <code>paused</code>, if any.
BooleanDelta? paused;
// The change in <code>error</code>, if any.
StringDelta? error;
// The change in <code>totalBytes</code>, if any.
DoubleDelta? totalBytes;
// The change in <code>fileSize</code>, if any.
DoubleDelta? fileSize;
// The change in <code>exists</code>, if any.
BooleanDelta? exists;
};
[inline_doc] dictionary GetFileIconOptions {
// The size of the returned icon. The icon will be square with dimensions
// size * size pixels. The default and largest size for the icon is 32x32
// pixels. The only supported sizes are 16 and 32. It is an error to specify
// any other size.
[legalValues=(16,32)] long? size;
};
callback DownloadCallback = void(long downloadId);
callback SearchCallback = void(DownloadItem[] results);
callback EraseCallback = void(long[] erasedIds);
callback NullCallback = void();
callback GetFileIconCallback = void(optional DOMString iconURL);
callback SuggestFilenameCallback = void(
optional FilenameSuggestion suggestion);
interface Functions {
// Download a URL. If the URL uses the HTTP[S] protocol, then the request
// will include all cookies currently set for its hostname. If both
// <code>filename</code> and <code>saveAs</code> are specified, then the
// Save As dialog will be displayed, pre-populated with the specified
// <code>filename</code>. If the download started successfully,
// <code>callback</code> will be called with the new $(ref:DownloadItem)'s
// <code>downloadId</code>. If there was an error starting the download,
// then <code>callback</code> will be called with
// <code>downloadId=undefined</code> and $(ref:runtime.lastError) will contain
// a descriptive string. The error strings are not guaranteed to remain
// backwards compatible between releases. Extensions must not parse it.
// |options|: What to download and how.
// |callback|: Called with the id of the new $(ref:DownloadItem).
static void download(DownloadOptions options,
optional DownloadCallback callback);
// Find $(ref:DownloadItem). Set <code>query</code> to the empty object to get
// all $(ref:DownloadItem). To get a specific $(ref:DownloadItem), set only the
// <code>id</code> field. To page through a large number of items, set
// <code>orderBy: ['-startTime']</code>, set <code>limit</code> to the
// number of items per page, and set <code>startedAfter</code> to the
// <code>startTime</code> of the last item from the last page.
static void search(DownloadQuery query, SearchCallback callback);
// Pause the download. If the request was successful the download is in a
// paused state. Otherwise $(ref:runtime.lastError) contains an error message.
// The request will fail if the download is not active.
// |downloadId|: The id of the download to pause.
// |callback|: Called when the pause request is completed.
static void pause(long downloadId, optional NullCallback callback);
// Resume a paused download. If the request was successful the download is
// in progress and unpaused. Otherwise $(ref:runtime.lastError) contains an
// error message. The request will fail if the download is not active.
// |downloadId|: The id of the download to resume.
// |callback|: Called when the resume request is completed.
static void resume(long downloadId, optional NullCallback callback);
// Cancel a download. When <code>callback</code> is run, the download is
// cancelled, completed, interrupted or doesn't exist anymore.
// |downloadId|: The id of the download to cancel.
// |callback|: Called when the cancel request is completed.
static void cancel(long downloadId, optional NullCallback callback);
// Retrieve an icon for the specified download. For new downloads, file
// icons are available after the $(ref:onCreated) event has been received. The
// image returned by this function while a download is in progress may be
// different from the image returned after the download is complete. Icon
// retrieval is done by querying the underlying operating system or toolkit
// depending on the platform. The icon that is returned will therefore
// depend on a number of factors including state of the download, platform,
// registered file types and visual theme. If a file icon cannot be
// determined, $(ref:runtime.lastError) will contain an error message.
// |downloadId|: The identifier for the download.
// |callback|: A URL to an image that represents the download.
static void getFileIcon(long downloadId,
optional GetFileIconOptions options,
GetFileIconCallback callback);
// Open the downloaded file now if the $(ref:DownloadItem) is complete;
// otherwise returns an error through $(ref:runtime.lastError). Requires the
// <code>"downloads.open"</code> permission in addition to the
// <code>"downloads"</code> permission. An $(ref:onChanged) event will fire
// when the item is opened for the first time.
// |downloadId|: The identifier for the downloaded file.
static void open(long downloadId);
// Show the downloaded file in its folder in a file manager.
// |downloadId|: The identifier for the downloaded file.
static void show(long downloadId);
// Show the default Downloads folder in a file manager.
static void showDefaultFolder();
// Erase matching $(ref:DownloadItem) from history without deleting the
// downloaded file. An $(ref:onErased) event will fire for each
// $(ref:DownloadItem) that matches <code>query</code>, then
// <code>callback</code> will be called.
static void erase(DownloadQuery query, optional EraseCallback callback);
// Remove the downloaded file if it exists and the $(ref:DownloadItem) is
// complete; otherwise return an error through $(ref:runtime.lastError).
static void removeFile(long downloadId, optional NullCallback callback);
// Prompt the user to accept a dangerous download. Can only be called from a
// visible context (tab, window, or page/browser action popup). Does not
// automatically accept dangerous downloads. If the download is accepted,
// then an $(ref:onChanged) event will fire, otherwise nothing will happen.
// When all the data is fetched into a temporary file and either the
// download is not dangerous or the danger has been accepted, then the
// temporary file is renamed to the target filename, the |state| changes to
// 'complete', and $(ref:onChanged) fires.
// |downloadId|: The identifier for the $(ref:DownloadItem).
// |callback|: Called when the danger prompt dialog closes.
static void acceptDanger(long downloadId, optional NullCallback callback);
// Enable or disable the gray shelf at the bottom of every window associated
// with the current browser profile. The shelf will be disabled as long as
// at least one extension has disabled it. Enabling the shelf while at least
// one other extension has disabled it will return an error through
// $(ref:runtime.lastError). Requires the <code>"downloads.shelf"</code>
// permission in addition to the <code>"downloads"</code> permission.
static void setShelfEnabled(boolean enabled);
};
interface Events {
// This event fires with the $(ref:DownloadItem) object when a download
// begins.
static void onCreated(DownloadItem downloadItem);
// Fires with the <code>downloadId</code> when a download is erased from
// history.
// |downloadId|: The <code>id</code> of the $(ref:DownloadItem) that was
// erased.
static void onErased(long downloadId);
// When any of a $(ref:DownloadItem)'s properties except
// <code>bytesReceived</code> and <code>estimatedEndTime</code> changes,
// this event fires with the <code>downloadId</code> and an object
// containing the properties that changed.
static void onChanged(DownloadDelta downloadDelta);
// During the filename determination process, extensions will be given the
// opportunity to override the target $(ref:DownloadItem.filename). Each
// extension may not register more than one listener for this event. Each
// listener must call <code>suggest</code> exactly once, either
// synchronously or asynchronously. If the listener calls
// <code>suggest</code> asynchronously, then it must return
// <code>true</code>. If the listener neither calls <code>suggest</code>
// synchronously nor returns <code>true</code>, then <code>suggest</code>
// will be called automatically. The $(ref:DownloadItem) will not complete
// until all listeners have called <code>suggest</code>. Listeners may call
// <code>suggest</code> without any arguments in order to allow the download
// to use <code>downloadItem.filename</code> for its filename, or pass a
// <code>suggestion</code> object to <code>suggest</code> in order to
// override the target filename. If more than one extension overrides the
// filename, then the last extension installed whose listener passes a
// <code>suggestion</code> object to <code>suggest</code> wins. In order to
// avoid confusion regarding which extension will win, users should not
// install extensions that may conflict. If the download is initiated by
// $(ref:download) and the target filename is known before the MIME type and
// tentative filename have been determined, pass <code>filename</code> to
// $(ref:download) instead.
[maxListeners=1] static void onDeterminingFilename(
DownloadItem downloadItem, SuggestFilenameCallback suggest);
};
};