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

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: Adds TODO comment related to passing certificate viewer parent. 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 = 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/12 19:58:26 s/Request/request/
flackr 2011/08/15 13:47:38 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++) {
James Hawkins 2011/08/12 19:58:26 Remove braces.
flackr 2011/08/15 13:47:38 Done.
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
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 }
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 } 118 }
123 119
124 /** 120 /**
121 * Request certificate fields for the selected certificate in the hierarchy.
122 */
123 function showCertificateFields() {
124 clearCertificateFields();
125 var item = $('hierarchy').selectedItem;
126 if (item && item.detail.payload.index !== undefined)
127 chrome.send('RequestCertificateFields', [item.detail.payload.index]);
128 }
129
130 /**
131 * Show the returned certificate fields for the selected certificate.
132 * @param {Object} certFields A dictionary containing the fields tree
133 * structure.
134 */
135 function getCertificateFields(certFields) {
136 clearCertificateFields();
137 var treeItem = $('cert-fields');
138 treeItem.add(treeItem.detail.children['root'] =
139 constructTree(certFields[0]));
140 revealTree(treeItem);
141 }
142
143 /**
125 * Show certificate field value for a selected certificate field. 144 * Show certificate field value for a selected certificate field.
126 */ 145 */
127 function showCertificateFieldValue() { 146 function showCertificateFieldValue() {
128 var item = $('cert-fields').selectedItem; 147 var item = $('cert-fields').selectedItem;
129 if (item && item.detail.payload.val) 148 if (item && item.detail.payload.val)
130 $('cert-field-value').textContent = item.detail.payload.val; 149 $('cert-field-value').textContent = item.detail.payload.val;
131 else 150 else
132 $('cert-field-value').textContent = ''; 151 $('cert-field-value').textContent = '';
133 } 152 }
134 153
154 /**
155 * Export the selected certificate.
156 */
157 function exportCertificate() {
158 var item = $('hierarchy').selectedItem;
159 if (item && item.detail.payload.index !== undefined)
160 chrome.send('ExportCertificate', [item.detail.payload.index]);
James Hawkins 2011/08/12 19:58:26 s/Export/export/
flackr 2011/08/15 13:47:38 Done.
161 }
162
135 return { 163 return {
136 initialize: initialize, 164 initialize: initialize,
137 getCertificateInfo: getCertificateInfo, 165 getCertificateInfo: getCertificateInfo,
166 getCertificateFields: getCertificateFields,
138 }; 167 };
139 }); 168 });
140 169
141 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); 170 document.addEventListener('DOMContentLoaded', cert_viewer.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698