OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Use the <code>chrome.downloads</code> API to programmatically initiate, | 5 // Use the <code>chrome.downloads</code> API to programmatically initiate, |
6 // monitor, manipulate, and search for downloads. | 6 // monitor, manipulate, and search for downloads. |
7 [permissions=downloads] | 7 [permissions=downloads] |
8 namespace downloads { | 8 namespace downloads { |
9 [inline_doc] dictionary HeaderNameValuePair { | 9 [inline_doc] dictionary HeaderNameValuePair { |
10 // Name of the HTTP header. | 10 // Name of the HTTP header. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 enum State {in_progress, interrupted, complete}; | 93 enum State {in_progress, interrupted, complete}; |
94 | 94 |
95 // The state of the process of downloading a file. | 95 // The state of the process of downloading a file. |
96 dictionary DownloadItem { | 96 dictionary DownloadItem { |
97 // An identifier that is persistent across browser sessions. | 97 // An identifier that is persistent across browser sessions. |
98 long id; | 98 long id; |
99 | 99 |
100 // Absolute URL. | 100 // Absolute URL. |
101 DOMString url; | 101 DOMString url; |
102 | 102 |
| 103 // Absolute URL. |
| 104 DOMString referrer; |
| 105 |
103 // Absolute local path. | 106 // Absolute local path. |
104 DOMString filename; | 107 DOMString filename; |
105 | 108 |
106 // False if this download is recorded in the history, true if it is not | 109 // False if this download is recorded in the history, true if it is not |
107 // recorded. | 110 // recorded. |
108 boolean incognito; | 111 boolean incognito; |
109 | 112 |
110 // Indication of whether this download is thought to be safe or known to be | 113 // Indication of whether this download is thought to be safe or known to be |
111 // suspicious. | 114 // suspicious. |
112 DangerType danger; | 115 DangerType danger; |
113 | 116 |
114 // True if the user has accepted the download's danger. | |
115 boolean? dangerAccepted; | |
116 | |
117 // The file's MIME type. | 117 // The file's MIME type. |
118 DOMString mime; | 118 DOMString mime; |
119 | 119 |
120 // The time when the download began in ISO 8601 format. May be passed | 120 // The time when the download began in ISO 8601 format. May be passed |
121 // directly to the Date constructor: <code>chrome.downloads.search({}, | 121 // directly to the Date constructor: <code>chrome.downloads.search({}, |
122 // function(items){items.forEach(function(item){console.log(new | 122 // function(items){items.forEach(function(item){console.log(new |
123 // Date(item.startTime))})})</code> | 123 // Date(item.startTime))})})</code> |
124 DOMString startTime; | 124 DOMString startTime; |
125 | 125 |
126 // The time when the download ended in ISO 8601 format. May be passed | 126 // The time when the download ended in ISO 8601 format. May be passed |
127 // directly to the Date constructor: <code>chrome.downloads.search({}, | 127 // directly to the Date constructor: <code>chrome.downloads.search({}, |
128 // function(items){items.forEach(function(item){if (item.endTime) | 128 // function(items){items.forEach(function(item){if (item.endTime) |
129 // console.log(new Date(item.endTime))})})</code> | 129 // console.log(new Date(item.endTime))})})</code> |
130 DOMString? endTime; | 130 DOMString? endTime; |
131 | 131 |
| 132 // Estimated time when the download will complete in ISO 8601 format. |
| 133 DOMString? estimatedEndTime; |
| 134 |
132 // Indicates whether the download is progressing, interrupted, or complete. | 135 // Indicates whether the download is progressing, interrupted, or complete. |
133 State state; | 136 State state; |
134 | 137 |
135 // True if the download has stopped reading data from the host, but kept the | 138 // True if the download has stopped reading data from the host, but kept the |
136 // connection open. | 139 // connection open. |
137 boolean paused; | 140 boolean paused; |
138 | 141 |
| 142 // True if the download is in progress and paused, or else if it is |
| 143 // interrupted and can be resumed starting from where it was interrupted. |
| 144 boolean canResume; |
| 145 |
139 // Number indicating why a download was interrupted. | 146 // Number indicating why a download was interrupted. |
140 long? error; | 147 long? error; |
141 | 148 |
142 // Number of bytes received so far from the host, without considering file | 149 // Number of bytes received so far from the host, without considering file |
143 // compression. | 150 // compression. |
144 long bytesReceived; | 151 long bytesReceived; |
145 | 152 |
146 // Number of bytes in the whole file, without considering file compression, | 153 // Number of bytes in the whole file, without considering file compression, |
147 // or -1 if unknown. | 154 // or -1 if unknown. |
148 long totalBytes; | 155 long totalBytes; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // Absolute URL. | 228 // Absolute URL. |
222 DOMString? url; | 229 DOMString? url; |
223 | 230 |
224 // Absolute local path. | 231 // Absolute local path. |
225 DOMString? filename; | 232 DOMString? filename; |
226 | 233 |
227 // Indication of whether this download is thought to be safe or known to be | 234 // Indication of whether this download is thought to be safe or known to be |
228 // suspicious. | 235 // suspicious. |
229 DangerType? danger; | 236 DangerType? danger; |
230 | 237 |
231 // True if the user has accepted the download's danger. | |
232 boolean? dangerAccepted; | |
233 | |
234 // The file's MIME type. | 238 // The file's MIME type. |
235 DOMString? mime; | 239 DOMString? mime; |
236 | 240 |
237 // The time when the download began in ISO 8601 format. | 241 // The time when the download began in ISO 8601 format. |
238 DOMString? startTime; | 242 DOMString? startTime; |
239 | 243 |
240 // The time when the download ended in ISO 8601 format. | 244 // The time when the download ended in ISO 8601 format. |
241 DOMString? endTime; | 245 DOMString? endTime; |
242 | 246 |
243 // Indicates whether the download is progressing, interrupted, or complete. | 247 // Indicates whether the download is progressing, interrupted, or complete. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 292 |
289 // The change in <code>url</code>, if any. | 293 // The change in <code>url</code>, if any. |
290 StringDelta? url; | 294 StringDelta? url; |
291 | 295 |
292 // The change in <code>filename</code>, if any. | 296 // The change in <code>filename</code>, if any. |
293 StringDelta? filename; | 297 StringDelta? filename; |
294 | 298 |
295 // The change in <code>danger</code>, if any. | 299 // The change in <code>danger</code>, if any. |
296 StringDelta? danger; | 300 StringDelta? danger; |
297 | 301 |
298 // The change in <code>dangerAccepted</code>, if any. | |
299 BooleanDelta? dangerAccepted; | |
300 | |
301 // The change in <code>mime</code>, if any. | 302 // The change in <code>mime</code>, if any. |
302 StringDelta? mime; | 303 StringDelta? mime; |
303 | 304 |
304 // The change in <code>startTime</code>, if any. | 305 // The change in <code>startTime</code>, if any. |
305 StringDelta? startTime; | 306 StringDelta? startTime; |
306 | 307 |
307 // The change in <code>endTime</code>, if any. | 308 // The change in <code>endTime</code>, if any. |
308 StringDelta? endTime; | 309 StringDelta? endTime; |
309 | 310 |
310 // The change in <code>state</code>, if any. | 311 // The change in <code>state</code>, if any. |
311 StringDelta? state; | 312 StringDelta? state; |
312 | 313 |
| 314 // The change in <code>canResume</code>, if any. |
| 315 BooleanDelta? canResume; |
| 316 |
313 // The change in <code>paused</code>, if any. | 317 // The change in <code>paused</code>, if any. |
314 BooleanDelta? paused; | 318 BooleanDelta? paused; |
315 | 319 |
316 // The change in <code>error</code>, if any. | 320 // The change in <code>error</code>, if any. |
317 LongDelta? error; | 321 LongDelta? error; |
318 | 322 |
319 // The change in <code>totalBytes</code>, if any. | 323 // The change in <code>totalBytes</code>, if any. |
320 LongDelta? totalBytes; | 324 LongDelta? totalBytes; |
321 | 325 |
322 // The change in <code>fileSize</code>, if any. | 326 // The change in <code>fileSize</code>, if any. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 optional GetFileIconOptions options, | 409 optional GetFileIconOptions options, |
406 GetFileIconCallback callback); | 410 GetFileIconCallback callback); |
407 | 411 |
408 // Open the downloaded file now if the $ref:DownloadItem is complete; | 412 // Open the downloaded file now if the $ref:DownloadItem is complete; |
409 // returns an error through $ref:runtime.lastError otherwise. An | 413 // returns an error through $ref:runtime.lastError otherwise. An |
410 // $ref:onChanged event will fire when the item is opened for the first | 414 // $ref:onChanged event will fire when the item is opened for the first |
411 // time. | 415 // time. |
412 // |downloadId|: The identifier for the downloaded file. | 416 // |downloadId|: The identifier for the downloaded file. |
413 static void open(long downloadId); | 417 static void open(long downloadId); |
414 | 418 |
415 // Show the downloaded file in its folder in a file manager. | 419 // Show the downloaded file in its folder in a file manager. If |
| 420 // <code>downloadId</code> is not specified, opens the default Downloads |
| 421 // folder in a file manager. |
416 // |downloadId|: The identifier for the downloaded file. | 422 // |downloadId|: The identifier for the downloaded file. |
417 static void show(long downloadId); | 423 static void show(optional long downloadId); |
418 | 424 |
419 // Erase matching $ref:DownloadItem from history. An $ref:onErased event | 425 // Erase matching $ref:DownloadItem from history. An $ref:onErased event |
420 // will fire for each $ref:DownloadItem that matches <code>query</code>, | 426 // will fire for each $ref:DownloadItem that matches <code>query</code>, |
421 // then <code>callback</code> will be called. | 427 // then <code>callback</code> will be called. |
422 static void erase(DownloadQuery query, optional EraseCallback callback); | 428 static void erase(DownloadQuery query, optional EraseCallback callback); |
423 | 429 |
424 // Prompt the user to accept a dangerous download. Does not automatically | 430 // Prompt the user to accept a dangerous download. Does not automatically |
425 // accept dangerous downloads. If the download is accepted, then an | 431 // accept dangerous downloads. If the download is accepted, then an |
426 // $ref:onChanged event will fire, otherwise nothing will happen. When all | 432 // $ref:onChanged event will fire, otherwise nothing will happen. When all |
427 // the data is fetched into a temporary file and either the download is not | 433 // the data is fetched into a temporary file and either the download is not |
428 // dangerous or the danger has been accepted, then the temporary file is | 434 // dangerous or the danger has been accepted, then the temporary file is |
429 // renamed to the target filename, the |state| changes to 'complete', and | 435 // renamed to the target filename, the |state| changes to 'complete', and |
430 // $ref:onChanged fires. | 436 // $ref:onChanged fires. |
431 // |downloadId|: The identifier for the $ref:DownloadItem. | 437 // |downloadId|: The identifier for the $ref:DownloadItem. |
432 static void acceptDanger(long downloadId); | 438 // |callback|: Called when the danger prompt dialog closes. |
| 439 static void acceptDanger(long downloadId, optional NullCallback callback); |
433 | 440 |
434 // Initiate dragging the downloaded file to another application. | 441 // Initiate dragging the downloaded file to another application. |
435 static void drag(long downloadId); | 442 static void drag(long downloadId); |
436 }; | 443 }; |
437 | 444 |
438 interface Events { | 445 interface Events { |
439 // This event fires with the $ref:DownloadItem | 446 // This event fires with the $ref:DownloadItem |
440 // object when a download begins. | 447 // object when a download begins. |
441 static void onCreated(DownloadItem downloadItem); | 448 static void onCreated(DownloadItem downloadItem); |
442 | 449 |
443 // Fires with the <code>downloadId</code> when a download is erased from | 450 // Fires with the <code>downloadId</code> when a download is erased from |
444 // history. | 451 // history. |
445 // |downloadId|: The <code>id</code> of the $ref:DownloadItem that was | 452 // |downloadId|: The <code>id</code> of the $ref:DownloadItem that was |
446 // erased. | 453 // erased. |
447 static void onErased(long downloadId); | 454 static void onErased(long downloadId); |
448 | 455 |
449 // When any of a $ref:DownloadItem's properties except | 456 // When any of a $ref:DownloadItem's properties except |
450 // <code>bytesReceived</code> changes, this event fires with the | 457 // <code>bytesReceived</code> and <code>estimatedEndTime</code> changes, |
451 // <code>downloadId</code> and an object containing the properties that | 458 // this event fires with the <code>downloadId</code> and an object |
452 // changed. | 459 // containing the properties that changed. |
453 static void onChanged(DownloadDelta downloadDelta); | 460 static void onChanged(DownloadDelta downloadDelta); |
454 | 461 |
455 // During the filename determination process, extensions will be given the | 462 // During the filename determination process, extensions will be given the |
456 // opportunity to override the target $ref:DownloadItem.filename. Each | 463 // opportunity to override the target $ref:DownloadItem.filename. Each |
457 // extension may not register more than one listener for this event. Each | 464 // extension may not register more than one listener for this event. Each |
458 // listener must call <code>suggest</code> exactly once, either | 465 // listener must call <code>suggest</code> exactly once, either |
459 // synchronously or asynchronously. If the listener calls | 466 // synchronously or asynchronously. If the listener calls |
460 // <code>suggest</code> asynchronously, then it must return | 467 // <code>suggest</code> asynchronously, then it must return |
461 // <code>true</code>. If the listener neither calls <code>suggest</code> | 468 // <code>true</code>. If the listener neither calls <code>suggest</code> |
462 // synchronously nor returns <code>true</code>, then <code>suggest</code> | 469 // synchronously nor returns <code>true</code>, then <code>suggest</code> |
463 // will be called automatically. The $ref:DownloadItem will not complete | 470 // will be called automatically. The $ref:DownloadItem will not complete |
464 // until all listeners have called <code>suggest</code>. Listeners may call | 471 // until all listeners have called <code>suggest</code>. Listeners may call |
465 // <code>suggest</code> without any arguments in order to allow the download | 472 // <code>suggest</code> without any arguments in order to allow the download |
466 // to use <code>downloadItem.filename</code> for its filename, or pass a | 473 // to use <code>downloadItem.filename</code> for its filename, or pass a |
467 // <code>suggestion</code> object to <code>suggest</code> in order to | 474 // <code>suggestion</code> object to <code>suggest</code> in order to |
468 // override the target filename. If more than one extension overrides the | 475 // override the target filename. If more than one extension overrides the |
469 // filename, then the last extension installed whose listener passes a | 476 // filename, then the last extension installed whose listener passes a |
470 // <code>suggestion</code> object to <code>suggest</code> wins. In order to | 477 // <code>suggestion</code> object to <code>suggest</code> wins. In order to |
471 // avoid confusion regarding which extension will win, users should not | 478 // avoid confusion regarding which extension will win, users should not |
472 // install extensions that may conflict. If the download is initiated by | 479 // install extensions that may conflict. If the download is initiated by |
473 // $ref:download and the target filename is known before the MIME type and | 480 // $ref:download and the target filename is known before the MIME type and |
474 // tentative filename have been determined, pass <code>filename</code> to | 481 // tentative filename have been determined, pass <code>filename</code> to |
475 // $ref:download instead. | 482 // $ref:download instead. |
476 [maxListeners=1] static void onDeterminingFilename( | 483 [maxListeners=1] static void onDeterminingFilename( |
477 DownloadItem downloadItem, SuggestFilenameCallback suggest); | 484 DownloadItem downloadItem, SuggestFilenameCallback suggest); |
478 }; | 485 }; |
479 }; | 486 }; |
OLD | NEW |