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

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: Address comments + rebase- 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 this.fire(
73 settings.CertificateActionEvent,
74 /** @type {!CertificateActionEventDetail} */ ({
75 action: action,
76 subnode: this.model,
77 certificateType: this.certificateType,
78 }));
79 },
80
81 /**
82 * Handles the case where a call to the browser resulted in a rejected
83 * promise.
84 * @param {null|!CertificatesError|!CertificatesImportError} error
85 * @private
86 */
87 onRejected_: function(error) {
88 if (error === null) {
89 // Nothing to do here. Null indicates that the user clicked "cancel" on
90 // the native file chooser dialog.
91 return;
92 }
93
94 // Otherwise propagate the error to the parents, such that a dialog
95 // displaying the error will be shown.
96 this.fire('certificates-error', error);
97 },
98
99 /**
29 * @param {!Event} event 100 * @param {!Event} event
30 * @private 101 * @private
31 */ 102 */
32 onViewTap_: function(event) { 103 onViewTap_: function(event) {
33 this.closePopupMenu_(); 104 this.closePopupMenu_();
34 this.browserProxy_.viewCertificate(this.model.id); 105 this.browserProxy_.viewCertificate(this.model.id);
35 }, 106 },
36 107
37 /** 108 /**
38 * @param {!Event} event 109 * @param {!Event} event
39 * @private 110 * @private
40 */ 111 */
41 onEditTap_: function(event) { 112 onEditTap_: function(event) {
42 this.closePopupMenu_(); 113 this.closePopupMenu_();
43 // TODO(dpapad): Open edit dialog. 114 this.dispatchCertificateActionEvent_(settings.CertificateAction.EDIT);
44 }, 115 },
45 116
46 /** 117 /**
47 * @param {!Event} event 118 * @param {!Event} event
48 * @private 119 * @private
49 */ 120 */
50 onDeleteTap_: function(event) { 121 onDeleteTap_: function(event) {
51 this.closePopupMenu_(); 122 this.closePopupMenu_();
52 // TODO(dpapad): Open delete confirmation dialog. 123 this.dispatchCertificateActionEvent_(settings.CertificateAction.DELETE);
53 }, 124 },
54 125
55 /** 126 /**
56 * @param {!Event} event 127 * @param {!Event} event
57 * @private 128 * @private
58 */ 129 */
59 onExportTap_: function(event) { 130 onExportTap_: function(event) {
60 this.closePopupMenu_(); 131 this.closePopupMenu_();
61 if (this.certificateType == settings.CertificateType.PERSONAL) { 132 if (this.certificateType == settings.CertificateType.PERSONAL) {
62 // TODO(dpapad): Open password encryption dialog. 133 this.browserProxy_.exportPersonalCertificate(this.model.id).then(
134 function() {
135 this.dispatchCertificateActionEvent_(
136 settings.CertificateAction.EXPORT_PERSONAL);
137 }.bind(this),
138 this.onRejected_.bind(this));
63 } else { 139 } else {
64 this.browserProxy_.exportCertificate(this.model.id); 140 this.browserProxy_.exportCertificate(this.model.id);
65 } 141 }
66 }, 142 },
67 143
68 /** @private */ 144 /** @private */
69 onImportTap_: function() { 145 onImportTap_: function() {
70 this.closePopupMenu_(); 146 this.closePopupMenu_();
71 if (this.certificateType == settings.CertificateType.PERSONAL) { 147 if (this.certificateType == settings.CertificateType.PERSONAL) {
72 // TODO(dpapad): Figure out when to pass true (ChromeOS?). 148 // TODO(dpapad): Figure out when to pass true (ChromeOS?).
73 this.browserProxy_.importPersonalCertificate(false).then( 149 this.browserProxy_.importPersonalCertificate(false).then(
74 function(showPasswordPrompt) { 150 function(showPasswordPrompt) {
75 if (showPasswordPrompt) { 151 if (showPasswordPrompt) {
76 // TODO(dpapad): Show password decryption dialog. 152 this.dispatchCertificateActionEvent_(
153 settings.CertificateAction.IMPORT_PERSONAL);
77 } 154 }
78 }.bind(this)); 155 }.bind(this),
156 this.onRejected_.bind(this));
79 } else if (this.certificateType == settings.CertificateType.CA) { 157 } else if (this.certificateType == settings.CertificateType.CA) {
80 this.browserProxy_.importCaCertificate().then( 158 this.browserProxy_.importCaCertificate().then(
81 function(certificateName) { 159 function(certificateName) {
82 // TODO(dpapad): Show import dialog. 160 this.dispatchCertificateActionEvent_(
83 }.bind(this)); 161 settings.CertificateAction.IMPORT_CA);
162 }.bind(this),
163 this.onRejected_.bind(this));
84 } else if (this.certificateType == settings.CertificateType.SERVER) { 164 } else if (this.certificateType == settings.CertificateType.SERVER) {
85 this.browserProxy_.importServerCertificate(); 165 this.browserProxy_.importServerCertificate().catch(
166 this.onRejected_.bind(this));
86 } 167 }
87 }, 168 },
88 169
89 /** 170 /**
90 * @param {string} certificateType The type of this certificate. 171 * @param {string} certificateType The type of this certificate.
91 * @return {boolean} Whether the certificate can be edited. 172 * @return {boolean} Whether the certificate can be edited.
92 * @private 173 * @private
93 */ 174 */
94 canEdit_: function(certificateType) { 175 canEdit_: function(certificateType) {
95 return this.certificateType == settings.CertificateType.CA; 176 return this.certificateType == settings.CertificateType.CA;
96 }, 177 },
97 178
98 /** 179 /**
99 * @param {string} certificateType The type of this certificate. 180 * @param {string} certificateType The type of this certificate.
100 * @return {boolean} Whether a certificate can be imported. 181 * @return {boolean} Whether a certificate can be imported.
101 * @private 182 * @private
102 */ 183 */
103 canImport_: function(certificateType) { 184 canImport_: function(certificateType) {
104 return this.certificateType != settings.CertificateType.OTHER; 185 return this.certificateType != settings.CertificateType.OTHER;
105 }, 186 },
106 187
107 /** @private */ 188 /** @private */
108 closePopupMenu_: function() { 189 closePopupMenu_: function() {
109 this.$$('iron-dropdown').close(); 190 this.$$('iron-dropdown').close();
110 }, 191 },
111 }); 192 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698