const char * url = nsnull; mPluginStreamInfo->GetURL(&url);  PLUGIN_LOG(PLUGIN_LOG_NOISY, ("nsPluginStreamListenerPeer::OnDataAvailable this=%p request=%p, offset=%d, length=%d, url=%s\n", this, request, sourceOffset, aLength, url ? url : "no url set"));    if(mStreamType != nsPluginStreamType_AsFileOnly) {  nsCOMPtr<nsIByteRangeRequest> brr = do_QueryInterface(request); PRInt32 absoluteOffset = 0; if (brr) { if (!mDataForwardToRequest) return NS_ERROR_FAILURE;  brr->GetStartRange(&absoluteOffset);         nsPRUintKey key(absoluteOffset); PRInt32 amtForwardToPlugin = NS_PTR_TO_INT32(mDataForwardToRequest->Get(&key)); mDataForwardToRequest->Put(&key, NS_INT32_TO_PTR(amtForwardToPlugin + aLength));  mPluginStreamInfo->SetStreamOffset(absoluteOffset + amtForwardToPlugin); }  nsCOMPtr<nsIInputStream> stream = aIStream;      if (mFileCacheOutputStream) { rv = NS_NewInputStreamTee(getter_AddRefs(stream), aIStream, mFileCacheOutputStream); if (NS_FAILED(rv)) return rv; }  rv =  mPStreamListener->OnDataAvailable(mPluginStreamInfo, stream, aLength);    if (NS_FAILED(rv)) request->Cancel(rv); } else {  char* buffer = new char[aLength]; PRUint32 amountRead, amountWrote = 0; rv = aIStream->Read(buffer, aLength, &amountRead);   if (mFileCacheOutputStream) { while (amountWrote < amountRead && NS_SUCCEEDED(rv)) { rv = mFileCacheOutputStream->Write(buffer, amountRead, &amountWrote); } } delete [] buffer; }
PR_Free(buffer);
NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request,                                                           nsISupports* aContext,                                                           nsIInputStream *aIStream,                                                           PRUint32 sourceOffset,                                                           PRUint32 aLength){  if (mRequestFailed)    return NS_ERROR_FAILURE;  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;  if(!mPStreamListener || !mPluginStreamInfo)    return NS_ERROR_FAILURE;  mPluginStreamInfo->SetRequest(request);  const char * url = nsnull;  mPluginStreamInfo->GetURL(&url);  PLUGIN_LOG(PLUGIN_LOG_NOISY,  ("nsPluginStreamListenerPeer::OnDataAvailable this=%p request=%p, offset=%d, length=%d, url=%s\n",  this, request, sourceOffset, aLength, url ? url : "no url set"));  // 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;    if (brr) {      if (!mDataForwardToRequest)        return NS_ERROR_FAILURE;      brr->GetStartRange(&absoluteOffset);      // we need to track how much data we have forwarded to the      // plugin.      // FIXME: http://bugzilla.mozilla.org/show_bug.cgi?id=240130      //      // Why couldn't this be tracked on the plugin info, and not in a      // *hash table*?      nsPRUintKey key(absoluteOffset);      PRInt32 amtForwardToPlugin =        NS_PTR_TO_INT32(mDataForwardToRequest->Get(&key));      mDataForwardToRequest->Put(&key, NS_INT32_TO_PTR(amtForwardToPlugin + aLength));      mPluginStreamInfo->SetStreamOffset(absoluteOffset + amtForwardToPlugin);    }    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.    if (mFileCacheOutputStream) {        rv = NS_NewInputStreamTee(getter_AddRefs(stream), aIStream, mFileCacheOutputStream);        if (NS_FAILED(rv))             return rv;    }    rv =  mPStreamListener->OnDataAvailable(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.    if (mFileCacheOutputStream) {      while (amountWrote < amountRead && NS_SUCCEEDED(rv)) {        rv = mFileCacheOutputStream->Write(buffer, amountRead, &amountWrote);      }    }    delete [] buffer;  }  return rv;}