nsIIncrementalDownload.idl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:set ts=2 sw=2 sts=2 et cindent: */
  3. /* This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #include "nsIRequest.idl"
  7. interface nsIURI;
  8. interface nsIFile;
  9. interface nsIRequestObserver;
  10. /**
  11. * An incremental download object attempts to fetch a file piecemeal over time
  12. * in an effort to minimize network bandwidth usage.
  13. *
  14. * Canceling a background download does not cause the file on disk to be
  15. * deleted.
  16. */
  17. [scriptable, uuid(6687823f-56c4-461d-93a1-7f6cb7dfbfba)]
  18. interface nsIIncrementalDownload : nsIRequest
  19. {
  20. /**
  21. * Initialize the incremental download object. If the destination file
  22. * already exists, then only the remaining portion of the file will be
  23. * fetched.
  24. *
  25. * NOTE: The downloader will create the destination file if it does not
  26. * already exist. It will create the file with the permissions 0600 if
  27. * needed. To affect the permissions of the file, consumers of this
  28. * interface may create an empty file at the specified destination prior to
  29. * starting the incremental download.
  30. *
  31. * NOTE: Since this class may create a temporary file at the specified
  32. * destination, it is advisable for the consumer of this interface to specify
  33. * a file name for the destination that would not tempt the user into
  34. * double-clicking it. For example, it might be wise to append a file
  35. * extension like ".part" to the end of the destination to protect users from
  36. * accidentally running "blah.exe" before it is a complete file.
  37. *
  38. * @param uri
  39. * The URI to fetch.
  40. * @param destination
  41. * The location where the file is to be stored.
  42. * @param chunkSize
  43. * The size of the chunks to fetch. A non-positive value results in
  44. * the default chunk size being used.
  45. * @param intervalInSeconds
  46. * The amount of time to wait between fetching chunks. Pass a
  47. * negative to use the default interval, or 0 to fetch the remaining
  48. * part of the file in one chunk.
  49. */
  50. void init(in nsIURI uri, in nsIFile destination, in long chunkSize,
  51. in long intervalInSeconds);
  52. /**
  53. * The URI being fetched.
  54. */
  55. readonly attribute nsIURI URI;
  56. /**
  57. * The URI being fetched after any redirects have been followed. This
  58. * attribute is set just prior to calling OnStartRequest on the observer
  59. * passed to the start method.
  60. */
  61. readonly attribute nsIURI finalURI;
  62. /**
  63. * The file where the download is being written.
  64. */
  65. readonly attribute nsIFile destination;
  66. /**
  67. * The total number of bytes for the requested file. This attribute is set
  68. * just prior to calling OnStartRequest on the observer passed to the start
  69. * method.
  70. *
  71. * This attribute has a value of -1 if the total size is unknown.
  72. */
  73. readonly attribute long long totalSize;
  74. /**
  75. * The current number of bytes downloaded so far. This attribute is set just
  76. * prior to calling OnStartRequest on the observer passed to the start
  77. * method.
  78. *
  79. * This attribute has a value of -1 if the current size is unknown.
  80. */
  81. readonly attribute long long currentSize;
  82. /**
  83. * Start the incremental download.
  84. *
  85. * @param observer
  86. * An observer to be notified of various events. OnStartRequest is
  87. * called when finalURI and totalSize have been determined or when an
  88. * error occurs. OnStopRequest is called when the file is completely
  89. * downloaded or when an error occurs. If this object implements
  90. * nsIProgressEventSink, then its OnProgress method will be called as
  91. * data is written to the destination file. If this object implements
  92. * nsIInterfaceRequestor, then it will be assigned as the underlying
  93. * channel's notification callbacks, which allows it to provide a
  94. * nsIAuthPrompt implementation if needed by the channel, for example.
  95. * @param ctxt
  96. * User defined object forwarded to the observer's methods.
  97. */
  98. void start(in nsIRequestObserver observer,
  99. in nsISupports ctxt);
  100. };