Bug 827188 - Initialize the hidden private window lazily; r=bzbarsky

This commit is contained in:
Ehsan Akhgari
2013-01-06 21:16:48 -05:00
parent c95ee8f5e1
commit ce9f1908ee
6 changed files with 118 additions and 36 deletions

View File

@@ -193,7 +193,10 @@
#include "mozilla/Telemetry.h"
#include "nsISecurityUITelemetry.h"
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
#include "nsIAppShellService.h"
#include "nsAppShellCID.h"
#else
#include "nsIPrivateBrowsingService.h"
#endif
@@ -220,9 +223,9 @@ static uint32_t gNumberOfPrivateDocShells = 0;
// Global count of private docshells which will always remain open
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
static const uint32_t kNumberOfAlwaysOpenPrivateDocShells = 1; // the private hidden window
static uint32_t gNumberOfAlwaysOpenPrivateDocShells = 0; // the private hidden window
#else
static const uint32_t kNumberOfAlwaysOpenPrivateDocShells = 0;
static const uint32_t gNumberOfAlwaysOpenPrivateDocShells = 0;
#endif
// Global reference to the URI fixup service.
@@ -688,11 +691,27 @@ ConvertLoadTypeToNavigationType(uint32_t aLoadType)
static nsISHEntry* GetRootSHEntry(nsISHEntry *entry);
static void
AdjustAlwaysOpenPrivateDocShellCount()
{
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
nsCOMPtr<nsIAppShellService> appShell
(do_GetService(NS_APPSHELLSERVICE_CONTRACTID));
bool hasHiddenPrivateWindow = false;
if (appShell) {
appShell->GetHasHiddenPrivateWindow(&hasHiddenPrivateWindow);
}
gNumberOfAlwaysOpenPrivateDocShells = hasHiddenPrivateWindow ? 1 : 0;
#endif
}
static void
IncreasePrivateDocShellCount()
{
AdjustAlwaysOpenPrivateDocShellCount();
gNumberOfPrivateDocShells++;
if (gNumberOfPrivateDocShells > kNumberOfAlwaysOpenPrivateDocShells + 1 ||
if (gNumberOfPrivateDocShells > gNumberOfAlwaysOpenPrivateDocShells + 1 ||
XRE_GetProcessType() != GeckoProcessType_Content) {
return;
}
@@ -704,9 +723,11 @@ IncreasePrivateDocShellCount()
static void
DecreasePrivateDocShellCount()
{
AdjustAlwaysOpenPrivateDocShellCount();
MOZ_ASSERT(gNumberOfPrivateDocShells > 0);
gNumberOfPrivateDocShells--;
if (gNumberOfPrivateDocShells == kNumberOfAlwaysOpenPrivateDocShells)
if (gNumberOfPrivateDocShells == gNumberOfAlwaysOpenPrivateDocShells)
{
if (XRE_GetProcessType() == GeckoProcessType_Content) {
mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild::GetSingleton();