diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index b9e24aec4ee..07a68106636 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -2077,114 +2077,64 @@ nsDocShell::GetGlobalHistory(nsIGlobalHistory ** aGlobalHistory) NS_IMETHODIMP nsDocShell::GetCanGoBack(PRBool * aCanGoBack) { - nsCOMPtr root; - //Get the root docshell - GetSameTypeRootTreeItem(getter_AddRefs(root)); - NS_ENSURE_TRUE(root, NS_ERROR_FAILURE); - // QI to nsIWebNavigation - nsCOMPtr rootAsWebnav(do_QueryInterface(root)); - if (rootAsWebnav) { - // Get the handle to SH from the root docshell - nsCOMPtr rootSH; - rootAsWebnav->GetSessionHistory(getter_AddRefs(rootSH)); - NS_ENSURE_TRUE(rootSH, NS_ERROR_FAILURE); - // QI SH to nsIWebNavigation - nsCOMPtr webNav(do_QueryInterface(rootSH)); - if (webNav) - return webNav->GetCanGoBack(aCanGoBack); - } - return NS_ERROR_FAILURE; + nsresult rv; + nsCOMPtr rootSH; + rv = GetRootSessionHistory(getter_AddRefs(rootSH)); + nsCOMPtr webnav(do_QueryInterface(rootSH)); + NS_ENSURE_TRUE(webnav, NS_ERROR_FAILURE); + rv = webnav->GetCanGoBack(aCanGoBack); + return rv; } NS_IMETHODIMP nsDocShell::GetCanGoForward(PRBool * aCanGoForward) { - nsCOMPtr root; - //Get the root docshell - GetSameTypeRootTreeItem(getter_AddRefs(root)); - NS_ENSURE_TRUE(root, NS_ERROR_FAILURE); - // QI to nsIWebNavigation - nsCOMPtr rootAsWebnav(do_QueryInterface(root)); - if (rootAsWebnav) { - // Get the handle to SH from the root docshell - nsCOMPtr rootSH; - rootAsWebnav->GetSessionHistory(getter_AddRefs(rootSH)); - NS_ENSURE_TRUE(rootSH, NS_ERROR_FAILURE); - // QI SH to nsIWebNavigation - nsCOMPtr webNav(do_QueryInterface(rootSH)); - if (webNav) - return webNav->GetCanGoForward(aCanGoForward); - } - return NS_ERROR_FAILURE; + nsresult rv; + nsCOMPtr rootSH; + rv = GetRootSessionHistory(getter_AddRefs(rootSH)); + nsCOMPtr webnav(do_QueryInterface(rootSH)); + NS_ENSURE_TRUE(webnav, NS_ERROR_FAILURE); + rv = webnav->GetCanGoForward(aCanGoForward); + return rv; } NS_IMETHODIMP nsDocShell::GoBack() { - nsCOMPtr root; - //Get the root docshell - GetSameTypeRootTreeItem(getter_AddRefs(root)); - NS_ENSURE_TRUE(root, NS_ERROR_FAILURE); - // QI to nsIWebNavigation - nsCOMPtr rootAsWebnav(do_QueryInterface(root)); - if (rootAsWebnav) { - // Get the handle to SH from the root docshell - nsCOMPtr rootSH; - rootAsWebnav->GetSessionHistory(getter_AddRefs(rootSH)); - NS_ENSURE_TRUE(rootSH, NS_ERROR_FAILURE); - // QI SH to nsIWebNavigation - nsCOMPtr webNav(do_QueryInterface(rootSH)); - if (webNav) - return webNav->GoBack(); - } - return NS_ERROR_FAILURE; + nsresult rv; + nsCOMPtr rootSH; + rv = GetRootSessionHistory(getter_AddRefs(rootSH)); + nsCOMPtr webnav(do_QueryInterface(rootSH)); + NS_ENSURE_TRUE(webnav, NS_ERROR_FAILURE); + rv = webnav->GoBack(); + return rv; } NS_IMETHODIMP nsDocShell::GoForward() { - nsCOMPtr root; - //Get the root docshell - GetSameTypeRootTreeItem(getter_AddRefs(root)); - NS_ENSURE_TRUE(root, NS_ERROR_FAILURE); - // QI to nsIWebNavigation - nsCOMPtr rootAsWebnav(do_QueryInterface(root)); - if (rootAsWebnav) { - // Get the handle to SH from the root docshell - nsCOMPtr rootSH; - rootAsWebnav->GetSessionHistory(getter_AddRefs(rootSH)); - NS_ENSURE_TRUE(rootSH, NS_ERROR_FAILURE); - // QI SH to nsIWebNavigation - nsCOMPtr webNav(do_QueryInterface(rootSH)); - if (webNav) - return webNav->GoForward(); - } - return NS_ERROR_FAILURE; + nsresult rv; + nsCOMPtr rootSH; + rv = GetRootSessionHistory(getter_AddRefs(rootSH)); + nsCOMPtr webnav(do_QueryInterface(rootSH)); + NS_ENSURE_TRUE(webnav, NS_ERROR_FAILURE); + rv = webnav->GoForward(); + return rv; } NS_IMETHODIMP nsDocShell::GotoIndex(PRInt32 aIndex) { - nsCOMPtr root; - //Get the root docshell - GetSameTypeRootTreeItem(getter_AddRefs(root)); - NS_ENSURE_TRUE(root, NS_ERROR_FAILURE); - // QI to nsIWebNavigation - nsCOMPtr rootAsWebnav(do_QueryInterface(root)); - if (rootAsWebnav) { - // Get the handle to SH from the root docshell - nsCOMPtr rootSH; - rootAsWebnav->GetSessionHistory(getter_AddRefs(rootSH)); - NS_ENSURE_TRUE(rootSH, NS_ERROR_FAILURE); - // QI SH to nsIWebNavigation - nsCOMPtr webNav(do_QueryInterface(rootSH)); - if (webNav) - return webNav->GotoIndex(aIndex); - } - return NS_ERROR_FAILURE; + nsresult rv; + nsCOMPtr rootSH; + rv = GetRootSessionHistory(getter_AddRefs(rootSH)); + nsCOMPtr webnav(do_QueryInterface(rootSH)); + NS_ENSURE_TRUE(webnav, NS_ERROR_FAILURE); + rv = webnav->GotoIndex(aIndex); + return rv; } @@ -2378,6 +2328,7 @@ nsDocShell::SetSessionHistory(nsISHistory * aSessionHistory) } + NS_IMETHODIMP nsDocShell::GetSessionHistory(nsISHistory ** aSessionHistory) { @@ -4706,21 +4657,12 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel, * the current frame or in the root docshell */ nsCOMPtr rootSH=mSessionHistory; - if (!mSessionHistory) { - nsCOMPtr root; - //Get the root docshell - GetSameTypeRootTreeItem(getter_AddRefs(root)); - if (root) { - // QI root to nsIWebNavigation - nsCOMPtr rootAsWebnav(do_QueryInterface(root)); - if (rootAsWebnav) { - // Get the handle to SH from the root docshell - rootAsWebnav->GetSessionHistory(getter_AddRefs(rootSH)); - if (!rootSH) - shAvailable = PR_FALSE; - } - } - } // mSessionHistory + if (!rootSH) { + // Get the handle to SH from the root docshell + nsresult rv = GetRootSessionHistory(getter_AddRefs(rootSH)); + if (!rootSH) + shAvailable = PR_FALSE; + } // rootSH // Determine if this type of load should update history. @@ -5425,6 +5367,23 @@ nsDocShell::CloneAndReplace(nsISHEntry * src, PRUint32 aCloneID, } +nsresult +nsDocShell::GetRootSessionHistory(nsISHistory ** aReturn) +{ + nsresult rv; + + nsCOMPtr root; + //Get the root docshell + rv = GetSameTypeRootTreeItem(getter_AddRefs(root)); + // QI to nsIWebNavigation + nsCOMPtr rootAsWebnav(do_QueryInterface(root)); + if (rootAsWebnav) { + // Get the handle to SH from the root docshell + rv = rootAsWebnav->GetSessionHistory(aReturn); + } + return rv; +} + //***************************************************************************** // nsDocShell: Global History //***************************************************************************** diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 506a06b0098..9c08bd3ea9e 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -237,6 +237,7 @@ protected: NS_IMETHOD PersistLayoutHistoryState(); NS_IMETHOD CloneAndReplace(nsISHEntry * srcEntry, PRUint32 aCloneID, nsISHEntry * areplaceEntry, nsISHEntry ** destEntry); + nsresult GetRootSessionHistory(nsISHistory ** aReturn); // Global History NS_IMETHOD ShouldAddToGlobalHistory(nsIURI * aURI, PRBool * aShouldAdd);