Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html i18n-values="dir:textdirection;"> | 2 <html i18n-values="dir:textdirection;"> |
| 3 <head> | 3 <head> |
| 4 <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"></meta> | 4 <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"></meta> |
| 5 <title i18n-content="title"></title> | 5 <title i18n-content="title"></title> |
| 6 <style> | 6 <style> |
| 7 html, body, ul, li { | 7 html, body, ul, li { |
|
Evan Stade
2011/10/11 21:35:23
tbarzic, at some point please pull this into a sep
| |
| 8 margin: 0; | 8 margin: 0; |
| 9 padding: 0; | 9 padding: 0; |
| 10 } | 10 } |
| 11 | 11 |
| 12 body, html { | 12 body, html { |
| 13 height: 100%; | 13 height: 100%; |
| 14 } | 14 } |
| 15 | 15 |
| 16 a { | 16 a { |
| 17 text-decoration: none; | 17 text-decoration: none; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 | 66 |
| 67 ul { | 67 ul { |
| 68 webkit-margin-after: 25px; | 68 webkit-margin-after: 25px; |
| 69 webkit-margin-before: 0; | 69 webkit-margin-before: 0; |
| 70 } | 70 } |
| 71 | 71 |
| 72 .aligned-to-start { | 72 .aligned-to-start { |
| 73 -webkit-padding-start: 120px; | 73 -webkit-padding-start: 120px; |
| 74 } | 74 } |
| 75 | 75 |
| 76 .float-start { | 76 .float-start { |
|
Evan Stade
2011/10/11 21:35:23
css classes should line up with the logical use of
| |
| 77 float: left; | 77 float: left; |
| 78 } | 78 } |
| 79 | 79 |
| 80 html[dir='rtl'] .float-start { | 80 html[dir='rtl'] .float-start { |
| 81 float-right; | 81 float-right; |
| 82 } | 82 } |
| 83 | 83 |
| 84 .float-stop { | 84 .float-stop { |
| 85 clear: both; | 85 clear: both; |
| 86 } | 86 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 | 178 |
| 179 #warning-icon{ | 179 #warning-icon{ |
| 180 width:25px; | 180 width:25px; |
| 181 height:26px; | 181 height:26px; |
| 182 -webkit-margin-end: 10px; | 182 -webkit-margin-end: 10px; |
| 183 display: none; | 183 display: none; |
| 184 } | 184 } |
| 185 | 185 |
| 186 #main-content.warning #warning-icon, #main-content.error #warning-icon { | 186 #main-content.warning #warning-icon, #main-content.error #warning-icon { |
| 187 background:url('shared/images/icon_warning.png'); | 187 background:url('shared/images/icon_warning.png'); |
| 188 background-repeat:no-repeat; | 188 background-repeat:no-repeat; |
| 189 display: block; | 189 display: block; |
| 190 } | 190 } |
| 191 | 191 |
| 192 #main-content.success #warning-icon { | 192 #main-content.success #warning-icon { |
| 193 background:url('shared/images/icon_checkmark.png'); | 193 background:url('shared/images/icon_checkmark.png'); |
| 194 background-repeat:no-repeat; | 194 background-repeat:no-repeat; |
| 195 display: block; | 195 display: block; |
| 196 } | 196 } |
| 197 | 197 |
| 198 #warning-div { | 198 #warning-div { |
| 199 display:block; | 199 display:block; |
| 200 } | 200 } |
| 201 | 201 |
| 202 #main-content.progress #warning-div { | 202 #main-content.progress #warning-div { |
| 203 display: none; | 203 display: none; |
| 204 } | 204 } |
| 205 | 205 |
| 206 #warning-text { | 206 #warning-text { |
| 207 max-width: 550px; | 207 max-width: 550px; |
| 208 padding-top: 4px; | 208 padding-top: 4px; |
| 209 } | 209 } |
| 210 | 210 |
| 211 #main-content.success #warning-button, | 211 #main-content.success #warning-button, |
| 212 #main-content.warning-no-conf #warning-button, | 212 #main-content.warning-no-conf #warning-button, |
| 213 #main-content.device-detected-none #warning-button { | 213 #main-content.device-detected-none #warning-button { |
| 214 display: none; | 214 display: none; |
| 215 } | 215 } |
| 216 | 216 |
| 217 #main-content.error #warning-button { | 217 #main-content.error #warning-button { |
| 218 clear: both; | 218 clear: both; |
| 219 } | 219 } |
| 220 | |
| 221 </style> | 220 </style> |
| 222 <script src="shared/js/util.js"></script> | 221 <script src="chrome://resources/js/util.js"></script> |
| 223 <script src="shared/js/local_strings.js"></script> | 222 <script src="chrome://resources/js/local_strings.js"></script> |
| 224 <script> | 223 <script src="chrome://imageburner/strings.js"></script> |
| 225 | 224 <script src="chrome://imageburner/image_burner.js"></script> |
| 226 var localStrings; | |
| 227 var browserBridge; | |
| 228 | |
| 229 // Class that keeps track of current burn process state. | |
| 230 function State(strings) { | |
| 231 this.setStrings(strings); | |
| 232 this.changeState(State.StatesEnum.DEVICE_NONE); | |
| 233 } | |
| 234 | |
| 235 State.StatesEnum = { | |
| 236 DEVICE_NONE : { | |
| 237 cssState : "device-detected-none", | |
| 238 }, | |
| 239 DEVICE_USB : { | |
| 240 cssState : "device-detected-usb warning", | |
| 241 }, | |
| 242 DEVICE_SD : { | |
| 243 cssState : "device-detected-sd warning", | |
| 244 }, | |
| 245 DEVICE_MUL : { | |
| 246 cssState: "device-detected-mul warning", | |
| 247 }, | |
| 248 ERROR_NO_NETWORK : { | |
| 249 cssState : "warning-no-conf", | |
| 250 }, | |
| 251 ERROR_DEVICE_TOO_SMALL : { | |
| 252 cssState : "warning-no-conf", | |
| 253 }, | |
| 254 PROGRESS_DOWNLOAD : { | |
| 255 cssState : "progress progress-canceble", | |
| 256 }, | |
| 257 PROGRESS_UNZIP : { | |
| 258 cssState : "progress progress-canceble", | |
| 259 }, | |
| 260 PROGRESS_BURN : { | |
| 261 cssState : "progress", | |
| 262 }, | |
| 263 FAIL : { | |
| 264 cssState : "error", | |
| 265 }, | |
| 266 SUCCESS : { | |
| 267 cssState : "success", | |
| 268 }, | |
| 269 }; | |
| 270 | |
| 271 State.prototype = { | |
| 272 setStrings: function(strings) { | |
| 273 State.StatesEnum.DEVICE_NONE.statusText = | |
| 274 strings.getString('statusDevicesNone'); | |
| 275 State.StatesEnum.DEVICE_NONE.warningText = | |
| 276 strings.getString('warningDevicesNone'); | |
| 277 State.StatesEnum.DEVICE_USB.statusText = | |
| 278 strings.getString('statusDeviceUSB'); | |
| 279 State.StatesEnum.DEVICE_SD.statusText = strings.getString('statusDeviceSD'); | |
| 280 State.StatesEnum.DEVICE_MUL.statusText = | |
| 281 strings.getString('statusDevicesMultiple'); | |
| 282 State.StatesEnum.ERROR_NO_NETWORK.statusText = | |
| 283 strings.getString('statusNoConnection'); | |
| 284 State.StatesEnum.ERROR_NO_NETWORK.warningText = | |
| 285 strings.getString('warningNoConnection'); | |
| 286 State.StatesEnum.ERROR_DEVICE_TOO_SMALL.statusText = | |
| 287 strings.getString('statusNoSpace'); | |
| 288 State.StatesEnum.PROGRESS_DOWNLOAD.statusText = | |
| 289 strings.getString('statusDownloading'); | |
| 290 State.StatesEnum.PROGRESS_UNZIP.statusText = | |
| 291 strings.getString('statusUnzip'); | |
| 292 State.StatesEnum.PROGRESS_BURN.statusText = strings.getString('statusBurn'); | |
| 293 State.StatesEnum.FAIL.statusText = strings.getString('statusError'); | |
| 294 State.StatesEnum.SUCCESS.statusText = strings.getString('statusSuccess'); | |
| 295 State.StatesEnum.SUCCESS.warningText = strings.getString('warningSuccess'); | |
| 296 }, | |
| 297 | |
| 298 changeState: function(newState) { | |
| 299 if (newState == this.state) | |
| 300 return; | |
| 301 this.state = newState; | |
| 302 | |
| 303 $('main-content').className = this.state.cssState; | |
| 304 | |
| 305 $('status-text').textContent = this.state.statusText; | |
| 306 | |
| 307 if (newState.warningText) { | |
| 308 $('warning-text').textContent = this.state.warningText; | |
| 309 } | |
| 310 | |
| 311 if (this.isInitialState() && this.state != State.StatesEnum.DEVICE_NONE) { | |
| 312 $('warning-button').textContent = localStrings.getString('confirmButton'); | |
| 313 } else if (this.state == State.StatesEnum.FAIL) { | |
| 314 $('warning-button').textContent = | |
| 315 localStrings.getString('retryButton'); | |
| 316 } | |
| 317 }, | |
| 318 | |
| 319 gotoInitialState: function(deviceCount) { | |
| 320 if (deviceCount == 0) { | |
| 321 this.changeState(State.StatesEnum.DEVICE_NONE); | |
| 322 } else if (deviceCount == 1) { | |
| 323 this.changeState(State.StatesEnum.DEVICE_USB); | |
| 324 } else { | |
| 325 this.changeState(State.StatesEnum.DEVICE_MUL); | |
| 326 } | |
| 327 }, | |
| 328 | |
| 329 isInitialState: function() { | |
| 330 return (this.state == State.StatesEnum.DEVICE_NONE || | |
| 331 this.state == State.StatesEnum.DEVICE_USB || | |
| 332 this.state == State.StatesEnum.DEVICE_SD || | |
| 333 this.state == State.StatesEnum.DEVICE_MUL); | |
| 334 }, | |
| 335 | |
| 336 equals: function(stateName) { | |
| 337 return this.state == stateName; | |
| 338 } | |
| 339 }; | |
| 340 | |
| 341 // Class that keeps track of available devices. | |
| 342 function DeviceSelection() { | |
| 343 this.deviceCount = 0; | |
| 344 }; | |
| 345 | |
| 346 DeviceSelection.prototype = { | |
| 347 clearSelectList: function(list) { | |
| 348 list.innerHtml = ''; | |
| 349 }, | |
| 350 | |
| 351 showDeviceSelection: function() { | |
| 352 if (this.deviceCount == 0) { | |
| 353 this.selectedDevice = undefined; | |
| 354 } else { | |
| 355 var devices = document.getElementsByClassName('selection-element'); | |
| 356 this.selectDevice(devices[0].devicePath); | |
| 357 } | |
| 358 return this.deviceCount; | |
| 359 }, | |
| 360 | |
| 361 onDeviceSelected: function(label, filePath, devicePath) { | |
| 362 $('warning-button').onclick = | |
| 363 browserBridge.sendBurnImageMessage.bind(browserBridge, filePath, | |
| 364 devicePath); | |
| 365 | |
| 366 this.selectedDevice = devicePath; | |
| 367 | |
| 368 $('warning-text').textContent = | |
| 369 localStrings.getStringF('warningDevices', label); | |
| 370 }, | |
| 371 | |
| 372 selectDevice: function(path) { | |
| 373 var element = $('radio ' + path); | |
| 374 element.checked = true; | |
| 375 element.onclick.apply(element); | |
| 376 }, | |
| 377 | |
| 378 createNewDeviceElement: function(device) { | |
| 379 var element = document.createElement('li'); | |
| 380 var radioButton = document.createElement('input'); | |
| 381 radioButton.type = 'radio'; | |
| 382 radioButton.name = 'device'; | |
| 383 radioButton.value = device.label; | |
| 384 radioButton.id = 'radio ' + device.devicePath; | |
| 385 radioButton.className = 'float-start'; | |
| 386 var deviceLabelText = document.createElement('p'); | |
| 387 deviceLabelText.textContent = device.label; | |
| 388 deviceLabelText.className = 'select-option float-start'; | |
| 389 var newLine = document.createElement('div'); | |
| 390 newLine.className = 'new-line'; | |
| 391 element.appendChild(radioButton); | |
| 392 element.appendChild(deviceLabelText); | |
| 393 element.appendChild(newLine); | |
| 394 element.id = 'select ' + device.devicePath; | |
| 395 element.devicePath = device.devicePath; | |
| 396 element.className = 'selection-element'; | |
| 397 radioButton.onclick = this.onDeviceSelected.bind(this, | |
| 398 device.label, device.filePath, device.devicePath); | |
| 399 return element; | |
| 400 }, | |
| 401 | |
| 402 getDevicesCallback: function(devices) { | |
| 403 var selectListDOM = $('device-selection'); | |
| 404 this.clearSelectList(selectListDOM); | |
| 405 this.deviceCount = devices.length; | |
| 406 if (devices.length > 0) { | |
| 407 for (var i = 0; i < devices.length; i++) { | |
| 408 var element = this.createNewDeviceElement(devices[i]); | |
| 409 selectListDOM.appendChild(element); | |
| 410 } | |
| 411 this.selectDevice(devices[0].devicePath); | |
| 412 } else { | |
| 413 this.selectedDevice = undefined; | |
| 414 } | |
| 415 return this.deviceCount; | |
| 416 }, | |
| 417 | |
| 418 deviceAdded: function(device, allowSelect) { | |
| 419 var selectListDOM = $('device-selection'); | |
| 420 selectListDOM.appendChild(this.createNewDeviceElement(device)); | |
| 421 this.deviceCount++; | |
| 422 if (allowSelect && this.deviceCount == 1) | |
| 423 this.selectDevice(device.devicePath); | |
| 424 return this.deviceCount; | |
| 425 }, | |
| 426 | |
| 427 deviceRemoved: function(devicePath, allowSelect) { | |
| 428 var deviceSelectElement = $('select ' + devicePath); | |
| 429 deviceSelectElement.parentNode.removeChild(deviceSelectElement); | |
| 430 this.deviceCount--; | |
| 431 var devices = document.getElementsByClassName('selection-element'); | |
| 432 | |
| 433 if (allowSelect) { | |
| 434 if (devices.length > 0) { | |
| 435 if (this.selectedDevice == devicePath) | |
| 436 this.selectDevice(devices[0].devicePath); | |
| 437 } else { | |
| 438 this.selectedDevice = undefined; | |
| 439 } | |
| 440 } | |
| 441 return this.deviceCount; | |
| 442 } | |
| 443 }; | |
| 444 | |
| 445 // Class that handles communication with chrome. | |
| 446 function BrowserBridge() { | |
| 447 this.currentState = new State(localStrings); | |
| 448 this.devices = new DeviceSelection(); | |
| 449 // We will use these often so it makes sence making them class members to | |
| 450 // avoid frequent document.getElementById calls. | |
| 451 this.progressElement = $('progress-div'); | |
| 452 this.progressText = $('progress-text'); | |
| 453 this.progressTimeLeftText = $('pending-time'); | |
| 454 }; | |
| 455 | |
| 456 BrowserBridge.prototype = { | |
| 457 sendCancelMessage: function() { | |
| 458 chrome.send("cancelBurnImage"); | |
| 459 }, | |
| 460 | |
| 461 sendGetDevicesMessage: function() { | |
| 462 chrome.send("getDevices"); | |
| 463 }, | |
| 464 | |
| 465 sendWebuiInitializedMessage: function() { | |
| 466 chrome.send("webuiInitialized"); | |
| 467 }, | |
| 468 | |
| 469 sendBurnImageMessage: function(filePath, devicePath) { | |
| 470 chrome.send('burnImage', [devicePath, filePath]); | |
| 471 }, | |
| 472 | |
| 473 reportSuccess: function() { | |
| 474 this.currentState.changeState(State.StatesEnum.SUCCESS); | |
| 475 }, | |
| 476 | |
| 477 reportFail: function(errorMessage) { | |
| 478 this.currentState.changeState(State.StatesEnum.FAIL); | |
| 479 $('warning-text').textContent = errorMessage; | |
| 480 $('warning-button').onclick = this.onBurnRetry.bind(this); | |
| 481 }, | |
| 482 | |
| 483 deviceAdded: function(device) { | |
| 484 var inInitialState = this.currentState.isInitialState(); | |
| 485 var deviceCount = this.devices.deviceAdded(device, inInitialState); | |
| 486 if (inInitialState) | |
| 487 this.currentState.gotoInitialState(deviceCount); | |
| 488 }, | |
| 489 | |
| 490 deviceRemoved: function(device) { | |
| 491 var inInitialState = this.currentState.isInitialState(); | |
| 492 var deviceCount = this.devices.deviceRemoved(device, inInitialState); | |
| 493 if (inInitialState) | |
| 494 this.currentState.gotoInitialState(deviceCount); | |
| 495 }, | |
| 496 | |
| 497 getDevicesCallback: function(devices) { | |
| 498 var deviceCount = this.devices.getDevicesCallback(devices); | |
| 499 this.currentState.gotoInitialState(deviceCount); | |
| 500 this.sendWebuiInitializedMessage(); | |
| 501 }, | |
| 502 | |
| 503 updateProgress: function(update_signal) { | |
| 504 if (update_signal.progressType == 'download' && | |
| 505 !this.currentState.equals(State.StatesEnum.PROGRESS_DOWNLOAD)) { | |
| 506 this.currentState.changeState(State.StatesEnum.PROGRESS_DOWNLOAD); | |
| 507 } else if (update_signal.progressType == 'unzip' && | |
| 508 !this.currentState.equals(State.StatesEnum.PROGRESS_UNZIP)) { | |
| 509 this.currentState.changeState(State.StatesEnum.PROGRESS_UNZIP); | |
| 510 } else if (update_signal.progressType == 'burn' && | |
| 511 !this.currentState.equals(State.StatesEnum.PROGRESS_BURN)) { | |
| 512 this.currentState.changeState(State.StatesEnum.PROGRESS_BURN); | |
| 513 } | |
| 514 | |
| 515 if (!(update_signal.amountTotal > 0)) { | |
| 516 this.progressElement.removeAttribute('value'); | |
| 517 } else { | |
| 518 this.progressElement.value = update_signal.amountFinished; | |
| 519 this.progressElement.max = update_signal.amountTotal; | |
| 520 } | |
| 521 | |
| 522 this.progressText.textContent = update_signal.progressText; | |
| 523 this.progressTimeLeftText.textContent = update_signal.timeLeftText; | |
| 524 }, | |
| 525 | |
| 526 reportNoNetwork: function() { | |
| 527 this.currentState.changeState(State.StatesEnum.ERROR_NO_NETWORK); | |
| 528 }, | |
| 529 | |
| 530 reportNetworkDetected: function() { | |
| 531 if (this.currentState.equals(State.StatesEnum.ERROR_NO_NETWORK)) { | |
| 532 var deviceCount = this.devices.showDeviceSelection(); | |
| 533 this.currentState.gotoInitialState(deviceCount); | |
| 534 } | |
| 535 }, | |
| 536 | |
| 537 reportDeviceTooSmall: function(device_size) { | |
| 538 this.currentState.changeState(State.StatesEnum.ERROR_DEVICE_TOO_SMALL); | |
| 539 $('warning-text').textContent = | |
| 540 localStrings.getStringF('warningNoSpace', device_size); | |
| 541 }, | |
| 542 | |
| 543 // Processes click on "Retry" button in FAIL state. | |
| 544 onBurnRetry: function () { | |
| 545 var deviceCount = this.devices.showDeviceSelection(); | |
| 546 this.currentState.gotoInitialState(deviceCount); | |
| 547 } | |
| 548 }; | |
| 549 | |
| 550 document.addEventListener('DOMContentLoaded', function() { | |
| 551 localStrings = new LocalStrings(); | |
| 552 browserBridge = new BrowserBridge(); | |
| 553 | |
| 554 $('cancel-button').onclick = | |
| 555 browserBridge.sendCancelMessage.bind(browserBridge); | |
| 556 browserBridge.sendGetDevicesMessage(); | |
| 557 }); | |
| 558 </script> | |
| 559 </head> | 225 </head> |
| 560 <body class="default-text"> | 226 <body class="default-text"> |
| 561 <header id="burn-header"> | 227 <header id="burn-header"> |
| 562 <h1 i18n-content="headerTitle"></h1> | 228 <h1 i18n-content="headerTitle"></h1> |
| 563 <p i18n-content="headerDescription"></p> | 229 <p i18n-content="headerDescription"></p> |
| 564 <a id="more-info-link" jsvalues="href:moreInfoLink" | 230 <a id="more-info-link" jsvalues="href:moreInfoLink" |
| 565 i18n-content="headerLink"></a> | 231 i18n-content="headerLink"></a> |
| 566 </header> | 232 </header> |
| 567 <div id="main-content"> | 233 <div id="main-content"> |
| 568 <div id="status-icon"></div> | 234 <div id="status-icon"></div> |
| 569 <div id="status-info"> | 235 <div id="status-info"> |
| 570 <h2 id="status-text" class="status-text"></h2> | 236 <h2 id="status-text" class="status-text"></h2> |
| 571 <div id="progress-status-div"> | 237 <div id="progress-status-div"> |
| 572 <p id="progress-text" class="progress-text"></p> | 238 <p id="progress-text" class="progress-text"></p> |
| 573 <div id="progress-status" class="float-start"> | 239 <div id="progress-status" class="float-start"> |
| 574 <progress id="progress-div" class="float-start"></progress> | 240 <progress id="progress-div" class="float-start"></progress> |
| 575 <button id="cancel-button" class="float-start" | 241 <button id="cancel-button" class="float-start" |
| 576 i18n-content="cancelButton"> | 242 i18n-content="cancelButton"> |
| 577 </button> | 243 </button> |
| 578 </div> | 244 </div> |
| 579 <p id="pending-time" class="progress-text"></p> | 245 <p id="pending-time" class="progress-text"></p> |
| 580 </div> | 246 </div> |
| 581 <ul id="device-selection"></ul> | 247 <ul id="device-selection"></ul> |
| 582 <div id="warning-div"> | 248 <div id="warning-div"> |
| 583 <div id="warning-icon" class="float-start"></div> | 249 <div id="warning-icon" class="float-start"></div> |
| 584 <p id="warning-text" class="float-start"></p> | 250 <p id="warning-text" class="float-start"></p> |
| 585 <button id="warning-button" class="float-start"></button> | 251 <button id="warning-button" class="float-start"></button> |
| 586 </div> | 252 </div> |
| 587 <div class="new-line"></div> | 253 <div class="new-line"></div> |
| 588 </div> | 254 </div> |
| 589 <div id="burn-footer"></div> | 255 <div id="burn-footer"></div> |
| 590 </div> | 256 </div> |
| 257 <script src="chrome://resources/js/i18n_template.js"></script> | |
| 258 <script src="chrome://resources/js/i18n_process.js"></script> | |
| 259 <script src="chrome://resources/js/jstemplate_compiled.js"></script> | |
| 591 </body> | 260 </body> |
| 592 </html> | 261 </html> |
| OLD | NEW |