function  Downloader_onStopRequest(request, context, status) {
    if (request instanceof Ci.nsIIncrementalDownload)
      LOG("Downloader:onStopRequest - original URI spec: " + request.URI.spec +
          ", final URI spec: " + request.finalURI.spec + ", status: " + status);

    // XXX ehsan shouldShowPrompt should always be false here.
    // But what happens when there is already a UI showing?
    var state = this._patch.state;
    var shouldShowPrompt = false;
    var deleteActiveUpdate = false;
    if (Components.isSuccessCode(status)) {
      if (this._verifyDownload()) {
        state = shouldUseService() ? STATE_PENDING_SVC : STATE_PENDING

        // We only need to explicitly show the prompt if this is a background
        // download, since otherwise some kind of UI is already visible and
        // that UI will notify.
        if (this.background)
          shouldShowPrompt = !getPref("getBoolPref", PREF_APP_UPDATE_STAGE_ENABLED, false);

        // Tell the updater.exe we're ready to apply.
        writeStatusFile(getUpdatesDir(), state);
        writeVersionFile(getUpdatesDir(), this._update.appVersion);
        this._update.installDate = (new Date()).getTime();
        this._update.statusText = gUpdateBundle.GetStringFromName("installPending");
      }
      else {
        LOG("Downloader:onStopRequest - download verification failed");
        state = STATE_DOWNLOAD_FAILED;

        // TODO: use more informative error code here
        status = Cr.NS_ERROR_UNEXPECTED;

        // Yes, this code is a string.
        const vfCode = "verification_failed";
        var message = getStatusTextFromCode(vfCode, vfCode);
        this._update.statusText = message;

        if (this._update.isCompleteUpdate || this._update.patchCount != 2)
          deleteActiveUpdate = true;

        // Destroy the updates directory, since we're done with it.
        cleanUpUpdatesDir();
      }
    }
    else if (status != Cr.NS_BINDING_ABORTED &&
             status != Cr.NS_ERROR_ABORT &&
             status != Cr.NS_ERROR_DOCUMENT_NOT_CACHED) {
      LOG("Downloader:onStopRequest - non-verification failure");
      // Some sort of other failure, log this in the |statusText| property
      state = STATE_DOWNLOAD_FAILED;

      // XXXben - if |request| (The Incremental Download) provided a means
      // for accessing the http channel we could do more here.

      this._update.statusText = getStatusTextFromCode(status,
                                                      Cr.NS_BINDING_FAILED);

      // Destroy the updates directory, since we're done with it.
      cleanUpUpdatesDir();

      deleteActiveUpdate = true;
    }
    LOG("Downloader:onStopRequest - setting state to: " + state);
    this._patch.state = state;
    var um = Cc["@mozilla.org/updates/update-manager;1"].
             getService(Ci.nsIUpdateManager);
    if (deleteActiveUpdate) {
      this._update.installDate = (new Date()).getTime();
      um.activeUpdate = null;
    }
    else {
      if (um.activeUpdate)
        um.activeUpdate.state = state;
    }
    um.saveUpdates();

    var listeners = this._listeners.concat();
    var listenerCount = listeners.length;
    for (var i = 0; i < listenerCount; ++i)
      listeners[i].onStopRequest(request, context, status);

    this._request = null;

    if (state == STATE_DOWNLOAD_FAILED) {
      var allFailed = true;
      // Check if there is a complete update patch that can be downloaded.
      if (!this._update.isCompleteUpdate && this._update.patchCount == 2) {
        LOG("Downloader:onStopRequest - verification of patch failed, " +
            "downloading complete update patch");
        this._update.isCompleteUpdate = true;
        var status = this.downloadUpdate(this._update);

        if (status == STATE_NONE) {
          cleanupActiveUpdate();
        } else {
          allFailed = false;
        }
      }

      if (allFailed) {
        LOG("Downloader:onStopRequest - all update patch downloads failed");
        // If the update UI is not open (e.g. the user closed the window while
        // downloading) and if at any point this was a foreground download
        // notify the user about the error. If the update was a background
        // update there is no notification since the user won't be expecting it.
        if (!Services.wm.getMostRecentWindow(UPDATE_WINDOW_NAME)) {
          try {
            this._update.QueryInterface(Ci.nsIWritablePropertyBag);
            var fgdl = this._update.getProperty("foregroundDownload");
          }
          catch (e) {
          }

          if (fgdl == "true") {
            var prompter = Cc["@mozilla.org/updates/update-prompt;1"].
                           createInstance(Ci.nsIUpdatePrompt);
            prompter.showUpdateError(this._update);
          }
        }
        // Prevent leaking the update object (bug 454964).
        this._update = null;
      }
      // A complete download has been initiated or the failure was handled.
      return;
    }

    // Do this after *everything* else, since it will likely cause the app
    // to shut down.
    if (shouldShowPrompt) {
      // Notify the user that an update has been downloaded and is ready for
      // installation (i.e. that they should restart the application). We do
      // not notify on failed update attempts.
      var prompter = Cc["@mozilla.org/updates/update-prompt;1"].
                     createInstance(Ci.nsIUpdatePrompt);
      prompter.showUpdateDownloaded(this._update, true);
    }

    if (state == STATE_PENDING || state == STATE_PENDING_SVC) {
      // Initiate the background update job.
      Cc["@mozilla.org/updates/update-service;1"].
        getService(Ci.nsIApplicationUpdateService).
        applyUpdateInBackground(this._update);
    }

    // Prevent leaking the update object (bug 454964)
    this._update = null;
  }
