Changed file transport to facilitate jar: protocol -- parameterized by nsIFileSystem. Bug#12579 r=gagan,gayatrib

This commit is contained in:
warren%netscape.com 1999-10-28 08:02:07 +00:00
Родитель e1f53e872b
Коммит d3269bc410
4 изменённых файлов: 63 добавлений и 35 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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<nsISupports> 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<nsIFileSystem> 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<nsIFileSystem> 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<nsISupports> 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()

Просмотреть файл

@ -62,6 +62,9 @@ public:
PRInt32 contentLength,
const char* command,
nsIEventSinkGetter* getter);
nsresult Init(nsIFileSystem* fsObj,
const char* command,
nsIEventSinkGetter* getter);
void Process(void);

Просмотреть файл

@ -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)
{