Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 /** @suppress {duplicate} */ | 5 /** @suppress {duplicate} */ |
| 6 var remoting = remoting || {}; | 6 var remoting = remoting || {}; |
| 7 | 7 |
| 8 (function() { | 8 (function() { |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 new base.DomEventHook(this.cancelButton_, 'click', onCancel, false)); | 49 new base.DomEventHook(this.cancelButton_, 'click', onCancel, false)); |
| 50 base.debug.assert(this.deferred_ === null); | 50 base.debug.assert(this.deferred_ === null); |
| 51 this.deferred_ = new base.Deferred(); | 51 this.deferred_ = new base.Deferred(); |
| 52 remoting.setMode(this.appMode_); | 52 remoting.setMode(this.appMode_); |
| 53 return this.deferred_.promise(); | 53 return this.deferred_.promise(); |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 /** @return {HTMLElement} */ | 56 /** @return {HTMLElement} */ |
| 57 remoting.InputDialog.prototype.inputField = function() { | 57 remoting.InputDialog.prototype.inputField = function() { |
| 58 return this.inputField_; | 58 return this.inputField_; |
| 59 } | 59 }; |
| 60 | 60 |
| 61 /** @private */ | 61 /** @private */ |
| 62 remoting.InputDialog.prototype.onSubmit_ = function() { | 62 remoting.InputDialog.prototype.onSubmit_ = function() { |
| 63 this.deferred_.resolve(this.inputField_.value); | 63 this.deferred_.resolve(this.inputField_.value); |
| 64 } | 64 }; |
| 65 | 65 |
| 66 /** @private */ | 66 /** @private */ |
| 67 remoting.InputDialog.prototype.onCancel_ = function() { | 67 remoting.InputDialog.prototype.onCancel_ = function() { |
| 68 this.deferred_.reject(new remoting.Error(remoting.Error.Tag.CANCELLED)); | 68 this.deferred_.reject(new remoting.Error(remoting.Error.Tag.CANCELLED)); |
| 69 } | 69 }; |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * @param {function():void} handler | 72 * @param {function():void} handler |
| 73 * @return {Function} | 73 * @return {Function} |
| 74 * @private | 74 * @private |
| 75 */ | 75 */ |
| 76 remoting.InputDialog.prototype.createFormEventHandler_ = function(handler) { | 76 remoting.InputDialog.prototype.createFormEventHandler_ = function(handler) { |
| 77 var that = this; | 77 var that = this; |
| 78 return function (/** Event */ e) { | 78 return function (/** Event */ e) { |
| 79 // Prevents form submission from reloading the v1 app. | 79 // Prevents form submission from reloading the v1 app. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 this.onClicked_.bind(this, remoting.MessageDialog.Result.SECONDARY), | 129 this.onClicked_.bind(this, remoting.MessageDialog.Result.SECONDARY), |
| 130 false)); | 130 false)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 base.debug.assert(this.deferred_ === null); | 133 base.debug.assert(this.deferred_ === null); |
| 134 this.deferred_ = new base.Deferred(); | 134 this.deferred_ = new base.Deferred(); |
| 135 remoting.setMode(this.mode_); | 135 remoting.setMode(this.mode_); |
| 136 return this.deferred_.promise(); | 136 return this.deferred_.promise(); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 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.
| |
| 140 base.dispose(this.eventHooks_); | |
| 141 this.eventHooks_ = null; | |
| 142 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.
| |
| 143 }; | |
| 144 | |
| 139 /** | 145 /** |
| 140 * @param {remoting.MessageDialog.Result} result | 146 * @param {remoting.MessageDialog.Result} result |
| 141 * @return {Function} | 147 * @return {Function} |
| 142 * @private | 148 * @private |
| 143 */ | 149 */ |
| 144 remoting.MessageDialog.prototype.onClicked_ = function(result) { | 150 remoting.MessageDialog.prototype.onClicked_ = function(result) { |
| 145 this.deferred_.resolve(result); | 151 this.deferred_.resolve(result); |
| 146 base.dispose(this.eventHooks_); | 152 this.reset(); |
| 147 this.eventHooks_ = null; | 153 }; |
| 148 this.deferred_ = null; | 154 |
| 155 /** | |
| 156 * @param {Function} cancelCallback The callback to invoke when the user clicks | |
| 157 * 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
| |
| 158 * @constructor | |
| 159 */ | |
| 160 remoting.ConnectingDialog = function(cancelCallback) { | |
| 161 /** @private */ | |
| 162 this.dialog_ = new remoting.MessageDialog( | |
| 163 remoting.AppMode.CLIENT_CONNECTING, | |
| 164 document.getElementById('cancel-connect-button')); | |
| 165 /** @private */ | |
| 166 this.onCancel_ = cancelCallback; | |
| 167 }; | |
| 168 | |
| 169 remoting.ConnectingDialog.prototype.show = function() { | |
| 170 var that = this; | |
| 171 this.dialog_.show().then(function() { | |
| 172 remoting.setMode(remoting.AppMode.HOME); | |
| 173 that.onCancel_(); | |
| 174 }); | |
| 175 }; | |
| 176 | |
| 177 remoting.ConnectingDialog.prototype.hide = function() { | |
| 178 this.dialog_.reset(); | |
| 149 }; | 179 }; |
| 150 | 180 |
| 151 })(); | 181 })(); |
| 152 | 182 |
| 153 /** | 183 /** |
| 154 * Define the enum at the end of file as JSCompile doesn't understand enums that | 184 * Define the enum at the end of file as JSCompile doesn't understand enums that |
| 155 * are defined within an IIFE (Immediately Invoked Function Expression). | 185 * are defined within an IIFE (Immediately Invoked Function Expression). |
| 156 * @enum {number} | 186 * @enum {number} |
| 157 */ | 187 */ |
| 158 remoting.MessageDialog.Result = { | 188 remoting.MessageDialog.Result = { |
| 159 PRIMARY: 0, | 189 PRIMARY: 0, |
| 160 SECONDARY: 1 | 190 SECONDARY: 1 |
| 161 }; | 191 }; |
| OLD | NEW |