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', |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 * @return {boolean} | 57 * @return {boolean} |
| 58 * @private | 58 * @private |
| 59 */ | 59 */ |
| 60 canImportAndBind_: function() { | 60 canImportAndBind_: function() { |
| 61 return this.certificateType == CertificateType.PERSONAL; | 61 return this.certificateType == CertificateType.PERSONAL; |
| 62 }, | 62 }, |
| 63 // </if> | 63 // </if> |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * Handles a rejected Promise returned from |browserProxy_|. | 66 * Handles a rejected Promise returned from |browserProxy_|. |
| 67 * @param {!HTMLElement} anchor | |
| 67 * @param {*} error Expects {!CertificatesError|!CertificatesImportError}. | 68 * @param {*} error Expects {!CertificatesError|!CertificatesImportError}. |
| 68 * @private | 69 * @private |
| 69 */ | 70 */ |
| 70 onRejected_: function(error) { | 71 onRejected_: function(anchor, error) { |
| 71 if (error === null) { | 72 if (error === null) { |
| 72 // Nothing to do here. Null indicates that the user clicked "cancel" on | 73 // Nothing to do here. Null indicates that the user clicked "cancel" on |
| 73 // a native file chooser dialog. | 74 // a native file chooser dialog. |
| 74 return; | 75 return; |
| 75 } | 76 } |
| 76 | 77 |
| 77 // Otherwise propagate the error to the parents, such that a dialog | 78 // Otherwise propagate the error to the parents, such that a dialog |
| 78 // displaying the error will be shown. | 79 // displaying the error will be shown. |
| 79 this.fire('certificates-error', error); | 80 this.fire('certificates-error', {error: error, anchor: anchor}); |
| 80 }, | 81 }, |
| 81 | 82 |
| 82 | 83 |
| 83 /** | 84 /** |
| 84 * @param {?NewCertificateSubNode} subnode | 85 * @param {?NewCertificateSubNode} subnode |
| 86 * @param {!HTMLElement} anchor | |
| 85 * @private | 87 * @private |
| 86 */ | 88 */ |
| 87 dispatchImportActionEvent_: function(subnode) { | 89 dispatchImportActionEvent_: function(subnode, anchor) { |
| 88 this.fire( | 90 this.fire( |
| 89 settings.CertificateActionEvent, | 91 settings.CertificateActionEvent, |
| 90 /** @type {!CertificateActionEventDetail} */ ({ | 92 /** @type {!CertificateActionEventDetail} */ ({ |
| 91 action: CertificateAction.IMPORT, | 93 action: CertificateAction.IMPORT, |
| 92 subnode: subnode, | 94 subnode: subnode, |
| 93 certificateType: this.certificateType, | 95 certificateType: this.certificateType, |
| 96 anchor: anchor, | |
| 94 })); | 97 })); |
| 95 }, | 98 }, |
| 96 | 99 |
| 97 /** @private */ | 100 /** |
| 98 onImportTap_: function() { | 101 * @param {!Event} e |
| 99 this.handleImport_(false); | 102 * @private |
| 103 */ | |
| 104 onImportTap_: function(e) { | |
| 105 this.handleImport_(false, /** @type {!HTMLElement} */ ( | |
| 106 Polymer.dom(e).localTarget)); | |
| 100 }, | 107 }, |
| 101 | 108 |
| 102 // <if expr="chromeos"> | 109 // <if expr="chromeos"> |
| 103 /** @private */ | 110 /** |
| 104 onImportAndBindTap_: function() { | 111 * @private |
| 105 this.handleImport_(true); | 112 * @param {!Event} e |
| 113 */ | |
| 114 onImportAndBindTap_: function(e) { | |
| 115 this.handleImport_(true, /** @type {!HTMLElement} */ ( | |
| 116 Polymer.dom(e).localTarget)); | |
| 106 }, | 117 }, |
| 107 // </if> | 118 // </if> |
| 108 | 119 |
| 109 /** | 120 /** |
| 110 * @param {boolean} useHardwareBacked | 121 * @param {boolean} useHardwareBacked |
| 122 * @param {!HTMLElement} anchor | |
| 111 * @private | 123 * @private |
| 112 */ | 124 */ |
| 113 handleImport_: function(useHardwareBacked) { | 125 handleImport_: function(useHardwareBacked, anchor) { |
| 114 var browserProxy = settings.CertificatesBrowserProxyImpl.getInstance(); | 126 var browserProxy = settings.CertificatesBrowserProxyImpl.getInstance(); |
| 115 if (this.certificateType == CertificateType.PERSONAL) { | 127 if (this.certificateType == CertificateType.PERSONAL) { |
| 116 browserProxy.importPersonalCertificate(useHardwareBacked).then( | 128 browserProxy.importPersonalCertificate(useHardwareBacked).then( |
| 117 function(showPasswordPrompt) { | 129 function(showPasswordPrompt) { |
| 118 if (showPasswordPrompt) | 130 if (showPasswordPrompt) |
| 119 this.dispatchImportActionEvent_(null); | 131 this.dispatchImportActionEvent_(null, anchor); |
| 120 }.bind(this), | 132 }.bind(this), |
| 121 this.onRejected_.bind(this)); | 133 this.onRejected_.bind(this, anchor)); |
| 122 } else if (this.certificateType == CertificateType.CA) { | 134 } else if (this.certificateType == CertificateType.CA) { |
| 123 browserProxy.importCaCertificate().then( | 135 browserProxy.importCaCertificate().then( |
| 124 function(certificateName) { | 136 function(certificateName) { |
| 125 this.dispatchImportActionEvent_({name: certificateName}); | 137 this.dispatchImportActionEvent_({name: certificateName}, anchor); |
| 126 }.bind(this), | 138 }.bind(this), |
| 127 this.onRejected_.bind(this)); | 139 this.onRejected_.bind(this, anchor)); |
| 128 } else if (this.certificateType == CertificateType.SERVER) { | 140 } else if (this.certificateType == CertificateType.SERVER) { |
| 129 browserProxy.importServerCertificate().catch( | 141 browserProxy.importServerCertificate().catch( |
| 130 this.onRejected_.bind(this)); | 142 this.onRejected_.bind(this, anchor)); |
|
tommycli
2017/04/04 22:42:29
Nice partially applied function.
dpapad
2017/04/04 23:15:42
Ack!
| |
| 131 } else { | 143 } else { |
| 132 assertNotReached(); | 144 assertNotReached(); |
| 133 } | 145 } |
| 134 }, | 146 }, |
| 135 }); | 147 }); |
| OLD | NEW |