| 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. |
| 11 */ | 11 */ |
| 12 function initialize() { | 12 function initialize() { |
| 13 cr.ui.decorate('tabbox', cr.ui.TabBox); | 13 cr.ui.decorate('tabbox', cr.ui.TabBox); |
| 14 | 14 |
| 15 i18nTemplate.process(document, templateData); | 15 i18nTemplate.process(document, templateData); |
| 16 | 16 |
| 17 var args = JSON.parse(chrome.dialogArguments); | 17 var args = JSON.parse(chrome.dialogArguments); |
| 18 getCertificateInfo(args); | 18 getCertificateInfo(args); |
| 19 | 19 |
| 20 /** |
| 21 * Initialize the second tab's contents. |
| 22 * This is a 'oneShot' function, meaning it will only be invoked once, |
| 23 * no matter how many times it is called. This is done for unit-testing |
| 24 * purposes in case a test needs to initialize the tab before the timer |
| 25 * fires. |
| 26 */ |
| 27 var initializeDetailTab = oneShot(function() { |
| 28 initializeTree($('hierarchy'), showCertificateFields); |
| 29 initializeTree($('cert-fields'), showCertificateFieldValue); |
| 30 createCertificateHierarchy(args.hierarchy); |
| 31 }); |
| 32 |
| 20 // The second tab's contents aren't visible on startup, so we can | 33 // The second tab's contents aren't visible on startup, so we can |
| 21 // shorten startup by not populating those controls until after we | 34 // shorten startup by not populating those controls until after we |
| 22 // have had a chance to draw the visible controls the first time. | 35 // have had a chance to draw the visible controls the first time. |
| 23 // The value of 200ms is quick enough that the user couldn't open the | 36 // The value of 200ms is quick enough that the user couldn't open the |
| 24 // tab in that time but long enough to allow the first tab to draw on | 37 // tab in that time but long enough to allow the first tab to draw on |
| 25 // even the slowest machine. | 38 // even the slowest machine. |
| 26 setTimeout(function() { | 39 setTimeout(initializeDetailTab, 200); |
| 27 initializeTree($('hierarchy'), showCertificateFields); | 40 |
| 28 initializeTree($('cert-fields'), showCertificateFieldValue); | 41 $('tabbox').addEventListener('selectedChange', function f(e) { |
| 29 createCertificateHierarchy(args.hierarchy); | 42 $('tabbox').removeEventListener('selectedChange', f); |
| 30 }, 200); | 43 initializeDetailTab(); |
| 44 }, true); |
| 31 | 45 |
| 32 stripGtkAccessorKeys(); | 46 stripGtkAccessorKeys(); |
| 33 | 47 |
| 34 $('export').onclick = exportCertificate; | 48 $('export').onclick = exportCertificate; |
| 35 | 49 |
| 36 // TODO(kochi): ESC key should be handled in the views window side. | 50 // TODO(kochi): ESC key should be handled in the views window side. |
| 37 document.addEventListener('keydown', function(e) { | 51 document.addEventListener('keydown', function(e) { |
| 38 if (e.keyCode == 27) // ESC | 52 if (e.keyCode == 27) // ESC |
| 39 chrome.send('DialogClose'); | 53 chrome.send('DialogClose'); |
| 40 }); | 54 }); |
| 41 } | 55 } |
| 42 | 56 |
| 43 /** | 57 /** |
| 58 * Decorate a function so that it can only be invoked once. |
| 59 */ |
| 60 function oneShot(fn) { |
| 61 var fired = false; |
| 62 return function() { |
| 63 if (fired) return; |
| 64 fn(); |
| 65 fired = true; |
| 66 }; |
| 67 } |
| 68 |
| 69 /** |
| 44 * Initialize a cr.ui.Tree object from a given element using the specified | 70 * Initialize a cr.ui.Tree object from a given element using the specified |
| 45 * change handler. | 71 * change handler. |
| 46 * @param {HTMLElement} tree The HTMLElement to style as a tree. | 72 * @param {HTMLElement} tree The HTMLElement to style as a tree. |
| 47 * @param {function()} handler Function to call when a node is selected. | 73 * @param {function()} handler Function to call when a node is selected. |
| 48 */ | 74 */ |
| 49 function initializeTree(tree, handler) { | 75 function initializeTree(tree, handler) { |
| 50 cr.ui.decorate(tree, cr.ui.Tree); | 76 cr.ui.decorate(tree, cr.ui.Tree); |
| 51 tree.detail = {payload: {}, children: {}}; | 77 tree.detail = {payload: {}, children: {}}; |
| 52 tree.addEventListener('change', handler); | 78 tree.addEventListener('change', handler); |
| 53 } | 79 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 chrome.send('exportCertificate', [item.detail.payload.index]); | 210 chrome.send('exportCertificate', [item.detail.payload.index]); |
| 185 } | 211 } |
| 186 | 212 |
| 187 return { | 213 return { |
| 188 initialize: initialize, | 214 initialize: initialize, |
| 189 getCertificateFields: getCertificateFields, | 215 getCertificateFields: getCertificateFields, |
| 190 }; | 216 }; |
| 191 }); | 217 }); |
| 192 | 218 |
| 193 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); | 219 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); |
| OLD | NEW |