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 10 matching lines...) Expand all Loading... | |
| 90 }; | 90 }; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * A helper class for implementing MessageDialog with a primary and | 94 * A helper class for implementing MessageDialog with a primary and |
| 95 * and secondary button using remoting.setMode(). | 95 * and secondary button using remoting.setMode(). |
| 96 * | 96 * |
| 97 * @param {remoting.AppMode} mode | 97 * @param {remoting.AppMode} mode |
| 98 * @param {HTMLElement} primaryButton | 98 * @param {HTMLElement} primaryButton |
| 99 * @param {HTMLElement=} opt_secondaryButton | 99 * @param {HTMLElement=} opt_secondaryButton |
| 100 * | |
| 100 * @constructor | 101 * @constructor |
| 102 * @implements {base.Disposable} | |
| 101 */ | 103 */ |
| 102 remoting.MessageDialog = function(mode, primaryButton, opt_secondaryButton) { | 104 remoting.MessageDialog = function(mode, primaryButton, opt_secondaryButton) { |
| 103 /** @private @const */ | 105 /** @private @const */ |
| 104 this.mode_ = mode; | 106 this.mode_ = mode; |
| 105 /** @private @const */ | 107 /** @private @const */ |
| 106 this.primaryButton_ = primaryButton; | 108 this.primaryButton_ = primaryButton; |
| 107 /** @private @const */ | 109 /** @private @const */ |
| 108 this.secondaryButton_ = opt_secondaryButton; | 110 this.secondaryButton_ = opt_secondaryButton; |
| 109 /** @private {base.Deferred} */ | 111 /** @private {base.Deferred} */ |
| 110 this.deferred_ = null; | 112 this.deferred_ = null; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 129 this.onClicked_.bind(this, remoting.MessageDialog.Result.SECONDARY), | 131 this.onClicked_.bind(this, remoting.MessageDialog.Result.SECONDARY), |
| 130 false)); | 132 false)); |
| 131 } | 133 } |
| 132 | 134 |
| 133 base.debug.assert(this.deferred_ === null); | 135 base.debug.assert(this.deferred_ === null); |
| 134 this.deferred_ = new base.Deferred(); | 136 this.deferred_ = new base.Deferred(); |
| 135 remoting.setMode(this.mode_); | 137 remoting.setMode(this.mode_); |
| 136 return this.deferred_.promise(); | 138 return this.deferred_.promise(); |
| 137 }; | 139 }; |
| 138 | 140 |
| 141 remoting.MessageDialog.prototype.dispose = function() { | |
| 142 base.dispose(this.eventHooks_); | |
| 143 this.eventHooks_ = null; | |
| 144 if (this.deferred_) { | |
| 145 this.deferred_.reject(new remoting.Error(remoting.Error.Tag.CANCELLED)); | |
| 146 this.deferred_ = null; | |
| 147 } | |
| 148 }; | |
| 149 | |
| 139 /** | 150 /** |
| 140 * @param {remoting.MessageDialog.Result} result | 151 * @param {remoting.MessageDialog.Result} result |
| 141 * @return {Function} | 152 * @return {Function} |
| 142 * @private | 153 * @private |
| 143 */ | 154 */ |
| 144 remoting.MessageDialog.prototype.onClicked_ = function(result) { | 155 remoting.MessageDialog.prototype.onClicked_ = function(result) { |
| 145 this.deferred_.resolve(result); | 156 this.deferred_.resolve(result); |
| 146 base.dispose(this.eventHooks_); | |
| 147 this.eventHooks_ = null; | |
| 148 this.deferred_ = null; | 157 this.deferred_ = null; |
|
Jamie
2015/04/24 17:59:18
Optional: Rejecting a Promise that has already res
kelvinp
2015/04/24 19:03:52
Done.
Jamie
2015/04/24 20:19:32
I don't think your new change will work; deferred
| |
| 158 this.dispose(); | |
| 159 }; | |
| 160 | |
| 161 /** | |
| 162 * @param {Function} cancelCallback The callback to invoke when the user clicks | |
| 163 * on the cancel button. | |
| 164 * @constructor | |
| 165 */ | |
| 166 remoting.ConnectingDialog = function(cancelCallback) { | |
| 167 /** @private */ | |
| 168 this.dialog_ = new remoting.MessageDialog( | |
| 169 remoting.AppMode.CLIENT_CONNECTING, | |
| 170 document.getElementById('cancel-connect-button')); | |
| 171 /** @private */ | |
| 172 this.onCancel_ = cancelCallback; | |
| 173 }; | |
| 174 | |
| 175 remoting.ConnectingDialog.prototype.show = function() { | |
| 176 var that = this; | |
| 177 this.dialog_.show().then(function() { | |
| 178 remoting.setMode(remoting.AppMode.HOME); | |
| 179 that.onCancel_(); | |
| 180 }).catch(remoting.Error.handler(base.doNothing)); | |
|
Jamie
2015/04/24 17:59:18
Why is this catch handler needed?
kelvinp
2015/04/24 19:03:52
The promise rejects when we hide the connection di
| |
| 181 }; | |
| 182 | |
| 183 remoting.ConnectingDialog.prototype.hide = function() { | |
| 184 this.dialog_.dispose(); | |
| 149 }; | 185 }; |
| 150 | 186 |
| 151 })(); | 187 })(); |
| 152 | 188 |
| 153 /** | 189 /** |
| 154 * Define the enum at the end of file as JSCompile doesn't understand enums that | 190 * 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). | 191 * are defined within an IIFE (Immediately Invoked Function Expression). |
| 156 * @enum {number} | 192 * @enum {number} |
| 157 */ | 193 */ |
| 158 remoting.MessageDialog.Result = { | 194 remoting.MessageDialog.Result = { |
| 159 PRIMARY: 0, | 195 PRIMARY: 0, |
| 160 SECONDARY: 1 | 196 SECONDARY: 1 |
| 161 }; | 197 }; |
| OLD | NEW |