From dce1fc7e3b229c4f4db12800e358277ce1dba46f Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Thu, 28 Oct 1999 08:02:07 +0000 Subject: [PATCH] Changed file transport to facilitate jar: protocol -- parameterized by nsIFileSystem. Bug#12579 r=gagan,gayatrib --- .../base/public/nsIFileTransportService.idl | 7 +- netwerk/base/src/nsFileTransport.cpp | 68 +++++++++---------- netwerk/base/src/nsFileTransport.h | 3 + netwerk/base/src/nsFileTransportService.cpp | 20 ++++++ 4 files changed, 63 insertions(+), 35 deletions(-) diff --git a/netwerk/base/public/nsIFileTransportService.idl b/netwerk/base/public/nsIFileTransportService.idl index 82ca80d7366..eb8f56d1be5 100644 --- a/netwerk/base/public/nsIFileTransportService.idl +++ b/netwerk/base/public/nsIFileTransportService.idl @@ -22,12 +22,13 @@ %} interface nsIChannel; +interface nsIFileSystem; interface nsIEventSinkGetter; interface nsIInputStream; interface nsIRunnable; native nsFileSpec(nsFileSpec&); -[scriptable, uuid(d4ced500-6882-11d3-9382-00104ba0fd40)] +[scriptable, uuid(57211a60-8c45-11d3-93ac-00104ba0fd40)] interface nsIFileTransportService : nsISupports { [noscript] nsIChannel createTransport(in nsFileSpec spec, // XXX change to nsIFile later @@ -42,6 +43,10 @@ interface nsIFileTransportService : nsISupports in string command, in nsIEventSinkGetter getter); + nsIChannel createTransportFromFileSystem(in nsIFileSystem fsObj, + in string command, + in nsIEventSinkGetter getter); + void dispatchRequest(in nsIRunnable runnable); void suspend(in nsIRunnable trans); void resume(in nsIRunnable trans); diff --git a/netwerk/base/src/nsFileTransport.cpp b/netwerk/base/src/nsFileTransport.cpp index 688c45e054d..91561217173 100644 --- a/netwerk/base/src/nsFileTransport.cpp +++ b/netwerk/base/src/nsFileTransport.cpp @@ -285,55 +285,55 @@ nsresult nsFileTransport::Init(nsFileSpec& spec, const char* command, nsIEventSinkGetter* getter) { nsresult rv; - if (mMonitor == nsnull) { - mMonitor = nsAutoMonitor::NewMonitor("nsFileTransport"); - if (mMonitor == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - } mSpec = spec; - rv = nsLocalFileSystem::Create(spec, getter_AddRefs(mFileObject)); - if (NS_FAILED(rv)) - return rv; - if (getter) { - nsCOMPtr sink; - (void)getter->GetEventSink(command, - nsIProgressEventSink::GetIID(), getter_AddRefs(sink)); - if (sink) - { - // Now generate a proxied event sink- - NS_WITH_SERVICE(nsIProxyObjectManager, - proxyMgr, kProxyObjectManagerCID, &rv); - if (NS_SUCCEEDED(rv)) - { - rv = proxyMgr->GetProxyObject( - nsnull, // primordial thread - should change? - NS_GET_IID(nsIProgressEventSink), - sink, - PROXY_ASYNC | PROXY_ALWAYS, - getter_AddRefs(mProgress)); - } - } - } - return NS_OK; + nsCOMPtr fsObj; + rv = nsLocalFileSystem::Create(spec, getter_AddRefs(fsObj)); + if (NS_FAILED(rv)) return rv; + return Init(fsObj, command, getter); } nsresult nsFileTransport::Init(nsIInputStream* fromStream, const char* contentType, PRInt32 contentLength, const char* command, nsIEventSinkGetter* getter) { + nsresult rv; + nsCOMPtr fsObj; + rv = nsInputStreamFileSystem::Create(fromStream, contentType, contentLength, + getter_AddRefs(fsObj)); + if (NS_FAILED(rv)) return rv; + return Init(fsObj, command, getter); +} + +nsresult +nsFileTransport::Init(nsIFileSystem* fsObj, + const char* command, + nsIEventSinkGetter* getter) +{ + nsresult rv = NS_OK; if (mMonitor == nsnull) { mMonitor = nsAutoMonitor::NewMonitor("nsFileTransport"); if (mMonitor == nsnull) return NS_ERROR_OUT_OF_MEMORY; } - nsInputStreamFileSystem::Create(fromStream, contentType, contentLength, - getter_AddRefs(mFileObject)); + mFileObject = fsObj; if (getter) { nsCOMPtr sink; - (void)getter->GetEventSink(command, nsIProgressEventSink::GetIID(), getter_AddRefs(sink)); - mProgress = (nsIProgressEventSink*)sink.get(); + rv = getter->GetEventSink(command, + nsIProgressEventSink::GetIID(), getter_AddRefs(sink)); + if (NS_FAILED(rv)) return NS_OK; // don't need a progress event sink + + // Now generate a proxied event sink + NS_WITH_SERVICE(nsIProxyObjectManager, + proxyMgr, kProxyObjectManagerCID, &rv); + if (NS_FAILED(rv)) return rv; + + rv = proxyMgr->GetProxyObject(nsnull, // primordial thread - should change? + NS_GET_IID(nsIProgressEventSink), + sink, + PROXY_ASYNC | PROXY_ALWAYS, + getter_AddRefs(mProgress)); } - return NS_OK; + return rv; } nsFileTransport::~nsFileTransport() diff --git a/netwerk/base/src/nsFileTransport.h b/netwerk/base/src/nsFileTransport.h index 9db29ecc7b1..e4ff20763f3 100644 --- a/netwerk/base/src/nsFileTransport.h +++ b/netwerk/base/src/nsFileTransport.h @@ -62,6 +62,9 @@ public: PRInt32 contentLength, const char* command, nsIEventSinkGetter* getter); + nsresult Init(nsIFileSystem* fsObj, + const char* command, + nsIEventSinkGetter* getter); void Process(void); diff --git a/netwerk/base/src/nsFileTransportService.cpp b/netwerk/base/src/nsFileTransportService.cpp index ae863710ac1..2235858db0b 100644 --- a/netwerk/base/src/nsFileTransportService.cpp +++ b/netwerk/base/src/nsFileTransportService.cpp @@ -119,6 +119,26 @@ nsFileTransportService::CreateTransportFromStream(nsIInputStream *fromStream, return NS_OK; } +NS_IMETHODIMP +nsFileTransportService::CreateTransportFromFileSystem(nsIFileSystem *fsObj, + const char *command, + nsIEventSinkGetter *getter, + nsIChannel **result) +{ + nsresult rv; + nsFileTransport* trans = new nsFileTransport(); + if (trans == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(trans); + rv = trans->Init(fsObj, command, getter); + if (NS_FAILED(rv)) { + NS_RELEASE(trans); + return rv; + } + *result = trans; + return NS_OK; +} + nsresult nsFileTransportService::ProcessPendingRequests(void) {