diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 7faa360321a..6464e5cdcf5 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -242,6 +242,9 @@ static PRInt32 gNumberOfDocumentsLoading = 0; // Global count of existing docshells. static PRInt32 gDocShellCount = 0; +// Global count of docshells with the private attribute set +static PRUint32 gNumberOfPrivateDocShells = 0; + // Global reference to the URI fixup service. nsIURIFixup *nsDocShell::sURIFixup = 0; @@ -710,6 +713,19 @@ ConvertLoadTypeToNavigationType(PRUint32 aLoadType) static nsISHEntry* GetRootSHEntry(nsISHEntry *entry); +static void +DecreasePrivateDocShellCount() +{ + MOZ_ASSERT(gNumberOfPrivateDocShells > 0); + gNumberOfPrivateDocShells--; + if (!gNumberOfPrivateDocShells) + { + nsCOMPtr obsvc = mozilla::services::GetObserverService(); + if (obsvc) + obsvc->NotifyObservers(nsnull, "last-pb-context-exited", nsnull); + } +} + //***************************************************************************** //*** nsDocShell: Object Management //***************************************************************************** @@ -816,6 +832,10 @@ nsDocShell::~nsDocShell() printf("--DOCSHELL %p == %ld\n", (void*) this, gNumberOfDocShells); } #endif + + if (mInPrivateBrowsing) { + DecreasePrivateDocShellCount(); + } } nsresult @@ -1998,7 +2018,12 @@ NS_IMETHODIMP nsDocShell::SetUsePrivateBrowsing(bool aUsePrivateBrowsing) { mInPrivateBrowsing = aUsePrivateBrowsing; - + if (aUsePrivateBrowsing) { + gNumberOfPrivateDocShells++; + } else { + DecreasePrivateDocShellCount(); + } + PRInt32 count = mChildList.Count(); for (PRInt32 i = 0; i < count; ++i) { nsCOMPtr shell = do_QueryInterface(ChildAt(i));