NS_IMETHODIMP
nsNPAPIPluginStreamListener::Notify(nsITimer *aTimer)
{
  NS_ASSERTION(aTimer == mDataPumpTimer, "Uh, wrong timer?");
  
  int32_t oldStreamBufferByteCount = mStreamBufferByteCount;
  
  nsresult rv = OnDataAvailable(mStreamListenerPeer, nullptr, mStreamBufferByteCount);
  
  if (NS_FAILED(rv)) {
    // We ran into an error, no need to keep firing this timer then.
    aTimer->Cancel();
    return NS_OK;
  }
  
  if (mStreamBufferByteCount != oldStreamBufferByteCount &&
      ((mStreamStarted && mStreamBufferByteCount < 1024) ||
       mStreamBufferByteCount == 0)) {
        // The plugin read some data and we've got less than 1024 bytes in
        // our buffer (or its empty and the stream is already
        // done). Resume the request so that we get more data off the
        // network.
        ResumeRequest();
        // Necko will pump data now that we've resumed the request.
        StopDataPump();
      }
  
  return NS_OK;
}
bool
nsNPAPIPluginStreamListener::SetStreamType(uint16_t aType, bool aNeedsResume)
{
  switch(aType)
  {
    case NP_NORMAL:
      mStreamType = NP_NORMAL;
      break;
    case NP_ASFILEONLY:
      mStreamType = NP_ASFILEONLY;
      break;
    case NP_ASFILE:
      mStreamType = NP_ASFILE;
      break;
    case NP_SEEK:
      mStreamType = NP_SEEK;
      // Seekable streams should continue to exist even after OnStopRequest
      // is fired, so we AddRef ourself an extra time and Release when the
      // plugin calls NPN_DestroyStream (CleanUpStream). If the plugin never
      // calls NPN_DestroyStream the stream will be destroyed before the plugin
      // instance is destroyed.
      NS_ADDREF_THIS();
      break;
    default:
      return false;
  }
  mStreamStarted = true;
  if (aNeedsResume) {
    if (mStreamListenerPeer) {
      mStreamListenerPeer->OnStreamTypeSet(mStreamType);
    }
    ResumeRequest();
  }
  return true;
}
bool
nsNPAPIPluginStreamListener::SetStreamType(uint16_t aType, bool aNeedsResume)
{
  switch(aType)
  {
    case NP_NORMAL:
      mStreamType = NP_NORMAL;
      break;
    case NP_ASFILEONLY:
      mStreamType = NP_ASFILEONLY;
      break;
    case NP_ASFILE:
      mStreamType = NP_ASFILE;
      break;
    case NP_SEEK:
      mStreamType = NP_SEEK;
      // Seekable streams should continue to exist even after OnStopRequest
      // is fired, so we AddRef ourself an extra time and Release when the
      // plugin calls NPN_DestroyStream (CleanUpStream). If the plugin never
      // calls NPN_DestroyStream the stream will be destroyed before the plugin
      // instance is destroyed.
      NS_ADDREF_THIS();
      break;
    case nsPluginStreamListenerPeer::STREAM_TYPE_UNKNOWN:
      MOZ_ASSERT(!aNeedsResume);
      mStreamType = nsPluginStreamListenerPeer::STREAM_TYPE_UNKNOWN;
      // In this case we just want to set mStreamType but we do not want to
      // execute anything else in this function.
      return true;
    default:
      return false;
  }
  mStreamState = eStreamTypeSet;
  if (aNeedsResume) {
    if (mStreamListenerPeer) {
      mStreamListenerPeer->OnStreamTypeSet(mStreamType);
    }
    ResumeRequest();
  }
  return true;
}