Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 var localStrings; | 5 var localStrings; |
| 6 var browserBridge; | 6 var browserBridge; |
| 7 | 7 |
| 8 // Class that keeps track of current burn process state. | 8 /** |
| 9 * Class that keeps track of current burn process state. | |
| 10 * @param {Object} strings Localized state strings. | |
| 11 * @constructor | |
| 12 */ | |
| 9 function State(strings) { | 13 function State(strings) { |
| 10 this.setStrings(strings); | 14 this.setStrings(strings); |
| 11 this.changeState(State.StatesEnum.DEVICE_NONE); | 15 this.changeState(State.StatesEnum.DEVICE_NONE); |
| 12 } | 16 } |
| 13 | 17 |
| 18 /** | |
| 19 * State Enum object. | |
| 20 */ | |
| 14 State.StatesEnum = { | 21 State.StatesEnum = { |
| 15 DEVICE_NONE : { | 22 DEVICE_NONE: { |
| 16 cssState : "device-detected-none", | 23 cssState: 'device-detected-none', |
| 17 }, | 24 }, |
| 18 DEVICE_USB : { | 25 DEVICE_USB: { |
| 19 cssState : "device-detected-usb warning", | 26 cssState: 'device-detected-usb warning', |
| 20 }, | 27 }, |
| 21 DEVICE_SD : { | 28 DEVICE_SD: { |
| 22 cssState : "device-detected-sd warning", | 29 cssState: 'device-detected-sd warning', |
| 23 }, | 30 }, |
| 24 DEVICE_MUL : { | 31 DEVICE_MUL: { |
| 25 cssState: "device-detected-mul warning", | 32 cssState: 'device-detected-mul warning', |
| 26 }, | 33 }, |
| 27 ERROR_NO_NETWORK : { | 34 ERROR_NO_NETWORK: { |
| 28 cssState : "warning-no-conf", | 35 cssState: 'warning-no-conf', |
| 29 }, | 36 }, |
| 30 ERROR_DEVICE_TOO_SMALL : { | 37 ERROR_DEVICE_TOO_SMALL: { |
| 31 cssState : "warning-no-conf", | 38 cssState: 'warning-no-conf', |
| 32 }, | 39 }, |
| 33 PROGRESS_DOWNLOAD : { | 40 PROGRESS_DOWNLOAD: { |
| 34 cssState : "progress progress-canceble", | 41 cssState: 'progress progress-canceble', |
| 35 }, | 42 }, |
| 36 PROGRESS_UNZIP : { | 43 PROGRESS_UNZIP: { |
| 37 cssState : "progress progress-canceble", | 44 cssState: 'progress progress-canceble', |
| 38 }, | 45 }, |
| 39 PROGRESS_BURN : { | 46 PROGRESS_BURN: { |
| 40 cssState : "progress", | 47 cssState: 'progress', |
| 41 }, | 48 }, |
| 42 FAIL : { | 49 FAIL: { |
| 43 cssState : "error", | 50 cssState: 'error', |
| 44 }, | 51 }, |
| 45 SUCCESS : { | 52 SUCCESS: { |
| 46 cssState : "success", | 53 cssState: 'success', |
| 47 }, | 54 }, |
| 48 }; | 55 }; |
| 49 | 56 |
| 50 State.prototype = { | 57 State.prototype = { |
| 58 /** | |
| 59 * Sets the state strings. | |
| 60 * @param {Object} strings Localized state strings. | |
| 61 */ | |
| 51 setStrings: function(strings) { | 62 setStrings: function(strings) { |
| 52 State.StatesEnum.DEVICE_NONE.statusText = | 63 State.StatesEnum.DEVICE_NONE.statusText = |
| 53 strings.getString('statusDevicesNone'); | 64 strings.getString('statusDevicesNone'); |
| 54 State.StatesEnum.DEVICE_NONE.warningText = | 65 State.StatesEnum.DEVICE_NONE.warningText = |
| 55 strings.getString('warningDevicesNone'); | 66 strings.getString('warningDevicesNone'); |
| 56 State.StatesEnum.DEVICE_USB.statusText = | 67 State.StatesEnum.DEVICE_USB.statusText = |
| 57 strings.getString('statusDeviceUSB'); | 68 strings.getString('statusDeviceUSB'); |
| 58 State.StatesEnum.DEVICE_SD.statusText = strings.getString('statusDeviceSD'); | 69 State.StatesEnum.DEVICE_SD.statusText = strings.getString('statusDeviceSD'); |
| 59 State.StatesEnum.DEVICE_MUL.statusText = | 70 State.StatesEnum.DEVICE_MUL.statusText = |
| 60 strings.getString('statusDevicesMultiple'); | 71 strings.getString('statusDevicesMultiple'); |
| 61 State.StatesEnum.ERROR_NO_NETWORK.statusText = | 72 State.StatesEnum.ERROR_NO_NETWORK.statusText = |
| 62 strings.getString('statusNoConnection'); | 73 strings.getString('statusNoConnection'); |
| 63 State.StatesEnum.ERROR_NO_NETWORK.warningText = | 74 State.StatesEnum.ERROR_NO_NETWORK.warningText = |
| 64 strings.getString('warningNoConnection'); | 75 strings.getString('warningNoConnection'); |
| 65 State.StatesEnum.ERROR_DEVICE_TOO_SMALL.statusText = | 76 State.StatesEnum.ERROR_DEVICE_TOO_SMALL.statusText = |
| 66 strings.getString('statusNoSpace'); | 77 strings.getString('statusNoSpace'); |
| 67 State.StatesEnum.PROGRESS_DOWNLOAD.statusText = | 78 State.StatesEnum.PROGRESS_DOWNLOAD.statusText = |
| 68 strings.getString('statusDownloading'); | 79 strings.getString('statusDownloading'); |
| 69 State.StatesEnum.PROGRESS_UNZIP.statusText = | 80 State.StatesEnum.PROGRESS_UNZIP.statusText = |
| 70 strings.getString('statusUnzip'); | 81 strings.getString('statusUnzip'); |
| 71 State.StatesEnum.PROGRESS_BURN.statusText = strings.getString('statusBurn'); | 82 State.StatesEnum.PROGRESS_BURN.statusText = strings.getString('statusBurn'); |
| 72 State.StatesEnum.FAIL.statusText = strings.getString('statusError'); | 83 State.StatesEnum.FAIL.statusText = strings.getString('statusError'); |
| 73 State.StatesEnum.SUCCESS.statusText = strings.getString('statusSuccess'); | 84 State.StatesEnum.SUCCESS.statusText = strings.getString('statusSuccess'); |
| 74 State.StatesEnum.SUCCESS.warningText = strings.getString('warningSuccess'); | 85 State.StatesEnum.SUCCESS.warningText = strings.getString('warningSuccess'); |
| 75 }, | 86 }, |
| 76 | 87 |
| 88 /** | |
| 89 * Changes the current state to new state. | |
| 90 * @param {Object} newState Specifies the new state object. | |
| 91 */ | |
| 77 changeState: function(newState) { | 92 changeState: function(newState) { |
| 78 if (newState == this.state) | 93 if (newState == this.state) |
| 79 return; | 94 return; |
| 80 this.state = newState; | 95 this.state = newState; |
| 81 | 96 |
| 82 $('main-content').className = this.state.cssState; | 97 $('main-content').className = this.state.cssState; |
| 83 | 98 |
| 84 $('status-text').textContent = this.state.statusText; | 99 $('status-text').textContent = this.state.statusText; |
| 85 | 100 |
| 86 if (newState.warningText) { | 101 if (newState.warningText) { |
|
Dan Beam
2012/05/11 01:06:09
nit: no curlies
kmadhusu
2012/05/11 21:52:42
Done.
| |
| 87 $('warning-text').textContent = this.state.warningText; | 102 $('warning-text').textContent = this.state.warningText; |
| 88 } | 103 } |
| 89 | 104 |
| 90 if (this.isInitialState() && this.state != State.StatesEnum.DEVICE_NONE) { | 105 if (this.isInitialState() && this.state != State.StatesEnum.DEVICE_NONE) { |
| 91 $('warning-button').textContent = localStrings.getString('confirmButton'); | 106 $('warning-button').textContent = localStrings.getString('confirmButton'); |
| 92 } else if (this.state == State.StatesEnum.FAIL) { | 107 } else if (this.state == State.StatesEnum.FAIL) { |
| 93 $('warning-button').textContent = | 108 $('warning-button').textContent = |
| 94 localStrings.getString('retryButton'); | 109 localStrings.getString('retryButton'); |
| 95 } | 110 } |
| 96 }, | 111 }, |
| 97 | 112 |
| 113 /** | |
| 114 * Reset to initial state. | |
| 115 * @param {number} deviceCount Device count information. | |
| 116 */ | |
| 98 gotoInitialState: function(deviceCount) { | 117 gotoInitialState: function(deviceCount) { |
| 99 if (deviceCount == 0) { | 118 if (deviceCount == 0) { |
|
Dan Beam
2012/05/11 01:06:09
nit: no curlies
kmadhusu
2012/05/11 21:52:42
Done.
| |
| 100 this.changeState(State.StatesEnum.DEVICE_NONE); | 119 this.changeState(State.StatesEnum.DEVICE_NONE); |
| 101 } else if (deviceCount == 1) { | 120 } else if (deviceCount == 1) { |
| 102 this.changeState(State.StatesEnum.DEVICE_USB); | 121 this.changeState(State.StatesEnum.DEVICE_USB); |
| 103 } else { | 122 } else { |
| 104 this.changeState(State.StatesEnum.DEVICE_MUL); | 123 this.changeState(State.StatesEnum.DEVICE_MUL); |
| 105 } | 124 } |
| 106 }, | 125 }, |
| 107 | 126 |
| 127 /** | |
| 128 * Returns true if the device is in initial state. | |
| 129 * @return {boolean} True if the device is in initial state else false. | |
| 130 */ | |
| 108 isInitialState: function() { | 131 isInitialState: function() { |
| 109 return (this.state == State.StatesEnum.DEVICE_NONE || | 132 return (this.state == State.StatesEnum.DEVICE_NONE || |
|
Dan Beam
2012/05/11 01:06:09
nit: remove ()
kmadhusu
2012/05/11 21:52:42
Done.
| |
| 110 this.state == State.StatesEnum.DEVICE_USB || | 133 this.state == State.StatesEnum.DEVICE_USB || |
| 111 this.state == State.StatesEnum.DEVICE_SD || | 134 this.state == State.StatesEnum.DEVICE_SD || |
| 112 this.state == State.StatesEnum.DEVICE_MUL); | 135 this.state == State.StatesEnum.DEVICE_MUL); |
| 113 }, | 136 }, |
| 114 | 137 |
| 138 /** | |
| 139 * Returns true if device state matches the given state name. | |
| 140 * @param {string} stateName Given state name. | |
| 141 * @return {boolean} True if the device state matches the given state name. | |
| 142 */ | |
| 115 equals: function(stateName) { | 143 equals: function(stateName) { |
| 116 return this.state == stateName; | 144 return this.state == stateName; |
| 117 } | 145 } |
| 118 }; | 146 }; |
| 119 | 147 |
| 120 // Class that keeps track of available devices. | 148 /** |
| 149 * Class that keeps track of available devices. | |
| 150 * @constructor | |
| 151 */ | |
| 121 function DeviceSelection() { | 152 function DeviceSelection() { |
| 122 this.deviceCount = 0; | 153 this.deviceCount = 0; |
| 123 }; | 154 } |
| 124 | 155 |
| 125 DeviceSelection.prototype = { | 156 DeviceSelection.prototype = { |
| 157 /** | |
| 158 * Clears the given selection list. | |
| 159 * @param {Array} list Device selection list. | |
| 160 */ | |
| 126 clearSelectList: function(list) { | 161 clearSelectList: function(list) { |
| 127 list.innerHtml = ''; | 162 list.innerHtml = ''; |
| 128 }, | 163 }, |
| 129 | 164 |
| 165 /** | |
| 166 * Returns the selected device count. | |
|
Dan Beam
2012/05/11 01:06:09
Shouldn't this say:
Shows the currently selecte
kmadhusu
2012/05/11 21:52:42
Done.
| |
| 167 * @return {number} Selected device count. | |
| 168 */ | |
| 130 showDeviceSelection: function() { | 169 showDeviceSelection: function() { |
| 131 if (this.deviceCount == 0) { | 170 if (this.deviceCount == 0) { |
| 132 this.selectedDevice = undefined; | 171 this.selectedDevice = undefined; |
| 133 } else { | 172 } else { |
| 134 var devices = document.getElementsByClassName('selection-element'); | 173 var devices = document.getElementsByClassName('selection-element'); |
| 135 this.selectDevice(devices[0].devicePath); | 174 this.selectDevice(devices[0].devicePath); |
| 136 } | 175 } |
| 137 return this.deviceCount; | 176 return this.deviceCount; |
| 138 }, | 177 }, |
| 139 | 178 |
| 179 /** | |
| 180 * Handles device selected event. | |
| 181 * @param {string} label Device label. | |
| 182 * @param {string} filePath File path. | |
| 183 * @param {string} devicePath Selected device path. | |
| 184 */ | |
| 140 onDeviceSelected: function(label, filePath, devicePath) { | 185 onDeviceSelected: function(label, filePath, devicePath) { |
| 141 $('warning-button').onclick = | 186 $('warning-button').onclick = |
| 142 browserBridge.sendBurnImageMessage.bind(browserBridge, filePath, | 187 browserBridge.sendBurnImageMessage.bind(browserBridge, filePath, |
| 143 devicePath); | 188 devicePath); |
| 144 | 189 |
| 145 this.selectedDevice = devicePath; | 190 this.selectedDevice = devicePath; |
| 146 | 191 |
| 147 $('warning-text').textContent = | 192 $('warning-text').textContent = |
| 148 localStrings.getStringF('warningDevices', label); | 193 localStrings.getStringF('warningDevices', label); |
| 149 }, | 194 }, |
| 150 | 195 |
| 196 /** | |
| 197 * Selects the specified device based on the specified path. | |
| 198 * @param {string} path Device path. | |
| 199 */ | |
| 151 selectDevice: function(path) { | 200 selectDevice: function(path) { |
| 152 var element = $('radio ' + path); | 201 var element = $('radio ' + path); |
| 153 element.checked = true; | 202 element.checked = true; |
| 154 element.onclick.apply(element); | 203 element.onclick.apply(element); |
| 155 }, | 204 }, |
| 156 | 205 |
| 206 /** | |
| 207 * Creates a new device element. | |
| 208 * @param {Object} device Specifies new device information. | |
| 209 * @return {HTMLLIElement} New device element. | |
| 210 */ | |
| 157 createNewDeviceElement: function(device) { | 211 createNewDeviceElement: function(device) { |
| 158 var element = document.createElement('li'); | 212 var element = document.createElement('li'); |
| 159 var radioButton = document.createElement('input'); | 213 var radioButton = document.createElement('input'); |
| 160 radioButton.type = 'radio'; | 214 radioButton.type = 'radio'; |
| 161 radioButton.name = 'device'; | 215 radioButton.name = 'device'; |
| 162 radioButton.value = device.label; | 216 radioButton.value = device.label; |
| 163 radioButton.id = 'radio ' + device.devicePath; | 217 radioButton.id = 'radio ' + device.devicePath; |
| 164 radioButton.className = 'float-start'; | 218 radioButton.className = 'float-start'; |
| 165 var deviceLabelText = document.createElement('p'); | 219 var deviceLabelText = document.createElement('p'); |
| 166 deviceLabelText.textContent = device.label; | 220 deviceLabelText.textContent = device.label; |
| 167 deviceLabelText.className = 'select-option float-start'; | 221 deviceLabelText.className = 'select-option float-start'; |
| 168 var newLine = document.createElement('div'); | 222 var newLine = document.createElement('div'); |
| 169 newLine.className = 'new-line'; | 223 newLine.className = 'new-line'; |
| 170 element.appendChild(radioButton); | 224 element.appendChild(radioButton); |
| 171 element.appendChild(deviceLabelText); | 225 element.appendChild(deviceLabelText); |
| 172 element.appendChild(newLine); | 226 element.appendChild(newLine); |
| 173 element.id = 'select ' + device.devicePath; | 227 element.id = 'select ' + device.devicePath; |
| 174 element.devicePath = device.devicePath; | 228 element.devicePath = device.devicePath; |
| 175 element.className = 'selection-element'; | 229 element.className = 'selection-element'; |
| 176 radioButton.onclick = this.onDeviceSelected.bind(this, | 230 radioButton.onclick = this.onDeviceSelected.bind(this, |
| 177 device.label, device.filePath, device.devicePath); | 231 device.label, device.filePath, device.devicePath); |
| 178 return element; | 232 return element; |
| 179 }, | 233 }, |
| 180 | 234 |
| 235 /** | |
| 236 * Updates the list of selected devices. | |
| 237 * @param {Array} devices List of devices. | |
| 238 * @return {number} Device count. | |
| 239 */ | |
| 181 getDevicesCallback: function(devices) { | 240 getDevicesCallback: function(devices) { |
| 182 var selectListDOM = $('device-selection'); | 241 var selectListDOM = $('device-selection'); |
| 183 this.clearSelectList(selectListDOM); | 242 this.clearSelectList(selectListDOM); |
| 184 this.deviceCount = devices.length; | 243 this.deviceCount = devices.length; |
| 185 if (devices.length > 0) { | 244 if (devices.length > 0) { |
| 186 for (var i = 0; i < devices.length; i++) { | 245 for (var i = 0; i < devices.length; i++) { |
| 187 var element = this.createNewDeviceElement(devices[i]); | 246 var element = this.createNewDeviceElement(devices[i]); |
| 188 selectListDOM.appendChild(element); | 247 selectListDOM.appendChild(element); |
| 189 } | 248 } |
| 190 this.selectDevice(devices[0].devicePath); | 249 this.selectDevice(devices[0].devicePath); |
| 191 } else { | 250 } else { |
| 192 this.selectedDevice = undefined; | 251 this.selectedDevice = undefined; |
| 193 } | 252 } |
| 194 return this.deviceCount; | 253 return this.deviceCount; |
| 195 }, | 254 }, |
| 196 | 255 |
| 256 /** | |
| 257 * Handles device added event. | |
| 258 * @param {Object} device Device information. | |
| 259 * @param {boolean} allowSelect True to update the selected device info. | |
| 260 * @return {number} Device count. | |
| 261 */ | |
| 197 deviceAdded: function(device, allowSelect) { | 262 deviceAdded: function(device, allowSelect) { |
| 198 var selectListDOM = $('device-selection'); | 263 var selectListDOM = $('device-selection'); |
| 199 selectListDOM.appendChild(this.createNewDeviceElement(device)); | 264 selectListDOM.appendChild(this.createNewDeviceElement(device)); |
| 200 this.deviceCount++; | 265 this.deviceCount++; |
| 201 if (allowSelect && this.deviceCount == 1) | 266 if (allowSelect && this.deviceCount == 1) |
| 202 this.selectDevice(device.devicePath); | 267 this.selectDevice(device.devicePath); |
| 203 return this.deviceCount; | 268 return this.deviceCount; |
| 204 }, | 269 }, |
| 205 | 270 |
| 271 /** | |
| 272 * Handles device removed event. | |
| 273 * @param {string} devicePath Selected device path. | |
| 274 * @param {boolean} allowSelect True to update the selected device info. | |
| 275 * @return {number} Device count. | |
| 276 */ | |
| 206 deviceRemoved: function(devicePath, allowSelect) { | 277 deviceRemoved: function(devicePath, allowSelect) { |
| 207 var deviceSelectElement = $('select ' + devicePath); | 278 var deviceSelectElement = $('select ' + devicePath); |
| 208 deviceSelectElement.parentNode.removeChild(deviceSelectElement); | 279 deviceSelectElement.parentNode.removeChild(deviceSelectElement); |
| 209 this.deviceCount--; | 280 this.deviceCount--; |
| 210 var devices = document.getElementsByClassName('selection-element'); | 281 var devices = document.getElementsByClassName('selection-element'); |
| 211 | 282 |
| 212 if (allowSelect) { | 283 if (allowSelect) { |
| 213 if (devices.length > 0) { | 284 if (devices.length > 0) { |
| 214 if (this.selectedDevice == devicePath) | 285 if (this.selectedDevice == devicePath) |
| 215 this.selectDevice(devices[0].devicePath); | 286 this.selectDevice(devices[0].devicePath); |
| 216 } else { | 287 } else { |
| 217 this.selectedDevice = undefined; | 288 this.selectedDevice = undefined; |
| 218 } | 289 } |
| 219 } | 290 } |
| 220 return this.deviceCount; | 291 return this.deviceCount; |
| 221 } | 292 } |
| 222 }; | 293 }; |
| 223 | 294 |
| 224 // Class that handles communication with chrome. | 295 /** |
| 296 * Class that handles communication with chrome. | |
| 297 * @constructor | |
| 298 */ | |
| 225 function BrowserBridge() { | 299 function BrowserBridge() { |
| 226 this.currentState = new State(localStrings); | 300 this.currentState = new State(localStrings); |
| 227 this.devices = new DeviceSelection(); | 301 this.devices = new DeviceSelection(); |
| 228 // We will use these often so it makes sence making them class members to | 302 // We will use these often so it makes sence making them class members to |
| 229 // avoid frequent document.getElementById calls. | 303 // avoid frequent document.getElementById calls. |
| 230 this.progressElement = $('progress-div'); | 304 this.progressElement = $('progress-div'); |
| 231 this.progressText = $('progress-text'); | 305 this.progressText = $('progress-text'); |
| 232 this.progressTimeLeftText = $('pending-time'); | 306 this.progressTimeLeftText = $('pending-time'); |
| 233 }; | 307 } |
| 234 | 308 |
| 235 BrowserBridge.prototype = { | 309 BrowserBridge.prototype = { |
| 236 sendCancelMessage: function() { | 310 sendCancelMessage: function() { |
| 237 chrome.send("cancelBurnImage"); | 311 chrome.send('cancelBurnImage'); |
| 238 }, | 312 }, |
| 239 | 313 |
| 240 sendGetDevicesMessage: function() { | 314 sendGetDevicesMessage: function() { |
| 241 chrome.send("getDevices"); | 315 chrome.send('getDevices'); |
| 242 }, | 316 }, |
| 243 | 317 |
| 244 sendWebuiInitializedMessage: function() { | 318 sendWebuiInitializedMessage: function() { |
| 245 chrome.send("webuiInitialized"); | 319 chrome.send('webuiInitialized'); |
| 246 }, | 320 }, |
| 247 | 321 |
| 322 /** | |
| 323 * Sends the burn image message to c++ code. | |
| 324 * @param {string} filePath Specifies the file path. | |
| 325 * @param {string} devicePath Specifies the device path. | |
| 326 */ | |
| 248 sendBurnImageMessage: function(filePath, devicePath) { | 327 sendBurnImageMessage: function(filePath, devicePath) { |
| 249 chrome.send('burnImage', [devicePath, filePath]); | 328 chrome.send('burnImage', [devicePath, filePath]); |
| 250 }, | 329 }, |
| 251 | 330 |
| 252 reportSuccess: function() { | 331 reportSuccess: function() { |
| 253 this.currentState.changeState(State.StatesEnum.SUCCESS); | 332 this.currentState.changeState(State.StatesEnum.SUCCESS); |
| 254 }, | 333 }, |
| 255 | 334 |
| 335 /** | |
| 336 * Update the device state to report a failure and display an error message to | |
| 337 * the user. | |
| 338 * @param {string} errorMessage Specifies the warning text message. | |
| 339 */ | |
| 256 reportFail: function(errorMessage) { | 340 reportFail: function(errorMessage) { |
| 257 this.currentState.changeState(State.StatesEnum.FAIL); | 341 this.currentState.changeState(State.StatesEnum.FAIL); |
| 258 $('warning-text').textContent = errorMessage; | 342 $('warning-text').textContent = errorMessage; |
| 259 $('warning-button').onclick = this.onBurnRetry.bind(this); | 343 $('warning-button').onclick = this.onBurnRetry.bind(this); |
| 260 }, | 344 }, |
| 261 | 345 |
| 346 /** | |
| 347 * Handles device added event. | |
| 348 * @param {Object} device Device information. | |
| 349 */ | |
| 262 deviceAdded: function(device) { | 350 deviceAdded: function(device) { |
| 263 var inInitialState = this.currentState.isInitialState(); | 351 var inInitialState = this.currentState.isInitialState(); |
| 264 var deviceCount = this.devices.deviceAdded(device, inInitialState); | 352 var deviceCount = this.devices.deviceAdded(device, inInitialState); |
| 265 if (inInitialState) | 353 if (inInitialState) |
| 266 this.currentState.gotoInitialState(deviceCount); | 354 this.currentState.gotoInitialState(deviceCount); |
| 267 }, | 355 }, |
| 268 | 356 |
| 357 /** | |
| 358 * Handles device removed event. | |
| 359 * @param {Object} device Device information. | |
| 360 */ | |
| 269 deviceRemoved: function(device) { | 361 deviceRemoved: function(device) { |
| 270 var inInitialState = this.currentState.isInitialState(); | 362 var inInitialState = this.currentState.isInitialState(); |
| 271 var deviceCount = this.devices.deviceRemoved(device, inInitialState); | 363 var deviceCount = this.devices.deviceRemoved(device, inInitialState); |
| 272 if (inInitialState) | 364 if (inInitialState) |
| 273 this.currentState.gotoInitialState(deviceCount); | 365 this.currentState.gotoInitialState(deviceCount); |
| 274 }, | 366 }, |
| 275 | 367 |
| 368 /** | |
| 369 * Gets device callbacks and update the current state. | |
| 370 * @param {Array} devices List of devices. | |
| 371 */ | |
| 276 getDevicesCallback: function(devices) { | 372 getDevicesCallback: function(devices) { |
| 277 var deviceCount = this.devices.getDevicesCallback(devices); | 373 var deviceCount = this.devices.getDevicesCallback(devices); |
| 278 this.currentState.gotoInitialState(deviceCount); | 374 this.currentState.gotoInitialState(deviceCount); |
| 279 this.sendWebuiInitializedMessage(); | 375 this.sendWebuiInitializedMessage(); |
| 280 }, | 376 }, |
| 281 | 377 |
| 378 /** | |
| 379 * Updates the progress information based on the signal received. | |
| 380 * @param {Object} update_signal Specifies the signal information. | |
|
Dan Beam
2012/05/11 01:06:09
nit: updateSignal
kmadhusu
2012/05/11 21:52:42
Done.
| |
| 381 */ | |
| 282 updateProgress: function(update_signal) { | 382 updateProgress: function(update_signal) { |
| 283 if (update_signal.progressType == 'download' && | 383 if (update_signal.progressType == 'download' && |
| 284 !this.currentState.equals(State.StatesEnum.PROGRESS_DOWNLOAD)) { | 384 !this.currentState.equals(State.StatesEnum.PROGRESS_DOWNLOAD)) { |
| 285 this.currentState.changeState(State.StatesEnum.PROGRESS_DOWNLOAD); | 385 this.currentState.changeState(State.StatesEnum.PROGRESS_DOWNLOAD); |
| 286 } else if (update_signal.progressType == 'unzip' && | 386 } else if (update_signal.progressType == 'unzip' && |
| 287 !this.currentState.equals(State.StatesEnum.PROGRESS_UNZIP)) { | 387 !this.currentState.equals(State.StatesEnum.PROGRESS_UNZIP)) { |
| 288 this.currentState.changeState(State.StatesEnum.PROGRESS_UNZIP); | 388 this.currentState.changeState(State.StatesEnum.PROGRESS_UNZIP); |
| 289 } else if (update_signal.progressType == 'burn' && | 389 } else if (update_signal.progressType == 'burn' && |
| 290 !this.currentState.equals(State.StatesEnum.PROGRESS_BURN)) { | 390 !this.currentState.equals(State.StatesEnum.PROGRESS_BURN)) { |
| 291 this.currentState.changeState(State.StatesEnum.PROGRESS_BURN); | 391 this.currentState.changeState(State.StatesEnum.PROGRESS_BURN); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 306 this.currentState.changeState(State.StatesEnum.ERROR_NO_NETWORK); | 406 this.currentState.changeState(State.StatesEnum.ERROR_NO_NETWORK); |
| 307 }, | 407 }, |
| 308 | 408 |
| 309 reportNetworkDetected: function() { | 409 reportNetworkDetected: function() { |
| 310 if (this.currentState.equals(State.StatesEnum.ERROR_NO_NETWORK)) { | 410 if (this.currentState.equals(State.StatesEnum.ERROR_NO_NETWORK)) { |
| 311 var deviceCount = this.devices.showDeviceSelection(); | 411 var deviceCount = this.devices.showDeviceSelection(); |
| 312 this.currentState.gotoInitialState(deviceCount); | 412 this.currentState.gotoInitialState(deviceCount); |
| 313 } | 413 } |
| 314 }, | 414 }, |
| 315 | 415 |
| 416 /** | |
| 417 * Updates the current state to report device too small error. | |
| 418 * @param {number} device_size Received device size. | |
|
Dan Beam
2012/05/11 01:06:09
nit: deviceSize
kmadhusu
2012/05/11 21:52:42
Done.
| |
| 419 */ | |
| 316 reportDeviceTooSmall: function(device_size) { | 420 reportDeviceTooSmall: function(device_size) { |
| 317 this.currentState.changeState(State.StatesEnum.ERROR_DEVICE_TOO_SMALL); | 421 this.currentState.changeState(State.StatesEnum.ERROR_DEVICE_TOO_SMALL); |
| 318 $('warning-text').textContent = | 422 $('warning-text').textContent = |
| 319 localStrings.getStringF('warningNoSpace', device_size); | 423 localStrings.getStringF('warningNoSpace', device_size); |
| 320 }, | 424 }, |
| 321 | 425 |
| 322 // Processes click on "Retry" button in FAIL state. | 426 /** |
| 323 onBurnRetry: function () { | 427 * Processes click on 'Retry' button in FAIL state. |
| 428 */ | |
| 429 onBurnRetry: function() { | |
| 324 var deviceCount = this.devices.showDeviceSelection(); | 430 var deviceCount = this.devices.showDeviceSelection(); |
| 325 this.currentState.gotoInitialState(deviceCount); | 431 this.currentState.gotoInitialState(deviceCount); |
| 326 } | 432 } |
| 327 }; | 433 }; |
| 328 | 434 |
| 329 document.addEventListener('DOMContentLoaded', function() { | 435 document.addEventListener('DOMContentLoaded', function() { |
| 330 localStrings = new LocalStrings(); | 436 localStrings = new LocalStrings(); |
| 331 browserBridge = new BrowserBridge(); | 437 browserBridge = new BrowserBridge(); |
| 332 | 438 |
| 333 jstProcess(new JsEvalContext(templateData), $("more-info-link")); | 439 jstProcess(new JsEvalContext(templateData), $('more-info-link')); |
| 334 | 440 |
| 335 $('cancel-button').onclick = | 441 $('cancel-button').onclick = |
| 336 browserBridge.sendCancelMessage.bind(browserBridge); | 442 browserBridge.sendCancelMessage.bind(browserBridge); |
| 337 browserBridge.sendGetDevicesMessage(); | 443 browserBridge.sendGetDevicesMessage(); |
| 338 }); | 444 }); |
| OLD | NEW |