2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-01-24 01:10:34 +03:00
|
|
|
|
|
|
|
#include "nsSimpleStreamListener.h"
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2001-01-24 01:10:34 +03:00
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsISupports implementation...
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsSimpleStreamListener,
|
|
|
|
nsISimpleStreamListener,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver)
|
2001-01-24 01:10:34 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
2001-04-10 10:01:08 +04:00
|
|
|
// nsIRequestObserver implementation...
|
2001-01-24 01:10:34 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsSimpleStreamListener::OnStartRequest(nsIRequest *aRequest,
|
2001-01-24 01:10:34 +03:00
|
|
|
nsISupports *aContext)
|
|
|
|
{
|
|
|
|
return mObserver ?
|
2001-02-21 23:38:08 +03:00
|
|
|
mObserver->OnStartRequest(aRequest, aContext) : NS_OK;
|
2001-01-24 01:10:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsSimpleStreamListener::OnStopRequest(nsIRequest* request,
|
2001-01-24 01:10:34 +03:00
|
|
|
nsISupports *aContext,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsresult aStatus)
|
2001-01-24 01:10:34 +03:00
|
|
|
{
|
2008-02-10 03:01:36 +03:00
|
|
|
return mObserver ?
|
|
|
|
mObserver->OnStopRequest(request, aContext, aStatus) : NS_OK;
|
2001-01-24 01:10:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsIStreamListener implementation...
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsSimpleStreamListener::OnDataAvailable(nsIRequest* request,
|
2001-01-24 01:10:34 +03:00
|
|
|
nsISupports *aContext,
|
|
|
|
nsIInputStream *aSource,
|
2012-09-06 06:41:02 +04:00
|
|
|
uint64_t aOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aCount)
|
2001-01-24 01:10:34 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t writeCount;
|
2001-01-24 01:10:34 +03:00
|
|
|
nsresult rv = mSink->WriteFrom(aSource, aCount, &writeCount);
|
|
|
|
//
|
|
|
|
// Equate zero bytes read and NS_SUCCEEDED to stopping the read.
|
|
|
|
//
|
|
|
|
if (NS_SUCCEEDED(rv) && (writeCount == 0))
|
|
|
|
return NS_BASE_STREAM_CLOSED;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsISimpleStreamListener implementation...
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleStreamListener::Init(nsIOutputStream *aSink,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsIRequestObserver *aObserver)
|
2001-01-24 01:10:34 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aSink, "null output stream");
|
|
|
|
|
|
|
|
mSink = aSink;
|
|
|
|
mObserver = aObserver;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-05-19 05:02:57 +03:00
|
|
|
|
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|