NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request, nsISupports* aContext, nsresult aStatus)
nsPluginCacheListener::OnStopRequest(nsIRequest *request, nsISupports* aContext, nsresult aStatus)
NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request,                                                         nsISupports* aContext,                                                        nsresult aStatus){  nsresult rv = NS_OK;  PLUGIN_LOG(PLUGIN_LOG_NOISY,  ("nsPluginStreamListenerPeer::OnStopRequest this=%p aStatus=%d request=%p\n",  this, aStatus, request));    // for ByteRangeRequest we're just updating the mDataForwardToRequest hash and return.  nsCOMPtr<nsIByteRangeRequest> brr = do_QueryInterface(request);  if (brr) {    PRInt32 absoluteOffset = 0;    brr->GetStartRange(&absoluteOffset);        nsPRUintKey key(absoluteOffset);        // remove the request from our data forwarding count hash.        (void) mDataForwardToRequest->Remove(&key);      PLUGIN_LOG(PLUGIN_LOG_NOISY,    ("                          ::OnStopRequest for ByteRangeRequest Started=%d\n",    absoluteOffset));  } else {    // if this is not byte range request and    // if we are writting the stream to disk ourselves, lets close it    nsCOMPtr<nsIOutputStream> outStream;    mPluginStreamInfo->GetLocalCachedFileStream(getter_AddRefs(outStream));    if (outStream) {       outStream->Close();      mPluginStreamInfo->SetLocalCachedFileStream(nsnull);    }  }  // if we still have pending stuff to do, lets not close the plugin socket.  if (--mPendingRequests > 0)      return NS_OK;    // we keep our connections around...  PRUint32 magicNumber = 0;  // set it to something that is not the magic number.  nsCOMPtr<nsISupportsPRUint32> container = do_QueryInterface(aContext);  if (container)    container->GetData(&magicNumber);        if (magicNumber == MAGIC_REQUEST_CONTEXT)  {    // this is one of our range requests    return NS_OK;  }    if(!mPStreamListener)      return NS_ERROR_FAILURE;    nsCOMPtr<nsIURI> aURL;  nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);  if (!channel)     return NS_ERROR_FAILURE;  rv = channel->GetURI(getter_AddRefs(aURL));  if (NS_FAILED(rv))     return rv;    nsCAutoString urlString;  rv = aURL->GetAsciiSpec(urlString);  if (NS_SUCCEEDED(rv))     mPluginStreamInfo->SetURL(urlString.get());    // Set the content type to ensure we don't pass null to the plugin  nsCAutoString aContentType;  rv = channel->GetContentType(aContentType);  if (NS_FAILED(rv))     return rv;  if (!aContentType.IsEmpty())    mPluginStreamInfo->SetContentType(aContentType.get());  // set error status if stream failed so we notify the plugin  if (mRequestFailed)    aStatus = NS_ERROR_FAILURE;  if (NS_FAILED(aStatus)) {    // on error status cleanup the stream     // and return w/o OnFileAvailable()    mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, aStatus);    return NS_OK;  }  nsXPIDLCString pathAndFilename;  mPluginStreamInfo->GetLocalCachedFile(getter_Copies(pathAndFilename));  if (!pathAndFilename) {    nsCOMPtr<nsIFile> localFile;    nsCOMPtr<nsICachingChannel> cacheChannel = do_QueryInterface(request);    if (cacheChannel) {      cacheChannel->GetCacheFile(getter_AddRefs(localFile));    } else {      // see if it is a file channel.      nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(request);      if (fileChannel) {        fileChannel->GetFile(getter_AddRefs(localFile));      }    }    if (localFile) {      localFile->GetPath(getter_Copies(pathAndFilename));    }  }    if (pathAndFilename && *pathAndFilename) {    OnFileAvailable(pathAndFilename);  }  if (mStartBinding)  {    // On start binding has been called    mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, aStatus);  }  else  {    // OnStartBinding hasn't been called, so complete the action.    mPStreamListener->OnStartBinding((nsIPluginStreamInfo*)mPluginStreamInfo);    mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, aStatus);  }  return NS_OK;}