Chromium Code Reviews| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Takes the |componentsData| input argument which represents data about the | 8 * Takes the |componentsData| input argument which represents data about the |
| 9 * currently installed components and populates the html jstemplate with | 9 * currently installed components and populates the html jstemplate with |
| 10 * that data. It expects an object structure like the above. | 10 * that data. It expects an object structure like the above. |
| 11 * @param {Object} componentsData Detailed info about installed components. | 11 * @param {Object} componentsData Detailed info about installed components. |
| 12 * Same expected format as returnComponentsData(). | 12 * Same expected format as returnComponentsData(). |
| 13 */ | 13 */ |
| 14 function renderTemplate(componentsData) { | 14 function renderTemplate(componentsData) { |
| 15 // This is the javascript code that processes the template: | 15 // This is the javascript code that processes the template: |
| 16 var input = new JsEvalContext(componentsData); | 16 var input = new JsEvalContext(componentsData); |
| 17 var output = $('componentTemplate'); | 17 var output = $('component-template').cloneNode(true); |
| 18 $('component-placeholder').innerHTML = ''; | |
| 19 $('component-placeholder').appendChild(output); | |
| 18 jstProcess(input, output); | 20 jstProcess(input, output); |
| 21 output.removeAttribute('hidden'); | |
| 19 } | 22 } |
| 20 | 23 |
| 21 /** | 24 /** |
| 22 * Asks the C++ ComponentsDOMHandler to get details about the installed | 25 * Asks the C++ ComponentsDOMHandler to get details about the installed |
| 23 * components. | 26 * components. |
| 24 * The ComponentsDOMHandler should reply to returnComponentsData() (below). | 27 * The ComponentsDOMHandler should reply to returnComponentsData() (below). |
| 25 */ | 28 */ |
| 26 function requestComponentsData() { | 29 function requestComponentsData() { |
| 27 chrome.send('requestComponentsData'); | 30 chrome.send('requestComponentsData'); |
| 28 } | 31 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 | 69 |
| 67 // Disable some controls for Guest in ChromeOS. | 70 // Disable some controls for Guest in ChromeOS. |
| 68 if (cr.isChromeOS) | 71 if (cr.isChromeOS) |
| 69 uiAccountTweaks.UIAccountTweaks.applyGuestModeVisibility(document); | 72 uiAccountTweaks.UIAccountTweaks.applyGuestModeVisibility(document); |
| 70 | 73 |
| 71 bodyContainer.style.visibility = 'visible'; | 74 bodyContainer.style.visibility = 'visible'; |
| 72 body.className = 'show-tmi-mode-initial'; | 75 body.className = 'show-tmi-mode-initial'; |
| 73 } | 76 } |
| 74 | 77 |
| 75 /** | 78 /** |
| 79 * This is a fallback function, which handles the case when | |
| 80 * component updater service doesn't fire onComponentEvent in response | |
|
Sorin Jianu
2014/05/08 22:07:24
I've been thinking about this case. Indeed, we don
Shrikant Kelkar
2014/05/15 23:12:43
Done.
| |
| 81 * to checkUpdate. | |
| 82 * @param {HTMLElement} node The HTML element representing the component. | |
| 83 */ | |
| 84 function updateComponentStatus(node) { | |
| 85 if (node.disabled) { | |
| 86 // If component button is still disabled, we | |
| 87 // report status as timeout and re-enable button. | |
| 88 $('status-' + node.id).textContent = 'timeout'; | |
| 89 node.disabled = false; | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 var timeoutMonitor = new Object(); | |
| 94 | |
| 95 /** | |
| 96 * This event function is called from component ui indicating changed state | |
| 97 * of component updater service. | |
| 98 * @param {Object} eventArgs Contains event and component id. Component id is | |
| 99 * optional. | |
| 100 */ | |
| 101 function onComponentEvent(eventArgs) { | |
| 102 if (eventArgs['id']) { | |
| 103 var id = eventArgs['id']; | |
| 104 $('status-' + id).textContent = eventArgs['event']; | |
| 105 | |
| 106 if (eventArgs['event'] != 'UpdateFound' && | |
| 107 eventArgs['event'] != 'UpdateReady') { | |
| 108 $(id).disabled = false; | |
| 109 timeoutMonitor[id] && clearTimeout(timeoutMonitor[id]); | |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 // 5 second refresh interval. | |
| 115 var STATUS_REFRESH_INTERVAL = 5000; | |
| 116 | |
| 117 /** | |
| 76 * Handles an 'enable' or 'disable' button getting clicked. | 118 * Handles an 'enable' or 'disable' button getting clicked. |
| 77 * @param {HTMLElement} node The HTML element representing the component | 119 * @param {HTMLElement} node The HTML element representing the component |
| 78 * being checked for update. | 120 * being checked for update. |
| 79 */ | 121 */ |
| 80 function handleCheckUpdate(node) { | 122 function handleCheckUpdate(node) { |
| 81 node.disabled = true; | 123 node.disabled = true; |
| 124 | |
| 125 $('status-' + String(node.id)).textContent = 'Checking for update...'; | |
| 126 | |
| 82 // Tell the C++ ComponentssDOMHandler to check for update. | 127 // Tell the C++ ComponentssDOMHandler to check for update. |
| 83 chrome.send('checkUpdate', [String(node.id)]); | 128 chrome.send('checkUpdate', [String(node.id)]); |
| 129 | |
| 130 timeoutMonitor[node.id] = window.setTimeout( | |
| 131 function() { updateComponentStatus(node); }, | |
| 132 STATUS_REFRESH_INTERVAL); | |
| 84 } | 133 } |
| 85 | 134 |
| 86 // Get data and have it displayed upon loading. | 135 // Get data and have it displayed upon loading. |
| 87 document.addEventListener('DOMContentLoaded', requestComponentsData); | 136 document.addEventListener('DOMContentLoaded', requestComponentsData); |
| 88 | |
| 89 // Add handlers to static HTML elements. | |
| 90 $('button-check-update').onclick = handleCheckUpdate; | |
| OLD | NEW |