Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/resources/settings/certificate_manager_page/certificate_subentry.js

Issue 1815733004: MD Settings: Certificate manager, hooking up all dialogs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@certificates_basic_ui
Patch Set: Adding more tests. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
10 /**
11 * The payload of the certificate-action event that is emitted from this
12 * component.
13 * @typedef {{
14 * action: !settings.CertificateAction,
15 * subnode: !CertificateSubnode,
16 * certificateType: !settings.CertificateType
17 * }}
18 */
19 var CertificateActionEventDetail;
20
21 cr.define('settings', function() {
22 /**
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_CA: 3,
31 IMPORT_PERSONAL: 4,
32 };
33
34 /**
35 * The name of the event that is fired when a menu item is tapped.
36 * @type {string}
37 */
38 var CertificateActionEvent = 'certificate-action';
39
40 return {
41 CertificateAction: CertificateAction,
42 CertificateActionEvent: CertificateActionEvent,
43 };
44 });
45
9 Polymer({ 46 Polymer({
10 is: 'settings-certificate-subentry', 47 is: 'settings-certificate-subentry',
11 48
12 properties: { 49 properties: {
13 /** @type {!CertificateSubnode>} */ 50 /** @type {!CertificateSubnode>} */
14 model: Object, 51 model: Object,
15 52
16 /** @type {!settings.CertificateType} */ 53 /** @type {!settings.CertificateType} */
17 certificateType: String, 54 certificateType: String,
18 }, 55 },
19 56
20 /** @private {!settings.CertificatesManagerBrowserProxy} */ 57 /** @private {!settings.CertificatesManagerBrowserProxy} */
21 browserProxy_: null, 58 browserProxy_: null,
22 59
23 /** @override */ 60 /** @override */
24 ready: function() { 61 created: function() {
25 this.browserProxy_ = settings.CertificatesBrowserProxyImpl.getInstance(); 62 this.browserProxy_ = settings.CertificatesBrowserProxyImpl.getInstance();
26 }, 63 },
27 64
28 /** 65 /**
66 * Dispatches an event indicating which certificate action was tapped. It is
67 * used by the parent of this element to display a modal dialog accordingly.
68 * @param {!settings.CertificateAction} action
69 * @private
70 */
71 dispatchCertificateActionEvent_: function(action) {
72 var eventDetail = /** @type {!CertificateActionEventDetail} */ ({
73 action: action,
74 subnode: this.model,
75 certificateType: this.certificateType,
76 });
77 this.dispatchEvent(new CustomEvent(
78 settings.CertificateActionEvent, {detail: eventDetail}));
79 },
80
81 /**
82 * @param {null|!CertificatesError|!CertificatesImportError} error
83 * @private
84 */
85 onError_: function(error) {
tommycli 2016/03/23 19:28:04 Since this can also indicate that the user clicked
dpapad 2016/03/24 22:06:11 Done. I chose "onRejected_" which is shorter but s
86 if (error === null) {
87 // Nothing to do here. Null indicates that the user clicked "cancel" on
88 // the native file chooser dialog.
89 return;
90 }
91
92 // Otherwise propagate the error to the parents, such that a dialog
93 // displaying the error will be shown.
94 this.dispatchEvent(new CustomEvent('certificates-error', {detail: error}));
95 },
96
97 /**
29 * @param {!Event} event 98 * @param {!Event} event
30 * @private 99 * @private
31 */ 100 */
32 onViewTap_: function(event) { 101 onViewTap_: function(event) {
33 this.closePopupMenu_(); 102 this.closePopupMenu_();
34 this.browserProxy_.viewCertificate(this.model.id); 103 this.browserProxy_.viewCertificate(this.model.id);
35 }, 104 },
36 105
37 /** 106 /**
38 * @param {!Event} event 107 * @param {!Event} event
39 * @private 108 * @private
40 */ 109 */
41 onEditTap_: function(event) { 110 onEditTap_: function(event) {
42 this.closePopupMenu_(); 111 this.closePopupMenu_();
43 // TODO(dpapad): Open edit dialog. 112 this.dispatchCertificateActionEvent_(settings.CertificateAction.EDIT);
44 }, 113 },
45 114
46 /** 115 /**
47 * @param {!Event} event 116 * @param {!Event} event
48 * @private 117 * @private
49 */ 118 */
50 onDeleteTap_: function(event) { 119 onDeleteTap_: function(event) {
51 this.closePopupMenu_(); 120 this.closePopupMenu_();
52 // TODO(dpapad): Open delete confirmation dialog. 121 this.dispatchCertificateActionEvent_(settings.CertificateAction.DELETE);
53 }, 122 },
54 123
55 /** 124 /**
56 * @param {!Event} event 125 * @param {!Event} event
57 * @private 126 * @private
58 */ 127 */
59 onExportTap_: function(event) { 128 onExportTap_: function(event) {
60 this.closePopupMenu_(); 129 this.closePopupMenu_();
61 if (this.certificateType == settings.CertificateType.PERSONAL) { 130 if (this.certificateType == settings.CertificateType.PERSONAL) {
62 // TODO(dpapad): Open password encryption dialog. 131 this.browserProxy_.exportPersonalCertificate(this.model.id).then(
132 function() {
133 this.dispatchCertificateActionEvent_(
134 settings.CertificateAction.EXPORT_PERSONAL);
135 }.bind(this), this.onError_.bind(this));
tommycli 2016/03/23 19:28:04 nit: All of these this.onError_.bind(this) args sh
dpapad 2016/03/24 22:06:11 Done.
63 } else { 136 } else {
64 this.browserProxy_.exportCertificate(this.model.id); 137 this.browserProxy_.exportCertificate(this.model.id);
65 } 138 }
66 }, 139 },
67 140
68 /** @private */ 141 /** @private */
69 onImportTap_: function() { 142 onImportTap_: function() {
70 this.closePopupMenu_(); 143 this.closePopupMenu_();
71 if (this.certificateType == settings.CertificateType.PERSONAL) { 144 if (this.certificateType == settings.CertificateType.PERSONAL) {
72 // TODO(dpapad): Figure out when to pass true (ChromeOS?). 145 // TODO(dpapad): Figure out when to pass true (ChromeOS?).
73 this.browserProxy_.importPersonalCertificate(false).then( 146 this.browserProxy_.importPersonalCertificate(false).then(
74 function(showPasswordPrompt) { 147 function(showPasswordPrompt) {
75 if (showPasswordPrompt) { 148 if (showPasswordPrompt) {
76 // TODO(dpapad): Show password decryption dialog. 149 this.dispatchCertificateActionEvent_(
150 settings.CertificateAction.IMPORT_PERSONAL);
77 } 151 }
78 }.bind(this)); 152 }.bind(this), this.onError_.bind(this));
79 } else if (this.certificateType == settings.CertificateType.CA) { 153 } else if (this.certificateType == settings.CertificateType.CA) {
80 this.browserProxy_.importCaCertificate().then( 154 this.browserProxy_.importCaCertificate().then(
81 function(certificateName) { 155 function(certificateName) {
82 // TODO(dpapad): Show import dialog. 156 this.dispatchCertificateActionEvent_(
83 }.bind(this)); 157 settings.CertificateAction.IMPORT_CA);
158 }.bind(this), this.onError_.bind(this));
84 } else if (this.certificateType == settings.CertificateType.SERVER) { 159 } else if (this.certificateType == settings.CertificateType.SERVER) {
85 this.browserProxy_.importServerCertificate(); 160 this.browserProxy_.importServerCertificate().catch(
161 this.onError_.bind(this));
86 } 162 }
87 }, 163 },
88 164
89 /** 165 /**
90 * @param {string} certificateType The type of this certificate. 166 * @param {string} certificateType The type of this certificate.
91 * @return {boolean} Whether the certificate can be edited. 167 * @return {boolean} Whether the certificate can be edited.
92 * @private 168 * @private
93 */ 169 */
94 canEdit_: function(certificateType) { 170 canEdit_: function(certificateType) {
95 return this.certificateType == settings.CertificateType.CA; 171 return this.certificateType == settings.CertificateType.CA;
96 }, 172 },
97 173
98 /** 174 /**
99 * @param {string} certificateType The type of this certificate. 175 * @param {string} certificateType The type of this certificate.
100 * @return {boolean} Whether a certificate can be imported. 176 * @return {boolean} Whether a certificate can be imported.
101 * @private 177 * @private
102 */ 178 */
103 canImport_: function(certificateType) { 179 canImport_: function(certificateType) {
104 return this.certificateType != settings.CertificateType.OTHER; 180 return this.certificateType != settings.CertificateType.OTHER;
105 }, 181 },
106 182
107 /** @private */ 183 /** @private */
108 closePopupMenu_: function() { 184 closePopupMenu_: function() {
109 this.$$('iron-dropdown').close(); 185 this.$$('iron-dropdown').close();
110 }, 186 },
111 }); 187 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698