1999-06-11 01:37:24 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-06-11 01:37:24 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-06-11 01:37:24 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-06-11 01:37:24 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:40:37 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-06-11 01:37:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsFileChannel.h"
|
1999-06-12 07:14:19 +00:00
|
|
|
#include "nsIURL.h"
|
1999-07-23 06:16:37 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-07-03 00:59:51 +00:00
|
|
|
#include "nsIMIMEService.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "netCore.h"
|
1999-09-16 01:16:22 +00:00
|
|
|
#include "nsIFileTransportService.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsInt64.h"
|
2000-02-09 05:04:52 +00:00
|
|
|
#include "nsMimeTypes.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "prio.h" // Need to pick up def of PR_RDONLY
|
1999-07-03 00:59:51 +00:00
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
2000-01-24 21:28:28 +00:00
|
|
|
static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID);
|
|
|
|
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
1999-06-11 01:37:24 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsFileChannel::nsFileChannel()
|
1999-11-17 08:14:52 +00:00
|
|
|
: mLoadAttributes(LOAD_NORMAL)
|
1999-06-11 01:37:24 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-01-24 21:28:28 +00:00
|
|
|
nsFileChannel::Init(const char* command,
|
1999-11-17 08:14:52 +00:00
|
|
|
nsIURI* uri,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
1999-11-18 07:36:41 +00:00
|
|
|
nsIInterfaceRequestor* notificationCallbacks,
|
1999-11-17 08:14:52 +00:00
|
|
|
nsLoadFlags loadAttributes,
|
1999-12-04 10:01:32 +00:00
|
|
|
nsIURI* originalURI,
|
|
|
|
PRUint32 bufferSegmentSize,
|
|
|
|
PRUint32 bufferMaxSize)
|
1999-06-11 01:37:24 +00:00
|
|
|
{
|
1999-06-12 01:41:12 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-10-26 09:16:24 +00:00
|
|
|
mOriginalURI = originalURI ? originalURI : uri;
|
1999-06-12 01:41:12 +00:00
|
|
|
mURI = uri;
|
1999-09-16 01:16:22 +00:00
|
|
|
mCommand = nsCRT::strdup(command);
|
1999-12-04 10:01:32 +00:00
|
|
|
mBufferSegmentSize = bufferSegmentSize;
|
|
|
|
mBufferMaxSize = bufferMaxSize;
|
1999-09-16 01:16:22 +00:00
|
|
|
if (mCommand == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-12 01:41:12 +00:00
|
|
|
|
1999-11-17 08:14:52 +00:00
|
|
|
rv = SetLoadAttributes(loadAttributes);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = SetLoadGroup(aLoadGroup);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = SetNotificationCallbacks(notificationCallbacks);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-08-26 22:45:55 +00:00
|
|
|
|
1999-07-23 06:16:37 +00:00
|
|
|
// if we support the nsIURL interface then use it to get just
|
1999-09-06 19:57:40 +00:00
|
|
|
// the file path with no other garbage!
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mURI, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// this URL doesn't denote a file
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
1999-09-06 19:57:40 +00:00
|
|
|
}
|
1999-06-12 01:41:12 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = fileURL->GetFile(getter_AddRefs(mFile));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
return rv;
|
1999-06-11 01:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFileChannel::~nsFileChannel()
|
|
|
|
{
|
1999-09-20 20:53:13 +00:00
|
|
|
if (mCommand) nsCRT::free(mCommand);
|
1999-06-11 01:37:24 +00:00
|
|
|
}
|
|
|
|
|
2000-03-14 03:18:26 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS5(nsFileChannel,
|
1999-11-17 08:14:52 +00:00
|
|
|
nsIFileChannel,
|
|
|
|
nsIChannel,
|
|
|
|
nsIRequest,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIStreamObserver)
|
1999-06-11 01:37:24 +00:00
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsFileChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
|
|
|
|
{
|
|
|
|
nsFileChannel* fc = new nsFileChannel();
|
|
|
|
if (fc == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(fc);
|
|
|
|
nsresult rv = fc->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(fc);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-06-12 02:53:21 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// From nsIRequest
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-07-01 19:30:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::IsPending(PRBool *result)
|
|
|
|
{
|
1999-09-16 01:16:22 +00:00
|
|
|
if (mFileTransport)
|
|
|
|
return mFileTransport->IsPending(result);
|
|
|
|
*result = PR_FALSE;
|
1999-09-06 19:57:40 +00:00
|
|
|
return NS_OK;
|
1999-07-01 19:30:20 +00:00
|
|
|
}
|
|
|
|
|
1999-06-12 02:53:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::Cancel()
|
|
|
|
{
|
1999-09-16 01:16:22 +00:00
|
|
|
if (mFileTransport)
|
|
|
|
return mFileTransport->Cancel();
|
|
|
|
return NS_OK;
|
1999-06-12 02:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::Suspend()
|
|
|
|
{
|
1999-09-16 01:16:22 +00:00
|
|
|
if (mFileTransport)
|
|
|
|
return mFileTransport->Suspend();
|
|
|
|
return NS_OK;
|
1999-06-12 02:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::Resume()
|
|
|
|
{
|
1999-09-16 01:16:22 +00:00
|
|
|
if (mFileTransport)
|
|
|
|
return mFileTransport->Resume();
|
|
|
|
return NS_OK;
|
1999-06-12 02:53:21 +00:00
|
|
|
}
|
|
|
|
|
1999-06-11 01:37:24 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// From nsIChannel
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-10-26 09:16:24 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::GetOriginalURI(nsIURI * *aURI)
|
|
|
|
{
|
|
|
|
*aURI = mOriginalURI;
|
|
|
|
NS_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-11 01:37:24 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::GetURI(nsIURI * *aURI)
|
|
|
|
{
|
1999-06-12 01:41:12 +00:00
|
|
|
*aURI = mURI;
|
1999-09-16 01:16:22 +00:00
|
|
|
NS_ADDREF(*aURI);
|
1999-06-12 01:41:12 +00:00
|
|
|
return NS_OK;
|
1999-06-11 01:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-12 07:14:19 +00:00
|
|
|
nsFileChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
|
|
|
nsIInputStream **result)
|
1999-06-11 01:37:24 +00:00
|
|
|
{
|
1999-06-12 07:14:19 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
if (mFileTransport)
|
1999-06-12 07:14:19 +00:00
|
|
|
return NS_ERROR_IN_PROGRESS;
|
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
1999-08-03 22:00:17 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = fts->CreateTransport(mFile, PR_RDONLY, mCommand, 0, 0, getter_AddRefs(mFileTransport));
|
1999-11-23 07:01:56 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
1999-11-17 08:14:52 +00:00
|
|
|
|
|
|
|
rv = mFileTransport->SetNotificationCallbacks(mCallbacks);
|
1999-11-23 07:01:56 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
1999-06-15 05:18:40 +00:00
|
|
|
|
1999-11-23 07:01:56 +00:00
|
|
|
rv = mFileTransport->OpenInputStream(startPosition, readCount, result);
|
|
|
|
done:
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// release the transport so that we don't think we're in progress
|
|
|
|
mFileTransport = nsnull;
|
|
|
|
}
|
|
|
|
return rv;
|
1999-06-15 05:18:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
if (mFileTransport)
|
1999-06-15 05:18:40 +00:00
|
|
|
return NS_ERROR_IN_PROGRESS;
|
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
1999-06-15 05:18:40 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-16 01:16:22 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = fts->CreateTransport(mFile, PR_RDONLY, mCommand, mBufferSegmentSize, mBufferMaxSize,
|
1999-12-04 10:01:32 +00:00
|
|
|
getter_AddRefs(mFileTransport));
|
1999-11-23 07:01:56 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
1999-11-17 08:14:52 +00:00
|
|
|
|
|
|
|
rv = mFileTransport->SetNotificationCallbacks(mCallbacks);
|
1999-11-23 07:01:56 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
1999-09-16 01:16:22 +00:00
|
|
|
|
1999-11-23 07:01:56 +00:00
|
|
|
rv = mFileTransport->OpenOutputStream(startPosition, result);
|
|
|
|
done:
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// release the transport so that we don't think we're in progress
|
|
|
|
mFileTransport = nsnull;
|
|
|
|
}
|
|
|
|
return rv;
|
1999-06-11 01:37:24 +00:00
|
|
|
}
|
|
|
|
|
1999-10-06 08:26:01 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-06-11 01:37:24 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
|
|
|
nsISupports *ctxt,
|
1999-07-20 08:46:33 +00:00
|
|
|
nsIStreamListener *listener)
|
1999-06-11 01:37:24 +00:00
|
|
|
{
|
1999-09-16 01:16:22 +00:00
|
|
|
nsresult rv;
|
1999-06-12 08:07:05 +00:00
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
if (mFileTransport)
|
|
|
|
return NS_ERROR_IN_PROGRESS;
|
1999-06-29 01:52:30 +00:00
|
|
|
|
1999-09-03 22:03:12 +00:00
|
|
|
mRealListener = listener;
|
1999-10-05 20:54:03 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> tempListener = this;
|
1999-06-12 07:14:19 +00:00
|
|
|
|
1999-08-26 22:45:55 +00:00
|
|
|
if (mLoadGroup) {
|
|
|
|
nsCOMPtr<nsILoadGroupListenerFactory> factory;
|
|
|
|
//
|
|
|
|
// Create a load group "proxy" listener...
|
|
|
|
//
|
|
|
|
rv = mLoadGroup->GetGroupListenerFactory(getter_AddRefs(factory));
|
|
|
|
if (factory) {
|
1999-09-16 01:16:22 +00:00
|
|
|
nsIStreamListener *newListener;
|
|
|
|
rv = factory->CreateLoadGroupListener(mRealListener, &newListener);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mRealListener = newListener;
|
|
|
|
NS_RELEASE(newListener);
|
|
|
|
}
|
1999-08-26 22:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rv = mLoadGroup->AddChannel(this, nsnull);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
1999-06-12 07:14:19 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = fts->CreateTransport(mFile, PR_RDONLY, mCommand, mBufferSegmentSize, mBufferMaxSize,
|
1999-12-04 10:01:32 +00:00
|
|
|
getter_AddRefs(mFileTransport));
|
1999-11-23 07:01:56 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
1999-11-17 08:14:52 +00:00
|
|
|
|
|
|
|
rv = mFileTransport->SetNotificationCallbacks(mCallbacks);
|
1999-11-23 07:01:56 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
1999-09-16 01:16:22 +00:00
|
|
|
|
1999-11-23 07:01:56 +00:00
|
|
|
rv = mFileTransport->AsyncRead(startPosition, readCount, ctxt, tempListener);
|
|
|
|
done:
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// release the transport so that we don't think we're in progress
|
|
|
|
mFileTransport = nsnull;
|
|
|
|
}
|
|
|
|
return rv;
|
1999-06-11 01:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::AsyncWrite(nsIInputStream *fromStream,
|
|
|
|
PRUint32 startPosition, PRInt32 writeCount,
|
|
|
|
nsISupports *ctxt,
|
1999-07-20 08:46:33 +00:00
|
|
|
nsIStreamObserver *observer)
|
1999-06-11 01:37:24 +00:00
|
|
|
{
|
1999-09-16 01:16:22 +00:00
|
|
|
nsresult rv;
|
1999-06-12 07:14:19 +00:00
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
if (mFileTransport)
|
|
|
|
return NS_ERROR_IN_PROGRESS;
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = fts->CreateTransport(mFile, PR_RDONLY, mCommand, mBufferSegmentSize, mBufferMaxSize,
|
1999-12-04 10:01:32 +00:00
|
|
|
getter_AddRefs(mFileTransport));
|
1999-11-23 07:01:56 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
1999-11-17 08:14:52 +00:00
|
|
|
|
|
|
|
rv = mFileTransport->SetNotificationCallbacks(mCallbacks);
|
1999-11-23 07:01:56 +00:00
|
|
|
if (NS_FAILED(rv)) goto done;
|
1999-09-16 01:16:22 +00:00
|
|
|
|
1999-11-23 07:01:56 +00:00
|
|
|
rv = mFileTransport->AsyncWrite(fromStream, startPosition, writeCount, ctxt, observer);
|
|
|
|
done:
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// release the transport so that we don't think we're in progress
|
|
|
|
mFileTransport = nsnull;
|
|
|
|
}
|
|
|
|
return rv;
|
1999-06-11 01:37:24 +00:00
|
|
|
}
|
|
|
|
|
1999-06-22 00:19:58 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-24 22:58:42 +00:00
|
|
|
nsFileChannel::GetLoadAttributes(PRUint32 *aLoadAttributes)
|
1999-06-22 00:19:58 +00:00
|
|
|
{
|
1999-06-24 22:58:42 +00:00
|
|
|
*aLoadAttributes = mLoadAttributes;
|
1999-06-22 00:19:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-24 22:58:42 +00:00
|
|
|
nsFileChannel::SetLoadAttributes(PRUint32 aLoadAttributes)
|
1999-06-22 00:19:58 +00:00
|
|
|
{
|
1999-06-24 22:58:42 +00:00
|
|
|
mLoadAttributes = aLoadAttributes;
|
1999-06-22 00:19:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::GetContentType(char * *aContentType)
|
|
|
|
{
|
1999-07-23 06:16:37 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2000-01-08 06:26:04 +00:00
|
|
|
*aContentType = nsnull;
|
|
|
|
if (mContentType.IsEmpty()) {
|
2000-01-24 21:28:28 +00:00
|
|
|
PRBool directory;
|
|
|
|
mFile->IsDirectory(&directory);
|
|
|
|
if (directory) {
|
2000-01-08 06:26:04 +00:00
|
|
|
mContentType = "application/http-index-format";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_WITH_SERVICE(nsIMIMEService, MIMEService, kMIMEServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = MIMEService->GetTypeFromURI(mURI, aContentType);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mContentType = *aContentType;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1999-07-03 00:59:51 +00:00
|
|
|
|
2000-01-08 06:26:04 +00:00
|
|
|
if (mContentType.IsEmpty()) {
|
2000-02-09 05:04:52 +00:00
|
|
|
mContentType = UNKNOWN_CONTENT_TYPE;
|
2000-01-08 06:26:04 +00:00
|
|
|
}
|
1999-08-24 04:23:55 +00:00
|
|
|
}
|
2000-01-08 06:26:04 +00:00
|
|
|
*aContentType = mContentType.ToNewCString();
|
1999-07-03 00:59:51 +00:00
|
|
|
|
|
|
|
if (!*aContentType) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
} else {
|
1999-07-03 03:54:28 +00:00
|
|
|
return NS_OK;
|
1999-07-03 00:59:51 +00:00
|
|
|
}
|
1999-06-22 00:19:58 +00:00
|
|
|
}
|
|
|
|
|
2000-01-08 06:26:04 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::SetContentType(const char *aContentType)
|
|
|
|
{
|
|
|
|
mContentType = aContentType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-09 05:07:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::GetContentLength(PRInt32 *aContentLength)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-01-24 21:28:28 +00:00
|
|
|
PRInt64 size;
|
|
|
|
rv = mFile->GetFileSize(&size);
|
1999-09-09 05:07:30 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-01-24 21:28:28 +00:00
|
|
|
*aContentLength = nsInt64(size);
|
1999-09-09 05:07:30 +00:00
|
|
|
} else {
|
|
|
|
*aContentLength = -1;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-07-31 06:53:12 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-17 08:14:52 +00:00
|
|
|
nsFileChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
1999-07-31 06:53:12 +00:00
|
|
|
{
|
|
|
|
*aLoadGroup = mLoadGroup;
|
|
|
|
NS_IF_ADDREF(*aLoadGroup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-29 21:58:42 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-17 08:14:52 +00:00
|
|
|
nsFileChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
|
|
|
{
|
1999-11-30 22:19:53 +00:00
|
|
|
mLoadGroup = aLoadGroup;
|
|
|
|
|
2000-01-15 06:12:54 +00:00
|
|
|
return NS_OK;
|
1999-11-17 08:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::GetOwner(nsISupports* *aOwner)
|
1999-08-29 21:58:42 +00:00
|
|
|
{
|
1999-09-11 19:43:06 +00:00
|
|
|
*aOwner = mOwner.get();
|
1999-09-11 18:45:36 +00:00
|
|
|
NS_IF_ADDREF(*aOwner);
|
1999-08-29 21:58:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-17 08:14:52 +00:00
|
|
|
nsFileChannel::SetOwner(nsISupports* aOwner)
|
1999-08-29 21:58:42 +00:00
|
|
|
{
|
1999-09-11 18:45:36 +00:00
|
|
|
mOwner = aOwner;
|
1999-08-29 21:58:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-31 06:53:12 +00:00
|
|
|
|
1999-11-17 08:14:52 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-18 07:36:41 +00:00
|
|
|
nsFileChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
|
1999-11-17 08:14:52 +00:00
|
|
|
{
|
|
|
|
*aNotificationCallbacks = mCallbacks.get();
|
|
|
|
NS_IF_ADDREF(*aNotificationCallbacks);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-18 07:36:41 +00:00
|
|
|
nsFileChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
|
1999-11-17 08:14:52 +00:00
|
|
|
{
|
|
|
|
mCallbacks = aNotificationCallbacks;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-17 22:06:32 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
|
|
|
{
|
|
|
|
*aSecurityInfo = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-26 22:45:55 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIStreamListener methods:
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-16 01:16:22 +00:00
|
|
|
nsFileChannel::OnStartRequest(nsIChannel* transportChannel, nsISupports* context)
|
1999-08-26 22:45:55 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mRealListener, "No listener...");
|
1999-09-16 01:16:22 +00:00
|
|
|
return mRealListener->OnStartRequest(this, context);
|
1999-08-26 22:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-16 01:16:22 +00:00
|
|
|
nsFileChannel::OnStopRequest(nsIChannel* transportChannel, nsISupports* context,
|
|
|
|
nsresult aStatus, const PRUnichar* aMsg)
|
1999-08-26 22:45:55 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
rv = mRealListener->OnStopRequest(this, context, aStatus, aMsg);
|
1999-09-06 19:57:40 +00:00
|
|
|
|
1999-08-26 22:45:55 +00:00
|
|
|
if (mLoadGroup) {
|
1999-09-16 01:16:22 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mLoadGroup->RemoveChannel(this, context, aStatus, aMsg);
|
|
|
|
}
|
1999-08-26 22:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Release the reference to the consumer stream listener...
|
|
|
|
mRealListener = null_nsCOMPtr();
|
1999-09-16 01:16:22 +00:00
|
|
|
mFileTransport = null_nsCOMPtr();
|
1999-08-26 22:45:55 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-16 01:16:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileChannel::OnDataAvailable(nsIChannel* transportChannel, nsISupports* context,
|
|
|
|
nsIInputStream *aIStream, PRUint32 aSourceOffset,
|
|
|
|
PRUint32 aLength)
|
|
|
|
{
|
1999-11-24 23:51:09 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = mRealListener->OnDataAvailable(this, context, aIStream,
|
|
|
|
aSourceOffset, aLength);
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the connection is being aborted cancel the transport. This will
|
|
|
|
// insure that the transport will go away even if it is blocked waiting
|
|
|
|
// for the consumer to empty the pipe...
|
|
|
|
//
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mFileTransport->Cancel();
|
|
|
|
}
|
|
|
|
return rv;
|
1999-09-16 01:16:22 +00:00
|
|
|
}
|
|
|
|
|
1999-06-11 01:37:24 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// From nsIFileChannel
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-01-24 21:28:28 +00:00
|
|
|
nsFileChannel::Init(nsIFile* file,
|
|
|
|
PRInt32 mode,
|
|
|
|
const char* contentType,
|
|
|
|
PRInt32 contentLength,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsIInterfaceRequestor* notificationCallbacks,
|
|
|
|
nsLoadFlags loadAttributes,
|
|
|
|
nsIURI* originalURI,
|
|
|
|
PRUint32 bufferSegmentSize,
|
|
|
|
PRUint32 bufferMaxSize)
|
1999-06-12 07:14:19 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsIFileURL> url;
|
|
|
|
rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull,
|
|
|
|
NS_GET_IID(nsIFileURL),
|
|
|
|
getter_AddRefs(url));
|
1999-06-12 07:14:19 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-06-11 01:37:24 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = url->SetFile(file);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-06 19:57:40 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
return Init("load", // XXX
|
|
|
|
url,
|
|
|
|
aLoadGroup,
|
|
|
|
notificationCallbacks,
|
|
|
|
loadAttributes,
|
|
|
|
originalURI,
|
|
|
|
bufferSegmentSize,
|
|
|
|
bufferMaxSize);
|
1999-06-12 07:14:19 +00:00
|
|
|
}
|
|
|
|
|
1999-11-12 06:13:13 +00:00
|
|
|
NS_IMETHODIMP
|
2000-01-24 21:28:28 +00:00
|
|
|
nsFileChannel::GetFile(nsIFile* *result)
|
1999-11-12 06:13:13 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
*result = mFile;
|
|
|
|
NS_ADDREF(*result);
|
1999-11-12 06:13:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-12 07:14:19 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
1999-08-27 10:33:37 +00:00
|
|
|
|
1999-08-24 22:30:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-08-25 21:21:22 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
|