From b99466aa41441000f3da267da563ffecceb5c917 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Fri, 2 Apr 1999 19:05:52 +0000 Subject: [PATCH] Landing changes to support chrome URLs in netlib. Approved by dp. --- network/module/makefile.win | 1 + network/module/nsHttpURLFactory.cpp | 2 + network/module/nsNetService.cpp | 61 ++++++++++++++++++++++++++++- network/module/nsNetService.h | 7 ++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/network/module/makefile.win b/network/module/makefile.win index 098be9cc1e8..99c918b1ed5 100644 --- a/network/module/makefile.win +++ b/network/module/makefile.win @@ -148,6 +148,7 @@ LINCS=$(LINCS) -I. \ -I$(PUBLIC)\sockstub \ -I$(PUBLIC)\remoturl \ -I$(PUBLIC)\netlib \ + -I$(PUBLIC)\chrome \ $(NULL) # clobber and clobber_all will remove the following garbage: diff --git a/network/module/nsHttpURLFactory.cpp b/network/module/nsHttpURLFactory.cpp index 8fb54097a3e..e340351e0c0 100644 --- a/network/module/nsHttpURLFactory.cpp +++ b/network/module/nsHttpURLFactory.cpp @@ -108,6 +108,8 @@ NS_InitializeHttpURLFactory(nsINetService* inet) if (rv != NS_OK) goto done; inet->RegisterProtocol(*new nsString("resource"), urlf, NULL); if (rv != NS_OK) goto done; + inet->RegisterProtocol(*new nsString("chrome"), urlf, NULL); + if (rv != NS_OK) goto done; inet->RegisterProtocol(*new nsString("file"), urlf, NULL); if (rv != NS_OK) goto done; inet->RegisterProtocol(*new nsString("javascript"), urlf, NULL); diff --git a/network/module/nsNetService.cpp b/network/module/nsNetService.cpp index e8fddc9bfa1..173a62e1fc1 100644 --- a/network/module/nsNetService.cpp +++ b/network/module/nsNetService.cpp @@ -51,6 +51,8 @@ extern "C" { #include "nsCRT.h" #include "nsSocketTransport.h" +#include "nsIChromeRegistry.h" + #ifdef XP_PC #include static HINSTANCE g_hInst = NULL; @@ -102,7 +104,8 @@ static void bam_exit_routine(URL_Struct *URL_s, int status, MWContext *window_id nsresult PerformNastyWindowsAsyncDNSHack(URL_Struct* URL_s, nsIURL* aURL); #endif /* XP_WIN && !NETLIB_THREAD */ -char *mangleResourceIntoFileURL(const char* aResourceFileName) ; +char *mangleResourceIntoFileURL(const char* aResourceFileName); + extern nsIStreamListener* ns_NewStreamListenerProxy(nsIStreamListener* aListener, PLEventQueue* aEventQ); extern "C" { @@ -126,6 +129,11 @@ static NS_DEFINE_IID(kINetlibURLIID, NS_INETLIBURL_IID); static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); +// Chrome registry service for handling of chrome URLs +static NS_DEFINE_IID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID); +static NS_DEFINE_IID(kIChromeRegistryIID, NS_ICHROMEREGISTRY_IID); +nsIChromeRegistry* nsNetlibService::gChromeRegistry = nsnull; +int nsNetlibService::gRefCnt = 0; nsNetlibService::nsNetlibService() { @@ -209,6 +217,20 @@ nsNetlibService::nsNetlibService() mProtocols = new nsHashtable(); PR_ASSERT(mProtocols); + + // Create the chrome registry. If it fails, that's ok. + gRefCnt++; + + if (gRefCnt == 1) + { + gChromeRegistry = nsnull; + if (NS_FAILED(nsServiceManager::GetService(kChromeRegistryCID, + kIChromeRegistryIID, + (nsISupports **)&gChromeRegistry))) { + gChromeRegistry = nsnull; + } + else gChromeRegistry->Init(); // Load the chrome registry + } } @@ -220,6 +242,13 @@ nsNetlibService::~nsNetlibService() { TRACEMSG(("nsNetlibService is being destroyed...\n")); + gRefCnt--; + if (gRefCnt == 0) + { + NS_IF_RELEASE(gChromeRegistry); + gChromeRegistry = nsnull; + } + /* if (NULL != m_stubContext) { free_stub_context((MWContext *)m_stubContext); @@ -363,6 +392,20 @@ nsresult nsNetlibService::OpenStream(nsIURL *aUrl, const char* protocol; result = aUrl->GetProtocol(&protocol); NS_ASSERTION(result == NS_OK, "deal with this"); + + // Deal with chrome URLS + if ((PL_strcmp(protocol, "chrome") == 0) && + gChromeRegistry != nsnull) { + + if (NS_FAILED(result = gChromeRegistry->ConvertChromeURL(aUrl))) { + NS_ERROR("Unable to convert chrome URL."); + return result; + } + + result = aUrl->GetProtocol(&protocol); + NS_ASSERTION(result == NS_OK, "deal with this"); + } + if (PL_strcmp(protocol, "resource") == 0) { char* fileName; const char* file; @@ -372,7 +415,7 @@ nsresult nsNetlibService::OpenStream(nsIURL *aUrl, aUrl->SetSpec(fileName); PR_Free(fileName); } - + /* Create the URLStruct... */ const char* spec = NULL; @@ -504,6 +547,20 @@ nsresult nsNetlibService::OpenBlockingStream(nsIURL *aUrl, const char* protocol; result = aUrl->GetProtocol(&protocol); NS_ASSERTION(result == NS_OK, "deal with this"); + + // Deal with chrome URLS + if ((PL_strcmp(protocol, "chrome") == 0) && + gChromeRegistry != nsnull) { + + if (NS_FAILED(result = gChromeRegistry->ConvertChromeURL(aUrl))) { + NS_ERROR("Unable to convert chrome URL."); + return result; + } + + result = aUrl->GetProtocol(&protocol); + NS_ASSERTION(result == NS_OK, "deal with this"); + } + if (PL_strcmp(protocol, "resource") == 0) { char* fileName; const char* file; diff --git a/network/module/nsNetService.h b/network/module/nsNetService.h index 5b9eb9477ee..fc306c91f77 100644 --- a/network/module/nsNetService.h +++ b/network/module/nsNetService.h @@ -31,6 +31,9 @@ class nsITimer; +// The chrome registry interface +class nsIChromeRegistry; + class nsNetlibService : public nsINetService { public: @@ -116,6 +119,10 @@ protected: static void NetlibThreadMain(void *aParam); #endif /* NETLIB_THREAD */ + // Chrome Registry static variables + static nsIChromeRegistry* gChromeRegistry; + static int gRefCnt; + private: void SetupURLStruct(nsIURL *aURL, URL_Struct *aURL_s); /* XXX: This is temporary until bamwrap.cpp is removed... */