OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 /** | 188 /** |
189 * Load an asset bundle after the document has been loaded and Chrome is idle. | 189 * Load an asset bundle after the document has been loaded and Chrome is idle. |
190 * @param {string} id Identifier for the asset bundle to load. | 190 * @param {string} id Identifier for the asset bundle to load. |
191 * @param {function()=} callback Function to invoke when done loading. | 191 * @param {function()=} callback Function to invoke when done loading. |
192 * @param {number=} opt_idleTimeoutMs The maximum amount of time to wait for | 192 * @param {number=} opt_idleTimeoutMs The maximum amount of time to wait for |
193 * an idle notification. | 193 * an idle notification. |
194 */ | 194 */ |
195 function loadAssetsOnIdle(id, callback, opt_idleTimeoutMs) { | 195 function loadAssetsOnIdle(id, callback, opt_idleTimeoutMs) { |
196 opt_idleTimeoutMs = opt_idleTimeoutMs || 250; | 196 opt_idleTimeoutMs = opt_idleTimeoutMs || 250; |
197 | 197 |
198 let loadOnIdle = function() { | 198 var loadOnIdle = function() { |
199 window.requestIdleCallback(function() { | 199 window.requestIdleCallback(function() { |
200 loadAssets(id, callback); | 200 loadAssets(id, callback); |
201 }, { timeout: opt_idleTimeoutMs }); | 201 }, { timeout: opt_idleTimeoutMs }); |
202 }; | 202 }; |
203 | 203 |
204 if (document.readyState == 'complete') { | 204 if (document.readyState == 'loading') { |
| 205 window.addEventListener('DOMContentLoaded', loadOnIdle); |
| 206 } else { |
| 207 // DOMContentLoaded has already been called if document.readyState is |
| 208 // 'interactive' or 'complete', so invoke the callback immediately. |
205 loadOnIdle(); | 209 loadOnIdle(); |
206 } else { | |
207 window.addEventListener('DOMContentLoaded', loadOnIdle); | |
208 } | 210 } |
209 } | 211 } |
210 | 212 |
211 /** | 213 /** |
212 * Wait until the element with the given |id| has finished its layout, | 214 * Wait until the element with the given |id| has finished its layout, |
213 * specifically, after it has an offsetHeight > 0. | 215 * specifically, after it has an offsetHeight > 0. |
214 * @param {string} id Identifier of the element to wait for. | 216 * @param {string} id Identifier of the element to wait for. |
215 * @param {function()} callback Function to invoke when done loading. | 217 * @param {function()} callback Function to invoke when done loading. |
216 */ | 218 */ |
217 function waitUntilLayoutComplete(id, callback) { | 219 function waitUntilLayoutComplete(id, callback) { |
(...skipping 12 matching lines...) Expand all Loading... |
230 | 232 |
231 return { | 233 return { |
232 alreadyLoadedAssets: alreadyLoadedAssets, | 234 alreadyLoadedAssets: alreadyLoadedAssets, |
233 hasDeferredAssets: hasDeferredAssets, | 235 hasDeferredAssets: hasDeferredAssets, |
234 loadAssets: loadAssets, | 236 loadAssets: loadAssets, |
235 loadAssetsOnIdle: loadAssetsOnIdle, | 237 loadAssetsOnIdle: loadAssetsOnIdle, |
236 waitUntilLayoutComplete: waitUntilLayoutComplete, | 238 waitUntilLayoutComplete: waitUntilLayoutComplete, |
237 registerAssets: registerAssets | 239 registerAssets: registerAssets |
238 }; | 240 }; |
239 }); | 241 }); |
OLD | NEW |