Skip to content

Commit

Permalink
Moved session history methods from nsIWebNavigation into a new interf…
Browse files Browse the repository at this point in the history
…ace called nsIDocShellHistory. Also made docshells persist layout state before being destroyed (this is necesssary for framesets).
  • Loading branch information
rpotts%netscape.com committed Jul 5, 2000
1 parent 6b7345e commit 32cbe86
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 204 deletions.
1 change: 1 addition & 0 deletions docshell/base/Makefile.in
Expand Up @@ -35,6 +35,7 @@ XPIDLSRCS = \
nsIDocShellTreeItem.idl \ nsIDocShellTreeItem.idl \
nsIDocShellTreeNode.idl \ nsIDocShellTreeNode.idl \
nsIDocShellTreeOwner.idl \ nsIDocShellTreeOwner.idl \
nsIDocShellHistory.idl \
nsIMarkupDocumentViewer.idl \ nsIMarkupDocumentViewer.idl \
nsIScrollable.idl \ nsIScrollable.idl \
nsITextScroll.idl \ nsITextScroll.idl \
Expand Down
1 change: 1 addition & 0 deletions docshell/base/makefile.win
Expand Up @@ -25,6 +25,7 @@ MODULE=docshell_base
XPIDLSRCS= \ XPIDLSRCS= \
.\nsCDocShell.idl \ .\nsCDocShell.idl \
.\nsIDocShell.idl \ .\nsIDocShell.idl \
.\nsIDocShellHistory.idl \
.\nsIDocShellLoadInfo.idl \ .\nsIDocShellLoadInfo.idl \
.\nsIDocShellTreeItem.idl \ .\nsIDocShellTreeItem.idl \
.\nsIDocShellTreeNode.idl \ .\nsIDocShellTreeNode.idl \
Expand Down
249 changes: 138 additions & 111 deletions docshell/base/nsDocShell.cpp
Expand Up @@ -138,6 +138,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell)
NS_INTERFACE_MAP_ENTRY(nsIDocShell) NS_INTERFACE_MAP_ENTRY(nsIDocShell)
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeItem) NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeItem)
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeNode) NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeNode)
NS_INTERFACE_MAP_ENTRY(nsIDocShellHistory)
NS_INTERFACE_MAP_ENTRY(nsIWebNavigation) NS_INTERFACE_MAP_ENTRY(nsIWebNavigation)
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
NS_INTERFACE_MAP_ENTRY(nsIScrollable) NS_INTERFACE_MAP_ENTRY(nsIScrollable)
Expand Down Expand Up @@ -239,13 +240,13 @@ NS_IMETHODIMP nsDocShell::LoadURI(nsIURI* aURI, nsIDocShellLoadInfo* aLoadInfo)
nsCOMPtr<nsIDocShellTreeItem> parentAsItem; nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
GetSameTypeParent(getter_AddRefs(parentAsItem)); GetSameTypeParent(getter_AddRefs(parentAsItem));
nsCOMPtr<nsISHEntry> entry; nsCOMPtr<nsISHEntry> entry;
nsCOMPtr<nsIWebNavigation> parent; nsCOMPtr<nsIDocShellHistory> parent;
// Get your SHEntry from your parent // Get your SHEntry from your parent
if (parentAsItem) { if (parentAsItem) {
parent = do_QueryInterface(parentAsItem); parent = do_QueryInterface(parentAsItem);
if (!parent) if (!parent)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
parent->GetSHEForChild(mChildOffset, getter_AddRefs(entry)); parent->GetChildSHEntry(mChildOffset, getter_AddRefs(entry));
// XXX: should loadType be set to loadHistory ? // XXX: should loadType be set to loadHistory ?
} }


Expand Down Expand Up @@ -377,33 +378,38 @@ nsDocShell::SetDocLoaderObserver(nsIDocumentLoaderObserver * aDocLoaderObserver)


NS_IMETHODIMP nsDocShell::GetPresContext(nsIPresContext** aPresContext) NS_IMETHODIMP nsDocShell::GetPresContext(nsIPresContext** aPresContext)
{ {
NS_ENSURE_ARG_POINTER(aPresContext); nsresult rv = NS_OK;
*aPresContext = nsnull;


NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE); NS_ENSURE_ARG_POINTER(aPresContext);

*aPresContext = nsnull;
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer));
NS_ENSURE_TRUE(docv, NS_ERROR_FAILURE);


NS_ENSURE_SUCCESS(docv->GetPresContext(*aPresContext), NS_ERROR_FAILURE); if (mContentViewer) {
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer));


return NS_OK; if (docv) {
rv = docv->GetPresContext(*aPresContext);
}
}

