| 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 /** | |
| 11 * The payload of the certificate-action event that is emitted from this | |
| 12 * component. | |
| 13 * @typedef {{ | |
| 14 * action: !settings.CertificateAction, | |
| 15 * subnode: null|CertificateSubnode|NewCertificateSubNode, | |
| 16 * certificateType: !settings.CertificateType | |
| 17 * }} | |
| 18 */ | |
| 19 var CertificateActionEventDetail; | |
| 20 | |
| 21 cr.define('settings', function() { | 10 cr.define('settings', function() { |
| 22 /** | 11 /** |
| 23 * Enumeration of actions that require a popup menu to be shown to the user. | |
| 24 * @enum {number} | |
| 25 */ | |
| 26 var CertificateAction = { | |
| 27 DELETE: 0, | |
| 28 EDIT: 1, | |
| 29 EXPORT_PERSONAL: 2, | |
| 30 IMPORT: 3, | |
| 31 }; | |
| 32 | |
| 33 /** | |
| 34 * The name of the event that is fired when a menu item is tapped. | 12 * The name of the event that is fired when a menu item is tapped. |
| 35 * @type {string} | 13 * @type {string} |
| 36 */ | 14 */ |
| 37 var CertificateActionEvent = 'certificate-action'; | 15 var CertificateActionEvent = 'certificate-action'; |
| 38 | 16 |
| 39 return { | 17 return { |
| 40 CertificateAction: CertificateAction, | |
| 41 CertificateActionEvent: CertificateActionEvent, | 18 CertificateActionEvent: CertificateActionEvent, |
| 42 }; | 19 }; |
| 43 }); | 20 }); |
| 44 | 21 |
| 45 Polymer({ | 22 Polymer({ |
| 46 is: 'settings-certificate-subentry', | 23 is: 'settings-certificate-subentry', |
| 47 | 24 |
| 48 properties: { | 25 properties: { |
| 49 /** @type {!CertificateSubnode>} */ | 26 /** @type {!CertificateSubnode} */ |
| 50 model: Object, | 27 model: Object, |
| 51 | 28 |
| 52 /** @type {!settings.CertificateType} */ | 29 /** @type {!CertificateType} */ |
| 53 certificateType: String, | 30 certificateType: String, |
| 54 }, | 31 }, |
| 55 | 32 |
| 56 /** @private {!settings.CertificatesManagerBrowserProxy} */ | 33 /** @private {settings.CertificatesBrowserProxy} */ |
| 57 browserProxy_: null, | 34 browserProxy_: null, |
| 58 | 35 |
| 59 /** @override */ | 36 /** @override */ |
| 60 created: function() { | 37 created: function() { |
| 61 this.browserProxy_ = settings.CertificatesBrowserProxyImpl.getInstance(); | 38 this.browserProxy_ = settings.CertificatesBrowserProxyImpl.getInstance(); |
| 62 }, | 39 }, |
| 63 | 40 |
| 64 /** | 41 /** |
| 65 * Dispatches an event indicating which certificate action was tapped. It is | 42 * Dispatches an event indicating which certificate action was tapped. It is |
| 66 * used by the parent of this element to display a modal dialog accordingly. | 43 * used by the parent of this element to display a modal dialog accordingly. |
| 67 * @param {!settings.CertificateAction} action | 44 * @param {!CertificateAction} action |
| 68 * @private | 45 * @private |
| 69 */ | 46 */ |
| 70 dispatchCertificateActionEvent_: function(action) { | 47 dispatchCertificateActionEvent_: function(action) { |
| 71 this.fire( | 48 this.fire( |
| 72 settings.CertificateActionEvent, | 49 settings.CertificateActionEvent, |
| 73 /** @type {!CertificateActionEventDetail} */ ({ | 50 /** @type {!CertificateActionEventDetail} */ ({ |
| 74 action: action, | 51 action: action, |
| 75 subnode: this.model, | 52 subnode: this.model, |
| 76 certificateType: this.certificateType, | 53 certificateType: this.certificateType, |
| 77 })); | 54 })); |
| 78 }, | 55 }, |
| 79 | 56 |
| 80 /** | 57 /** |
| 81 * Handles the case where a call to the browser resulted in a rejected | 58 * Handles the case where a call to the browser resulted in a rejected |
| 82 * promise. | 59 * promise. |
| 83 * @param {?CertificatesError} error | 60 * @param {*} error Expects {?CertificatesError}. |
| 84 * @private | 61 * @private |
| 85 */ | 62 */ |
| 86 onRejected_: function(error) { | 63 onRejected_: function(error) { |
| 87 if (error === null) { | 64 if (error === null) { |
| 88 // Nothing to do here. Null indicates that the user clicked "cancel" on | 65 // Nothing to do here. Null indicates that the user clicked "cancel" on |
| 89 // the native file chooser dialog. | 66 // the native file chooser dialog. |
| 90 return; | 67 return; |
| 91 } | 68 } |
| 92 | 69 |
| 93 // Otherwise propagate the error to the parents, such that a dialog | 70 // Otherwise propagate the error to the parents, such that a dialog |
| 94 // displaying the error will be shown. | 71 // displaying the error will be shown. |
| 95 this.fire('certificates-error', error); | 72 this.fire('certificates-error', error); |
| 96 }, | 73 }, |
| 97 | 74 |
| 98 /** | 75 /** |
| 99 * @param {!Event} event | 76 * @param {!Event} event |
| 100 * @private | 77 * @private |
| 101 */ | 78 */ |
| 102 onViewTap_: function(event) { | 79 onViewTap_: function(event) { |
| 103 this.closePopupMenu_(); | 80 this.closePopupMenu_(); |
| 104 this.browserProxy_.viewCertificate(this.model.id); | 81 this.browserProxy_.viewCertificate(this.model.id); |
| 105 }, | 82 }, |
| 106 | 83 |
| 107 /** | 84 /** |
| 108 * @param {!Event} event | 85 * @param {!Event} event |
| 109 * @private | 86 * @private |
| 110 */ | 87 */ |
| 111 onEditTap_: function(event) { | 88 onEditTap_: function(event) { |
| 112 this.closePopupMenu_(); | 89 this.closePopupMenu_(); |
| 113 this.dispatchCertificateActionEvent_(settings.CertificateAction.EDIT); | 90 this.dispatchCertificateActionEvent_(CertificateAction.EDIT); |
| 114 }, | 91 }, |
| 115 | 92 |
| 116 /** | 93 /** |
| 117 * @param {!Event} event | 94 * @param {!Event} event |
| 118 * @private | 95 * @private |
| 119 */ | 96 */ |
| 120 onDeleteTap_: function(event) { | 97 onDeleteTap_: function(event) { |
| 121 this.closePopupMenu_(); | 98 this.closePopupMenu_(); |
| 122 this.dispatchCertificateActionEvent_(settings.CertificateAction.DELETE); | 99 this.dispatchCertificateActionEvent_(CertificateAction.DELETE); |
| 123 }, | 100 }, |
| 124 | 101 |
| 125 /** | 102 /** |
| 126 * @param {!Event} event | 103 * @param {!Event} event |
| 127 * @private | 104 * @private |
| 128 */ | 105 */ |
| 129 onExportTap_: function(event) { | 106 onExportTap_: function(event) { |
| 130 this.closePopupMenu_(); | 107 this.closePopupMenu_(); |
| 131 if (this.certificateType == settings.CertificateType.PERSONAL) { | 108 if (this.certificateType == CertificateType.PERSONAL) { |
| 132 this.browserProxy_.exportPersonalCertificate(this.model.id).then( | 109 this.browserProxy_.exportPersonalCertificate(this.model.id).then( |
| 133 function() { | 110 function() { |
| 134 this.dispatchCertificateActionEvent_( | 111 this.dispatchCertificateActionEvent_( |
| 135 settings.CertificateAction.EXPORT_PERSONAL); | 112 CertificateAction.EXPORT_PERSONAL); |
| 136 }.bind(this), | 113 }.bind(this), |
| 137 this.onRejected_.bind(this)); | 114 this.onRejected_.bind(this)); |
| 138 } else { | 115 } else { |
| 139 this.browserProxy_.exportCertificate(this.model.id); | 116 this.browserProxy_.exportCertificate(this.model.id); |
| 140 } | 117 } |
| 141 }, | 118 }, |
| 142 | 119 |
| 143 /** | 120 /** |
| 144 * @param {!settings.CertificateType} certificateType | 121 * @param {!CertificateType} certificateType |
| 145 * @param {!CertificateSubnode} model | 122 * @param {!CertificateSubnode} model |
| 146 * @return {boolean} Whether the certificate can be edited. | 123 * @return {boolean} Whether the certificate can be edited. |
| 147 * @private | 124 * @private |
| 148 */ | 125 */ |
| 149 canEdit_: function(certificateType, model) { | 126 canEdit_: function(certificateType, model) { |
| 150 return certificateType == settings.CertificateType.CA && !model.policy; | 127 return certificateType == CertificateType.CA && !model.policy; |
| 151 }, | 128 }, |
| 152 | 129 |
| 153 /** | 130 /** |
| 154 * @param {!settings.CertificateType} certificateType | 131 * @param {!CertificateType} certificateType |
| 155 * @param {!CertificateSubnode} model | 132 * @param {!CertificateSubnode} model |
| 156 * @return {boolean} Whether the certificate can be exported. | 133 * @return {boolean} Whether the certificate can be exported. |
| 157 * @private | 134 * @private |
| 158 */ | 135 */ |
| 159 canExport_: function(certificateType, model) { | 136 canExport_: function(certificateType, model) { |
| 160 if (certificateType == settings.CertificateType.PERSONAL) { | 137 if (certificateType == CertificateType.PERSONAL) { |
| 161 return model.extractable; | 138 return model.extractable; |
| 162 } | 139 } |
| 163 return true; | 140 return true; |
| 164 }, | 141 }, |
| 165 | 142 |
| 166 /** | 143 /** |
| 167 * @param {!CertificateSubnode} model | 144 * @param {!CertificateSubnode} model |
| 168 * @return {boolean} Whether the certificate can be deleted. | 145 * @return {boolean} Whether the certificate can be deleted. |
| 169 * @private | 146 * @private |
| 170 */ | 147 */ |
| 171 canDelete_: function(model) { | 148 canDelete_: function(model) { |
| 172 return !model.readonly && !model.policy; | 149 return !model.readonly && !model.policy; |
| 173 }, | 150 }, |
| 174 | 151 |
| 175 /** @private */ | 152 /** @private */ |
| 176 closePopupMenu_: function() { | 153 closePopupMenu_: function() { |
| 177 this.$$('iron-dropdown').close(); | 154 this.$$('iron-dropdown').close(); |
| 178 }, | 155 }, |
| 179 }); | 156 }); |
| OLD | NEW |