Bug 829180 - Never open externally opened links in a private window; r=gavin
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 10 Jan 2013 23:25:56 -0500
changeset 118507 1830a14dd3af839a4c5f633fc334750ee3fdd956
parent 118506 6cda85d6e4f6140c196bc3e23d611edf1cc1606b
child 118508 33ff2a97b02129933ce6453d5878559d5f563567
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersgavin
bugs829180
milestone21.0a1
Bug 829180 - Never open externally opened links in a private window; r=gavin
browser/components/nsBrowserContentHandler.js
browser/modules/RecentWindow.jsm
--- a/browser/components/nsBrowserContentHandler.js
+++ b/browser/components/nsBrowserContentHandler.js
@@ -2,16 +2,18 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
                                   "resource://gre/modules/PrivateBrowsingUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
+                                  "resource:///modules/RecentWindow.jsm");
 
 const nsISupports            = Components.interfaces.nsISupports;
 
 const nsIBrowserDOMWindow    = Components.interfaces.nsIBrowserDOMWindow;
 const nsIBrowserHandler      = Components.interfaces.nsIBrowserHandler;
 const nsIBrowserHistory      = Components.interfaces.nsIBrowserHistory;
 const nsIChannel             = Components.interfaces.nsIChannel;
 const nsICommandLine         = Components.interfaces.nsICommandLine;
@@ -292,23 +294,16 @@ function openPreferences() {
 }
 
 function getMostRecentWindow(aType) {
   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
                      .getService(nsIWindowMediator);
   return wm.getMostRecentWindow(aType);
 }
 
-// this returns the most recent non-popup browser window
-function getMostRecentBrowserWindow() {
-  var browserGlue = Components.classes["@mozilla.org/browser/browserglue;1"]
-                              .getService(Components.interfaces.nsIBrowserGlue);
-  return browserGlue.getMostRecentBrowserWindow();
-}
-
 function doSearch(searchTerm, cmdLine) {
   var ss = Components.classes["@mozilla.org/browser/search-service;1"]
                      .getService(nsIBrowserSearchService);
 
   var submission = ss.defaultEngine.getSubmission(searchTerm);
 
   // fill our nsISupportsArray with uri-as-wstring, null, null, postData
   var sa = Components.classes["@mozilla.org/supports-array;1"]
@@ -730,17 +725,18 @@ nsBrowserContentHandler.prototype = {
 };
 var gBrowserContentHandler = new nsBrowserContentHandler();
 
 function handURIToExistingBrowser(uri, location, cmdLine)
 {
   if (!shouldLoadURI(uri))
     return;
 
-  var navWin = getMostRecentBrowserWindow();
+  // Do not open external links in private windows
+  var navWin = RecentWindow.getMostRecentBrowserWindow({private: false});
   if (!navWin) {
     // if we couldn't load it in an existing window, open a new one
     openWindow(null, gBrowserContentHandler.chromeURL, "_blank",
                "chrome,dialog=no,all" + gBrowserContentHandler.getFeatures(cmdLine),
                uri.spec);
     return;
   }
 
--- a/browser/modules/RecentWindow.jsm
+++ b/browser/modules/RecentWindow.jsm
@@ -21,18 +21,23 @@ this.RecentWindow = {
    *
    * @param aOptions an object accepting the arguments for the search.
    *        Set the private property to true in order to restrict the
    *        search to private windows only, or to false in order to
    *        restrict the search to non-private windows only.  To search
    *        in both groups, don't specify the private property.
    */
   getMostRecentBrowserWindow: function RW_getMostRecentBrowserWindow(aOptions) {
+#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
     let checkPrivacy = typeof aOptions == "object" &&
                        "private" in aOptions;
+#else
+    // In global PB builds, always ignore the requested privacy status
+    let checkPrivacy = false;
+#endif
 
     function isSuitableBrowserWindow(win) {
       return (!win.closed &&
               win.toolbar.visible &&
               (!checkPrivacy ||
                PrivateBrowsingUtils.isWindowPrivate(win) == aOptions.private));
     }