// Fail silently, if no PresContext is available...
return rv;
} }


NS_IMETHODIMP nsDocShell::GetPresShell(nsIPresShell** aPresShell) NS_IMETHODIMP nsDocShell::GetPresShell(nsIPresShell** aPresShell)
{ {
NS_ENSURE_ARG_POINTER(aPresShell); nsresult rv = NS_OK;
*aPresShell = nsnull;
NS_ENSURE_ARG_POINTER(aPresShell);
*aPresShell = nsnull;


nsCOMPtr<nsIPresContext> presContext; nsCOMPtr<nsIPresContext> presContext;
NS_ENSURE_SUCCESS(GetPresContext(getter_AddRefs(presContext)), (void) GetPresContext(getter_AddRefs(presContext));
NS_ERROR_FAILURE);
if(!presContext)
return NS_OK;


NS_ENSURE_SUCCESS(presContext->GetShell(aPresShell), NS_ERROR_FAILURE); if(presContext) {
rv = presContext->GetShell(aPresShell);
}


return NS_OK; return rv;
} }


NS_IMETHODIMP nsDocShell::GetContentViewer(nsIContentViewer** aContentViewer) NS_IMETHODIMP nsDocShell::GetContentViewer(nsIContentViewer** aContentViewer)
Expand Down Expand Up @@ -955,6 +961,90 @@ NS_IMETHODIMP nsDocShell::FindChildWithName(const PRUnichar *aName,
return NS_OK; return NS_OK;
} }


//*****************************************************************************
// nsDocShell::nsIDocShellHistory
//*****************************************************************************
NS_IMETHODIMP
nsDocShell::GetChildSHEntry(PRInt32 aChildOffset, nsISHEntry ** aResult)
{
nsresult rv = NS_OK;

NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;

//
// A nsISHEntry for a child is *only* available when the parent is in
// the progress of loading a document too...
//
if (LSHE) {
nsCOMPtr<nsISHContainer> container(do_QueryInterface(LSHE));
if (container) {
rv = container->GetChildAt(aChildOffset, aResult);
}
}
return rv;
}

NS_IMETHODIMP
nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry,
PRInt32 aChildOffset)
{
nsresult rv;

if (LSHE) {
/* You get here if you are currently building a
* hierarchy ie.,you just visited a frameset page
*/
nsCOMPtr<nsISHContainer> container(do_QueryInterface(LSHE, &rv));
if(container)
rv = container->AddChild(aNewEntry, aChildOffset);
}
else if (mSessionHistory) {
/* You are currently in the rootDocShell.
* You will get here when a subframe has a new url
* to load and you have walked up the tree all the
* way to the top
*/
PRInt32 index=-1;
nsCOMPtr<nsISHEntry> currentEntry;
mSessionHistory->GetIndex(&index);
if (index < 0)
return NS_ERROR_FAILURE;

rv = mSessionHistory->GetEntryAtIndex(index, PR_FALSE,
getter_AddRefs(currentEntry));
if (currentEntry) {
nsCOMPtr<nsISHEntry> nextEntry; //(do_CreateInstance(NS_SHENTRY_PROGID));
// NS_ENSURE_TRUE(result, NS_ERROR_FAILURE);
rv = CloneAndReplace(currentEntry, aCloneRef, aNewEntry,
getter_AddRefs(nextEntry));

if (NS_SUCCEEDED(rv)) {
rv = mSessionHistory->AddEntry(nextEntry, PR_TRUE);
}
}
}
else {
/* You will get here when you are in a subframe and
* a new url has been loaded on you.
* The OSHE in this subframe will be the previous url's
* OSHE. This OSHE will be used as the identification
* for this subframe in the CloneAndReplace function.
*/

nsCOMPtr<nsIDocShellHistory> parent(do_QueryInterface(mParent, &rv));
if (parent) {
if (!aCloneRef) {
aCloneRef = OSHE;
}
rv = parent->AddChildSHEntry(aCloneRef, aNewEntry, aChildOffset);
}

}
return rv;
}


//***************************************************************************** //*****************************************************************************
// nsDocShell::nsIWebNavigation // nsDocShell::nsIWebNavigation
//***************************************************************************** //*****************************************************************************
Expand Down Expand Up @@ -1333,6 +1423,11 @@ NS_IMETHODIMP nsDocShell::Destroy()


SetDocLoaderObserver(nsnull); SetDocLoaderObserver(nsnull);


// Save the state of the current document, before destroying the window.
// This is needed to capture the state of a frameset when the new document
// causes the frameset to be destroyed...
PersistLayoutHistoryState();

