diff --git a/mozilla/docshell/base/nsDSURIContentListener.cpp b/mozilla/docshell/base/nsDSURIContentListener.cpp index 979a57c3ba5..68a768248a5 100644 --- a/mozilla/docshell/base/nsDSURIContentListener.cpp +++ b/mozilla/docshell/base/nsDSURIContentListener.cpp @@ -43,6 +43,7 @@ #include "nsXPIDLString.h" #include "nsIServiceManager.h" #include "nsIDOMWindowInternal.h" +#include "nsAutoPtr.h" //***************************************************************************** //*** nsDSURIContentListener: Object Management @@ -209,13 +210,20 @@ nsDSURIContentListener::CanHandleContent(const char* aContentType, NS_IMETHODIMP nsDSURIContentListener::GetLoadCookie(nsISupports ** aLoadCookie) { - return mDocShell->GetLoadCookie(aLoadCookie); + NS_ADDREF(*aLoadCookie = NS_STATIC_CAST(nsIDocumentLoader*, mDocShell)); + return NS_OK; } NS_IMETHODIMP nsDSURIContentListener::SetLoadCookie(nsISupports * aLoadCookie) { - return mDocShell->SetLoadCookie(aLoadCookie); +#ifdef DEBUG + nsRefPtr cookieAsDocLoader = + nsDocLoader::GetAsDocLoader(aLoadCookie); + NS_ASSERTION(cookieAsDocLoader && cookieAsDocLoader == mDocShell, + "Invalid load cookie being set!"); +#endif + return NS_OK; } NS_IMETHODIMP diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index d4c0e587273..31822ec53ce 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -230,6 +230,7 @@ nsDocShellFocusController nsDocShellFocusController::mDocShellFocusControllerSin //***************************************************************************** nsDocShell::nsDocShell(): + nsDocLoader(), mAllowSubframes(PR_TRUE), mAllowPlugins(PR_TRUE), mAllowJavascript(PR_TRUE), @@ -256,7 +257,6 @@ nsDocShell::nsDocShell(): mContentListener(nsnull), mDefaultScrollbarPref(Scrollbar_Auto, Scrollbar_Auto), mEditorData(nsnull), - mParent(nsnull), mTreeOwner(nsnull), mChromeEventHandler(nsnull) { @@ -286,37 +286,59 @@ nsDocShell::~nsDocShell() } } -NS_IMETHODIMP +nsresult +nsDocShell::Init() +{ + nsresult rv = nsDocLoader::Init(); + NS_ENSURE_SUCCESS(rv, rv); + + NS_ASSERTION(mLoadGroup, "Something went wrong!"); + + // We want to hold a strong ref to the loadgroup, so it better hold a weak + // ref to us... use an InterfaceRequestorProxy to do this. + nsCOMPtr proxy = + new InterfaceRequestorProxy(NS_STATIC_CAST(nsIInterfaceRequestor*, + this)); + NS_ENSURE_TRUE(proxy, NS_ERROR_OUT_OF_MEMORY); + mLoadGroup->SetNotificationCallbacks(proxy); + + rv = nsDocLoader::AddDocLoaderAsChildOfRoot(this); + NS_ENSURE_SUCCESS(rv, rv); + + // Add as |this| a progress listener to itself. A little weird, but + // simpler than reproducing all the listener-notification logic in + // overrides of the various methods via which nsDocLoader can be + // notified. Note that this holds an nsWeakPtr to ourselves, so it's ok. + return AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT | + nsIWebProgress::NOTIFY_STATE_NETWORK); + +} + +void nsDocShell::DestroyChildren() { - PRInt32 i, n = mChildren.Count(); nsCOMPtr shell; - for (i = 0; i < n; i++) { - shell = dont_AddRef((nsIDocShellTreeItem *) mChildren.ElementAt(i)); + PRInt32 n = mChildList.Count(); + for (PRInt32 i = 0; i < n; i++) { + shell = do_QueryInterface(ChildAt(i)); NS_WARN_IF_FALSE(shell, "docshell has null child"); if (shell) { - shell->SetParent(nsnull); shell->SetTreeOwner(nsnull); - // just clear out the array. When the nsFrameFrame that holds - // the subshell is destroyed, then the Destroy() method of - // that subshell will actually get called. } } - mChildren.Clear(); - return NS_OK; + nsDocLoader::DestroyChildren(); } //***************************************************************************** // nsDocShell::nsISupports //***************************************************************************** -NS_IMPL_THREADSAFE_ADDREF(nsDocShell) -NS_IMPL_THREADSAFE_RELEASE(nsDocShell) +NS_IMPL_ADDREF_INHERITED(nsDocShell, nsDocLoader) +NS_IMPL_RELEASE_INHERITED(nsDocShell, nsDocLoader) NS_INTERFACE_MAP_BEGIN(nsDocShell) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShell) NS_INTERFACE_MAP_ENTRY(nsIDocShell) NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeItem) NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeNode) @@ -326,7 +348,6 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell) NS_INTERFACE_MAP_ENTRY(nsIScrollable) NS_INTERFACE_MAP_ENTRY(nsITextScroll) NS_INTERFACE_MAP_ENTRY(nsIDocCharset) - NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner) NS_INTERFACE_MAP_ENTRY(nsIRefreshURI) NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) @@ -335,7 +356,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell) NS_INTERFACE_MAP_ENTRY(nsIEditorDocShell) NS_INTERFACE_MAP_ENTRY(nsIWebPageDescriptor) NS_INTERFACE_MAP_ENTRY(nsIAuthPromptProvider) -NS_INTERFACE_MAP_END_THREADSAFE +NS_INTERFACE_MAP_END_INHERITING(nsDocLoader) ///***************************************************************************** // nsDocShell::nsIInterfaceRequestor @@ -344,6 +365,8 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink) { NS_PRECONDITION(aSink, "null out param"); + *aSink = nsnull; + if (aIID.Equals(NS_GET_IID(nsIURIContentListener)) && NS_SUCCEEDED(EnsureContentListener())) { *aSink = mContentListener; @@ -354,35 +377,25 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink) } else if (aIID.Equals(NS_GET_IID(nsIDOMWindowInternal)) && NS_SUCCEEDED(EnsureScriptEnvironment())) { - NS_ENSURE_SUCCESS(mScriptGlobal-> - QueryInterface(NS_GET_IID(nsIDOMWindowInternal), - aSink), NS_ERROR_FAILURE); - return NS_OK; + return mScriptGlobal->QueryInterface(aIID, aSink); } else if (aIID.Equals(NS_GET_IID(nsPIDOMWindow)) && NS_SUCCEEDED(EnsureScriptEnvironment())) { - NS_ENSURE_SUCCESS(mScriptGlobal-> - QueryInterface(NS_GET_IID(nsPIDOMWindow), aSink), - NS_ERROR_FAILURE); - return NS_OK; + return mScriptGlobal->QueryInterface(aIID, aSink); } else if (aIID.Equals(NS_GET_IID(nsIDOMWindow)) && NS_SUCCEEDED(EnsureScriptEnvironment())) { - NS_ENSURE_SUCCESS(mScriptGlobal-> - QueryInterface(NS_GET_IID(nsIDOMWindow), aSink), - NS_ERROR_FAILURE); - return NS_OK; + return mScriptGlobal->QueryInterface(aIID, aSink); } else if (aIID.Equals(NS_GET_IID(nsIDOMDocument)) && NS_SUCCEEDED(EnsureContentViewer())) { mContentViewer->GetDOMDocument((nsIDOMDocument **) aSink); - return NS_OK; + return *aSink ? NS_OK : NS_NOINTERFACE; } else if (aIID.Equals(NS_GET_IID(nsIPrompt))) { nsCOMPtr prompter(do_GetInterface(mTreeOwner)); if (prompter) { - *aSink = prompter; - NS_ADDREF((nsISupports *) * aSink); + prompter.swap((nsIPrompt*) *aSink); return NS_OK; } else @@ -394,27 +407,6 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink) NS_OK : NS_NOINTERFACE; } - else if (aIID.Equals(NS_GET_IID(nsIProgressEventSink)) - || 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; - } else if (aIID.Equals(NS_GET_IID(nsISHistory))) { nsCOMPtr shistory; nsresult @@ -466,11 +458,11 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink) return treeOwner->QueryInterface(aIID, aSink); } else { - return QueryInterface(aIID, aSink); + return nsDocLoader::GetInterface(aIID, aSink); } NS_IF_ADDREF(((nsISupports *) * aSink)); - return NS_OK; + return *aSink ? NS_OK : NS_NOINTERFACE; } PRUint32 @@ -838,11 +830,9 @@ nsDocShell::FireUnloadNotification() mContentViewer->Unload(); - PRInt32 i, n = mChildren.Count(); + PRInt32 i, n = mChildList.Count(); for (i = 0; i < n; i++) { - nsIDocShellTreeItem* item = (nsIDocShellTreeItem*) mChildren.ElementAt(i); - - nsCOMPtr shell(do_QueryInterface(item)); + nsCOMPtr shell(do_QueryInterface(ChildAt(i))); if (shell) { shell->FireUnloadNotification(); } @@ -1373,11 +1363,6 @@ nsDocShell::SetCurrentURI(nsIURI *aURI) PRBool isRoot = PR_FALSE; // Is this the root docshell PRBool isSubFrame = PR_FALSE; // Is this a subframe navigation? - if (!mLoadCookie) - return NS_OK; - - nsCOMPtr loader(do_GetInterface(mLoadCookie)); - nsCOMPtr webProgress(do_QueryInterface(mLoadCookie)); nsCOMPtr root; GetSameTypeRootTreeItem(getter_AddRefs(root)); @@ -1404,10 +1389,7 @@ nsDocShell::SetCurrentURI(nsIURI *aURI) return NS_OK; } - NS_ASSERTION(loader, "No document loader"); - if (loader) { - loader->FireOnLocationChange(webProgress, nsnull, aURI); - } + FireOnLocationChange(this, nsnull, aURI); return NS_OK; } @@ -1756,7 +1738,14 @@ NS_IMETHODIMP nsDocShell::SetItemType(PRInt32 aItemType) { NS_ENSURE_ARG((aItemType == typeChrome) || (typeContent == aItemType)); - NS_ENSURE_STATE(!mParent); + + // Only allow setting the type on root docshells. Those would be the ones + // that have the docloader service as mParent or have no mParent at all. + nsCOMPtr docLoaderService = + do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(docLoaderService, NS_ERROR_UNEXPECTED); + + NS_ENSURE_STATE(!mParent || mParent == docLoaderService); mItemType = aItemType; @@ -1769,28 +1758,27 @@ nsDocShell::SetItemType(PRInt32 aItemType) NS_IMETHODIMP nsDocShell::GetParent(nsIDocShellTreeItem ** aParent) { - NS_ENSURE_ARG_POINTER(aParent); - - *aParent = mParent; - NS_IF_ADDREF(*aParent); - + if (!mParent) { + *aParent = nsnull; + } else { + CallQueryInterface(mParent, aParent); + } + // Note that in the case when the parent is not an nsIDocShellTreeItem we + // don't want to throw; we just want to return null. return NS_OK; } -NS_IMETHODIMP -nsDocShell::SetParent(nsIDocShellTreeItem * aParent) +nsresult +nsDocShell::SetDocLoaderParent(nsDocLoader * aParent) { - // null aParent is ok - /* - Note this doesn't do an addref on purpose. This is because the parent - is an implied lifetime. We don't want to create a cycle by refcounting - the parent. - */ - mParent = aParent; + nsDocLoader::SetDocLoaderParent(aParent); + + // Curse ambiguous nsISupports inheritance! + nsISupports* parent = GetAsSupports(aParent); // If parent is another docshell, we inherit all their flags for // allowing plugins, scripting etc. - nsCOMPtr parentAsDocShell = do_QueryInterface(mParent); + nsCOMPtr parentAsDocShell(do_QueryInterface(parent)); if (parentAsDocShell) { PRBool value; @@ -1816,8 +1804,7 @@ nsDocShell::SetParent(nsIDocShellTreeItem * aParent) } } - nsCOMPtr - parentURIListener(do_GetInterface(aParent)); + nsCOMPtr parentURIListener(do_GetInterface(parent)); if (parentURIListener) SetParentURIContentListener(parentURIListener); return NS_OK; @@ -1829,15 +1816,16 @@ nsDocShell::GetSameTypeParent(nsIDocShellTreeItem ** aParent) NS_ENSURE_ARG_POINTER(aParent); *aParent = nsnull; - if (!mParent) + nsCOMPtr parent = + do_QueryInterface(GetAsSupports(mParent)); + if (!parent) return NS_OK; PRInt32 parentType; - NS_ENSURE_SUCCESS(mParent->GetItemType(&parentType), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(parent->GetItemType(&parentType), NS_ERROR_FAILURE); if (parentType == mItemType) { - *aParent = mParent; - NS_ADDREF(*aParent); + parent.swap(*aParent); } return NS_OK; } @@ -1929,22 +1917,24 @@ nsDocShell::FindItemWithName(const PRUnichar * aName, // and let the parent do the rest. // If we don't have a parent, then we should ask the docShellTreeOwner to do // the search. - if (mParent) { - if (mParent == reqAsTreeItem.get()) + + nsCOMPtr parentAsTreeItem = + do_QueryInterface(GetAsSupports(mParent)); + if (parentAsTreeItem) { + if (parentAsTreeItem == reqAsTreeItem) return NS_OK; PRInt32 parentType; - mParent->GetItemType(&parentType); + parentAsTreeItem->GetItemType(&parentType); if (parentType == mItemType) { - NS_ENSURE_SUCCESS(mParent->FindItemWithName(aName, - NS_STATIC_CAST - (nsIDocShellTreeItem *, - this), _retval), - NS_ERROR_FAILURE); - return NS_OK; + return parentAsTreeItem->FindItemWithName(aName, + NS_STATIC_CAST + (nsIDocShellTreeItem *, + this), _retval); } - // If the parent isn't of the same type fall through and ask tree owner. } + // If the parent is null or not of the same type fall through and ask tree + // owner. // This may fail, but comparing against null serves the same purpose nsCOMPtr @@ -2057,7 +2047,8 @@ nsDocShell::SetTreeOwner(nsIDocShellTreeOwner * aTreeOwner) // Don't automatically set the progress based on the tree owner for frames if (!IsFrame()) { - nsCOMPtr webProgress(do_QueryInterface(mLoadCookie)); + nsCOMPtr webProgress = + do_QueryInterface(GetAsSupports(this)); if (webProgress) { nsCOMPtr @@ -2078,9 +2069,9 @@ nsDocShell::SetTreeOwner(nsIDocShellTreeOwner * aTreeOwner) mTreeOwner = aTreeOwner; // Weak reference per API - PRInt32 i, n = mChildren.Count(); + PRInt32 i, n = mChildList.Count(); for (i = 0; i < n; i++) { - nsIDocShellTreeItem *child = (nsIDocShellTreeItem *) mChildren.ElementAt(i); // doesn't addref the result + nsCOMPtr child = do_QueryInterface(ChildAt(i)); NS_ENSURE_TRUE(child, NS_ERROR_FAILURE); PRInt32 childType = ~mItemType; // Set it to not us in case the get fails child->GetItemType(&childType); // We don't care if this fails, if it does we won't set the owner @@ -2114,7 +2105,7 @@ NS_IMETHODIMP nsDocShell::GetChildCount(PRInt32 * aChildCount) { NS_ENSURE_ARG_POINTER(aChildCount); - *aChildCount = mChildren.Count(); + *aChildCount = mChildList.Count(); return NS_OK; } @@ -2125,15 +2116,35 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild) { NS_ENSURE_ARG_POINTER(aChild); - NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE); - mChildren.AppendElement(aChild); - NS_ADDREF(aChild); + nsRefPtr childAsDocLoader = GetAsDocLoader(aChild); + NS_ENSURE_TRUE(childAsDocLoader, NS_ERROR_UNEXPECTED); + + // Make sure we're not creating a loop in the docshell tree + nsDocLoader* ancestor = this; + do { + if (childAsDocLoader == ancestor) { + return NS_ERROR_ILLEGAL_VALUE; + } + ancestor = ancestor->GetParent(); + } while (ancestor); + + // Make sure to remove the child from its current parent. + nsDocLoader* childsParent = childAsDocLoader->GetParent(); + if (childsParent) { + childsParent->RemoveChildLoader(childAsDocLoader); + } + + // Make sure to clear the treeowner in case this child is a different type + // from us. + aChild->SetTreeOwner(nsnull); + + nsresult res = AddChildLoader(childAsDocLoader); + NS_ENSURE_SUCCESS(res, res); // Set the child's index in the parent's children list // XXX What if the parent had different types of children? - // XXX in that case docshell hierarchyand SH hierarchy won't match. - PRInt32 childCount = mChildren.Count(); - aChild->SetChildOffset(childCount - 1); + // XXX in that case docshell hierarchy and SH hierarchy won't match. + aChild->SetChildOffset(mChildList.Count() - 1); /* Set the child's global history if the parent has one */ if (mGlobalHistory) { @@ -2171,8 +2182,6 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild) if (mItemType == nsIDocShellTreeItem::typeChrome) return NS_OK; - nsresult res = NS_OK; - // get the child's docCSInfo object nsCOMPtr dcInfo = NULL; res = childAsDocShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo)); @@ -2226,15 +2235,15 @@ nsDocShell::RemoveChild(nsIDocShellTreeItem * aChild) { NS_ENSURE_ARG_POINTER(aChild); - if (mChildren.RemoveElement(aChild)) { - aChild->SetParent(nsnull); - aChild->SetTreeOwner(nsnull); - NS_RELEASE(aChild); - } - else - NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG); + nsRefPtr childAsDocLoader = GetAsDocLoader(aChild); + NS_ENSURE_TRUE(childAsDocLoader, NS_ERROR_UNEXPECTED); + + nsresult rv = RemoveChildLoader(childAsDocLoader); + NS_ENSURE_SUCCESS(rv, rv); + + aChild->SetTreeOwner(nsnull); - return NS_OK; + return nsDocLoader::AddDocLoaderAsChildOfRoot(childAsDocLoader); } NS_IMETHODIMP @@ -2242,11 +2251,13 @@ nsDocShell::GetChildAt(PRInt32 aIndex, nsIDocShellTreeItem ** aChild) { NS_ENSURE_ARG_POINTER(aChild); - NS_WARN_IF_FALSE(aIndex >=0 && aIndex < mChildren.Count(), "index of child element is out of range!"); - *aChild = (nsIDocShellTreeItem *) mChildren.SafeElementAt(aIndex); - NS_IF_ADDREF(*aChild); + NS_WARN_IF_FALSE(aIndex >=0 && aIndex < mChildList.Count(), + "index of child element is out of range!"); - return NS_OK; + nsIDocumentLoader* child = SafeChildAt(aIndex); + NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED); + + return CallQueryInterface(child, aChild); } NS_IMETHODIMP @@ -2261,9 +2272,9 @@ nsDocShell::FindChildWithName(const PRUnichar * aName, *_retval = nsnull; // if we don't find one, we return NS_OK and a null result nsXPIDLString childName; - PRInt32 i, n = mChildren.Count(); + PRInt32 i, n = mChildList.Count(); for (i = 0; i < n; i++) { - nsIDocShellTreeItem *child = (nsIDocShellTreeItem *) mChildren.ElementAt(i); // doesn't addref the result + nsCOMPtr child = do_QueryInterface(ChildAt(i)); NS_ENSURE_TRUE(child, NS_ERROR_FAILURE); PRInt32 childType; child->GetItemType(&childType); @@ -2418,7 +2429,8 @@ nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry, } else { /* Just pass this along */ - nsCOMPtr parent(do_QueryInterface(mParent, &rv)); + nsCOMPtr parent = + do_QueryInterface(GetAsSupports(mParent), &rv); if (parent) { rv = parent->AddChildSHEntry(aCloneRef, aNewEntry, aChildOffset); } @@ -2437,7 +2449,8 @@ nsDocShell::DoAddChildSHEntry(nsISHEntry* aNewEntry, PRInt32 aChildOffset) */ nsresult rv; - nsCOMPtr parent(do_QueryInterface(mParent, &rv)); + nsCOMPtr parent = + do_QueryInterface(GetAsSupports(mParent), &rv); if (parent) { rv = parent->AddChildSHEntry(mOSHE, aNewEntry, aChildOffset); } @@ -2921,21 +2934,16 @@ nsDocShell::Stop(PRUint32 aStopFlags) // Cancel any timers that were set for this loader. CancelRefreshURITimers(); - if (mLoadCookie) { - nsCOMPtr uriLoader; - - uriLoader = do_GetService(NS_URI_LOADER_CONTRACTID); - if (uriLoader) - uriLoader->Stop(mLoadCookie); - } + // XXXbz We could also pass |this| to nsIURILoader::Stop. That will + // just call Stop() on us as an nsIDocumentLoader... We need fewer + // redundant apis! + Stop(); } PRInt32 n; - PRInt32 count = mChildren.Count(); + PRInt32 count = mChildList.Count(); for (n = 0; n < count; n++) { - nsIDocShellTreeItem *shell = - (nsIDocShellTreeItem *) mChildren.ElementAt(n); - nsCOMPtr shellAsNav(do_QueryInterface(shell)); + nsCOMPtr shellAsNav(do_QueryInterface(ChildAt(n))); if (shellAsNav) shellAsNav->Stop(aStopFlags); } @@ -3163,8 +3171,8 @@ nsDocShell::Destroy() PersistLayoutHistoryState(); // Remove this docshell from its parent's child list - nsCOMPtr - docShellParentAsNode(do_QueryInterface(mParent)); + nsCOMPtr docShellParentAsNode = + do_QueryInterface(GetAsSupports(mParent)); if (docShellParentAsNode) docShellParentAsNode->RemoveChild(this); @@ -3174,8 +3182,8 @@ nsDocShell::Destroy() mContentViewer = nsnull; } - DestroyChildren(); - + nsDocLoader::Destroy(); + mParentWidget = nsnull; mCurrentURI = nsnull; @@ -3192,8 +3200,6 @@ nsDocShell::Destroy() mSessionHistory = nsnull; SetTreeOwner(nsnull); - SetLoadCookie(nsnull); - if (mContentListener) { mContentListener->DocShell(nsnull); mContentListener->SetParentContentListener(nsnull); @@ -4224,7 +4230,8 @@ nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest, // Update the busy cursor if ((~aStateFlags & (STATE_START | STATE_IS_NETWORK)) == 0) { nsCOMPtr wcwgChannel(do_QueryInterface(aRequest)); - nsCOMPtr webProgress(do_QueryInterface(mLoadCookie)); + nsCOMPtr webProgress = + do_QueryInterface(GetAsSupports(this)); // Was the wyciwyg document loaded on this docshell? if (wcwgChannel && !mLSHE && (mItemType == typeContent) && aProgress == webProgress.get()) { @@ -4271,7 +4278,8 @@ nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest, } } if ((~aStateFlags & (STATE_IS_DOCUMENT | STATE_STOP)) == 0) { - nsCOMPtr webProgress(do_QueryInterface(mLoadCookie)); + nsCOMPtr webProgress = + do_QueryInterface(GetAsSupports(this)); // Is the document stop notification for this document? if (aProgress == webProgress.get()) { nsCOMPtr channel(do_QueryInterface(aRequest)); @@ -4280,7 +4288,8 @@ nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest, } else if ((~aStateFlags & (STATE_IS_DOCUMENT | STATE_REDIRECTING)) == 0) { // XXX Is it enough if I check just for the above 2 flags for redirection - nsCOMPtr webProgress(do_QueryInterface(mLoadCookie)); + nsCOMPtr webProgress = + do_QueryInterface(GetAsSupports(this)); // Is the document stop notification for this document? if (aProgress == webProgress.get()) { @@ -4462,11 +4471,8 @@ nsDocShell::CreateAboutBlankContentViewer() nsCOMPtr docFactory(do_GetService(contractId)); if (docFactory) { - - nsCOMPtr loadGroup(do_GetInterface(mLoadCookie)); - // generate (about:blank) document to load - docFactory->CreateBlankDocument(loadGroup, getter_AddRefs(blankDoc)); + docFactory->CreateBlankDocument(mLoadGroup, getter_AddRefs(blankDoc)); if (blankDoc) { blankDoc->SetContainer(NS_STATIC_CAST(nsIDocShell *, this)); @@ -4500,12 +4506,11 @@ nsDocShell::CreateContentViewer(const char *aContentType, // Can we check the content type of the current content viewer // and reuse it without destroying it and re-creating it? - nsCOMPtr loadGroup(do_GetInterface(mLoadCookie)); - NS_ENSURE_TRUE(loadGroup, NS_ERROR_FAILURE); + NS_ASSERTION(mLoadGroup, "Someone ignored return from Init()?"); // Instantiate the content viewer object nsCOMPtr viewer; - nsresult rv = NewContentViewerObj(aContentType, request, loadGroup, + nsresult rv = NewContentViewerObj(aContentType, request, mLoadGroup, aContentHandler, getter_AddRefs(viewer)); if (NS_FAILED(rv)) @@ -4536,7 +4541,7 @@ nsDocShell::CreateContentViewer(const char *aContentType, GetLoadGroup(getter_AddRefs(currentLoadGroup)), NS_ERROR_FAILURE); - if (currentLoadGroup.get() != loadGroup.get()) { + if (currentLoadGroup != mLoadGroup) { nsLoadFlags loadFlags = 0; //Cancel any URIs that are currently loading... @@ -4550,7 +4555,7 @@ nsDocShell::CreateContentViewer(const char *aContentType, * we don't null-out mLSHE in OnStateChange() for * all redirected urls */ - aOpenedChannel->SetLoadGroup(loadGroup); + aOpenedChannel->SetLoadGroup(mLoadGroup); // Mark the channel as being a document URI... aOpenedChannel->GetLoadFlags(&loadFlags); @@ -4558,7 +4563,7 @@ nsDocShell::CreateContentViewer(const char *aContentType, aOpenedChannel->SetLoadFlags(loadFlags); - loadGroup->AddRequest(request, nsnull); + mLoadGroup->AddRequest(request, nsnull); if (currentLoadGroup) currentLoadGroup->RemoveRequest(request, nsnull, NS_BINDING_RETARGETED); @@ -6581,53 +6586,6 @@ nsDocShell::AddToGlobalHistory(nsIURI * aURI, PRBool aRedirect, nsIURI * aReferr // nsDocShell: Helper Routines //***************************************************************************** -nsresult -nsDocShell::SetLoadCookie(nsISupports * aCookie) -{ - // Remove the DocShell as a listener of the old WebProgress... - if (mLoadCookie) { - nsCOMPtr webProgress(do_QueryInterface(mLoadCookie)); - - if (webProgress) { - webProgress->RemoveProgressListener(this); - } - } - - mLoadCookie = aCookie; - - // Add the DocShell as a listener to the new WebProgress... - if (mLoadCookie) { - nsCOMPtr webProgress(do_QueryInterface(mLoadCookie)); - - if (webProgress) { - webProgress->AddProgressListener(this, - nsIWebProgress::NOTIFY_STATE_DOCUMENT | - nsIWebProgress::NOTIFY_STATE_NETWORK); - } - - nsCOMPtr loadGroup(do_GetInterface(mLoadCookie)); - NS_ENSURE_TRUE(loadGroup, NS_ERROR_FAILURE); - if (loadGroup) { - nsIInterfaceRequestor *ifPtr = NS_STATIC_CAST(nsIInterfaceRequestor *, this); - nsCOMPtr ptr(new InterfaceRequestorProxy(ifPtr)); - if (ptr) { - loadGroup->SetNotificationCallbacks(ptr); - } - } - } - return NS_OK; -} - - -nsresult -nsDocShell::GetLoadCookie(nsISupports ** aResult) -{ - *aResult = mLoadCookie; - NS_IF_ADDREF(*aResult); - - return NS_OK; -} - NS_IMETHODIMP nsDocShell::SetLoadType(PRUint32 aLoadType) { @@ -6831,9 +6789,11 @@ NS_IMETHODIMP nsDocShell::EnsureFind() PRBool nsDocShell::IsFrame() { - if (mParent) { + nsCOMPtr parent = + do_QueryInterface(GetAsSupports(mParent)); + if (parent) { PRInt32 parentType = ~mItemType; // Not us - mParent->GetItemType(&parentType); + parent->GetItemType(&parentType); if (parentType == mItemType) // This is a frame return PR_TRUE; } diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 350f15e7c10..984bdeb419a 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -56,7 +56,7 @@ #include "nsIContentViewerContainer.h" #include "nsIDeviceContext.h" -#include "nsIDocumentLoader.h" +#include "nsDocLoader.h" #include "nsIURILoader.h" #include "nsIEditorDocShell.h" @@ -179,7 +179,8 @@ protected: //*** nsDocShell //***************************************************************************** -class nsDocShell : public nsIDocShell, +class nsDocShell : public nsDocLoader, + public nsIDocShell, public nsIDocShellTreeItem, public nsIDocShellTreeNode, public nsIDocShellHistory, @@ -189,14 +190,12 @@ class nsDocShell : public nsIDocShell, public nsITextScroll, public nsIDocCharset, public nsIContentViewerContainer, - public nsIInterfaceRequestor, public nsIScriptGlobalObjectOwner, public nsIRefreshURI, public nsIWebProgressListener, public nsIEditorDocShell, public nsIWebPageDescriptor, - public nsIAuthPromptProvider, - public nsSupportsWeakReference + public nsIAuthPromptProvider { friend class nsDSURIContentListener; @@ -204,7 +203,9 @@ public: // Object Management nsDocShell(); - NS_DECL_ISUPPORTS + virtual nsresult Init(); + + NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIDOCSHELL NS_DECL_NSIDOCSHELLTREEITEM @@ -223,8 +224,16 @@ public: NS_DECL_NSIWEBPAGEDESCRIPTOR NS_DECL_NSIAUTHPROMPTPROVIDER - nsresult SetLoadCookie(nsISupports * aCookie); - nsresult GetLoadCookie(nsISupports ** aResult); + NS_IMETHOD Stop() { + // Need this here because otherwise nsIWebNavigation::Stop + // overrides the docloader's Stop() + return nsDocLoader::Stop(); + } + + // Need to implement (and forward) nsISecurityEventSink, because + // nsIWebProgressListener has methods with identical names... + NS_FORWARD_NSISECURITYEVENTSINK(nsDocLoader::) + nsDocShellInfoLoadType ConvertLoadTypeToDocShellLoadInfo(PRUint32 aLoadType); PRUint32 ConvertDocShellLoadInfoToLoadType(nsDocShellInfoLoadType aDocShellLoadType); @@ -233,7 +242,7 @@ public: protected: // Object Management virtual ~nsDocShell(); - NS_IMETHOD DestroyChildren(); + virtual void DestroyChildren(); // Content Viewer Management NS_IMETHOD EnsureContentViewer(); @@ -333,6 +342,9 @@ protected: nsresult CheckLoadingPermissions(); protected: + // Override the parent setter from nsDocLoader + virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader); + PRPackedBool mAllowSubframes; PRPackedBool mAllowPlugins; PRPackedBool mAllowJavascript; @@ -383,7 +395,6 @@ protected: * session history entries. */ nsCString mContentTypeHint; - nsVoidArray mChildren; nsCOMPtr mRefreshURIList; nsDSURIContentListener * mContentListener; nsRect mBounds; // Dimensions of the docshell @@ -398,7 +409,6 @@ protected: nsCOMPtr mScriptContext; nsCOMPtr mSessionHistory; nsCOMPtr mGlobalHistory; - nsCOMPtr mLoadCookie; // the load cookie associated with the window context. nsCOMPtr mFind; nsPoint mDefaultScrollbarPref; // persistent across doc loads // Reference to the SHEntry for this docshell until the page is destroyed. @@ -418,7 +428,6 @@ protected: // Note these are intentionally not addrefd. Doing so will create a cycle. // For that reasons don't use nsCOMPtr. - nsIDocShellTreeItem * mParent; // Weak Reference nsIDocShellTreeOwner * mTreeOwner; // Weak Reference nsIChromeEventHandler * mChromeEventHandler; //Weak Reference diff --git a/mozilla/docshell/base/nsIDocShellTreeItem.idl b/mozilla/docshell/base/nsIDocShellTreeItem.idl index b95b5abb313..3a5dfa68c12 100644 --- a/mozilla/docshell/base/nsIDocShellTreeItem.idl +++ b/mozilla/docshell/base/nsIDocShellTreeItem.idl @@ -48,7 +48,7 @@ interface nsIDocShellTreeOwner; * node or a leaf. */ -[scriptable, uuid(B52AE780-A966-11d3-AFC7-00A024FFC08C)] +[scriptable, uuid(1b3416f3-0ec6-49e6-8bdf-77bfdbc4a102)] interface nsIDocShellTreeItem : nsISupports { /* @@ -81,17 +81,9 @@ interface nsIDocShellTreeItem : nsISupports attribute long itemType; /* - Parent DocShell.. Note Implementers of this interface should NOT effect - the lifetime of the parent DocShellTreeItem by holding this reference as it - creates a cycle. Parents when releasing this interface should set the - parent to nsnull. Implementers of this interface are guaranteed that when - parent is set that the pointer is valid without having to addref. - - Further note however when others try to Get the interface you should add - ref it before handing it to them. + Parent DocShell. */ readonly attribute nsIDocShellTreeItem parent; - [noscript] void setParent(in nsIDocShellTreeItem parent); /* This is call returns the same thing parent does however if the parent is diff --git a/mozilla/docshell/base/nsIDocShellTreeNode.idl b/mozilla/docshell/base/nsIDocShellTreeNode.idl index 0497c91ae42..f01f2f107e0 100644 --- a/mozilla/docshell/base/nsIDocShellTreeNode.idl +++ b/mozilla/docshell/base/nsIDocShellTreeNode.idl @@ -47,6 +47,9 @@ * into a docshell tree. */ +// XXXbz this interface should probably inherit from nsIDocShellTreeItem, and +// some methods should move from there to here... + [scriptable, uuid(C094F810-A8AB-11d3-AFC6-00A024FFC08C)] interface nsIDocShellTreeNode : nsISupports { @@ -58,11 +61,17 @@ interface nsIDocShellTreeNode : nsISupports /* Add a new child DocShellTreeItem. Adds to the end of the list. + Note that this does NOT take a reference to the child. The child stays + alive only as long as it's referenced from outside the docshell tree. + @throws NS_ERROR_ILLEGAL_VALUE if child corresponds to the same + object as this treenode or an ancestor of this treenode. + // XXXbz this should take an nsIDocShellTreeNode, I think. */ void addChild(in nsIDocShellTreeItem child); /* Removes a child DocShellTreeItem. + // XXXbz this should take an nsIDocShellTreeNode, I think. */ void removeChild(in nsIDocShellTreeItem child); @@ -80,6 +89,7 @@ interface nsIDocShellTreeNode : nsISupports tree again when a child has asked a parent to search for children. Note the search is depth first when recursing. + // XXXbz this should return an nsIDocShellTreeNode, I think. */ nsIDocShellTreeItem findChildWithName(in wstring aName, in boolean aRecurse, in boolean aSameType, in nsIDocShellTreeItem aRequestor); diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 1f5d336b9db..96c51fb4421 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -183,13 +183,6 @@ nsWebShell::~nsWebShell() { Destroy(); - // Stop any pending document loads and destroy the loader... - if (mDocLoader) { - mDocLoader->Stop(); - mDocLoader->SetContainer(nsnull); - mDocLoader->Destroy(); - mDocLoader = nsnull; - } // Cancel any timers that were set for this loader. CancelRefreshURITimers(); @@ -264,55 +257,19 @@ NS_INTERFACE_MAP_END_INHERITING(nsDocShell) NS_IMETHODIMP nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr) { - NS_ENSURE_ARG_POINTER(aInstancePtr); - nsresult rv = NS_OK; + NS_PRECONDITION(aInstancePtr, "null out param"); + *aInstancePtr = nsnull; - if(aIID.Equals(NS_GET_IID(nsILinkHandler))) - { - // Note: If we ever allow for registering other link handlers, - // we need to make sure that link handler implementations take - // the necessary precautions to prevent the security compromise - // that is blocked by nsWebSell::OnLinkClickSync(). - - *aInstancePtr = NS_STATIC_CAST(nsILinkHandler*, this); - NS_ADDREF((nsISupports*)*aInstancePtr); - return NS_OK; - } - else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObjectOwner))) - { - *aInstancePtr = NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this); - NS_ADDREF((nsISupports*)*aInstancePtr); - return NS_OK; - } - else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObject))) - { - NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE); - *aInstancePtr = mScriptGlobal; - NS_ADDREF((nsISupports*)*aInstancePtr); - return NS_OK; - } - else if(aIID.Equals(NS_GET_IID(nsIDOMWindowInternal)) || - aIID.Equals(NS_GET_IID(nsIDOMWindow))) - - { - NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(aIID, aInstancePtr), - NS_ERROR_FAILURE); - return NS_OK; - } - else if(aIID.Equals(NS_GET_IID(nsICommandManager))) + if(aIID.Equals(NS_GET_IID(nsICommandManager))) { NS_ENSURE_SUCCESS(EnsureCommandHandler(), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(mCommandManager->QueryInterface(NS_GET_IID(nsICommandManager), - aInstancePtr), NS_ERROR_FAILURE); + *aInstancePtr = mCommandManager; + NS_ADDREF((nsISupports*) *aInstancePtr); return NS_OK; } - if (!*aInstancePtr || NS_FAILED(rv)) - return nsDocShell::GetInterface(aIID,aInstancePtr); - else - return rv; + return nsDocShell::GetInterface(aIID, aInstancePtr); } NS_IMETHODIMP @@ -340,19 +297,6 @@ nsWebShell::HandleEvent(nsGUIEvent *aEvent) } -/** - * Document Load methods - */ -NS_IMETHODIMP -nsWebShell::GetDocumentLoader(nsIDocumentLoader*& aResult) -{ - aResult = mDocLoader; - if (!mDocLoader) - return NS_ERROR_FAILURE; - NS_ADDREF(aResult); - return NS_OK; -} - //---------------------------------------------------------------------- // Web Shell Services API @@ -1194,22 +1138,6 @@ NS_IMETHODIMP nsWebShell::Create() WEB_TRACE(WEB_TRACE_CALLS, ("nsWebShell::Init: this=%p", this)); - // HACK....force the uri loader to give us a load cookie for this webshell...then get its - // doc loader and store it...as more of the docshell lands, we'll be able to get rid - // of this hack... - nsresult rv; - nsCOMPtr uriLoader = do_GetService(NS_URI_LOADER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - rv = uriLoader->GetDocumentLoaderForContext(this, - getter_AddRefs(mDocLoader)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr shellAsContainer; - CallQueryInterface(this, NS_STATIC_CAST(nsIContentViewerContainer**, getter_AddRefs(shellAsContainer))); - // Set the webshell as the default IContentViewerContainer for the loader... - mDocLoader->SetContainer(shellAsContainer); - return nsDocShell::Create(); } @@ -1217,7 +1145,7 @@ NS_IMETHODIMP nsWebShell::Destroy() { nsDocShell::Destroy(); - SetContainer(nsnull); + NS_IF_RELEASE(mContainer); return NS_OK; } diff --git a/mozilla/docshell/base/nsWebShell.h b/mozilla/docshell/base/nsWebShell.h index 1caabb8aae5..529f4bd5bbe 100644 --- a/mozilla/docshell/base/nsWebShell.h +++ b/mozilla/docshell/base/nsWebShell.h @@ -83,8 +83,13 @@ public: // nsIWebShell NS_IMETHOD SetContainer(nsIWebShellContainer* aContainer); NS_IMETHOD GetContainer(nsIWebShellContainer*& aResult); - NS_IMETHOD GetDocumentLoader(nsIDocumentLoader*& aResult); + // nsIWebShellContainer::GetContainer overrides an + // nsIDocumentLoader method, so redeclare and forward + NS_IMETHOD GetContainer(nsISupports** aContainer) { + return nsDocLoader::GetContainer(aContainer); + } + // nsILinkHandler NS_IMETHOD OnLinkClick(nsIContent* aContent, nsLinkVerb aVerb, @@ -139,7 +144,6 @@ protected: PRThread *mThread; nsIWebShellContainer* mContainer; - nsCOMPtr mDocLoader; eCharsetReloadState mCharsetReloadState; diff --git a/mozilla/docshell/build/nsDocShellModule.cpp b/mozilla/docshell/build/nsDocShellModule.cpp index 38b590b7ecf..78324dfaca1 100644 --- a/mozilla/docshell/build/nsDocShellModule.cpp +++ b/mozilla/docshell/build/nsDocShellModule.cpp @@ -59,12 +59,12 @@ #include "nsGlobalHistory2Adapter.h" // docshell -NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebShell) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWebShell, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDefaultURIFixup) // uriloader NS_GENERIC_FACTORY_CONSTRUCTOR(nsURILoader) -NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDocLoaderImpl, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDocLoader, Init) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsOSHelperAppService, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsExternalProtocolHandler) NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlockedExternalProtocolHandler) @@ -102,9 +102,8 @@ static const nsModuleComponentInfo gDocShellModuleInfo[] = { // uriloader { "Netscape URI Loader Service", NS_URI_LOADER_CID, NS_URI_LOADER_CONTRACTID, nsURILoaderConstructor, }, - { "Netscape Doc Loader", NS_DOCUMENTLOADER_CID, NS_DOCUMENTLOADER_CONTRACTID, nsDocLoaderImplConstructor, }, { "Netscape Doc Loader Service", NS_DOCUMENTLOADER_SERVICE_CID, NS_DOCUMENTLOADER_SERVICE_CONTRACTID, - nsDocLoaderImplConstructor, }, + nsDocLoaderConstructor, }, { "Netscape External Helper App Service", NS_EXTERNALHELPERAPPSERVICE_CID, NS_EXTERNALHELPERAPPSERVICE_CONTRACTID, nsOSHelperAppServiceConstructor, }, { "Netscape External Helper App Service", NS_EXTERNALHELPERAPPSERVICE_CID, NS_EXTERNALPROTOCOLSERVICE_CONTRACTID, diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp index 4b0c0ccfa81..f432a3b3222 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp @@ -114,7 +114,6 @@ nsWebBrowser::nsWebBrowser() : mDocShellTreeOwner(nsnull), mPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_NONE), mStream(nsnull), mParentWidget(nsnull), - mParent(nsnull), mListenerArray(nsnull) #if (defined(XP_MAC) || defined(XP_MACOSX)) && !defined(MOZ_WIDGET_COCOA) , mTopLevelWidget(nsnull) @@ -521,41 +520,14 @@ NS_IMETHODIMP nsWebBrowser::SetItemType(PRInt32 aItemType) NS_IMETHODIMP nsWebBrowser::GetParent(nsIDocShellTreeItem** aParent) { - NS_ENSURE_ARG_POINTER(aParent); - - *aParent = mParent; - NS_IF_ADDREF(*aParent); - + *aParent = nsnull; return NS_OK; } -NS_IMETHODIMP nsWebBrowser::SetParent(nsIDocShellTreeItem* aParent) -{ - // null aParent is ok - - /* Note this doesn't do an addref on purpose. This is because the parent - is an implied lifetime. We don't want to create a cycle by refcounting - the parent.*/ - mParent = aParent; - return NS_OK; -} - NS_IMETHODIMP nsWebBrowser::GetSameTypeParent(nsIDocShellTreeItem** aParent) { - NS_ENSURE_ARG_POINTER(aParent); *aParent = nsnull; - if(!mParent) - return NS_OK; - - PRInt32 parentType; - NS_ENSURE_SUCCESS(mParent->GetItemType(&parentType), NS_ERROR_FAILURE); - - if(typeContentWrapper == parentType) - { - *aParent = mParent; - NS_ADDREF(*aParent); - } return NS_OK; } diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowser.h b/mozilla/embedding/browser/webBrowser/nsWebBrowser.h index 20e1767b325..05f9f351670 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowser.h +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowser.h @@ -181,7 +181,6 @@ protected: //Weak Reference interfaces... nsIWidget* mParentWidget; - nsIDocShellTreeItem* mParent; nsVoidArray * mListenerArray; #if (defined(XP_MAC) || defined(XP_MACOSX)) && !defined(MOZ_WIDGET_COCOA) diff --git a/mozilla/mailnews/base/src/nsMsgWindow.cpp b/mozilla/mailnews/base/src/nsMsgWindow.cpp index 07502162fcc..b1ccf7c35c1 100644 --- a/mozilla/mailnews/base/src/nsMsgWindow.cpp +++ b/mozilla/mailnews/base/src/nsMsgWindow.cpp @@ -269,16 +269,12 @@ NS_IMETHODIMP nsMsgWindow::SetOpenFolder(nsIMsgFolder * aOpenFolder) NS_IMETHODIMP nsMsgWindow::GetRootDocShell(nsIDocShell * *aDocShell) { - if(!aDocShell) - return NS_ERROR_NULL_POINTER; - - nsCOMPtr rootShell(do_QueryReferent(mRootDocShellWeak)); - - if (rootShell == nsnull) + if (mRootDocShellWeak) { + CallQueryReferent(mRootDocShellWeak.get(), aDocShell); + } else { *aDocShell = nsnull; - else - rootShell->QueryInterface(nsIDocShell::GetIID(), (void **) aDocShell); - + } + return NS_OK; } @@ -382,30 +378,12 @@ NS_IMETHODIMP nsMsgWindow::SetDOMWindow(nsIDOMWindowInternal *aWindow) NS_IMETHODIMP nsMsgWindow::StopUrls() { m_stopped = PR_TRUE; - nsCOMPtr docShell; - GetRootDocShell(getter_AddRefs(docShell)); - if (docShell) + nsCOMPtr webnav(do_QueryReferent(mRootDocShellWeak)); + if (webnav) { - nsCOMPtr webnav(do_QueryInterface(docShell)); return webnav->Stop(nsIWebNavigation::STOP_NETWORK); } - nsCOMPtr rootShell(do_QueryReferent(mRootDocShellWeak)); - nsCOMPtr rootWebShell(do_QueryInterface(rootShell)); - if (rootWebShell) - { - nsCOMPtr docLoader; - nsCOMPtr loadGroup; - - rootWebShell->GetDocumentLoader(*getter_AddRefs(docLoader)); - if (docLoader) - { - docLoader->GetLoadGroup(getter_AddRefs(loadGroup)); - if (loadGroup) - loadGroup->Cancel(NS_BINDING_ABORTED); - } - return NS_OK; - } return NS_ERROR_NULL_POINTER; } diff --git a/mozilla/mailnews/base/util/nsMsgMailNewsUrl.cpp b/mozilla/mailnews/base/util/nsMsgMailNewsUrl.cpp index da6cb1c01d5..55207383442 100644 --- a/mozilla/mailnews/base/util/nsMsgMailNewsUrl.cpp +++ b/mozilla/mailnews/base/util/nsMsgMailNewsUrl.cpp @@ -272,9 +272,10 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetLoadGroup(nsILoadGroup **aLoadGroup) { if (m_msgWindow) { + // XXXbz This is really weird... why are we getting some + // random loadgroup we're not really a part of? nsCOMPtr docShell; m_msgWindow->GetRootDocShell(getter_AddRefs(docShell)); - nsCOMPtr webShell(do_QueryInterface(docShell)); #if 0 // since we're not going through the doc loader for most mail/news urls, //, this code isn't useful @@ -299,13 +300,7 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetLoadGroup(nsILoadGroup **aLoadGroup) } } #endif - if (webShell) - { - nsCOMPtr docLoader; - webShell->GetDocumentLoader(*getter_AddRefs(docLoader)); - if (docLoader) - docLoader->GetLoadGroup(getter_AddRefs(m_loadGroup)); - } + m_loadGroup = do_GetInterface(docShell); } } diff --git a/mozilla/uriloader/base/nsCURILoader.idl b/mozilla/uriloader/base/nsCURILoader.idl index 50fc194d54f..d98aaa18178 100644 --- a/mozilla/uriloader/base/nsCURILoader.idl +++ b/mozilla/uriloader/base/nsCURILoader.idl @@ -52,15 +52,6 @@ nsIURILoader #define NS_URI_LOADER_CONTRACTID \ "@mozilla.org/uriloader;1" -/* 057b04d0-0ccf-11d2-beba-00805f8a66dc */ -#define NS_DOCUMENTLOADER_SERVICE_CID \ - { 0x057b04d0, 0x0ccf, 0x11d2,{0xbe, 0xba, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc}} - -#define NS_DOCUMENTLOADER_CID \ - { 0xdbe63944, 0xd434, 0x11d3, { 0x98, 0xb1, 0x0, 0x10, 0x83, 0x1, 0xe, 0x9b}} -#define NS_DOCUMENTLOADER_CONTRACTID \ -"@mozilla.org/docloader;1" - /* 057b04d0-0ccf-11d2-beba-00805f8a66dc */ #define NS_DOCUMENTLOADER_SERVICE_CID \ { 0x057b04d0, 0x0ccf, 0x11d2,{0xbe, 0xba, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc}} diff --git a/mozilla/uriloader/base/nsDocLoader.cpp b/mozilla/uriloader/base/nsDocLoader.cpp index 5a91d488174..4e1d3fabf5a 100644 --- a/mozilla/uriloader/base/nsDocLoader.cpp +++ b/mozilla/uriloader/base/nsDocLoader.cpp @@ -50,6 +50,7 @@ #include "nsCOMPtr.h" #include "nscore.h" #include "nsWeakPtr.h" +#include "nsAutoPtr.h" #include "nsIDOMWindow.h" @@ -62,6 +63,7 @@ #include "nsISocketTransport.h" static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); +static NS_DEFINE_CID(kThisImplCID, NS_THIS_DOCLOADER_IMPL_CID); #if defined(PR_LOGGING) // @@ -128,7 +130,7 @@ struct nsListenerInfo { }; -nsDocLoaderImpl::nsDocLoaderImpl() +nsDocLoader::nsDocLoader() : mListenerInfoList(8) { #if defined(PR_LOGGING) @@ -137,7 +139,6 @@ nsDocLoaderImpl::nsDocLoaderImpl() } #endif /* PR_LOGGING */ - mContainer = nsnull; mParent = nsnull; mIsLoadingDocument = PR_FALSE; @@ -167,14 +168,14 @@ nsDocLoaderImpl::nsDocLoaderImpl() } nsresult -nsDocLoaderImpl::SetDocLoaderParent(nsDocLoaderImpl *aParent) +nsDocLoader::SetDocLoaderParent(nsDocLoader *aParent) { mParent = aParent; return NS_OK; } nsresult -nsDocLoaderImpl::Init() +nsDocLoader::Init() { if (!mRequestInfoHash.ops) { return NS_ERROR_OUT_OF_MEMORY; @@ -189,7 +190,7 @@ nsDocLoaderImpl::Init() return NS_OK; } -nsDocLoaderImpl::~nsDocLoaderImpl() +nsDocLoader::~nsDocLoader() { /* |ClearWeakReferences()| here is intended to prevent people holding weak references @@ -200,6 +201,8 @@ nsDocLoaderImpl::~nsDocLoaderImpl() An alternative would be incrementing our refcount (consider it a compressed flag saying "Don't re-destroy."). I haven't yet decided which is better. [scc] */ + // XXXbz now that NS_IMPL_RELEASE stabilizes by setting refcount to 1, is + // this needed? ClearWeakReferences(); Destroy(); @@ -207,25 +210,6 @@ nsDocLoaderImpl::~nsDocLoaderImpl() PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader:%p: deleted.\n", this)); - PRInt32 count = mChildList.Count(); - // if the doc loader still has children...we need to enumerate the - // children and make them null out their back ptr to the parent doc - // loader - if (count > 0) - { - for (PRInt32 i=0; i < count; i++) - { - nsIDocumentLoader* loader = mChildList.ObjectAt(i); - - 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(); - } - if (mRequestInfoHash.ops) { PL_DHashTableFinish(&mRequestInfoHash); } @@ -235,10 +219,10 @@ nsDocLoaderImpl::~nsDocLoaderImpl() /* * Implementation of ISupports methods... */ -NS_IMPL_THREADSAFE_ADDREF(nsDocLoaderImpl) -NS_IMPL_THREADSAFE_RELEASE(nsDocLoaderImpl) +NS_IMPL_THREADSAFE_ADDREF(nsDocLoader) +NS_IMPL_THREADSAFE_RELEASE(nsDocLoader) -NS_INTERFACE_MAP_BEGIN(nsDocLoaderImpl) +NS_INTERFACE_MAP_BEGIN(nsDocLoader) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRequestObserver) NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) NS_INTERFACE_MAP_ENTRY(nsIDocumentLoader) @@ -248,13 +232,16 @@ NS_INTERFACE_MAP_BEGIN(nsDocLoaderImpl) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY(nsIHttpEventSink) NS_INTERFACE_MAP_ENTRY(nsISecurityEventSink) + if (aIID.Equals(kThisImplCID)) + foundInterface = NS_STATIC_CAST(nsIDocumentLoader *, this); + else NS_INTERFACE_MAP_END /* * Implementation of nsIInterfaceRequestor methods... */ -NS_IMETHODIMP nsDocLoaderImpl::GetInterface(const nsIID& aIID, void** aSink) +NS_IMETHODIMP nsDocLoader::GetInterface(const nsIID& aIID, void** aSink) { nsresult rv = NS_ERROR_NO_INTERFACE; @@ -271,43 +258,36 @@ NS_IMETHODIMP nsDocLoaderImpl::GetInterface(const nsIID& aIID, void** aSink) return rv; } - - - -NS_IMETHODIMP -nsDocLoaderImpl::CreateDocumentLoader(nsIDocumentLoader** anInstance) +/* static */ +already_AddRefed +nsDocLoader::GetAsDocLoader(nsISupports* aSupports) { - - nsresult rv = NS_OK; - *anInstance = nsnull; - - nsDocLoaderImpl * newLoader = new nsDocLoaderImpl(); - NS_ENSURE_TRUE(newLoader, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(newLoader); - - // Initialize now that we have a reference - rv = newLoader->Init(); - - if (NS_SUCCEEDED(rv)) { - rv = newLoader->SetDocLoaderParent(this); + if (!aSupports) { + return nsnull; } - if (NS_SUCCEEDED(rv)) { - rv = mChildList.AppendObject(newLoader) - ? NS_OK : NS_ERROR_FAILURE; - } - - if (NS_SUCCEEDED(rv)) { - rv = CallQueryInterface(newLoader, anInstance); - } - - NS_RELEASE(newLoader); - return rv; + nsDocLoader* ptr; + CallQueryInterface(aSupports, &ptr); + return ptr; +} + +/* static */ +nsresult +nsDocLoader::AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader) +{ + nsresult rv; + nsCOMPtr docLoaderService = + do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsRefPtr rootDocLoader = GetAsDocLoader(docLoaderService); + NS_ENSURE_TRUE(rootDocLoader, NS_ERROR_UNEXPECTED); + + return rootDocLoader->AddChildLoader(aDocLoader); } NS_IMETHODIMP -nsDocLoaderImpl::Stop(void) +nsDocLoader::Stop(void) { nsresult rv = NS_OK; PRInt32 count, i; @@ -319,7 +299,7 @@ nsDocLoaderImpl::Stop(void) nsCOMPtr loader; for (i=0; i < count; i++) { - loader = mChildList.ObjectAt(i); + loader = ChildAt(i); if (loader) { (void) loader->Stop(); @@ -334,7 +314,7 @@ nsDocLoaderImpl::Stop(void) PRBool -nsDocLoaderImpl::IsBusy() +nsDocLoader::IsBusy() { nsresult rv; @@ -361,11 +341,11 @@ nsDocLoaderImpl::IsBusy() count = mChildList.Count(); for (i=0; i < count; i++) { - nsIDocumentLoader* loader = mChildList.ObjectAt(i); + nsIDocumentLoader* loader = ChildAt(i); - // This is a safe cast, because we only put nsDocLoaderImpl objects into the + // This is a safe cast, because we only put nsDocLoader objects into the // array - if (loader && NS_STATIC_CAST(nsDocLoaderImpl*, loader)->IsBusy()) + if (loader && NS_STATIC_CAST(nsDocLoader*, loader)->IsBusy()) return PR_TRUE; } @@ -373,27 +353,15 @@ nsDocLoaderImpl::IsBusy() } NS_IMETHODIMP -nsDocLoaderImpl::SetContainer(nsISupports* aContainer) +nsDocLoader::GetContainer(nsISupports** aResult) { - // This is a weak reference... - mContainer = aContainer; - - return NS_OK; -} - -NS_IMETHODIMP -nsDocLoaderImpl::GetContainer(nsISupports** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = mContainer; - NS_IF_ADDREF(*aResult); + NS_ADDREF(*aResult = NS_STATIC_CAST(nsIDocumentLoader*, this)); return NS_OK; } NS_IMETHODIMP -nsDocLoaderImpl::GetLoadGroup(nsILoadGroup** aResult) +nsDocLoader::GetLoadGroup(nsILoadGroup** aResult) { nsresult rv = NS_OK; @@ -406,26 +374,23 @@ nsDocLoaderImpl::GetLoadGroup(nsILoadGroup** aResult) return rv; } -NS_IMETHODIMP -nsDocLoaderImpl::Destroy() +void +nsDocLoader::Destroy() { Stop(); -// Remove the document loader from the parent list of loaders... + // Remove the document loader from the parent list of loaders... if (mParent) { - mParent->RemoveChildGroup(this); - mParent = nsnull; + mParent->RemoveChildLoader(this); } // Release all the information about network requests... ClearRequestInfoHash(); // Release all the information about registered listeners... - PRInt32 i, count; - - count = mListenerInfoList.Count(); - for(i=0; iSetGroupObserver(nsnull); - return NS_OK; + DestroyChildren(); +} + +void +nsDocLoader::DestroyChildren() +{ + PRInt32 i, count; + + count = mChildList.Count(); + // if the doc loader still has children...we need to enumerate the + // children and make them null out their back ptr to the parent doc + // loader + for (i=0; i < count; i++) + { + nsIDocumentLoader* loader = ChildAt(i); + + if (loader) { + // This is a safe cast, as we only put nsDocLoader objects into the + // array + NS_STATIC_CAST(nsDocLoader*, loader)->SetDocLoaderParent(nsnull); + } + } + mChildList.Clear(); } NS_IMETHODIMP -nsDocLoaderImpl::OnStartRequest(nsIRequest *request, nsISupports *aCtxt) +nsDocLoader::OnStartRequest(nsIRequest *request, nsISupports *aCtxt) { // called each time a request is added to the group. @@ -527,7 +514,7 @@ nsDocLoaderImpl::OnStartRequest(nsIRequest *request, nsISupports *aCtxt) } NS_IMETHODIMP -nsDocLoaderImpl::OnStopRequest(nsIRequest *aRequest, +nsDocLoader::OnStopRequest(nsIRequest *aRequest, nsISupports *aCtxt, nsresult aStatus) { @@ -666,17 +653,25 @@ nsDocLoaderImpl::OnStopRequest(nsIRequest *aRequest, } -nsresult nsDocLoaderImpl::RemoveChildGroup(nsDocLoaderImpl* aLoader) +nsresult nsDocLoader::RemoveChildLoader(nsDocLoader* aChild) { - nsresult rv = NS_OK; - + nsresult rv = mChildList.RemoveElement(aChild) ? NS_OK : NS_ERROR_FAILURE; if (NS_SUCCEEDED(rv)) { - mChildList.RemoveObject((nsIDocumentLoader*)aLoader); + aChild->SetDocLoaderParent(nsnull); } return rv; } -NS_IMETHODIMP nsDocLoaderImpl::GetDocumentChannel(nsIChannel ** aChannel) +nsresult nsDocLoader::AddChildLoader(nsDocLoader* aChild) +{ + nsresult rv = mChildList.AppendElement(aChild) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + if (NS_SUCCEEDED(rv)) { + aChild->SetDocLoaderParent(this); + } + return rv; +} + +NS_IMETHODIMP nsDocLoader::GetDocumentChannel(nsIChannel ** aChannel) { if (!mDocumentRequest) { *aChannel = nsnull; @@ -687,7 +682,7 @@ NS_IMETHODIMP nsDocLoaderImpl::GetDocumentChannel(nsIChannel ** aChannel) } -void nsDocLoaderImpl::DocLoaderIsEmpty() +void nsDocLoader::DocLoaderIsEmpty() { if (mIsLoadingDocument) { /* In the unimagineably rude circumstance that onload event handlers @@ -733,7 +728,7 @@ void nsDocLoaderImpl::DocLoaderIsEmpty() } } -void nsDocLoaderImpl::doStartDocumentLoad(void) +void nsDocLoader::doStartDocumentLoad(void) { #if defined(DEBUG) @@ -759,7 +754,7 @@ void nsDocLoaderImpl::doStartDocumentLoad(void) NS_OK); } -void nsDocLoaderImpl::doStartURLLoad(nsIRequest *request) +void nsDocLoader::doStartURLLoad(nsIRequest *request) { #if defined(DEBUG) nsCAutoString buffer; @@ -778,7 +773,7 @@ void nsDocLoaderImpl::doStartURLLoad(nsIRequest *request) NS_OK); } -void nsDocLoaderImpl::doStopURLLoad(nsIRequest *request, nsresult aStatus) +void nsDocLoader::doStopURLLoad(nsIRequest *request, nsresult aStatus) { #if defined(DEBUG) nsCAutoString buffer; @@ -797,7 +792,7 @@ void nsDocLoaderImpl::doStopURLLoad(nsIRequest *request, nsresult aStatus) aStatus); } -void nsDocLoaderImpl::doStopDocumentLoad(nsIRequest *request, +void nsDocLoader::doStopDocumentLoad(nsIRequest *request, nsresult aStatus) { #if defined(DEBUG) @@ -839,7 +834,7 @@ void nsDocLoaderImpl::doStopDocumentLoad(nsIRequest *request, // get web progress returns our web progress listener or if // we don't have one, it will look up the doc loader hierarchy // to see if one of our parent doc loaders has one. -nsresult nsDocLoaderImpl::GetParentWebProgressListener(nsDocLoaderImpl * aDocLoader, nsIWebProgressListener ** aWebProgress) +nsresult nsDocLoader::GetParentWebProgressListener(nsDocLoader * aDocLoader, nsIWebProgressListener ** aWebProgress) { // if we got here, there is no web progress to return *aWebProgress = nsnull; @@ -848,7 +843,7 @@ nsresult nsDocLoaderImpl::GetParentWebProgressListener(nsDocLoaderImpl * aDocLoa } NS_IMETHODIMP -nsDocLoaderImpl::AddProgressListener(nsIWebProgressListener *aListener, +nsDocLoader::AddProgressListener(nsIWebProgressListener *aListener, PRUint32 aNotifyMask) { nsresult rv; @@ -874,7 +869,7 @@ nsDocLoaderImpl::AddProgressListener(nsIWebProgressListener *aListener, } NS_IMETHODIMP -nsDocLoaderImpl::RemoveProgressListener(nsIWebProgressListener *aListener) +nsDocLoader::RemoveProgressListener(nsIWebProgressListener *aListener) { nsresult rv; @@ -890,36 +885,20 @@ nsDocLoaderImpl::RemoveProgressListener(nsIWebProgressListener *aListener) } NS_IMETHODIMP -nsDocLoaderImpl::GetDOMWindow(nsIDOMWindow **aResult) +nsDocLoader::GetDOMWindow(nsIDOMWindow **aResult) { - nsresult rv = NS_OK; - - *aResult = nsnull; - // - // The DOM Window is available from the associated container (ie DocShell) - // if one is available... - // - if (mContainer) { - nsCOMPtr window(do_GetInterface(mContainer, &rv)); - - *aResult = window; - NS_IF_ADDREF(*aResult); - } else { - rv = NS_ERROR_FAILURE; - } - - return rv; + return CallGetInterface(this, aResult); } NS_IMETHODIMP -nsDocLoaderImpl::GetIsLoadingDocument(PRBool *aIsLoadingDocument) +nsDocLoader::GetIsLoadingDocument(PRBool *aIsLoadingDocument) { *aIsLoadingDocument = mIsLoadingDocument; return NS_OK; } -PRInt32 nsDocLoaderImpl::GetMaxTotalProgress() +PRInt32 nsDocLoader::GetMaxTotalProgress() { PRInt32 count = 0; PRInt32 individualProgress, newMaxTotal; @@ -932,11 +911,11 @@ PRInt32 nsDocLoaderImpl::GetMaxTotalProgress() for (PRInt32 i=0; i < count; i++) { individualProgress = 0; - docloader = mChildList.ObjectAt(i); + docloader = ChildAt(i); if (docloader) { - // Cast is safe since all children are nsDocLoaderImpl too - individualProgress = ((nsDocLoaderImpl *) docloader.get())->GetMaxTotalProgress(); + // Cast is safe since all children are nsDocLoader too + individualProgress = ((nsDocLoader *) docloader.get())->GetMaxTotalProgress(); } if (individualProgress < 0) // if one of the elements doesn't know it's size // then none of them do @@ -961,7 +940,7 @@ PRInt32 nsDocLoaderImpl::GetMaxTotalProgress() // then turns around and makes the right web progress calls based on this information. //////////////////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsDocLoaderImpl::OnProgress(nsIRequest *aRequest, nsISupports* ctxt, +NS_IMETHODIMP nsDocLoader::OnProgress(nsIRequest *aRequest, nsISupports* ctxt, PRUint32 aProgress, PRUint32 aProgressMax) { nsRequestInfo *info; @@ -1052,7 +1031,7 @@ NS_IMETHODIMP nsDocLoaderImpl::OnProgress(nsIRequest *aRequest, nsISupports* ctx return NS_OK; } -NS_IMETHODIMP nsDocLoaderImpl::OnStatus(nsIRequest* aRequest, nsISupports* ctxt, +NS_IMETHODIMP nsDocLoader::OnStatus(nsIRequest* aRequest, nsISupports* ctxt, nsresult aStatus, const PRUnichar* aStatusArg) { // @@ -1089,7 +1068,7 @@ NS_IMETHODIMP nsDocLoaderImpl::OnStatus(nsIRequest* aRequest, nsISupports* ctxt, return NS_OK; } -void nsDocLoaderImpl::ClearInternalProgress() +void nsDocLoader::ClearInternalProgress() { ClearRequestInfoHash(); @@ -1100,13 +1079,13 @@ void nsDocLoaderImpl::ClearInternalProgress() } -void nsDocLoaderImpl::FireOnProgressChange(nsDocLoaderImpl *aLoadInitiator, - nsIRequest *request, - PRInt32 aProgress, - PRInt32 aProgressMax, - PRInt32 aProgressDelta, - PRInt32 aTotalProgress, - PRInt32 aMaxTotalProgress) +void nsDocLoader::FireOnProgressChange(nsDocLoader *aLoadInitiator, + nsIRequest *request, + PRInt32 aProgress, + PRInt32 aProgressMax, + PRInt32 aProgressDelta, + PRInt32 aTotalProgress, + PRInt32 aMaxTotalProgress) { if (mIsLoadingDocument) { mCurrentTotalProgress += aProgressDelta; @@ -1167,10 +1146,10 @@ void nsDocLoaderImpl::FireOnProgressChange(nsDocLoaderImpl *aLoadInitiator, } -void nsDocLoaderImpl::FireOnStateChange(nsIWebProgress *aProgress, - nsIRequest *aRequest, - PRInt32 aStateFlags, - nsresult aStatus) +void nsDocLoader::FireOnStateChange(nsIWebProgress *aProgress, + nsIRequest *aRequest, + PRInt32 aStateFlags, + nsresult aStatus) { // // Remove the STATE_IS_NETWORK bit if necessary. @@ -1234,10 +1213,10 @@ void nsDocLoaderImpl::FireOnStateChange(nsIWebProgress *aProgress, -NS_IMETHODIMP -nsDocLoaderImpl::FireOnLocationChange(nsIWebProgress* aWebProgress, - nsIRequest* aRequest, - nsIURI *aUri) +void +nsDocLoader::FireOnLocationChange(nsIWebProgress* aWebProgress, + nsIRequest* aRequest, + nsIURI *aUri) { /* * First notify any listeners of the new state info... @@ -1273,15 +1252,13 @@ nsDocLoaderImpl::FireOnLocationChange(nsIWebProgress* aWebProgress, if (mParent) { mParent->FireOnLocationChange(aWebProgress, aRequest, aUri); } - - return NS_OK; } void -nsDocLoaderImpl::FireOnStatusChange(nsIWebProgress* aWebProgress, - nsIRequest* aRequest, - nsresult aStatus, - const PRUnichar* aMessage) +nsDocLoader::FireOnStatusChange(nsIWebProgress* aWebProgress, + nsIRequest* aRequest, + nsresult aStatus, + const PRUnichar* aMessage) { /* * First notify any listeners of the new state info... @@ -1319,7 +1296,7 @@ nsDocLoaderImpl::FireOnStatusChange(nsIWebProgress* aWebProgress, } nsListenerInfo * -nsDocLoaderImpl::GetListenerInfo(nsIWebProgressListener *aListener) +nsDocLoader::GetListenerInfo(nsIWebProgressListener *aListener) { PRInt32 i, count; nsListenerInfo *info; @@ -1339,7 +1316,7 @@ nsDocLoaderImpl::GetListenerInfo(nsIWebProgressListener *aListener) return nsnull; } -nsresult nsDocLoaderImpl::AddRequestInfo(nsIRequest *aRequest) +nsresult nsDocLoader::AddRequestInfo(nsIRequest *aRequest) { if (!PL_DHashTableOperate(&mRequestInfoHash, aRequest, PL_DHASH_ADD)) { return NS_ERROR_OUT_OF_MEMORY; @@ -1348,7 +1325,7 @@ nsresult nsDocLoaderImpl::AddRequestInfo(nsIRequest *aRequest) return NS_OK; } -nsRequestInfo * nsDocLoaderImpl::GetRequestInfo(nsIRequest *aRequest) +nsRequestInfo * nsDocLoader::GetRequestInfo(nsIRequest *aRequest) { nsRequestInfo *info = NS_STATIC_CAST(nsRequestInfo *, @@ -1375,7 +1352,7 @@ RemoveInfoCallback(PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, return PL_DHASH_REMOVE; } -void nsDocLoaderImpl::ClearRequestInfoHash(void) +void nsDocLoader::ClearRequestInfoHash(void) { if (!mRequestInfoHash.ops || !mRequestInfoHash.entryCount) { // No hash, or the hash is empty, nothing to do here then... @@ -1405,14 +1382,15 @@ CalcMaxProgressCallback(PLDHashTable *table, PLDHashEntryHdr *hdr, return PL_DHASH_NEXT; } -PRInt32 nsDocLoaderImpl::CalculateMaxProgress() +PRInt32 nsDocLoader::CalculateMaxProgress() { PRInt32 max = 0; PL_DHashTableEnumerate(&mRequestInfoHash, CalcMaxProgressCallback, &max); return max; } -NS_IMETHODIMP nsDocLoaderImpl::OnRedirect(nsIHttpChannel *aOldChannel, nsIChannel *aNewChannel) +NS_IMETHODIMP nsDocLoader::OnRedirect(nsIHttpChannel *aOldChannel, + nsIChannel *aNewChannel) { if (aOldChannel) { @@ -1452,8 +1430,8 @@ NS_IMETHODIMP nsDocLoaderImpl::OnRedirect(nsIHttpChannel *aOldChannel, nsIChanne * Implementation of nsISecurityEventSink method... */ -NS_IMETHODIMP nsDocLoaderImpl::OnSecurityChange(nsISupports * aContext, - PRUint32 aState) +NS_IMETHODIMP nsDocLoader::OnSecurityChange(nsISupports * aContext, + PRUint32 aState) { // // Fire progress notifications out to any registered nsIWebProgressListeners. @@ -1503,7 +1481,7 @@ NS_IMETHODIMP nsDocLoaderImpl::OnSecurityChange(nsISupports * aContext, #if 0 -void nsDocLoaderImpl::DumpChannelInfo() +void nsDocLoader::DumpChannelInfo() { nsChannelInfo *info; PRInt32 i, count; diff --git a/mozilla/uriloader/base/nsDocLoader.h b/mozilla/uriloader/base/nsDocLoader.h index f38f8918c8f..e60083a6130 100644 --- a/mozilla/uriloader/base/nsDocLoader.h +++ b/mozilla/uriloader/base/nsDocLoader.h @@ -63,26 +63,41 @@ struct nsRequestInfo; struct nsListenerInfo; /**************************************************************************** - * nsDocLoaderImpl implementation... + * nsDocLoader implementation... ****************************************************************************/ -class nsDocLoaderImpl : public nsIDocumentLoader, - public nsIRequestObserver, - public nsSupportsWeakReference, - public nsIProgressEventSink, - public nsIWebProgress, - public nsIInterfaceRequestor, - public nsIHttpEventSink, - public nsISecurityEventSink +#define NS_THIS_DOCLOADER_IMPL_CID \ + { /* 2f7f940d-d67e-40bc-b1ba-8c46de2b4cec */ \ + 0x2f7f940d, \ + 0xd67e, \ + 0x40bc, \ + {0xb1, 0xba, 0x8c, 0x46, 0xde, 0x2b, 0x4c, 0xec} \ + } + +class nsDocLoader : public nsIDocumentLoader, + public nsIRequestObserver, + public nsSupportsWeakReference, + public nsIProgressEventSink, + public nsIWebProgress, + public nsIInterfaceRequestor, + public nsIHttpEventSink, + public nsISecurityEventSink { public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_THIS_DOCLOADER_IMPL_CID); - nsDocLoaderImpl(); + nsDocLoader(); - nsresult Init(); + virtual nsresult Init(); - // for nsIGenericFactory: - static NS_IMETHODIMP Create(nsISupports *aOuter, const nsIID &aIID, void **aResult); + static already_AddRefed GetAsDocLoader(nsISupports* aSupports); + // Needed to deal with ambiguous inheritance from nsISupports... + static nsISupports* GetAsSupports(nsDocLoader* aDocLoader) { + return NS_STATIC_CAST(nsIDocumentLoader*, aDocLoader); + } + + // Add aDocLoader as a child to the docloader service. + static nsresult AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader); NS_DECL_ISUPPORTS NS_DECL_NSIDOCUMENTLOADER @@ -100,16 +115,36 @@ public: NS_DECL_NSIHTTPEVENTSINK // Implementation specific methods... -protected: - virtual ~nsDocLoaderImpl(); - nsresult SetDocLoaderParent(nsDocLoaderImpl * aLoader); - nsresult RemoveChildGroup(nsDocLoaderImpl *aLoader); + // Remove aChild from our childlist. This nulls out the child's mParent + // pointer. + nsresult RemoveChildLoader(nsDocLoader *aChild); + // Add aChild to our child list. This will set aChild's mParent pointer to + // |this|. + nsresult AddChildLoader(nsDocLoader* aChild); + nsDocLoader* GetParent() const { return mParent; } + +protected: + virtual ~nsDocLoader(); + + virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader); + void DocLoaderIsEmpty(); PRBool IsBusy(); - void FireOnProgressChange(nsDocLoaderImpl* aLoadInitiator, + void Destroy(); + virtual void DestroyChildren(); + + nsIDocumentLoader* ChildAt(PRInt32 i) { + return NS_STATIC_CAST(nsDocLoader*, mChildList[i]); + } + + nsIDocumentLoader* SafeChildAt(PRInt32 i) { + return NS_STATIC_CAST(nsDocLoader*, mChildList.SafeElementAt(i)); + } + + void FireOnProgressChange(nsDocLoader* aLoadInitiator, nsIRequest *request, PRInt32 aProgress, PRInt32 aProgressMax, @@ -127,6 +162,10 @@ protected: nsresult aStatus, const PRUnichar* aMessage); + void FireOnLocationChange(nsIWebProgress* aWebProgress, + nsIRequest* aRequest, + nsIURI *aUri); + void doStartDocumentLoad(); void doStartURLLoad(nsIRequest *request); void doStopURLLoad(nsIRequest *request, nsresult aStatus); @@ -135,10 +174,9 @@ protected: // get web progress returns our web progress listener or if // we don't have one, it will look up the doc loader hierarchy // to see if one of our parent doc loaders has one. - nsresult GetParentWebProgressListener(nsDocLoaderImpl * aDocLoader, nsIWebProgressListener ** aWebProgres); + nsresult GetParentWebProgressListener(nsDocLoader * aDocLoader, nsIWebProgressListener ** aWebProgres); protected: - // IMPORTANT: The ownership implicit in the following member // variables has been explicitly checked and set using nsCOMPtr // for owning pointers and raw COM interface pointers for weak @@ -146,9 +184,8 @@ protected: // class, please make the ownership explicit (pinkerton, scc). nsCOMPtr mDocumentRequest; // [OWNER] ???compare with document - nsISupports* mContainer; // [WEAK] it owns me! - nsDocLoaderImpl* mParent; // [WEAK] + nsDocLoader* mParent; // [WEAK] nsVoidArray mListenerInfoList; /* @@ -159,11 +196,11 @@ protected: PRBool mIsLoadingDocument; nsCOMPtr mLoadGroup; - nsCOMArray mChildList; + // We hold weak refs to all our kids + nsVoidArray mChildList; // The following member variables are related to the new nsIWebProgress // feedback interfaces that travis cooked up. - nsCOMPtr mProgressListener; PRInt32 mProgressStateFlags; PRInt32 mCurrentSelfProgress; diff --git a/mozilla/uriloader/base/nsIDocumentLoader.idl b/mozilla/uriloader/base/nsIDocumentLoader.idl index 84a2ca701b8..3e315d3e986 100644 --- a/mozilla/uriloader/base/nsIDocumentLoader.idl +++ b/mozilla/uriloader/base/nsIDocumentLoader.idl @@ -43,28 +43,26 @@ interface nsIWebProgress; interface nsIRequest; /** - * An nsIDocumentLoader is a component responsible for tracking groups of loads - * that belong together (images, external scripts, etc) and subdocuments + * An nsIDocumentLoader is an interface responsible for tracking groups of + * loads that belong together (images, external scripts, etc) and subdocuments * (