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

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: 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
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..19af3cf549472e76b51f5e81efd55614de9103fe 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
@@ -136,6 +136,12 @@ remoting.MessageDialog.prototype.show = function() {
return this.deferred_.promise();
};
+remoting.MessageDialog.prototype.reset = function() {
Jamie 2015/04/22 23:11:55 Why not call this dispose() and use the base.Dispo
kelvinp 2015/04/23 01:17:23 Done.
+ base.dispose(this.eventHooks_);
+ this.eventHooks_ = null;
+ this.deferred_ = null;
Jamie 2015/04/22 23:11:55 If this remains public, you should call deferred_.
kelvinp 2015/04/23 01:17:23 Done.
+};
+
/**
* @param {remoting.MessageDialog.Result} result
* @return {Function}
@@ -143,9 +149,33 @@ 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.reset();
+};
+
+/**
+ * @param {Function} cancelCallback The callback to invoke when the user clicks
+ * on the cancel button.
Jamie 2015/04/22 23:11:55 Why not make show return a Promise?
kelvinp 2015/04/23 01:17:23 The cancel dialog has a different use case than ot
Jamie 2015/04/24 17:59:18 I don't understand. A Promise is guaranteed one-sh
kelvinp 2015/04/24 19:03:52 While a promise only resolves once, every time whe
+ * @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_();
+ });
+};
+
+remoting.ConnectingDialog.prototype.hide = function() {
+ this.dialog_.reset();
};
})();

Powered by Google App Engine
This is Rietveld 408576698