From f67b37e6c13747d9bdcdc6d1d6accfe29520361d Mon Sep 17 00:00:00 2001 From: "cbiesinger%web.de" Date: Tue, 28 Sep 2004 20:48:58 +0000 Subject: [PATCH] Bug 234257 nsIDocumentLoader/nsDocLoader misc cleanup r=bz sr=darin --- docshell/base/nsDocShell.cpp | 37 ++------ docshell/base/nsDocShell.h | 1 - mailnews/compose/src/nsURLFetcher.cpp | 4 +- uriloader/base/nsDocLoader.cpp | 126 +++++++++----------------- uriloader/base/nsDocLoader.h | 13 ++- uriloader/base/nsIDocumentLoader.idl | 24 ++--- uriloader/base/nsIURILoader.idl | 8 +- uriloader/base/nsURILoader.cpp | 23 +---- 8 files changed, 80 insertions(+), 156 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 21cc300b74c..3e104693618 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -421,22 +421,13 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink) || aIID.Equals(NS_GET_IID(nsIHttpEventSink)) || aIID.Equals(NS_GET_IID(nsIWebProgress)) || aIID.Equals(NS_GET_IID(nsISecurityEventSink))) { - nsCOMPtr - uriLoader(do_GetService(NS_URI_LOADER_CONTRACTID)); - NS_ENSURE_TRUE(uriLoader, NS_ERROR_FAILURE); - nsCOMPtr docLoader; - NS_ENSURE_SUCCESS(uriLoader-> - GetDocumentLoaderForContext(this, - getter_AddRefs - (docLoader)), - NS_ERROR_FAILURE); - if (docLoader) { - nsCOMPtr - requestor(do_QueryInterface(docLoader)); - return requestor->GetInterface(aIID, aSink); - } - else - return NS_ERROR_FAILURE; + // mLoadCookie is our nsIDocumentLoader + nsCOMPtr requestor(do_QueryInterface(mLoadCookie)); + nsresult rv = NS_ERROR_FAILURE; + if (requestor) + rv = requestor->GetInterface(aIID, aSink); + + return rv; } else if (aIID.Equals(NS_GET_IID(nsISHistory))) { nsCOMPtr shistory; @@ -871,7 +862,6 @@ nsDocShell::FireUnloadNotification() } } } - return NS_OK; } @@ -3136,10 +3126,6 @@ nsDocShell::Destroy() // Stop any URLs that are currently being loaded... Stop(nsIWebNavigation::STOP_ALL); - if (mDocLoader) { - mDocLoader->Destroy(); - mDocLoader->SetContainer(nsnull); - } delete mEditorData; mEditorData = 0; @@ -3165,7 +3151,6 @@ nsDocShell::Destroy() DestroyChildren(); - mDocLoader = nsnull; mParentWidget = nsnull; mPrefs = nsnull; mCurrentURI = nsnull; @@ -5467,12 +5452,6 @@ nsDocShell::DoURILoad(nsIURI * aURI, uriLoader = do_GetService(NS_URI_LOADER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; - // we need to get the load group from our load cookie so we can pass it into open uri... - nsCOMPtr loadGroup; - rv = uriLoader->GetLoadGroupForContext(this, - getter_AddRefs(loadGroup)); - if (NS_FAILED(rv)) return rv; - nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL; if (firstParty) { // tag first party URL loads @@ -5485,7 +5464,7 @@ nsDocShell::DoURILoad(nsIURI * aURI, rv = NS_NewChannel(getter_AddRefs(channel), aURI, nsnull, - loadGroup, + nsnull, NS_STATIC_CAST(nsIInterfaceRequestor *, this), loadFlags); if (NS_FAILED(rv)) { diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index f6f8ce0e34b..bc2ad746026 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -400,7 +400,6 @@ protected: nsCOMPtr mContentViewer; nsCOMPtr mDocumentCharsetInfo; nsCOMPtr mDeviceContext; - nsCOMPtrmDocLoader; nsCOMPtr mParentWidget; nsCOMPtr mPrefs; nsCOMPtr mCurrentURI; diff --git a/mailnews/compose/src/nsURLFetcher.cpp b/mailnews/compose/src/nsURLFetcher.cpp index 945afff40c7..021b38244ed 100644 --- a/mailnews/compose/src/nsURLFetcher.cpp +++ b/mailnews/compose/src/nsURLFetcher.cpp @@ -357,9 +357,7 @@ nsURLFetcher::FireURLRequest(nsIURI *aURL, nsILocalFile *localFile, nsIFileOutpu NS_ENSURE_TRUE(pURILoader, NS_ERROR_FAILURE); nsCOMPtr channel; - nsCOMPtr loadGroup; - pURILoader->GetLoadGroupForContext(this, getter_AddRefs(loadGroup)); - NS_ENSURE_SUCCESS(NS_NewChannel(getter_AddRefs(channel), aURL, nsnull, loadGroup, this), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(NS_NewChannel(getter_AddRefs(channel), aURL, nsnull, nsnull, this), NS_ERROR_FAILURE); return pURILoader->OpenURI(channel, PR_FALSE, this); } diff --git a/uriloader/base/nsDocLoader.cpp b/uriloader/base/nsDocLoader.cpp index c5be38ef2e4..1e2a26f027e 100644 --- a/uriloader/base/nsDocLoader.cpp +++ b/uriloader/base/nsDocLoader.cpp @@ -53,9 +53,6 @@ #include "nsIDOMWindow.h" -// XXX ick ick ick -#include "nsIContentViewerContainer.h" -#include "nsIDocument.h" #include "nsIPresShell.h" #include "nsPresContext.h" #include "nsIStringBundle.h" @@ -92,11 +89,6 @@ void GetURIStringFromRequest(nsIRequest* request, nsACString &name) } #endif /* DEBUG */ -/* Define IIDs... */ -static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); -static NS_DEFINE_IID(kIContentViewerContainerIID, NS_ICONTENTVIEWERCONTAINER_IID); - - struct nsRequestInfo : public PLDHashEntryHdr { nsRequestInfo(const void *key) @@ -197,12 +189,6 @@ nsDocLoaderImpl::Init() return NS_OK; } -NS_IMETHODIMP nsDocLoaderImpl::ClearParentDocLoader() -{ - SetDocLoaderParent(nsnull); - return NS_OK; -} - nsDocLoaderImpl::~nsDocLoaderImpl() { /* @@ -229,10 +215,13 @@ nsDocLoaderImpl::~nsDocLoaderImpl() { for (PRInt32 i=0; i < count; i++) { - nsCOMPtr loader = mChildList.ObjectAt(i); + nsIDocumentLoader* loader = mChildList.ObjectAt(i); - if (loader) - loader->ClearParentDocLoader(); + if (loader) { + // This is a safe cast, as we only put nsDocLoaderImpl objects into the + // array + NS_STATIC_CAST(nsDocLoaderImpl*, loader)->SetDocLoaderParent(nsnull); + } } mChildList.Clear(); } @@ -305,7 +294,7 @@ nsDocLoaderImpl::CreateDocumentLoader(nsIDocumentLoader** anInstance) } if (NS_SUCCEEDED(rv)) { - rv = mChildList.AppendObject((nsIDocumentLoader*)newLoader) + rv = mChildList.AppendObject(newLoader) ? NS_OK : NS_ERROR_FAILURE; } @@ -344,8 +333,8 @@ nsDocLoaderImpl::Stop(void) } -NS_IMETHODIMP -nsDocLoaderImpl::IsBusy(PRBool * aResult) +PRBool +nsDocLoaderImpl::IsBusy() { nsresult rv; @@ -355,33 +344,32 @@ nsDocLoaderImpl::IsBusy(PRBool * aResult) // 1. It is currently loading a document (ie. one or more URIs) // 2. One of it's child document loaders is busy... // - *aResult = PR_FALSE; /* Is this document loader busy? */ if (mIsLoadingDocument) { - rv = mLoadGroup->IsPending(aResult); - if (NS_FAILED(rv)) return rv; + PRBool busy; + rv = mLoadGroup->IsPending(&busy); + if (NS_FAILED(rv)) + return PR_FALSE; + if (busy) + return PR_TRUE; } /* Otherwise, check its child document loaders... */ - if (!*aResult) { - PRInt32 count, i; + PRInt32 count, i; - count = mChildList.Count(); + count = mChildList.Count(); - nsCOMPtr loader; - for (i=0; i < count; i++) { - loader = mChildList.ObjectAt(i); + for (i=0; i < count; i++) { + nsIDocumentLoader* loader = mChildList.ObjectAt(i); - if (loader) { - (void) loader->IsBusy(aResult); - - if (*aResult) break; - } - } + // This is a safe cast, because we only put nsDocLoaderImpl objects into the + // array + if (loader && NS_STATIC_CAST(nsDocLoaderImpl*, loader)->IsBusy()) + return PR_TRUE; } - return NS_OK; + return PR_FALSE; } NS_IMETHODIMP @@ -418,28 +406,6 @@ nsDocLoaderImpl::GetLoadGroup(nsILoadGroup** aResult) return rv; } -NS_IMETHODIMP -nsDocLoaderImpl::GetContentViewerContainer(nsISupports* aDocumentID, - nsIContentViewerContainer** aResult) -{ - nsCOMPtr doc(do_QueryInterface(aDocumentID)); - - if (doc) { - nsIPresShell *pres = doc->GetShellAt(0); - if (pres) { - nsPresContext *presContext = pres->GetPresContext(); - if (presContext) { - nsCOMPtr supp = presContext->GetContainer(); - if (supp) { - return CallQueryInterface(supp, aResult); - } - } - } - } - - return NS_OK; -} - NS_IMETHODIMP nsDocLoaderImpl::Destroy() { @@ -610,7 +576,7 @@ nsDocLoaderImpl::OnStopRequest(nsIRequest *aRequest, // mMaxSelfProgress... // if ((oldMax < 0) && (mMaxSelfProgress < 0)) { - CalculateMaxProgress(&mMaxSelfProgress); + mMaxSelfProgress = CalculateMaxProgress(); } // @@ -724,15 +690,13 @@ NS_IMETHODIMP nsDocLoaderImpl::GetDocumentChannel(nsIChannel ** aChannel) void nsDocLoaderImpl::DocLoaderIsEmpty() { if (mIsLoadingDocument) { - PRBool busy = PR_FALSE; /* In the unimagineably rude circumstance that onload event handlers triggered by this function actually kill the window ... ok, it's not unimagineable; it's happened ... this deathgrip keeps this object alive long enough to survive this function call. */ nsCOMPtr kungFuDeathGrip(this); - IsBusy(&busy); - if (!busy) { + if (!IsBusy()) { PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p: Is now idle...\n", this)); @@ -957,10 +921,10 @@ nsDocLoaderImpl::GetIsLoadingDocument(PRBool *aIsLoadingDocument) return NS_OK; } -nsresult nsDocLoaderImpl::GetMaxTotalProgress(PRInt32 *aMaxTotalProgress) +PRInt32 nsDocLoaderImpl::GetMaxTotalProgress() { PRInt32 count = 0; - PRInt32 invididualProgress, newMaxTotal; + PRInt32 individualProgress, newMaxTotal; newMaxTotal = 0; @@ -969,28 +933,28 @@ nsresult nsDocLoaderImpl::GetMaxTotalProgress(PRInt32 *aMaxTotalProgress) nsCOMPtr docloader; for (PRInt32 i=0; i < count; i++) { - invididualProgress = 0; + individualProgress = 0; docloader = mChildList.ObjectAt(i); if (docloader) { // Cast is safe since all children are nsDocLoaderImpl too - ((nsDocLoaderImpl *) docloader.get())->GetMaxTotalProgress(&invididualProgress); + individualProgress = ((nsDocLoaderImpl *) docloader.get())->GetMaxTotalProgress(); } - if (invididualProgress < 0) // if one of the elements doesn't know it's size + if (individualProgress < 0) // if one of the elements doesn't know it's size // then none of them do { newMaxTotal = -1; break; } else - newMaxTotal += invididualProgress; + newMaxTotal += individualProgress; } - if (mMaxSelfProgress >= 0 && newMaxTotal >= 0) { - *aMaxTotalProgress = newMaxTotal + mMaxSelfProgress; - } else { - *aMaxTotalProgress = -1; - } - return NS_OK; + + PRInt32 progress = -1; + if (mMaxSelfProgress >= 0 && newMaxTotal >= 0) + progress = newMaxTotal + mMaxSelfProgress; + + return progress; } //////////////////////////////////////////////////////////////////////////////////// @@ -1148,7 +1112,7 @@ void nsDocLoaderImpl::FireOnProgressChange(nsDocLoaderImpl *aLoadInitiator, { if (mIsLoadingDocument) { mCurrentTotalProgress += aProgressDelta; - GetMaxTotalProgress(&mMaxTotalProgress); + mMaxTotalProgress = GetMaxTotalProgress(); aTotalProgress = mCurrentTotalProgress; aMaxTotalProgress = mMaxTotalProgress; @@ -1315,7 +1279,7 @@ nsDocLoaderImpl::FireOnLocationChange(nsIWebProgress* aWebProgress, return NS_OK; } -NS_IMETHODIMP +void nsDocLoaderImpl::FireOnStatusChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, nsresult aStatus, @@ -1354,8 +1318,6 @@ nsDocLoaderImpl::FireOnStatusChange(nsIWebProgress* aWebProgress, if (mParent) { mParent->FireOnStatusChange(aWebProgress, aRequest, aStatus, aMessage); } - - return NS_OK; } nsListenerInfo * @@ -1442,11 +1404,11 @@ CalcMaxProgressCallback(PLDHashTable *table, PLDHashEntryHdr *hdr, return PL_DHASH_NEXT; } -void nsDocLoaderImpl::CalculateMaxProgress(PRInt32 *aMax) +PRInt32 nsDocLoaderImpl::CalculateMaxProgress() { - *aMax = 0; - - PL_DHashTableEnumerate(&mRequestInfoHash, CalcMaxProgressCallback, aMax); + PRInt32 max = 0; + PL_DHashTableEnumerate(&mRequestInfoHash, CalcMaxProgressCallback, &max); + return max; } NS_IMETHODIMP nsDocLoaderImpl::OnRedirect(nsIHttpChannel *aOldChannel, nsIChannel *aNewChannel) diff --git a/uriloader/base/nsDocLoader.h b/uriloader/base/nsDocLoader.h index f4e0aa84fe7..4f9a9c041b9 100644 --- a/uriloader/base/nsDocLoader.h +++ b/uriloader/base/nsDocLoader.h @@ -107,6 +107,8 @@ protected: nsresult RemoveChildGroup(nsDocLoaderImpl *aLoader); void DocLoaderIsEmpty(); + PRBool IsBusy(); + void FireOnProgressChange(nsDocLoaderImpl* aLoadInitiator, nsIRequest *request, PRInt32 aProgress, @@ -120,6 +122,11 @@ protected: PRInt32 aStateFlags, nsresult aStatus); + void FireOnStatusChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + nsresult aStatus, + const PRUnichar* aMessage); + void doStartDocumentLoad(); void doStartURLLoad(nsIRequest *request); void doStopURLLoad(nsIRequest *request, nsresult aStatus); @@ -170,12 +177,12 @@ protected: private: nsListenerInfo *GetListenerInfo(nsIWeakReference* aListener); - nsresult GetMaxTotalProgress(PRInt32* aMaxTotalProgress); + PRInt32 GetMaxTotalProgress(); nsresult AddRequestInfo(nsIRequest* aRequest); nsRequestInfo *GetRequestInfo(nsIRequest* aRequest); - void ClearRequestInfoHash(void); - void CalculateMaxProgress(PRInt32 *aMax); + void ClearRequestInfoHash(); + PRInt32 CalculateMaxProgress(); /// void DumpChannelInfo(void); // used to clear our internal progress state between loads... diff --git a/uriloader/base/nsIDocumentLoader.idl b/uriloader/base/nsIDocumentLoader.idl index 80eeb09d66c..84a2ca701b8 100644 --- a/uriloader/base/nsIDocumentLoader.idl +++ b/uriloader/base/nsIDocumentLoader.idl @@ -35,42 +35,36 @@ * * ***** END LICENSE BLOCK ***** */ -/* nsIDocumentLoader --> - -*/ - #include "nsISupports.idl" interface nsILoadGroup; -interface nsIContentViewerContainer; interface nsIChannel; interface nsIURI; interface nsIWebProgress; interface nsIRequest; -[scriptable, uuid(f43ba260-0737-11d2-beb9-00805f8a66dc)] +/** + * An nsIDocumentLoader is a component responsible for tracking groups of loads + * that belong together (images, external scripts, etc) and subdocuments + * (