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
3 // found in the LICENSE file.
8 * Takes the |componentsData| input argument which represents data about the
9 * currently installed components and populates the html jstemplate with
10 * that data. It expects an object structure like the above.
11 * @param {Object} componentsData Detailed info about installed components.
12 * Same expected format as returnComponentsData().
14 function renderTemplate(componentsData
) {
15 // This is the javascript code that processes the template:
16 var input
= new JsEvalContext(componentsData
);
17 var output
= $('component-template').cloneNode(true);
18 $('component-placeholder').innerHTML
= '';
19 $('component-placeholder').appendChild(output
);
20 jstProcess(input
, output
);
21 output
.removeAttribute('hidden');
25 * Asks the C++ ComponentsDOMHandler to get details about the installed
27 * The ComponentsDOMHandler should reply to returnComponentsData() (below).
29 function requestComponentsData() {
30 chrome
.send('requestComponentsData');
34 * Called by the WebUI to re-populate the page with data representing the
35 * current state of installed components.
36 * @param {Object} componentsData Detailed info about installed components. The
37 * template expects each component's format to match the following
38 * structure to correctly populate the page:
52 function returnComponentsData(componentsData
) {
53 var bodyContainer
= $('body-container');
54 var body
= document
.body
;
56 bodyContainer
.style
.visibility
= 'hidden';
59 renderTemplate(componentsData
);
61 // Add handlers to dynamically created HTML elements.
62 var links
= document
.getElementsByClassName('button-check-update');
63 for (var i
= 0; i
< links
.length
; i
++) {
64 links
[i
].onclick = function(e
) {
65 handleCheckUpdate(this);
71 // Disable some controls for Guest in ChromeOS.
72 uiAccountTweaks
.UIAccountTweaks
.applyGuestSessionVisibility(document
);
74 // Disable some controls for Public session in ChromeOS.
75 uiAccountTweaks
.UIAccountTweaks
.applyPublicSessionVisibility(document
);
78 bodyContainer
.style
.visibility
= 'visible';
79 body
.className
= 'show-tmi-mode-initial';
83 * This event function is called from component UI indicating changed state
84 * of component updater service.
85 * @param {Object} eventArgs Contains event and component ID. Component ID is
88 function onComponentEvent(eventArgs
) {
89 if (eventArgs
['id']) {
90 var id
= eventArgs
['id'];
91 $('status-' + id
).textContent
= eventArgs
['event'];
93 if (eventArgs
['version']) {
94 $('version-' + id
).textContent
= eventArgs
['version'];
99 * Handles an 'enable' or 'disable' button getting clicked.
100 * @param {HTMLElement} node The HTML element representing the component
101 * being checked for update.
103 function handleCheckUpdate(node
) {
104 $('status-' + String(node
.id
)).textContent
=
105 loadTimeData
.getString('checkingLabel');
107 // Tell the C++ ComponentssDOMHandler to check for update.
108 chrome
.send('checkUpdate', [String(node
.id
)]);
111 // Get data and have it displayed upon loading.
112 document
.addEventListener('DOMContentLoaded', requestComponentsData
);