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() { |
| 17 return []; |
| 18 }, |
17 }, | 19 }, |
18 | 20 |
19 /** @type {!CertificateType} */ | 21 /** @type {!CertificateType} */ |
20 certificateType: String, | 22 certificateType: String, |
21 | 23 |
22 // <if expr="chromeos"> | 24 // <if expr="chromeos"> |
23 /** @private */ | 25 /** @private */ |
24 isGuest_: { | 26 isGuest_: { |
25 type: Boolean, | 27 type: Boolean, |
26 value: function() { | 28 value: function() { |
27 return loadTimeData.getBoolean('isGuest'); | 29 return loadTimeData.getBoolean('isGuest'); |
28 } | 30 } |
29 }, | 31 }, |
30 // </if> | 32 // </if> |
31 }, | 33 }, |
32 | 34 |
33 behaviors: [I18nBehavior], | 35 behaviors: [I18nBehavior], |
34 | 36 |
35 /** | 37 /** |
36 * @return {string} | 38 * @return {string} |
37 * @private | 39 * @private |
38 */ | 40 */ |
39 getDescription_: function() { | 41 getDescription_: function() { |
40 if (this.certificates.length == 0) | 42 if (this.certificates.length == 0) |
(...skipping 14 matching lines...) Expand all Loading... |
55 }, | 57 }, |
56 | 58 |
57 /** | 59 /** |
58 * @return {boolean} | 60 * @return {boolean} |
59 * @private | 61 * @private |
60 */ | 62 */ |
61 canImport_: function() { | 63 canImport_: function() { |
62 return this.certificateType != CertificateType.OTHER; | 64 return this.certificateType != CertificateType.OTHER; |
63 }, | 65 }, |
64 | 66 |
65 // <if expr="chromeos"> | 67 // <if expr="chromeos"> |
66 /** | 68 /** |
67 * @return {boolean} | 69 * @return {boolean} |
68 * @private | 70 * @private |
69 */ | 71 */ |
70 canImportAndBind_: function() { | 72 canImportAndBind_: function() { |
71 return !this.isGuest_ && this.certificateType == CertificateType.PERSONAL; | 73 return !this.isGuest_ && this.certificateType == CertificateType.PERSONAL; |
72 }, | 74 }, |
73 // </if> | 75 // </if> |
74 | 76 |
75 /** | 77 /** |
76 * Handles a rejected Promise returned from |browserProxy_|. | 78 * Handles a rejected Promise returned from |browserProxy_|. |
77 * @param {!HTMLElement} anchor | 79 * @param {!HTMLElement} anchor |
78 * @param {*} error Expects {!CertificatesError|!CertificatesImportError}. | 80 * @param {*} error Expects {!CertificatesError|!CertificatesImportError}. |
79 * @private | 81 * @private |
80 */ | 82 */ |
81 onRejected_: function(anchor, error) { | 83 onRejected_: function(anchor, error) { |
82 if (error === null) { | 84 if (error === null) { |
83 // Nothing to do here. Null indicates that the user clicked "cancel" on | 85 // Nothing to do here. Null indicates that the user clicked "cancel" on |
(...skipping 21 matching lines...) Expand all Loading... |
105 certificateType: this.certificateType, | 107 certificateType: this.certificateType, |
106 anchor: anchor, | 108 anchor: anchor, |
107 })); | 109 })); |
108 }, | 110 }, |
109 | 111 |
110 /** | 112 /** |
111 * @param {!Event} e | 113 * @param {!Event} e |
112 * @private | 114 * @private |
113 */ | 115 */ |
114 onImportTap_: function(e) { | 116 onImportTap_: function(e) { |
115 this.handleImport_(false, /** @type {!HTMLElement} */ ( | 117 this.handleImport_( |
116 Polymer.dom(e).localTarget)); | 118 false, /** @type {!HTMLElement} */ (Polymer.dom(e).localTarget)); |
117 }, | 119 }, |
118 | 120 |
119 // <if expr="chromeos"> | 121 // <if expr="chromeos"> |
120 /** | 122 /** |
121 * @private | 123 * @private |
122 * @param {!Event} e | 124 * @param {!Event} e |
123 */ | 125 */ |
124 onImportAndBindTap_: function(e) { | 126 onImportAndBindTap_: function(e) { |
125 this.handleImport_(true, /** @type {!HTMLElement} */ ( | 127 this.handleImport_( |
126 Polymer.dom(e).localTarget)); | 128 true, /** @type {!HTMLElement} */ (Polymer.dom(e).localTarget)); |
127 }, | 129 }, |
128 // </if> | 130 // </if> |
129 | 131 |
130 /** | 132 /** |
131 * @param {boolean} useHardwareBacked | 133 * @param {boolean} useHardwareBacked |
132 * @param {!HTMLElement} anchor | 134 * @param {!HTMLElement} anchor |
133 * @private | 135 * @private |
134 */ | 136 */ |
135 handleImport_: function(useHardwareBacked, anchor) { | 137 handleImport_: function(useHardwareBacked, anchor) { |
136 var browserProxy = settings.CertificatesBrowserProxyImpl.getInstance(); | 138 var browserProxy = settings.CertificatesBrowserProxyImpl.getInstance(); |
137 if (this.certificateType == CertificateType.PERSONAL) { | 139 if (this.certificateType == CertificateType.PERSONAL) { |
138 browserProxy.importPersonalCertificate(useHardwareBacked).then( | 140 browserProxy.importPersonalCertificate(useHardwareBacked) |
139 function(showPasswordPrompt) { | 141 .then(function(showPasswordPrompt) { |
140 if (showPasswordPrompt) | 142 if (showPasswordPrompt) |
141 this.dispatchImportActionEvent_(null, anchor); | 143 this.dispatchImportActionEvent_(null, anchor); |
142 }.bind(this), | 144 }.bind(this), this.onRejected_.bind(this, anchor)); |
143 this.onRejected_.bind(this, anchor)); | |
144 } else if (this.certificateType == CertificateType.CA) { | 145 } else if (this.certificateType == CertificateType.CA) { |
145 browserProxy.importCaCertificate().then( | 146 browserProxy.importCaCertificate().then(function(certificateName) { |
146 function(certificateName) { | 147 this.dispatchImportActionEvent_({name: certificateName}, anchor); |
147 this.dispatchImportActionEvent_({name: certificateName}, anchor); | 148 }.bind(this), this.onRejected_.bind(this, anchor)); |
148 }.bind(this), | |
149 this.onRejected_.bind(this, anchor)); | |
150 } else if (this.certificateType == CertificateType.SERVER) { | 149 } else if (this.certificateType == CertificateType.SERVER) { |
151 browserProxy.importServerCertificate().catch( | 150 browserProxy.importServerCertificate().catch( |
152 this.onRejected_.bind(this, anchor)); | 151 this.onRejected_.bind(this, anchor)); |
153 } else { | 152 } else { |
154 assertNotReached(); | 153 assertNotReached(); |
155 } | 154 } |
156 }, | 155 }, |
157 }); | 156 }); |
OLD | NEW |