Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 | |
| 5 (function() { | |
| 6 'use strict'; | |
| 7 | |
| 8 // How long until we wait for an idle event before forcibly loading the PIN | |
| 9 // HTML. | |
| 10 /** @const */ var PIN_IDLE_TIMEOUT_MS = 250; | |
| 11 | |
| 12 let onPinLoaded = function() { | |
| 13 let pinContainer = $('pin-container'); | |
| 14 pinContainer.style.opacity = 1; | |
| 15 }; | |
| 16 | |
| 17 // We only want to load the PIN HTML if we are actually showing it. The PIN | |
| 18 // element pulls in polymer with paper elements and can take a significant | |
| 19 // amount of time to load. If the user does not have a PIN unlock, we can skip | |
| 20 // loading all of the PIN-related code. | |
| 21 // | |
| 22 // TODO(jdufault): If we don't have pods, we don't need to worry about the | |
| 23 // intro-animation, and we can load directly in DOMContentLoaded. | |
| 24 // | |
| 25 // Directly loading the element in DOMContentLoaded or load results in the | |
| 26 // pod intro animation getting interrupted. Loading it in an idle callback | |
| 27 // defers the load enough that the animation does not get interrupted. | |
| 28 let showPin = loadTimeData.getBoolean('showPin'); | |
| 29 if (showPin) { | |
| 30 window.addEventListener('DOMContentLoaded', function() { | |
|
tommycli
2016/05/02 16:11:26
Can we commit the "naive" and obvious approach for
jdufault
2016/05/03 19:21:57
We can't load this directly from the HTML file, be
tommycli
2016/05/04 19:29:02
Hmm, this still seems pretty non-obvious. Can we l
jdufault
2016/05/06 00:05:46
I did some investigation here.
Using polymer lazy
xiyuan
2016/05/06 16:52:34
I wonder whether we could use existing cr.ui.login
jdufault
2016/05/06 23:44:17
Done - moving the resource loading code to Resourc
| |
| 31 let loadPin = function() { | |
| 32 let link = document.createElement('link'); | |
| 33 link.rel = 'import'; | |
| 34 link.href = 'chrome://oobe/custom_elements/pin.html'; | |
| 35 link.onload = onPinLoaded; | |
| 36 document.head.appendChild(link); | |
| 37 }; | |
| 38 | |
| 39 window.requestIdleCallback(loadPin, { timeout: PIN_IDLE_TIMEOUT_MS }); | |
| 40 }); | |
| 41 } | |
| 42 })(); | |
| OLD | NEW |