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