Backed out changeset cc665373ff61 (bug 829383). CLOSED TREEs don't bother me.
authorJosh Matthews <josh@joshmatthews.net>
Mon, 21 Jan 2013 16:22:38 +0000
changeset 119430 1aa6bf0a46a2fb1598ef427e77edfb31628d677a
parent 119429 f57f7c12b6dc379233f42533c66dde5e523fc5ee
child 119431 97e4a7b942cdc903a0a42123aad1d726420155c8
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
bugs829383
milestone21.0a1
backs outcc665373ff61580dde5379b6de4006b93e6ab5e5
Backed out changeset cc665373ff61 (bug 829383). CLOSED TREEs don't bother me.
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
docshell/base/nsIDocShell.idl
docshell/test/chrome/Makefile.in
docshell/test/chrome/test_private_hidden_window.html
xpfe/appshell/src/nsAppShellService.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -217,16 +217,23 @@ using namespace mozilla::dom;
 static int32_t gNumberOfDocumentsLoading = 0;
 
 // Global count of existing docshells.
 static int32_t gDocShellCount = 0;
 
 // Global count of docshells with the private attribute set
 static uint32_t gNumberOfPrivateDocShells = 0;
 
+// Global count of private docshells which will always remain open
+#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
+static uint32_t gNumberOfAlwaysOpenPrivateDocShells = 0; // the private hidden window
+#else
+static const uint32_t gNumberOfAlwaysOpenPrivateDocShells = 0;
+#endif
+
 // Global reference to the URI fixup service.
 nsIURIFixup *nsDocShell::sURIFixup = 0;
 
 // True means we validate window targets to prevent frameset
 // spoofing. Initialize this to a non-bolean value so we know to check
 // the pref on the creation of the first docshell.
 static uint32_t gValidateOrigin = 0xffffffff;
 
@@ -681,34 +688,52 @@ ConvertLoadTypeToNavigationType(uint32_t
   }
 
   return result;
 }
 
 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 > 1 ||
