Delinking nsCookieHTTPNotify and cookie internal apis. Now the

nsCookieHTTPNotify calls the cookie api using the cookieservice. This
gets us to removing the nsCookieHTTPNotify off the cookie dll into
apprunner which would cause a delayed on demand load of the cookie
dll. r=neeti@netscape.com


git-svn-id: svn://10.0.0.236/trunk@54604 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dp%netscape.com 1999-11-29 22:02:20 +00:00
parent 7de4c964c0
commit fbcff1c752
4 changed files with 85 additions and 46 deletions

View File

@ -26,10 +26,13 @@
#include "nsIHTTPChannel.h"
#include "nsCookie.h"
#include "nsIURL.h"
#include "nsCOMPtr.h"
#include "nsIAtom.h"
#include "nsCRT.h"
#include "nsXPIDLString.h"
#include "nsIServiceManager.h"
#include "nsIAllocator.h"
#include "nsINetModuleMgr.h"
static NS_DEFINE_CID(kINetModuleMgrCID, NS_NETMODULEMGR_CID);
///////////////////////////////////
// nsISupports
@ -60,6 +63,19 @@ nsCookieHTTPNotify::Init()
if (!mSetCookieHeader) return NS_ERROR_OUT_OF_MEMORY;
mExpiresHeader = NS_NewAtom("date");
if (!mExpiresHeader) return NS_ERROR_OUT_OF_MEMORY;
// Register to handing http requests and responses
nsresult rv;
nsCOMPtr<nsINetModuleMgr> pNetModuleMgr = do_GetService(kINetModuleMgrCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_REQUEST_PROGID,
(nsIHTTPNotify *)this);
if (NS_FAILED(rv)) return rv;
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_RESPONSE_PROGID,
(nsIHTTPNotify *)this);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
@ -67,6 +83,15 @@ nsCookieHTTPNotify::~nsCookieHTTPNotify()
{
}
NS_IMETHODIMP
nsCookieHTTPNotify::SetupCookieService()
{
nsresult rv = NS_OK;
if (!mCookieService)
mCookieService = do_GetService(NS_COOKIESERVICE_PROGID, &rv);
return rv;
}
///////////////////////////////////
// nsIHTTPNotify
@ -74,7 +99,8 @@ NS_IMETHODIMP
nsCookieHTTPNotify::ModifyRequest(nsISupports *aContext)
{
nsresult rv;
if (!aContext) return NS_ERROR_NULL_POINTER;
// Preconditions
NS_ENSURE_ARG_POINTER(aContext);
nsCOMPtr<nsIHTTPChannel> pHTTPConnection = do_QueryInterface(aContext, &rv);
if (NS_FAILED(rv)) return rv;
@ -83,54 +109,57 @@ nsCookieHTTPNotify::ModifyRequest(nsISupports *aContext)
rv = pHTTPConnection->GetURI(getter_AddRefs(pURL));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString url;
rv = pURL->GetSpec(getter_Copies(url));
if (NS_FAILED(rv)) return rv;
if (url == nsnull) return NS_ERROR_FAILURE;
const char* cookie = ::COOKIE_GetCookie((char*)(const char*)url);
if (cookie == nsnull) return rv;
rv = pHTTPConnection->SetRequestHeader(mCookieHeader, cookie);
// Ensure that the cookie service exists
rv = SetupCookieService();
if (NS_FAILED(rv)) return rv;
return NS_OK;
nsString cookie;
rv = mCookieService->GetCookieString(pURL, cookie);
if (NS_FAILED(rv)) return rv;
// Set the cookie into the request headers
// XXX useless convertion from nsString to char * again
const char *cookieRaw = cookie.ToNewCString();
if (!cookieRaw) return NS_ERROR_OUT_OF_MEMORY;
rv = pHTTPConnection->SetRequestHeader(mCookieHeader, cookieRaw);
nsAllocator::Free((void *)cookieRaw);
return rv;
}
NS_IMETHODIMP
nsCookieHTTPNotify::AsyncExamineResponse(nsISupports *aContext)
{
nsresult rv;
// Preconditions
NS_ENSURE_ARG_POINTER(aContext);
nsCOMPtr<nsIHTTPChannel> pHTTPConnection = do_QueryInterface(aContext);
if (NS_FAILED(rv)) return rv;
// Get the Cookie header
nsXPIDLCString cookie;
rv = pHTTPConnection->GetResponseHeader(mSetCookieHeader, getter_Copies(cookie));
nsXPIDLCString cookieHeader;
rv = pHTTPConnection->GetResponseHeader(mSetCookieHeader, getter_Copies(cookieHeader));
if (NS_FAILED(rv)) return rv;
if (!cookie) return NS_ERROR_OUT_OF_MEMORY;
if (!cookieHeader) return NS_ERROR_OUT_OF_MEMORY;
// Get the url string
// Get the url
nsCOMPtr<nsIURI> pURL;
nsXPIDLCString url;
rv = pHTTPConnection->GetURI(getter_AddRefs(pURL));
if (NS_FAILED(rv)) return rv;
rv = pURL->GetSpec(getter_Copies(url));
if (NS_FAILED(rv)) return rv;
if (url == nsnull) return NS_ERROR_FAILURE;
// Get the expires
nsXPIDLCString pDate;
rv = pHTTPConnection->GetResponseHeader(mExpiresHeader, getter_Copies(pDate));
nsXPIDLCString expiresHeader;
rv = pHTTPConnection->GetResponseHeader(mExpiresHeader, getter_Copies(expiresHeader));
if (NS_FAILED(rv)) return rv;
// Ensure that we have the cookie service
rv = SetupCookieService();
if (NS_FAILED(rv)) return rv;
// Save the cookie
COOKIE_SetCookieStringFromHttp((char*)(const char*)url,
(char *)(const char *)cookie,
(char *)(const char *)pDate);
rv = mCookieService->SetCookieStringFromHttp(pURL, cookieHeader, expiresHeader);
return NS_OK;
return rv;
}

