Bug 1166066 - Fix opening new windows from a private window. r=jdm a=sylvestre
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 03 Jun 2015 13:42:32 +0100
changeset 274946 9b7747061d335e87c89d935c9d7783a1555c1af0
parent 274945 66b5afbbe9a741215c73d3220c70e09be26ea668
child 274947 65b5fb8dc1261192f68ef64c1bf5c74423497b97
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm, sylvestre
bugs1166066
milestone40.0a2
Bug 1166066 - Fix opening new windows from a private window. r=jdm a=sylvestre
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;
   }