Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * @fileoverview 'settings-certificate-list' is an element that displays a list | 6 * @fileoverview 'settings-certificate-list' is an element that displays a list |
| 7 * of certificates. | 7 * of certificates. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'settings-certificate-list', | 10 is: 'settings-certificate-list', |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 /** @type {!Array<!Certificate>} */ | 13 /** @type {!Array<!Certificate>} */ |
| 14 certificates: { | 14 certificates: { |
| 15 type: Array, | 15 type: Array, |
| 16 value: function() { return []; }, | 16 value: function() { return []; }, |
| 17 }, | 17 }, |
| 18 | 18 |
| 19 /** @type {!settings.CertificateType} */ | 19 /** @type {!settings.CertificateType} */ |
| 20 certificateType: String, | 20 certificateType: String, |
| 21 }, | 21 }, |
| 22 | |
| 23 /** | |
| 24 * @return {string} | |
| 25 * @private | |
| 26 */ | |
| 27 getDescription_: function() { | |
| 28 var get = function(string) { | |
| 29 return loadTimeData.getString( | |
| 30 'certificateManager' + string + 'Description'); | |
| 31 }; | |
| 32 | |
| 33 switch (this.certificateType) { | |
| 34 case settings.CertificateType.PERSONAL: | |
| 35 return get('YourCertificates'); | |
|
Dan Beam
2016/04/01 18:38:02
I would recommend not splitting up these identifie
dpapad
2016/04/01 21:13:17
Done. Also modified 18n() definition to call getSt
| |
| 36 case settings.CertificateType.SERVER: | |
| 37 return get('Servers'); | |
| 38 case settings.CertificateType.CA: | |
| 39 return get('Authorities'); | |
| 40 case settings.CertificateType.OTHER: | |
| 41 return get('Others'); | |
| 42 } | |
| 43 | |
| 44 assertNotReached(); | |
| 45 }, | |
| 46 | |
| 47 /** | |
| 48 * @return {boolean} | |
| 49 * @private | |
| 50 */ | |
| 51 canImport_: function() { | |
| 52 return this.certificateType != settings.CertificateType.OTHER; | |
| 53 }, | |
| 54 | |
| 55 /** | |
| 56 * Handles a rejected Promise returned from |browserProxy_|. | |
| 57 * @param {null|!CertificatesError|!CertificatesImportError} error | |
| 58 * @private | |
| 59 */ | |
| 60 onRejected_: function(error) { | |
| 61 if (error === null) { | |
| 62 // Nothing to do here. Null indicates that the user clicked "cancel" on | |
| 63 // a native file chooser dialog. | |
| 64 return; | |
| 65 } | |
| 66 | |
| 67 // Otherwise propagate the error to the parents, such that a dialog | |
| 68 // displaying the error will be shown. | |
| 69 this.fire('certificates-error', error); | |
| 70 }, | |
| 71 | |
| 72 | |
| 73 /** @private */ | |
| 74 dispatchImportActionEvent_: function() { | |
| 75 this.fire( | |
| 76 settings.CertificateActionEvent, | |
| 77 /** @type {!CertificateActionEventDetail} */ ({ | |
| 78 action: settings.CertificateAction.IMPORT, | |
| 79 subnode: null, | |
| 80 certificateType: this.certificateType, | |
| 81 })); | |
| 82 }, | |
| 83 | |
| 84 /** @private */ | |
| 85 onImportTap_: function() { | |
| 86 var browserProxy = settings.CertificatesBrowserProxyImpl.getInstance(); | |
| 87 if (this.certificateType == settings.CertificateType.PERSONAL) { | |
| 88 browserProxy.importPersonalCertificate(false).then( | |
| 89 function(showPasswordPrompt) { | |
| 90 if (showPasswordPrompt) { | |
| 91 this.dispatchImportActionEvent_(); | |
| 92 } | |
|
Dan Beam
2016/04/01 18:38:02
nit: no curlies
dpapad
2016/04/01 21:13:17
Done.
| |
| 93 }.bind(this), | |
| 94 this.onRejected_.bind(this)); | |
| 95 } else if (this.certificateType == settings.CertificateType.CA) { | |
| 96 browserProxy.importCaCertificate().then( | |
| 97 function(certificateName) { | |
| 98 this.dispatchImportActionEvent_(); | |
| 99 }.bind(this), | |
| 100 this.onRejected_.bind(this)); | |
| 101 } else if (this.certificateType == settings.CertificateType.SERVER) { | |
| 102 browserProxy.importServerCertificate().catch( | |
| 103 this.onRejected_.bind(this)); | |
| 104 } else { | |
| 105 assertNotReached(); | |
| 106 } | |
| 107 }, | |
| 22 }); | 108 }); |
| OLD | NEW |