// Remove this docshell from its parent's child list // Remove this docshell from its parent's child list
nsCOMPtr<nsIDocShellTreeNode> docShellParentAsNode(do_QueryInterface(mParent)); nsCOMPtr<nsIDocShellTreeNode> docShellParentAsNode(do_QueryInterface(mParent));
if(docShellParentAsNode) if(docShellParentAsNode)
Expand Down Expand Up @@ -2128,7 +2223,7 @@ NS_IMETHODIMP nsDocShell::Embed(nsIContentViewer* aContentViewer,
// XXX What if SetupNewViewer fails? // XXX What if SetupNewViewer fails?


OSHE = LSHE; OSHE = LSHE;

/*
PRBool updateHistory = PR_TRUE; PRBool updateHistory = PR_TRUE;
// Determine if this type of load should update history // Determine if this type of load should update history
Expand All @@ -2144,20 +2239,20 @@ NS_IMETHODIMP nsDocShell::Embed(nsIContentViewer* aContentViewer,
default: default:
break; break;
} }
nsCOMPtr<nsILayoutHistoryState> layoutState; */
if (OSHE) { if (OSHE) {
nsCOMPtr<nsILayoutHistoryState> layoutState;

rv = OSHE->GetLayoutHistoryState(getter_AddRefs(layoutState)); rv = OSHE->GetLayoutHistoryState(getter_AddRefs(layoutState));
if (!updateHistory && layoutState) { if (layoutState) {
// This is a SH load. That's why there is a LayoutHistoryState in OSHE // This is a SH load. That's why there is a LayoutHistoryState in OSHE
if (NS_SUCCEEDED(rv) && layoutState) { nsCOMPtr<nsIPresShell> presShell;
nsCOMPtr<nsIPresShell> presShell; rv = GetPresShell(getter_AddRefs(presShell));
rv = GetPresShell(getter_AddRefs(presShell)); if (NS_SUCCEEDED(rv) && presShell) {
if (NS_SUCCEEDED(rv) && presShell) { rv = presShell->SetHistoryState(layoutState);
rv = presShell->SetHistoryState(layoutState); }
}
}
} }
} }
return NS_OK; return NS_OK;
#else #else
return SetupNewViewer(aContentViewer); return SetupNewViewer(aContentViewer);
Expand Down Expand Up @@ -3059,6 +3154,7 @@ nsDocShell::OnNewURI(nsIURI *aURI, nsIChannel *aChannel, nsDocShellInfoLoadType
*. Create a Entry for it and add it to SH, if this is the *. Create a Entry for it and add it to SH, if this is the
* rootDocShell * rootDocShell
*/ */
nsresult rv;
nsCOMPtr<nsISHEntry> entry; nsCOMPtr<nsISHEntry> entry;
PRBool shouldPersist = PR_FALSE; PRBool shouldPersist = PR_FALSE;
ShouldPersistInSessionHistory(aURI, &shouldPersist); ShouldPersistInSessionHistory(aURI, &shouldPersist);
Expand Down Expand Up @@ -3094,17 +3190,16 @@ nsDocShell::OnNewURI(nsIURI *aURI, nsIChannel *aChannel, nsDocShellInfoLoadType
NS_ENSURE_SUCCESS(entry->Create(aURI, nsnull, nsnull, NS_ENSURE_SUCCESS(entry->Create(aURI, nsnull, nsnull,
inputStream, nsnull), NS_ERROR_FAILURE); inputStream, nsnull), NS_ERROR_FAILURE);


if (mSessionHistory) { if (mSessionHistory) {
NS_ENSURE_SUCCESS(mSessionHistory->AddEntry(entry, shouldPersist), rv = mSessionHistory->AddEntry(entry, shouldPersist);
NS_ERROR_FAILURE); }
LSHE = entry; else {
} rv = AddChildSHEntry(nsnull, entry, mChildOffset);
else { }
// OSHE could be null here // Update LSHE if the entry was added...
NS_ENSURE_SUCCESS(AddChildSHEntry(nsnull /* OSHE */, entry, mChildOffset), if (NS_SUCCEEDED(rv)) {
NS_ERROR_FAILURE); LSHE = entry;
LSHE = entry; }
}
//} //!she //} //!she
// Set the LSHE for non-SH initiated loads. // Set the LSHE for non-SH initiated loads.
//LSHE = entry; //LSHE = entry;
Expand Down Expand Up @@ -3373,7 +3468,7 @@ NS_IMETHODIMP nsDocShell::UpdateCurrentSessionHistory()
} }


#ifdef SH_IN_FRAMES #ifdef SH_IN_FRAMES
NS_IMETHODIMP nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry, nsDocShellInfoLoadType aLoadType) NS_IMETHODIMP nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry, nsDocShellInfoLoadType aLoadType)
#else #else
NS_IMETHODIMP nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry) NS_IMETHODIMP nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry)
#endif #endif
Expand Down Expand Up @@ -3431,19 +3526,6 @@ nsDocShell::GetSHEForChild(PRInt32 aChildOffset, nsISHEntry ** aResult)
} }
*/ */
NS_IMETHODIMP
nsDocShell::GetSHEForChild(PRInt32 aChildOffset, nsISHEntry ** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);

