diff --git a/netwerk/base/public/nsIIOService.idl b/netwerk/base/public/nsIIOService.idl index 89334d1d9aa9..14b06e1e87e9 100644 --- a/netwerk/base/public/nsIIOService.idl +++ b/netwerk/base/public/nsIIOService.idl @@ -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++ diff --git a/netwerk/base/src/nsIOService.cpp b/netwerk/base/src/nsIOService.cpp index 2ead13f2eebd..0341b426d7f0 100644 --- a/netwerk/base/src/nsIOService.cpp +++ b/netwerk/base/src/nsIOService.cpp @@ -29,6 +29,7 @@ #include "prprf.h" #include "prmem.h" // for PR_Malloc #include // 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 //////////////////////////////////////////////////////////////////////////////// diff --git a/netwerk/base/src/nsIOService.h b/netwerk/base/src/nsIOService.h index 079b576a2b33..68ebe8c46e8d 100644 --- a/netwerk/base/src/nsIOService.h +++ b/netwerk/base/src/nsIOService.h @@ -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();