зеркало из https://github.com/mozilla/gecko-dev.git
Added methods to nsINetService to get and set cookie string for a URL
This commit is contained in:
Родитель
92e85525b5
Коммит
5639f27847
|
@ -77,6 +77,24 @@ struct nsINetService : public nsISupports
|
||||||
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||||
*/
|
*/
|
||||||
NS_IMETHOD GetContainerApplication(nsINetContainerApplication **aContainer)=0;
|
NS_IMETHOD GetContainerApplication(nsINetContainerApplication **aContainer)=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the complete cookie string associated with the URL
|
||||||
|
*
|
||||||
|
* @param aURL The URL for which to get the cookie string
|
||||||
|
* @param aCookie The string object which will hold the result
|
||||||
|
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||||
|
*/
|
||||||
|
NS_IMETHOD GetCookieString(nsIURL *aURL, nsString& aCookie)=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the cookie string associated with the URL
|
||||||
|
*
|
||||||
|
* @param aURL The URL for which to set the cookie string
|
||||||
|
* @param aCookie The string to set
|
||||||
|
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||||
|
*/
|
||||||
|
NS_IMETHOD SetCookieString(nsIURL *aURL, const nsString& aCookie)=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ extern "C" {
|
||||||
#include "cvchunk.h"
|
#include "cvchunk.h"
|
||||||
};
|
};
|
||||||
#include "netcache.h"
|
#include "netcache.h"
|
||||||
|
#include "cookies.h"
|
||||||
#include "plstr.h"
|
#include "plstr.h"
|
||||||
|
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
|
@ -402,6 +403,42 @@ nsNetlibService::SetContainerApplication(nsINetContainerApplication *aContainer)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsNetlibService::GetCookieString(nsIURL *aURL, nsString& aCookie)
|
||||||
|
{
|
||||||
|
// XXX How safe is it to create a stub context without a URL_Struct?
|
||||||
|
MWContext *stubContext = new_stub_context(nsnull);
|
||||||
|
|
||||||
|
const char *spec = aURL->GetSpec();
|
||||||
|
char *cookie = NET_GetCookie(stubContext, (char *)spec);
|
||||||
|
|
||||||
|
if (nsnull != cookie) {
|
||||||
|
aCookie.SetString(cookie);
|
||||||
|
PR_FREEIF(cookie);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
aCookie.SetString("");
|
||||||
|
}
|
||||||
|
|
||||||
|
free_stub_context(stubContext);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsNetlibService::SetCookieString(nsIURL *aURL, const nsString& aCookie)
|
||||||
|
{
|
||||||
|
// XXX How safe is it to create a stub context without a URL_Struct?
|
||||||
|
MWContext *stubContext = new_stub_context(nsnull);
|
||||||
|
|
||||||
|
const char *spec = aURL->GetSpec();
|
||||||
|
char *cookie = aCookie.ToNewCString();
|
||||||
|
|
||||||
|
NET_SetCookieString(stubContext, (char *)spec, cookie);
|
||||||
|
|
||||||
|
PR_FREEIF(cookie);
|
||||||
|
free_stub_context(stubContext);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,9 @@ public:
|
||||||
NS_IMETHOD GetContainerApplication(nsINetContainerApplication **aContainer);
|
NS_IMETHOD GetContainerApplication(nsINetContainerApplication **aContainer);
|
||||||
nsresult SetContainerApplication(nsINetContainerApplication *aContainer);
|
nsresult SetContainerApplication(nsINetContainerApplication *aContainer);
|
||||||
|
|
||||||
|
NS_IMETHOD GetCookieString(nsIURL *aURL, nsString& aCookie);
|
||||||
|
NS_IMETHOD SetCookieString(nsIURL *aURL, const nsString& aCookie);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~nsNetlibService();
|
virtual ~nsNetlibService();
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ static nsIStreamListener *getStreamListener(URL_Struct *URL_s)
|
||||||
{
|
{
|
||||||
nsIStreamListener *res = NULL;
|
nsIStreamListener *res = NULL;
|
||||||
|
|
||||||
if (URL_s->fe_data) {
|
if (URL_s && URL_s->fe_data) {
|
||||||
/*
|
/*
|
||||||
* Retrieve the nsConnectionInfo object from the fe_data field
|
* Retrieve the nsConnectionInfo object from the fe_data field
|
||||||
* of the URL_Struct...
|
* of the URL_Struct...
|
||||||
|
|
Загрузка…
Ссылка в новой задаче