Bug 485624 - Downloads in progress for previous releases should be canceled on startu...
[mozilla-1.9.git] / toolkit / mozapps / update / content / updates.xml
blob07c23fff33606d89eeb4c8826b517fd71cfbf652
1 <?xml version="1.0"?>
3 <!DOCTYPE bindings SYSTEM "chrome://mozapps/locale/update/updates.dtd">
5 <bindings id="updatesBindings"
6           xmlns="http://www.mozilla.org/xbl"
7           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
8           xmlns:xbl="http://www.mozilla.org/xbl">
9   
10   <binding id="license">
11     <content>
12       <xul:vbox flex="1" class="loadingBox">
13         <xul:hbox align="start">
14           <xul:image class="licenseLoadingThrobber" xbl:inherits="state"/>
15           <xul:vbox flex="1">
16             <xul:description flex="1" class="licenseLoadingMessage" crop="right"/>
17           </xul:vbox>
18         </xul:hbox>
19       </xul:vbox>
20       <xul:vbox flex="1">
21         <xul:browser class="licenseContent" type="content" flex="1"/>
22       </xul:vbox>
23       <xul:stringbundle anonid="strings" 
24                         src="chrome://mozapps/locale/update/updates.properties"/>
25     </content>
26     <implementation>
27       <constructor><![CDATA[
28         // just to be safe, turn off js, auth, plugins, and subframes
29         var docShell = this._content.docShell;
30         docShell.allowJavascript = false;
31         docShell.allowAuth = false;
32         docShell.allowPlugins = false;
33         //allow redirects
34         //docShell.allowMetaRedirects = false;
35         docShell.allowSubframes = false;
36         //allow images
37         //docShell.allowImages = false;
38       ]]></constructor>
40       <destructor><![CDATA[
41         // clean up the listener
42         // but you may not have one if you never showed the page with
43         // a <license> element
44         if (this._licenseProgressListener) 
45           this._content.webProgress
46               .removeProgressListener(this._licenseProgressListener);
47       ]]></destructor>
49       <field name="_message">
50         document.getAnonymousElementByAttribute(this, "class", "licenseLoadingMessage");
51       </field>
52       <field name="_content">
53         document.getAnonymousElementByAttribute(this, "class", "licenseContent");
54       </field>
55       <field name="_strings">
56         document.getAnonymousElementByAttribute(this, "anonid", "strings");
57       </field>
58       
59       <field name="update_name">null</field>
60       <field name="update_version">null</field>
61       <field name="_licenseProgressListener">null</field>
63       <method name="_setMessageValue">
64         <parameter name="value"/>
65         <body><![CDATA[
66           while (this._message.hasChildNodes())
67             this._message.removeChild(this._message.firstChild);
68           this._message.appendChild(document.createTextNode(value));
69         ]]></body>
70       </method>
72       <method name="onError">
73         <body><![CDATA[
74           this.setAttribute("selectedIndex", "0");
76           var errorPropertyName = this.getAttribute("id") + "NotFound";
77           var statusText = this._strings.getFormattedString(errorPropertyName, 
78                                                             [this.update_name]);
79           this._setMessageValue(statusText);
80           this.setAttribute("state", "error");
81         ]]></body>
82       </method>
84       <method name="onLoad">
85         <body><![CDATA[
86           this.setAttribute("selectedIndex", "1");
88           var e = document.createEvent("Events");
89           e.initEvent("load", false, true);
90           this.dispatchEvent(e);
91         ]]></body>
92       </method>
94       <method name="onStart">
95         <body><![CDATA[
96           this.setAttribute("selectedIndex", "0");
98           this.setAttribute("state", "loading");
99           var loadingPropertyName = this.getAttribute("id") + "Downloading";
100           this._setMessageValue(this._strings.getFormattedString(
101             loadingPropertyName, [this.update_name, this.update_version]));
102         ]]></body>
103       </method>
105       <property name="url">
106         <getter><![CDATA[
107           return this.getAttribute("url");
108         ]]></getter>
109         <setter><![CDATA[
110           var self = this;
112           this._licenseProgressListener = {
113             QueryInterface: function(aIID) 
114             {
115               if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
116                   aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
117                   aIID.equals(Components.interfaces.nsISupports))
118                 return this;
119               throw Components.results.NS_NOINTERFACE;
120             },
121             onLocationChange: function() {},
122             onProgressChange: function() {},
123             onStatusChange:   function() {},
124             onSecurityChange: function() {},
125             onStateChange:    function(aWebProgress, aRequest, 
126                                        aStateFlags, aStatus) 
127             {
128               if (!aRequest)
129                 return;
131               const nsIWebProgressListener = 
132                 Components.interfaces.nsIWebProgressListener;
134               if (aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) 
135               {
136                 if (aStateFlags & nsIWebProgressListener.STATE_START) 
137                   self.onStart();
138                 else if (aStateFlags & nsIWebProgressListener.STATE_STOP)
139                 {
140                   const nsIHttpChannel = Components.interfaces.nsIHttpChannel;
141                   try {
142                     var channel = aRequest.QueryInterface(nsIHttpChannel);
143                     if (channel.requestSucceeded) 
144                     {
145                       // if we get here, the load was OK, report success
146                       self.onLoad();
147                       return;
148                     }
149                   }
150                   catch (ex) 
151                   { 
152                     // the channel.requestSucceeded can throw 
153                     // NS_ERROR_NOT_AVAILABLE if you can't reach the server
154                     // so we treat that as an error
155                   }
157                   // everything else (like a 404) is an error
158                   self.onError();
159                 }
160               }
161             }
162           }
164           this._content.webProgress
165               .addProgressListener(this._licenseProgressListener,
166                Components.interfaces.nsIWebProgress.NOTIFY_ALL);
168           // load the url now that the listener is registered
169           this._content.setAttribute("src", val);
170         ]]></setter>
171       </property>
172       
173       <method name="stopDownloading">
174         <body><![CDATA[
175           this._content.stop();
176         ]]></body>
177       </method>
178     </implementation>
179   </binding>
180   
181   <binding id="update" extends="chrome://global/content/bindings/richlistbox.xml#richlistitem">
182     <content>
183       <xul:hbox>
184         <xul:label class="update-name" xbl:inherits="value=name" flex="1" crop="right"/>
185         <xul:label xbl:inherits="href=detailsURL" class="text-link"
186                    value="&update.details.label;"/>
187       </xul:hbox>
188       <xul:label class="update-type" xbl:inherits="value=type"/>
189       <xul:grid>
190         <xul:columns>
191           <xul:column class="update-label-column"/>
192           <xul:column flex="1"/>
193         </xul:columns>
194         <xul:rows>
195           <xul:row>
196             <xul:label class="update-installedOn-label">&update.installedOn.label;</xul:label>
197             <xul:label class="update-installedOn-value" xbl:inherits="value=installDate" flex="1" crop="right"/>
198           </xul:row>
199           <xul:row>
200             <xul:label class="update-status-label">&update.status.label;</xul:label>
201             <xul:description class="update-status-value" flex="1"/>
202           </xul:row>
203         </xul:rows>
204       </xul:grid>
205     </content>
206     <implementation>
207       <property name="name"
208                 onget="return this.getAttribute('name');"
209                 onset="this.setAttribute('name', val); return val;"/>
210       <property name="detailsURL"
211                 onget="return this.getAttribute('detailsURL');"
212                 onset="this.setAttribute('detailsURL', val); return val;"/>
213       <property name="installDate"
214                 onget="return this.getAttribute('installDate');"
215                 onset="this.setAttribute('installDate', val); return val;"/>
216       <property name="type"
217                 onget="return this.getAttribute('type');"
218                 onset="this.setAttribute('type', val); return val;"/>
219       <property name="status"
220                 onget="return this.getAttribute('status');">
221         <setter><![CDATA[
222           this.setAttribute("status", val);
223           var field = document.getAnonymousElementByAttribute(this, "class", "update-status-value");
224           while (field.hasChildNodes())
225             field.removeChild(field.firstChild);
226           field.appendChild(document.createTextNode(val));
227           return val;
228         ]]></setter>
229       </property>
230     </implementation>
231   </binding>
232 </bindings>