OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010, Google Inc. | 2 * Copyright 2010, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 180 |
181 /** | 181 /** |
182 * Set up several of the request fields. | 182 * Set up several of the request fields. |
183 * @param {string} method "GET" is the only supported method at this time | 183 * @param {string} method "GET" is the only supported method at this time |
184 * @param {string} uri the location of the file to fetch | 184 * @param {string} uri the location of the file to fetch |
185 * @param {boolean} async true is the only legal value at this time. | 185 * @param {boolean} async true is the only legal value at this time. |
186 */ | 186 */ |
187 o3d.FileRequest.prototype.open = | 187 o3d.FileRequest.prototype.open = |
188 function(method, uri, async) { | 188 function(method, uri, async) { |
189 this.uri = uri; | 189 this.uri = uri; |
| 190 // TODO(petersont): I think there is a race condition here -- calling |
| 191 // code expects that it can still set up the onreadystatechange callback |
| 192 // between open() and send(), but if open() actually initiates the XHR |
| 193 // then the caller may miss the crucial completion callback! |
190 if (this.isImageUrl_(uri)) { | 194 if (this.isImageUrl_(uri)) { |
191 this.image_ = new Image(); | 195 this.image_ = new Image(); |
192 var that = this; | 196 var that = this; |
193 this.image_.onload = function() { | 197 this.image_.onload = function() { |
194 that.imageLoaded_.call(that); | 198 that.imageLoaded_.call(that); |
195 } | 199 } |
196 this.image_.src = uri; | 200 this.image_.src = uri; |
197 } else { | 201 } else { |
198 this.request_.open(method, uri, async); | 202 this.request_.open(method, uri, async); |
199 } | 203 } |
200 }; | 204 }; |
201 | 205 |
202 | 206 |
203 /** | 207 /** |
204 * Send the request. | 208 * Send the request. |
205 * Unlike XMLHttpRequest the onreadystatechange callback will be called no | 209 * Unlike XMLHttpRequest the onreadystatechange callback will be called no |
206 * matter what, with success or failure. | 210 * matter what, with success or failure. |
207 */ | 211 */ |
208 o3d.FileRequest.prototype.send = function() { | 212 o3d.FileRequest.prototype.send = function() { |
209 // This function left blank for compatability with o3djs.io. | 213 // This function left blank for compatability with o3djs.io. |
210 }; | 214 }; |
211 | 215 |
212 | 216 |
213 | 217 |
OLD | NEW |