| 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-subentry represents an SSL certificate | 6 * @fileoverview settings-certificate-subentry represents an SSL certificate |
| 7 * sub-entry. | 7 * sub-entry. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * The payload of the certificate-action event that is emitted from this | 11 * The payload of the certificate-action event that is emitted from this |
| 12 * component. | 12 * component. |
| 13 * @typedef {{ | 13 * @typedef {{ |
| 14 * action: !settings.CertificateAction, | 14 * action: !settings.CertificateAction, |
| 15 * subnode: !CertificateSubnode, | 15 * subnode: ?CertificateSubnode, |
| 16 * certificateType: !settings.CertificateType | 16 * certificateType: !settings.CertificateType |
| 17 * }} | 17 * }} |
| 18 */ | 18 */ |
| 19 var CertificateActionEventDetail; | 19 var CertificateActionEventDetail; |
| 20 | 20 |
| 21 cr.define('settings', function() { | 21 cr.define('settings', function() { |
| 22 /** | 22 /** |
| 23 * Enumeration of actions that require a popup menu to be shown to the user. | 23 * Enumeration of actions that require a popup menu to be shown to the user. |
| 24 * @enum {number} | 24 * @enum {number} |
| 25 */ | 25 */ |
| 26 var CertificateAction = { | 26 var CertificateAction = { |
| 27 DELETE: 0, | 27 DELETE: 0, |
| 28 EDIT: 1, | 28 EDIT: 1, |
| 29 EXPORT_PERSONAL: 2, | 29 EXPORT_PERSONAL: 2, |
| 30 IMPORT_CA: 3, | 30 IMPORT: 3, |
| 31 IMPORT_PERSONAL: 4, | |
| 32 }; | 31 }; |
| 33 | 32 |
| 34 /** | 33 /** |
| 35 * The name of the event that is fired when a menu item is tapped. | 34 * The name of the event that is fired when a menu item is tapped. |
| 36 * @type {string} | 35 * @type {string} |
| 37 */ | 36 */ |
| 38 var CertificateActionEvent = 'certificate-action'; | 37 var CertificateActionEvent = 'certificate-action'; |
| 39 | 38 |
| 40 return { | 39 return { |
| 41 CertificateAction: CertificateAction, | 40 CertificateAction: CertificateAction, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 /** @type {!CertificateActionEventDetail} */ ({ | 73 /** @type {!CertificateActionEventDetail} */ ({ |
| 75 action: action, | 74 action: action, |
| 76 subnode: this.model, | 75 subnode: this.model, |
| 77 certificateType: this.certificateType, | 76 certificateType: this.certificateType, |
| 78 })); | 77 })); |
| 79 }, | 78 }, |
| 80 | 79 |
| 81 /** | 80 /** |
| 82 * Handles the case where a call to the browser resulted in a rejected | 81 * Handles the case where a call to the browser resulted in a rejected |
| 83 * promise. | 82 * promise. |
| 84 * @param {null|!CertificatesError|!CertificatesImportError} error | 83 * @param {?CertificatesError} error |
| 85 * @private | 84 * @private |
| 86 */ | 85 */ |
| 87 onRejected_: function(error) { | 86 onRejected_: function(error) { |
| 88 if (error === null) { | 87 if (error === null) { |
| 89 // Nothing to do here. Null indicates that the user clicked "cancel" on | 88 // Nothing to do here. Null indicates that the user clicked "cancel" on |
| 90 // the native file chooser dialog. | 89 // the native file chooser dialog. |
| 91 return; | 90 return; |
| 92 } | 91 } |
| 93 | 92 |
| 94 // Otherwise propagate the error to the parents, such that a dialog | 93 // Otherwise propagate the error to the parents, such that a dialog |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 function() { | 133 function() { |
| 135 this.dispatchCertificateActionEvent_( | 134 this.dispatchCertificateActionEvent_( |
| 136 settings.CertificateAction.EXPORT_PERSONAL); | 135 settings.CertificateAction.EXPORT_PERSONAL); |
| 137 }.bind(this), | 136 }.bind(this), |
| 138 this.onRejected_.bind(this)); | 137 this.onRejected_.bind(this)); |
| 139 } else { | 138 } else { |
| 140 this.browserProxy_.exportCertificate(this.model.id); | 139 this.browserProxy_.exportCertificate(this.model.id); |
| 141 } | 140 } |
| 142 }, | 141 }, |
| 143 | 142 |
| 144 /** @private */ | |
| 145 onImportTap_: function() { | |
| 146 this.closePopupMenu_(); | |
| 147 if (this.certificateType == settings.CertificateType.PERSONAL) { | |
| 148 // TODO(dpapad): Figure out when to pass true (ChromeOS?). | |
| 149 this.browserProxy_.importPersonalCertificate(false).then( | |
| 150 function(showPasswordPrompt) { | |
| 151 if (showPasswordPrompt) { | |
| 152 this.dispatchCertificateActionEvent_( | |
| 153 settings.CertificateAction.IMPORT_PERSONAL); | |
| 154 } | |
| 155 }.bind(this), | |
| 156 this.onRejected_.bind(this)); | |
| 157 } else if (this.certificateType == settings.CertificateType.CA) { | |
| 158 this.browserProxy_.importCaCertificate().then( | |
| 159 function(certificateName) { | |
| 160 this.dispatchCertificateActionEvent_( | |
| 161 settings.CertificateAction.IMPORT_CA); | |
| 162 }.bind(this), | |
| 163 this.onRejected_.bind(this)); | |
| 164 } else if (this.certificateType == settings.CertificateType.SERVER) { | |
| 165 this.browserProxy_.importServerCertificate().catch( | |
| 166 this.onRejected_.bind(this)); | |
| 167 } | |
| 168 }, | |
| 169 | |
| 170 /** | 143 /** |
| 171 * @param {string} certificateType The type of this certificate. | 144 * @param {string} certificateType The type of this certificate. |
| 172 * @return {boolean} Whether the certificate can be edited. | 145 * @return {boolean} Whether the certificate can be edited. |
| 173 * @private | 146 * @private |
| 174 */ | 147 */ |
| 175 canEdit_: function(certificateType) { | 148 canEdit_: function(certificateType) { |
| 176 return this.certificateType == settings.CertificateType.CA; | 149 return this.certificateType == settings.CertificateType.CA; |
| 177 }, | 150 }, |
| 178 | 151 |
| 179 /** | |
| 180 * @param {string} certificateType The type of this certificate. | |
| 181 * @return {boolean} Whether a certificate can be imported. | |
| 182 * @private | |
| 183 */ | |
| 184 canImport_: function(certificateType) { | |
| 185 return this.certificateType != settings.CertificateType.OTHER; | |
| 186 }, | |
| 187 | |
| 188 /** @private */ | 152 /** @private */ |
| 189 closePopupMenu_: function() { | 153 closePopupMenu_: function() { |
| 190 this.$$('iron-dropdown').close(); | 154 this.$$('iron-dropdown').close(); |
| 191 }, | 155 }, |
| 192 }); | 156 }); |
| OLD | NEW |