/**
   * When data transfer ceases
   * @param   request
   *          The nsIRequest object for the transfer
   * @param   context
   *          Additional data
   * @param   status
   *          Status code containing the reason for the cessation.
   */
When data transfer ceases
@param   request
The nsIRequest object for the transfer
@param   context
Additional data
@param   status
Status code containing the reason for the cessation.
When data transfer ceases @param request The nsIRequest object for the transfer @param context Additional data @param status Status code containing the reason for the cessation .
function  Downloader_onStopRequest(request, context, status) {
    if (request instanceof Ci.nsIIncrementalDownload)
      LOG("Downloader:onStopRequest - original URI spec: " + request.URI.spec +
          ", final URI spec: " + request.finalURI.spec + ", status: " + status);
    var state = this._patch.state;
    var shouldShowPrompt = false;
    var deleteActiveUpdate = false;
    if (Components.isSuccessCode(status)) {
      if (this._verifyDownload()) {
        state = shouldUseService() ? STATE_PENDING_SVC : STATE_PENDING
        if (this.background)
          shouldShowPrompt = !getPref("getBoolPref", PREF_APP_UPDATE_STAGE_ENABLED, false);
        writeStatusFile(getUpdatesDir(), state);
        writeVersionFile(getUpdatesDir(), this._update.appVersion);
        this._update.installDate = (new Date()).getTime();
        this._update.statusText = gUpdateBundle.GetStringFromName("installPending");
      }
      else {
        LOG("Downloader:onStopRequest - download verification failed");
        state = STATE_DOWNLOAD_FAILED;
        status = Cr.NS_ERROR_UNEXPECTED;
        const vfCode = "verification_failed";
        var message = getStatusTextFromCode(vfCode, vfCode);
        this._update.statusText = message;
        if (this._update.isCompleteUpdate || this._update.patchCount != 2)
          deleteActiveUpdate = true;
        cleanUpUpdatesDir();
      }
    }
    else if (status != Cr.NS_BINDING_ABORTED &&
             status != Cr.NS_ERROR_ABORT &&
             status != Cr.NS_ERROR_DOCUMENT_NOT_CACHED) {
      LOG("Downloader:onStopRequest - non-verification failure");
      state = STATE_DOWNLOAD_FAILED;
      this._update.statusText = getStatusTextFromCode(status,
                                                      Cr.NS_BINDING_FAILED);
      cleanUpUpdatesDir();
      deleteActiveUpdate = true;
    }
    LOG("Downloader:onStopRequest - setting state to: " + state);
    this._patch.state = state;
    var um = Cc["@mozilla.org/updates/update-manager;1"].
             getService(Ci.nsIUpdateManager);
    if (deleteActiveUpdate) {
      this._update.installDate = (new Date()).getTime();
      um.activeUpdate = null;
    }
    else {
      if (um.activeUpdate)
        um.activeUpdate.state = state;
    }
    um.saveUpdates();
    var listeners = this._listeners.concat();
    var listenerCount = listeners.length;
    for (var i = 0; i < listenerCount; ++i)
      listeners[i].onStopRequest(request, context, status);
    this._request = null;
    if (state == STATE_DOWNLOAD_FAILED) {
      var allFailed = true;
      if (!this._update.isCompleteUpdate && this._update.patchCount == 2) {
        LOG("Downloader:onStopRequest - verification of patch failed, " +
            "downloading complete update patch");
        this._update.isCompleteUpdate = true;
        var status = this.downloadUpdate(this._update);
        if (status == STATE_NONE) {
          cleanupActiveUpdate();
        } else {
          allFailed = false;
        }
      }
      if (allFailed) {
        LOG("Downloader:onStopRequest - all update patch downloads failed");
        if (!Services.wm.getMostRecentWindow(UPDATE_WINDOW_NAME)) {
          try {
            this._update.QueryInterface(Ci.nsIWritablePropertyBag);
            var fgdl = this._update.getProperty("foregroundDownload");
          }
          catch (e) {
          }
          if (fgdl == "true") {
            var prompter = Cc["@mozilla.org/updates/update-prompt;1"].
                           createInstance(Ci.nsIUpdatePrompt);
            prompter.showUpdateError(this._update);
          }
        }
        this._update = null;
      }
      return;
    }
    if (shouldShowPrompt) {
      var prompter = Cc["@mozilla.org/updates/update-prompt;1"].
                     createInstance(Ci.nsIUpdatePrompt);
      prompter.showUpdateDownloaded(this._update, true);
    }
    if (state == STATE_PENDING || state == STATE_PENDING_SVC) {
      Cc["@mozilla.org/updates/update-service;1"].
        getService(Ci.nsIApplicationUpdateService).
        applyUpdateInBackground(this._update);
    }
    this._update = null;
  }
