| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 [permissions=downloads] |
| 6 namespace downloads { |
| 7 [inline_doc] dictionary HeaderNameValuePair { |
| 8 // Name of the HTTP header. |
| 9 DOMString name; |
| 10 |
| 11 // Value of the HTTP header. |
| 12 DOMString value; |
| 13 }; |
| 14 |
| 15 [inline_doc] enum HttpMethod {GET, POST}; |
| 16 |
| 17 [inline_doc] dictionary DownloadOptions { |
| 18 // The URL to download. |
| 19 DOMString url; |
| 20 |
| 21 // A file path relative to the Downloads directory to contain the downloaded |
| 22 // file. |
| 23 DOMString? filename; |
| 24 |
| 25 // Use a file-chooser to allow the user to select a filename. |
| 26 boolean? saveAs; |
| 27 |
| 28 // The HTTP method to use if the URL uses the HTTP[S] protocol. |
| 29 HttpMethod? method; |
| 30 |
| 31 // Extra HTTP headers to send with the request if the URL uses the HTTP[s] |
| 32 // protocol. Each header is represented as a dictionary containing the keys |
| 33 // <code>name</code> and either <code>value</code> or |
| 34 // <code>binaryValue</code>, restricted to those allowed by XMLHttpRequest. |
| 35 HeaderNameValuePair[]? headers; |
| 36 |
| 37 // Post body. |
| 38 DOMString? body; |
| 39 }; |
| 40 |
| 41 // <dl><dt>file</dt> |
| 42 // <dd>The download's filename is suspicious.</dd> |
| 43 // <dt>url</dt> |
| 44 // <dd>The download's URL is known to be malicious.</dd> |
| 45 // <dt>content</dt> |
| 46 // <dd>The downloaded file is known to be malicious.</dd> |
| 47 // <dt>uncommon</dt> |
| 48 // <dd>The download's URL is not commonly downloaded and could be |
| 49 // dangerous.</dd> |
| 50 // <dt>host</dt> |
| 51 // <dd>The download came from a host known to distribute malicious |
| 52 // binaries and is likely dangerous.</dd> |
| 53 // <dt>safe</dt> |
| 54 // <dd>The download presents no known danger to the user's computer.</dd> |
| 55 // </dl> |
| 56 // These string constants will never change, however the set of DangerTypes |
| 57 // may change. |
| 58 enum DangerType {file, url, content, uncommon, host, safe}; |
| 59 |
| 60 // <dl><dt>in_progress</dt> |
| 61 // <dd>The download is currently receiving data from the server.</dd> |
| 62 // <dt>interrupted</dt> |
| 63 // <dd>An error broke the connection with the file host.</dd> |
| 64 // <dt>complete</dt> |
| 65 // <dd>The download completed successfully.</dd> |
| 66 // </dl> |
| 67 // These string constants will never change, however the set of States may |
| 68 // change. |
| 69 enum State {in_progress, interrupted, complete}; |
| 70 |
| 71 // The state of the process of downloading a file. |
| 72 dictionary DownloadItem { |
| 73 // An identifier that is persistent across browser sessions. |
| 74 long id; |
| 75 |
| 76 // Absolute URL. |
| 77 DOMString url; |
| 78 |
| 79 // Absolute local path. |
| 80 DOMString filename; |
| 81 |
| 82 // False if this download is recorded in the history, true if it is not |
| 83 // recorded. |
| 84 boolean incognito; |
| 85 |
| 86 // Indication of whether this download is thought to be safe or known to be |
| 87 // suspicious. |
| 88 DangerType danger; |
| 89 |
| 90 // True if the user has accepted the download's danger. |
| 91 boolean? dangerAccepted; |
| 92 |
| 93 // The file's MIME type. |
| 94 DOMString mime; |
| 95 |
| 96 // The time when the download began in ISO 8601 format. May be passed |
| 97 // directly to the Date constructor: <code>chrome.downloads.search({}, |
| 98 // function(items){items.forEach(function(item){console.log(new |
| 99 // Date(item.startTime))})})</code> |
| 100 DOMString startTime; |
| 101 |
| 102 // The time when the download ended in ISO 8601 format. May be passed |
| 103 // directly to the Date constructor: <code>chrome.downloads.search({}, |
| 104 // function(items){items.forEach(function(item){if (item.endTime) |
| 105 // console.log(new Date(item.endTime))})})</code> |
| 106 DOMString? endTime; |
| 107 |
| 108 // Indicates whether the download is progressing, interrupted, or complete. |
| 109 State state; |
| 110 |
| 111 // True if the download has stopped reading data from the host, but kept the |
| 112 // connection open. |
| 113 boolean paused; |
| 114 |
| 115 // Number indicating why a download was interrupted. |
| 116 long? error; |
| 117 |
| 118 // Number of bytes received so far from the host, without considering file |
| 119 // compression. |
| 120 long bytesReceived; |
| 121 |
| 122 // Number of bytes in the whole file, without considering file compression, |
| 123 // or -1 if unknown. |
| 124 long totalBytes; |
| 125 |
| 126 // Number of bytes in the whole file post-decompression, or -1 if unknown. |
| 127 long fileSize; |
| 128 |
| 129 // Whether the downloaded file still exists. This information may be out of |
| 130 // date because Chrome does not automatically watch for file removal. Call |
| 131 // $ref:search() in order to trigger the check for file existence. When the |
| 132 // existence check completes, if the file has been deleted, then an |
| 133 // $ref:onChanged event will fire. Note that $ref:search() does not wait |
| 134 // for the existence check to finish before returning, so results from |
| 135 // $ref:search() may not accurately reflect the file system. Also, |
| 136 // $ref:search() may be called as often as necessary, but will not check for |
| 137 // file existence any more frequently than once every 10 seconds. |
| 138 boolean exists; |
| 139 }; |
| 140 |
| 141 [inline_doc] dictionary DownloadQuery { |
| 142 // This space-separated string of search terms that may be grouped using |
| 143 // quotation marks limits results to |
| 144 // $ref:DownloadItem whose <code>filename</code> |
| 145 // or <code>url</code> contain all of the search terms that do not begin wit
h a dash '-' |
| 146 // and none of the search terms that do begin with a dash. |
| 147 DOMString? query; |
| 148 |
| 149 // Limits results to $ref:DownloadItem that |
| 150 // started before the given ms since the epoch. |
| 151 DOMString? startedBefore; |
| 152 |
| 153 // Limits results to $ref:DownloadItem that |
| 154 // started after the given ms since the epoch. |
| 155 DOMString? startedAfter; |
| 156 |
| 157 // Limits results to $ref:DownloadItem that ended before the given ms since
the |
| 158 // epoch. |
| 159 DOMString? endedBefore; |
| 160 |
| 161 // Limits results to $ref:DownloadItem that ended after the given ms since t
he |
| 162 // epoch. |
| 163 DOMString? endedAfter; |
| 164 |
| 165 // Limits results to $ref:DownloadItem whose |
| 166 // <code>totalBytes</code> is greater than the given integer. |
| 167 long? totalBytesGreater; |
| 168 |
| 169 // Limits results to $ref:DownloadItem whose |
| 170 // <code>totalBytes</code> is less than the given integer. |
| 171 long? totalBytesLess; |
| 172 |
| 173 // Limits results to $ref:DownloadItem whose |
| 174 // <code>filename</code> matches the given regular expression. |
| 175 DOMString? filenameRegex; |
| 176 |
| 177 // Limits results to $ref:DownloadItem whose |
| 178 // <code>url</code> matches the given regular expression. |
| 179 DOMString? urlRegex; |
| 180 |
| 181 // Setting this integer limits the number of results. Otherwise, all |
| 182 // matching $ref:DownloadItem will be returned. |
| 183 long? limit; |
| 184 |
| 185 // Setting this string to a $ref:DownloadItem |
| 186 // property sorts the $ref:DownloadItem prior |
| 187 // to applying the above filters. For example, setting |
| 188 // <code>orderBy='startTime'</code> sorts the |
| 189 // $ref:DownloadItem by their start time in |
| 190 // ascending order. To specify descending order, prefix <code>orderBy</code> |
| 191 // with a hyphen: '-startTime'. |
| 192 DOMString? orderBy; |
| 193 |
| 194 // The <code>id</code> of the $ref:DownloadItem |
| 195 // that changed. |
| 196 long? id; |
| 197 |
| 198 // Absolute URL. |
| 199 DOMString? url; |
| 200 |
| 201 // Absolute local path. |
| 202 DOMString? filename; |
| 203 |
| 204 // Indication of whether this download is thought to be safe or known to be |
| 205 // suspicious. |
| 206 DangerType? danger; |
| 207 |
| 208 // True if the user has accepted the download's danger. |
| 209 boolean? dangerAccepted; |
| 210 |
| 211 // The file's MIME type. |
| 212 DOMString? mime; |
| 213 |
| 214 // The time when the download began in ISO 8601 format. |
| 215 DOMString? startTime; |
| 216 |
| 217 // The time when the download ended in ISO 8601 format. |
| 218 DOMString? endTime; |
| 219 |
| 220 // Indicates whether the download is progressing, interrupted, or complete. |
| 221 State? state; |
| 222 |
| 223 // True if the download has stopped reading data from the host, but kept the |
| 224 // connection open. |
| 225 boolean? paused; |
| 226 |
| 227 // Number indicating why a download was interrupted. |
| 228 long? error; |
| 229 |
| 230 // Number of bytes received so far from the host, without considering file |
| 231 // compression. |
| 232 long? bytesReceived; |
| 233 |
| 234 // Number of bytes in the whole file, without considering file compression, |
| 235 // or -1 if unknown. |
| 236 long? totalBytes; |
| 237 |
| 238 // Number of bytes in the whole file post-decompression, or -1 if unknown. |
| 239 long? fileSize; |
| 240 |
| 241 // Whether the downloaded file exists; |
| 242 boolean? exists; |
| 243 }; |
| 244 |
| 245 [inline_doc] dictionary DownloadStringDiff { |
| 246 DOMString? previous; |
| 247 DOMString? current; |
| 248 }; |
| 249 |
| 250 [inline_doc] dictionary DownloadLongDiff { |
| 251 long? previous; |
| 252 long? current; |
| 253 }; |
| 254 |
| 255 [inline_doc] dictionary DownloadBooleanDiff { |
| 256 boolean? previous; |
| 257 boolean? current; |
| 258 }; |
| 259 |
| 260 // Encapsulates a change in a DownloadItem. |
| 261 [inline_doc] dictionary DownloadDelta { |
| 262 // An identifier that is persistent across browser sessions. |
| 263 long id; |
| 264 |
| 265 // The change in <code>url</code>, if any. |
| 266 DownloadStringDiff? url; |
| 267 |
| 268 // The change in <code>filename</code>, if any. |
| 269 DownloadStringDiff? filename; |
| 270 |
| 271 // The change in <code>danger</code>, if any. |
| 272 DownloadStringDiff? danger; |
| 273 |
| 274 // The change in <code>dangerAccepted</code>, if any. |
| 275 DownloadBooleanDiff? dangerAccepted; |
| 276 |
| 277 // The change in <code>mime</code>, if any. |
| 278 DownloadStringDiff? mime; |
| 279 |
| 280 // The change in <code>startTime</code>, if any. |
| 281 DownloadStringDiff? startTime; |
| 282 |
| 283 // The change in <code>endTime</code>, if any. |
| 284 DownloadStringDiff? endTime; |
| 285 |
| 286 // The change in <code>state</code>, if any. |
| 287 DownloadStringDiff? state; |
| 288 |
| 289 // The change in <code>paused</code>, if any. |
| 290 DownloadBooleanDiff? paused; |
| 291 |
| 292 // The change in <code>error</code>, if any. |
| 293 DownloadLongDiff? error; |
| 294 |
| 295 // The change in <code>totalBytes</code>, if any. |
| 296 DownloadLongDiff? totalBytes; |
| 297 |
| 298 // The change in <code>fileSize</code>, if any. |
| 299 DownloadLongDiff? fileSize; |
| 300 |
| 301 // The change in <code>exists</code>, if any. |
| 302 DownloadBooleanDiff? exists; |
| 303 }; |
| 304 |
| 305 [inline_doc] dictionary GetFileIconOptions { |
| 306 // 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. |
| 308 [legalValues=(16,32)] long? size; |
| 309 }; |
| 310 |
| 311 callback DownloadCallback = void(long downloadId); |
| 312 callback SearchCallback = void(DownloadItem[] results); |
| 313 callback EraseCallback = void(long[] erasedIds); |
| 314 callback NullCallback = void(); |
| 315 callback GetFileIconCallback = void(optional DOMString iconURL); |
| 316 |
| 317 interface Functions { |
| 318 // 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 |
| 320 // <code>filename</code> and <code>saveAs</code> are specified, then the |
| 321 // Save As dialog will be displayed, pre-populated with the specified |
| 322 // <code>filename</code>. If the download started successfully, |
| 323 // <code>callback</code> will be called with the new $ref:DownloadItem's |
| 324 // <code>downloadId</code>. If there was an error starting the download, |
| 325 // then <code>callback</code> will be called with |
| 326 // <code>downloadId=undefined</code> and |
| 327 // $ref:runtime.lastError |
| 328 // will contain a descriptive string. The error strings are not guaranteed |
| 329 // to remain backwards compatible between releases. You must not parse it. |
| 330 // |options|: What to download and how. |
| 331 // |callback|: Called with the id of the new $ref:DownloadItem. |
| 332 static void download(DownloadOptions options, |
| 333 optional DownloadCallback callback); |
| 334 |
| 335 // Find $ref:DownloadItem. Set |
| 336 // <code>query</code> to the empty object to get all |
| 337 // $ref:DownloadItem. To get a specific |
| 338 // $ref:DownloadItem, set only the <code>id</code> |
| 339 // field. |
| 340 static void search(DownloadQuery query, SearchCallback callback); |
| 341 |
| 342 // Pause the download. If the request was successful the download is in a |
| 343 // paused state. Otherwise |
| 344 // $ref:runtime.lastError |
| 345 // contains an error message. The request will fail if the download is not |
| 346 // active. |
| 347 // |downloadId|: The id of the download to pause. |
| 348 // |callback|: Called when the pause request is completed. |
| 349 static void pause(long downloadId, optional NullCallback callback); |
| 350 |
| 351 // Resume a paused download. If the request was successful the download is |
| 352 // in progress and unpaused. Otherwise |
| 353 // $ref:runtime.lastError |
| 354 // contains an error message. The request will fail if the download is not |
| 355 // active. |
| 356 // |downloadId|: The id of the download to resume. |
| 357 // |callback|: Called when the resume request is completed. |
| 358 static void resume(long downloadId, optional NullCallback callback); |
| 359 |
| 360 // Cancel a download. When <code>callback</code> is run, the download is |
| 361 // cancelled, completed, interrupted or doesn't exist anymore. |
| 362 // |downloadId|: The id of the download to cancel. |
| 363 // |callback|: Called when the cancel request is completed. |
| 364 static void cancel(long downloadId, optional NullCallback callback); |
| 365 |
| 366 // Retrieve an icon for the specified download. For new downloads, file |
| 367 // icons are available after the $ref:onCreated |
| 368 // event has been received. The image returned by this function while a |
| 369 // download is in progress may be different from the image returned after |
| 370 // the download is complete. Icon retrieval is done by querying the |
| 371 // underlying operating system or toolkit depending on the platform. The |
| 372 // icon that is returned will therefore depend on a number of factors |
| 373 // including state of the download, platform, registered file types and |
| 374 // visual theme. If a file icon cannot be determined, |
| 375 // $ref:runtime.lastError |
| 376 // will contain an error message. |
| 377 // |downloadId|: The identifier for the download. |
| 378 // |callback|: A URL to an image that represents the download. |
| 379 static void getFileIcon(long downloadId, |
| 380 optional GetFileIconOptions options, |
| 381 GetFileIconCallback callback); |
| 382 |
| 383 // Open the downloaded file now if the $ref:DownloadItem is complete; |
| 384 // returns an error through $ref:runtime.lastError otherwise. An |
| 385 // $ref:onChanged event will fire when the item is opened for the first |
| 386 // time. |
| 387 // |downloadId|: The identifier for the downloaded file. |
| 388 static void open(long downloadId); |
| 389 |
| 390 // Show the downloaded file in its folder in a file manager. |
| 391 // |downloadId|: The identifier for the downloaded file. |
| 392 static void show(long downloadId); |
| 393 |
| 394 // Erase matching $ref:DownloadItem from history. An $ref:onErased event |
| 395 // will fire for each $ref:DownloadItem that matches <code>query</code>, |
| 396 // then <code>callback</code> will be called. |
| 397 static void erase(DownloadQuery query, optional EraseCallback callback); |
| 398 |
| 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 |
| 403 // accept dangerous downloads. If the download is accepted, then an |
| 404 // $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 |
| 406 // dangerous or the danger has been accepted, then the temporary file is |
| 407 // renamed to the target filename, the |state| changes to 'complete', and |
| 408 // $ref:onChanged fires. |
| 409 // |downloadId|: The identifier for the $ref:DownloadItem. |
| 410 static void acceptDanger(long downloadId); |
| 411 |
| 412 // Initiate dragging the downloaded file to another application. |
| 413 static void drag(long downloadId); |
| 414 }; |
| 415 |
| 416 interface Events { |
| 417 // This event fires with the $ref:DownloadItem |
| 418 // object when a download begins. |
| 419 static void onCreated(DownloadItem downloadItem); |
| 420 |
| 421 // Fires with the <code>downloadId</code> when a download is erased from |
| 422 // history. |
| 423 // |downloadId|: The <code>id</code> of the $ref:DownloadItem that was erase
d. |
| 424 static void onErased(long downloadId); |
| 425 |
| 426 // When any of a $ref:DownloadItem's properties |
| 427 // except <code>bytesReceived</code> changes, this event fires with the |
| 428 // <code>downloadId</code> and an object containing the properties that chan
ged. |
| 429 static void onChanged(DownloadDelta downloadDelta); |
| 430 }; |
| 431 }; |
| OLD | NEW |