Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: chrome/browser/resources/certificate_viewer.js

Issue 7528027: Add export function to WebUI certificate viewer. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 = function() {
Rick Byers 2011/08/09 17:29:18 Doesn't seem to be any value in using a lambda her
flackr 2011/08/09 18:25:15 Done.
17 exportCertificate();
18 }
16 cr.ui.decorate('tabbox', cr.ui.TabBox); 19 cr.ui.decorate('tabbox', cr.ui.TabBox);
17 20
18 initializeTree($('hierarchy'), showCertificateFields); 21 initializeTree($('hierarchy'), showCertificateFields);
19 initializeTree($('cert-fields'), showCertificateFieldValue); 22 initializeTree($('cert-fields'), showCertificateFieldValue);
20 23
21 i18nTemplate.process(document, templateData); 24 i18nTemplate.process(document, templateData);
22 stripGtkAccessorKeys(); 25 stripGtkAccessorKeys();
23 var args = JSON.parse(chrome.dialogArguments); 26 chrome.send('RequestCertificateInfo', ['']);
Rick Byers 2011/08/09 17:29:18 can you just send an empty array for the args inst
flackr 2011/08/09 18:25:15 Done.
24 chrome.send('requestCertificateInfo', [args.cert]);
25 } 27 }
26 28
27 /** 29 /**
28 * Initialize a cr.ui.Tree object from a given element using the specified 30 * Initialize a cr.ui.Tree object from a given element using the specified
29 * change handler. 31 * change handler.
30 * @param {HTMLElement} tree The HTMLElement to style as a tree. 32 * @param {HTMLElement} tree The HTMLElement to style as a tree.
31 * @param {function()} handler Function to call when a node is selected. 33 * @param {function()} handler Function to call when a node is selected.
32 */ 34 */
33 function initializeTree(tree, handler) { 35 function initializeTree(tree, handler) {
34 cr.ui.decorate(tree, cr.ui.Tree); 36 cr.ui.decorate(tree, cr.ui.Tree);
35 tree.detail = {payload: {}, children: {}}; 37 tree.detail = {payload: {}, children: {}};
36 tree.addEventListener('change', handler); 38 tree.addEventListener('change', handler);
37 } 39 }
38 40
39 /** 41 /**
40 * The tab name strings in the languages file have accessor keys indicated 42 * The tab name strings in the languages file have accessor keys indicated
41 * by a preceding & sign. Strip these out for now. 43 * by a preceding & sign. Strip these out for now.
42 * @TODO(flackr) These accessor keys could be implemented with Javascript or 44 * @TODO(flackr) These accessor keys could be implemented with Javascript or
43 * translated strings could be added / modified to remove the & sign. 45 * translated strings could be added / modified to remove the & sign.
44 */ 46 */
45 function stripGtkAccessorKeys() { 47 function stripGtkAccessorKeys() {
46 var tabs = $('tabs').childNodes; 48 // Convert the NodeList to an array so that we can use concat.
47 for (var i = 0; i < tabs.length; i++) { 49 var nodes = Array.prototype.slice.call($('tabs').childNodes, 0)
48 tabs[i].textContent = tabs[i].textContent.replace('&',''); 50 .concat([$('export')]);
Rick Byers 2011/08/09 17:29:18 I'd suggest just using Array.push instead of Array
flackr 2011/08/09 18:25:15 Done.
51 for (var i = 0; i < nodes.length; i++) {
52 nodes[i].textContent = nodes[i].textContent.replace('&','');
49 } 53 }
50 } 54 }
51 55
52 /** 56 /**
53 * Expand all nodes of the given tree object. 57 * Expand all nodes of the given tree object.
54 * @param {cr.ui.Tree} tree The tree object to expand all nodes on. 58 * @param {cr.ui.Tree} tree The tree object to expand all nodes on.
55 */ 59 */
56 function revealTree(tree) { 60 function revealTree(tree) {
57 tree.expanded = true; 61 tree.expanded = true;
58 for (var key in tree.detail.children) { 62 for (var key in tree.detail.children) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (tree.children) { 102 if (tree.children) {
99 for (var i = 0; i < tree.children.length; i++) { 103 for (var i = 0; i < tree.children.length; i++) {
100 treeItem.add(treeItem.detail.children[i] = 104 treeItem.add(treeItem.detail.children[i] =
101 constructTree(tree.children[i])); 105 constructTree(tree.children[i]));
102 } 106 }
103 } 107 }
104 return treeItem; 108 return treeItem;
105 } 109 }
106 110
107 /** 111 /**
108 * Show certificate fields for the selected certificate in the hierarchy. 112 * Clear any previous certificate fields in the tree.
109 */ 113 */
110 function showCertificateFields() { 114 function clearCertificateFields() {
111 var treeItem = $('cert-fields'); 115 var treeItem = $('cert-fields');
112 for (var key in treeItem.detail.children) { 116 for (var key in treeItem.detail.children) {
113 treeItem.remove(treeItem.detail.children[key]); 117 treeItem.remove(treeItem.detail.children[key]);
114 delete treeItem.detail.children[key]; 118 delete treeItem.detail.children[key];
115 } 119 }
120 }
121
122 /**
123 * Request certificate fields for the selected certificate in the hierarchy.
124 */
125 function showCertificateFields() {
126 clearCertificateFields();
116 var item = $('hierarchy').selectedItem; 127 var item = $('hierarchy').selectedItem;
117 if (item && item.detail.payload.fields) { 128 if (item && item.detail.payload.index) {
118 treeItem.add(treeItem.detail.children['root'] = 129 chrome.send('RequestCertificateFields', [item.detail.payload.index]);
119 constructTree(item.detail.payload.fields[0]));
120 revealTree(treeItem);
121 } 130 }
122 } 131 }
123 132
124 /** 133 /**
134 * Show the returned certificate fields for the selected certificate.
135 * @param {Object} certFields A dictionary containing the fields tree
136 * structure.
137 */
138 function getCertificateFields(certFields) {
139 clearCertificateFields();
140 var treeItem = $('cert-fields');
141 treeItem.add(treeItem.detail.children['root'] =
142 constructTree(certFields[0]));
143 revealTree(treeItem);
144 }
145
146 /**
125 * Show certificate field value for a selected certificate field. 147 * Show certificate field value for a selected certificate field.
126 */ 148 */
127 function showCertificateFieldValue() { 149 function showCertificateFieldValue() {
128 var item = $('cert-fields').selectedItem; 150 var item = $('cert-fields').selectedItem;
129 if (item && item.detail.payload.val) 151 if (item && item.detail.payload.val)
130 $('cert-field-value').textContent = item.detail.payload.val; 152 $('cert-field-value').textContent = item.detail.payload.val;
131 else 153 else
132 $('cert-field-value').textContent = ''; 154 $('cert-field-value').textContent = '';
133 } 155 }
134 156
157 /**
158 * Export the selected certificate.
159 */
160 function exportCertificate() {
161 var item = $('hierarchy').selectedItem;
162 if (item && item.detail.payload.index)
163 chrome.send('ExportCertificate', [item.detail.payload.index]);
164 }
165
135 return { 166 return {
136 initialize: initialize, 167 initialize: initialize,
137 getCertificateInfo: getCertificateInfo, 168 getCertificateInfo: getCertificateInfo,
169 getCertificateFields: getCertificateFields,
138 }; 170 };
139 }); 171 });
140 172
141 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); 173 document.addEventListener('DOMContentLoaded', cert_viewer.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698