Add a global limit to the number of cached content viewers that scales with the amount of physical memory. Patch by Marria Nazif <marria@gmail.com>. Bug 292965, r=biesi, sr=me.
git-svn-id: svn://10.0.0.236/trunk@180875 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -264,6 +264,8 @@ nsDocShell::nsDocShell():
|
||||
mMarginHeight(0),
|
||||
mItemType(typeContent),
|
||||
mDefaultScrollbarPref(Scrollbar_Auto, Scrollbar_Auto),
|
||||
mPreviousTransIndex(-1),
|
||||
mLoadedTransIndex(-1),
|
||||
mEditorData(nsnull),
|
||||
mTreeOwner(nsnull),
|
||||
mChromeEventHandler(nsnull)
|
||||
@@ -1721,6 +1723,36 @@ nsDocShell::SetUseErrorPages(PRBool aUseErrorPages)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetPreviousTransIndex(PRInt32 *aPreviousTransIndex)
|
||||
{
|
||||
*aPreviousTransIndex = mPreviousTransIndex;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetLoadedTransIndex(PRInt32 *aLoadedTransIndex)
|
||||
{
|
||||
*aLoadedTransIndex = mLoadedTransIndex;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::HistoryPurged(PRInt32 aNumEntries)
|
||||
{
|
||||
mPreviousTransIndex = PR_MAX(-1, mPreviousTransIndex - aNumEntries);
|
||||
|
||||
PRInt32 count = mChildList.Count();
|
||||
for (PRInt32 i = 0; i < count; ++i) {
|
||||
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
|
||||
if (shell) {
|
||||
shell->HistoryPurged(aNumEntries);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// nsDocShell::nsIDocShellTreeItem
|
||||
//*****************************************************************************
|
||||
@@ -2647,12 +2679,30 @@ nsDocShell::DoAddChildSHEntry(nsISHEntry* aNewEntry, PRInt32 aChildOffset)
|
||||
* for this subframe in the CloneAndReplace function.
|
||||
*/
|
||||
|
||||
// In this case, we will end up calling AddEntry, which increases the
|
||||
// current index by 1
|
||||
nsCOMPtr<nsISHistory> rootSH;
|
||||
GetRootSessionHistory(getter_AddRefs(rootSH));
|
||||
if (rootSH) {
|
||||
rootSH->GetIndex(&mPreviousTransIndex);
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDocShellHistory> parent =
|
||||
do_QueryInterface(GetAsSupports(mParent), &rv);
|
||||
if (parent) {
|
||||
rv = parent->AddChildSHEntry(mOSHE, aNewEntry, aChildOffset);
|
||||
}
|
||||
|
||||
|
||||
if (rootSH) {
|
||||
rootSH->GetIndex(&mLoadedTransIndex);
|
||||
#ifdef DEBUG_PAGE_CACHE
|
||||
printf("Previous index: %d, Loaded index: %d\n\n", mPreviousTransIndex,
|
||||
mLoadedTransIndex);
|
||||
#endif
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -4908,10 +4958,15 @@ nsDocShell::CanSavePresentation(PRUint32 aLoadType,
|
||||
|
||||
// Avoid doing the work of saving the presentation state in the case where
|
||||
// the content viewer cache is disabled.
|
||||
PRInt32 maxViewers = 0;
|
||||
mPrefs->GetIntPref("browser.sessionhistory.max_viewers", &maxViewers);
|
||||
if (maxViewers == 0)
|
||||
nsCOMPtr<nsISHistory> rootSH;
|
||||
GetRootSessionHistory(getter_AddRefs(rootSH));
|
||||
if (rootSH) {
|
||||
nsCOMPtr<nsISHistoryInternal> shistInt(do_QueryInterface(rootSH));
|
||||
PRInt32 maxViewers;
|
||||
shistInt->GetHistoryMaxTotalViewers(&maxViewers);
|
||||
if (maxViewers == 0)
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// Don't cache the content viewer if we're in a subframe and the subframe
|
||||
// pref is disabled.
|
||||
@@ -5264,7 +5319,13 @@ nsDocShell::RestoreFromHistory()
|
||||
GetRootSessionHistory(getter_AddRefs(rootSH));
|
||||
if (rootSH) {
|
||||
nsCOMPtr<nsISHistoryInternal> hist = do_QueryInterface(rootSH);
|
||||
rootSH->GetIndex(&mPreviousTransIndex);
|
||||
hist->UpdateIndex();
|
||||
rootSH->GetIndex(&mLoadedTransIndex);
|
||||
#ifdef DEBUG_PAGE_CACHE
|
||||
printf("Previous index: %d, Loaded index: %d\n\n", mPreviousTransIndex,
|
||||
mLoadedTransIndex);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Rather than call Embed(), we will retrieve the viewer from the session
|
||||
@@ -5332,7 +5393,7 @@ nsDocShell::RestoreFromHistory()
|
||||
|
||||
if (mContentViewer) {
|
||||
mContentViewer->Close(mSavingOldViewer ? mOSHE.get() : nsnull);
|
||||
mContentViewer->Destroy();
|
||||
viewer->SetPreviousViewer(mContentViewer);
|
||||
}
|
||||
|
||||
mContentViewer.swap(viewer);
|
||||
@@ -7267,8 +7328,15 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel,
|
||||
// SH.
|
||||
if (rootSH && (mLoadType & LOAD_CMD_HISTORY)) {
|
||||
nsCOMPtr<nsISHistoryInternal> shInternal(do_QueryInterface(rootSH));
|
||||
if (shInternal)
|
||||
if (shInternal) {
|
||||
rootSH->GetIndex(&mPreviousTransIndex);
|
||||
shInternal->UpdateIndex();
|
||||
rootSH->GetIndex(&mLoadedTransIndex);
|
||||
#ifdef DEBUG_PAGE_CACHE
|
||||
printf("Previous index: %d, Loaded index: %d\n\n",
|
||||
mPreviousTransIndex, mLoadedTransIndex);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
PRBool onLocationChangeNeeded = SetCurrentURI(aURI, aChannel,
|
||||
aFireOnLocationChange);
|
||||
@@ -7478,7 +7546,13 @@ nsDocShell::AddToSessionHistory(nsIURI * aURI,
|
||||
nsCOMPtr<nsISHistoryInternal>
|
||||
shPrivate(do_QueryInterface(mSessionHistory));
|
||||
NS_ENSURE_TRUE(shPrivate, NS_ERROR_FAILURE);
|
||||
mSessionHistory->GetIndex(&mPreviousTransIndex);
|
||||
rv = shPrivate->AddEntry(entry, shouldPersist);
|
||||
mSessionHistory->GetIndex(&mLoadedTransIndex);
|
||||
#ifdef DEBUG_PAGE_CACHE
|
||||
printf("Previous index: %d, Loaded index: %d\n\n",
|
||||
mPreviousTransIndex, mLoadedTransIndex);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user