deviceFirmwareWizard.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //
5 // BEGIN SONGBIRD GPL
6 //
7 // This file is part of the Songbird web player.
8 //
9 // Copyright(c) 2005-2009 POTI, Inc.
10 // http://songbirdnest.com
11 //
12 // This file may be licensed under the terms of of the
13 // GNU General Public License Version 2 (the "GPL").
14 //
15 // Software distributed under the License is distributed
16 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
17 // express or implied. See the GPL for the specific language
18 // governing rights and limitations.
19 //
20 // You should have received a copy of the GPL along with this
21 // program. If not, go to http://www.gnu.org/licenses/gpl.html
22 // or write to the Free Software Foundation, Inc.,
23 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // END SONGBIRD GPL
26 //
27  */
28 
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");
37 
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;
46 
48  _device: null,
49  _deviceProperties: null,
51  _isDefaultDevice: false,
52  _wizardElem: null,
53  _wizardMode: "update",
54 
55  _currentMode: null,
56  _currentOperation: null,
57  _firmwareUpdate: null,
58 
59  _waitingForDeviceReconnect: false,
60  _initialized: false,
61 
62  _repairDescriptionNode: null,
63  _activeDataRemote: "firmware.wizard.active",
64 
65  get wizardElem() {
66  if (!this._wizardElem)
67  this._wizardElem = document.getElementById("device_firmware_wizard");
68  return this._wizardElem;
69  },
70 
71  doLoad: function deviceFirmwareWizard_doLoad() {
72  this._initialize();
73  },
74 
75 
76  doUnload: function deviceFirmwareWizard_doUnload() {
77  this._finalize();
78  },
79 
80  doFinish: function deviceFirmwareWizard_doFinish() {
81  // Looks like we were actually busy and we need to retry.
82  if(this._currentOperation == "busy") {
83  var self = this;
84  setTimeout(function() { self.wizardElem.goTo("device_firmware_wizard_download_page"); }, 0);
85  return false;
86  }
87 
88  this._deviceFirmwareUpdater.finalizeUpdate(this._device);
89 
90  var self = window;
91  setTimeout(function() { self.close(); }, 0);
92 
93  return true;
94  },
95 
96  doCancel: function deviceFirmwareWizard_doCancel() {
97  // If we are in the process of installing the firmware we have
98  // to disable the cancel operation on the wizard.
99  if(this._currentOperation == "install") {
100  return false;
101  }
102 
103  try {
104  if(this._currentOperation != "complete") {
105  this._deviceFirmwareUpdater.cancel(this._device);
106  }
107  } catch (e) {
108  // Ignore any exceptions thrown so we continue to close the window
109  }
110 
111  return true;
112  },
113 
114  doClose: function deviceFirmwareWizard_doClose() {
115  return this.doCancel();
116  },
117 
118  doPageShow: function deviceFirmwareWizard_doPageShow() {
119  if(!this._initialized)
120  return;
121 
122  var currentPage = this.wizardElem.currentPage;
123  var self = this;
124 
125  switch(currentPage.id) {
126  case "device_firmware_check": {
127  let self = this;
128 
129  this._currentOperation = "checkforupdate";
130  if(this._isDefaultDevice) {
131  this._deviceFirmwareUpdater.checkForUpdate(this._device,
132  this._defaultDeviceVID,
133  this._defaultDevicePID,
134  this);
135  }
136  else {
137  this._deviceFirmwareUpdater.checkForUpdate(this._device, 0, 0, this);
138  }
139  }
140  break;
141 
142  case "device_firwmare_check_error": {
143  this._currentOperation = "checkforupdate_error";
144 
145  let okButton = this.wizardElem.getButton("next");
146  okButton.label = SBString("window.ok.label");
147  okButton.accessKey = SBString("window.ok.accessKey");
148 
149  let supportLink =
150  document.getElementById("device_firmware_check_error_link");
151  let handler = this._deviceFirmwareUpdater.getActiveHandler(this._device);
152 
153  let supportLinkValue = handler.customerSupportLocation.spec;
154  supportLink.value = supportLinkValue;
155  supportLink.href = supportLinkValue;
156  }
157  break;
158 
159  case "device_needs_recovery_mode": {
160  this._currentOperation = "needsrecoverymode";
161 
162  let cancelButton = this.wizardElem.getButton("cancel");
163  cancelButton.disabled = false;
164 
165  let deviceManager =
166  Cc["@songbirdnest.com/Songbird/DeviceManager;2"]
167  .getService(Ci.sbIDeviceManager2);
168 
169  deviceManager.addEventListener(this);
170 
171  // Handle default device
172  let handler = null;
173  if(this._isDefaultDevice) {
174  // Get a firmware handler for the selected device and hint it to
175  // expect a recovery mode connection
176  handler = this._deviceFirmwareUpdater.getHandler(
177  null,
178  this._defaultDeviceVID,
179  this._defaultDevicePID);
180  handler.initiateRecoveryModeSwitch(this._defaultDeviceVID,
181  this._defaultDevicePID);
182  let recoveryInstructions =
183  SBFormattedString("device.firmware.wizard.recovery_mode.instructions",
184  [this._defaultDeviceName,
185  this._defaultDeviceKey,
186  this._defaultDeviceKey]);
187 
188  // Hack up the style so that it doesn't look so damn ugly.
189  recoveryInstructions = "<html><body><p style=\"font-family: sans-serif; font-size: 12px\">" +
190  recoveryInstructions +
191  "</p></body></html>";
192 
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);
196 
197  let label = document.getElementById("device_firmware_wizard_recovery_mode_label");
198  label.value = SBFormattedString("device.firmware.wizard.recovery_mode.connected",
199  [this._defaultDeviceName]);
200  return;
201  }
202 
203  // Not default device, proceed as normal.
204  try {
205  handler = this._deviceFirmwareUpdater.getActiveHandler(this._device);
206  }
207  catch(e) {
208  if(e.result == Cr.NS_ERROR_NOT_AVAILABLE &&
209  this._wizardMode == "repair") {
210  let listener = {
211  device: self._device,
212  onDeviceEvent: function(aEvent) {
213  // Even if there's an error we should have the information
214  // necessary to continue. All firmware handlers are required
215  // to provide a basic set of reset instructions and a basic
216  // firmware for recovery.
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);
220 
221  // Hint the handler to expect a recovery mode connection
222  handler.initiateRecoveryModeSwitch();
223 
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]);
227 
228  if(handler.recoveryModeKeyCombination) {
229  let recoveryInstructions =
230  SBFormattedString("device.firmware.wizard.recovery_mode.instructions",
231  [self._deviceProperties.modelNumber,
232  handler.recoveryModeKeyCombination,
233  handler.recoveryModeKeyCombination]);
234 
235  // Hack up the style so that it doesn't look so damn ugly.
236  recoveryInstructions = "<html><body><p style=\"font-family: sans-serif; font-size: 12px\">" +
237  recoveryInstructions +
238  "</p></body></html>";
239 
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);
243  }
244  else if(handler.resetInstructionsLocation) {
245  let browser = document.getElementById("device_firmware_wizard_recovery_mode_browser");
246  browser.setAttribute("src", handler.resetInstructionsLocation.spec);
247  }
248  }
249  }
250  };
251 
252  this._deviceFirmwareUpdater.checkForUpdate(this._device, 0, 0, listener);
253  this._deviceFirmwareUpdater.requireRecovery(this._device);
254 
255  return;
256  }
257  }
258 
259  this._deviceFirmwareUpdater.requireRecovery(this._device);
260 
261  // Hint the handler to expect a recovery mode connection
262  handler.initiateRecoveryModeSwitch();
263 
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]);
267 
268  if(handler.recoveryModeKeyCombination) {
269  let recoveryInstructions =
270  SBFormattedString("device.firmware.wizard.recovery_mode.instructions",
271  [this._deviceProperties.modelNumber,
272  handler.recoveryModeKeyCombination,
273  handler.recoveryModeKeyCombination]);
274 
275  // Hack up the style so that it doesn't look so damn ugly.
276  recoveryInstructions = "<html><body><p style=\"font-family: sans-serif; font-size: 12px\">" +
277  recoveryInstructions +
278  "</p></body></html>";
279 
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);
283  }
284  else if(handler.resetInstructionsLocation) {
285  let browser = document.getElementById("device_firmware_wizard_recovery_mode_browser");
286  browser.setAttribute("src", handler.resetInstructionsLocation.spec);
287  }
288  }
289  break;
290 
291  case "device_firmware_download": {
292  if(this._device.isBusy) {
293  this._currentOperation = "busy";
294  setTimeout(function() {
295  self.wizardElem.goTo("device_firmware_busy_device_page");
296  }, 0);
297  }
298  else {
299  let descElem =
300  document.getElementById("device_firmware_download_no_disconnect_desc");
301  let descTextNode =
302  document.createTextNode(SBString("device.firmware.wizard.no_disconnect_warn"));
303 
304  if(descElem.firstChild &&
305  descElem.firstChild.nodeType == Ci.nsIDOMNode.TEXT_NODE) {
306  descElem.removeChild(descElem.firstChild);
307  }
308 
309  descElem.appendChild(descTextNode);
310 
311  this._currentOperation = "download";
312  this._deviceFirmwareUpdater.downloadUpdate(this._device, false, this);
313  }
314  }
315  break;
316 
317  case "device_firmware_download_error": {
318  this._currentOperation = "download_error";
319 
320  let okButton = this.wizardElem.getButton("next");
321  okButton.label = SBString("window.ok.label");
322  okButton.accessKey = SBString("window.ok.accessKey");
323 
324  let supportLink =
325  document.getElementById("device_firmware_download_error_link");
326  let handler = this._deviceFirmwareUpdater.getActiveHandler(this._device);
327 
328  let supportLinkValue = handler.customerSupportLocation.spec;
329  supportLink.value = supportLinkValue;
330  supportLink.href = supportLinkValue;
331  }
332  break;
333 
334  case "device_firmware_repair": {
335  this._currentOperation = "confirmrepair";
336 
337  let restoreButton = this.wizardElem.getButton("next");
338  restoreButton.label = SBString("device.firmware.repair.button");
339  restoreButton.accessKey = null;
340 
341  let descElem = document.getElementById("device_firmware_repair_description");
342  if(this._repairDescriptionNode) {
343  descElem.removeChild(this._repairDescriptionNode);
344  this._repairDescriptionNode = null;
345  }
346 
347  let deviceName = this._isDefaultDevice ?
348  this._defaultDeviceName : this._deviceProperties.friendlyName;
349  let descString = SBFormattedString("device.firmware.repair.description",
350  [deviceName]);
351  this._repairDescriptionNode = document.createTextNode(descString);
352  descElem.appendChild(this._repairDescriptionNode);
353  }
354  break;
355 
356  case "device_firmware_install": {
357  this._currentOperation = "install";
358 
359  let cancelButton = this.wizardElem.getButton("cancel");
360  cancelButton.disabled = true;
361 
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);
366  }
367 
368  if(this._wizardMode == "repair") {
369  let label = document.getElementById("device_firmware_wizard_install_title");
370  label.value = SBString("device.firmware.repair.inprocess");
371 
372  let textNode =
373  document.createTextNode(SBString("device.firmware.repair.no_disconnect_warning"));
374  descElem.appendChild(textNode);
375 
376  try {
377  if(this._isDefaultDevice) {
378  this._deviceFirmwareUpdater.recoveryUpdate(this._device,
379  this._firmwareUpdate,
380  this._defaultDeviceVID,
381  this._defaultDevicePID,
382  this);
383  }
384  else {
385  this._deviceFirmwareUpdater.recoveryUpdate(this._device,
386  this._firmwareUpdate,
387  0,
388  0,
389  this);
390  }
391  }
392  catch(e) {
393  this.wizardElem.goTo("device_firmware_install_error_page");
394  }
395  }
396  else {
397  let textNode =
398  document.createTextNode(SBString("device.firmware.wizard.no_disconnect_warn"));
399  descElem.appendChild(textNode);
400 
401  // We have to do this to ensure that the device event is propagated
402  // to everyone before we actually start the update. Yes this is lame.
403  // Yes, it would be nice to do it a different way.
404  setTimeout(function() {
405  self._deviceFirmwareUpdater.applyUpdate(self._device, self._firmwareUpdate, self);
406  }, 0);
407  }
408  }
409  break;
410 
411  case "device_firmware_install_error": {
412  this._currentOperation = "install_error";
413 
414  let okButton = this.wizardElem.getButton("next");
415  okButton.label = SBString("window.ok.label");
416  okButton.accessKey = SBString("window.ok.accessKey");
417 
418  let supportLink =
419  document.getElementById("device_firmware_install_error_link");
420  let handler = this._deviceFirmwareUpdater.getActiveHandler(this._device);
421 
422  let supportLinkValue = null;
423 
424  try {
425  supportLinkValue = handler.customerSupportLocation.spec;
426  } catch(e) {}
427 
428  supportLink.value = supportLinkValue;
429  supportLink.href = supportLinkValue;
430 
431  let descElem =
432  document.getElementById("device_firmware_install_error_description");
433 
434  if(descElem.firstChild &&
435  descElem.firstChild.nodeType == Ci.nsIDOMNode.TEXT_NODE) {
436  descElem.removeChild(descElem.firstChild);
437  }
438 
439  let text = null;
440  if(this._wizardMode == "repair") {
441  text = SBString("device.firmware.repair.error.description");
442  }
443  else {
444  text = SBString("device.firmware.wizard.install.error.desc");
445  }
446  descElem.appendChild(document.createTextNode(text));
447  }
448  break;
449 
450  case "device_firmware_update_complete": {
451  this._currentOperation = "complete";
452 
453  let desc =
454  document.getElementById("device_firmware_update_complete_description");
455  let descStr = "";
456 
457  if(this._wizardMode == "repair") {
458  descStr = SBString("device.firmware.repair.complete.desc");
459 
460  // Automatically close the wizard when in repair mode.
461  this.doFinish();
462  }
463  else {
464  descStr = SBString("device.firmware.wizard.complete.desc");
465  }
466 
467  let descTextNode = document.createTextNode(descStr);
468  desc.appendChild(descTextNode);
469  }
470  break;
471 
472  case "device_firmware_busy_device": {
473  let retryButton = this.wizardElem.getButton("next");
474  retryButton.label =
475  SBString("device.firmware.wizard.retry.button");
476  retryButton.accessKey = null;
477  }
478  break;
479 
480  default:
481  throw new Error("not reached");
482  }
483  },
484 
485  doBack: function deviceFirmwareWizard_onBack(aEvent) {
486  this._deviceFirmwareUpdater.cancel(this._device);
487 
488  var self = window;
489  setTimeout(function() { self.close(); }, 0);
490 
491  return false;
492  },
493 
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") {
498  if(isError) {
499  // Error, cancel the operation
500  this._deviceFirmwareUpdater.cancel(this._device);
501  }
502 
503  try {
504  this._deviceFirmwareUpdater.finalizeUpdate(this._device);
505  } catch(e) { Cu.reportError(e); }
506 
507  window.close();
508 
509  return false;
510  }
511  else if(this._currentOperation == "checkforupdate") {
512  // Check if the handler needs to be in recovery mode, if so
513  // go to the recovery mode page to show the instructions and
514  // wait for the device to be reconnected in recovery mode.
515  let handler =
516  this._deviceFirmwareUpdater.getActiveHandler(this._device);
517 
518  if(handler.needsRecoveryMode) {
519  this._currentOperation = "needsrecoverymode";
520 
521  let self = this;
522  setTimeout(function() {
523  self.wizardElem.goTo("device_needs_recovery_mode_page");
524  }, 0);
525  return false;
526  }
527  }
528  else if(this._currentOperation == "confirmrepair") {
529  let self = this;
530  setTimeout(function() {
531  self.wizardElem.goTo("device_firmware_wizard_download_page");
532  }, 0);
533  return false;
534  }
535  }
536 
537  return true;
538  },
539 
540  doExtra1: function deviceFirmwareWizard_onExtra1(aEvent) {
541  return true;
542  },
543 
544  doExtra2: function deviceFirmwareWizard_onExtra2(aEvent) {
545  return true;
546  },
547 
548  onDeviceEvent: function deviceFirmwareWizard_onDeviceEvent(aEvent) {
549  this._handleDeviceEvent(aEvent);
550  },
551 
552  update: function deviceFirmwareWizard_update() {
553  },
554 
555  _initialize: function deviceFirmwareWizard__initialize() {
556  if (this._initialized)
557  return;
558 
559  var dialogPB =
560  window.arguments[0].QueryInterface(Ci.nsIDialogParamBlock);
561 
562  try {
563  var wizardMode = dialogPB.GetString(0).split("=");
564  this._wizardMode = wizardMode[1];
565  } catch(e) {
566  this._wizardMode = "update";
567  }
568 
569  try {
570  var defaultDevice = dialogPB.GetString(1).split("=");
571  this._isDefaultDevice = (defaultDevice[1] == "true");
572  }
573  catch(e) {
574  this._isDefaultDevice = false;
575  }
576 
577  if(!this._isDefaultDevice) {
578  this._device = dialogPB.objects.queryElementAt(0, Ci.sbIDevice);
579  }
580  else {
581  this._defaultDeviceName = dialogPB.GetString(2);
582  this._defaultDeviceKey = dialogPB.GetString(3);
583 
584  var deviceVIDPID = dialogPB.GetString(4).split("-");
585  this._defaultDeviceVID = deviceVIDPID[0];
586  this._defaultDevicePID = deviceVIDPID[1];
587  }
588 
589  if(!this._isDefaultDevice) {
590  this._deviceProperties = this._device.properties;
591  }
592 
593  this._deviceFirmwareUpdater =
594  Cc["@songbirdnest.com/Songbird/Device/Firmware/Updater;1"]
595  .getService(Ci.sbIDeviceFirmwareUpdater);
596 
597  this._wizardElem = document.getElementById("device_firmware_wizard");
598  this._domEventListenerSet = new DOMEventListenerSet();
599 
600  var browserBox = document.getElementById("device_firmware_wizard_release_notes_box");
601  this._domEventListenerSet.add(browserBox, "collapse", this._handleBrowserCollapse, true, false);
602 
603  this._wizardElem.canRewind = true;
604 
605  this._initialized = true;
606  SBDataSetBoolValue(this._activeDataRemote, true);
607 
608  // in repair mode and default device mode, skip check for update and
609  // download firmware.
610  var self = this;
611 
612  // first check for default device mode as it needs to bypass the use
613  // of the firmware handler.
614  if(this._wizardMode == "repair" && this._isDefaultDevice) {
615  // repair mode + default device means we go straight to displaying
616  // the instructions to put the device in recovery mode.
617  this._wizardElem.title = SBString("device.firmware.repair.title");
618  return this._wizardElem.goTo("device_needs_recovery_mode_page");
619  }
620 
621  // not default device, proceed as normal.
622  if(this._wizardMode == "repair") {
623  this._wizardElem.title = SBString("device.firmware.repair.title");
624  let handler = this._deviceFirmwareUpdater.getHandler(this._device, 0, 0);
625  handler.bind(this._device, null);
626  let recoveryMode = handler.recoveryMode;
627 
628  handler.unbind();
629  handler = null;
630 
631  if(recoveryMode) {
632  setTimeout(function() {
633  self._wizardElem.goTo("device_firmware_wizard_check_page");
634  }, 0);
635  }
636  else {
637  // device needs to be switched to recovery mode
638  setTimeout(function() {
639  self._wizardElem.goTo("device_needs_recovery_mode_page");
640  }, 0);
641  }
642  }
643  else {
644  setTimeout(function() {
645  self._wizardElem.goTo("device_firmware_wizard_check_page");
646  }, 0);
647  }
648  },
649 
650 
651  _finalize: function deviceFirmwareWizard__finalize() {
652  this._deviceFirmwareUpdater.finalizeUpdate(this._device);
653 
654  let deviceManager = Cc["@songbirdnest.com/Songbird/DeviceManager;2"]
655  .getService(Ci.sbIDeviceManager2);
656  deviceManager.removeEventListener(this);
657 
658  this._device = null;
660 
661  if (this._domEventListenerSet)
662  this._domEventListenerSet.removeAll();
663  this._domEventListenerSet = null;
664 
665  SBDataSetBoolValue(this._activeDataRemote, false);
666  },
667 
668  _handleBrowserCollapse: function deviceFirmwareWizard__handleBrowserCollapse(aEvent) {
669  const BROWSER_VISIBLE_INNER_HEIGHT = 360;
670 
671  if(aEvent.detail == true) {
672  window.innerHeight = BROWSER_VISIBLE_INNER_HEIGHT;
673  }
674  },
675 
676  _handleDeviceEvent: function deviceFirmwareWizard__handleDeviceEvent(aEvent) {
677  switch(this._currentOperation) {
678  case "checkforupdate":
679  this._handleCheckForUpdate(aEvent);
680  break;
681 
682  case "download":
683  this._handleDownloadFirmware(aEvent);
684  break;
685 
686  case "install":
687  this._handleApplyUpdate(aEvent);
688  break;
689 
690  case "needsrecoverymode":
691  this._handleNeedsRecoveryMode(aEvent);
692  break;
693  }
694  },
695 
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) {
700 
701  // If we are in repair mode, we skip to the repair confirmation page
702  if(this._wizardMode == "repair") {
703  var self = this;
704  setTimeout(function() {
705  self._wizardElem.goTo("device_firmware_wizard_repair_page");
706  }, 0);
707  return;
708  }
709 
710  var newVerDesc =
711  document.getElementById("device_firmware_wizard_check_newver_description");
712 
713  var handler = this._deviceFirmwareUpdater.getActiveHandler(this._device);
714 
715  var text = SBFormattedString("device.firmware.wizard.check.newver.description",
716  [handler.latestFirmwareReadableVersion]);
717 
718  newVerDesc.appendChild(document.createTextNode(text));
719 
720  var remindMeLaterButton = this.wizardElem.getButton("back");
721  var installNewFirmwareButton = this.wizardElem.getButton("next");
722 
723  remindMeLaterButton.label =
724  SBString("device.firmware.wizard.check.remind_me_later.label");
725  remindMeLaterButton.accessKey = null;
726  remindMeLaterButton.disabled = false;
727 
728  installNewFirmwareButton.label =
729  SBString("device.firmware.wizard.check.install.label");
730  installNewFirmwareButton.accessKey = null;
731 
732  this.wizardElem.currentPage.setAttribute("showback", "true");
733  this.wizardElem.currentPage.setAttribute("shownext", "true");
734 
735  var browser = document.getElementById("device_firmware_wizard_release_notes_browser");
736 
737  var releaseNotesLocation = null;
738  try {
739  releaseNotesLocation = handler.releaseNotesLocation;
740  }
741  catch(e) {}
742 
743  var spec = releaseNotesLocation ? releaseNotesLocation.spec : "about:blank";
744  browser.setAttribute("src", spec);
745 
746  progressDeck.selectedPanel =
747  document.getElementById("device_firmware_wizard_check_new_box");
748 
749  var browserBox =
750  document.getElementById("device_firmware_wizard_release_notes_box");
751  browserBox.open = true;
752 
753  // force canRewind since we need to be able to use the back button
754  // as the remind me later button.
755  this._wizardElem.canRewind = true;
756  }
757  else {
758  let okButton = this.wizardElem.getButton("next");
759  okButton.label = SBString("window.ok.label");
760  okButton.accessKey = SBString("window.ok.accessKey");
761 
762  this.wizardElem.currentPage.setAttribute("hidecancel", "true");
763  this.wizardElem.currentPage.setAttribute("shownext", "true");
764 
765  progressDeck.selectedPanel =
766  document.getElementById("device_firmware_wizard_check_already_box");
767 
768  this._currentOperation = "uptodate";
769  }
770  }
771  else if(aEvent.type == Ci.sbIDeviceEvent.EVENT_FIRMWARE_CFU_ERROR) {
772  this.wizardElem.goTo("device_firmware_wizard_check_error_page");
773  }
774  },
775 
776  _handleDownloadFirmware: function deviceFirmwareWizard__handleDownloadFirmware(aEvent) {
777  var progressMeter =
778  document.getElementById("device_firmware_wizard_download_progress");
779  switch(aEvent.type) {
780  // Good events
781  case Ci.sbIDeviceEvent.EVENT_FIRMWARE_DOWNLOAD_PROGRESS:
782  progressMeter.value = aEvent.data;
783  break;
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");
787  break;
788 
789  // Error Events
790  case Ci.sbIDeviceEvent.EVENT_FIRMWARE_DOWNLOAD_ERROR:
791  this.wizardElem.goTo("device_firmware_wizard_download_error_page");
792  break;
793  }
794  },
795 
796  _handleApplyUpdate: function deviceFirmwareWizard__handleApplyUpdate(aEvent) {
797  var progressMeter =
798  document.getElementById("device_firmware_wizard_install_progress");
799 
800  switch(aEvent.type) {
801  // Good events
802  case Ci.sbIDeviceEvent.EVENT_FIRMWARE_WRITE_START:
803  progressMeter.mode = "undetermined";
804  break;
805  case Ci.sbIDeviceEvent.EVENT_FIRMWARE_WRITE_PROGRESS:
806  if(progressMeter.mode != "determined") {
807  progressMeter.mode = "determined";
808  }
809  progressMeter.value = aEvent.data;
810  break;
811  case Ci.sbIDeviceEvent.EVENT_FIRMWARE_WRITE_END:
812  if(progressMeter.mode != "determined") {
813  progressMeter.mode = "determined";
814  }
815  progressMeter.value = 100;
816  break;
817  case Ci.sbIDeviceEvent.EVENT_FIRMWARE_UPDATE_END:
818  this.wizardElem.goTo("device_firmware_wizard_complete_page");
819  break;
820 
821  // Special error that indicates that the firmware image we're
822  // attempting to put on the device actually requires the device to
823  // be in recovery mode.
824  case Ci.sbIDeviceEvent.EVENT_FIRMWARE_NEEDREC_ERROR:
825  let handler =
826  this._deviceFirmwareUpdater.getActiveHandler(this._device);
827 
828  if(handler.needsRecoveryMode) {
829  this._currentOperation = "needsrecoverymode";
830 
831  let self = this;
832  setTimeout(function() {
833  self.wizardElem.goTo("device_needs_recovery_mode_page");
834  }, 0);
835  }
836  break;
837 
838  // Error events
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");
842  break;
843  }
844  },
845 
846  _handleNeedsRecoveryMode: function deviceFirmwareWizard__handleNeedsRecoveryMode(aEvent) {
847  switch(aEvent.type) {
848  case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED: {
849  if(!this._waitingForDeviceReconnect && !this._isDefaultDevice) {
850  return;
851  }
852 
853  this._device = aEvent.data.QueryInterface(Ci.sbIDevice);
854 
855  let criticalFailure = false;
856  let continueSuccess = false;
857 
858  // Not default device, proceed as normal.
859  if(!this._isDefaultDevice) {
860  try {
861  continueSuccess =
862  this._deviceFirmwareUpdater.continueUpdate(this._device, this);
863  }
864  catch(e) {
865  criticalFailure = true;
866  Cu.reportError(e);
867  }
868  }
869  else {
870  // Simply continue if we're dealing with the default device.
871  continueSuccess = true;
872  }
873 
874  if(continueSuccess || criticalFailure) {
875  this._waitingForDeviceReconnect = false;
876 
877  let deviceManager =
878  Cc["@songbirdnest.com/Songbird/DeviceManager;2"]
879  .getService(Ci.sbIDeviceManager2);
880 
881  deviceManager.removeEventListener(this);
882 
883  if(criticalFailure) {
884  // We're not recovering from this one, go to the error page.
885  this.wizardElem.goTo("device_firmware_install_error_page");
886  }
887  else {
888  if(this._wizardMode == "repair") {
889  // Repair mode needs to ask for confirmation first.
890  this.wizardElem.goTo("device_firmware_wizard_check_page");
891  }
892  else {
893  // Business as usual, download the new firmware and proceed
894  // with the installation.
895  this.wizardElem.goTo("device_firmware_wizard_download_page");
896  }
897  }
898  }
899  }
900  break;
901 
902  case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED: {
903  this._waitingForDeviceReconnect = true;
904 
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]);
909  }
910  else {
911  label.value = SBFormattedString("device.firmware.wizard.recovery_mode.disconnected",
912  [this._deviceProperties.modelNumber]);
913  }
914  }
915  break;
916  }
917  }
918 };
const Cu
const Cc
var cancelButton
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
var deviceFirmwareWizard
function doLoad()
function DOMEventListenerSet()
Definition: DOMUtils.jsm:766
function SBString(aKey, aDefault, aStringBundle)
Definition: StringUtils.jsm:93
let window
function doCancel()
this _contentSandbox label
Definition: FeedWriter.js:814
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)
return null
Definition: FeedWriter.js:1143
const Cr
const Ci
var browser
Definition: openLocation.js:42
sbDeviceFirmwareAutoCheckForUpdate prototype _deviceFirmwareUpdater
GstMessage gpointer data sbGStreamerMessageHandler * handler