Bug 234257 nsIDocumentLoader/nsDocLoader misc cleanup

r=bz sr=darin
This commit is contained in:
cbiesinger%web.de 2004-09-28 20:48:58 +00:00
Родитель c2e5d84c70
Коммит f67b37e6c1
8 изменённых файлов: 80 добавлений и 156 удалений

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

@ -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<nsIURILoader>
uriLoader(do_GetService(NS_URI_LOADER_CONTRACTID));
NS_ENSURE_TRUE(uriLoader, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocumentLoader> docLoader;
NS_ENSURE_SUCCESS(uriLoader->
GetDocumentLoaderForContext(this,
getter_AddRefs
(docLoader)),
NS_ERROR_FAILURE);
if (docLoader) {
nsCOMPtr<nsIInterfaceRequestor>
requestor(do_QueryInterface(docLoader));
return requestor->GetInterface(aIID, aSink);
}
else
return NS_ERROR_FAILURE;
// mLoadCookie is our nsIDocumentLoader
nsCOMPtr<nsIInterfaceRequestor> 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<nsISHistory> 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<nsILoadGroup> 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)) {

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

@ -400,7 +400,6 @@ protected:
nsCOMPtr<nsIContentViewer> mContentViewer;
nsCOMPtr<nsIDocumentCharsetInfo> mDocumentCharsetInfo;
nsCOMPtr<nsIDeviceContext> mDeviceContext;
nsCOMPtr<nsIDocumentLoader>mDocLoader;
nsCOMPtr<nsIWidget> mParentWidget;
nsCOMPtr<nsIPrefBranch> mPrefs;
nsCOMPtr<nsIURI> mCurrentURI;

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

@ -357,9 +357,7 @@ nsURLFetcher::FireURLRequest(nsIURI *aURL, nsILocalFile *localFile, nsIFileOutpu
NS_ENSURE_TRUE(pURILoader, NS_ERROR_FAILURE);
nsCOMPtr<nsIChannel> channel;
nsCOMPtr<nsILoadGroup> 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);
}

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

@ -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<nsIDocumentLoader> 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<nsIDocumentLoader> 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<nsIDocument> doc(do_QueryInterface(aDocumentID));
if (doc) {
nsIPresShell *pres = doc->GetShellAt(0);
if (pres) {
nsPresContext *presContext = pres->GetPresContext();
if (presContext) {
nsCOMPtr<nsISupports> 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<nsIDocumentLoader> 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<nsIDocumentLoader> 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)

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

@ -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...

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

@ -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
* (<iframe>, <frame>, etc). It is also responsible for sending
* nsIWebProgressListener notifications.
*/
[scriptable, uuid(8cb3d66d-a39c-46d4-9786-373b6b052e6d)]
interface nsIDocumentLoader : nsISupports
{
void stop();
boolean isBusy();
// XXXbiesi this seems like not such a good method here
void createDocumentLoader(out nsIDocumentLoader anInstance);
attribute nsISupports container;
[noscript] void getContentViewerContainer(in nsISupports aDocumentID, out nsIContentViewerContainer aResult);
nsILoadGroup getLoadGroup();
void destroy();
// this should really be in a private interface as it is only
// called between a parent doc loader and it's child.
void clearParentDocLoader();
readonly attribute nsIChannel documentChannel;
void fireOnLocationChange(in nsIWebProgress aWebProgress,
in nsIRequest aRequest,
in nsIURI aUri);
void fireOnStatusChange(in nsIWebProgress aWebProgress,
in nsIRequest aRequest,
in nsresult aStatus,
in wstring aMessage);
};

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

@ -68,7 +68,7 @@ interface nsIInterfaceRequestor;
* or helper app. Or it may hand the url off to an OS registered
* application.
*/
[scriptable, uuid(59432929-288b-4fa9-83c9-a5bc8d7ca3bd)]
[scriptable, uuid(b90c6e12-48a0-4954-8eb3-b6e0075d4e4f)]
interface nsIURILoader : nsISupports
{
/**
@ -90,6 +90,8 @@ interface nsIURILoader : nsISupports
* OpenURI requires the following parameters.....
* @param aChannel
* The channel that should be opened. This must not be asyncOpen'd yet!
* If a loadgroup is set on the channel, it will get replaced with a
* different one.
* @param aIsContentPreferred
* Should the content be displayed in a container that prefers the
* content-type, or will any container do.
@ -112,10 +114,8 @@ interface nsIURILoader : nsISupports
void stop(in nsISupports aLoadCookie);
/**
* dirty little back door for sneaking the load group out in case you need
* it to create the channel before calling openURI
* XXXbiesi is this really needed?
*/
nsILoadGroup getLoadGroupForContext(in nsIInterfaceRequestor aWindowContext);
nsIDocumentLoader getDocumentLoaderForContext (in nsIInterfaceRequestor aWindowContext);
};

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

@ -833,6 +833,10 @@ NS_IMETHODIMP nsURILoader::OpenURI(nsIChannel *channel,
nsCOMPtr<nsIInterfaceRequestor> loadCookie;
SetupLoadCookie(aWindowContext, getter_AddRefs(loadCookie));
// Set the correct loadgroup on the channel
nsCOMPtr<nsILoadGroup> loadGroup(do_GetInterface(loadCookie));
channel->SetLoadGroup(loadGroup);
// now instruct the loader to go ahead and open the url
return loader->Open(channel);
}
@ -851,25 +855,6 @@ NS_IMETHODIMP nsURILoader::Stop(nsISupports* aLoadCookie)
return rv;
}
NS_IMETHODIMP
nsURILoader::GetLoadGroupForContext(nsIInterfaceRequestor* aWindowContext,
nsILoadGroup ** aLoadGroup)
{
nsresult rv;
nsCOMPtr<nsIInterfaceRequestor> loadCookieForWindow;
// Initialize the [out] parameter...
*aLoadGroup = nsnull;
NS_ENSURE_ARG(aWindowContext);
rv = SetupLoadCookie(aWindowContext, getter_AddRefs(loadCookieForWindow));
if (NS_FAILED(rv)) return rv;
rv = CallGetInterface(loadCookieForWindow.get(), aLoadGroup);
return rv;
}
NS_IMETHODIMP
nsURILoader::GetDocumentLoaderForContext(nsIInterfaceRequestor * aWindowContext,
nsIDocumentLoader ** aDocLoader)