Bug 1166066 - Fix opening new windows from a private window. r=jdm, a=lizzard
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 03 Jun 2015 13:42:32 +0100
changeset 266199 a7f385942c76
parent 266198 b2455e4eca11
child 266200 d744ad902c75
push id4785
push userryanvm@gmail.com
push date2015-06-08 13:34 +0000
treeherdermozilla-beta@a2c9c4c49319 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm, lizzard
bugs1166066
milestone39.0
Bug 1166066 - Fix opening new windows from a private window. r=jdm, a=lizzard
embedding/components/windowwatcher/nsWindowWatcher.cpp
--- a/embedding/components/windowwatcher/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/nsWindowWatcher.cpp
@@ -1405,44 +1405,50 @@ nsWindowWatcher::URIfromURL(const char *
 uint32_t nsWindowWatcher::CalculateChromeFlags(nsIDOMWindow *aParent,
                                                const char *aFeatures,
                                                bool aFeaturesSpecified,
                                                bool aDialog,
                                                bool aChromeURL,
                                                bool aHasChromeParent,
                                                bool aOpenedFromRemoteTab)
 {
-   if(!aFeaturesSpecified || !aFeatures) {
-      if(aDialog)
-         return nsIWebBrowserChrome::CHROME_ALL | 
-                nsIWebBrowserChrome::CHROME_OPENAS_DIALOG | 
-                nsIWebBrowserChrome::CHROME_OPENAS_CHROME;
-      else
-         return nsIWebBrowserChrome::CHROME_ALL;
-   }
+  uint32_t chromeFlags = 0;
+  bool isCallerChrome =
+    nsContentUtils::IsCallerChrome() && !aOpenedFromRemoteTab;
+
+  bool onlyPrivateFlag = aFeaturesSpecified && aFeatures && isCallerChrome &&
+    nsCRT::strcasecmp(aFeatures, "private") == 0;
+  if (!aFeaturesSpecified || !aFeatures || onlyPrivateFlag) {
+    chromeFlags = nsIWebBrowserChrome::CHROME_ALL;
+    if (aDialog) {
+      chromeFlags |= nsIWebBrowserChrome::CHROME_OPENAS_DIALOG |
+                     nsIWebBrowserChrome::CHROME_OPENAS_CHROME;
+    }
+    if (onlyPrivateFlag) {
+      chromeFlags |= nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW;
+    }
+    return chromeFlags;
+  }
 
   /* This function has become complicated since browser windows and
      dialogs diverged. The difference is, browser windows assume all
      chrome not explicitly mentioned is off, if the features string
      is not null. Exceptions are some OS border chrome new with Mozilla.
      Dialogs interpret a (mostly) empty features string to mean
      "OS's choice," and also support an "all" flag explicitly disallowed
      in the standards-compliant window.(normal)open. */
 
-  uint32_t chromeFlags = 0;
   bool presenceFlag = false;
 
   chromeFlags = nsIWebBrowserChrome::CHROME_WINDOW_BORDERS;
   if (aDialog && WinHasOption(aFeatures, "all", 0, &presenceFlag))
     chromeFlags = nsIWebBrowserChrome::CHROME_ALL;
 
   /* Next, allow explicitly named options to override the initial settings */
 
-  bool isCallerChrome = nsContentUtils::IsCallerChrome() && !aOpenedFromRemoteTab;
-
   // Determine whether the window is a private browsing window
   if (isCallerChrome) {
     chromeFlags |= WinHasOption(aFeatures, "private", 0, &presenceFlag) ?
       nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW : 0;
     chromeFlags |= WinHasOption(aFeatures, "non-private", 0, &presenceFlag) ?
       nsIWebBrowserChrome::CHROME_NON_PRIVATE_WINDOW : 0;
   }