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