OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 cr.define('cert_viewer', function() { | 5 cr.define('cert_viewer', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Initialize the certificate viewer dialog by wiring up the close button, | 9 * Initialize the certificate viewer dialog by wiring up the close button, |
10 * substituting in translated strings and requesting certificate details. | 10 * substituting in translated strings and requesting certificate details. |
11 */ | 11 */ |
12 function initialize() { | 12 function initialize() { |
13 $('close').onclick = function() { | 13 $('close').onclick = function() { |
14 window.close(); | 14 window.close(); |
15 } | 15 } |
16 $('export').onclick = exportCertificate; | |
16 cr.ui.decorate('tabbox', cr.ui.TabBox); | 17 cr.ui.decorate('tabbox', cr.ui.TabBox); |
17 | 18 |
18 initializeTree($('hierarchy'), showCertificateFields); | 19 initializeTree($('hierarchy'), showCertificateFields); |
19 initializeTree($('cert-fields'), showCertificateFieldValue); | 20 initializeTree($('cert-fields'), showCertificateFieldValue); |
20 | 21 |
21 i18nTemplate.process(document, templateData); | 22 i18nTemplate.process(document, templateData); |
22 stripGtkAccessorKeys(); | 23 stripGtkAccessorKeys(); |
23 var args = JSON.parse(chrome.dialogArguments); | 24 chrome.send('RequestCertificateInfo', []); |
James Hawkins
2011/08/09 21:00:50
No need to pass an empty array param.
flackr
2011/08/09 21:14:23
Done.
| |
24 chrome.send('requestCertificateInfo', [args.cert]); | |
25 } | 25 } |
26 | 26 |
27 /** | 27 /** |
28 * Initialize a cr.ui.Tree object from a given element using the specified | 28 * Initialize a cr.ui.Tree object from a given element using the specified |
29 * change handler. | 29 * change handler. |
30 * @param {HTMLElement} tree The HTMLElement to style as a tree. | 30 * @param {HTMLElement} tree The HTMLElement to style as a tree. |
31 * @param {function()} handler Function to call when a node is selected. | 31 * @param {function()} handler Function to call when a node is selected. |
32 */ | 32 */ |
33 function initializeTree(tree, handler) { | 33 function initializeTree(tree, handler) { |
34 cr.ui.decorate(tree, cr.ui.Tree); | 34 cr.ui.decorate(tree, cr.ui.Tree); |
35 tree.detail = {payload: {}, children: {}}; | 35 tree.detail = {payload: {}, children: {}}; |
36 tree.addEventListener('change', handler); | 36 tree.addEventListener('change', handler); |
37 } | 37 } |
38 | 38 |
39 /** | 39 /** |
40 * The tab name strings in the languages file have accessor keys indicated | 40 * The tab name strings in the languages file have accessor keys indicated |
41 * by a preceding & sign. Strip these out for now. | 41 * by a preceding & sign. Strip these out for now. |
42 * @TODO(flackr) These accessor keys could be implemented with Javascript or | 42 * @TODO(flackr) These accessor keys could be implemented with Javascript or |
43 * translated strings could be added / modified to remove the & sign. | 43 * translated strings could be added / modified to remove the & sign. |
44 */ | 44 */ |
45 function stripGtkAccessorKeys() { | 45 function stripGtkAccessorKeys() { |
46 var tabs = $('tabs').childNodes; | 46 // Copy all the tab labels into an array. |
47 for (var i = 0; i < tabs.length; i++) { | 47 var nodes = Array.prototype.slice.call($('tabs').childNodes, 0); |
48 tabs[i].textContent = tabs[i].textContent.replace('&',''); | 48 nodes.push($('export')); |
49 for (var i = 0; i < nodes.length; i++) { | |
50 nodes[i].textContent = nodes[i].textContent.replace('&',''); | |
49 } | 51 } |
50 } | 52 } |
51 | 53 |
52 /** | 54 /** |
53 * Expand all nodes of the given tree object. | 55 * Expand all nodes of the given tree object. |
54 * @param {cr.ui.Tree} tree The tree object to expand all nodes on. | 56 * @param {cr.ui.Tree} tree The tree object to expand all nodes on. |
55 */ | 57 */ |
56 function revealTree(tree) { | 58 function revealTree(tree) { |
57 tree.expanded = true; | 59 tree.expanded = true; |
58 for (var key in tree.detail.children) { | 60 for (var key in tree.detail.children) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 if (tree.children) { | 100 if (tree.children) { |
99 for (var i = 0; i < tree.children.length; i++) { | 101 for (var i = 0; i < tree.children.length; i++) { |
100 treeItem.add(treeItem.detail.children[i] = | 102 treeItem.add(treeItem.detail.children[i] = |
101 constructTree(tree.children[i])); | 103 constructTree(tree.children[i])); |
102 } | 104 } |
103 } | 105 } |
104 return treeItem; | 106 return treeItem; |
105 } | 107 } |
106 | 108 |
107 /** | 109 /** |
108 * Show certificate fields for the selected certificate in the hierarchy. | 110 * Clear any previous certificate fields in the tree. |
109 */ | 111 */ |
110 function showCertificateFields() { | 112 function clearCertificateFields() { |
111 var treeItem = $('cert-fields'); | 113 var treeItem = $('cert-fields'); |
112 for (var key in treeItem.detail.children) { | 114 for (var key in treeItem.detail.children) { |
113 treeItem.remove(treeItem.detail.children[key]); | 115 treeItem.remove(treeItem.detail.children[key]); |
114 delete treeItem.detail.children[key]; | 116 delete treeItem.detail.children[key]; |
115 } | 117 } |
118 } | |
119 | |
120 /** | |
121 * Request certificate fields for the selected certificate in the hierarchy. | |
122 */ | |
123 function showCertificateFields() { | |
124 clearCertificateFields(); | |
116 var item = $('hierarchy').selectedItem; | 125 var item = $('hierarchy').selectedItem; |
117 if (item && item.detail.payload.fields) { | 126 if (item && item.detail.payload.index !== undefined) { |
James Hawkins
2011/08/09 21:00:50
No braces for single line logic blocks.
flackr
2011/08/09 21:14:23
Done.
| |
118 treeItem.add(treeItem.detail.children['root'] = | 127 chrome.send('RequestCertificateFields', [item.detail.payload.index]); |
119 constructTree(item.detail.payload.fields[0])); | |
120 revealTree(treeItem); | |
121 } | 128 } |
122 } | 129 } |
123 | 130 |
124 /** | 131 /** |
132 * Show the returned certificate fields for the selected certificate. | |
133 * @param {Object} certFields A dictionary containing the fields tree | |
134 * structure. | |
135 */ | |
136 function getCertificateFields(certFields) { | |
137 clearCertificateFields(); | |
138 var treeItem = $('cert-fields'); | |
139 treeItem.add(treeItem.detail.children['root'] = | |
140 constructTree(certFields[0])); | |
141 revealTree(treeItem); | |
142 } | |
143 | |
144 /** | |
125 * Show certificate field value for a selected certificate field. | 145 * Show certificate field value for a selected certificate field. |
126 */ | 146 */ |
127 function showCertificateFieldValue() { | 147 function showCertificateFieldValue() { |
128 var item = $('cert-fields').selectedItem; | 148 var item = $('cert-fields').selectedItem; |
129 if (item && item.detail.payload.val) | 149 if (item && item.detail.payload.val) |
130 $('cert-field-value').textContent = item.detail.payload.val; | 150 $('cert-field-value').textContent = item.detail.payload.val; |
131 else | 151 else |
132 $('cert-field-value').textContent = ''; | 152 $('cert-field-value').textContent = ''; |
133 } | 153 } |
134 | 154 |
155 /** | |
156 * Export the selected certificate. | |
157 */ | |
158 function exportCertificate() { | |
159 var item = $('hierarchy').selectedItem; | |
160 if (item && item.detail.payload.index !== undefined) | |
161 chrome.send('ExportCertificate', [item.detail.payload.index]); | |
162 } | |
163 | |
135 return { | 164 return { |
136 initialize: initialize, | 165 initialize: initialize, |
137 getCertificateInfo: getCertificateInfo, | 166 getCertificateInfo: getCertificateInfo, |
167 getCertificateFields: getCertificateFields, | |
138 }; | 168 }; |
139 }); | 169 }); |
140 | 170 |
141 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); | 171 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); |
OLD | NEW |