Fixed circular references. nsDocLoader now supports weak references to it. Init() method moves out of constructor. nsDocLoader now has Destroy() method to start breakdown process.

This commit is contained in:
vidur%netscape.com 1999-09-09 23:53:55 +00:00
Родитель de42666720
Коммит 56c104a8a3
5 изменённых файлов: 62 добавлений и 22 удалений

Просмотреть файл

@ -1267,6 +1267,7 @@ nsWebShell::Destroy()
// Stop any URLs that are currently being loaded... // Stop any URLs that are currently being loaded...
Stop(); Stop();
mDocLoader->Destroy();
SetContainer(nsnull); SetContainer(nsnull);
SetObserver(nsnull); SetObserver(nsnull);

Просмотреть файл

@ -58,6 +58,8 @@
#include "prlog.h" #include "prlog.h"
#include "prprf.h" #include "prprf.h"
#include "nsWeakReference.h"
#include "nsIStreamConverterService.h" #include "nsIStreamConverterService.h"
#include "nsIStreamConverter.h" #include "nsIStreamConverter.h"
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID); static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
@ -205,7 +207,8 @@ protected:
class nsDocLoaderImpl : public nsIDocumentLoader, class nsDocLoaderImpl : public nsIDocumentLoader,
public nsIStreamObserver, public nsIStreamObserver,
public nsILoadGroupListenerFactory public nsILoadGroupListenerFactory,
public nsSupportsWeakReference
{ {
public: public:
@ -246,6 +249,7 @@ public:
NS_IMETHOD GetContainer(nsIContentViewerContainer** aResult); NS_IMETHOD GetContainer(nsIContentViewerContainer** aResult);
NS_IMETHOD GetContentViewerContainer(PRUint32 aDocumentID, NS_IMETHOD GetContentViewerContainer(PRUint32 aDocumentID,
nsIContentViewerContainer** aResult); nsIContentViewerContainer** aResult);
NS_IMETHOD Destroy();
// nsILoadGroup interface... // nsILoadGroup interface...
NS_IMETHOD CreateURL(nsIURI** aInstancePtrResult, NS_IMETHOD CreateURL(nsIURI** aInstancePtrResult,
@ -362,13 +366,6 @@ nsDocLoaderImpl::nsDocLoaderImpl()
mIsLoadingDocument = PR_FALSE; mIsLoadingDocument = PR_FALSE;
// XXX I wanted to pull this initialization code out of this constructor
// because it could fail... but the web shell uses this implementation
// as a service too. Since it's a service, it really can't have any
// initialization. We're sort of screwed here.
nsresult rv = Init();
NS_ASSERTION(NS_SUCCEEDED(rv), "nsDocLoaderImpl::Init failed");
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
("DocLoader:%p: created.\n", this)); ("DocLoader:%p: created.\n", this));
} }
@ -456,6 +453,11 @@ nsDocLoaderImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
return NS_OK; return NS_OK;
} }
#endif // NECKO #endif // NECKO
if (aIID.Equals(nsCOMTypeInfo<nsISupportsWeakReference>::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsISupportsWeakReference*,this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE; return NS_NOINTERFACE;
} }
@ -480,6 +482,9 @@ nsDocLoaderImpl::CreateDocumentLoader(nsIDocumentLoader** anInstance)
rv = newLoader->QueryInterface(kIDocumentLoaderIID, (void**)anInstance); rv = newLoader->QueryInterface(kIDocumentLoaderIID, (void**)anInstance);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
// Initialize now that we have a reference
rv = newLoader->Init();
if (NS_SUCCEEDED(rv)) {
#ifdef NECKO #ifdef NECKO
AddChildGroup(newLoader->GetLoadGroup()); AddChildGroup(newLoader->GetLoadGroup());
#else #else
@ -487,6 +492,7 @@ nsDocLoaderImpl::CreateDocumentLoader(nsIDocumentLoader** anInstance)
#endif #endif
newLoader->SetParent(this); newLoader->SetParent(this);
} }
}
done: done:
return rv; return rv;
@ -778,6 +784,15 @@ nsDocLoaderImpl::GetContentViewerContainer(PRUint32 aDocumentID,
return rv; return rv;
} }
NS_IMETHODIMP
nsDocLoaderImpl::Destroy()
{
Stop();
NS_IF_RELEASE(mDocumentChannel);
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsDocLoaderImpl::CreateURL(nsIURI** aInstancePtrResult, nsDocLoaderImpl::CreateURL(nsIURI** aInstancePtrResult,
nsIURI* aBaseURL, nsIURI* aBaseURL,
@ -2302,6 +2317,9 @@ nsDocLoaderImpl::Create(nsISupports *aOuter, const nsIID &aIID, void **aResult)
NS_ADDREF(inst); NS_ADDREF(inst);
rv = inst->QueryInterface(aIID, aResult); rv = inst->QueryInterface(aIID, aResult);
if (NS_SUCCEEDED(rv)) {
rv = inst->Init();
}
NS_RELEASE(inst); NS_RELEASE(inst);
done: done:

Просмотреть файл

@ -131,6 +131,8 @@ public:
NS_IMETHOD GetContainer(nsIContentViewerContainer** aResult) = 0; NS_IMETHOD GetContainer(nsIContentViewerContainer** aResult) = 0;
NS_IMETHOD GetContentViewerContainer(PRUint32 aDocumentID, nsIContentViewerContainer** aResult) = 0; NS_IMETHOD GetContentViewerContainer(PRUint32 aDocumentID, nsIContentViewerContainer** aResult) = 0;
NS_IMETHOD Destroy() = 0;
}; };
/* 057b04d0-0ccf-11d2-beba-00805f8a66dc */ /* 057b04d0-0ccf-11d2-beba-00805f8a66dc */

Просмотреть файл

@ -58,6 +58,8 @@
#include "prlog.h" #include "prlog.h"
#include "prprf.h" #include "prprf.h"
#include "nsWeakReference.h"
#include "nsIStreamConverterService.h" #include "nsIStreamConverterService.h"
#include "nsIStreamConverter.h" #include "nsIStreamConverter.h"
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID); static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
@ -205,7 +207,8 @@ protected:
class nsDocLoaderImpl : public nsIDocumentLoader, class nsDocLoaderImpl : public nsIDocumentLoader,
public nsIStreamObserver, public nsIStreamObserver,
public nsILoadGroupListenerFactory public nsILoadGroupListenerFactory,
public nsSupportsWeakReference
{ {
public: public:
@ -246,6 +249,7 @@ public:
NS_IMETHOD GetContainer(nsIContentViewerContainer** aResult); NS_IMETHOD GetContainer(nsIContentViewerContainer** aResult);
NS_IMETHOD GetContentViewerContainer(PRUint32 aDocumentID, NS_IMETHOD GetContentViewerContainer(PRUint32 aDocumentID,
nsIContentViewerContainer** aResult); nsIContentViewerContainer** aResult);
NS_IMETHOD Destroy();
// nsILoadGroup interface... // nsILoadGroup interface...
NS_IMETHOD CreateURL(nsIURI** aInstancePtrResult, NS_IMETHOD CreateURL(nsIURI** aInstancePtrResult,
@ -362,13 +366,6 @@ nsDocLoaderImpl::nsDocLoaderImpl()
mIsLoadingDocument = PR_FALSE; mIsLoadingDocument = PR_FALSE;
// XXX I wanted to pull this initialization code out of this constructor
// because it could fail... but the web shell uses this implementation
// as a service too. Since it's a service, it really can't have any
// initialization. We're sort of screwed here.
nsresult rv = Init();
NS_ASSERTION(NS_SUCCEEDED(rv), "nsDocLoaderImpl::Init failed");
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
("DocLoader:%p: created.\n", this)); ("DocLoader:%p: created.\n", this));
} }
@ -456,6 +453,11 @@ nsDocLoaderImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
return NS_OK; return NS_OK;
} }
#endif // NECKO #endif // NECKO
if (aIID.Equals(nsCOMTypeInfo<nsISupportsWeakReference>::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsISupportsWeakReference*,this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE; return NS_NOINTERFACE;
} }
@ -480,6 +482,9 @@ nsDocLoaderImpl::CreateDocumentLoader(nsIDocumentLoader** anInstance)
rv = newLoader->QueryInterface(kIDocumentLoaderIID, (void**)anInstance); rv = newLoader->QueryInterface(kIDocumentLoaderIID, (void**)anInstance);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
// Initialize now that we have a reference
rv = newLoader->Init();
if (NS_SUCCEEDED(rv)) {
#ifdef NECKO #ifdef NECKO
AddChildGroup(newLoader->GetLoadGroup()); AddChildGroup(newLoader->GetLoadGroup());
#else #else
@ -487,6 +492,7 @@ nsDocLoaderImpl::CreateDocumentLoader(nsIDocumentLoader** anInstance)
#endif #endif
newLoader->SetParent(this); newLoader->SetParent(this);
} }
}
done: done:
return rv; return rv;
@ -778,6 +784,15 @@ nsDocLoaderImpl::GetContentViewerContainer(PRUint32 aDocumentID,
return rv; return rv;
} }
NS_IMETHODIMP
nsDocLoaderImpl::Destroy()
{
Stop();
NS_IF_RELEASE(mDocumentChannel);
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsDocLoaderImpl::CreateURL(nsIURI** aInstancePtrResult, nsDocLoaderImpl::CreateURL(nsIURI** aInstancePtrResult,
nsIURI* aBaseURL, nsIURI* aBaseURL,
@ -2302,6 +2317,9 @@ nsDocLoaderImpl::Create(nsISupports *aOuter, const nsIID &aIID, void **aResult)
NS_ADDREF(inst); NS_ADDREF(inst);
rv = inst->QueryInterface(aIID, aResult); rv = inst->QueryInterface(aIID, aResult);
if (NS_SUCCEEDED(rv)) {
rv = inst->Init();
}
NS_RELEASE(inst); NS_RELEASE(inst);
done: done:

Просмотреть файл

@ -1267,6 +1267,7 @@ nsWebShell::Destroy()
// Stop any URLs that are currently being loaded... // Stop any URLs that are currently being loaded...
Stop(); Stop();
mDocLoader->Destroy();
SetContainer(nsnull); SetContainer(nsnull);
SetObserver(nsnull); SetObserver(nsnull);