PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p: OnStopRequest[%p](%s) status=%x mIsLoadingDocument=%s, %u active URLs", this, aRequest, name.get(), aStatus, (mIsLoadingDocument ? "true" : "false"), count)); } #endif      if (mIsLoadingDocument) { PRUint32 count; PRBool bFireTransferring = PR_FALSE;        nsRequestInfo *info; info = GetRequestInfo(aRequest); if (info) { PRInt32 oldMax = info->mMaxProgress;  info->mMaxProgress = info->mCurrentProgress;      if ((oldMax < 0) && (mMaxSelfProgress < 0)) { CalculateMaxProgress(&mMaxSelfProgress); }          if ((oldMax == 0) && (info->mCurrentProgress == 0)) { nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));     if (channel) { if (NS_SUCCEEDED(aStatus)) { bFireTransferring = PR_TRUE; }      else if (aStatus != NS_BINDING_REDIRECTED) { nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest));  if (httpChannel) { PRUint32 responseCode;  rv = httpChannel->GetResponseStatus(&responseCode); if (NS_SUCCEEDED(rv)) {      bFireTransferring = PR_TRUE; } } } } } }  if (bFireTransferring) {  PRInt32 flags;  flags = nsIWebProgressListener::STATE_TRANSFERRING | nsIWebProgressListener::STATE_IS_REQUEST;    if (mProgressStateFlags & nsIWebProgressListener::STATE_START) { mProgressStateFlags = nsIWebProgressListener::STATE_TRANSFERRING;   flags |= nsIWebProgressListener::STATE_IS_DOCUMENT; }  FireOnStateChange(this, aRequest, flags, NS_OK); }     doStopURLLoad(aRequest, aStatus);  rv = mLoadGroup->GetActiveCount(&count); if (NS_FAILED(rv)) return rv;     if (0 == count) { DocLoaderIsEmpty();
if (!(loadAttribs & nsIChannel::LOAD_BACKGROUND)) { mDocLoader->FireOnEndURLLoad(mDocLoader, aChannel, aStatus);
nsDocLoaderImpl::OnStopRequest(nsIRequest *aRequest,                                nsISupports *aCtxt,                                nsresult aStatus){  nsresult rv = NS_OK;#ifdef PR_LOGGING  if (PR_LOG_TEST(gDocLoaderLog, PR_LOG_DEBUG)) {    nsCAutoString name;    aRequest->GetName(name);    PRUint32 count = 0;    if (mLoadGroup)      mLoadGroup->GetActiveCount(&count);    PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,           ("DocLoader:%p: OnStopRequest[%p](%s) status=%x mIsLoadingDocument=%s, %u active URLs",           this, aRequest, name.get(),           aStatus, (mIsLoadingDocument ? "true" : "false"),           count));  }#endif  //  // Only fire the OnEndDocumentLoad(...) if the document loader   // has initiated a load...  //  if (mIsLoadingDocument) {    PRUint32 count;    PRBool bFireTransferring = PR_FALSE;    //    // Set the Maximum progress to the same value as the current progress.    // Since the URI has finished loading, all the data is there.  Also,    // this will allow a more accurate estimation of the max progress (in case    // the old value was unknown ie. -1)    //    nsRequestInfo *info;    info = GetRequestInfo(aRequest);    if (info) {      PRInt32 oldMax = info->mMaxProgress;      info->mMaxProgress = info->mCurrentProgress;      //      // If a request whose content-length was previously unknown has just      // finished loading, then use this new data to try to calculate a      // mMaxSelfProgress...      //      if ((oldMax < 0) && (mMaxSelfProgress < 0)) {        CalculateMaxProgress(&mMaxSelfProgress);      }      //      // Determine whether a STATE_TRANSFERRING notification should be       // 'synthesized'.      //      // If nsRequestInfo::mMaxProgress (as stored in oldMax) and      // nsRequestInfo::mCurrentProgress are both 0, then the      // STATE_TRANSFERRING notification has not been fired yet...      //      if ((oldMax == 0) && (info->mCurrentProgress == 0)) {        nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));        // Only fire a TRANSFERRING notification if the request is also a        // channel -- data transfer requires a nsIChannel!        //        if (channel) {          if (NS_SUCCEEDED(aStatus)) {            bFireTransferring = PR_TRUE;          }           //          // If the request failed (for any reason other than being          // redirected), the TRANSFERRING notification can still be fired          // if a HTTP connection was established to a server.          //          else if (aStatus != NS_BINDING_REDIRECTED) {            nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest));            if (httpChannel) {              PRUint32 responseCode;              rv = httpChannel->GetResponseStatus(&responseCode);              if (NS_SUCCEEDED(rv)) {                //                // A valid server status indicates that a connection was                // established to the server... So, fire the notification                // even though a failure occurred later...                //                bFireTransferring = PR_TRUE;              }            }          }        }      }    }    if (bFireTransferring) {      // Send a STATE_TRANSFERRING notification for the request.      PRInt32 flags;          flags = nsIWebProgressListener::STATE_TRANSFERRING |               nsIWebProgressListener::STATE_IS_REQUEST;      //      // Move the WebProgress into the STATE_TRANSFERRING state if necessary...      //      if (mProgressStateFlags & nsIWebProgressListener::STATE_START) {        mProgressStateFlags = nsIWebProgressListener::STATE_TRANSFERRING;        // Send STATE_TRANSFERRING for the document too...        flags |= nsIWebProgressListener::STATE_IS_DOCUMENT;      }      FireOnStateChange(this, aRequest, flags, NS_OK);    }    //    // Fire the OnStateChange(...) notification for stop request    //    doStopURLLoad(aRequest, aStatus);        rv = mLoadGroup->GetActiveCount(&count);    if (NS_FAILED(rv)) return rv;    //    // The load group for this DocumentLoader is idle...    //    if (0 == count) {      DocLoaderIsEmpty();    }  }  else {    doStopURLLoad(aRequest, aStatus);   }    return NS_OK;}