OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 $('export').onclick = exportCertificate; | 46 $('export').onclick = exportCertificate; |
47 } | 47 } |
48 | 48 |
49 /** | 49 /** |
50 * Decorate a function so that it can only be invoked once. | 50 * Decorate a function so that it can only be invoked once. |
51 */ | 51 */ |
52 function oneShot(fn) { | 52 function oneShot(fn) { |
53 var fired = false; | 53 var fired = false; |
54 return function() { | 54 return function() { |
55 if (fired) return; | 55 if (fired) |
56 fired = true; | 56 return; |
57 fn(); | 57 fired = true; |
| 58 fn(); |
58 }; | 59 }; |
59 } | 60 } |
60 | 61 |
61 /** | 62 /** |
62 * Initialize a cr.ui.Tree object from a given element using the specified | 63 * Initialize a cr.ui.Tree object from a given element using the specified |
63 * change handler. | 64 * change handler. |
64 * @param {HTMLElement} tree The HTMLElement to style as a tree. | 65 * @param {HTMLElement} tree The HTMLElement to style as a tree. |
65 * @param {function()} handler Function to call when a node is selected. | 66 * @param {function()} handler Function to call when a node is selected. |
66 */ | 67 */ |
67 function initializeTree(tree, handler) { | 68 function initializeTree(tree, handler) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 while (last.detail.children && last.detail.children[0]) | 124 while (last.detail.children && last.detail.children[0]) |
124 last = last.detail.children[0]; | 125 last = last.detail.children[0]; |
125 last.selected = true; | 126 last.selected = true; |
126 } | 127 } |
127 | 128 |
128 /** | 129 /** |
129 * Constructs a cr.ui.TreeItem corresponding to the passed in tree | 130 * Constructs a cr.ui.TreeItem corresponding to the passed in tree |
130 * @param {Object} tree Dictionary describing the tree structure. | 131 * @param {Object} tree Dictionary describing the tree structure. |
131 * @return {cr.ui.TreeItem} Tree node corresponding to the input dictionary. | 132 * @return {cr.ui.TreeItem} Tree node corresponding to the input dictionary. |
132 */ | 133 */ |
133 function constructTree(tree) | 134 function constructTree(tree) { |
134 { | |
135 var treeItem = new cr.ui.TreeItem({ | 135 var treeItem = new cr.ui.TreeItem({ |
136 label: tree.label, | 136 label: tree.label, |
137 detail: {payload: tree.payload ? tree.payload : {}, | 137 detail: {payload: tree.payload ? tree.payload : {}, children: {}} |
138 children: {} | 138 }); |
139 }}); | |
140 if (tree.children) { | 139 if (tree.children) { |
141 for (var i = 0; i < tree.children.length; i++) { | 140 for (var i = 0; i < tree.children.length; i++) { |
142 treeItem.add(treeItem.detail.children[i] = | 141 treeItem.add( |
143 constructTree(tree.children[i])); | 142 treeItem.detail.children[i] = constructTree(tree.children[i])); |
144 } | 143 } |
145 } | 144 } |
146 return treeItem; | 145 return treeItem; |
147 } | 146 } |
148 | 147 |
149 /** | 148 /** |
150 * Clear any previous certificate fields in the tree. | 149 * Clear any previous certificate fields in the tree. |
151 */ | 150 */ |
152 function clearCertificateFields() { | 151 function clearCertificateFields() { |
153 var treeItem = $('cert-fields'); | 152 var treeItem = $('cert-fields'); |
(...skipping 14 matching lines...) Expand all Loading... |
168 } | 167 } |
169 | 168 |
170 /** | 169 /** |
171 * Show the returned certificate fields for the selected certificate. | 170 * Show the returned certificate fields for the selected certificate. |
172 * @param {Object} certFields A dictionary containing the fields tree | 171 * @param {Object} certFields A dictionary containing the fields tree |
173 * structure. | 172 * structure. |
174 */ | 173 */ |
175 function getCertificateFields(certFields) { | 174 function getCertificateFields(certFields) { |
176 clearCertificateFields(); | 175 clearCertificateFields(); |
177 var treeItem = $('cert-fields'); | 176 var treeItem = $('cert-fields'); |
178 treeItem.add(treeItem.detail.children['root'] = | 177 treeItem.add( |
179 constructTree(certFields[0])); | 178 treeItem.detail.children['root'] = constructTree(certFields[0])); |
180 revealTree(treeItem); | 179 revealTree(treeItem); |
181 // Ensure the list is scrolled to the top by selecting the first item. | 180 // Ensure the list is scrolled to the top by selecting the first item. |
182 treeItem.children[0].selected = true; | 181 treeItem.children[0].selected = true; |
183 } | 182 } |
184 | 183 |
185 /** | 184 /** |
186 * Show certificate field value for a selected certificate field. | 185 * Show certificate field value for a selected certificate field. |
187 */ | 186 */ |
188 function showCertificateFieldValue() { | 187 function showCertificateFieldValue() { |
189 var item = $('cert-fields').selectedItem; | 188 var item = $('cert-fields').selectedItem; |
(...skipping 12 matching lines...) Expand all Loading... |
202 chrome.send('exportCertificate', [item.detail.payload.index]); | 201 chrome.send('exportCertificate', [item.detail.payload.index]); |
203 } | 202 } |
204 | 203 |
205 return { | 204 return { |
206 initialize: initialize, | 205 initialize: initialize, |
207 getCertificateFields: getCertificateFields, | 206 getCertificateFields: getCertificateFields, |
208 }; | 207 }; |
209 }); | 208 }); |
210 | 209 |
211 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); | 210 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); |
OLD | NEW |