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>safe</dt> |
| 51 // <dd>The download presents no known danger to the user's computer.</dd> |
| 52 // </dl> |
| 53 // These string constants will never change, however the set of DangerTypes |
| 54 // may change. |
| 55 enum DangerType {file, url, content, uncommon, safe}; |
| 56 |
| 57 // <dl><dt>in_progress</dt> |
| 58 // <dd>The download is currently receiving data from the server.</dd> |
| 59 // <dt>interrupted</dt> |
| 60 // <dd>An error broke the connection with the file host.</dd> |
| 61 // <dt>complete</dt> |
| 62 // <dd>The download completed successfully.</dd> |
| 63 // </dl> |
| 64 // These string constants will never change, however the set of States may |
| 65 // change. |
| 66 enum State {in_progress, interrupted, complete}; |
| 67 |
| 68 // The state of the process of downloading a file. |
| 69 dictionary DownloadItem { |
| 70 // An identifier that is persistent across browser sessions. |
| 71 long id; |
| 72 |
| 73 // Absolute URL. |
| 74 DOMString url; |
| 75 |
| 76 // Absolute local path. |
| 77 DOMString filename; |
| 78 |
| 79 // False if this download is recorded in the history, true if it is not |
| 80 // recorded. |
| 81 boolean incognito; |
| 82 |
| 83 // Indication of whether this download is thought to be safe or known to be |
| 84 // suspicious. |
| 85 DangerType danger; |
| 86 |
| 87 // True if the user has accepted the download's danger. |
| 88 boolean? dangerAccepted; |
| 89 |
| 90 // The file's MIME type. |
| 91 DOMString mime; |
| 92 |
| 93 // Number of milliseconds between the unix epoch and when this download |
| 94 // began. |
| 95 long startTime; |
| 96 |
| 97 // Number of milliseconds between the unix epoch and when this download |
| 98 // ended. |
| 99 long? endTime; |
| 100 |
| 101 // Indicates whether the download is progressing, interrupted, or complete. |
| 102 State state; |
| 103 |
| 104 // True if the download has stopped reading data from the host, but kept the |
| 105 // connection open. |
| 106 boolean paused; |
| 107 |
| 108 // Number indicating why a download was interrupted. |
| 109 long? error; |
| 110 |
| 111 // Number of bytes received so far from the host, without considering file |
| 112 // compression. |
| 113 long bytesReceived; |
| 114 |
| 115 // Number of bytes in the whole file, without considering file compression, |
| 116 // or -1 if unknown. |
| 117 long totalBytes; |
| 118 |
| 119 // Number of bytes in the whole file post-decompression, or -1 if unknown. |
| 120 long fileSize; |
| 121 }; |
| 122 |
| 123 [inline_doc] dictionary DownloadQuery { |
| 124 // This space-separated string of search terms that may be grouped using |
| 125 // quotation marks limits results to <a |
| 126 // href='#type-DownloadItem'>DownloadItems</a> whose <code>filename</code> |
| 127 // or <code>url</code> contain all of the search terms that do not begin wit
h a dash '-' |
| 128 // and none of the search terms that do begin with a dash. |
| 129 DOMString? query; |
| 130 |
| 131 // Limits results to <a href='#type-DownloadItem'>DownloadItems</a> that |
| 132 // started before the given ms since the epoch. |
| 133 long? startedBefore; |
| 134 |
| 135 // Limits results to <a href='#type-DownloadItem'>DownloadItems</a> that |
| 136 // started after the given ms since the epoch. |
| 137 long? startedAfter; |
| 138 |
| 139 // Limits results to <a href='#type-DownloadItem'>DownloadItems</a> that end
ed before the given ms since the |
| 140 // epoch. |
| 141 long? endedBefore; |
| 142 |
| 143 // Limits results to <a href='#type-DownloadItem'>DownloadItems</a> that end
ed after the given ms since the |
| 144 // epoch. |
| 145 long? endedAfter; |
| 146 |
| 147 // Limits results to <a href='#type-DownloadItem'>DownloadItems</a> whose |
| 148 // <code>totalBytes</code> is greater than the given integer. |
| 149 long? totalBytesGreater; |
| 150 |
| 151 // Limits results to <a href='#type-DownloadItem'>DownloadItems</a> whose |
| 152 // <code>totalBytes</code> is less than the given integer. |
| 153 long? totalBytesLess; |
| 154 |
| 155 // Limits results to <a href='#type-DownloadItem'>DownloadItems</a> whose |
| 156 // <code>filename</code> matches the given regular expression. |
| 157 DOMString? filenameRegex; |
| 158 |
| 159 // Limits results to <a href='#type-DownloadItem'>DownloadItems</a> whose |
| 160 // <code>url</code> matches the given regular expression. |
| 161 DOMString? urlRegex; |
| 162 |
| 163 // Setting this integer limits the number of results. Otherwise, all |
| 164 // matching <a href='#type-DownloadItem'>DownloadItems</a> will be returned. |
| 165 long? limit; |
| 166 |
| 167 // Setting this string to a <a href='#type-DownloadItem'>DownloadItem</a> |
| 168 // property sorts the <a href='#type-DownloadItem'>DownloadItems</a> prior |
| 169 // to applying the above filters. For example, setting |
| 170 // <code>orderBy='startTime'</code> sorts the <a |
| 171 // href='#type-DownloadItem'>DownloadItems</a> by their start time in |
| 172 // ascending order. To specify descending order, prefix <code>orderBy</code> |
| 173 // with a hyphen: '-startTime'. |
| 174 DOMString? orderBy; |
| 175 |
| 176 // The <code>id</code> of the <a href="#type-DownloadItem">DownloadItem</a> |
| 177 // that changed. |
| 178 long? id; |
| 179 |
| 180 // Absolute URL. |
| 181 DOMString? url; |
| 182 |
| 183 // Absolute local path. |
| 184 DOMString? filename; |
| 185 |
| 186 // Indication of whether this download is thought to be safe or known to be |
| 187 // suspicious. |
| 188 DangerType? danger; |
| 189 |
| 190 // True if the user has accepted the download's danger. |
| 191 boolean? dangerAccepted; |
| 192 |
| 193 // The file's MIME type. |
| 194 DOMString? mime; |
| 195 |
| 196 // Number of milliseconds between the unix epoch and when this download |
| 197 // began. |
| 198 long? startTime; |
| 199 |
| 200 // Number of milliseconds between the unix epoch and when this download |
| 201 // ended. |
| 202 long? endTime; |
| 203 |
| 204 // Indicates whether the download is progressing, interrupted, or complete. |
| 205 State? state; |
| 206 |
| 207 // True if the download has stopped reading data from the host, but kept the |
| 208 // connection open. |
| 209 boolean? paused; |
| 210 |
| 211 // Number indicating why a download was interrupted. |
| 212 long? error; |
| 213 |
| 214 // Number of bytes received so far from the host, without considering file |
| 215 // compression. |
| 216 long? bytesReceived; |
| 217 |
| 218 // Number of bytes in the whole file, without considering file compression, |
| 219 // or -1 if unknown. |
| 220 long? totalBytes; |
| 221 |
| 222 // Number of bytes in the whole file post-decompression, or -1 if unknown. |
| 223 long? fileSize; |
| 224 }; |
| 225 |
| 226 [inline_doc] dictionary DownloadStringDiff { |
| 227 DOMString? previous; |
| 228 DOMString? current; |
| 229 }; |
| 230 |
| 231 [inline_doc] dictionary DownloadLongDiff { |
| 232 long? previous; |
| 233 long? current; |
| 234 }; |
| 235 |
| 236 [inline_doc] dictionary DownloadBooleanDiff { |
| 237 boolean? previous; |
| 238 boolean? current; |
| 239 }; |
| 240 |
| 241 // Encapsulates a change in a DownloadItem. |
| 242 [inline_doc] dictionary DownloadDelta { |
| 243 // An identifier that is persistent across browser sessions. |
| 244 long id; |
| 245 |
| 246 // The change in <code>url</code>, if any. |
| 247 DownloadStringDiff? url; |
| 248 |
| 249 // The change in <code>filename</code>, if any. |
| 250 DownloadStringDiff? filename; |
| 251 |
| 252 // The change in <code>danger</code>, if any. |
| 253 DownloadStringDiff? danger; |
| 254 |
| 255 // The change in <code>dangerAccepted</code>, if any. |
| 256 DownloadBooleanDiff? dangerAccepted; |
| 257 |
| 258 // The change in <code>mime</code>, if any. |
| 259 DownloadStringDiff? mime; |
| 260 |
| 261 // The change in <code>startTime</code>, if any. |
| 262 DownloadLongDiff? startTime; |
| 263 |
| 264 // The change in <code>endTime</code>, if any. |
| 265 DownloadLongDiff? endTime; |
| 266 |
| 267 // The change in <code>state</code>, if any. |
| 268 DownloadStringDiff? state; |
| 269 |
| 270 // The change in <code>paused</code>, if any. |
| 271 DownloadBooleanDiff? paused; |
| 272 |
| 273 // The change in <code>error</code>, if any. |
| 274 DownloadLongDiff? error; |
| 275 |
| 276 // The change in <code>totalBytes</code>, if any. |
| 277 DownloadLongDiff? totalBytes; |
| 278 |
| 279 // The change in <code>fileSize</code>, if any. |
| 280 DownloadLongDiff? fileSize; |
| 281 }; |
| 282 |
| 283 [inline_doc] dictionary GetFileIconOptions { |
| 284 // The size of the icon. The returned icon will be square with dimensions |
| 285 // size * size pixels. The default size for the icon is 32x32 pixels. |
| 286 [legalValues=(16,32)] long? size; |
| 287 }; |
| 288 |
| 289 callback DownloadCallback = void(long downloadId); |
| 290 callback SearchCallback = void(DownloadItem[] results); |
| 291 callback EraseCallback = void(long[] erasedIds); |
| 292 callback NullCallback = void(); |
| 293 callback GetFileIconCallback = void(optional DOMString iconURL); |
| 294 |
| 295 interface Functions { |
| 296 // Download a URL. If the URL uses the HTTP[S] protocol, then the request |
| 297 // will include all cookies currently set for its hostname. If both |
| 298 // <code>filename</code> and <code>saveAs</code> are specified, then the |
| 299 // Save As dialog will be displayed, pre-populated with the specified |
| 300 // <code>filename</code>. If the download started successfully, |
| 301 // <code>callback</code> will be called with the new <a href='#type-Download
Item'>DownloadItem</a>'s |
| 302 // <code>downloadId</code>. If there was an error starting the download, |
| 303 // then <code>callback</code> will be called with |
| 304 // <code>downloadId=undefined</code> and <a |
| 305 // href='extension.html#property-lastError'>chrome.extension.lastError</a> |
| 306 // will contain a descriptive string. The error strings are not guaranteed |
| 307 // to remain backwards compatible between releases. You must not parse it. |
| 308 // |options|: What to download and how. |
| 309 // |callback|: Called with the id of the new <a href='#type-DownloadItem'>Do
wnloadItem</a>. |
| 310 static void download(DownloadOptions options, |
| 311 optional DownloadCallback callback); |
| 312 |
| 313 // Find <a href='#type-DownloadItem'>DownloadItems</a>. Set |
| 314 // <code>query</code> to the empty object to get all <a |
| 315 // href='#type-DownloadItem'>DownloadItems</a>. To get a specific <a |
| 316 // href='#type-DownloadItem'>DownloadItem</a>, set only the <code>id</code> |
| 317 // field. |
| 318 static void search(DownloadQuery query, SearchCallback callback); |
| 319 |
| 320 // Pause the download. If the request was successful the download is in a |
| 321 // paused state. Otherwise <a |
| 322 // href='extension.html#property-lastError'>chrome.extension.lastError</a> |
| 323 // contains an error message. The request will fail if the download is not |
| 324 // active. |
| 325 // |downloadId|: The id of the download to pause. |
| 326 // |callback|: Called when the pause request is completed. |
| 327 static void pause(long downloadId, optional NullCallback callback); |
| 328 |
| 329 // Resume a paused download. If the request was successful the download is |
| 330 // in progress and unpaused. Otherwise <a |
| 331 // href='extension.html#property-lastError'>chrome.extension.lastError</a> |
| 332 // contains an error message. The request will fail if the download is not |
| 333 // active. |
| 334 // |downloadId|: The id of the download to resume. |
| 335 // |callback|: Called when the resume request is completed. |
| 336 static void resume(long downloadId, optional NullCallback callback); |
| 337 |
| 338 // Cancel a download. When <code>callback</code> is run, the download is |
| 339 // cancelled, completed, interrupted or doesn't exist anymore. |
| 340 // |downloadId|: The id of the download to cancel. |
| 341 // |callback|: Called when the cancel request is completed. |
| 342 static void cancel(long downloadId, optional NullCallback callback); |
| 343 |
| 344 // Retrieve an icon for the specified download. For new downloads, file |
| 345 // icons are available after the <a href='#event-onCreated'>onCreated</a> |
| 346 // event has been received. The image returned by this function while a |
| 347 // download is in progress may be different from the image returned after |
| 348 // the download is complete. Icon retrieval is done by querying the |
| 349 // underlying operating system or toolkit depending on the platform. The |
| 350 // icon that is returned will therefore depend on a number of factors |
| 351 // including state of the download, platform, registered file types and |
| 352 // visual theme. If a file icon cannot be determined, <a |
| 353 // href='extension.html#property-lastError'>chrome.extension.lastError</a> |
| 354 // will contain an error message. |
| 355 // |downloadId|: The identifier for the download. |
| 356 // |callback|: A URL to an image that represents the download. |
| 357 static void getFileIcon(long downloadId, |
| 358 optional GetFileIconOptions options, |
| 359 GetFileIconCallback callback); |
| 360 |
| 361 // Erase matching <a href='#type-DownloadItem'>DownloadItems</a> from |
| 362 // history |
| 363 [nodoc] static void erase(DownloadQuery query, |
| 364 optional EraseCallback callback); |
| 365 |
| 366 // TODO(benjhayden) Comment. |
| 367 [nodoc] static void setDestination(long downloadId, DOMString relativePath); |
| 368 |
| 369 // Prompt the user to either accept or cancel a dangerous download. |
| 370 // <code>acceptDanger()</code> does not automatically accept dangerous |
| 371 // downloads. |
| 372 [nodoc] static void acceptDanger(long downloadId); |
| 373 |
| 374 // Show the downloaded file in its folder in a file manager. |
| 375 [nodoc] static void show(long downloadId); |
| 376 |
| 377 // Open the downloaded file. |
| 378 [nodoc] static void open(long downloadId); |
| 379 |
| 380 // Initiate dragging the file to another application. |
| 381 [nodoc] static void drag(long downloadId); |
| 382 }; |
| 383 |
| 384 interface Events { |
| 385 // This event fires with the <a href='#type-DownloadItem'>DownloadItem</a> |
| 386 // object when a download begins. |
| 387 static void onCreated(DownloadItem downloadItem); |
| 388 |
| 389 // Fires with the <code>downloadId</code> when a download is erased from |
| 390 // history. |
| 391 // |downloadId|: The <code>id</code> of the <a href='#type-DownloadItem'>Dow
nloadItem</a> that was erased. |
| 392 static void onErased(long downloadId); |
| 393 |
| 394 // When any of a <a href='#type-DownloadItem'>DownloadItem</a>'s properties |
| 395 // except <code>bytesReceived</code> changes, this event fires with the |
| 396 // <code>downloadId</code> and an object containing the properties that chan
ged. |
| 397 static void onChanged(DownloadDelta downloadDelta); |
| 398 }; |
| 399 }; |
OLD | NEW |