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.
6 * WebUI to monitor File Metadata per Extension ID.
8 var FileMetadata
= (function() {
11 var FileMetadata
= {};
14 * Gets extension data so the select drop down can be filled.
16 function getExtensions() {
17 chrome
.send('getExtensions');
21 * Renders result of getFileMetadata as a table.
22 * @param {Array} list of dictionaries containing 'extensionName',
23 * 'extensionID', 'status'.
25 FileMetadata
.onGetExtensions = function(extensionStatuses
) {
26 var select
= $('extensions-select');
28 // Record existing drop down extension ID. If it's still there after the
29 // refresh then keep it as the selected value.
30 var oldSelectedExtension
= getSelectedExtensionId();
32 select
.textContent
= '';
33 for (var i
= 0; i
< extensionStatuses
.length
; i
++) {
34 var originEntry
= extensionStatuses
[i
];
35 var tr
= document
.createElement('tr');
36 var title
= originEntry
.extensionName
+ ' [' + originEntry
.status
+ ']';
37 select
.options
.add(new Option(title
, originEntry
.extensionID
));
39 // If option was the previously only selected, make it selected again.
40 if (originEntry
.extensionID
!= oldSelectedExtension
)
42 select
.options
[select
.options
.length
- 1].selected
= true;
45 // After drop down has been loaded with options, file metadata can be loaded
50 * @return {string} extension ID that's currently selected in drop down box.
52 function getSelectedExtensionId() {
53 var dropDown
= $('extensions-select').options
;
54 if (dropDown
.selectedIndex
>= 0)
55 return dropDown
[dropDown
.selectedIndex
].value
;
61 * Get File Metadata depending on which extension is selected from the drop down
64 function getFileMetadata() {
65 var dropDown
= $('extensions-select');
66 if (dropDown
.options
.length
=== 0) {
67 $('file-metadata-header').textContent
= '';
68 $('file-metadata-entries').textContent
= 'No file metadata available.';
72 var selectedExtensionId
= getSelectedExtensionId();
73 chrome
.send('getFileMetadata', [selectedExtensionId
]);
77 * Renders result of getFileMetadata as a table.
79 FileMetadata
.onGetFileMetadata = function(fileMetadataMap
) {
80 var header
= $('file-metadata-header');
81 // Only draw the header if it hasn't been drawn yet
82 if (header
.children
.length
=== 0) {
83 var tr
= document
.createElement('tr');
84 tr
.appendChild(createElementFromText('td', 'Type'));
85 tr
.appendChild(createElementFromText('td', 'Status'));
86 tr
.appendChild(createElementFromText('td', 'Path', {width
: '250px'}));
87 tr
.appendChild(createElementFromText('td', 'Details'));
88 header
.appendChild(tr
);
92 var itemContainer
= $('file-metadata-entries');
93 itemContainer
.textContent
= '';
94 for (var i
= 0; i
< fileMetadataMap
.length
; i
++) {
95 var metadatEntry
= fileMetadataMap
[i
];
96 var tr
= document
.createElement('tr');
97 tr
.appendChild(createFileIconCell(metadatEntry
.type
));
98 tr
.appendChild(createElementFromText('td', metadatEntry
.status
));
99 tr
.appendChild(createElementFromText('td', metadatEntry
.path
));
100 tr
.appendChild(createElementFromDictionary('td', metadatEntry
.details
));
101 itemContainer
.appendChild(tr
);
106 * @param {string} file type string.
107 * @return {HTMLElement} TD with file or folder icon depending on type.
109 function createFileIconCell(type
) {
110 var td
= createElementFromText('td', type
);
111 td
.setAttribute('class', type
.toLowerCase() + '-icon');
117 $('refresh-metadata-button').addEventListener('click', getExtensions
);
118 $('extensions-select').addEventListener('change', getFileMetadata
);
121 document
.addEventListener('DOMContentLoaded', main
);