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

Unified Diff: remoting/webapp/base/js/message_window.js

Issue 1144593002: Revert of [Chromoting] Show any startup errors in the LoadingWindow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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/message_window.js
diff --git a/remoting/webapp/base/js/message_window.js b/remoting/webapp/base/js/message_window.js
index c25f6e367d89d5f13bfe91760465d8d0ef47ff5b..f2c36347eb9ffb6128916a5189d4fe056d515ab2 100644
--- a/remoting/webapp/base/js/message_window.js
+++ b/remoting/webapp/base/js/message_window.js
@@ -44,16 +44,19 @@
};
/**
- * 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.
*
* @param{HTMLElement} button
* @param{?string} label
+ * @param{Function} clickHandler
* @private
*/
-MessageWindowImpl.prototype.updateButton_ = function(button, label) {
+MessageWindowImpl.prototype.initButton_ =
+ function(button, label, clickHandler) {
if (label) {
button.innerText = label;
+ button.addEventListener('click', clickHandler, false);
}
button.hidden = !Boolean(label);
};
@@ -66,89 +69,86 @@
* @private
*/
MessageWindowImpl.prototype.onMessage_ = function(event) {
- var command = /** @type {string} */ (event.data['command']);
- if (command !== 'show' && command !== 'update') {
- console.error('Unexpected message: ' + command);
- return;
- }
+ switch (event.data['command']) {
+ case 'show':
+ // Validate the message.
+ var messageId = /** @type {number} */ (event.data['id']);
+ var title = /** @type {string} */ (event.data['title']);
+ var message = /** @type {string} */ (event.data['message']);
+ var infobox = /** @type {string} */ (event.data['infobox']);
+ var buttonLabel = /** @type {string} */ (event.data['buttonLabel']);
+ /** @type {string} */
+ var cancelButtonLabel = (event.data['cancelButtonLabel']);
+ var showSpinner = /** @type {boolean} */ (event.data['showSpinner']);
+ if (typeof(messageId) != 'number' ||
+ typeof(title) != 'string' ||
+ typeof(message) != 'string' ||
+ typeof(infobox) != 'string' ||
+ typeof(buttonLabel) != 'string' ||
+ typeof(showSpinner) != 'boolean') {
+ console.log('Bad show message:', event.data);
+ break;
+ }
- // Validate the message.
- var messageId = /** @type {number} */ (event.data['id']);
- var title = /** @type {string} */ (event.data['title']);
- var message = /** @type {string} */ (event.data['message']);
- var infobox = /** @type {string} */ (event.data['infobox']);
- var buttonLabel = /** @type {string} */ (event.data['buttonLabel']);
- var cancelButtonLabel = /** @type {string} */
- (event.data['cancelButtonLabel']);
- var showSpinner = /** @type {boolean} */ (event.data['showSpinner']);
+ // Set the dialog text.
+ var button = document.getElementById('button-primary');
+ var cancelButton = document.getElementById('button-secondary');
+ var messageDiv = document.getElementById('message');
+ var infoboxDiv = document.getElementById('infobox');
- // Many of these fields are optional for either the 'show' or 'update'
- // message. These vars are used to mark the optional fields to allow
- // them to be undefined.
- var optionalFieldShow = command === 'show';
- var optionalFieldUpdate = command === 'update';
- if (isNumber(messageId) ||
- isString(title, optionalFieldUpdate) ||
- isString(message, optionalFieldUpdate) ||
- isString(infobox, optionalFieldUpdate) ||
- isString(buttonLabel, optionalFieldUpdate) ||
- isString(cancelButtonLabel, optionalFieldShow || optionalFieldUpdate) ||
- isBoolean(showSpinner, optionalFieldUpdate) {
- console.log('Bad ' + command + ' message: ' + event.data);
- return;
- }
+ document.getElementById('title').innerText = title;
+ document.querySelector('title').innerText = title;
+ messageDiv.innerHTML = message;
- var button = document.getElementById('button-primary');
- var cancelButton = document.getElementById('button-secondary');
- var messageDiv = document.getElementById('message');
- var infoboxDiv = document.getElementById('infobox');
+ if (showSpinner) {
+ messageDiv.classList.add('waiting');
+ messageDiv.classList.add('prominent');
+ }
+ if (infobox != '') {
+ infoboxDiv.innerText = infobox;
+ } else {
+ infoboxDiv.hidden = true;
+ }
- if (isString(title)) {
- document.getElementById('title').innerText = title;
- document.querySelector('title').innerText = title;
- }
- if (isString(message) {
- messageDiv.innerText = message;
- }
- if (isString(infobox)) {
- if (infobox != '') {
- infoboxDiv.innerText = infobox;
- } else {
- infoboxDiv.hidden = true;
- }
- }
- if (isBoolean(showSpinner)) {
- if (showSpinner) {
- messageDiv.classList.add('waiting');
- messageDiv.classList.add('prominent');
- } else {
- messageDiv.classList.remove('waiting');
- messageDiv.classList.remove('prominent');
- }
- }
- this.updateButton_(button, buttonLabel);
- this.updateButton_(cancelButton, cancelButtonLabel);
+ this.initButton_(
+ button,
+ buttonLabel,
+ this.sendReply_.bind(this, event.source, messageId, 1));
- base.resizeWindowToContent(true);
+ this.initButton_(
+ cancelButton,
+ cancelButtonLabel,
+ this.sendReply_.bind(this, event.source, messageId, 0));
- if (command === 'show') {
- // Set up click-handlers for the buttons.
- button.addEventListener(
- 'click', this.sendReply_.bind(this, event.source, messageId, 1), false);
- cancelButton.addEventListener(
- 'click', this.sendReply_.bind(this, event.source, messageId, 0), false);
+ var buttonToFocus = (cancelButtonLabel) ? cancelButton : button;
+ buttonToFocus.focus();
- var buttonToFocus = (cancelButtonLabel) ? cancelButton : button;
- buttonToFocus.focus();
+ // Add a close handler in case the window is closed without clicking one
+ // of the buttons. This will send a 0 as the result.
+ // Note that when a button is pressed, this will result in sendReply_
+ // 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));
- // Add a close handler in case the window is closed without clicking one
- // of the buttons. This will send a 0 as the result.
- // Note that when a button is pressed, this will result in sendReply_
- // 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));
+ base.resizeWindowToContent(true);
+ chrome.app.window.current().show();
+ break;
- chrome.app.window.current().show();
+ case 'update_message':
+ var message = /** @type {string} */ (event.data['message']);
+ if (typeof(message) != 'string') {
+ console.log('Bad update_message message:', event.data);
+ break;
+ }
+
+ var messageDiv = document.getElementById('message');
+ messageDiv.innerText = message;
+
+ base.resizeWindowToContent(true);
+ break;
+
+ default:
+ console.error('Unexpected message:', event.data);
}
};
« no previous file with comments | « remoting/webapp/app_remoting/js/app_remoting_activity.js ('k') | remoting/webapp/base/js/message_window_helper.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698