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 [permissions=downloads] | 5 [permissions=downloads] |
6 namespace downloads { | 6 namespace downloads { |
7 [inline_doc] dictionary HeaderNameValuePair { | 7 [inline_doc] dictionary HeaderNameValuePair { |
8 // Name of the HTTP header. | 8 // Name of the HTTP header. |
9 DOMString name; | 9 DOMString name; |
10 | 10 |
11 // Value of the HTTP header. | 11 // Value of the HTTP header. |
12 DOMString value; | 12 DOMString value; |
13 }; | 13 }; |
14 | 14 |
| 15 // $ref:onDeterminingFilename handlers may return a FilenameSuggestion |
| 16 // object in order to override a download's target filename. |
| 17 dictionary FilenameSuggestion { |
| 18 // The $ref:DownloadItem's new target $ref:DownloadItem.filename, as a path |
| 19 // relative to the user's default Downloads directory, possibly containing |
| 20 // subdirectories. Absolute paths, empty paths, and paths containing |
| 21 // back-references ".." will be ignored. |
| 22 DOMString filename; |
| 23 |
| 24 // Whether to overwrite any existing files. |
| 25 boolean? overwrite; |
| 26 }; |
| 27 |
15 [inline_doc] enum HttpMethod {GET, POST}; | 28 [inline_doc] enum HttpMethod {GET, POST}; |
16 | 29 |
17 [inline_doc] dictionary DownloadOptions { | 30 [inline_doc] dictionary DownloadOptions { |
18 // The URL to download. | 31 // The URL to download. |
19 DOMString url; | 32 DOMString url; |
20 | 33 |
21 // A file path relative to the Downloads directory to contain the downloaded | 34 // A file path relative to the Downloads directory to contain the downloaded |
22 // file. | 35 // file. |
23 DOMString? filename; | 36 DOMString? filename; |
24 | 37 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 // The size of the icon. The returned icon will be square with dimensions | 319 // The size of the icon. The returned icon will be square with dimensions |
307 // size * size pixels. The default size for the icon is 32x32 pixels. | 320 // size * size pixels. The default size for the icon is 32x32 pixels. |
308 [legalValues=(16,32)] long? size; | 321 [legalValues=(16,32)] long? size; |
309 }; | 322 }; |
310 | 323 |
311 callback DownloadCallback = void(long downloadId); | 324 callback DownloadCallback = void(long downloadId); |
312 callback SearchCallback = void(DownloadItem[] results); | 325 callback SearchCallback = void(DownloadItem[] results); |
313 callback EraseCallback = void(long[] erasedIds); | 326 callback EraseCallback = void(long[] erasedIds); |
314 callback NullCallback = void(); | 327 callback NullCallback = void(); |
315 callback GetFileIconCallback = void(optional DOMString iconURL); | 328 callback GetFileIconCallback = void(optional DOMString iconURL); |
| 329 callback SuggestFilenameCallback = void(optional FilenameSuggestion suggestion
); |
316 | 330 |
317 interface Functions { | 331 interface Functions { |
318 // Download a URL. If the URL uses the HTTP[S] protocol, then the request | 332 // Download a URL. If the URL uses the HTTP[S] protocol, then the request |
319 // will include all cookies currently set for its hostname. If both | 333 // will include all cookies currently set for its hostname. If both |
320 // <code>filename</code> and <code>saveAs</code> are specified, then the | 334 // <code>filename</code> and <code>saveAs</code> are specified, then the |
321 // Save As dialog will be displayed, pre-populated with the specified | 335 // Save As dialog will be displayed, pre-populated with the specified |
322 // <code>filename</code>. If the download started successfully, | 336 // <code>filename</code>. If the download started successfully, |
323 // <code>callback</code> will be called with the new $ref:DownloadItem's | 337 // <code>callback</code> will be called with the new $ref:DownloadItem's |
324 // <code>downloadId</code>. If there was an error starting the download, | 338 // <code>downloadId</code>. If there was an error starting the download, |
325 // then <code>callback</code> will be called with | 339 // then <code>callback</code> will be called with |
326 // <code>downloadId=undefined</code> and | 340 // <code>downloadId=undefined</code> and $ref:runtime.lastError will contain |
327 // $ref:runtime.lastError | 341 // a descriptive string. The error strings are not guaranteed to remain |
328 // will contain a descriptive string. The error strings are not guaranteed | 342 // backwards compatible between releases. You must not parse it. |
329 // to remain backwards compatible between releases. You must not parse it. | |
330 // |options|: What to download and how. | 343 // |options|: What to download and how. |
331 // |callback|: Called with the id of the new $ref:DownloadItem. | 344 // |callback|: Called with the id of the new $ref:DownloadItem. |
332 static void download(DownloadOptions options, | 345 static void download(DownloadOptions options, |
333 optional DownloadCallback callback); | 346 optional DownloadCallback callback); |
334 | 347 |
335 // Find $ref:DownloadItem. Set | 348 // Find $ref:DownloadItem. Set |
336 // <code>query</code> to the empty object to get all | 349 // <code>query</code> to the empty object to get all |
337 // $ref:DownloadItem. To get a specific | 350 // $ref:DownloadItem. To get a specific |
338 // $ref:DownloadItem, set only the <code>id</code> | 351 // $ref:DownloadItem, set only the <code>id</code> |
339 // field. | 352 // field. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 402 |
390 // Show the downloaded file in its folder in a file manager. | 403 // Show the downloaded file in its folder in a file manager. |
391 // |downloadId|: The identifier for the downloaded file. | 404 // |downloadId|: The identifier for the downloaded file. |
392 static void show(long downloadId); | 405 static void show(long downloadId); |
393 | 406 |
394 // Erase matching $ref:DownloadItem from history. An $ref:onErased event | 407 // Erase matching $ref:DownloadItem from history. An $ref:onErased event |
395 // will fire for each $ref:DownloadItem that matches <code>query</code>, | 408 // will fire for each $ref:DownloadItem that matches <code>query</code>, |
396 // then <code>callback</code> will be called. | 409 // then <code>callback</code> will be called. |
397 static void erase(DownloadQuery query, optional EraseCallback callback); | 410 static void erase(DownloadQuery query, optional EraseCallback callback); |
398 | 411 |
399 // TODO(benjhayden) Comment. | |
400 [nodoc] static void setDestination(long downloadId, DOMString relativePath); | |
401 | |
402 // Prompt the user to accept a dangerous download. Does not automatically | 412 // Prompt the user to accept a dangerous download. Does not automatically |
403 // accept dangerous downloads. If the download is accepted, then an | 413 // accept dangerous downloads. If the download is accepted, then an |
404 // $ref:onChanged event will fire, otherwise nothing will happen. When all | 414 // $ref:onChanged event will fire, otherwise nothing will happen. When all |
405 // the data is fetched into a temporary file and either the download is not | 415 // the data is fetched into a temporary file and either the download is not |
406 // dangerous or the danger has been accepted, then the temporary file is | 416 // dangerous or the danger has been accepted, then the temporary file is |
407 // renamed to the target filename, the |state| changes to 'complete', and | 417 // renamed to the target filename, the |state| changes to 'complete', and |
408 // $ref:onChanged fires. | 418 // $ref:onChanged fires. |
409 // |downloadId|: The identifier for the $ref:DownloadItem. | 419 // |downloadId|: The identifier for the $ref:DownloadItem. |
410 static void acceptDanger(long downloadId); | 420 static void acceptDanger(long downloadId); |
411 | 421 |
412 // Initiate dragging the downloaded file to another application. | 422 // Initiate dragging the downloaded file to another application. |
413 static void drag(long downloadId); | 423 static void drag(long downloadId); |
414 }; | 424 }; |
415 | 425 |
416 interface Events { | 426 interface Events { |
417 // This event fires with the $ref:DownloadItem | 427 // This event fires with the $ref:DownloadItem |
418 // object when a download begins. | 428 // object when a download begins. |
419 static void onCreated(DownloadItem downloadItem); | 429 static void onCreated(DownloadItem downloadItem); |
420 | 430 |
421 // Fires with the <code>downloadId</code> when a download is erased from | 431 // Fires with the <code>downloadId</code> when a download is erased from |
422 // history. | 432 // history. |
423 // |downloadId|: The <code>id</code> of the $ref:DownloadItem that was erase
d. | 433 // |downloadId|: The <code>id</code> of the $ref:DownloadItem that was erase
d. |
424 static void onErased(long downloadId); | 434 static void onErased(long downloadId); |
425 | 435 |
426 // When any of a $ref:DownloadItem's properties | 436 // When any of a $ref:DownloadItem's properties |
427 // except <code>bytesReceived</code> changes, this event fires with the | 437 // except <code>bytesReceived</code> changes, this event fires with the |
428 // <code>downloadId</code> and an object containing the properties that chan
ged. | 438 // <code>downloadId</code> and an object containing the properties that chan
ged. |
429 static void onChanged(DownloadDelta downloadDelta); | 439 static void onChanged(DownloadDelta downloadDelta); |
| 440 |
| 441 // During the filename determination process, extensions will be given the |
| 442 // opportunity to override the target $ref:DownloadItem.filename. Each |
| 443 // handler MUST call <code>suggest</code> exactly once, either synchronously |
| 444 // or asynchronously. The $ref:DownloadItem will not complete until all |
| 445 // handlers have called <code>suggest</code>. Extensions may use any number |
| 446 // of $ref:onDeterminingFilename handlers. Handlers may call |
| 447 // <code>suggest</code> without any arguments in order to allow the download |
| 448 // to use <code>downloadItem.filename</code> for its filename, or pass a |
| 449 // $ref:FilenameSuggestion object to <code>suggest</code> in order to |
| 450 // override the target filename. If more than one extension overrides the |
| 451 // filename, then the last handler registered in the last extension |
| 452 // installed that returns a $ref:FilenameSuggestion object wins. In order to |
| 453 // avoid confusion regarding extension/handler will win, users should not |
| 454 // install extensions that may conflict. |
| 455 static void onDeterminingFilename(DownloadItem downloadItem, |
| 456 SuggestFilenameCallback suggest); |
430 }; | 457 }; |
431 }; | 458 }; |
OLD | NEW |