Added NewChannelFromNativePath for convenience.

This commit is contained in:
warren%netscape.com 1999-06-16 04:15:22 +00:00
Родитель 158480b852
Коммит 98606d8e53
3 изменённых файлов: 31 добавлений и 4 удалений

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

@ -18,10 +18,6 @@
#include "nsISupports.idl"
%{C++
#include "nscore.h" // for PRUnichar
%}
interface nsIProtocolHandler;
interface nsIURI;
interface nsIEventSinkGetter;
@ -31,6 +27,7 @@ interface nsIStreamListener;
interface nsIEventQueue;
interface nsIBufferInputStream;
interface nsIBufferOutputStream;
interface nsIFileChannel;
[scriptable, uuid(01f0a170-1881-11d3-9337-00104ba0fd40)]
interface nsIIOService : nsISupports
@ -128,6 +125,11 @@ interface nsIIOService : nsISupports
nsIStreamListener NewSyncStreamListener(out nsIBufferInputStream inStream,
out nsIBufferOutputStream outStream);
/**
* This convenience routine first looks up the file protocol handler, and
* then uses it to construct a file channel from a native path string.
*/
nsIFileChannel NewChannelFromNativePath(in string nativePath);
};
%{C++

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

@ -29,6 +29,7 @@
#include "prprf.h"
#include "prmem.h" // for PR_Malloc
#include <ctype.h> // for isalpha
#include "nsIFileProtocolHandler.h" // for NewChannelFromNativePath
static NS_DEFINE_CID(kFileTransportService, NS_FILETRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
@ -292,6 +293,29 @@ nsIOService::NewSyncStreamListener(nsIBufferInputStream **inStream,
}
NS_IMETHODIMP
nsIOService::NewChannelFromNativePath(const char *nativePath, nsIFileChannel **result)
{
nsresult rv;
nsIProtocolHandler* handler;
rv = GetProtocolHandler("file", &handler);
if (NS_FAILED(rv)) return rv;
nsIFileProtocolHandler* fileHandler = nsnull;
rv = handler->QueryInterface(nsIFileProtocolHandler::GetIID(),
(void**)&fileHandler);
NS_RELEASE(handler);
if (NS_FAILED(rv)) return rv;
nsIFileChannel* channel;
rv = fileHandler->NewChannelFromNativePath(nativePath, &channel);
NS_RELEASE(fileHandler);
if (NS_FAILED(rv)) return rv;
*result = channel;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// HELPER ROUTINES
////////////////////////////////////////////////////////////////////////////////

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

@ -51,6 +51,7 @@ public:
NS_IMETHOD NewAsyncStreamObserver(nsIStreamObserver *receiver, nsIEventQueue *eventQueue, nsIStreamObserver **_retval);
NS_IMETHOD NewAsyncStreamListener(nsIStreamListener *receiver, nsIEventQueue *eventQueue, nsIStreamListener **_retval);
NS_IMETHOD NewSyncStreamListener(nsIBufferInputStream **inStream, nsIBufferOutputStream **outStream, nsIStreamListener **_retval);
NS_IMETHOD NewChannelFromNativePath(const char *nativePath, nsIFileChannel **_retval);
// nsIOService methods:
nsIOService();