зеркало из https://github.com/mozilla/gecko-dev.git
*** empty log message ***
This commit is contained in:
Родитель
d79137420a
Коммит
a150a17c4e
|
@ -52,6 +52,31 @@ nsCookieHTTPNotify::nsCookieHTTPNotify() {
|
|||
nsCookieHTTPNotify::~nsCookieHTTPNotify() {
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsCookieHTTPNotify::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) {
|
||||
if (! aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
*aResult = nsnull;
|
||||
nsresult rv;
|
||||
nsIHTTPNotify* inst = nsnull;
|
||||
if (NS_FAILED(rv = NS_NewCookieHTTPNotify(&inst))) {
|
||||
return rv;
|
||||
}
|
||||
if (!inst) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = NULL;
|
||||
}
|
||||
NS_RELEASE(inst);
|
||||
return rv;
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
// nsIHTTPNotify
|
||||
|
||||
|
@ -188,46 +213,3 @@ nsCookieHTTPNotify::AsyncExamineResponse(nsISupports *aContext) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsCookieHTTPFactory Implementation
|
||||
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
NS_IMPL_ISUPPORTS(nsCookieHTTPNotifyFactory, kIFactoryIID);
|
||||
|
||||
nsCookieHTTPNotifyFactory::nsCookieHTTPNotifyFactory(void) {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsCookieHTTPNotifyFactory::~nsCookieHTTPNotifyFactory(void) {
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCookieHTTPNotifyFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) {
|
||||
if (! aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
*aResult = nsnull;
|
||||
nsresult rv;
|
||||
nsIHTTPNotify* inst = nsnull;
|
||||
if (NS_FAILED(rv = NS_NewCookieHTTPNotify(&inst))) {
|
||||
return rv;
|
||||
}
|
||||
if (!inst) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = NULL;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCookieHTTPNotifyFactory::LockFactory(PRBool aLock) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -40,25 +40,14 @@ public:
|
|||
// nsCookieHTTPNotify methods:
|
||||
nsCookieHTTPNotify();
|
||||
virtual ~nsCookieHTTPNotify();
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
class nsCookieHTTPNotifyFactory : public nsIFactory {
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods:
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
// nsCookieHTTPNotifyFactory methods:
|
||||
nsCookieHTTPNotifyFactory(void);
|
||||
virtual ~nsCookieHTTPNotifyFactory(void);
|
||||
};
|
||||
|
||||
extern NS_EXPORT nsresult NS_NewCookieHTTPNotify(nsIHTTPNotify** aHTTPNotify);
|
||||
|
||||
#endif /* nsCookieHTTPNotify_h___ */
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#define NS_IMPL_IDS
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICookieService.h"
|
||||
|
@ -26,12 +27,15 @@
|
|||
#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);
|
||||
static NS_DEFINE_IID(kCookieServiceCID, NS_COOKIESERVICE_CID);
|
||||
static NS_DEFINE_IID(kCookieHTTPNotifyCID, NS_COOKIEHTTPNOTIFY_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -65,21 +69,25 @@ private:
|
|||
static nsCookieService* gCookieService = nsnull; // The one-and-only CookieService
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsCookieServiceFactory : public nsIFactory {
|
||||
// Module implementation
|
||||
class nsCookieServiceModule : public nsIModule
|
||||
{
|
||||
public:
|
||||
nsCookieServiceModule();
|
||||
virtual ~nsCookieServiceModule();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods:
|
||||
NS_DECL_NSIMODULE
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
protected:
|
||||
nsresult Initialize();
|
||||
|
||||
// nsCookieService methods:
|
||||
void Shutdown();
|
||||
|
||||
nsCookieServiceFactory(void);
|
||||
virtual ~nsCookieServiceFactory(void);
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIGenericFactory> mCookieServiceFactory;
|
||||
nsCOMPtr<nsIGenericFactory> mCookieHTTPNotifyFactory;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -196,109 +204,252 @@ NS_IMETHODIMP nsCookieService::Cookie_GetPermissionListForViewer(nsString& aPerm
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsCookieServiceFactory Implementation
|
||||
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
NS_IMPL_ISUPPORTS(nsCookieServiceFactory, kIFactoryIID);
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
nsCookieServiceFactory::nsCookieServiceFactory(void) {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
// Functions used to create new instances of a given object by the
|
||||
// generic factory.
|
||||
|
||||
nsCookieServiceFactory::~nsCookieServiceFactory(void) {
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCookieServiceFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) {
|
||||
if (! aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
*aResult = nsnull;
|
||||
nsresult rv;
|
||||
nsICookieService* inst = nsnull;
|
||||
if (NS_FAILED(rv = NS_NewCookieService(&inst))) {
|
||||
return rv;
|
||||
}
|
||||
if (!inst) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = NULL;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCookieServiceFactory::LockFactory(PRBool aLock) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DLL Entry Points:
|
||||
|
||||
static NS_DEFINE_IID(kCookieServiceCID, NS_COOKIESERVICE_CID);
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSGetFactory(
|
||||
nsISupports* servMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory) {
|
||||
if (! aFactory) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aClass.Equals(kCookieServiceCID)) {
|
||||
nsCookieServiceFactory *factory = new nsCookieServiceFactory();
|
||||
if (factory == nsnull) {
|
||||
static NS_IMETHODIMP
|
||||
CreateNewCookieService(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (!aResult) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
*aResult = nsnull;
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
nsICookieService* inst = nsnull;
|
||||
nsresult rv = NS_NewCookieService(&inst);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = nsnull;
|
||||
return rv;
|
||||
}
|
||||
if(!inst) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(factory);
|
||||
*aFactory = factory;
|
||||
return NS_OK;
|
||||
}
|
||||
if (aClass.Equals(kCookieHTTPNotifyCID)) {
|
||||
nsCookieHTTPNotifyFactory *factory = new nsCookieHTTPNotifyFactory();
|
||||
if (factory == nsnull) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = nsnull;
|
||||
}
|
||||
NS_RELEASE(inst); /* get rid of extra refcnt */
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
nsCookieServiceModule::nsCookieServiceModule()
|
||||
: mInitialized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsCookieServiceModule::~nsCookieServiceModule()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCookieServiceModule, NS_GET_IID(nsIModule))
|
||||
|
||||
// Perform our one-time intialization for this module
|
||||
nsresult
|
||||
nsCookieServiceModule::Initialize()
|
||||
{
|
||||
if (mInitialized) {
|
||||
return NS_OK;
|
||||
}
|
||||
NS_ADDREF(factory);
|
||||
*aFactory = factory;
|
||||
mInitialized = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT PRBool
|
||||
NSCanUnload(nsISupports* serviceMgr) {
|
||||
return PR_FALSE;
|
||||
// Shutdown this module, releasing all of the module resources
|
||||
void
|
||||
nsCookieServiceModule::Shutdown()
|
||||
{
|
||||
// Release the factory objects
|
||||
mCookieServiceFactory = nsnull;
|
||||
mCookieHTTPNotifyFactory = nsnull;
|
||||
}
|
||||
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSRegisterSelf(nsISupports* serviceMgr, const char* aPath) {
|
||||
nsresult rv;
|
||||
rv = nsComponentManager::RegisterComponent(kCookieServiceCID, "CookieService", NS_COOKIESERVICE_PROGID, aPath,PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
// Create a factory object for creating instances of aClass.
|
||||
NS_IMETHODIMP
|
||||
nsCookieServiceModule::GetClassObject(nsIComponentManager *aCompMgr,
|
||||
const nsCID& aClass,
|
||||
const nsIID& aIID,
|
||||
void** r_classObj)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Defensive programming: Initialize *r_classObj in case of error below
|
||||
if (!r_classObj) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*r_classObj = NULL;
|
||||
|
||||
// Do one-time-only initialization if necessary
|
||||
if (!mInitialized) {
|
||||
rv = Initialize();
|
||||
if (NS_FAILED(rv)) {
|
||||
// Initialization failed! yikes!
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// Choose the appropriate factory, based on the desired instance
|
||||
// class type (aClass).
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
if (aClass.Equals(kCookieServiceCID)) {
|
||||
if (!mCookieServiceFactory) {
|
||||
// Create and save away the factory object for creating
|
||||
// new instances of CookieService. This way if we are called
|
||||
// again for the factory, we won't need to create a new
|
||||
// one.
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mCookieServiceFactory),
|
||||
CreateNewCookieService);
|
||||
}
|
||||
fact = mCookieServiceFactory;
|
||||
}
|
||||
else if (aClass.Equals(kCookieHTTPNotifyCID)) {
|
||||
if (!mCookieHTTPNotifyFactory) {
|
||||
// Create and save away the factory object for creating
|
||||
// new instances of CookieHTTPNotify. This way if we are called
|
||||
// again for the factory, we won't need to create a new
|
||||
// one.
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mCookieHTTPNotifyFactory),
|
||||
nsCookieHTTPNotify::Create);
|
||||
}
|
||||
fact = mCookieHTTPNotifyFactory;
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
#ifdef DEBUG
|
||||
char* cs = aClass.ToString();
|
||||
printf("+++ nsCookieServiceModule: unable to create factory for %s\n", cs);
|
||||
nsCRT::free(cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (fact) {
|
||||
rv = fact->QueryInterface(aIID, r_classObj);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
rv = nsComponentManager::RegisterComponent(kCookieHTTPNotifyCID, "CookieHTTPNotifyService", "component://netscape/cookie-http-notify", aPath, PR_TRUE, PR_TRUE);
|
||||
return rv;
|
||||
}
|
||||
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSUnregisterSelf(nsISupports* serviceMgr, const char* aPath) {
|
||||
nsresult rv;
|
||||
rv = nsComponentManager::UnregisterComponent(kCookieServiceCID, aPath);
|
||||
if (NS_FAILED(rv)) {
|
||||
//----------------------------------------
|
||||
|
||||
struct Components {
|
||||
const char* mDescription;
|
||||
const nsID* mCID;
|
||||
const char* mProgID;
|
||||
};
|
||||
|
||||
// The list of components we register
|
||||
static Components gComponents[] = {
|
||||
{ "CookieService", &kCookieServiceCID,
|
||||
"component://netscape/cookie", },
|
||||
{ "CookieHTTPNotifyService", &kCookieHTTPNotifyCID,
|
||||
"component://netscape/cookie-http-notify", },
|
||||
};
|
||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieServiceModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation,
|
||||
const char* componentType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("*** Registering CookieService components\n");
|
||||
#endif
|
||||
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
|
||||
cp->mProgID, aPath, PR_TRUE,
|
||||
PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsCookieServiceModule: unable to register %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
rv = nsComponentManager::UnregisterComponent(kCookieHTTPNotifyCID, aPath);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieServiceModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("*** Unregistering CookieService components\n");
|
||||
#endif
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsCookieServiceModule: unable to unregister %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieServiceModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
||||
{
|
||||
if (!okToUnload) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*okToUnload = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static nsCookieServiceModule *gModule = NULL;
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
|
||||
nsIFileSpec* location,
|
||||
nsIModule** return_cobj)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(return_cobj);
|
||||
NS_ENSURE_NOT(gModule, NS_ERROR_FAILURE);
|
||||
|
||||
// Create and initialize the module instance
|
||||
nsCookieServiceModule *m = new nsCookieServiceModule();
|
||||
if (!m) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Increase refcnt and store away nsIModule interface to m in return_cobj
|
||||
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete m;
|
||||
m = nsnull;
|
||||
}
|
||||
gModule = m; // WARNING: Weak Reference
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Загрузка…
Ссылка в новой задаче