From 8bb87d2184efa7120714cafceff3a660bac2c9ec Mon Sep 17 00:00:00 2001 From: "radha%netscape.com" Date: Thu, 2 Sep 1999 21:39:01 +0000 Subject: [PATCH] Hook up session history with the history state object. Let LoadURL() accept a historystate as an argument git-svn-id: svn://10.0.0.236/trunk@45753 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsWebShell.cpp | 64 +++++++++++++++++++++------ mozilla/webshell/public/nsIWebShell.h | 6 ++- mozilla/webshell/src/nsWebShell.cpp | 64 +++++++++++++++++++++------ 3 files changed, 106 insertions(+), 28 deletions(-) diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 8b0229a345c..6820552fbc3 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -241,7 +241,8 @@ public: #else nsURLReloadType aType = nsURLReload, #endif - const PRUint32 localIP = 0); + const PRUint32 localIP = 0, + nsISupports * aHistoryState = nsnull); NS_IMETHOD LoadURL(const PRUnichar *aURLSpec, const char* aCommand, nsIInputStream* aPostDataStream=nsnull, @@ -251,7 +252,8 @@ public: #else nsURLReloadType aType = nsURLReload, #endif - const PRUint32 localIP = 0); + const PRUint32 localIP = 0, + nsISupports * aHistoryState=nsnull); NS_IMETHOD Stop(void); @@ -1990,14 +1992,15 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec, #else nsURLReloadType aType, #endif - const PRUint32 aLocalIP) + const PRUint32 aLocalIP, + nsISupports * aHistoryState) { // Initialize margnwidth, marginheight. Put scrolling back the way it was // before the last document was loaded. InitFrameData(PR_FALSE); return LoadURL(aURLSpec, "view", aPostDataStream, - aModifyHistory,aType, aLocalIP); + aModifyHistory,aType, aLocalIP, aHistoryState); } // Nisheeth: returns true if the host and the file parts of @@ -2226,7 +2229,8 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec, #else nsURLReloadType aType, #endif - const PRUint32 aLocalIP) + const PRUint32 aLocalIP, + nsISupports * aHistoryState) { nsresult rv; @@ -2342,24 +2346,55 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec, } + /* + * Before the new page is added to the session history, + * save the history information of the previous page in + * session history + */ + nsISupports * historyState=nsnull; + + // Get the history object for the previous page. + rv = GetHistoryState(&historyState); + nsCOMPtr rootWebShell; + rv = GetRootWebShell(*getter_AddRefs(rootWebShell)); + if (NS_SUCCEEDED(rv) && rootWebShell) + { + nsCOMPtr shist; + rv = rootWebShell->GetSessionHistory(*getter_AddRefs(shist)); + if (NS_SUCCEEDED(rv) && shist) { + PRInt32 indix=0; + shist->getCurrentIndex(indix); + // Save it in session history + shist->SetHistoryObjectForIndex(indix, historyState); + } + } + + + /* If this is one of the frames, get it from the top level shell */ if (aModifyHistory) { - nsCOMPtr webShell; - rv = GetRootWebShell(*getter_AddRefs(webShell)); - if (NS_SUCCEEDED(rv) && webShell) + if (rootWebShell) { - nsCOMPtr shist; - webShell->GetSessionHistory(*getter_AddRefs(shist)); + nsCOMPtr shist; + rootWebShell->GetSessionHistory(*getter_AddRefs(shist)); /* Add yourself to the Session History */ if (shist) { PRInt32 ret=0; ret = shist->add(this); } - } + } } - + + /* Set the History state object for the current page in the + * presentation shell. If it is a new page being visited, + * aHistoryState is null. If the load is coming from + * session History, it will be set to the cached history object by + * session History. + */ + SetHistoryState(aHistoryState); + nsString* url = new nsString(uriSpec); if (aModifyHistory) { // Discard part of history that is no longer reachable @@ -2402,6 +2437,7 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec, //#endif } + NS_IMETHODIMP nsWebShell::Stop(void) { if (nsnull != mContentViewer) { @@ -2846,7 +2882,9 @@ nsWebShell::GetHistoryState(nsISupports** aLayoutHistoryState) // XXX Need to think about what to do for framesets. // For now, return an error if this webshell // contains a frame or a frameset document. - if (mParent || mChildren.Count() > 0) { + // The main content area will always have a parent. It is + // enough to check the children count to verify frames. + if (mChildren.Count() > 0) { return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/webshell/public/nsIWebShell.h b/mozilla/webshell/public/nsIWebShell.h index d7041c2aacf..e59d81db9f4 100644 --- a/mozilla/webshell/public/nsIWebShell.h +++ b/mozilla/webshell/public/nsIWebShell.h @@ -347,7 +347,8 @@ public: #else nsURLReloadType aType=nsURLReload, #endif - const PRUint32 aLocalIP=0) = 0; + const PRUint32 aLocalIP=0, + nsISupports * aHistoryState=nsnull) = 0; /** * Load the document associated with the specified URL into the WebShell. @@ -361,7 +362,8 @@ public: #else nsURLReloadType aType=nsURLReload, #endif - const PRUint32 aLocalIP=0) = 0; + const PRUint32 aLocalIP=0, + nsISupports * aHistoryState=nsnull) = 0; /** diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index 8b0229a345c..6820552fbc3 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -241,7 +241,8 @@ public: #else nsURLReloadType aType = nsURLReload, #endif - const PRUint32 localIP = 0); + const PRUint32 localIP = 0, + nsISupports * aHistoryState = nsnull); NS_IMETHOD LoadURL(const PRUnichar *aURLSpec, const char* aCommand, nsIInputStream* aPostDataStream=nsnull, @@ -251,7 +252,8 @@ public: #else nsURLReloadType aType = nsURLReload, #endif - const PRUint32 localIP = 0); + const PRUint32 localIP = 0, + nsISupports * aHistoryState=nsnull); NS_IMETHOD Stop(void); @@ -1990,14 +1992,15 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec, #else nsURLReloadType aType, #endif - const PRUint32 aLocalIP) + const PRUint32 aLocalIP, + nsISupports * aHistoryState) { // Initialize margnwidth, marginheight. Put scrolling back the way it was // before the last document was loaded. InitFrameData(PR_FALSE); return LoadURL(aURLSpec, "view", aPostDataStream, - aModifyHistory,aType, aLocalIP); + aModifyHistory,aType, aLocalIP, aHistoryState); } // Nisheeth: returns true if the host and the file parts of @@ -2226,7 +2229,8 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec, #else nsURLReloadType aType, #endif - const PRUint32 aLocalIP) + const PRUint32 aLocalIP, + nsISupports * aHistoryState) { nsresult rv; @@ -2342,24 +2346,55 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec, } + /* + * Before the new page is added to the session history, + * save the history information of the previous page in + * session history + */ + nsISupports * historyState=nsnull; + + // Get the history object for the previous page. + rv = GetHistoryState(&historyState); + nsCOMPtr rootWebShell; + rv = GetRootWebShell(*getter_AddRefs(rootWebShell)); + if (NS_SUCCEEDED(rv) && rootWebShell) + { + nsCOMPtr shist; + rv = rootWebShell->GetSessionHistory(*getter_AddRefs(shist)); + if (NS_SUCCEEDED(rv) && shist) { + PRInt32 indix=0; + shist->getCurrentIndex(indix); + // Save it in session history + shist->SetHistoryObjectForIndex(indix, historyState); + } + } + + + /* If this is one of the frames, get it from the top level shell */ if (aModifyHistory) { - nsCOMPtr webShell; - rv = GetRootWebShell(*getter_AddRefs(webShell)); - if (NS_SUCCEEDED(rv) && webShell) + if (rootWebShell) { - nsCOMPtr shist; - webShell->GetSessionHistory(*getter_AddRefs(shist)); + nsCOMPtr shist; + rootWebShell->GetSessionHistory(*getter_AddRefs(shist)); /* Add yourself to the Session History */ if (shist) { PRInt32 ret=0; ret = shist->add(this); } - } + } } - + + /* Set the History state object for the current page in the + * presentation shell. If it is a new page being visited, + * aHistoryState is null. If the load is coming from + * session History, it will be set to the cached history object by + * session History. + */ + SetHistoryState(aHistoryState); + nsString* url = new nsString(uriSpec); if (aModifyHistory) { // Discard part of history that is no longer reachable @@ -2402,6 +2437,7 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec, //#endif } + NS_IMETHODIMP nsWebShell::Stop(void) { if (nsnull != mContentViewer) { @@ -2846,7 +2882,9 @@ nsWebShell::GetHistoryState(nsISupports** aLayoutHistoryState) // XXX Need to think about what to do for framesets. // For now, return an error if this webshell // contains a frame or a frameset document. - if (mParent || mChildren.Count() > 0) { + // The main content area will always have a parent. It is + // enough to check the children count to verify frames. + if (mChildren.Count() > 0) { return NS_ERROR_NOT_IMPLEMENTED; }