function Downloader_onStopRequest ( request , context , status ) { if ( request instanceof Ci . nsIIncrementalDownload ) LOG ( "Downloader:onStopRequest - original URI spec: " + request . URI . spec + ", final URI spec: " + request . finalURI . spec + ", status: " + status ) ; var state = this . _patch . state ; var shouldShowPrompt = false ; var deleteActiveUpdate = false ; if ( Components . isSuccessCode ( status ) ) { if ( this . _verifyDownload ( ) ) { state = shouldUseService ( ) ? STATE_PENDING_SVC : STATE_PENDING if ( this . background ) shouldShowPrompt = ! getPref ( "getBoolPref" , PREF_APP_UPDATE_STAGE_ENABLED , false ) ; writeStatusFile ( getUpdatesDir ( ) , state ) ; writeVersionFile ( getUpdatesDir ( ) , this . _update . appVersion ) ; this . _update . installDate = ( new Date ( ) ) . getTime ( ) ; this . _update . statusText = gUpdateBundle . GetStringFromName ( "installPending" ) ; } else { LOG ( "Downloader:onStopRequest - download verification failed" ) ; state = STATE_DOWNLOAD_FAILED ; status = Cr . NS_ERROR_UNEXPECTED ; const vfCode = "verification_failed" ; var message = getStatusTextFromCode ( vfCode , vfCode ) ; this . _update . statusText = message ; if ( this . _update . isCompleteUpdate || this . _update . patchCount != 2 ) deleteActiveUpdate = true ; cleanUpUpdatesDir ( ) ; } } else if ( status != Cr . NS_BINDING_ABORTED && status != Cr . NS_ERROR_ABORT && status != Cr . NS_ERROR_DOCUMENT_NOT_CACHED ) { LOG ( "Downloader:onStopRequest - non-verification failure" ) ; state = STATE_DOWNLOAD_FAILED ; this . _update . statusText = getStatusTextFromCode ( status , Cr . NS_BINDING_FAILED ) ; cleanUpUpdatesDir ( ) ; deleteActiveUpdate = true ; } LOG ( "Downloader:onStopRequest - setting state to: " + state ) ; this . _patch . state = state ; var um = Cc [ "@mozilla.org/updates/update-manager;1" ] . getService ( Ci . nsIUpdateManager ) ; if ( deleteActiveUpdate ) { this . _update . installDate = ( new Date ( ) ) . getTime ( ) ; um . activeUpdate = null ; } else { if ( um . activeUpdate ) um . activeUpdate . state = state ; } um . saveUpdates ( ) ; var listeners = this . _listeners . concat ( ) ; var listenerCount = listeners . length ; for ( var i = 0 ; i < listenerCount ; ++ i ) listeners [ i ] . onStopRequest ( request , context , status ) ; this . _request = null ; if ( state == STATE_DOWNLOAD_FAILED ) { var allFailed = true ; if ( ! this . _update . isCompleteUpdate && this . _update . patchCount == 2 ) { LOG ( "Downloader:onStopRequest - verification of patch failed, " + "downloading complete update patch" ) ; this . _update . isCompleteUpdate = true ; var status = this . downloadUpdate ( this . _update ) ; if ( status == STATE_NONE ) { cleanupActiveUpdate ( ) ; } else { allFailed = false ; } } if ( allFailed ) { LOG ( "Downloader:onStopRequest - all update patch downloads failed" ) ; if ( ! Services . wm . getMostRecentWindow ( UPDATE_WINDOW_NAME ) ) { try { this . _update . QueryInterface ( Ci . nsIWritablePropertyBag ) ; var fgdl = this . _update . getProperty ( "foregroundDownload" ) ; } catch ( e ) { } if ( fgdl == "true" ) { var prompter = Cc [ "@mozilla.org/updates/update-prompt;1" ] . createInstance ( Ci . nsIUpdatePrompt ) ; prompter . showUpdateError ( this . _update ) ; } } this . _update = null ; } return ; } if ( shouldShowPrompt ) { var prompter = Cc [ "@mozilla.org/updates/update-prompt;1" ] . createInstance ( Ci . nsIUpdatePrompt ) ; prompter . showUpdateDownloaded ( this . _update , true ) ; } if ( state == STATE_PENDING || state == STATE_PENDING_SVC ) { Cc [ "@mozilla.org/updates/update-service;1" ] . getService ( Ci . nsIApplicationUpdateService ) . applyUpdateInBackground ( this . _update ) ; } this . _update = null ; }
When data transfer ceases
 @param   request
          The nsIRequest object for the transfer
 @param   context
          Additional data
 @param   status
          Status code containing the reason for the cessation.
When data transfer ceases @param request The nsIRequest object for the transfer @param context Additional data @param status Status code containing the reason for the cessation .
// XXX ehsan shouldShowPrompt should always be false here. // But what happens when there is already a UI showing? // We only need to explicitly show the prompt if this is a background // download, since otherwise some kind of UI is already visible and // that UI will notify. // Tell the updater.exe we're ready to apply. // TODO: use more informative error code here // Yes, this code is a string. // Destroy the updates directory, since we're done with it. // Some sort of other failure, log this in the |statusText| property // XXXben - if |request| (The Incremental Download) provided a means // for accessing the http channel we could do more here. // Destroy the updates directory, since we're done with it. // Check if there is a complete update patch that can be downloaded. // If the update UI is not open (e.g. the user closed the window while // downloading) and if at any point this was a foreground download // notify the user about the error. If the update was a background // update there is no notification since the user won't be expecting it. // Prevent leaking the update object (bug 454964). // A complete download has been initiated or the failure was handled. // Do this after *everything* else, since it will likely cause the app // to shut down. // Notify the user that an update has been downloaded and is ready for // installation (i.e. that they should restart the application). We do // not notify on failed update attempts. // Initiate the background update job. // Prevent leaking the update object (bug 454964)