PRLibrary* lib = nsnull; PRBool started = PR_FALSE; if(mInst) { lib = mInst->fLibrary; started = mInst->IsStarted(); }
NS_TRY_SAFE_CALL_RETURN(numtowrite, CallNPP_WriteReadyProc(callbacks->writeready, npp, &mNPStream), lib);
ns4xPluginStreamListener::OnDataAvailable(nsIPluginStreamInfo* pluginInfo,                                          nsIInputStream* input,                                          PRUint32 length){	const NPPluginFuncs *callbacks;  NPP       npp;  PRUint32  numtowrite = 0;  PRUint32  amountRead = 0;  PRInt32   writeCount = 0;  pluginInfo->GetURL(&mNPStream.url);  pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified));  mInst->GetCallbacks(&callbacks);  mInst->GetNPP(&npp);  if (callbacks->write == NULL || length == 0)    return NS_OK; // XXX ?	// Get the data from the input stream  char* buffer = (char*) PR_Malloc(length);  if (buffer)     input->Read(buffer, length, &amountRead);  // amountRead tells us how many bytes were put in the buffer  // WriteReady returns to us how many bytes the plugin is   // ready to handle  - we have to keep calling WriteReady and  // Write until the buffer is empty  while (amountRead > 0)  {    if (callbacks->writeready != NULL)    {#if !TARGET_CARBON      // pinkerton      // relies on routine descriptors, not present in carbon.       // We need to fix this.    PRLibrary* lib = nsnull;    PRBool started = PR_FALSE;    if(mInst) {      lib = mInst->fLibrary;      started = mInst->IsStarted();    }    if (started)    {      NS_TRY_SAFE_CALL_RETURN(numtowrite, CallNPP_WriteReadyProc(callbacks->writeready,                                              npp,                                              &mNPStream), lib);    }#endif		          // if WriteReady returned 0, the plugin is not ready to handle       // the data, return FAILURE for now      if(numtowrite <= 0)        return NS_ERROR_FAILURE;      if (numtowrite > amountRead)        numtowrite = amountRead;    }    else       // if WriteReady is not supported by the plugin,       // just write the whole buffer      numtowrite = length;    if(numtowrite > 0)    {#if !TARGET_CARBON      // pinkerton      // relies on routine descriptors, not present in carbon.       // We need to fix this.      PRLibrary* lib = nsnull;      if(mInst)        lib = mInst->fLibrary;      NS_TRY_SAFE_CALL_RETURN(writeCount, CallNPP_WriteProc(callbacks->write,                              npp,                              &mNPStream,                               mPosition,                              numtowrite,                              (void *)buffer), lib);      if(writeCount < 0)        return NS_ERROR_FAILURE;#endif      amountRead -= numtowrite;      mPosition += numtowrite;    }  }  return NS_OK;}