PLUGIN_LOG(PLUGIN_LOG_NOISY, ("nsPluginStreamListenerPeer::OnDataAvailable request=%p, offset=%d, length=%d, url=%s\n", request, sourceOffset, aLength, urlString));
NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request,                                                           nsISupports* aContext,                                                           nsIInputStream *aIStream,                                                           PRUint32 sourceOffset,                                                           PRUint32 aLength){    if(mAbort)  {      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 not one of our range requests        mAbort = PR_FALSE;        return NS_BINDING_ABORTED;      }  }  nsresult rv = NS_OK;  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;  if(!mPStreamListener)	  return NS_ERROR_FAILURE;  char* urlString;  aURL->GetSpec(&urlString);  mPluginStreamInfo->SetURL(urlString);  nsCRT::free(urlString);  // if the plugin has requested an AsFileOnly stream, then don't   // call OnDataAvailable  if(mStreamType != nsPluginStreamType_AsFileOnly)  {    // get the absolute offset of the request, if one exists.    nsCOMPtr<nsIByteRangeRequest> brr = do_QueryInterface(request);    PRInt32 absoluteOffset = 0;    PRInt32 amtForwardToPlugin = 0;    if (brr) {        brr->GetStartRange(&absoluteOffset);                // we need to track how much data we have forward on to the plugin.          nsPRUintKey key(absoluteOffset);        if (!mDataForwardToRequest)            return NS_ERROR_FAILURE;        if (mDataForwardToRequest->Exists(&key))            amtForwardToPlugin = NS_PTR_TO_INT32(mDataForwardToRequest->Remove(&key));            mDataForwardToRequest->Put(&key, (void*) (amtForwardToPlugin+aLength));    }    nsCOMPtr<nsIInputStream> stream = aIStream;    // if we are caching the file ourselves to disk, we want to 'tee' off    // the data as the plugin read from the stream.  We do this by the magic    // of an input stream tee.    nsCOMPtr<nsIOutputStream> outStream;    mPluginStreamInfo->GetLocalCachedFileStream(getter_AddRefs(outStream));    if (outStream) {        rv = NS_NewInputStreamTee(getter_AddRefs(stream), aIStream, outStream);        if (NS_FAILED(rv))             return rv;    }    nsCOMPtr<nsIPluginStreamListener2> PStreamListener2 = do_QueryInterface(mPStreamListener);    if (PStreamListener2 && brr)      rv =  PStreamListener2->OnDataAvailable((nsIPluginStreamInfo*)mPluginStreamInfo,                                             stream,                                             absoluteOffset+amtForwardToPlugin,                                             aLength);    else      rv =  mPStreamListener->OnDataAvailable((nsIPluginStreamInfo*)mPluginStreamInfo,                                               stream,                                               aLength);    // if a plugin returns an error, the peer must kill the stream    //   else the stream and PluginStreamListener leak    if (NS_FAILED(rv))      request->Cancel(rv);  }  else  {    // if we don't read from the stream, OnStopRequest will never be called    char* buffer = new char[aLength];    PRUint32 amountRead, amountWrote = 0;    rv = aIStream->Read(buffer, aLength, &amountRead);        // if we are caching this to disk ourselves, lets write the bytes out.    nsCOMPtr<nsIOutputStream> outStream;    mPluginStreamInfo->GetLocalCachedFileStream(getter_AddRefs(outStream));    while (outStream && amountWrote <= amountRead && NS_SUCCEEDED(rv))      rv = outStream->Write(buffer, amountRead, &amountWrote);    delete [] buffer;  }  return rv;}