From c701f711d38027b3837f656fe6bb14bfa050e45c Mon Sep 17 00:00:00 2001 From: "tbogard%aol.net" Date: Sun, 16 Apr 2000 08:39:15 +0000 Subject: [PATCH] Cached the globalHistory service as it is called a lot especially when dealing with links up in the webshell. Fixed a bug in GetInterface where we were failing to do an else if so if you were requesting a nsIURIContentListener you ended up clearing out the object. --- docshell/base/nsDocShell.cpp | 40 ++++++++++++++++++++++-------------- docshell/base/nsDocShell.h | 19 ++++++++++------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 5105820f0c6c..9d7690abc11e 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -53,7 +53,6 @@ // Interfaces Needed #include "nsICharsetConverterManager.h" -#include "nsIGlobalHistory.h" #include "nsIHTTPChannel.h" #include "nsILayoutHistoryState.h" #include "nsILocaleService.h" @@ -163,7 +162,7 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID& aIID, void** aSink) if(aIID.Equals(NS_GET_IID(nsIURIContentListener)) && NS_SUCCEEDED(EnsureContentListener())) *aSink = mContentListener; - if(aIID.Equals(NS_GET_IID(nsIWebProgressListener)) && + else if(aIID.Equals(NS_GET_IID(nsIWebProgressListener)) && NS_SUCCEEDED(EnsureWebProgressListener())) *aSink = mWebProgressListener; else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObject)) && @@ -637,7 +636,11 @@ NS_IMETHODIMP nsDocShell::SetParent(nsIDocShellTreeItem* aParent) the parent. */ mParent = aParent; - return NS_OK; + + nsCOMPtr parentURIListener(do_GetInterface(aParent)); + if(parentURIListener) + SetParentURIContentListener(parentURIListener); + return NS_OK; } NS_IMETHODIMP nsDocShell::GetSameTypeParent(nsIDocShellTreeItem** aParent) @@ -1624,13 +1627,13 @@ NS_IMETHODIMP nsDocShell::SetTitle(const PRUnichar* aTitle) treeOwnerAsWin->SetTitle(aTitle); } - nsCOMPtr - globalHistory(do_GetService(NS_GLOBALHISTORY_PROGID)); - if(globalHistory && mCurrentURI) + EnsureGlobalHistory(); + + if(mGlobalHistory && mCurrentURI) { nsXPIDLCString url; mCurrentURI->GetSpec(getter_Copies(url)); - globalHistory->SetPageTitle(url, aTitle); + mGlobalHistory->SetPageTitle(url, aTitle); } @@ -2717,6 +2720,18 @@ NS_IMETHODIMP nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry) // nsDocShell: Global History //***************************************************************************** +NS_IMETHODIMP nsDocShell::EnsureGlobalHistory() +{ + if(mGlobalHistory) + return NS_OK; + + mGlobalHistory = do_GetService(NS_GLOBALHISTORY_PROGID); + if(!mGlobalHistory) + return NS_ERROR_FAILURE; + + return NS_OK; +} + NS_IMETHODIMP nsDocShell::ShouldAddToGlobalHistory(nsIURI* aURI, PRBool* aShouldAdd) { @@ -2733,17 +2748,12 @@ NS_IMETHODIMP nsDocShell::ShouldAddToGlobalHistory(nsIURI* aURI, NS_IMETHODIMP nsDocShell::AddToGlobalHistory(nsIURI* aURI) { - nsCOMPtr - globalHistory(do_GetService(NS_GLOBALHISTORY_PROGID)); - - // XXX Remove this when this starts working - if(!globalHistory) - return NS_ERROR_FAILURE; - NS_ENSURE_TRUE(globalHistory, NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(EnsureGlobalHistory(), NS_ERROR_FAILURE); + nsXPIDLCString spec; NS_ENSURE_SUCCESS(aURI->GetSpec(getter_Copies(spec)), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(globalHistory->AddPage(spec, nsnull, PR_Now()), + NS_ENSURE_SUCCESS(mGlobalHistory->AddPage(spec, nsnull, PR_Now()), NS_ERROR_FAILURE); return NS_OK; diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 2dbeffabbc8b..527ab7fba239 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -23,8 +23,6 @@ #ifndef nsDocShell_h__ #define nsDocShell_h__ -#include "nsCOMPtr.h" -#include "nsString.h" #include "nsIParser.h" // for nsCharSetSource #include "nsIPresShell.h" #include "nsIDOMNode.h" @@ -43,23 +41,28 @@ #include "nsIDocumentLoader.h" #include "nsIDocumentLoaderObserver.h" -#include "nsIScriptGlobalObject.h" -#include "nsIScriptGlobalObjectOwner.h" -#include "nsIInterfaceRequestor.h" -#include "nsPoint.h" // mCurrent/mDefaultScrollbarPreferences // Local Includes #include "nsDSURIContentListener.h" #include "nsDSWebProgressListener.h" +// Helper Classes +#include "nsCOMPtr.h" +#include "nsPoint.h" // mCurrent/mDefaultScrollbarPreferences +#include "nsString.h" + // Interfaces Needed #include "nsIDocumentCharsetInfo.h" +#include "nsIGlobalHistory.h" +#include "nsIInterfaceRequestor.h" #include "nsIRefreshURI.h" -#include "nsISupportsArray.h" +#include "nsIScriptGlobalObject.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsISHistory.h" #include "nsIStringBundle.h" +#include "nsISupportsArray.h" #include "nsITimerCallback.h" #include "nsIWebNavigation.h" #include "nsIWebProgress.h" @@ -204,6 +207,7 @@ protected: NS_IMETHOD LoadHistoryEntry(nsISHEntry* aEntry); // Global History + NS_IMETHOD EnsureGlobalHistory(); NS_IMETHOD ShouldAddToGlobalHistory(nsIURI* aURI, PRBool* aShouldAdd); NS_IMETHOD AddToGlobalHistory(nsIURI* aURI); NS_IMETHOD UpdateCurrentGlobalHistory(); @@ -263,6 +267,7 @@ protected: nsCOMPtr mScriptGlobal; nsCOMPtr mScriptContext; nsCOMPtr mSessionHistory; + nsCOMPtr mGlobalHistory; nsCOMPtr mWebProgressListenerList; nsCOMPtr mLoadCookie; // the load cookie associated with the window context. PRInt32 mMarginWidth;