| 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 behaviors: [I18nBehavior], |
| 24 |
| 25 /** |
| 26 * @return {string} |
| 27 * @private |
| 28 */ |
| 29 getDescription_: function() { |
| 30 switch (this.certificateType) { |
| 31 case settings.CertificateType.PERSONAL: |
| 32 return this.i18n('certificateManagerYourCertificatesDescription'); |
| 33 case settings.CertificateType.SERVER: |
| 34 return this.i18n('certificateManagerServersDescription'); |
| 35 case settings.CertificateType.CA: |
| 36 return this.i18n('certificateManagerAuthoritiesDescription'); |
| 37 case settings.CertificateType.OTHER: |
| 38 return this.i18n('certificateManagerOthersDescription'); |
| 39 } |
| 40 |
| 41 assertNotReached(); |
| 42 }, |
| 43 |
| 44 /** |
| 45 * @return {boolean} |
| 46 * @private |
| 47 */ |
| 48 canImport_: function() { |
| 49 return this.certificateType != settings.CertificateType.OTHER; |
| 50 }, |
| 51 |
| 52 /** |
| 53 * Handles a rejected Promise returned from |browserProxy_|. |
| 54 * @param {null|!CertificatesError|!CertificatesImportError} error |
| 55 * @private |
| 56 */ |
| 57 onRejected_: function(error) { |
| 58 if (error === null) { |
| 59 // Nothing to do here. Null indicates that the user clicked "cancel" on |
| 60 // a native file chooser dialog. |
| 61 return; |
| 62 } |
| 63 |
| 64 // Otherwise propagate the error to the parents, such that a dialog |
| 65 // displaying the error will be shown. |
| 66 this.fire('certificates-error', error); |
| 67 }, |
| 68 |
| 69 |
| 70 /** @private */ |
| 71 dispatchImportActionEvent_: function() { |
| 72 this.fire( |
| 73 settings.CertificateActionEvent, |
| 74 /** @type {!CertificateActionEventDetail} */ ({ |
| 75 action: settings.CertificateAction.IMPORT, |
| 76 subnode: null, |
| 77 certificateType: this.certificateType, |
| 78 })); |
| 79 }, |
| 80 |
| 81 /** @private */ |
| 82 onImportTap_: function() { |
| 83 var browserProxy = settings.CertificatesBrowserProxyImpl.getInstance(); |
| 84 if (this.certificateType == settings.CertificateType.PERSONAL) { |
| 85 browserProxy.importPersonalCertificate(false).then( |
| 86 function(showPasswordPrompt) { |
| 87 if (showPasswordPrompt) |
| 88 this.dispatchImportActionEvent_(); |
| 89 }.bind(this), |
| 90 this.onRejected_.bind(this)); |
| 91 } else if (this.certificateType == settings.CertificateType.CA) { |
| 92 browserProxy.importCaCertificate().then( |
| 93 function(certificateName) { |
| 94 this.dispatchImportActionEvent_(); |
| 95 }.bind(this), |
| 96 this.onRejected_.bind(this)); |
| 97 } else if (this.certificateType == settings.CertificateType.SERVER) { |
| 98 browserProxy.importServerCertificate().catch( |
| 99 this.onRejected_.bind(this)); |
| 100 } else { |
| 101 assertNotReached(); |
| 102 } |
| 103 }, |
| 22 }); | 104 }); |
| OLD | NEW |