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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/certificate_manager_page/certificate_subentry.js
diff --git a/chrome/browser/resources/settings/certificate_manager_page/certificate_subentry.js b/chrome/browser/resources/settings/certificate_manager_page/certificate_subentry.js
index b750ebbb3cdf58cfd2ec6a43cb9cb40fda073123..fcd4da7036241b105febf070439f964e676b793f 100644
--- a/chrome/browser/resources/settings/certificate_manager_page/certificate_subentry.js
+++ b/chrome/browser/resources/settings/certificate_manager_page/certificate_subentry.js
@@ -6,6 +6,43 @@
* @fileoverview settings-certificate-subentry represents an SSL certificate
* sub-entry.
*/
+
+/**
+ * The payload of the certificate-action event that is emitted from this
+ * component.
+ * @typedef {{
+ * action: !settings.CertificateAction,
+ * subnode: !CertificateSubnode,
+ * certificateType: !settings.CertificateType
+ * }}
+ */
+var CertificateActionEventDetail;
+
+cr.define('settings', function() {
+ /**
+ * Enumeration of actions that require a popup menu to be shown to the user.
+ * @enum {number}
+ */
+ var CertificateAction = {
+ DELETE: 0,
+ EDIT: 1,
+ EXPORT_PERSONAL: 2,
+ IMPORT_CA: 3,
+ IMPORT_PERSONAL: 4,
+ };
+
+ /**
+ * The name of the event that is fired when a menu item is tapped.
+ * @type {string}
+ */
+ var CertificateActionEvent = 'certificate-action';
+
+ return {
+ CertificateAction: CertificateAction,
+ CertificateActionEvent: CertificateActionEvent,
+ };
+});
+
Polymer({
is: 'settings-certificate-subentry',
@@ -21,11 +58,43 @@ Polymer({
browserProxy_: null,
/** @override */
- ready: function() {
+ created: function() {
this.browserProxy_ = settings.CertificatesBrowserProxyImpl.getInstance();
},
/**
+ * Dispatches an event indicating which certificate action was tapped. It is
+ * used by the parent of this element to display a modal dialog accordingly.
+ * @param {!settings.CertificateAction} action
+ * @private
+ */
+ dispatchCertificateActionEvent_: function(action) {
+ var eventDetail = /** @type {!CertificateActionEventDetail} */ ({
+ action: action,
+ subnode: this.model,
+ certificateType: this.certificateType,
+ });
+ this.dispatchEvent(new CustomEvent(
+ settings.CertificateActionEvent, {detail: eventDetail}));
+ },
+
+ /**
+ * @param {null|!CertificatesError|!CertificatesImportError} error
+ * @private
+ */
+ 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
+ if (error === null) {
+ // Nothing to do here. Null indicates that the user clicked "cancel" on
+ // the native file chooser dialog.
+ return;
+ }
+
+ // Otherwise propagate the error to the parents, such that a dialog
+ // displaying the error will be shown.
+ this.dispatchEvent(new CustomEvent('certificates-error', {detail: error}));
+ },
+
+ /**
* @param {!Event} event
* @private
*/
@@ -40,7 +109,7 @@ Polymer({
*/
onEditTap_: function(event) {
this.closePopupMenu_();
- // TODO(dpapad): Open edit dialog.
+ this.dispatchCertificateActionEvent_(settings.CertificateAction.EDIT);
},
/**
@@ -49,7 +118,7 @@ Polymer({
*/
onDeleteTap_: function(event) {
this.closePopupMenu_();
- // TODO(dpapad): Open delete confirmation dialog.
+ this.dispatchCertificateActionEvent_(settings.CertificateAction.DELETE);
},
/**
@@ -59,7 +128,11 @@ Polymer({
onExportTap_: function(event) {
this.closePopupMenu_();
if (this.certificateType == settings.CertificateType.PERSONAL) {
- // TODO(dpapad): Open password encryption dialog.
+ this.browserProxy_.exportPersonalCertificate(this.model.id).then(
+ function() {
+ this.dispatchCertificateActionEvent_(
+ settings.CertificateAction.EXPORT_PERSONAL);
+ }.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.
} else {
this.browserProxy_.exportCertificate(this.model.id);
}
@@ -73,16 +146,19 @@ Polymer({
this.browserProxy_.importPersonalCertificate(false).then(
function(showPasswordPrompt) {
if (showPasswordPrompt) {
- // TODO(dpapad): Show password decryption dialog.
+ this.dispatchCertificateActionEvent_(
+ settings.CertificateAction.IMPORT_PERSONAL);
}
- }.bind(this));
+ }.bind(this), this.onError_.bind(this));
} else if (this.certificateType == settings.CertificateType.CA) {
this.browserProxy_.importCaCertificate().then(
function(certificateName) {
- // TODO(dpapad): Show import dialog.
- }.bind(this));
+ this.dispatchCertificateActionEvent_(
+ settings.CertificateAction.IMPORT_CA);
+ }.bind(this), this.onError_.bind(this));
} else if (this.certificateType == settings.CertificateType.SERVER) {
- this.browserProxy_.importServerCertificate();
+ this.browserProxy_.importServerCertificate().catch(
+ this.onError_.bind(this));
}
},

Powered by Google App Engine
This is Rietveld 408576698