| 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'); |
| 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 } | 49 for (var i = 0; i < nodes.length; i++) |
| 50 nodes[i].textContent = nodes[i].textContent.replace('&',''); |
| 50 } | 51 } |
| 51 | 52 |
| 52 /** | 53 /** |
| 53 * Expand all nodes of the given tree object. | 54 * Expand all nodes of the given tree object. |
| 54 * @param {cr.ui.Tree} tree The tree object to expand all nodes on. | 55 * @param {cr.ui.Tree} tree The tree object to expand all nodes on. |
| 55 */ | 56 */ |
| 56 function revealTree(tree) { | 57 function revealTree(tree) { |
| 57 tree.expanded = true; | 58 tree.expanded = true; |
| 58 for (var key in tree.detail.children) { | 59 for (var key in tree.detail.children) { |
| 59 revealTree(tree.detail.children[key]); | 60 revealTree(tree.detail.children[key]); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 if (tree.children) { | 99 if (tree.children) { |
| 99 for (var i = 0; i < tree.children.length; i++) { | 100 for (var i = 0; i < tree.children.length; i++) { |
| 100 treeItem.add(treeItem.detail.children[i] = | 101 treeItem.add(treeItem.detail.children[i] = |
| 101 constructTree(tree.children[i])); | 102 constructTree(tree.children[i])); |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 return treeItem; | 105 return treeItem; |
| 105 } | 106 } |
| 106 | 107 |
| 107 /** | 108 /** |
| 108 * Show certificate fields for the selected certificate in the hierarchy. | 109 * Clear any previous certificate fields in the tree. |
| 109 */ | 110 */ |
| 110 function showCertificateFields() { | 111 function clearCertificateFields() { |
| 111 var treeItem = $('cert-fields'); | 112 var treeItem = $('cert-fields'); |
| 112 for (var key in treeItem.detail.children) { | 113 for (var key in treeItem.detail.children) { |
| 113 treeItem.remove(treeItem.detail.children[key]); | 114 treeItem.remove(treeItem.detail.children[key]); |
| 114 delete treeItem.detail.children[key]; | 115 delete treeItem.detail.children[key]; |
| 115 } | 116 } |
| 116 var item = $('hierarchy').selectedItem; | |
| 117 if (item && item.detail.payload.fields) { | |
| 118 treeItem.add(treeItem.detail.children['root'] = | |
| 119 constructTree(item.detail.payload.fields[0])); | |
| 120 revealTree(treeItem); | |
| 121 } | |
| 122 } | 117 } |
| 123 | 118 |
| 124 /** | 119 /** |
| 120 * Request certificate fields for the selected certificate in the hierarchy. |
| 121 */ |
| 122 function showCertificateFields() { |
| 123 clearCertificateFields(); |
| 124 var item = $('hierarchy').selectedItem; |
| 125 if (item && item.detail.payload.index !== undefined) |
| 126 chrome.send('requestCertificateFields', [item.detail.payload.index]); |
| 127 } |
| 128 |
| 129 /** |
| 130 * Show the returned certificate fields for the selected certificate. |
| 131 * @param {Object} certFields A dictionary containing the fields tree |
| 132 * structure. |
| 133 */ |
| 134 function getCertificateFields(certFields) { |
| 135 clearCertificateFields(); |
| 136 var treeItem = $('cert-fields'); |
| 137 treeItem.add(treeItem.detail.children['root'] = |
| 138 constructTree(certFields[0])); |
| 139 revealTree(treeItem); |
| 140 } |
| 141 |
| 142 /** |
| 125 * Show certificate field value for a selected certificate field. | 143 * Show certificate field value for a selected certificate field. |
| 126 */ | 144 */ |
| 127 function showCertificateFieldValue() { | 145 function showCertificateFieldValue() { |
| 128 var item = $('cert-fields').selectedItem; | 146 var item = $('cert-fields').selectedItem; |
| 129 if (item && item.detail.payload.val) | 147 if (item && item.detail.payload.val) |
| 130 $('cert-field-value').textContent = item.detail.payload.val; | 148 $('cert-field-value').textContent = item.detail.payload.val; |
| 131 else | 149 else |
| 132 $('cert-field-value').textContent = ''; | 150 $('cert-field-value').textContent = ''; |
| 133 } | 151 } |
| 134 | 152 |
| 153 /** |
| 154 * Export the selected certificate. |
| 155 */ |
| 156 function exportCertificate() { |
| 157 var item = $('hierarchy').selectedItem; |
| 158 if (item && item.detail.payload.index !== undefined) |
| 159 chrome.send('exportCertificate', [item.detail.payload.index]); |
| 160 } |
| 161 |
| 135 return { | 162 return { |
| 136 initialize: initialize, | 163 initialize: initialize, |
| 137 getCertificateInfo: getCertificateInfo, | 164 getCertificateInfo: getCertificateInfo, |
| 165 getCertificateFields: getCertificateFields, |
| 138 }; | 166 }; |
| 139 }); | 167 }); |
| 140 | 168 |
| 141 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); | 169 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); |
| OLD | NEW |