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

Unified Diff: remoting/webapp/base/js/modal_dialogs.js

Issue 1101613003: [Webapp Refactor] Reliably cancels a connection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ImproveUnittest
Patch Set: Rebase Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | remoting/webapp/crd/js/client_session.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/base/js/modal_dialogs.js
diff --git a/remoting/webapp/base/js/modal_dialogs.js b/remoting/webapp/base/js/modal_dialogs.js
index f8837e51026bddb3ee20238b9cf5aa47e9455b08..9c489b3154178259fa55558be95ec3c5525a1b30 100644
--- a/remoting/webapp/base/js/modal_dialogs.js
+++ b/remoting/webapp/base/js/modal_dialogs.js
@@ -56,17 +56,17 @@ remoting.InputDialog.prototype.show = function() {
/** @return {HTMLElement} */
remoting.InputDialog.prototype.inputField = function() {
return this.inputField_;
-}
+};
/** @private */
remoting.InputDialog.prototype.onSubmit_ = function() {
this.deferred_.resolve(this.inputField_.value);
-}
+};
/** @private */
remoting.InputDialog.prototype.onCancel_ = function() {
this.deferred_.reject(new remoting.Error(remoting.Error.Tag.CANCELLED));
-}
+};
/**
* @param {function():void} handler
@@ -97,7 +97,9 @@ remoting.InputDialog.prototype.createFormEventHandler_ = function(handler) {
* @param {remoting.AppMode} mode
* @param {HTMLElement} primaryButton
* @param {HTMLElement=} opt_secondaryButton
+ *
* @constructor
+ * @implements {base.Disposable}
*/
remoting.MessageDialog = function(mode, primaryButton, opt_secondaryButton) {
/** @private @const */
@@ -136,6 +138,15 @@ remoting.MessageDialog.prototype.show = function() {
return this.deferred_.promise();
};
+remoting.MessageDialog.prototype.dispose = function() {
+ base.dispose(this.eventHooks_);
+ this.eventHooks_ = null;
+ if (this.deferred_) {
+ this.deferred_.reject(new remoting.Error(remoting.Error.Tag.CANCELLED));
+ }
+ this.deferred_ = null;
+};
+
/**
* @param {remoting.MessageDialog.Result} result
* @return {Function}
@@ -143,9 +154,35 @@ remoting.MessageDialog.prototype.show = function() {
*/
remoting.MessageDialog.prototype.onClicked_ = function(result) {
this.deferred_.resolve(result);
- base.dispose(this.eventHooks_);
- this.eventHooks_ = null;
this.deferred_ = null;
+ this.dispose();
+};
+
+/**
+ * @param {Function} cancelCallback The callback to invoke when the user clicks
+ * on the cancel button.
+ * @constructor
+ */
+remoting.ConnectingDialog = function(cancelCallback) {
+ /** @private */
+ this.dialog_ = new remoting.MessageDialog(
+ remoting.AppMode.CLIENT_CONNECTING,
+ document.getElementById('cancel-connect-button'));
+ /** @private */
+ this.onCancel_ = cancelCallback;
+};
+
+remoting.ConnectingDialog.prototype.show = function() {
+ var that = this;
+ this.dialog_.show().then(function() {
+ remoting.setMode(remoting.AppMode.HOME);
+ that.onCancel_();
+ // The promise rejects when the dialog is hidden. Don't report that as error.
+ }).catch(remoting.Error.handler(base.doNothing));
+};
+
+remoting.ConnectingDialog.prototype.hide = function() {
+ this.dialog_.dispose();
};
})();
« no previous file with comments | « no previous file | remoting/webapp/crd/js/client_session.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698