diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 8e522aa7271..134bd465e80 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -230,10 +230,28 @@ NS_IMETHODIMP nsDocShell::LoadURI(nsIURI* aURI, nsIDocShellLoadInfo* aLoadInfo) #endif } - + /* Check if we are in the middle of loading a subframe whose parent + * was originally loaded thro' Session History. ie., you were in a frameset + * page, went somewhere else and clicked 'back'. The loading of the root page + * is done and we are currently loading one of its children or sub-children. + */ + nsCOMPtr parentAsItem; + GetSameTypeParent(getter_AddRefs(parentAsItem)); + nsCOMPtr entry; + nsCOMPtr parent; + // Get your SHEntry from your parent + if (parentAsItem) { + parent = do_QueryInterface(parentAsItem); + if (!parent) + return NS_ERROR_FAILURE; + parent->GetSHEForChild(mChildOffset, getter_AddRefs(entry)); + } + #ifdef SH_IN_FRAMES if (loadInfoSHEntry) NS_ENSURE_SUCCESS(LoadHistoryEntry(loadInfoSHEntry, loadType), NS_ERROR_FAILURE); + else if (entry) + NS_ENSURE_SUCCESS(LoadHistoryEntry(entry, loadType), NS_ERROR_FAILURE); else NS_ENSURE_SUCCESS(InternalLoad(aURI, referrer, owner, nsnull, nsnull, loadType, loadInfoSHEntry), NS_ERROR_FAILURE); #else @@ -436,7 +454,7 @@ NS_IMETHODIMP nsDocShell::SetViewMode(PRInt32 aViewMode) mViewMode = aViewMode; if(reload) - Reload(reloadNormal); + Reload(nsIDocShellLoadInfo::loadReloadNormal); return NS_OK; } @@ -767,7 +785,8 @@ NS_IMETHODIMP nsDocShell::AddChild(nsIDocShellTreeItem *aChild) // 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. - aChild->SetChildOffset((mChildren.Count())-1); + PRInt32 childCount = mChildren.Count(); + aChild->SetChildOffset(childCount-1); PRInt32 childType = ~mItemType; // Set it to not us in case the get fails aChild->GetItemType(&childType); @@ -1054,7 +1073,7 @@ NS_IMETHODIMP nsDocShell::Reload(PRInt32 aReloadType) // XXXTAB Convert reload type to our type nsDocShellInfoLoadType type = nsIDocShellLoadInfo::loadReloadNormal; - if ( aReloadType == nsIWebNavigation::reloadBypassProxyAndCache ) + if ( aReloadType == nsIWebNavigation::loadReloadBypassProxyAndCache ) type = nsIDocShellLoadInfo::loadReloadBypassProxyAndCache; if (mSessionHistory == nsnull) { @@ -1097,7 +1116,7 @@ NS_IMETHODIMP nsDocShell::Reload(PRInt32 aReloadType) // XXXTAB Convert reload type to our type nsDocShellInfoLoadType type = nsIDocShellLoadInfo::loadReloadNormal; - if ( aReloadType == nsIWebNavigation::reloadBypassProxyAndCache ) + if ( aReloadType == nsIWebNavigation::loadReloadBypassProxyAndCache ) type = nsIDocShellLoadInfo::loadReloadBypassProxyAndCache; UpdateCurrentSessionHistory(); @@ -2040,6 +2059,7 @@ NS_IMETHODIMP nsDocShell::Embed(nsIContentViewer* aContentViewer, break; } nsCOMPtr layoutState; + if (OSHE) { rv = OSHE->GetLayoutHistoryState(getter_AddRefs(layoutState)); if (!updateHistory && layoutState) { // This is a SH load. That's why there is a LayoutHistoryState in OSHE @@ -2051,6 +2071,7 @@ NS_IMETHODIMP nsDocShell::Embed(nsIContentViewer* aContentViewer, } } } + } return NS_OK; #else return SetupNewViewer(aContentViewer); @@ -2167,8 +2188,12 @@ NS_IMETHODIMP nsDocShell::CreateContentViewer(const char* aContentType, loadGroup->AddChannel(aOpenedChannel, nsnull); } - +#ifdef SH_IN_FRAMES + NS_ENSURE_SUCCESS(Embed(viewer, "", (nsISupports *) nsnull), NS_ERROR_FAILURE); +#else NS_ENSURE_SUCCESS(SetupNewViewer(viewer), NS_ERROR_FAILURE); +#endif /* SH_IN_FRAMES */ + mEODForCurrentDocument = PR_FALSE; // clear the current flag return NS_OK; } @@ -2295,7 +2320,8 @@ NS_IMETHODIMP nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer) mContentViewer = nsnull; NS_ERROR("ContentViewer Initialization failed"); return NS_ERROR_FAILURE; - } + } +#ifndef SH_IN_FRAMES // Restore up any HistoryLayoutState this page might have. nsresult rv = NS_OK; PRBool updateHistory = PR_TRUE; @@ -2336,6 +2362,7 @@ NS_IMETHODIMP nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer) } } } +#endif /* SH_IN_FRAMES */ mContentViewer->Show(); @@ -2910,29 +2937,31 @@ nsDocShell::OnNewURI(nsIURI *aURI, nsIChannel *aChannel, nsDocShellInfoLoadType * on back/forward and went to a frameset page. and currently, * a subframe in that page is being loaded. */ + /* nsCOMPtr parentAsItem; GetSameTypeParent(getter_AddRefs(parentAsItem)); - nsCOMPtr she; + nsCOMPtr parent; // Get your SHEntry from your parent if (parentAsItem) { parent = do_QueryInterface(parentAsItem); if (!parent) return NS_ERROR_FAILURE; - parent->GetSHEForChild(mChildOffset, getter_AddRefs(she)); + parent->GetSHEForChild(mChildOffset, getter_AddRefs(entry)); } - if (!she) { // Parent didn't have any SHEntry for you + if (!entry) { // Parent didn't have any SHEntry for you + */ /* This is a fresh page getting loaded for the first time *. Create a Entry for it and add it to SH, if this is the * rootDocShell */ - + nsCOMPtr entry; PRBool shouldPersist = PR_FALSE; ShouldPersistInSessionHistory(aURI, &shouldPersist); - nsCOMPtr entry; - if(nsIDocShellLoadInfo::loadNormalReplace == mLoadType) + + if(nsIDocShellLoadInfo::loadNormalReplace == mLoadType && mSessionHistory) { PRInt32 index = 0; mSessionHistory->GetIndex(&index); @@ -2954,7 +2983,9 @@ nsDocShell::OnNewURI(nsIURI *aURI, nsIChannel *aChannel, nsDocShellInfoLoadType } } - + nsXPIDLCString uriSpec; + aURI->GetSpec(getter_Copies(uriSpec)); + printf("Adding url %s to SH\n", (const char *) uriSpec); //Title is set in nsDocShell::SetTitle() NS_ENSURE_SUCCESS(entry->Create(aURI, nsnull, nsnull, inputStream, nsnull), NS_ERROR_FAILURE); @@ -2962,17 +2993,17 @@ nsDocShell::OnNewURI(nsIURI *aURI, nsIChannel *aChannel, nsDocShellInfoLoadType if (mSessionHistory) { NS_ENSURE_SUCCESS(mSessionHistory->AddEntry(entry, shouldPersist), NS_ERROR_FAILURE); + LSHE = entry; } else { - if (parent) { // OSHE could be null here - NS_ENSURE_SUCCESS(parent->AddChildSHEntry(nsnull /* OSHE */, entry), + NS_ENSURE_SUCCESS(AddChildSHEntry(nsnull /* OSHE */, entry, mChildOffset), NS_ERROR_FAILURE); - } + LSHE = entry; } - } //!she + //} //!she // Set the LSHE for non-SH initiated loads. - LSHE = she; + //LSHE = entry; } //!LSHE @@ -2980,7 +3011,7 @@ nsDocShell::OnNewURI(nsIURI *aURI, nsIChannel *aChannel, nsDocShellInfoLoadType if(updateHistory) { - UpdateCurrentSessionHistory(); + UpdateCurrentSessionHistory(); PRBool shouldAdd = PR_FALSE; ShouldAddToSessionHistory(aURI, &shouldAdd); @@ -3330,7 +3361,7 @@ nsDocShell::PersistLayoutHistoryState() } NS_IMETHODIMP -nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry) +nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry, PRInt32 aChildOffset) { nsresult rv; if (LSHE) { @@ -3339,7 +3370,7 @@ nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry) */ nsCOMPtr container(do_QueryInterface(LSHE)); if(container) - rv = container->AddChild(aNewEntry); + rv = container->AddChild(aNewEntry, aChildOffset); } else if (mSessionHistory) { @@ -3355,9 +3386,9 @@ nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry) return NS_ERROR_FAILURE; mSessionHistory->GetEntryAtIndex(index, PR_FALSE, getter_AddRefs(currentEntry)); if (currentEntry) { - nsCOMPtr result(do_CreateInstance(NS_SHENTRY_PROGID)); - NS_ENSURE_TRUE(result, NS_ERROR_FAILURE); - rv = CloneAndReplace(currentEntry, aCloneRef, aNewEntry, result); + nsCOMPtr result; //(do_CreateInstance(NS_SHENTRY_PROGID)); + // NS_ENSURE_TRUE(result, NS_ERROR_FAILURE); + rv = CloneAndReplace(currentEntry, aCloneRef, aNewEntry, getter_AddRefs(result)); if (!NS_SUCCEEDED(rv)) return NS_ERROR_FAILURE; NS_ENSURE_SUCCESS(mSessionHistory->AddEntry(result, PR_TRUE), @@ -3376,14 +3407,15 @@ nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry) if (!webNav) return NS_ERROR_FAILURE; if (aCloneRef) - webNav->AddChildSHEntry(aCloneRef, aNewEntry); + webNav->AddChildSHEntry(aCloneRef, aNewEntry, aChildOffset); else - webNav->AddChildSHEntry(OSHE, aNewEntry); + webNav->AddChildSHEntry(OSHE, aNewEntry, aChildOffset); } return rv; } +#if 0 NS_IMETHODIMP nsDocShell::CloneAndReplace(nsISHEntry * src, nsISHEntry * cloneRef, nsISHEntry * replaceEntry, nsISHEntry * dest) @@ -3443,21 +3475,108 @@ nsDocShell::CloneAndReplace(nsISHEntry * src, nsISHEntry * cloneRef, if (!srcChild) return NS_ERROR_FAILURE; nsCOMPtr destChild(do_CreateInstance(NS_SHENTRY_PROGID)); - if (!destChild) - return NS_ERROR_FAILURE; - result = destContainer->AddChild(destChild); if (!NS_SUCCEEDED(result)) return result; result = CloneAndReplace(srcChild, cloneRef, replaceEntry, destChild); if (!NS_SUCCEEDED(result)) return result; + result = destContainer->AddChild(destChild, i); + if (!NS_SUCCEEDED(result)) + return result; } return result; } +#else +NS_IMETHODIMP +nsDocShell::CloneAndReplace(nsISHEntry * src, nsISHEntry * cloneRef, + nsISHEntry * replaceEntry, nsISHEntry ** resultEntry) +{ + nsresult result = NS_OK; + NS_ENSURE_ARG_POINTER(resultEntry); + if (!src || !replaceEntry || !cloneRef) + return NS_ERROR_FAILURE; +// NS_ENSURE_ARG_POINTER(dest, NS_ERROR_FAILURE); +// static PRBool firstTime = PR_TRUE; +// static nsISHEntry * rootSHEntry = nsnull; + nsISHEntry * dest = *resultEntry; + dest = (nsISHEntry *) nsnull; + if (src == cloneRef) { + // release the original object before assigning a new one. + //NS_RELEASE(dest); + + dest = replaceEntry; + *resultEntry = dest; + NS_IF_ADDREF(*resultEntry); + } + else { + nsCOMPtr uri; + nsCOMPtr postdata; + nsCOMPtr LHS; + PRUnichar * title=nsnull; + nsCOMPtr parent; + result = nsComponentManager::CreateInstance(NS_SHENTRY_PROGID, NULL, + NS_GET_IID(nsISHEntry), (void **) &dest); + if (!NS_SUCCEEDED(result)) + return result; + + src->GetURI(getter_AddRefs(uri)); + src->GetPostData(getter_AddRefs(postdata)); + src->GetTitle(&title); + src->GetLayoutHistoryState(getter_AddRefs(LHS)); + //XXX Is this correct? parent is a weak ref in nsISHEntry + src->GetParent(getter_AddRefs(parent)); + + // XXX do we care much about valid values for these uri, title etc.... + dest->SetURI(uri); + dest->SetPostData(postdata); + dest->SetLayoutHistoryState(LHS); + dest->SetTitle(title); + dest->SetParent(parent); + *resultEntry = dest; + + } + *resultEntry = dest; + /* + if (firstTime) { + // Save the root of the hierarchy in the result parameter + rootSHEntry = dest; + firstTime = PR_FALSE; + } + */ + PRInt32 childCount= 0; + + nsCOMPtr srcContainer(do_QueryInterface(src)); + if (!srcContainer) + return NS_ERROR_FAILURE; + nsCOMPtr destContainer(do_QueryInterface(dest)); + if (!destContainer) + return NS_ERROR_FAILURE; + srcContainer->GetChildCount(&childCount); + for(PRInt32 i = 0; i srcChild; + srcContainer->GetChildAt(i, getter_AddRefs(srcChild)); + if (!srcChild) + return NS_ERROR_FAILURE; + nsCOMPtr destChild; + if (!NS_SUCCEEDED(result)) + return result; + result = CloneAndReplace(srcChild, cloneRef, replaceEntry, getter_AddRefs(destChild)); + if (!NS_SUCCEEDED(result)) + return result; + result = destContainer->AddChild(destChild, i); + if (!NS_SUCCEEDED(result)) + return result; + } + + + return result; + +} +#endif /* 0 */ //***************************************************************************** // nsDocShell: Global History diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 20131cf458e..d4e159ad4c3 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -214,7 +214,7 @@ protected: // NS_IMETHOD GetCurrentSHE(PRInt32 aChildOffset, nsISHEntry ** aResult); NS_IMETHOD PersistLayoutHistoryState(); NS_IMETHOD CloneAndReplace(nsISHEntry * srcEntry, nsISHEntry * aCloneRef, - nsISHEntry * areplaceEntry, nsISHEntry * destEntry); + nsISHEntry * areplaceEntry, nsISHEntry **destEntry); // Global History NS_IMETHOD ShouldAddToGlobalHistory(nsIURI* aURI, PRBool* aShouldAdd); NS_IMETHOD AddToGlobalHistory(nsIURI* aURI); diff --git a/mozilla/docshell/base/nsIWebNavigation.idl b/mozilla/docshell/base/nsIWebNavigation.idl index eb441399fb6..0f75e349447 100644 --- a/mozilla/docshell/base/nsIWebNavigation.idl +++ b/mozilla/docshell/base/nsIWebNavigation.idl @@ -85,10 +85,16 @@ interface nsIWebNavigation : nsISupports /* Definitions for the reload types. */ - const long reloadNormal=0; // Does a normal reload - const long reloadBypassCache=1; // Reloads bypassing the cache - const long reloadBypassProxy=2; // Reloads bypassing the proxy - const long reloadBypassProxyAndCache=3; // Reloads bypassing proxy and cache + /* these are load type enums... */ + const long loadNormal = 0; // Normal Load + const long loadNormalReplace = 1; // Normal Load but replaces current history slot + const long loadHistory = 2; // Load from history + const long loadReloadNormal = 3; // normal Reload + const long loadReloadBypassCache = 4; // Reloads bypassing the cache + const long loadReloadBypassProxy = 5; // Reloads bypassing the proxy + const long loadReloadBypassProxyAndCache = 6;// Reloads bypassing proxy and cache + const long loadLink = 7; + const long loadRefresh = 8; /* Tells the Object to reload the current location. @@ -136,6 +142,6 @@ interface nsIWebNavigation : nsISupports /* Add a Child SHEntry for a frameset page */ - void AddChildSHEntry(in nsISHEntry cloneReference, in nsISHEntry newEntry); + void AddChildSHEntry(in nsISHEntry cloneReference, in nsISHEntry newEntry, in long childOffset); }; \ No newline at end of file diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index ea731cfe9db..789af55611a 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -132,7 +132,7 @@ static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_C #define DETECT_WEBSHELL_LEAKS #endif -//#ifdef SH_IN_FRAMES 1 +//#define SH_IN_FRAMES 1 #ifdef NS_DEBUG /** @@ -580,7 +580,11 @@ nsWebShell::Embed(nsIContentViewer* aContentViewer, const char* aCommand, nsISupports* aExtraInfo) { +#ifdef SH_IN_FRAMES + return nsDocShell::Embed(aContentViewer, aCommand, aExtraInfo); +#else return SetupNewViewer(aContentViewer); +#endif /* SH_IN_FRAMES */ } NS_IMETHODIMP @@ -870,7 +874,7 @@ nsWebShell::ReloadDocument(const char* aCharset, if(eCharsetReloadRequested != mCharsetReloadState) { mCharsetReloadState = eCharsetReloadRequested; - return Reload(reloadNormal); + return Reload(nsIWebNavigation::loadReloadNormal); } } } diff --git a/mozilla/dom/src/base/nsLocation.cpp b/mozilla/dom/src/base/nsLocation.cpp index 7e32a0ecd68..648ef0139a4 100644 --- a/mozilla/dom/src/base/nsLocation.cpp +++ b/mozilla/dom/src/base/nsLocation.cpp @@ -606,7 +606,7 @@ LocationImpl::Reload(PRBool aForceget) nsCOMPtr webNav(do_QueryInterface(mDocShell)); NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(webNav->Reload(nsIWebNavigation::reloadNormal), + NS_ENSURE_SUCCESS(webNav->Reload(nsIWebNavigation::loadReloadNormal), NS_ERROR_FAILURE); return NS_OK; diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp index f9e6f59fe3a..b4baa257873 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp @@ -454,7 +454,7 @@ NS_IMETHODIMP nsWebBrowser::GetSessionHistory(nsISHistory** aSessionHistory) } NS_IMETHODIMP -nsWebBrowser::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry) +nsWebBrowser::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry, PRInt32 aChildOffset) { //XXX Not yet implemented diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index ea731cfe9db..789af55611a 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -132,7 +132,7 @@ static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_C #define DETECT_WEBSHELL_LEAKS #endif -//#ifdef SH_IN_FRAMES 1 +//#define SH_IN_FRAMES 1 #ifdef NS_DEBUG /** @@ -580,7 +580,11 @@ nsWebShell::Embed(nsIContentViewer* aContentViewer, const char* aCommand, nsISupports* aExtraInfo) { +#ifdef SH_IN_FRAMES + return nsDocShell::Embed(aContentViewer, aCommand, aExtraInfo); +#else return SetupNewViewer(aContentViewer); +#endif /* SH_IN_FRAMES */ } NS_IMETHODIMP @@ -870,7 +874,7 @@ nsWebShell::ReloadDocument(const char* aCharset, if(eCharsetReloadRequested != mCharsetReloadState) { mCharsetReloadState = eCharsetReloadRequested; - return Reload(reloadNormal); + return Reload(nsIWebNavigation::loadReloadNormal); } } } diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp index b7f5063f174..e393616f666 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp @@ -519,12 +519,12 @@ nsBrowserInstance::Reload(nsLoadFlags flags) #ifdef SH_IN_FRAMES NS_ENSURE_TRUE(mSessionHistory, NS_ERROR_UNEXPECTED); nsCOMPtr webNav(do_QueryInterface(mSessionHistory)); - webNav->Reload(flags); + webNav->Reload(nsIWebNavigation::loadReloadNormal); #else nsCOMPtr webNav(do_QueryInterface(GetContentAreaDocShell())); NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE); - webNav->Reload(nsIWebNavigation::reloadNormal); + webNav->Reload(nsIWebNavigation::loadReloadNormal); #endif return NS_OK; } diff --git a/mozilla/xpfe/components/shistory/public/nsISHContainer.idl b/mozilla/xpfe/components/shistory/public/nsISHContainer.idl index 78dae93e74a..f7a834c47d3 100644 --- a/mozilla/xpfe/components/shistory/public/nsISHContainer.idl +++ b/mozilla/xpfe/components/shistory/public/nsISHContainer.idl @@ -43,7 +43,7 @@ interface nsISHContainer : nsISupports /** * Add a new child SHEntry. Adds to the end of the list. */ - void AddChild(in nsISHEntry child); + void AddChild(in nsISHEntry child, in long offset); /** * Removes a child SHEntry diff --git a/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp b/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp index 42c561a7270..9e5543ff062 100644 --- a/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp +++ b/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp @@ -46,7 +46,7 @@ NS_IMPL_RELEASE(nsSHEntry) NS_INTERFACE_MAP_BEGIN(nsSHEntry) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISHEntry) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISHContainer) + NS_INTERFACE_MAP_ENTRY(nsISHContainer) NS_INTERFACE_MAP_ENTRY(nsISHEntry) NS_INTERFACE_MAP_END @@ -171,12 +171,16 @@ nsSHEntry::GetChildCount(PRInt32 * aCount) } NS_IMETHODIMP -nsSHEntry::AddChild(nsISHEntry * aChild) +nsSHEntry::AddChild(nsISHEntry * aChild, PRInt32 aOffset) { - NS_ENSURE_ARG_POINTER(aChild); + NS_ENSURE_TRUE(aChild, NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE); - mChildren.AppendElement((void *)aChild); + PRInt32 childCount = mChildren.Count(); + if (aOffset < childCount) + mChildren.InsertElementAt((void *) aChild, aOffset); + else + mChildren.AppendElement((void *)aChild); NS_ADDREF(aChild); return NS_OK; @@ -185,7 +189,7 @@ nsSHEntry::AddChild(nsISHEntry * aChild) NS_IMETHODIMP nsSHEntry::RemoveChild(nsISHEntry * aChild) { - NS_ENSURE_ARG_POINTER(aChild); + NS_ENSURE_TRUE(aChild, NS_ERROR_FAILURE); PRBool childRemoved = mChildren.RemoveElement((void *)aChild); if (childRemoved) { aChild->SetParent(nsnull); diff --git a/mozilla/xpfe/components/shistory/src/nsSHistory.cpp b/mozilla/xpfe/components/shistory/src/nsSHistory.cpp index f11323ecd28..f62a768c724 100644 --- a/mozilla/xpfe/components/shistory/src/nsSHistory.cpp +++ b/mozilla/xpfe/components/shistory/src/nsSHistory.cpp @@ -60,6 +60,7 @@ NS_IMPL_RELEASE(nsSHistory) NS_INTERFACE_MAP_BEGIN(nsSHistory) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISHistory) NS_INTERFACE_MAP_ENTRY(nsISHistory) + NS_INTERFACE_MAP_ENTRY(nsIWebNavigation) NS_INTERFACE_MAP_END //***************************************************************************** @@ -422,7 +423,7 @@ nsSHistory::LoadURI(const PRUnichar* aURI) NS_IMETHODIMP -nsSHistory::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry) +nsSHistory::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry, PRInt32 aChildOffset) { //XXX Not yet implemented @@ -448,7 +449,9 @@ nsSHistory::GotoIndex(PRInt32 aIndex) NS_IMETHODIMP nsSHistory::LoadEntry(PRInt32 aIndex, PRBool aReloadFlag, long aLoadType) { - nsCOMPtr docShell; + // XXX I think the docshell should be a weakref here. The rootDocshell + // from which we start walking down the hierarchy is a weak ref. + nsIDocShell* docShell = nsnull; nsCOMPtr shEntry; PRInt32 oldIndex = mIndex; @@ -462,18 +465,19 @@ nsSHistory::LoadEntry(PRInt32 aIndex, PRBool aReloadFlag, long aLoadType) nsCOMPtr nexturi; nsCOMPtr loadInfo; if (oldIndex != aIndex) { - PRBool result = CompareSHEntry(prevEntry, nextEntry, mRootDocShell, getter_AddRefs(docShell), getter_AddRefs(shEntry)); + PRBool result = CompareSHEntry(prevEntry, nextEntry, mRootDocShell, (&docShell), getter_AddRefs(shEntry)); if (!result) - mIndex = oldIndex; - - if (!docShell || !shEntry || !mRootDocShell) - return NS_ERROR_FAILURE; + mIndex = oldIndex; - - shEntry->GetURI(getter_AddRefs(nexturi)); - } + nextEntry = shEntry; + } else - nextEntry->GetURI(getter_AddRefs(nexturi)); + docShell = mRootDocShell; + + if (!docShell || !nextEntry || !mRootDocShell) + return NS_ERROR_FAILURE; + + nextEntry->GetURI(getter_AddRefs(nexturi)); mRootDocShell->CreateLoadInfo (getter_AddRefs(loadInfo)); // This is not available yet @@ -515,9 +519,17 @@ nsSHistory::CompareSHEntry(nsISHEntry * aPrevEntry, nsISHEntry * aNextEntry, nsI if (!prevUriSpec || !nextUriSpec) return PR_FALSE; - if (prevUriSpec != nextUriSpec) { + // XXX for some reason PL_strcmp isn't returning right value + nsAutoString prevAutoStr(NS_ConvertASCIItoUCS2((const char *)prevUriSpec)); + //nsAutoString nextAutoStr(nextUriSpec); + + if (!(prevAutoStr.EqualsWithConversion((const char *)nextUriSpec))) { *aDSResult = docshell; *aSHEResult = nextEntry; + NS_IF_ADDREF(*aSHEResult); + // XXX we don't addref docshell here. The rootDocShell from which we started + // walking down the hierarchy is a weak ref. + //NS_IF_ADDREF(*aDSResult); return PR_TRUE; } @@ -533,6 +545,8 @@ nsSHistory::CompareSHEntry(nsISHEntry * aPrevEntry, nsISHEntry * aNextEntry, nsI if (!NS_SUCCEEDED(rv) || !dsTreeNode) return PR_FALSE; + if (!prevContainer || !nextContainer) + return PR_FALSE; prevContainer->GetChildCount(&pcnt); nextContainer->GetChildCount(&ncnt); @@ -549,10 +563,13 @@ nsSHistory::CompareSHEntry(nsISHEntry * aPrevEntry, nsISHEntry * aNextEntry, nsI nextContainer->GetChildAt(i, getter_AddRefs(nChild)); dsTreeNode->GetChildAt(i, &dsTreeItemChild); + if (!dsTreeItemChild) + return PR_FALSE; + // XXX How about AddRef in QueryInterface? Is this OK? nsIDocShell * dsChild = nsnull; - rv = dsTreeItemChild->QueryInterface(NS_GET_IID(nsIDocShell), (void **) dsChild); + rv = dsTreeItemChild->QueryInterface(NS_GET_IID(nsIDocShell), (void **) &dsChild); result = CompareSHEntry(pChild, nChild, dsChild, aDSResult, aSHEResult); if (result) // We have found the docshell in which loadUri is to be called.