B2G/gecko/toolkit/mozapps/update/nsUpdateService.js
/**
 * Update
 * Implements nsIUpdate
 * @param   update
 *          An <update> element to initialize this object with
 * @throws if the update contains no patches
 * @constructor
 */
Update
Implements nsIUpdate
@param   update
An  element to initialize this object with
@throws if the update contains no patches
@constructor
Update Implements nsIUpdate @param update An element to initialize this object with @throws if the update contains no patches @constructor
function Update(update) {
  this._properties = {};
  this._patches = [];
  this.isCompleteUpdate = false;
  this.isOSUpdate = false;
  this.showPrompt = false;
  this.showSurvey = false;
  this.showNeverForVersion = false;
  this.channel = "default"
  if (!update)
    return;
  const ELEMENT_NODE = Ci.nsIDOMNode.ELEMENT_NODE;
  for (var i = 0; i < update.childNodes.length; ++i) {
    var patchElement = update.childNodes.item(i);
    if (patchElement.nodeType != ELEMENT_NODE ||
        patchElement.localName != "patch")
      continue;
    patchElement.QueryInterface(Ci.nsIDOMElement);
    try {
      var patch = new UpdatePatch(patchElement);
    } catch (e) {
      continue;
    }
    this._patches.push(patch);
  }
  if (0 == this._patches.length)
    throw Cr.NS_ERROR_ILLEGAL_VALUE;
  if (!update.hasAttribute("appVersion")) {
    if (update.getAttribute("type") == "major") {
      if (update.hasAttribute("detailsURL")) {
        this.billboardURL = update.getAttribute("detailsURL");
        this.showPrompt = true;
        this.showNeverForVersion = true;
      }
    }
  }
  for (var i = 0; i < update.attributes.length; ++i) {
    var attr = update.attributes.item(i);
    attr.QueryInterface(Ci.nsIDOMAttr);
    if (attr.value == "undefined")
      continue;
    else if (attr.name == "detailsURL")
      this._detailsURL = attr.value;
    else if (attr.name == "extensionVersion") {
      if (!this.appVersion)
        this.appVersion = attr.value;
    }
    else if (attr.name == "installDate" && attr.value)
      this.installDate = parseInt(attr.value);
    else if (attr.name == "isCompleteUpdate")
      this.isCompleteUpdate = attr.value == "true";
    else if (attr.name == "isSecurityUpdate")
      this.isSecurityUpdate = attr.value == "true";
    else if (attr.name == "isOSUpdate")
      this.isOSUpdate = attr.value == "true";
    else if (attr.name == "showNeverForVersion")
      this.showNeverForVersion = attr.value == "true";
    else if (attr.name == "showPrompt")
      this.showPrompt = attr.value == "true";
    else if (attr.name == "showSurvey")
      this.showSurvey = attr.value == "true";
    else if (attr.name == "version") {
      if (!this.displayVersion)
        this.displayVersion = attr.value;
    }
    else {
      this[attr.name] = attr.value;
      switch (attr.name) {
      case "appVersion":
      case "billboardURL":
      case "buildID":
      case "channel":
      case "displayVersion":
      case "licenseURL":
      case "name":
      case "platformVersion":
      case "previousAppVersion":
      case "serviceURL":
      case "statusText":
      case "type":
        break;
      default:
        this.setProperty(attr.name, attr.value);
        break;
      };
    }
  }
  if (!this.installDate && this.installDate != 0)
    this.installDate = (new Date()).getTime();
  var name = "";
  if (update.hasAttribute("name"))
    name = update.getAttribute("name");
  else {
    var brandBundle = Services.strings.createBundle(URI_BRAND_PROPERTIES);
    var appName = brandBundle.GetStringFromName("brandShortName");
    name = gUpdateBundle.formatStringFromName("updateName",
                                              [appName, this.displayVersion], 2);
  }
  this.name = name;
}
function Update ( update ) { this . _properties = { } ; this . _patches = [ ] ; this . isCompleteUpdate = false ; this . isOSUpdate = false ; this . showPrompt = false ; this . showSurvey = false ; this . showNeverForVersion = false ; this . channel = "default" if ( ! update ) return ; const ELEMENT_NODE = Ci . nsIDOMNode . ELEMENT_NODE ; for ( var i = 0 ; i < update . childNodes . length ; ++ i ) { var patchElement = update . childNodes . item ( i ) ; if ( patchElement . nodeType != ELEMENT_NODE || patchElement . localName != "patch" ) continue ; patchElement . QueryInterface ( Ci . nsIDOMElement ) ; try { var patch = new UpdatePatch ( patchElement ) ; } catch ( e ) { continue ; } this . _patches . push ( patch ) ; } if ( 0 == this . _patches . length ) throw Cr . NS_ERROR_ILLEGAL_VALUE ; if ( ! update . hasAttribute ( "appVersion" ) ) { if ( update . getAttribute ( "type" ) == "major" ) { if ( update . hasAttribute ( "detailsURL" ) ) { this . billboardURL = update . getAttribute ( "detailsURL" ) ; this . showPrompt = true ; this . showNeverForVersion = true ; } } } for ( var i = 0 ; i < update . attributes . length ; ++ i ) { var attr = update . attributes . item ( i ) ; attr . QueryInterface ( Ci . nsIDOMAttr ) ; if ( attr . value == "undefined" ) continue ; else if ( attr . name == "detailsURL" ) this . _detailsURL = attr . value ; else if ( attr . name == "extensionVersion" ) { if ( ! this . appVersion ) this . appVersion = attr . value ; } else if ( attr . name == "installDate" && attr . value ) this . installDate = parseInt ( attr . value ) ; else if ( attr . name == "isCompleteUpdate" ) this . isCompleteUpdate = attr . value == "true" ; else if ( attr . name == "isSecurityUpdate" ) this . isSecurityUpdate = attr . value == "true" ; else if ( attr . name == "isOSUpdate" ) this . isOSUpdate = attr . value == "true" ; else if ( attr . name == "showNeverForVersion" ) this . showNeverForVersion = attr . value == "true" ; else if ( attr . name == "showPrompt" ) this . showPrompt = attr . value == "true" ; else if ( attr . name == "showSurvey" ) this . showSurvey = attr . value == "true" ; else if ( attr . name == "version" ) { if ( ! this . displayVersion ) this . displayVersion = attr . value ; } else { this [ attr . name ] = attr . value ; switch ( attr . name ) { case "appVersion" : case "billboardURL" : case "buildID" : case "channel" : case "displayVersion" : case "licenseURL" : case "name" : case "platformVersion" : case "previousAppVersion" : case "serviceURL" : case "statusText" : case "type" : break ; default : this . setProperty ( attr . name , attr . value ) ; break ; } ; } } if ( ! this . installDate && this . installDate != 0 ) this . installDate = ( new Date ( ) ) . getTime ( ) ; var name = "" ; if ( update . hasAttribute ( "name" ) ) name = update . getAttribute ( "name" ) ; else { var brandBundle = Services . strings . createBundle ( URI_BRAND_PROPERTIES ) ; var appName = brandBundle . GetStringFromName ( "brandShortName" ) ; name = gUpdateBundle . formatStringFromName ( "updateName" , [ appName , this . displayVersion ] , 2 ) ; } this . name = name ; }
Update
 Implements nsIUpdate
 @param   update
          An <update> element to initialize this object with
 @throws if the update contains no patches
 @constructor
Update Implements nsIUpdate @param update An <update > element to initialize this object with @throws if the update contains no patches @constructor
// Null <update>, assume this is a message container and do no // further initialization // Fallback to the behavior prior to bug 530872 if the update does not have an // appVersion attribute. // Prevent extensionVersion from replacing appVersion if appVersion is // present in the update xml. // Prevent version from replacing displayVersion if displayVersion is // present in the update xml. // Save custom attributes when serializing to the local xml file but // don't use this method for the expected attributes which are already // handled in serialize. // Set the initial value with the current time when it doesn't already have a // value or the value is already set to 0 (bug 316328). // The Update Name is either the string provided by the <update> element, or // the string: "<App Name> <Update App Version>"