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 * @this {State} | |
|
Tyler Breisacher (Chromium)
2012/05/07 20:37:03
These @this's shouldn't be necessary because we're
kmadhusu
2012/05/08 20:20:19
Removed.
| |
| 92 */ | |
| 77 changeState: function(newState) { | 93 changeState: function(newState) { |
| 78 if (newState == this.state) | 94 if (newState == this.state) |
| 79 return; | 95 return; |
| 80 this.state = newState; | 96 this.state = newState; |
| 81 | 97 |
| 82 $('main-content').className = this.state.cssState; | 98 $('main-content').className = this.state.cssState; |
| 83 | 99 |
| 84 $('status-text').textContent = this.state.statusText; | 100 $('status-text').textContent = this.state.statusText; |
| 85 | 101 |
| 86 if (newState.warningText) { | 102 if (newState.warningText) { |
| 87 $('warning-text').textContent = this.state.warningText; | 103 $('warning-text').textContent = this.state.warningText; |
| 88 } | 104 } |
| 89 | 105 |
| 90 if (this.isInitialState() && this.state != State.StatesEnum.DEVICE_NONE) { | 106 if (this.isInitialState() && this.state != State.StatesEnum.DEVICE_NONE) { |
| 91 $('warning-button').textContent = localStrings.getString('confirmButton'); | 107 $('warning-button').textContent = localStrings.getString('confirmButton'); |
| 92 } else if (this.state == State.StatesEnum.FAIL) { | 108 } else if (this.state == State.StatesEnum.FAIL) { |
| 93 $('warning-button').textContent = | 109 $('warning-button').textContent = |
| 94 localStrings.getString('retryButton'); | 110 localStrings.getString('retryButton'); |
| 95 } | 111 } |
| 96 }, | 112 }, |
| 97 | 113 |
| 114 /** | |
| 115 * Reset to initial state. | |
| 116 * @param {number} deviceCount Device count information. | |
| 117 * @this {State} | |
| 118 */ | |
| 98 gotoInitialState: function(deviceCount) { | 119 gotoInitialState: function(deviceCount) { |
| 99 if (deviceCount == 0) { | 120 if (deviceCount == 0) { |
| 100 this.changeState(State.StatesEnum.DEVICE_NONE); | 121 this.changeState(State.StatesEnum.DEVICE_NONE); |
| 101 } else if (deviceCount == 1) { | 122 } else if (deviceCount == 1) { |
| 102 this.changeState(State.StatesEnum.DEVICE_USB); | 123 this.changeState(State.StatesEnum.DEVICE_USB); |
| 103 } else { | 124 } else { |
| 104 this.changeState(State.StatesEnum.DEVICE_MUL); | 125 this.changeState(State.StatesEnum.DEVICE_MUL); |
| 105 } | 126 } |
| 106 }, | 127 }, |
| 107 | 128 |
| 129 /** | |
| 130 * Returns true if the device is in initial state. | |
| 131 * @this {State} | |
| 132 * @return {boolean} True if the device is in initial state else false. | |
| 133 */ | |
| 108 isInitialState: function() { | 134 isInitialState: function() { |
| 109 return (this.state == State.StatesEnum.DEVICE_NONE || | 135 return (this.state == State.StatesEnum.DEVICE_NONE || |
| 110 this.state == State.StatesEnum.DEVICE_USB || | 136 this.state == State.StatesEnum.DEVICE_USB || |
| 111 this.state == State.StatesEnum.DEVICE_SD || | 137 this.state == State.StatesEnum.DEVICE_SD || |
| 112 this.state == State.StatesEnum.DEVICE_MUL); | 138 this.state == State.StatesEnum.DEVICE_MUL); |
| 113 }, | 139 }, |
| 114 | 140 |
| 141 /** | |
| 142 * Returns true if device state matches the given state name. | |
| 143 * @param {string} stateName Given state name. | |
| 144 * @this {State} | |
| 145 * @return {boolean} True if the device state matches the given state name. | |
| 146 */ | |
| 115 equals: function(stateName) { | 147 equals: function(stateName) { |
| 116 return this.state == stateName; | 148 return this.state == stateName; |
| 117 } | 149 } |
| 118 }; | 150 }; |
| 119 | 151 |
| 120 // Class that keeps track of available devices. | 152 /** |
| 153 * Class that keeps track of available devices. | |
| 154 * @constructor | |
| 155 */ | |
| 121 function DeviceSelection() { | 156 function DeviceSelection() { |
| 122 this.deviceCount = 0; | 157 this.deviceCount = 0; |
| 123 }; | 158 } |
| 124 | 159 |
| 125 DeviceSelection.prototype = { | 160 DeviceSelection.prototype = { |
| 161 /** | |
| 162 * Clears the given selection list. | |
| 163 * @param {Array} list Device selection list. | |
| 164 */ | |
| 126 clearSelectList: function(list) { | 165 clearSelectList: function(list) { |
| 127 list.innerHtml = ''; | 166 list.innerHtml = ''; |
| 128 }, | 167 }, |
| 129 | 168 |
| 169 /** | |
| 170 * Returns the selected device count. | |
| 171 * @this {DeviceSelection} | |
| 172 * @return {number} Selected device count. | |
| 173 */ | |
| 130 showDeviceSelection: function() { | 174 showDeviceSelection: function() { |
| 131 if (this.deviceCount == 0) { | 175 if (this.deviceCount == 0) { |
| 132 this.selectedDevice = undefined; | 176 this.selectedDevice = undefined; |
| 133 } else { | 177 } else { |
| 134 var devices = document.getElementsByClassName('selection-element'); | 178 var devices = document.getElementsByClassName('selection-element'); |
| 135 this.selectDevice(devices[0].devicePath); | 179 this.selectDevice(devices[0].devicePath); |
| 136 } | 180 } |
| 137 return this.deviceCount; | 181 return this.deviceCount; |
| 138 }, | 182 }, |
| 139 | 183 |
| 184 /** | |
| 185 * Handles device selected event. | |
| 186 * @param {string} label Device label. | |
| 187 * @param {string} filePath File path. | |
| 188 * @param {string} devicePath Selected device path. | |
| 189 * @this {DeviceSelection} | |
| 190 */ | |
| 140 onDeviceSelected: function(label, filePath, devicePath) { | 191 onDeviceSelected: function(label, filePath, devicePath) { |
| 141 $('warning-button').onclick = | 192 $('warning-button').onclick = |
| 142 browserBridge.sendBurnImageMessage.bind(browserBridge, filePath, | 193 browserBridge.sendBurnImageMessage.bind(browserBridge, filePath, |
| 143 devicePath); | 194 devicePath); |
| 144 | 195 |
| 145 this.selectedDevice = devicePath; | 196 this.selectedDevice = devicePath; |
| 146 | 197 |
| 147 $('warning-text').textContent = | 198 $('warning-text').textContent = |
| 148 localStrings.getStringF('warningDevices', label); | 199 localStrings.getStringF('warningDevices', label); |
| 149 }, | 200 }, |
| 150 | 201 |
| 202 /** | |
| 203 * Selects the specified device based on the specified path. | |
| 204 * @param {string} path Device path. | |
| 205 */ | |
| 151 selectDevice: function(path) { | 206 selectDevice: function(path) { |
| 152 var element = $('radio ' + path); | 207 var element = $('radio ' + path); |
| 153 element.checked = true; | 208 element.checked = true; |
| 154 element.onclick.apply(element); | 209 element.onclick.apply(element); |
| 155 }, | 210 }, |
| 156 | 211 |
| 212 /** | |
| 213 * Creates a new device element. | |
| 214 * @param {Object} device Specifies new device information. | |
| 215 * @return {HTMLLIElement} New device element. | |
| 216 * @this {DeviceSelection} | |
| 217 */ | |
| 157 createNewDeviceElement: function(device) { | 218 createNewDeviceElement: function(device) { |
| 158 var element = document.createElement('li'); | 219 var element = document.createElement('li'); |
| 159 var radioButton = document.createElement('input'); | 220 var radioButton = document.createElement('input'); |
| 160 radioButton.type = 'radio'; | 221 radioButton.type = 'radio'; |
| 161 radioButton.name = 'device'; | 222 radioButton.name = 'device'; |
| 162 radioButton.value = device.label; | 223 radioButton.value = device.label; |
| 163 radioButton.id = 'radio ' + device.devicePath; | 224 radioButton.id = 'radio ' + device.devicePath; |
| 164 radioButton.className = 'float-start'; | 225 radioButton.className = 'float-start'; |
| 165 var deviceLabelText = document.createElement('p'); | 226 var deviceLabelText = document.createElement('p'); |
| 166 deviceLabelText.textContent = device.label; | 227 deviceLabelText.textContent = device.label; |
| 167 deviceLabelText.className = 'select-option float-start'; | 228 deviceLabelText.className = 'select-option float-start'; |
| 168 var newLine = document.createElement('div'); | 229 var newLine = document.createElement('div'); |
| 169 newLine.className = 'new-line'; | 230 newLine.className = 'new-line'; |
| 170 element.appendChild(radioButton); | 231 element.appendChild(radioButton); |
| 171 element.appendChild(deviceLabelText); | 232 element.appendChild(deviceLabelText); |
| 172 element.appendChild(newLine); | 233 element.appendChild(newLine); |
| 173 element.id = 'select ' + device.devicePath; | 234 element.id = 'select ' + device.devicePath; |
| 174 element.devicePath = device.devicePath; | 235 element.devicePath = device.devicePath; |
| 175 element.className = 'selection-element'; | 236 element.className = 'selection-element'; |
| 176 radioButton.onclick = this.onDeviceSelected.bind(this, | 237 radioButton.onclick = this.onDeviceSelected.bind(this, |
| 177 device.label, device.filePath, device.devicePath); | 238 device.label, device.filePath, device.devicePath); |
| 178 return element; | 239 return element; |
| 179 }, | 240 }, |
| 180 | 241 |
| 242 /** | |
| 243 * Updates the list of selected devices. | |
| 244 * @param {Array} devices List of devices. | |
| 245 * @return {number} Device count. | |
| 246 * @this {DeviceSelection} | |
| 247 */ | |
| 181 getDevicesCallback: function(devices) { | 248 getDevicesCallback: function(devices) { |
| 182 var selectListDOM = $('device-selection'); | 249 var selectListDOM = $('device-selection'); |
| 183 this.clearSelectList(selectListDOM); | 250 this.clearSelectList(selectListDOM); |
| 184 this.deviceCount = devices.length; | 251 this.deviceCount = devices.length; |
| 185 if (devices.length > 0) { | 252 if (devices.length > 0) { |
| 186 for (var i = 0; i < devices.length; i++) { | 253 for (var i = 0; i < devices.length; i++) { |
| 187 var element = this.createNewDeviceElement(devices[i]); | 254 var element = this.createNewDeviceElement(devices[i]); |
| 188 selectListDOM.appendChild(element); | 255 selectListDOM.appendChild(element); |
| 189 } | 256 } |
| 190 this.selectDevice(devices[0].devicePath); | 257 this.selectDevice(devices[0].devicePath); |
| 191 } else { | 258 } else { |
| 192 this.selectedDevice = undefined; | 259 this.selectedDevice = undefined; |
| 193 } | 260 } |
| 194 return this.deviceCount; | 261 return this.deviceCount; |
| 195 }, | 262 }, |
| 196 | 263 |
| 264 /** | |
| 265 * Handles device added event. | |
| 266 * @param {Object} device Device information. | |
| 267 * @param {boolean} allowSelect True to update the selected device info. | |
| 268 * @return {number} Device count. | |
| 269 * @this {DeviceSelection} | |
| 270 */ | |
| 197 deviceAdded: function(device, allowSelect) { | 271 deviceAdded: function(device, allowSelect) { |
| 198 var selectListDOM = $('device-selection'); | 272 var selectListDOM = $('device-selection'); |
| 199 selectListDOM.appendChild(this.createNewDeviceElement(device)); | 273 selectListDOM.appendChild(this.createNewDeviceElement(device)); |
| 200 this.deviceCount++; | 274 this.deviceCount++; |
| 201 if (allowSelect && this.deviceCount == 1) | 275 if (allowSelect && this.deviceCount == 1) |
| 202 this.selectDevice(device.devicePath); | 276 this.selectDevice(device.devicePath); |
| 203 return this.deviceCount; | 277 return this.deviceCount; |
| 204 }, | 278 }, |
| 205 | 279 |
| 280 /** | |
| 281 * Handles device removed event. | |
| 282 * @param {string} devicePath Selected device path. | |
| 283 * @param {boolean} allowSelect True to update the selected device info. | |
| 284 * @return {number} Device count. | |
| 285 * @this {DeviceSelection} | |
| 286 */ | |
| 206 deviceRemoved: function(devicePath, allowSelect) { | 287 deviceRemoved: function(devicePath, allowSelect) { |
| 207 var deviceSelectElement = $('select ' + devicePath); | 288 var deviceSelectElement = $('select ' + devicePath); |
| 208 deviceSelectElement.parentNode.removeChild(deviceSelectElement); | 289 deviceSelectElement.parentNode.removeChild(deviceSelectElement); |
| 209 this.deviceCount--; | 290 this.deviceCount--; |
| 210 var devices = document.getElementsByClassName('selection-element'); | 291 var devices = document.getElementsByClassName('selection-element'); |
| 211 | 292 |
| 212 if (allowSelect) { | 293 if (allowSelect) { |
| 213 if (devices.length > 0) { | 294 if (devices.length > 0) { |
| 214 if (this.selectedDevice == devicePath) | 295 if (this.selectedDevice == devicePath) |
| 215 this.selectDevice(devices[0].devicePath); | 296 this.selectDevice(devices[0].devicePath); |
| 216 } else { | 297 } else { |
| 217 this.selectedDevice = undefined; | 298 this.selectedDevice = undefined; |
| 218 } | 299 } |
| 219 } | 300 } |
| 220 return this.deviceCount; | 301 return this.deviceCount; |
| 221 } | 302 } |
| 222 }; | 303 }; |
| 223 | 304 |
| 224 // Class that handles communication with chrome. | 305 /** |
| 306 * Class that handles communication with chrome. | |
| 307 * @constructor | |
| 308 */ | |
| 225 function BrowserBridge() { | 309 function BrowserBridge() { |
| 226 this.currentState = new State(localStrings); | 310 this.currentState = new State(localStrings); |
| 227 this.devices = new DeviceSelection(); | 311 this.devices = new DeviceSelection(); |
| 228 // We will use these often so it makes sence making them class members to | 312 // We will use these often so it makes sence making them class members to |
| 229 // avoid frequent document.getElementById calls. | 313 // avoid frequent document.getElementById calls. |
| 230 this.progressElement = $('progress-div'); | 314 this.progressElement = $('progress-div'); |
| 231 this.progressText = $('progress-text'); | 315 this.progressText = $('progress-text'); |
| 232 this.progressTimeLeftText = $('pending-time'); | 316 this.progressTimeLeftText = $('pending-time'); |
| 233 }; | 317 } |
| 234 | 318 |
| 235 BrowserBridge.prototype = { | 319 BrowserBridge.prototype = { |
| 236 sendCancelMessage: function() { | 320 sendCancelMessage: function() { |
| 237 chrome.send("cancelBurnImage"); | 321 chrome.send('cancelBurnImage'); |
| 238 }, | 322 }, |
| 239 | 323 |
| 240 sendGetDevicesMessage: function() { | 324 sendGetDevicesMessage: function() { |
| 241 chrome.send("getDevices"); | 325 chrome.send('getDevices'); |
| 242 }, | 326 }, |
| 243 | 327 |
| 244 sendWebuiInitializedMessage: function() { | 328 sendWebuiInitializedMessage: function() { |
| 245 chrome.send("webuiInitialized"); | 329 chrome.send('webuiInitialized'); |
| 246 }, | 330 }, |
| 247 | 331 |
| 332 /** | |
| 333 * Sends the burn image message to c++ code. | |
| 334 * @param {string} filePath Specifies the file path. | |
| 335 * @param {string} devicePath Specifies the device path. | |
| 336 */ | |
| 248 sendBurnImageMessage: function(filePath, devicePath) { | 337 sendBurnImageMessage: function(filePath, devicePath) { |
| 249 chrome.send('burnImage', [devicePath, filePath]); | 338 chrome.send('burnImage', [devicePath, filePath]); |
| 250 }, | 339 }, |
| 251 | 340 |
| 252 reportSuccess: function() { | 341 reportSuccess: function() { |
| 253 this.currentState.changeState(State.StatesEnum.SUCCESS); | 342 this.currentState.changeState(State.StatesEnum.SUCCESS); |
| 254 }, | 343 }, |
| 255 | 344 |
| 345 /** | |
| 346 * Update the device state to report a failure and display an error message to | |
| 347 * the user. | |
| 348 * @param {string} errorMessage Specifies the warning text message. | |
| 349 * @this {BrowserBridge} | |
| 350 */ | |
| 256 reportFail: function(errorMessage) { | 351 reportFail: function(errorMessage) { |
| 257 this.currentState.changeState(State.StatesEnum.FAIL); | 352 this.currentState.changeState(State.StatesEnum.FAIL); |
| 258 $('warning-text').textContent = errorMessage; | 353 $('warning-text').textContent = errorMessage; |
| 259 $('warning-button').onclick = this.onBurnRetry.bind(this); | 354 $('warning-button').onclick = this.onBurnRetry.bind(this); |
| 260 }, | 355 }, |
| 261 | 356 |
| 357 /** | |
| 358 * Handles device added event. | |
| 359 * @param {Object} device Device information. | |
| 360 * @this {BrowserBridge} | |
| 361 */ | |
| 262 deviceAdded: function(device) { | 362 deviceAdded: function(device) { |
| 263 var inInitialState = this.currentState.isInitialState(); | 363 var inInitialState = this.currentState.isInitialState(); |
| 264 var deviceCount = this.devices.deviceAdded(device, inInitialState); | 364 var deviceCount = this.devices.deviceAdded(device, inInitialState); |
| 265 if (inInitialState) | 365 if (inInitialState) |
| 266 this.currentState.gotoInitialState(deviceCount); | 366 this.currentState.gotoInitialState(deviceCount); |
| 267 }, | 367 }, |
| 268 | 368 |
| 369 /** | |
| 370 * Handles device removed event. | |
| 371 * @param {Object} device Device information. | |
| 372 * @this {BrowserBridge} | |
| 373 */ | |
| 269 deviceRemoved: function(device) { | 374 deviceRemoved: function(device) { |
| 270 var inInitialState = this.currentState.isInitialState(); | 375 var inInitialState = this.currentState.isInitialState(); |
| 271 var deviceCount = this.devices.deviceRemoved(device, inInitialState); | 376 var deviceCount = this.devices.deviceRemoved(device, inInitialState); |
| 272 if (inInitialState) | 377 if (inInitialState) |
| 273 this.currentState.gotoInitialState(deviceCount); | 378 this.currentState.gotoInitialState(deviceCount); |
| 274 }, | 379 }, |
| 275 | 380 |
| 381 /** | |
| 382 * Gets device callbacks and update the current state. | |
| 383 * @param {Array} devices List of devices. | |
| 384 * @this {BrowserBridge} | |
| 385 */ | |
| 276 getDevicesCallback: function(devices) { | 386 getDevicesCallback: function(devices) { |
| 277 var deviceCount = this.devices.getDevicesCallback(devices); | 387 var deviceCount = this.devices.getDevicesCallback(devices); |
| 278 this.currentState.gotoInitialState(deviceCount); | 388 this.currentState.gotoInitialState(deviceCount); |
| 279 this.sendWebuiInitializedMessage(); | 389 this.sendWebuiInitializedMessage(); |
| 280 }, | 390 }, |
| 281 | 391 |
| 392 /** | |
| 393 * Updates the progress information based on the signal received. | |
| 394 * @param {Object} update_signal Specifies the signal information. | |
| 395 * @this {BrowserBridge} | |
| 396 */ | |
| 282 updateProgress: function(update_signal) { | 397 updateProgress: function(update_signal) { |
| 283 if (update_signal.progressType == 'download' && | 398 if (update_signal.progressType == 'download' && |
| 284 !this.currentState.equals(State.StatesEnum.PROGRESS_DOWNLOAD)) { | 399 !this.currentState.equals(State.StatesEnum.PROGRESS_DOWNLOAD)) { |
| 285 this.currentState.changeState(State.StatesEnum.PROGRESS_DOWNLOAD); | 400 this.currentState.changeState(State.StatesEnum.PROGRESS_DOWNLOAD); |
| 286 } else if (update_signal.progressType == 'unzip' && | 401 } else if (update_signal.progressType == 'unzip' && |
| 287 !this.currentState.equals(State.StatesEnum.PROGRESS_UNZIP)) { | 402 !this.currentState.equals(State.StatesEnum.PROGRESS_UNZIP)) { |
| 288 this.currentState.changeState(State.StatesEnum.PROGRESS_UNZIP); | 403 this.currentState.changeState(State.StatesEnum.PROGRESS_UNZIP); |
| 289 } else if (update_signal.progressType == 'burn' && | 404 } else if (update_signal.progressType == 'burn' && |
| 290 !this.currentState.equals(State.StatesEnum.PROGRESS_BURN)) { | 405 !this.currentState.equals(State.StatesEnum.PROGRESS_BURN)) { |
| 291 this.currentState.changeState(State.StatesEnum.PROGRESS_BURN); | 406 this.currentState.changeState(State.StatesEnum.PROGRESS_BURN); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 306 this.currentState.changeState(State.StatesEnum.ERROR_NO_NETWORK); | 421 this.currentState.changeState(State.StatesEnum.ERROR_NO_NETWORK); |
| 307 }, | 422 }, |
| 308 | 423 |
| 309 reportNetworkDetected: function() { | 424 reportNetworkDetected: function() { |
| 310 if (this.currentState.equals(State.StatesEnum.ERROR_NO_NETWORK)) { | 425 if (this.currentState.equals(State.StatesEnum.ERROR_NO_NETWORK)) { |
| 311 var deviceCount = this.devices.showDeviceSelection(); | 426 var deviceCount = this.devices.showDeviceSelection(); |
| 312 this.currentState.gotoInitialState(deviceCount); | 427 this.currentState.gotoInitialState(deviceCount); |
| 313 } | 428 } |
| 314 }, | 429 }, |
| 315 | 430 |
| 431 /** | |
| 432 * Updates the current state to report device too small error. | |
| 433 * @param {number} device_size Received device size. | |
| 434 * @this {BrowserBridge} | |
| 435 */ | |
| 316 reportDeviceTooSmall: function(device_size) { | 436 reportDeviceTooSmall: function(device_size) { |
| 317 this.currentState.changeState(State.StatesEnum.ERROR_DEVICE_TOO_SMALL); | 437 this.currentState.changeState(State.StatesEnum.ERROR_DEVICE_TOO_SMALL); |
| 318 $('warning-text').textContent = | 438 $('warning-text').textContent = |
| 319 localStrings.getStringF('warningNoSpace', device_size); | 439 localStrings.getStringF('warningNoSpace', device_size); |
| 320 }, | 440 }, |
| 321 | 441 |
| 322 // Processes click on "Retry" button in FAIL state. | 442 /** |
| 323 onBurnRetry: function () { | 443 * Processes click on 'Retry' button in FAIL state. |
| 444 * @this {BrowserBridge} | |
| 445 */ | |
| 446 onBurnRetry: function() { | |
| 324 var deviceCount = this.devices.showDeviceSelection(); | 447 var deviceCount = this.devices.showDeviceSelection(); |
| 325 this.currentState.gotoInitialState(deviceCount); | 448 this.currentState.gotoInitialState(deviceCount); |
| 326 } | 449 } |
| 327 }; | 450 }; |
| 328 | 451 |
| 329 document.addEventListener('DOMContentLoaded', function() { | 452 document.addEventListener('DOMContentLoaded', function() { |
| 330 localStrings = new LocalStrings(); | 453 localStrings = new LocalStrings(); |
| 331 browserBridge = new BrowserBridge(); | 454 browserBridge = new BrowserBridge(); |
| 332 | 455 |
| 333 jstProcess(new JsEvalContext(templateData), $("more-info-link")); | 456 jstProcess(new JsEvalContext(templateData), $('more-info-link')); |
| 334 | 457 |
| 335 $('cancel-button').onclick = | 458 $('cancel-button').onclick = |
| 336 browserBridge.sendCancelMessage.bind(browserBridge); | 459 browserBridge.sendCancelMessage.bind(browserBridge); |
| 337 browserBridge.sendGetDevicesMessage(); | 460 browserBridge.sendGetDevicesMessage(); |
| 338 }); | 461 }); |
| OLD | NEW |