if (LSHE) {
nsCOMPtr<nsISHContainer> container(do_QueryInterface(LSHE));
if (container)
return container->GetChildAt(aChildOffset, aResult);
}
return NS_ERROR_FAILURE;
}

NS_IMETHODIMP NS_IMETHODIMP
nsDocShell::PersistLayoutHistoryState() nsDocShell::PersistLayoutHistoryState()
{ {
Expand All @@ -3464,61 +3546,6 @@ nsDocShell::PersistLayoutHistoryState()
return rv; return rv;
} }


NS_IMETHODIMP
nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry, PRInt32 aChildOffset)
{
nsresult rv;
if (LSHE) {
/* You get here if you are currently building a
* hierarchy ie.,you just visited a frameset page
*/
nsCOMPtr<nsISHContainer> container(do_QueryInterface(LSHE));
if(container)
rv = container->AddChild(aNewEntry, aChildOffset);

}
else if (mSessionHistory) {
/* You are currently in the rootDocShell.
* You will get here when a subframe has a new url
* to load and you have walked up the tree all the
* way to the top
*/
PRInt32 index=-1;
nsCOMPtr<nsISHEntry> currentEntry;
mSessionHistory->GetIndex(&index);
if (index < 0)
return NS_ERROR_FAILURE;
mSessionHistory->GetEntryAtIndex(index, PR_FALSE, getter_AddRefs(currentEntry));
if (currentEntry) {
nsCOMPtr<nsISHEntry> 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),
NS_ERROR_FAILURE);
}
}
else {
/* You will get here when you are in a subframe and
* a new url has been loaded on you.
* The OSHE in this subframe will be the previous url's
* OSHE. This OSHE will be used as the identification
* for this subframe in the CloneAndReplace function.
*/

nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mParent));
if (!webNav)
return NS_ERROR_FAILURE;
if (aCloneRef)
webNav->AddChildSHEntry(aCloneRef, aNewEntry, aChildOffset);
else
webNav->AddChildSHEntry(OSHE, aNewEntry, aChildOffset);

}
return rv;
}

#if 0 #if 0
NS_IMETHODIMP NS_IMETHODIMP
nsDocShell::CloneAndReplace(nsISHEntry * src, nsISHEntry * cloneRef, nsDocShell::CloneAndReplace(nsISHEntry * src, nsISHEntry * cloneRef,
Expand Down
3 changes: 3 additions & 0 deletions docshell/base/nsDocShell.h
Expand Up @@ -69,6 +69,7 @@
#include "nsIWebProgressListener.h" #include "nsIWebProgressListener.h"
#include "nsISHContainer.h" #include "nsISHContainer.h"
#include "nsIDocShellLoadInfo.h" #include "nsIDocShellLoadInfo.h"
#include "nsIDocShellHistory.h"


//***************************************************************************** //*****************************************************************************
//*** nsRefreshTimer //*** nsRefreshTimer
Expand Down Expand Up @@ -114,6 +115,7 @@ class nsDocShellInitInfo
class nsDocShell : public nsIDocShell, class nsDocShell : public nsIDocShell,
public nsIDocShellTreeItem, public nsIDocShellTreeItem,
public nsIDocShellTreeNode, public nsIDocShellTreeNode,
public nsIDocShellHistory,
public nsIWebNavigation, public nsIWebNavigation,
public nsIBaseWindow, public nsIBaseWindow,
public nsIScrollable, public nsIScrollable,
Expand All @@ -136,6 +138,7 @@ friend class nsDSURIContentListener;
NS_DECL_NSIDOCSHELL NS_DECL_NSIDOCSHELL
NS_DECL_NSIDOCSHELLTREEITEM NS_DECL_NSIDOCSHELLTREEITEM
NS_DECL_NSIDOCSHELLTREENODE NS_DECL_NSIDOCSHELLTREENODE
NS_DECL_NSIDOCSHELLHISTORY
NS_DECL_NSIWEBNAVIGATION NS_DECL_NSIWEBNAVIGATION
NS_DECL_NSIBASEWINDOW NS_DECL_NSIBASEWINDOW
NS_DECL_NSISCROLLABLE NS_DECL_NSISCROLLABLE
Expand Down

0 comments on commit 32cbe86

Please sign in to comment.