Bug 1449925 - make the --private command line parameter work when browser.startup.blankWindow is true, r=Ehsan.
authorFlorian Quèze <florian@queze.net>
Wed, 04 Apr 2018 21:29:16 +0200
changeset 411731 658361dcadf317b2276eb13896de8d576d5d99c1
parent 411730 7495760c7501bb9a36ee345e078aa44f49f4066a
child 411732 5cc5f9c978a3f1a8c6e0083e8024c216a11805bd
push id101738
push userflorian@queze.net
push dateWed, 04 Apr 2018 19:29:47 +0000
treeherdermozilla-inbound@658361dcadf3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1449925
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1449925 - make the --private command line parameter work when browser.startup.blankWindow is true, r=Ehsan.
browser/components/nsBrowserContentHandler.js
docshell/base/nsDocShell.cpp
--- a/browser/components/nsBrowserContentHandler.js
+++ b/browser/components/nsBrowserContentHandler.js
@@ -208,19 +208,16 @@ function openBrowserWindow(cmdLine, urlO
   if (cmdLine.state == Ci.nsICommandLine.STATE_INITIAL_LAUNCH) {
     let win = Services.wm.getMostRecentWindow("navigator:blank");
     if (win) {
       // Remove the windowtype of our blank window so that we don't close it
       // later on when seeing cmdLine.preventDefault is true.
       win.document.documentElement.removeAttribute("windowtype");
 
       if (forcePrivate) {
-        // This causes a "Only internal code is allowed to set the
-        // usePrivateBrowsing attribute" warning in the Browser Console.
-        // Still better than having a white window that flickers.
         win.QueryInterface(Ci.nsIInterfaceRequestor)
            .getInterface(Ci.nsIWebNavigation)
            .QueryInterface(Ci.nsILoadContext)
            .usePrivateBrowsing = true;
       }
 
       win.location = chromeURL;
       win.arguments = args; // <-- needs to be a plain JS array here.
@@ -413,16 +410,25 @@ nsBrowserContentHandler.prototype = {
       doSearch(searchParam, cmdLine);
       cmdLine.preventDefault = true;
     }
 
     // The global PB Service consumes this flag, so only eat it in per-window
     // PB builds.
     if (cmdLine.handleFlag("private", false) && PrivateBrowsingUtils.enabled) {
       PrivateBrowsingUtils.enterTemporaryAutoStartMode();
+      if (cmdLine.state == nsICommandLine.STATE_INITIAL_LAUNCH) {
+        let win = Services.wm.getMostRecentWindow("navigator:blank");
+        if (win) {
+          win.QueryInterface(Ci.nsIInterfaceRequestor)
+             .getInterface(Ci.nsIWebNavigation)
+             .QueryInterface(Ci.nsILoadContext)
+             .usePrivateBrowsing = true;
+        }
+      }
     }
     if (cmdLine.handleFlag("setDefaultBrowser", false)) {
       ShellService.setDefaultBrowser(true, true);
     }
 
     var fileParam = cmdLine.handleFlagWithParam("file", false);
     if (fileParam) {
       var file = cmdLine.resolveFile(fileParam);
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -107,17 +107,16 @@
 #include "nsIObserverService.h"
 #include "nsIOService.h"
 #include "nsIPrincipal.h"
 #include "nsIPrivacyTransitionObserver.h"
 #include "nsIPrompt.h"
 #include "nsIPromptFactory.h"
 #include "nsIReflowObserver.h"
 #include "nsIScriptChannel.h"
-#include "nsIScriptError.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIScrollableFrame.h"
 #include "nsIScrollObserver.h"
 #include "nsISecureBrowserUI.h"
 #include "nsISecurityUITelemetry.h"
 #include "nsISeekableStream.h"
 #include "nsISelectionDisplay.h"
@@ -1727,22 +1726,16 @@ nsDocShell::GetUsePrivateBrowsing(bool* 
   AssertOriginAttributesMatchPrivateBrowsing();
   *aUsePrivateBrowsing = mPrivateBrowsingId > 0;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
 {
-  nsContentUtils::ReportToConsoleNonLocalized(
-    NS_LITERAL_STRING("Only internal code is allowed to set the usePrivateBrowsing attribute"),
-    nsIScriptError::warningFlag,
-    NS_LITERAL_CSTRING("Internal API Used"),
-    mContentViewer ? mContentViewer->GetDocument() : nullptr);
-
   if (!CanSetOriginAttributes()) {
     bool changed = aUsePrivateBrowsing != (mPrivateBrowsingId > 0);
 
     return changed ? NS_ERROR_FAILURE : NS_OK;
   }
 
   return SetPrivateBrowsing(aUsePrivateBrowsing);
 }