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

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

Issue 2792663002: MD Settings: Restore focus after closing dialogs, for certificate page. (Closed)
Patch Set: Update error dialog. Created 3 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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-manager-page' is the settings page 6 * @fileoverview 'settings-certificate-manager-page' is the settings page
7 * containing SSL certificate settings. 7 * containing SSL certificate settings.
8 */ 8 */
9 Polymer({ 9 Polymer({
10 is: 'settings-certificate-manager-page', 10 is: 'settings-certificate-manager-page',
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 * certificate. 75 * certificate.
76 * @private {?CertificateType} 76 * @private {?CertificateType}
77 */ 77 */
78 dialogModelCertificateType_: String, 78 dialogModelCertificateType_: String,
79 79
80 /** 80 /**
81 * The model to be passed to the error dialog. 81 * The model to be passed to the error dialog.
82 * @private {null|!CertificatesError|!CertificatesImportError} 82 * @private {null|!CertificatesError|!CertificatesImportError}
83 */ 83 */
84 errorDialogModel_: Object, 84 errorDialogModel_: Object,
85
86 /**
87 * The element to return focus to, when the currently shown dialog is
88 * closed.
89 * @private {?HTMLElement}
90 */
91 activeDialogAnchor_: Object,
85 }, 92 },
86 93
87 /** @override */ 94 /** @override */
88 attached: function() { 95 attached: function() {
89 this.addWebUIListener('certificates-changed', this.set.bind(this)); 96 this.addWebUIListener('certificates-changed', this.set.bind(this));
90 settings.CertificatesBrowserProxyImpl.getInstance().refreshCertificates(); 97 settings.CertificatesBrowserProxyImpl.getInstance().refreshCertificates();
91 }, 98 },
92 99
93 /** 100 /**
94 * @param {number} selectedIndex 101 * @param {number} selectedIndex
95 * @param {number} tabIndex 102 * @param {number} tabIndex
96 * @return {boolean} Whether to show tab at |tabIndex|. 103 * @return {boolean} Whether to show tab at |tabIndex|.
97 * @private 104 * @private
98 */ 105 */
99 isTabSelected_: function(selectedIndex, tabIndex) { 106 isTabSelected_: function(selectedIndex, tabIndex) {
100 return selectedIndex == tabIndex; 107 return selectedIndex == tabIndex;
101 }, 108 },
102 109
103 /** @override */ 110 /** @override */
104 ready: function() { 111 ready: function() {
105 this.addEventListener(settings.CertificateActionEvent, function(event) { 112 this.addEventListener(settings.CertificateActionEvent, function(event) {
106 this.dialogModel_ = event.detail.subnode; 113 this.dialogModel_ = event.detail.subnode;
107 this.dialogModelCertificateType_ = event.detail.certificateType; 114 this.dialogModelCertificateType_ = event.detail.certificateType;
108 115
109 if (event.detail.action == CertificateAction.IMPORT) { 116 if (event.detail.action == CertificateAction.IMPORT) {
110 if (event.detail.certificateType == CertificateType.PERSONAL) { 117 if (event.detail.certificateType == CertificateType.PERSONAL) {
111 this.openDialog_( 118 this.openDialog_(
112 'settings-certificate-password-decryption-dialog', 119 'settings-certificate-password-decryption-dialog',
113 'showPasswordDecryptionDialog_'); 120 'showPasswordDecryptionDialog_',
121 event.detail.anchor);
114 } else if (event.detail.certificateType == 122 } else if (event.detail.certificateType ==
115 CertificateType.CA) { 123 CertificateType.CA) {
116 this.openDialog_( 124 this.openDialog_(
117 'settings-ca-trust-edit-dialog', 'showCaTrustEditDialog_'); 125 'settings-ca-trust-edit-dialog', 'showCaTrustEditDialog_',
126 event.detail.anchor);
118 } 127 }
119 } else { 128 } else {
120 if (event.detail.action == CertificateAction.EDIT) { 129 if (event.detail.action == CertificateAction.EDIT) {
121 this.openDialog_( 130 this.openDialog_(
122 'settings-ca-trust-edit-dialog', 'showCaTrustEditDialog_'); 131 'settings-ca-trust-edit-dialog', 'showCaTrustEditDialog_',
132 event.detail.anchor);
123 } else if (event.detail.action == CertificateAction.DELETE) { 133 } else if (event.detail.action == CertificateAction.DELETE) {
124 this.openDialog_( 134 this.openDialog_(
125 'settings-certificate-delete-confirmation-dialog', 135 'settings-certificate-delete-confirmation-dialog',
126 'showDeleteConfirmationDialog_'); 136 'showDeleteConfirmationDialog_', event.detail.anchor);
127 } else if (event.detail.action == 137 } else if (event.detail.action ==
128 CertificateAction.EXPORT_PERSONAL) { 138 CertificateAction.EXPORT_PERSONAL) {
129 this.openDialog_( 139 this.openDialog_(
130 'settings-certificate-password-encryption-dialog', 140 'settings-certificate-password-encryption-dialog',
131 'showPasswordEncryptionDialog_'); 141 'showPasswordEncryptionDialog_', event.detail.anchor);
132 } 142 }
133 } 143 }
134 144
135 event.stopPropagation(); 145 event.stopPropagation();
136 }.bind(this)); 146 }.bind(this));
137 147
138 this.addEventListener('certificates-error', function(event) { 148 this.addEventListener('certificates-error', function(event) {
139 this.errorDialogModel_ = event.detail; 149 var detail = /** @type {!CertificatesErrorEventDetail} */ (event.detail);
150 this.errorDialogModel_ = detail.error;
140 this.openDialog_( 151 this.openDialog_(
141 'settings-certificates-error-dialog', 152 'settings-certificates-error-dialog',
142 'showErrorDialog_'); 153 'showErrorDialog_',
154 detail.anchor);
143 event.stopPropagation(); 155 event.stopPropagation();
144 }.bind(this)); 156 }.bind(this));
145 }, 157 },
146 158
147 /** 159 /**
148 * Opens a dialog and registers a listener for removing the dialog from the 160 * Opens a dialog and registers a listener for removing the dialog from the
149 * DOM once is closed. The listener is destroyed when the dialog is removed 161 * DOM once is closed. The listener is destroyed when the dialog is removed
150 * (because of 'restamp'). 162 * (because of 'restamp').
151 * 163 *
152 * @param {string} dialogTagName The tag name of the dialog to be shown. 164 * @param {string} dialogTagName The tag name of the dialog to be shown.
153 * @param {string} domIfBooleanName The name of the boolean variable 165 * @param {string} domIfBooleanName The name of the boolean variable
154 * corresponding to the dialog. 166 * corresponding to the dialog.
167 * @param {?HTMLElement} anchor The element to focus when the dialog is
168 * closed. If null, the previous anchor element should be reused.
155 * @private 169 * @private
156 */ 170 */
157 openDialog_: function(dialogTagName, domIfBooleanName) { 171 openDialog_: function(dialogTagName, domIfBooleanName, anchor) {
172 if (anchor)
173 this.activeDialogAnchor_ = anchor;
158 this.set(domIfBooleanName, true); 174 this.set(domIfBooleanName, true);
159 this.async(function() { 175 this.async(function() {
160 var dialog = this.$$(dialogTagName); 176 var dialog = this.$$(dialogTagName);
161 dialog.addEventListener('close', function() { 177 dialog.addEventListener('close', function() {
162 this.set(domIfBooleanName, false); 178 this.set(domIfBooleanName, false);
179 this.activeDialogAnchor_.focus();
tommycli 2017/04/04 22:42:29 It looks like you don't actually need to store act
Dan Beam 2017/04/04 22:46:00 also, why only set it if (anchor)?
Dan Beam 2017/04/04 22:47:21 tommycli@: the difference is that openDialog_ (in
tommycli 2017/04/04 22:56:49 Ah yes, that behavior is different. Actually now
dpapad 2017/04/04 23:15:42 Certificates manager page is a pretty interesting
tommycli 2017/04/04 23:21:26 Wow that's really tricky. If the above is the inte
dpapad 2017/04/05 00:03:18 I was hoping that the explanation given at the JSD
Dan Beam 2017/04/05 03:31:36 ping ^
tommycli 2017/04/05 16:11:44 dbeam: I'm assuming it's because if anchor is null
163 }.bind(this)); 180 }.bind(this));
164 }.bind(this)); 181 }.bind(this));
165 }, 182 },
166 }); 183 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698