| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This function takes an object |imageSpec| with the key |path| - | 5 // This function takes an object |imageSpec| with the key |path| - |
| 6 // corresponding to the internet URL to be translated - and optionally | 6 // corresponding to the internet URL to be translated - and optionally |
| 7 // |width| and |height| which are the maximum dimensions to be used when | 7 // |width| and |height| which are the maximum dimensions to be used when |
| 8 // converting the image. | 8 // converting the image. |
| 9 function loadImageData(imageSpec, callbacks) { | 9 function loadImageData(imageSpec, callbacks) { |
| 10 var path = imageSpec.path; | 10 var path = imageSpec.path; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 img.src = path; | 54 img.src = path; |
| 55 } | 55 } |
| 56 | 56 |
| 57 function on_complete_index(index, err, loading, finished, callbacks) { | 57 function on_complete_index(index, err, loading, finished, callbacks) { |
| 58 return function(width, height, imageData) { | 58 return function(width, height, imageData) { |
| 59 delete loading[index]; | 59 delete loading[index]; |
| 60 finished[index] = { width: width, height: height, data: imageData }; | 60 finished[index] = { width: width, height: height, data: imageData }; |
| 61 if (err) | 61 if (err) |
| 62 callbacks.onerror(index); | 62 callbacks.onerror(index); |
| 63 if (Object.keys(loading).length == 0) | 63 if ($Object.keys(loading).length == 0) |
| 64 callbacks.oncomplete(finished); | 64 callbacks.oncomplete(finished); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 function loadAllImages(imageSpecs, callbacks) { | 68 function loadAllImages(imageSpecs, callbacks) { |
| 69 var loading = {}, finished = [], | 69 var loading = {}, finished = [], |
| 70 index, pathname; | 70 index, pathname; |
| 71 | 71 |
| 72 for (var index = 0; index < imageSpecs.length; index++) { | 72 for (var index = 0; index < imageSpecs.length; index++) { |
| 73 loading[index] = imageSpecs[index]; | 73 loading[index] = imageSpecs[index]; |
| 74 loadImageData(imageSpecs[index], { | 74 loadImageData(imageSpecs[index], { |
| 75 oncomplete: on_complete_index(index, false, loading, finished, callbacks), | 75 oncomplete: on_complete_index(index, false, loading, finished, callbacks), |
| 76 onerror: on_complete_index(index, true, loading, finished, callbacks) | 76 onerror: on_complete_index(index, true, loading, finished, callbacks) |
| 77 }); | 77 }); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 exports.loadImageData = loadImageData; | 81 exports.loadImageData = loadImageData; |
| 82 exports.loadAllImages = loadAllImages; | 82 exports.loadAllImages = loadAllImages; |
| OLD | NEW |