Bug 725210 - Add observer notification for last PB docshell going away. r=bz

This commit is contained in:
Josh Matthews 2012-02-21 12:32:17 -05:00
parent dbe94b8be8
commit 2cc5f8574f

View File

@ -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<nsIObserverService> obsvc = mozilla::services::GetObserverService();
if (obsvc)
obsvc->NotifyObservers(nsnull, "last-pb-context-exited", nsnull);
}
}
//*****************************************************************************
//*** nsDocShell: Object Management
//*****************************************************************************
@ -818,6 +834,10 @@ nsDocShell::~nsDocShell()
gNumberOfDocShells, mHistoryID);
}
#endif
if (mInPrivateBrowsing) {
DecreasePrivateDocShellCount();
}
}
nsresult
@ -1999,8 +2019,15 @@ nsDocShell::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
NS_IMETHODIMP
nsDocShell::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
{
mInPrivateBrowsing = aUsePrivateBrowsing;
if (aUsePrivateBrowsing != mInPrivateBrowsing) {
mInPrivateBrowsing = aUsePrivateBrowsing;
if (aUsePrivateBrowsing) {
gNumberOfPrivateDocShells++;
} else {
DecreasePrivateDocShellCount();
}
}
PRInt32 count = mChildList.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsCOMPtr<nsILoadContext> shell = do_QueryInterface(ChildAt(i));