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 /** | 5 /** |
6 * @fileoverview Deferred resource loader for OOBE/Login screens. | 6 * @fileoverview Deferred resource loader for OOBE/Login screens. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('cr.ui.login.ResourceLoader', function() { | 9 cr.define('cr.ui.login.ResourceLoader', function() { |
10 'use strict'; | 10 'use strict'; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 146 } |
147 | 147 |
148 /** | 148 /** |
149 * Finishes loading an asset bundle. | 149 * Finishes loading an asset bundle. |
150 * @param {string} id Identifier of the asset bundle. | 150 * @param {string} id Identifier of the asset bundle. |
151 */ | 151 */ |
152 function finishedLoading(id) { | 152 function finishedLoading(id) { |
153 var assets = ASSETS[id]; | 153 var assets = ASSETS[id]; |
154 console.log('Finished loading asset bundle', id); | 154 console.log('Finished loading asset bundle', id); |
155 assets.loaded = true; | 155 assets.loaded = true; |
156 window.setTimeout(assets.callback, 0); | 156 window.setTimeout(function() { |
| 157 assets.callback(); |
| 158 chrome.send('screenAssetsLoaded', [id]); |
| 159 }, 0); |
157 } | 160 } |
158 | 161 |
159 /** | 162 /** |
160 * Load an asset bundle, invoking the callback when finished. | 163 * Load an asset bundle, invoking the callback when finished. |
161 * @param {string} id Identifier for the asset bundle to load. | 164 * @param {string} id Identifier for the asset bundle to load. |
162 * @param {function()=} callback Function to invoke when done loading. | 165 * @param {function()=} callback Function to invoke when done loading. |
163 */ | 166 */ |
164 function loadAssets(id, callback) { | 167 function loadAssets(id, callback) { |
165 var assets = ASSETS[id]; | 168 var assets = ASSETS[id]; |
166 assets.callback = callback || function() {}; | 169 assets.callback = callback || function() {}; |
167 console.log('Loading asset bundle', id); | 170 console.log('Loading asset bundle', id); |
168 if (alreadyLoadedAssets(id)) | 171 if (alreadyLoadedAssets(id)) |
169 console.warn('asset bundle', id, 'already loaded!'); | 172 console.warn('asset bundle', id, 'already loaded!'); |
170 if (assets.count == 0) { | 173 if (assets.count == 0) { |
171 finishedLoading(id); | 174 finishedLoading(id); |
172 } else { | 175 } else { |
173 assets.css.forEach(loadCSS.bind(null, id)); | 176 assets.css.forEach(loadCSS.bind(null, id)); |
174 assets.js.forEach(loadJS.bind(null, id)); | 177 assets.js.forEach(loadJS.bind(null, id)); |
175 assets.html.forEach(loadHTML.bind(null, id)); | 178 assets.html.forEach(loadHTML.bind(null, id)); |
176 } | 179 } |
177 } | 180 } |
178 | 181 |
179 return { | 182 return { |
180 alreadyLoadedAssets: alreadyLoadedAssets, | 183 alreadyLoadedAssets: alreadyLoadedAssets, |
181 hasDeferredAssets: hasDeferredAssets, | 184 hasDeferredAssets: hasDeferredAssets, |
182 loadAssets: loadAssets, | 185 loadAssets: loadAssets, |
183 registerAssets: registerAssets | 186 registerAssets: registerAssets |
184 }; | 187 }; |
185 }); | 188 }); |
OLD | NEW |