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
3 // found in the LICENSE file.
5 /** @suppress {duplicate} */
6 var remoting
= remoting
|| {};
13 * A Dialog that is shown to the user when the connection is dropped.
16 * @param {HTMLElement} rootElement
17 * @param {remoting.WindowShape=} opt_windowShape
18 * @implements {base.Disposable}
20 remoting
.ConnectionDroppedDialog = function(rootElement
, opt_windowShape
) {
22 this.dialog_
= new remoting
.Html5ModalDialog({
23 dialog
: /** @type {HTMLDialogElement} */ (rootElement
),
24 primaryButton
: rootElement
.querySelector('.restart-button'),
25 secondaryButton
: rootElement
.querySelector('.close-button'),
27 windowShape
: opt_windowShape
31 this.disposables_
= new base
.Disposables(this.dialog_
);
34 remoting
.ConnectionDroppedDialog
.prototype.dispose = function() {
35 base
.dispose(this.disposables_
);
36 this.disposables_
= null;
40 * @return {Promise} Promise that resolves if
41 * the user chooses to reconnect, or rejects if the user chooses to cancel.
42 * This class doesn't re-establish the connection. The caller must
43 * implement the reconnect logic.
45 remoting
.ConnectionDroppedDialog
.prototype.show = function() {
46 var promise
= this.dialog_
.show();
47 this.waitForOnline_().then(
48 this.dialog_
.close
.bind(this.dialog_
, remoting
.MessageDialog
.Result
.PRIMARY
)
50 return promise
.then(function(/** remoting.MessageDialog.Result */ result
) {
51 if (result
=== remoting
.MessageDialog
.Result
.PRIMARY
) {
52 return Promise
.resolve();
54 return Promise
.reject(new remoting
.Error(remoting
.Error
.Tag
.CANCELLED
));
63 remoting
.ConnectionDroppedDialog
.prototype.waitForOnline_ = function() {
64 if (base
.isOnline()) {
65 return Promise
.resolve();
68 var deferred
= new base
.Deferred();
69 this.disposables_
.add(new base
.DomEventHook(
70 window
, 'online', deferred
.resolve
.bind(deferred
), false));
71 return deferred
.promise();