View File

@ -26,6 +26,7 @@
#include "nsIHttpNotify.h"
#include "nsCOMPtr.h"
#include "nsIAtom.h"
#include "nsICookieService.h"
// {6BC1F522-1F45-11d3-8AD4-00105A1B8860}
#define NS_COOKIEHTTPNOTIFY_CID \
@ -53,6 +54,9 @@ private:
nsCOMPtr<nsIAtom> mCookieHeader;
nsCOMPtr<nsIAtom> mSetCookieHeader;
nsCOMPtr<nsIAtom> mExpiresHeader;
nsCOMPtr<nsICookieService> mCookieService;
NS_IMETHOD SetupCookieService();
};
extern NS_EXPORT nsresult NS_NewCookieHTTPNotify(nsIHTTPNotify** aHTTPNotify);

View File

@ -27,17 +27,12 @@
#include "nsIServiceManager.h"
#include "nsICookieService.h"
#include "nsCookieHTTPNotify.h"
#include "nsINetModuleMgr.h"
#include "nsIEventQueueService.h"
#include "nsCRT.h"
#include "nsCookie.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kICookieServiceIID, NS_ICOOKIESERVICE_IID);
static NS_DEFINE_CID(kNetModuleMgrCID, NS_NETMODULEMGR_CID);
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
////////////////////////////////////////////////////////////////////////////////
@ -53,6 +48,7 @@ public:
NS_IMETHOD GetCookieString(nsIURI *aURL, nsString& aCookie);
NS_IMETHOD SetCookieString(nsIURI *aURL, const nsString& aCookie);
NS_IMETHOD SetCookieStringFromHttp(nsIURI *aURL, const char *aCookie, const char *aExpires);
NS_IMETHOD Cookie_RemoveAllCookies(void);
NS_IMETHOD Cookie_CookieViewerReturn(nsAutoString results);
NS_IMETHOD Cookie_GetCookieListForViewer(nsString& aCookieList);
@ -73,7 +69,7 @@ static nsCookieService* gCookieService = nsnull; // The one-and-only CookieServi
////////////////////////////////////////////////////////////////////////////////
// nsCookieService Implementation
NS_IMPL_ISUPPORTS(nsCookieService, kICookieServiceIID);
NS_IMPL_ISUPPORTS1(nsCookieService, nsICookieService);
NS_EXPORT nsresult NS_NewCookieService(nsICookieService** aCookieService) {
return nsCookieService::GetCookieService(aCookieService);
@ -105,9 +101,6 @@ nsresult nsCookieService::GetCookieService(nsICookieService** aCookieService) {
nsresult nsCookieService::Init() {
nsresult rv;
NS_WITH_SERVICE(nsINetModuleMgr, pNetModuleMgr, kNetModuleMgrCID, &rv);
if (NS_FAILED(rv)) return rv;
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = eventQService->CreateThreadEventQueue();
@ -116,11 +109,6 @@ nsresult nsCookieService::Init() {
if (NS_FAILED(rv = NS_NewCookieHTTPNotify(&mCookieHTTPNotify))) {
return rv;
}
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_REQUEST_PROGID, mCookieHTTPNotify);
if (NS_FAILED(rv)) return rv;
rv = pNetModuleMgr->RegisterModule(NS_NETWORK_MODULE_MANAGER_HTTP_RESPONSE_PROGID, mCookieHTTPNotify);
if (NS_FAILED(rv)) return rv;
COOKIE_RegisterCookiePrefCallbacks();
COOKIE_ReadCookies();
@ -156,6 +144,16 @@ nsCookieService::SetCookieString(nsIURI *aURL, const nsString& aCookie) {
return NS_OK;
}
NS_IMETHODIMP
nsCookieService::SetCookieStringFromHttp(nsIURI *aURL, const char *aCookie, const char *aExpires) {
char *spec = NULL;
nsresult rv = aURL->GetSpec(&spec);
if (NS_FAILED(rv)) return rv;
COOKIE_SetCookieStringFromHttp(spec, (char *)aCookie, (char *)aExpires);
nsCRT::free(spec);
return NS_OK;
}
NS_IMETHODIMP nsCookieService::Cookie_RemoveAllCookies(void) {
::COOKIE_RemoveAllCookies();
return NS_OK;
@ -219,9 +217,7 @@ CreateNewCookieService(nsISupports* aOuter, REFNSIID aIID, void **aResult)
//
static nsModuleComponentInfo components[] = {
{ "CookieService", NS_COOKIESERVICE_CID,
"component://netscape/cookie", CreateNewCookieService, }, // XXX Singleton
{ "CookieHTTPNotifyService", NS_COOKIEHTTPNOTIFY_CID,
"component://netscape/cookie-http-notify", CreateNewCookieService, },
NS_COOKIESERVICE_PROGID, CreateNewCookieService, }, // XXX Singleton
};
////////////////////////////////////////////////////////////////////////

View File

@ -58,6 +58,16 @@ public:
*/
NS_IMETHOD SetCookieString(nsIURI *aURL, const nsString& aCookie)=0;
/*
* Set the cookie string and expires associated with the URL
*
* @param aURL The URL for which to set the cookie string
* @param aCookie The char * string to set
* @param aExpires The expiry information of the cookie
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
*/
NS_IMETHOD SetCookieStringFromHttp(nsIURI *aURL, const char *aCookie, const char *aExpires)=0;
/*
* Blows away all permissions currently in the cookie permissions list,
* and then blows away all cookies currently in the cookie list.
@ -74,6 +84,6 @@ public:
/* ProgID prefixes for Cookie DLL registration. */
#define NS_COOKIESERVICE_PROGID "component:||netscape|cookie"
#define NS_COOKIESERVICE_PROGID "component://netscape/cookie"
#endif /* nsICookieService_h__ */