OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * @constructor | 8 * @constructor |
9 */ | 9 */ |
10 function MessageWindowImpl() { | 10 function MessageWindowImpl() { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 if (showSpinner) { | 118 if (showSpinner) { |
119 messageDiv.classList.add('waiting'); | 119 messageDiv.classList.add('waiting'); |
120 messageDiv.classList.add('prominent'); | 120 messageDiv.classList.add('prominent'); |
121 } | 121 } |
122 if (infobox != '') { | 122 if (infobox != '') { |
123 infoboxDiv.innerText = infobox; | 123 infoboxDiv.innerText = infobox; |
124 } else { | 124 } else { |
125 infoboxDiv.hidden = true; | 125 infoboxDiv.hidden = true; |
126 } | 126 } |
127 | 127 |
| 128 var messageIdStr = messageId.toString(); |
| 129 |
128 this.initButton_( | 130 this.initButton_( |
129 button, | 131 button, |
130 buttonLabel, | 132 buttonLabel, |
131 this.sendReply_.bind(this, event.source, messageId, 1)); | 133 this.sendReply_.bind(this, event.source, messageIdStr, 1)); |
132 | 134 |
133 this.initButton_( | 135 this.initButton_( |
134 cancelButton, | 136 cancelButton, |
135 cancelButtonLabel, | 137 cancelButtonLabel, |
136 this.sendReply_.bind(this, event.source, messageId, 0)); | 138 this.sendReply_.bind(this, event.source, messageIdStr, 0)); |
137 | 139 |
138 var buttonToFocus = (cancelButtonLabel) ? cancelButton : button; | 140 var buttonToFocus = (cancelButtonLabel) ? cancelButton : button; |
139 buttonToFocus.focus(); | 141 buttonToFocus.focus(); |
140 | 142 |
141 // Add a close handler in case the window is closed without clicking one | 143 // Add a close handler in case the window is closed without clicking one |
142 // of the buttons. This will send a 0 as the result. | 144 // of the buttons. This will send a 0 as the result. |
143 // Note that when a button is pressed, this will result in sendReply_ | 145 // Note that when a button is pressed, this will result in sendReply_ |
144 // being called multiple times (once for the button, once for close). | 146 // being called multiple times (once for the button, once for close). |
145 chrome.app.window.current().onClosed.addListener( | 147 chrome.app.window.current().onClosed.addListener( |
146 this.sendReply_.bind(this, event.source, messageId, 0)); | 148 this.sendReply_.bind(this, event.source, messageIdStr, 0)); |
147 | 149 |
148 this.updateSize_(); | 150 this.updateSize_(); |
149 chrome.app.window.current().show(); | 151 chrome.app.window.current().show(); |
150 break; | 152 break; |
151 | 153 |
152 case 'update_message': | 154 case 'update_message': |
153 var message = /** @type {string} */ (event.data['message']); | 155 var message = /** @type {string} */ (event.data['message']); |
154 if (typeof(message) != 'string') { | 156 if (typeof(message) != 'string') { |
155 console.log('Bad update_message message:', event.data); | 157 console.log('Bad update_message message:', event.data); |
156 break; | 158 break; |
157 } | 159 } |
158 | 160 |
159 var messageDiv = document.getElementById('message'); | 161 var messageDiv = document.getElementById('message'); |
160 messageDiv.innerText = message; | 162 messageDiv.innerText = message; |
161 | 163 |
162 this.updateSize_(); | 164 this.updateSize_(); |
163 break; | 165 break; |
164 | 166 |
165 default: | 167 default: |
166 console.error('Unexpected message:', event.data); | 168 console.error('Unexpected message:', event.data); |
167 } | 169 } |
168 }; | 170 }; |
169 | 171 |
170 var messageWindow = new MessageWindowImpl(); | 172 var messageWindow = new MessageWindowImpl(); |
OLD | NEW |