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