Chromium Code Reviews| 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); | |
| 18 getCertificateInfo(args); | |
| 19 | |
| 20 // The second tab's contents aren't visible on startup, so we can | 17 // The second tab's contents aren't visible on startup, so we can |
| 21 // shorten startup by not populating those controls until after we | 18 // shorten startup by not populating those controls until after we |
| 22 // have had a chance to draw the visible controls the first time. | 19 // 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 | 20 // 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 | 21 // tab in that time but long enough to allow the first tab to draw on |
| 25 // even the slowest machine. | 22 // even the slowest machine. |
| 26 setTimeout(function() { | 23 setTimeout(initializeSecondTab, 200); |
|
flackr
2012/05/17 15:46:56
Can we also hook this up to the tab change and use
Kevin Greer
2012/05/17 15:56:12
Are you sure? That seems a little hackish and add
flackr
2012/05/17 16:56:58
By triggering it on selecting the details tab the
| |
| 27 initializeTree($('hierarchy'), showCertificateFields); | |
| 28 initializeTree($('cert-fields'), showCertificateFieldValue); | |
| 29 createCertificateHierarchy(args.hierarchy); | |
| 30 }, 200); | |
| 31 | 24 |
| 32 stripGtkAccessorKeys(); | 25 stripGtkAccessorKeys(); |
| 33 | 26 |
| 34 $('export').onclick = exportCertificate; | 27 $('export').onclick = exportCertificate; |
| 35 | 28 |
| 36 // TODO(kochi): ESC key should be handled in the views window side. | 29 // TODO(kochi): ESC key should be handled in the views window side. |
| 37 document.addEventListener('keydown', function(e) { | 30 document.addEventListener('keydown', function(e) { |
| 38 if (e.keyCode == 27) // ESC | 31 if (e.keyCode == 27) // ESC |
| 39 chrome.send('DialogClose'); | 32 chrome.send('DialogClose'); |
| 40 }); | 33 }); |
| 41 } | 34 } |
| 42 | 35 |
| 43 /** | 36 /** |
| 37 * Decorate a function so that it can only be invoked once. | |
| 38 */ | |
| 39 function oneShot(fn) { | |
| 40 var fired = false; | |
| 41 return function() { | |
| 42 if (fired) return; | |
| 43 fn(); | |
| 44 fired = true; | |
| 45 }; | |
| 46 } | |
| 47 | |
| 48 /** | |
| 49 * Initialize the second tab's contents. | |
| 50 * This is a 'oneShot' function, meaning it will only be invoked once, | |
| 51 * no matter how many times it is called. This is done for unit-testing | |
| 52 * purposes in case a test needs to initialize the tab before the timer | |
| 53 * fires. | |
| 54 */ | |
| 55 var initializeSecondTab = oneShot(function() { | |
|
flackr
2012/05/17 15:46:56
nit: Call this initializeDetailsTab.
Kevin Greer
2012/05/17 15:56:12
Agreed. That's a better name. Changed.
On 2012/0
| |
| 56 var args = JSON.parse(chrome.dialogArguments); | |
| 57 getCertificateInfo(args); | |
| 58 initializeTree($('hierarchy'), showCertificateFields); | |
| 59 initializeTree($('cert-fields'), showCertificateFieldValue); | |
| 60 createCertificateHierarchy(args.hierarchy); | |
| 61 }); | |
| 62 | |
| 63 /** | |
| 44 * Initialize a cr.ui.Tree object from a given element using the specified | 64 * Initialize a cr.ui.Tree object from a given element using the specified |
| 45 * change handler. | 65 * change handler. |
| 46 * @param {HTMLElement} tree The HTMLElement to style as a tree. | 66 * @param {HTMLElement} tree The HTMLElement to style as a tree. |
| 47 * @param {function()} handler Function to call when a node is selected. | 67 * @param {function()} handler Function to call when a node is selected. |
| 48 */ | 68 */ |
| 49 function initializeTree(tree, handler) { | 69 function initializeTree(tree, handler) { |
| 50 cr.ui.decorate(tree, cr.ui.Tree); | 70 cr.ui.decorate(tree, cr.ui.Tree); |
| 51 tree.detail = {payload: {}, children: {}}; | 71 tree.detail = {payload: {}, children: {}}; |
| 52 tree.addEventListener('change', handler); | 72 tree.addEventListener('change', handler); |
| 53 } | 73 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 chrome.send('exportCertificate', [item.detail.payload.index]); | 204 chrome.send('exportCertificate', [item.detail.payload.index]); |
| 185 } | 205 } |
| 186 | 206 |
| 187 return { | 207 return { |
| 188 initialize: initialize, | 208 initialize: initialize, |
| 189 getCertificateFields: getCertificateFields, | 209 getCertificateFields: getCertificateFields, |
| 190 }; | 210 }; |
| 191 }); | 211 }); |
| 192 | 212 |
| 193 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); | 213 document.addEventListener('DOMContentLoaded', cert_viewer.initialize); |
| OLD | NEW |