Commit b9c8f811 authored by dbeam's avatar dbeam Committed by Commit bot

Revert of [Chromoting] Show any startup errors in the LoadingWindow. (patchset...

Revert of [Chromoting] Show any startup errors in the LoadingWindow. (patchset #5 id:80001 of https://codereview.chromium.org/1139543002/)

Reason for revert:
Syntax error in the JS, breaking the closure bot and almost surely doesn't work well/breaking something in remoting.
http://build.chromium.org/p/chromium.fyi/builders/Closure%20Compilation%20Linux/builds/22330/steps/compile/logs/stdio

Original issue's description:
> [Chromoting] Show any startup errors in the LoadingWindow.
>
> Show any connection errors during startup in the LoadingWindow rather
> than creating a new error window for the error.
>
> This cl also adds a new updateErrorMessage method to the MessageWindow
> to update the message and reset the message window as appropriate for
> an error message (disabling the spinner, updating the button label).
>
> BUG=
>
> Committed: https://crrev.com/d44e8a774ce99a89c350d10d5b3f9f644eb0c3d1
> Cr-Commit-Position: refs/heads/master@{#330022}

TBR=jamiewalch@chromium.org,garykac@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review URL: https://codereview.chromium.org/1144593002

Cr-Commit-Position: refs/heads/master@{#330052}
parent 01954fd5
...@@ -189,8 +189,8 @@ remoting.AppRemotingActivity.prototype.onDisconnected = function(error) { ...@@ -189,8 +189,8 @@ remoting.AppRemotingActivity.prototype.onDisconnected = function(error) {
* @param {!remoting.Error} error * @param {!remoting.Error} error
*/ */
remoting.AppRemotingActivity.prototype.onConnectionFailed = function(error) { remoting.AppRemotingActivity.prototype.onConnectionFailed = function(error) {
remoting.loadingWindow_.updateErrorMessage( remoting.LoadingWindow.close();
chrome.i18n.getMessage(error.getTag())); this.showErrorMessage_(error);
this.cleanup_(); this.cleanup_();
}; };
...@@ -199,7 +199,7 @@ remoting.AppRemotingActivity.prototype.onConnectionFailed = function(error) { ...@@ -199,7 +199,7 @@ remoting.AppRemotingActivity.prototype.onConnectionFailed = function(error) {
* @private * @private
*/ */
remoting.AppRemotingActivity.prototype.showErrorMessage_ = function(error) { remoting.AppRemotingActivity.prototype.showErrorMessage_ = function(error) {
console.error('Error: ' + error.toString()); console.error('Connection failed: ' + error.toString());
remoting.MessageWindow.showErrorMessage( remoting.MessageWindow.showErrorMessage(
remoting.app.getApplicationName(), remoting.app.getApplicationName(),
chrome.i18n.getMessage(error.getTag())); chrome.i18n.getMessage(error.getTag()));
......
...@@ -44,16 +44,19 @@ MessageWindowImpl.prototype.sendReply_ = function( ...@@ -44,16 +44,19 @@ MessageWindowImpl.prototype.sendReply_ = function(
}; };
/** /**
* Updates the button label text. * Initializes the button with the label and the click handler.
* Hides the button if the label is null or undefined. * Hides the button if the label is null or undefined.
* *
* @param{HTMLElement} button * @param{HTMLElement} button
* @param{?string} label * @param{?string} label
* @param{Function} clickHandler
* @private * @private
*/ */
MessageWindowImpl.prototype.updateButton_ = function(button, label) { MessageWindowImpl.prototype.initButton_ =
function(button, label, clickHandler) {
if (label) { if (label) {
button.innerText = label; button.innerText = label;
button.addEventListener('click', clickHandler, false);
} }
button.hidden = !Boolean(label); button.hidden = !Boolean(label);
}; };
...@@ -66,89 +69,86 @@ MessageWindowImpl.prototype.updateButton_ = function(button, label) { ...@@ -66,89 +69,86 @@ MessageWindowImpl.prototype.updateButton_ = function(button, label) {
* @private * @private
*/ */
MessageWindowImpl.prototype.onMessage_ = function(event) { MessageWindowImpl.prototype.onMessage_ = function(event) {
var command = /** @type {string} */ (event.data['command']); switch (event.data['command']) {
if (command !== 'show' && command !== 'update') { case 'show':
console.error('Unexpected message: ' + command); // Validate the message.
return; var messageId = /** @type {number} */ (event.data['id']);
} var title = /** @type {string} */ (event.data['title']);
var message = /** @type {string} */ (event.data['message']);
// Validate the message. var infobox = /** @type {string} */ (event.data['infobox']);
var messageId = /** @type {number} */ (event.data['id']); var buttonLabel = /** @type {string} */ (event.data['buttonLabel']);
var title = /** @type {string} */ (event.data['title']); /** @type {string} */
var message = /** @type {string} */ (event.data['message']); var cancelButtonLabel = (event.data['cancelButtonLabel']);
var infobox = /** @type {string} */ (event.data['infobox']); var showSpinner = /** @type {boolean} */ (event.data['showSpinner']);
var buttonLabel = /** @type {string} */ (event.data['buttonLabel']); if (typeof(messageId) != 'number' ||
var cancelButtonLabel = /** @type {string} */ typeof(title) != 'string' ||
(event.data['cancelButtonLabel']); typeof(message) != 'string' ||
var showSpinner = /** @type {boolean} */ (event.data['showSpinner']); typeof(infobox) != 'string' ||
typeof(buttonLabel) != 'string' ||
// Many of these fields are optional for either the 'show' or 'update' typeof(showSpinner) != 'boolean') {
// message. These vars are used to mark the optional fields to allow console.log('Bad show message:', event.data);
// them to be undefined. break;
var optionalFieldShow = command === 'show'; }
var optionalFieldUpdate = command === 'update';
if (isNumber(messageId) || // Set the dialog text.
isString(title, optionalFieldUpdate) || var button = document.getElementById('button-primary');
isString(message, optionalFieldUpdate) || var cancelButton = document.getElementById('button-secondary');
isString(infobox, optionalFieldUpdate) || var messageDiv = document.getElementById('message');
isString(buttonLabel, optionalFieldUpdate) || var infoboxDiv = document.getElementById('infobox');
isString(cancelButtonLabel, optionalFieldShow || optionalFieldUpdate) ||
isBoolean(showSpinner, optionalFieldUpdate) { document.getElementById('title').innerText = title;
console.log('Bad ' + command + ' message: ' + event.data); document.querySelector('title').innerText = title;
return; messageDiv.innerHTML = message;
}
if (showSpinner) {
var button = document.getElementById('button-primary'); messageDiv.classList.add('waiting');
var cancelButton = document.getElementById('button-secondary'); messageDiv.classList.add('prominent');
var messageDiv = document.getElementById('message'); }
var infoboxDiv = document.getElementById('infobox'); if (infobox != '') {
infoboxDiv.innerText = infobox;
if (isString(title)) { } else {
document.getElementById('title').innerText = title; infoboxDiv.hidden = true;
document.querySelector('title').innerText = title; }
}
if (isString(message) { this.initButton_(
messageDiv.innerText = message; button,
} buttonLabel,
if (isString(infobox)) { this.sendReply_.bind(this, event.source, messageId, 1));
if (infobox != '') {
infoboxDiv.innerText = infobox; this.initButton_(
} else { cancelButton,
infoboxDiv.hidden = true; cancelButtonLabel,
} this.sendReply_.bind(this, event.source, messageId, 0));
}
if (isBoolean(showSpinner)) { var buttonToFocus = (cancelButtonLabel) ? cancelButton : button;
if (showSpinner) { buttonToFocus.focus();
messageDiv.classList.add('waiting');
messageDiv.classList.add('prominent'); // Add a close handler in case the window is closed without clicking one
} else { // of the buttons. This will send a 0 as the result.
messageDiv.classList.remove('waiting'); // Note that when a button is pressed, this will result in sendReply_
messageDiv.classList.remove('prominent'); // being called multiple times (once for the button, once for close).
} chrome.app.window.current().onClosed.addListener(
} this.sendReply_.bind(this, event.source, messageId, 0));
this.updateButton_(button, buttonLabel);
this.updateButton_(cancelButton, cancelButtonLabel); base.resizeWindowToContent(true);
chrome.app.window.current().show();
base.resizeWindowToContent(true); break;
if (command === 'show') { case 'update_message':
// Set up click-handlers for the buttons. var message = /** @type {string} */ (event.data['message']);
button.addEventListener( if (typeof(message) != 'string') {
'click', this.sendReply_.bind(this, event.source, messageId, 1), false); console.log('Bad update_message message:', event.data);
cancelButton.addEventListener( break;
'click', this.sendReply_.bind(this, event.source, messageId, 0), false); }
var buttonToFocus = (cancelButtonLabel) ? cancelButton : button; var messageDiv = document.getElementById('message');
buttonToFocus.focus(); messageDiv.innerText = message;
// Add a close handler in case the window is closed without clicking one base.resizeWindowToContent(true);
// of the buttons. This will send a 0 as the result. break;
// Note that when a button is pressed, this will result in sendReply_
// being called multiple times (once for the button, once for close). default:
chrome.app.window.current().onClosed.addListener( console.error('Unexpected message:', event.data);
this.sendReply_.bind(this, event.source, messageId, 0));
chrome.app.window.current().show();
} }
}; };
......
...@@ -41,9 +41,6 @@ remoting.MessageWindowOptions = function() { ...@@ -41,9 +41,6 @@ remoting.MessageWindowOptions = function() {
/** @type {number} */ /** @type {number} */
this.minimumWidth = 0; this.minimumWidth = 0;
/** @type {boolean} */
this.showSpinner = false;
}; };
/** /**
...@@ -154,36 +151,12 @@ remoting.MessageWindow.prototype.updateMessage = function(message) { ...@@ -154,36 +151,12 @@ remoting.MessageWindow.prototype.updateMessage = function(message) {
} }
var message_struct = { var message_struct = {
command: 'update', command: 'update_message',
message: message message: message
}; };
this.window_.postMessage(message_struct, '*'); this.window_.postMessage(message_struct, '*');
}; };
/**
* Update the message being shown in the window to the given error message.
* In addition to updating the message, any spinner is disabled and the
* button text is changed to 'OK'.
* This should only be called after the window has been shown.
*
* @param {string} message The message.
*/
remoting.MessageWindow.prototype.updateErrorMessage = function(message) {
if (!this.window_) {
this.pendingWindowOperations_.push(this.updateMessage.bind(this, message));
return;
}
var message_struct = {
command: 'update',
message: message,
buttonLabel: chrome.i18n.getMessage(/*i18n-content*/'OK'),
cancelButtonLabel: '',
showSpinner: false
};
this.window_.postMessage(message_struct, '*');
};
/** /**
* Close the message box and unregister it with the window manager. * Close the message box and unregister it with the window manager.
*/ */
......
...@@ -19,25 +19,17 @@ var isArray = function(value) { ...@@ -19,25 +19,17 @@ var isArray = function(value) {
/** /**
* @param {*} value * @param {*} value
* @param {boolean=} opt_allowUndefined True to accept undefined.
* @return {boolean} * @return {boolean}
*/ */
var isBoolean = function(value, opt_allowUndefined) { var isBoolean = function(value) {
if (opt_allowUndefined && value === 'undefined') {
return true;
}
return typeof value == 'boolean'; return typeof value == 'boolean';
}; };
/** /**
* @param {*} value * @param {*} value
* @param {boolean=} opt_allowUndefined True to accept undefined.
* @return {boolean} * @return {boolean}
*/ */
var isNumber = function(value, opt_allowUndefined) { var isNumber = function(value) {
if (opt_allowUndefined && value === 'undefined') {
return true;
}
return typeof value == 'number'; return typeof value == 'number';
}; };
...@@ -51,13 +43,9 @@ var isObject = function(value) { ...@@ -51,13 +43,9 @@ var isObject = function(value) {
/** /**
* @param {*} value * @param {*} value
* @param {boolean=} opt_allowUndefined True to accept undefined.
* @return {boolean} * @return {boolean}
*/ */
var isString = function(value, opt_allowUndefined) { var isString = function(value) {
if (opt_allowUndefined && value === 'undefined') {
return true;
}
return typeof value == 'string'; return typeof value == 'string';
}; };
...@@ -258,4 +246,4 @@ base.getJsonObjectFromString = function(jsonString) { ...@@ -258,4 +246,4 @@ base.getJsonObjectFromString = function(jsonString) {
return base.assertObject(base.jsonParseSafe(jsonString)); return base.assertObject(base.jsonParseSafe(jsonString));
}; };
})(); })();
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment