!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 //@line 42 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/mozapps/downloads/content/DownloadProgressListener.js"
2
3 /**
4 * DownloadProgressListener "class" is used to help update download items shown
5 * in the Download Manager UI such as displaying amount transferred, transfer
6 * rate, and time left for each download.
7 *
8 * This class implements the nsIDownloadProgressListener interface.
9 */
DownloadProgressListener
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
10 function DownloadProgressListener() {}
11
12 DownloadProgressListener.prototype = {
13 //////////////////////////////////////////////////////////////////////////////
14 //// nsISupports
15
16 QueryInterface: XPCOMUtils.generateQI([Ci.nsIDownloadProgressListener]),
17
18 //////////////////////////////////////////////////////////////////////////////
19 //// nsIDownloadProgressListener
20
dlPL_onDownloadStateChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
21 onDownloadStateChange: function dlPL_onDownloadStateChange(aState, aDownload)
22 {
23 // Update window title in-case we don't get all progress notifications
24 onUpdateProgress();
25
26 let state = aDownload.state;
27 switch (state) {
28 case nsIDM.DOWNLOAD_QUEUED:
29 prependList(aDownload);
30 break;
31
32 case nsIDM.DOWNLOAD_BLOCKED_POLICY:
33 prependList(aDownload);
34 // Should fall through, this is a final state but DOWNLOAD_QUEUED
35 // is skipped. See nsDownloadManager::AddDownload.
36 case nsIDM.DOWNLOAD_FAILED:
37 case nsIDM.DOWNLOAD_CANCELED:
38 case nsIDM.DOWNLOAD_BLOCKED_PARENTAL:
39 case nsIDM.DOWNLOAD_DIRTY:
40 case nsIDM.DOWNLOAD_FINISHED:
41 downloadCompleted(aDownload);
42 if (state == nsIDM.DOWNLOAD_FINISHED)
43 autoRemoveAndClose(aDownload);
44 break;
45 }
46
47 // autoRemoveAndClose could have already closed our window...
48 try {
49 let dl = getDownload(aDownload.id);
50
51 // We should eventually know the referrer at some point
52 let referrer = aDownload.referrer;
53 if (referrer)
54 dl.setAttribute("referrer", referrer.spec);
55
56 // Update to the new state
57 dl.setAttribute("state", state);
58
59 // Update ui text values after switching states
60 updateTime(dl);
61 updateStatus(dl);
62 updateButtons(dl);
63 } catch (e) { }
64 },
65
onProgressChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
66 onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress,
67 aMaxSelfProgress, aCurTotalProgress,
68 aMaxTotalProgress, aDownload)
69 {
70 var download = getDownload(aDownload.id);
71
72 // Update this download's progressmeter
73 if (aDownload.percentComplete == -1) {
74 download.setAttribute("progressmode", "undetermined");
75 } else {
76 download.setAttribute("progressmode", "normal");
77 download.setAttribute("progress", aDownload.percentComplete);
78 }
79
80 // Dispatch ValueChange for a11y
81 var event = document.createEvent("Events");
82 event.initEvent("ValueChange", true, true);
83 document.getAnonymousElementByAttribute(download, "anonid", "progressmeter")
84 .dispatchEvent(event);
85
86 // Update the progress so the status can be correctly updated
87 download.setAttribute("currBytes", aDownload.amountTransferred);
88 download.setAttribute("maxBytes", aDownload.size);
89
90 // Update the rest of the UI (bytes transferred, bytes total, download rate,
91 // time remaining).
92 updateStatus(download, aDownload);
93
94 // Update window title
95 onUpdateProgress();
96 },
97
onStateChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
98 onStateChange: function(aWebProgress, aRequest, aState, aStatus, aDownload)
99 {
100 },
101
onSecurityChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
102 onSecurityChange: function(aWebProgress, aRequest, aState, aDownload)
103 {
104 }
105 };