34 Components.utils.import(
"resource://app/jsmodules/DOMUtils.jsm");
35 Components.utils.import(
"resource://app/jsmodules/SBDataRemoteUtils.jsm");
36 Components.utils.import(
"resource://app/jsmodules/SBUtils.jsm");
38 if (typeof(
Cc) ==
"undefined")
39 var
Cc = Components.classes;
40 if (typeof(
Ci) ==
"undefined")
41 var
Ci = Components.interfaces;
42 if (typeof(
Cr) ==
"undefined")
43 var
Cr = Components.results;
44 if (typeof(
Cu) ==
"undefined")
45 var
Cu = Components.utils;
49 _deviceProperties:
null,
51 _isDefaultDevice:
false,
53 _wizardMode:
"update",
56 _currentOperation:
null,
57 _firmwareUpdate:
null,
59 _waitingForDeviceReconnect:
false,
62 _repairDescriptionNode:
null,
63 _activeDataRemote:
"firmware.wizard.active",
66 if (!this._wizardElem)
67 this._wizardElem = document.getElementById(
"device_firmware_wizard");
68 return this._wizardElem;
71 doLoad:
function deviceFirmwareWizard_doLoad() {
76 doUnload:
function deviceFirmwareWizard_doUnload() {
80 doFinish:
function deviceFirmwareWizard_doFinish() {
82 if(this._currentOperation ==
"busy") {
84 setTimeout(
function() {
self.wizardElem.goTo(
"device_firmware_wizard_download_page"); }, 0);
96 doCancel:
function deviceFirmwareWizard_doCancel() {
99 if(this._currentOperation ==
"install") {
104 if(this._currentOperation !=
"complete") {
114 doClose:
function deviceFirmwareWizard_doClose() {
118 doPageShow:
function deviceFirmwareWizard_doPageShow() {
119 if(!this._initialized)
122 var currentPage = this.wizardElem.currentPage;
125 switch(currentPage.id) {
126 case "device_firmware_check": {
129 this._currentOperation =
"checkforupdate";
130 if(this._isDefaultDevice) {
132 this._defaultDeviceVID,
133 this._defaultDevicePID,
142 case "device_firwmare_check_error": {
143 this._currentOperation =
"checkforupdate_error";
145 let okButton = this.wizardElem.getButton(
"next");
146 okButton.label =
SBString(
"window.ok.label");
147 okButton.accessKey =
SBString(
"window.ok.accessKey");
150 document.getElementById(
"device_firmware_check_error_link");
153 let supportLinkValue = handler.customerSupportLocation.spec;
154 supportLink.value = supportLinkValue;
155 supportLink.href = supportLinkValue;
159 case "device_needs_recovery_mode": {
160 this._currentOperation =
"needsrecoverymode";
163 cancelButton.disabled =
false;
166 Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
167 .getService(Ci.sbIDeviceManager2);
169 deviceManager.addEventListener(
this);
173 if(this._isDefaultDevice) {
178 this._defaultDeviceVID,
179 this._defaultDevicePID);
180 handler.initiateRecoveryModeSwitch(this._defaultDeviceVID,
181 this._defaultDevicePID);
182 let recoveryInstructions =
184 [this._defaultDeviceName,
185 this._defaultDeviceKey,
186 this._defaultDeviceKey]);
189 recoveryInstructions =
"<html><body><p style=\"font-family: sans-serif; font-size: 12px\">" +
190 recoveryInstructions +
191 "</p></body></html>";
193 let
browser = document.getElementById(
"device_firmware_wizard_recovery_mode_browser");
194 let dataURI =
"data:text/html;charset=UTF-8," + recoveryInstructions;
195 browser.setAttribute(
"src", dataURI);
197 let
label = document.getElementById(
"device_firmware_wizard_recovery_mode_label");
198 label.value =
SBFormattedString(
"device.firmware.wizard.recovery_mode.connected",
199 [this._defaultDeviceName]);
208 if(e.result == Cr.NS_ERROR_NOT_AVAILABLE &&
209 this._wizardMode ==
"repair") {
211 device:
self._device,
212 onDeviceEvent:
function(aEvent) {
217 if(aEvent.type == Ci.sbIDeviceEvent.EVENT_FIRMWARE_CFU_END ||
218 aEvent.type == Ci.sbIDeviceEvent.EVENT_FIRMWARE_CFU_ERROR) {
219 let handler =
self._deviceFirmwareUpdater.getActiveHandler(this.device);
222 handler.initiateRecoveryModeSwitch();
224 let
label = document.getElementById(
"device_firmware_wizard_recovery_mode_label");
225 label.value =
SBFormattedString(
"device.firmware.wizard.recovery_mode.connected",
226 [
self._deviceProperties.modelNumber]);
228 if(handler.recoveryModeKeyCombination) {
229 let recoveryInstructions =
231 [
self._deviceProperties.modelNumber,
232 handler.recoveryModeKeyCombination,
233 handler.recoveryModeKeyCombination]);
236 recoveryInstructions =
"<html><body><p style=\"font-family: sans-serif; font-size: 12px\">" +
237 recoveryInstructions +
238 "</p></body></html>";
240 let
browser = document.getElementById(
"device_firmware_wizard_recovery_mode_browser");
241 let dataURI =
"data:text/html;charset=UTF-8," + recoveryInstructions;
242 browser.setAttribute(
"src", dataURI);
244 else if(handler.resetInstructionsLocation) {
245 let
browser = document.getElementById(
"device_firmware_wizard_recovery_mode_browser");
246 browser.setAttribute(
"src", handler.resetInstructionsLocation.spec);
262 handler.initiateRecoveryModeSwitch();
264 let
label = document.getElementById(
"device_firmware_wizard_recovery_mode_label");
265 label.value =
SBFormattedString(
"device.firmware.wizard.recovery_mode.connected",
266 [this._deviceProperties.modelNumber]);
268 if(handler.recoveryModeKeyCombination) {
269 let recoveryInstructions =
271 [this._deviceProperties.modelNumber,
272 handler.recoveryModeKeyCombination,
273 handler.recoveryModeKeyCombination]);
276 recoveryInstructions =
"<html><body><p style=\"font-family: sans-serif; font-size: 12px\">" +
277 recoveryInstructions +
278 "</p></body></html>";
280 let
browser = document.getElementById(
"device_firmware_wizard_recovery_mode_browser");
281 let dataURI =
"data:text/html;charset=UTF-8," + recoveryInstructions;
282 browser.setAttribute(
"src", dataURI);
284 else if(handler.resetInstructionsLocation) {
285 let
browser = document.getElementById(
"device_firmware_wizard_recovery_mode_browser");
286 browser.setAttribute(
"src", handler.resetInstructionsLocation.spec);
291 case "device_firmware_download": {
292 if(this._device.isBusy) {
293 this._currentOperation =
"busy";
295 self.wizardElem.goTo(
"device_firmware_busy_device_page");
300 document.getElementById(
"device_firmware_download_no_disconnect_desc");
302 document.createTextNode(
SBString(
"device.firmware.wizard.no_disconnect_warn"));
304 if(descElem.firstChild &&
305 descElem.firstChild.nodeType == Ci.nsIDOMNode.TEXT_NODE) {
306 descElem.removeChild(descElem.firstChild);
309 descElem.appendChild(descTextNode);
311 this._currentOperation =
"download";
317 case "device_firmware_download_error": {
318 this._currentOperation =
"download_error";
320 let okButton = this.wizardElem.getButton(
"next");
321 okButton.label =
SBString(
"window.ok.label");
322 okButton.accessKey =
SBString(
"window.ok.accessKey");
325 document.getElementById(
"device_firmware_download_error_link");
328 let supportLinkValue = handler.customerSupportLocation.spec;
329 supportLink.value = supportLinkValue;
330 supportLink.href = supportLinkValue;
334 case "device_firmware_repair": {
335 this._currentOperation =
"confirmrepair";
337 let restoreButton = this.wizardElem.getButton(
"next");
338 restoreButton.label =
SBString(
"device.firmware.repair.button");
339 restoreButton.accessKey =
null;
341 let descElem = document.getElementById(
"device_firmware_repair_description");
342 if(this._repairDescriptionNode) {
343 descElem.removeChild(this._repairDescriptionNode);
344 this._repairDescriptionNode =
null;
347 let deviceName = this._isDefaultDevice ?
348 this._defaultDeviceName : this._deviceProperties.friendlyName;
351 this._repairDescriptionNode = document.createTextNode(descString);
352 descElem.appendChild(this._repairDescriptionNode);
356 case "device_firmware_install": {
357 this._currentOperation =
"install";
360 cancelButton.disabled =
true;
362 let descElem = document.getElementById(
"device_firmware_install_no_disconnect_desc");
363 if(descElem.firstChild &&
364 descElem.firstChild.nodeType == Ci.nsIDOMNode.TEXT_NODE) {
365 descElem.removeChild(descElem.firstChild);
368 if(this._wizardMode ==
"repair") {
369 let
label = document.getElementById(
"device_firmware_wizard_install_title");
370 label.value =
SBString(
"device.firmware.repair.inprocess");
373 document.createTextNode(
SBString(
"device.firmware.repair.no_disconnect_warning"));
374 descElem.appendChild(textNode);
377 if(this._isDefaultDevice) {
379 this._firmwareUpdate,
380 this._defaultDeviceVID,
381 this._defaultDevicePID,
386 this._firmwareUpdate,
393 this.wizardElem.goTo(
"device_firmware_install_error_page");
398 document.createTextNode(
SBString(
"device.firmware.wizard.no_disconnect_warn"));
399 descElem.appendChild(textNode);
405 self._deviceFirmwareUpdater.applyUpdate(
self._device,
self._firmwareUpdate,
self);
411 case "device_firmware_install_error": {
412 this._currentOperation =
"install_error";
414 let okButton = this.wizardElem.getButton(
"next");
415 okButton.label =
SBString(
"window.ok.label");
416 okButton.accessKey =
SBString(
"window.ok.accessKey");
419 document.getElementById(
"device_firmware_install_error_link");
422 let supportLinkValue =
null;
425 supportLinkValue = handler.customerSupportLocation.spec;
428 supportLink.value = supportLinkValue;
429 supportLink.href = supportLinkValue;
432 document.getElementById(
"device_firmware_install_error_description");
434 if(descElem.firstChild &&
435 descElem.firstChild.nodeType == Ci.nsIDOMNode.TEXT_NODE) {
436 descElem.removeChild(descElem.firstChild);
440 if(this._wizardMode ==
"repair") {
441 text =
SBString(
"device.firmware.repair.error.description");
444 text =
SBString(
"device.firmware.wizard.install.error.desc");
446 descElem.appendChild(document.createTextNode(text));
450 case "device_firmware_update_complete": {
451 this._currentOperation =
"complete";
454 document.getElementById(
"device_firmware_update_complete_description");
457 if(this._wizardMode ==
"repair") {
458 descStr =
SBString(
"device.firmware.repair.complete.desc");
464 descStr =
SBString(
"device.firmware.wizard.complete.desc");
467 let descTextNode = document.createTextNode(descStr);
468 desc.appendChild(descTextNode);
472 case "device_firmware_busy_device": {
473 let retryButton = this.wizardElem.getButton(
"next");
475 SBString(
"device.firmware.wizard.retry.button");
476 retryButton.accessKey =
null;
481 throw new Error(
"not reached");
485 doBack:
function deviceFirmwareWizard_onBack(aEvent) {
494 doNext:
function deviceFirmwareWizard_onNext(aEvent) {
495 if(this._currentOperation) {
496 let isError = this._currentOperation.substring(-5, 5) ==
"error";
497 if(isError || this._currentOperation ==
"uptodate") {
505 }
catch(e) { Cu.reportError(e); }
511 else if(this._currentOperation ==
"checkforupdate") {
518 if(handler.needsRecoveryMode) {
519 this._currentOperation =
"needsrecoverymode";
523 self.wizardElem.goTo(
"device_needs_recovery_mode_page");
528 else if(this._currentOperation ==
"confirmrepair") {
531 self.wizardElem.goTo(
"device_firmware_wizard_download_page");
540 doExtra1:
function deviceFirmwareWizard_onExtra1(aEvent) {
544 doExtra2:
function deviceFirmwareWizard_onExtra2(aEvent) {
548 onDeviceEvent:
function deviceFirmwareWizard_onDeviceEvent(aEvent) {
549 this._handleDeviceEvent(aEvent);
552 update:
function deviceFirmwareWizard_update() {
555 _initialize:
function deviceFirmwareWizard__initialize() {
556 if (this._initialized)
560 window.arguments[0].QueryInterface(Ci.nsIDialogParamBlock);
563 var wizardMode = dialogPB.GetString(0).split(
"=");
564 this._wizardMode = wizardMode[1];
566 this._wizardMode =
"update";
570 var defaultDevice = dialogPB.GetString(1).split(
"=");
571 this._isDefaultDevice = (defaultDevice[1] ==
"true");
574 this._isDefaultDevice =
false;
577 if(!this._isDefaultDevice) {
578 this._device = dialogPB.objects.queryElementAt(0, Ci.sbIDevice);
581 this._defaultDeviceName = dialogPB.GetString(2);
582 this._defaultDeviceKey = dialogPB.GetString(3);
584 var deviceVIDPID = dialogPB.GetString(4).split(
"-");
585 this._defaultDeviceVID = deviceVIDPID[0];
586 this._defaultDevicePID = deviceVIDPID[1];
589 if(!this._isDefaultDevice) {
590 this._deviceProperties = this._device.properties;
594 Cc[
"@songbirdnest.com/Songbird/Device/Firmware/Updater;1"]
595 .getService(Ci.sbIDeviceFirmwareUpdater);
597 this._wizardElem = document.getElementById(
"device_firmware_wizard");
600 var browserBox = document.getElementById(
"device_firmware_wizard_release_notes_box");
601 this._domEventListenerSet.add(browserBox,
"collapse", this._handleBrowserCollapse,
true,
false);
603 this._wizardElem.canRewind =
true;
605 this._initialized =
true;
614 if(this._wizardMode ==
"repair" && this._isDefaultDevice) {
617 this._wizardElem.title =
SBString(
"device.firmware.repair.title");
618 return this._wizardElem.goTo(
"device_needs_recovery_mode_page");
622 if(this._wizardMode ==
"repair") {
623 this._wizardElem.title =
SBString(
"device.firmware.repair.title");
625 handler.bind(this._device,
null);
626 let recoveryMode = handler.recoveryMode;
633 self._wizardElem.goTo(
"device_firmware_wizard_check_page");
639 self._wizardElem.goTo(
"device_needs_recovery_mode_page");
645 self._wizardElem.goTo(
"device_firmware_wizard_check_page");
651 _finalize:
function deviceFirmwareWizard__finalize() {
654 let deviceManager = Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
655 .getService(Ci.sbIDeviceManager2);
656 deviceManager.removeEventListener(
this);
661 if (this._domEventListenerSet)
662 this._domEventListenerSet.removeAll();
663 this._domEventListenerSet =
null;
668 _handleBrowserCollapse:
function deviceFirmwareWizard__handleBrowserCollapse(aEvent) {
669 const BROWSER_VISIBLE_INNER_HEIGHT = 360;
671 if(aEvent.detail ==
true) {
672 window.innerHeight = BROWSER_VISIBLE_INNER_HEIGHT;
676 _handleDeviceEvent:
function deviceFirmwareWizard__handleDeviceEvent(aEvent) {
677 switch(this._currentOperation) {
678 case "checkforupdate":
679 this._handleCheckForUpdate(aEvent);
683 this._handleDownloadFirmware(aEvent);
687 this._handleApplyUpdate(aEvent);
690 case "needsrecoverymode":
691 this._handleNeedsRecoveryMode(aEvent);
696 _handleCheckForUpdate:
function deviceFirmwareWizard__handleCheckForUpdate(aEvent) {
697 if(aEvent.type == Ci.sbIDeviceEvent.EVENT_FIRMWARE_CFU_END) {
698 var progressDeck = document.getElementById(
"device_firmware_wizard_check_deck");
699 if(aEvent.data ==
true) {
702 if(this._wizardMode ==
"repair") {
705 self._wizardElem.goTo(
"device_firmware_wizard_repair_page");
711 document.getElementById(
"device_firmware_wizard_check_newver_description");
716 [handler.latestFirmwareReadableVersion]);
718 newVerDesc.appendChild(document.createTextNode(text));
720 var remindMeLaterButton = this.wizardElem.getButton(
"back");
721 var installNewFirmwareButton = this.wizardElem.getButton(
"next");
723 remindMeLaterButton.label =
724 SBString(
"device.firmware.wizard.check.remind_me_later.label");
725 remindMeLaterButton.accessKey =
null;
726 remindMeLaterButton.disabled =
false;
728 installNewFirmwareButton.label =
729 SBString(
"device.firmware.wizard.check.install.label");
730 installNewFirmwareButton.accessKey =
null;
732 this.wizardElem.currentPage.setAttribute(
"showback",
"true");
733 this.wizardElem.currentPage.setAttribute(
"shownext",
"true");
735 var
browser = document.getElementById(
"device_firmware_wizard_release_notes_browser");
737 var releaseNotesLocation =
null;
739 releaseNotesLocation = handler.releaseNotesLocation;
743 var spec = releaseNotesLocation ? releaseNotesLocation.spec :
"about:blank";
744 browser.setAttribute(
"src", spec);
746 progressDeck.selectedPanel =
747 document.getElementById(
"device_firmware_wizard_check_new_box");
750 document.getElementById(
"device_firmware_wizard_release_notes_box");
751 browserBox.open =
true;
755 this._wizardElem.canRewind =
true;
758 let okButton = this.wizardElem.getButton(
"next");
759 okButton.label =
SBString(
"window.ok.label");
760 okButton.accessKey =
SBString(
"window.ok.accessKey");
762 this.wizardElem.currentPage.setAttribute(
"hidecancel",
"true");
763 this.wizardElem.currentPage.setAttribute(
"shownext",
"true");
765 progressDeck.selectedPanel =
766 document.getElementById(
"device_firmware_wizard_check_already_box");
768 this._currentOperation =
"uptodate";
771 else if(aEvent.type == Ci.sbIDeviceEvent.EVENT_FIRMWARE_CFU_ERROR) {
772 this.wizardElem.goTo(
"device_firmware_wizard_check_error_page");
776 _handleDownloadFirmware:
function deviceFirmwareWizard__handleDownloadFirmware(aEvent) {
778 document.getElementById(
"device_firmware_wizard_download_progress");
779 switch(aEvent.type) {
781 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_DOWNLOAD_PROGRESS:
782 progressMeter.value = aEvent.data;
784 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_DOWNLOAD_END:
785 this._firmwareUpdate = aEvent.data.QueryInterface(Ci.sbIDeviceFirmwareUpdate);
786 this.wizardElem.goTo(
"device_firmware_wizard_install_page");
790 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_DOWNLOAD_ERROR:
791 this.wizardElem.goTo(
"device_firmware_wizard_download_error_page");
796 _handleApplyUpdate:
function deviceFirmwareWizard__handleApplyUpdate(aEvent) {
798 document.getElementById(
"device_firmware_wizard_install_progress");
800 switch(aEvent.type) {
802 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_WRITE_START:
803 progressMeter.mode =
"undetermined";
805 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_WRITE_PROGRESS:
806 if(progressMeter.mode !=
"determined") {
807 progressMeter.mode =
"determined";
809 progressMeter.value = aEvent.data;
811 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_WRITE_END:
812 if(progressMeter.mode !=
"determined") {
813 progressMeter.mode =
"determined";
815 progressMeter.value = 100;
817 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_UPDATE_END:
818 this.wizardElem.goTo(
"device_firmware_wizard_complete_page");
824 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_NEEDREC_ERROR:
828 if(handler.needsRecoveryMode) {
829 this._currentOperation =
"needsrecoverymode";
833 self.wizardElem.goTo(
"device_needs_recovery_mode_page");
839 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_WRITE_ERROR:
840 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_UPDATE_ERROR:
841 this.wizardElem.goTo(
"device_firmware_install_error_page");
846 _handleNeedsRecoveryMode:
function deviceFirmwareWizard__handleNeedsRecoveryMode(aEvent) {
847 switch(aEvent.type) {
848 case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED: {
849 if(!this._waitingForDeviceReconnect && !this._isDefaultDevice) {
853 this._device = aEvent.data.QueryInterface(Ci.sbIDevice);
855 let criticalFailure =
false;
856 let continueSuccess =
false;
859 if(!this._isDefaultDevice) {
865 criticalFailure =
true;
871 continueSuccess =
true;
874 if(continueSuccess || criticalFailure) {
875 this._waitingForDeviceReconnect =
false;
878 Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
879 .getService(Ci.sbIDeviceManager2);
881 deviceManager.removeEventListener(
this);
883 if(criticalFailure) {
885 this.wizardElem.goTo(
"device_firmware_install_error_page");
888 if(this._wizardMode ==
"repair") {
890 this.wizardElem.goTo(
"device_firmware_wizard_check_page");
895 this.wizardElem.goTo(
"device_firmware_wizard_download_page");
902 case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED: {
903 this._waitingForDeviceReconnect =
true;
905 let
label = document.getElementById(
"device_firmware_wizard_recovery_mode_label");
906 if(this._isDefaultDevice) {
907 label.value =
SBFormattedString(
"device.firmware.wizard.recovery_mode.disconnected",
908 [this._defaultDeviceName]);
911 label.value =
SBFormattedString(
"device.firmware.wizard.recovery_mode.disconnected",
912 [this._deviceProperties.modelNumber]);
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
function DOMEventListenerSet()
function SBString(aKey, aDefault, aStringBundle)
this _contentSandbox label
function SBDataSetBoolValue(aKey, aBoolValue)
Set a boolean value. Changes the value of the data remote to the boolean passed in, regardless of its value before.
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
sbDeviceFirmwareAutoCheckForUpdate prototype _deviceFirmwareUpdater