+    if (gNumberOfPrivateDocShells > gNumberOfAlwaysOpenPrivateDocShells + 1 ||
         XRE_GetProcessType() != GeckoProcessType_Content) {
         return;
     }
 
     mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild::GetSingleton();
     cc->SendPrivateDocShellsExist(true);
 }
 
 static void
 DecreasePrivateDocShellCount()
 {
+    AdjustAlwaysOpenPrivateDocShellCount();
+
     MOZ_ASSERT(gNumberOfPrivateDocShells > 0);
     gNumberOfPrivateDocShells--;
-    if (!gNumberOfPrivateDocShells)
+    if (gNumberOfPrivateDocShells == gNumberOfAlwaysOpenPrivateDocShells)
     {
         if (XRE_GetProcessType() == GeckoProcessType_Content) {
             mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild::GetSingleton();
             cc->SendPrivateDocShellsExist(false);
             return;
         }
 
         nsCOMPtr<nsIObserverService> obsvc = mozilla::services::GetObserverService();
@@ -765,17 +790,16 @@ nsDocShell::nsDocShell():
     mURIResultedInDocument(false),
     mIsBeingDestroyed(false),
     mIsExecutingOnLoadHandler(false),
     mIsPrintingOrPP(false),
     mSavingOldViewer(false),
 #ifdef DEBUG
     mInEnsureScriptEnv(false),
 #endif
-    mAffectPrivateSessionLifetime(true),
     mFrameType(eFrameTypeRegular),
     mOwnOrContainingAppId(nsIScriptSecurityManager::UNKNOWN_APP_ID),
     mParentCharsetSource(0)
 {
     mHistoryID = ++gDocshellIDCounter;
     if (gDocShellCount++ == 0) {
         NS_ASSERTION(sURIFixup == nullptr,
                      "Huh, sURIFixup not null in first nsDocShell ctor!");
@@ -2040,22 +2064,20 @@ nsDocShell::SetUsePrivateBrowsing(bool a
 }
 
 NS_IMETHODIMP
 nsDocShell::SetPrivateBrowsing(bool aUsePrivateBrowsing)
 {
     bool changed = aUsePrivateBrowsing != mInPrivateBrowsing;
     if (changed) {
         mInPrivateBrowsing = aUsePrivateBrowsing;
-        if (mAffectPrivateSessionLifetime) {
-            if (aUsePrivateBrowsing) {
-                IncreasePrivateDocShellCount();
-            } else {
-                DecreasePrivateDocShellCount();
-            }
+        if (aUsePrivateBrowsing) {
+            IncreasePrivateDocShellCount();
+        } else {
+            DecreasePrivateDocShellCount();
         }
     }
 
     int32_t count = mChildList.Count();
     for (int32_t i = 0; i < count; ++i) {
         nsCOMPtr<nsILoadContext> shell = do_QueryInterface(ChildAt(i));
         if (shell) {
             shell->SetPrivateBrowsing(aUsePrivateBrowsing);
@@ -2073,46 +2095,16 @@ nsDocShell::SetPrivateBrowsing(bool aUse
                 obs->PrivateModeChanged(aUsePrivateBrowsing);
             }
         }
     }
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDocShell::SetAffectPrivateSessionLifetime(bool aAffectLifetime)
-{
-    bool change = aAffectLifetime != mAffectPrivateSessionLifetime;
-    if (change && mInPrivateBrowsing) {
-        if (aAffectLifetime) {
-            IncreasePrivateDocShellCount();
-        } else {
-            DecreasePrivateDocShellCount();
-        }
-    }
-    mAffectPrivateSessionLifetime = aAffectLifetime;
-
-    int32_t count = mChildList.Count();
-    for (int32_t i = 0; i < count; ++i) {
-        nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
-        if (shell) {
-            shell->SetAffectPrivateSessionLifetime(aAffectLifetime);
-        }
-    }
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDocShell::GetAffectPrivateSessionLifetime(bool* aAffectLifetime)
-{
-    *aAffectLifetime = mAffectPrivateSessionLifetime;
-    return NS_OK;
-}
-
-NS_IMETHODIMP
 nsDocShell::AddWeakPrivacyTransitionObserver(nsIPrivacyTransitionObserver* aObserver)
 {
     nsWeakPtr weakObs = do_GetWeakReference(aObserver);
     if (!weakObs) {
         return NS_ERROR_NOT_AVAILABLE;
     }
     return mPrivacyObservers.AppendElement(weakObs) ? NS_OK : NS_ERROR_FAILURE;
 }
@@ -2836,18 +2828,16 @@ nsDocShell::SetDocLoaderParent(nsDocLoad
         if (NS_SUCCEEDED(parentAsDocShell->GetIsActive(&value)))
         {
             SetIsActive(value);
         }
         if (NS_FAILED(parentAsDocShell->GetAllowDNSPrefetch(&value))) {
             value = false;
         }
         SetAllowDNSPrefetch(value);
-        value = parentAsDocShell->GetAffectPrivateSessionLifetime();
-        SetAffectPrivateSessionLifetime(value);
     }
 
     nsCOMPtr<nsILoadContext> parentAsLoadContext(do_QueryInterface(parent));
     if (parentAsLoadContext &&
         NS_SUCCEEDED(parentAsLoadContext->GetUsePrivateBrowsing(&value)))
     {
         SetPrivateBrowsing(value);
 #ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
@@ -4982,19 +4972,17 @@ nsDocShell::Destroy()
     mSecurityUI = nullptr;
 
     // Cancel any timers that were set for this docshell; this is needed
     // to break the cycle between us and the timers.
     CancelRefreshURITimers();
 
     if (mInPrivateBrowsing) {
         mInPrivateBrowsing = false;
-        if (mAffectPrivateSessionLifetime) {
-            DecreasePrivateDocShellCount();
-        }
+        DecreasePrivateDocShellCount();
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetUnscaledDevicePixelsPerCSSPixel(double *aScale)
 {
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -837,17 +837,16 @@ protected:
     // should be passed a SHEntry to save itself into.
     bool                       mSavingOldViewer;
     
     // @see nsIDocShellHistory::createdDynamically
     bool                       mDynamicallyCreated;
 #ifdef DEBUG
     bool                       mInEnsureScriptEnv;
 #endif
-    bool                       mAffectPrivateSessionLifetime;
     uint64_t                   mHistoryID;
 
     static nsIURIFixup *sURIFixup;
 
     nsRefPtr<nsDOMNavigationTiming> mTiming;
 
     // Are we a regular frame, a browser frame, or an app frame?
     FrameType mFrameType;
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -34,17 +34,17 @@ interface nsISHEntry;
 interface nsILayoutHistoryState;
 interface nsISecureBrowserUI;
 interface nsIDOMStorage;
 interface nsIPrincipal;
 interface nsIWebBrowserPrint;
 interface nsIVariant;
 interface nsIPrivacyTransitionObserver;
 
-[scriptable, builtinclass, uuid(fc7e18cd-c671-4d78-a022-7de87555e15f)]
+[scriptable, builtinclass, uuid(ca15d803-1330-4154-b3f9-063fb2b443e7)]
 interface nsIDocShell : nsISupports
 {
   /**
    * Loads a given URI.  This will give priority to loading the requested URI
    * in the object implementing	this interface.  If it can't be loaded here
    * however, the URL dispatcher will go through its normal process of content
    * loading.
    *
@@ -721,16 +721,14 @@ interface nsIDocShell : nsISupports
    * "allowfullscreen" attribute to the child process. Setting
    * fullscreenAllowed on docshells which aren't content boundaries throws an
    * exception.
    */
   [infallible] readonly attribute boolean fullscreenAllowed;
   
   void setFullscreenAllowed(in boolean allowed);
 
-  [noscript, infallible] attribute boolean affectPrivateSessionLifetime;
-
   /**
    * Indicates whether the UI may enable the character encoding menu. The UI
    * must disable the menu when this property is false.
    */
   [infallible] readonly attribute boolean mayEnableCharacterEncodingMenu;
 };
--- a/docshell/test/chrome/Makefile.in
+++ b/docshell/test/chrome/Makefile.in
@@ -89,17 +89,16 @@ MOCHITEST_CHROME_FILES =	\
 		test_bug690056.xul \
 		bug690056_window.xul \
 		test_bug311007.xul \
 		bug311007_window.xul \
 		test_principalInherit.xul \
 		test_mozFrameType.xul \
 		mozFrameType_window.xul \
 		test_bug789773.xul \
-		test_private_hidden_window.html \
     docshell_helpers.js \
     generic.html \
     $(NULL)
 
 ifneq ($(MOZ_WIDGET_TOOLKIT),gtk2)
 MOCHITEST_CHROME_FILES += \
 		test_bug454235.xul \
 		$(NULL)
deleted file mode 100644
--- a/docshell/test/chrome/test_private_hidden_window.html
+++ /dev/null
@@ -1,61 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=829383
--->
-<head>
-  <title>Test for Bug 829383</title>
-  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=829383">Mozilla Bug 829383</a>
-<p id="display"></p>
-<div id="content" style="display: none">
-  <iframe name="target"></iframe>
-</div>
-<pre id="test">
-<script class="testbody" type="text/javascript">
-
-SimpleTest.waitForExplicitFinish();
-const Ci = Components.interfaces;
-var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
-                       .getInterface(Ci.nsIWebNavigation)
-                       .QueryInterface(Ci.nsIDocShellTreeItem)
-                       .rootTreeItem
-                       .QueryInterface(Ci.nsIInterfaceRequestor)
-                       .getInterface(Ci.nsIDOMWindow);
-
-// We need to wait for the hidden window to load, but can't access
-// an event target for a regular event listener.
-var hidden = mainWindow.Services.appShell.hiddenPrivateDOMWindow;
-var tmp = setTimeout(function poll() {
-  if (hidden.location.href != "resource://gre-resources/hiddenWindow.html") {
-    setTimeout(poll, 100);
-    return;
-  }
-
-  var iframe = hidden.document.createElement('iframe');
-  iframe.src = 'generic.html';
-  hidden.document.body.appendChild(iframe);
-
-  var win = mainWindow.OpenBrowserWindow({private: true});
-  win.addEventListener("load", function onLoad() {
-    win.removeEventListener("load", onLoad, false);
-    win.close();
-    win = null;
-  }, false);
-}, 100);
-
-function observer(aSubject, aTopic, aData) {
-  is(aTopic, "last-pb-context-exited", "Unexpected observer topic");
-  mainWindow.Services.obs.removeObserver(observer, "last-pb-context-exited");
-  SimpleTest.finish();
-}
-mainWindow.Services.obs.addObserver(observer, "last-pb-context-exited", false);
-
-</script>
-</pre>
-</body>
-</html>
-
--- a/xpfe/appshell/src/nsAppShellService.cpp
+++ b/xpfe/appshell/src/nsAppShellService.cpp
@@ -135,22 +135,16 @@ nsAppShellService::CreateHiddenWindowHel
     // Create the hidden private window
     chromeMask |= nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW;
 
     rv = JustCreateTopWindow(nullptr, url,
                              chromeMask, initialWidth, initialHeight,
                              true, getter_AddRefs(newWindow));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsCOMPtr<nsIDocShell> docShell;
-    newWindow->GetDocShell(getter_AddRefs(docShell));
-    if (docShell) {
-      docShell->SetAffectPrivateSessionLifetime(false);
-    }
-
     mHiddenPrivateWindow.swap(newWindow);
   }
 #endif
 
   // RegisterTopLevelWindow(newWindow); -- Mac only
 
   return NS_OK;
 }