зеркало из https://github.com/mozilla/pjs.git
fixes bug 97528 "1200 urls created on startup about:blank" (take 2)
r=dp, sr=brendan
This commit is contained in:
Родитель
a522c8de8a
Коммит
19b5bdab36
|
@ -270,16 +270,20 @@ NS_IMETHODIMP
|
|||
nsJARChannel::AsyncOpen(nsIStreamListener* listener, nsISupports* ctxt)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
mUserContext = ctxt;
|
||||
mUserListener = listener;
|
||||
mSynchronousRead = PR_FALSE;
|
||||
|
||||
if (mLoadGroup) {
|
||||
rv = mLoadGroup->AddRequest(this, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
mSynchronousRead = PR_FALSE;
|
||||
return EnsureJARFileAvailable();
|
||||
rv = EnsureJARFileAvailable();
|
||||
if (NS_FAILED(rv) && mLoadGroup)
|
||||
mLoadGroup->RemoveRequest(this, nsnull, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -288,30 +292,43 @@ nsJARChannel::EnsureJARFileAvailable()
|
|||
nsresult rv;
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: EnsureJARFileAvailable %s", (const char*)jarURLStr));
|
||||
if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: EnsureJARFileAvailable %s", (const char*)jarURLStr));
|
||||
}
|
||||
#endif
|
||||
|
||||
rv = mURI->GetJARFile(getter_AddRefs(mJARBaseURI));
|
||||
if (NS_FAILED(rv)) goto error;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mURI->GetJAREntry(&mJAREntry);
|
||||
if (NS_FAILED(rv)) goto error;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_NewDownloader(getter_AddRefs(mDownloader),
|
||||
mJARBaseURI, this, nsnull, mSynchronousRead,
|
||||
mLoadGroup, mCallbacks, mLoadFlags);
|
||||
// try to get a nsIFile directly from the url, which will often succeed.
|
||||
{
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mJARBaseURI);
|
||||
if (fileURL)
|
||||
fileURL->GetFile(getter_AddRefs(mDownloadedJARFile));
|
||||
}
|
||||
|
||||
// if DownloadComplete() was called early, need to release the reference.
|
||||
if (mSynchronousRead && mSynchronousInputStream)
|
||||
mDownloader = null_nsCOMPtr();
|
||||
if (mDownloadedJARFile) {
|
||||
// after successfully downloading the jar file to the cache,
|
||||
// start the extraction process:
|
||||
if (mSynchronousRead)
|
||||
rv = OpenJARElement();
|
||||
else
|
||||
rv = AsyncReadJARElement();
|
||||
}
|
||||
else {
|
||||
rv = NS_NewDownloader(getter_AddRefs(mDownloader),
|
||||
mJARBaseURI, this, nsnull, mSynchronousRead,
|
||||
mLoadGroup, mCallbacks, mLoadFlags);
|
||||
|
||||
error:
|
||||
if (NS_FAILED(rv) && mLoadGroup) {
|
||||
nsresult rv2 = mLoadGroup->RemoveRequest(this, nsnull, NS_OK);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv2), "RemoveChannel failed");
|
||||
// if DownloadComplete() was called early, need to release the reference.
|
||||
if (mSynchronousRead && mSynchronousInputStream)
|
||||
mDownloader = 0;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -340,10 +357,12 @@ nsJARChannel::AsyncReadJARElement()
|
|||
}
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: AsyncRead jar entry %s", (const char*)jarURLStr));
|
||||
if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: AsyncRead jar entry %s", (const char*)jarURLStr));
|
||||
}
|
||||
#endif
|
||||
|
||||
rv = jarTransport->AsyncRead(this, nsnull, 0, PRUint32(-1), 0,
|
||||
|
@ -566,13 +585,15 @@ nsJARChannel::OnStopRequest(nsIRequest* jarExtractionTransport, nsISupports* con
|
|||
{
|
||||
nsresult rv;
|
||||
#ifdef PR_LOGGING
|
||||
nsCOMPtr<nsIURI> jarURI;
|
||||
nsXPIDLCString jarURLStr;
|
||||
rv = mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: jar extraction complete %s status=%x",
|
||||
(const char*)jarURLStr, aStatus));
|
||||
if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
|
||||
nsCOMPtr<nsIURI> jarURI;
|
||||
nsXPIDLCString jarURLStr;
|
||||
rv = mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: jar extraction complete %s status=%x",
|
||||
(const char*)jarURLStr, aStatus));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -656,10 +677,12 @@ NS_IMETHODIMP
|
|||
nsJARChannel::GetInputStream(nsIInputStream* *aInputStream)
|
||||
{
|
||||
#ifdef PR_LOGGING
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: GetInputStream jar entry %s", (const char*)jarURLStr));
|
||||
if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: GetInputStream jar entry %s", (const char*)jarURLStr));
|
||||
}
|
||||
#endif
|
||||
NS_ENSURE_TRUE(mJAR, NS_ERROR_NULL_POINTER);
|
||||
return mJAR->GetInputStream(mJAREntry, aInputStream);
|
||||
|
|
|
@ -270,16 +270,20 @@ NS_IMETHODIMP
|
|||
nsJARChannel::AsyncOpen(nsIStreamListener* listener, nsISupports* ctxt)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
mUserContext = ctxt;
|
||||
mUserListener = listener;
|
||||
mSynchronousRead = PR_FALSE;
|
||||
|
||||
if (mLoadGroup) {
|
||||
rv = mLoadGroup->AddRequest(this, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
mSynchronousRead = PR_FALSE;
|
||||
return EnsureJARFileAvailable();
|
||||
rv = EnsureJARFileAvailable();
|
||||
if (NS_FAILED(rv) && mLoadGroup)
|
||||
mLoadGroup->RemoveRequest(this, nsnull, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -288,30 +292,43 @@ nsJARChannel::EnsureJARFileAvailable()
|
|||
nsresult rv;
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: EnsureJARFileAvailable %s", (const char*)jarURLStr));
|
||||
if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: EnsureJARFileAvailable %s", (const char*)jarURLStr));
|
||||
}
|
||||
#endif
|
||||
|
||||
rv = mURI->GetJARFile(getter_AddRefs(mJARBaseURI));
|
||||
if (NS_FAILED(rv)) goto error;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mURI->GetJAREntry(&mJAREntry);
|
||||
if (NS_FAILED(rv)) goto error;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_NewDownloader(getter_AddRefs(mDownloader),
|
||||
mJARBaseURI, this, nsnull, mSynchronousRead,
|
||||
mLoadGroup, mCallbacks, mLoadFlags);
|
||||
// try to get a nsIFile directly from the url, which will often succeed.
|
||||
{
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mJARBaseURI);
|
||||
if (fileURL)
|
||||
fileURL->GetFile(getter_AddRefs(mDownloadedJARFile));
|
||||
}
|
||||
|
||||
// if DownloadComplete() was called early, need to release the reference.
|
||||
if (mSynchronousRead && mSynchronousInputStream)
|
||||
mDownloader = null_nsCOMPtr();
|
||||
if (mDownloadedJARFile) {
|
||||
// after successfully downloading the jar file to the cache,
|
||||
// start the extraction process:
|
||||
if (mSynchronousRead)
|
||||
rv = OpenJARElement();
|
||||
else
|
||||
rv = AsyncReadJARElement();
|
||||
}
|
||||
else {
|
||||
rv = NS_NewDownloader(getter_AddRefs(mDownloader),
|
||||
mJARBaseURI, this, nsnull, mSynchronousRead,
|
||||
mLoadGroup, mCallbacks, mLoadFlags);
|
||||
|
||||
error:
|
||||
if (NS_FAILED(rv) && mLoadGroup) {
|
||||
nsresult rv2 = mLoadGroup->RemoveRequest(this, nsnull, NS_OK);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv2), "RemoveChannel failed");
|
||||
// if DownloadComplete() was called early, need to release the reference.
|
||||
if (mSynchronousRead && mSynchronousInputStream)
|
||||
mDownloader = 0;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -340,10 +357,12 @@ nsJARChannel::AsyncReadJARElement()
|
|||
}
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: AsyncRead jar entry %s", (const char*)jarURLStr));
|
||||
if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: AsyncRead jar entry %s", (const char*)jarURLStr));
|
||||
}
|
||||
#endif
|
||||
|
||||
rv = jarTransport->AsyncRead(this, nsnull, 0, PRUint32(-1), 0,
|
||||
|
@ -566,13 +585,15 @@ nsJARChannel::OnStopRequest(nsIRequest* jarExtractionTransport, nsISupports* con
|
|||
{
|
||||
nsresult rv;
|
||||
#ifdef PR_LOGGING
|
||||
nsCOMPtr<nsIURI> jarURI;
|
||||
nsXPIDLCString jarURLStr;
|
||||
rv = mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: jar extraction complete %s status=%x",
|
||||
(const char*)jarURLStr, aStatus));
|
||||
if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
|
||||
nsCOMPtr<nsIURI> jarURI;
|
||||
nsXPIDLCString jarURLStr;
|
||||
rv = mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: jar extraction complete %s status=%x",
|
||||
(const char*)jarURLStr, aStatus));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -656,10 +677,12 @@ NS_IMETHODIMP
|
|||
nsJARChannel::GetInputStream(nsIInputStream* *aInputStream)
|
||||
{
|
||||
#ifdef PR_LOGGING
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: GetInputStream jar entry %s", (const char*)jarURLStr));
|
||||
if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: GetInputStream jar entry %s", (const char*)jarURLStr));
|
||||
}
|
||||
#endif
|
||||
NS_ENSURE_TRUE(mJAR, NS_ERROR_NULL_POINTER);
|
||||
return mJAR->GetInputStream(mJAREntry, aInputStream);
|
||||
|
|
|
@ -75,4 +75,9 @@ interface nsIResProtocolHandler : nsIProtocolHandler
|
|||
* Returns true if substitutions are already defined for the specified root.
|
||||
*/
|
||||
boolean hasSubstitutions(in string root);
|
||||
|
||||
/**
|
||||
* Resolution utility function.
|
||||
*/
|
||||
string resolveURI(in nsIURI resourceURI);
|
||||
};
|
||||
|
|
|
@ -31,7 +31,6 @@ LIBRARY_NAME = nkres_s
|
|||
REQUIRES = xpcom string exthandler mimetype
|
||||
|
||||
CPPSRCS = \
|
||||
nsResChannel.cpp \
|
||||
nsResProtocolHandler.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
@ -41,6 +40,10 @@ EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
|
|||
# static lib.
|
||||
FORCE_STATIC_LIB = 1
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
-I$(DEPTH)/netwerk/base/src \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
|
|
|
@ -28,10 +28,13 @@ LIBRARY_NAME=nkres_s
|
|||
LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsResChannel.obj \
|
||||
.\$(OBJDIR)\nsResProtocolHandler.obj \
|
||||
$(NULL)
|
||||
|
||||
INCS = $(INCS) \
|
||||
-I$(DEPTH)\netwerk\base\src \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* IBM Corp.
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsResProtocolHandler.h"
|
||||
|
@ -26,25 +27,65 @@
|
|||
#include "nsIURL.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsResChannel.h"
|
||||
#include "nsIFileChannel.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "prenv.h"
|
||||
#include "prmem.h"
|
||||
#include "prprf.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsResURL : overrides nsStdURL::GetFile to provide nsIFile resolution
|
||||
|
||||
#include "nsStdURL.h"
|
||||
|
||||
class nsResURL : public nsStdURL
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD GetFile(nsIFile **);
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsResURL::GetFile(nsIFile **result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_ENSURE_TRUE(nsResProtocolHandler::get(), NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
nsXPIDLCString spec;
|
||||
rv = nsResProtocolHandler::get()->ResolveURI(this, getter_Copies(spec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> localFile =
|
||||
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = localFile->SetURL(spec);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return CallQueryInterface(localFile, result);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsResProtocolHandler *nsResProtocolHandler::mGlobalInstance = nsnull;
|
||||
|
||||
nsResProtocolHandler::nsResProtocolHandler()
|
||||
: mLock(nsnull), mSubstitutions(32)
|
||||
: mSubstitutions(32)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
NS_ASSERTION(!mGlobalInstance, "res handler already created!");
|
||||
mGlobalInstance = this;
|
||||
}
|
||||
|
||||
nsResProtocolHandler::~nsResProtocolHandler()
|
||||
{
|
||||
mGlobalInstance = nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -55,14 +96,8 @@ nsResProtocolHandler::SetSpecialDir(const char* rootName, const char* sysDir)
|
|||
rv = NS_GetSpecialDirectory(sysDir, getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_CreateInstance(kStandardURLCID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = fileURL->SetFile(file);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString spec;
|
||||
rv = fileURL->GetSpec(getter_Copies(spec));
|
||||
rv = file->GetURL(getter_Copies(spec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return AppendSubstitution(rootName, spec);
|
||||
|
@ -73,9 +108,8 @@ nsResProtocolHandler::Init()
|
|||
{
|
||||
nsresult rv;
|
||||
|
||||
mLock = PR_NewLock();
|
||||
if (mLock == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
mIOService = do_GetIOService(&rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// set up initial mappings
|
||||
rv = SetSpecialDir("ProgramDir", NS_OS_CURRENT_PROCESS_DIR);
|
||||
|
@ -121,12 +155,6 @@ nsResProtocolHandler::Init()
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsResProtocolHandler::~nsResProtocolHandler()
|
||||
{
|
||||
if (mLock)
|
||||
PR_DestroyLock(mLock);
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(nsResProtocolHandler, nsIResProtocolHandler, nsIProtocolHandler, nsISupportsWeakReference)
|
||||
|
||||
NS_METHOD
|
||||
|
@ -179,23 +207,16 @@ nsResProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
|||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIURI> url(do_CreateInstance(kStandardURLCID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsResURL *resURL;
|
||||
NS_NEWXPCOM(resURL, nsResURL);
|
||||
if (!resURL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(resURL);
|
||||
|
||||
if (aBaseURI) {
|
||||
nsXPIDLCString aResolvedURI;
|
||||
rv = aBaseURI->Resolve(aSpec, getter_Copies(aResolvedURI));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = url->SetSpec(aResolvedURI);
|
||||
} else {
|
||||
rv = url->SetSpec((char*)aSpec);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
*result = url;
|
||||
NS_ADDREF(*result);
|
||||
rv = resURL->Init(nsIStandardURL::URLTYPE_STANDARD, -1, aSpec, aBaseURI);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = CallQueryInterface(resURL, result);
|
||||
NS_RELEASE(resURL);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -203,19 +224,15 @@ NS_IMETHODIMP
|
|||
nsResProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsResChannel* channel;
|
||||
rv = nsResChannel::Create(nsnull, NS_GET_IID(nsIResChannel), (void**)&channel);
|
||||
nsXPIDLCString spec;
|
||||
|
||||
rv = ResolveURI(uri, getter_Copies(spec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->Init(this, uri);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
}
|
||||
rv = mIOService->NewChannel(spec, nsnull, result);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = (nsIChannel*)(nsIResChannel*)channel;
|
||||
return NS_OK;
|
||||
return (*result)->SetOriginalURI(uri);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -231,12 +248,9 @@ NS_IMETHODIMP
|
|||
nsResProtocolHandler::PrependSubstitution(const char *root, const char *urlStr)
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoLock lock(mLock);
|
||||
|
||||
nsCOMPtr<nsIIOService> ioServ = do_GetIOService(&rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIURI> url;
|
||||
rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url));
|
||||
rv = mIOService->NewURI(urlStr, nsnull, getter_AddRefs(url));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCStringKey key(root);
|
||||
|
@ -268,12 +282,9 @@ NS_IMETHODIMP
|
|||
nsResProtocolHandler::AppendSubstitution(const char *root, const char *urlStr)
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoLock lock(mLock);
|
||||
|
||||
nsCOMPtr<nsIIOService> ioServ = do_GetIOService(&rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIURI> url;
|
||||
rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url));
|
||||
rv = mIOService->NewURI(urlStr, nsnull, getter_AddRefs(url));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCStringKey key(root);
|
||||
|
@ -324,12 +335,9 @@ NS_IMETHODIMP
|
|||
nsResProtocolHandler::RemoveSubstitution(const char *root, const char *urlStr)
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoLock lock(mLock);
|
||||
|
||||
nsCOMPtr<nsIIOService> ioServ = do_GetIOService(&rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIURI> url;
|
||||
rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url));
|
||||
rv = mIOService->NewURI(urlStr, nsnull, getter_AddRefs(url));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCStringKey key(root);
|
||||
|
@ -361,7 +369,6 @@ NS_IMETHODIMP
|
|||
nsResProtocolHandler::GetSubstitutions(const char *root, nsISupportsArray* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoLock lock(mLock);
|
||||
|
||||
nsCStringKey key(root);
|
||||
nsISupportsArray* strings = (nsISupportsArray*)mSubstitutions.Get(&key);
|
||||
|
@ -382,4 +389,35 @@ nsResProtocolHandler::HasSubstitutions(const char *root, PRBool *result)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsResProtocolHandler::ResolveURI(nsIURI *uri, char **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPIDLCString host, path;
|
||||
|
||||
rv = uri->GetHost(getter_Copies(host));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = uri->GetPath(getter_Copies(path));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> substitutions;
|
||||
rv = GetSubstitutions(host.get() ?
|
||||
host.get() : "", getter_AddRefs(substitutions));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// always use the first substitution
|
||||
nsCOMPtr<nsIURI> substURI;
|
||||
substitutions->GetElementAt(0, getter_AddRefs(substURI));
|
||||
if (!substURI) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
rv = substURI->Resolve(path[0] == '/' ? path+1 : path, result);
|
||||
#if 0
|
||||
nsXPIDLCString spec;
|
||||
uri->GetSpec(getter_Copies(spec));
|
||||
printf("%s\n -> %s\n", spec.get(), *result);
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef nsResProtocolHandler_h___
|
||||
|
@ -26,6 +27,7 @@
|
|||
#include "nsIResProtocolHandler.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
class nsResProtocolHandler : public nsIResProtocolHandler, public nsSupportsWeakReference
|
||||
|
@ -45,9 +47,13 @@ public:
|
|||
nsresult Init();
|
||||
nsresult SetSpecialDir(const char* rootName, const char* specialDir);
|
||||
|
||||
protected:
|
||||
PRLock* mLock;
|
||||
nsSupportsHashtable mSubstitutions;
|
||||
static nsResProtocolHandler *get() { return mGlobalInstance; }
|
||||
|
||||
private:
|
||||
static nsResProtocolHandler *mGlobalInstance;
|
||||
|
||||
nsSupportsHashtable mSubstitutions;
|
||||
nsCOMPtr<nsIIOService> mIOService;
|
||||
};
|
||||
|
||||
#endif /* nsResProtocolHandler_h___ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче