Bug 837492 Detect whether the browser has been opened as a private window r=IanN
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Tue, 12 Feb 2013 19:19:58 +0000
changeset 14851 d9f8f39bf0fac7cda35c5c5e01213f955e5a33a4
parent 14850 13c3733f053f99a2071e2f10cabdb0f5637c26e7
child 14852 8a31b4fc6ce47f4e51f30e676a46e0cd0c6ede3d
push id867
push userbugzilla@standard8.plus.com
push dateMon, 01 Apr 2013 20:44:27 +0000
treeherdercomm-beta@797726b8d244 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN
bugs837492
Bug 837492 Detect whether the browser has been opened as a private window r=IanN
suite/browser/navigator.js
suite/browser/navigator.xul
suite/common/contentAreaClick.js
suite/common/utilityOverlay.js
suite/debugQA/content/debugQANavigatorOverlay.xul
suite/locales/en-US/chrome/browser/navigator.dtd
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -458,23 +458,35 @@ function Startup()
 
   // Do all UI building here:
   UpdateNavBar();
   updateWindowState();
 
   // set home button tooltip text
   updateHomeButtonTooltip();
 
-  // initialize observers and listeners
-  var xw = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+  var lc = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                  .getInterface(Components.interfaces.nsIWebNavigation)
-                 .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
-                 .treeOwner
-                 .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                 .getInterface(Components.interfaces.nsIXULWindow);
+                 .QueryInterface(Components.interfaces.nsILoadContext);
+  if (lc.usePrivateBrowsing) {
+    gPrivate = window;
+    document.documentElement.setAttribute("windowtype", "navigator:private");
+    var titlemodifier = document.documentElement.getAttribute("titlemodifier");
+    if (titlemodifier)
+      titlemodifier += " ";
+    titlemodifier += document.documentElement.getAttribute("titleprivate");
+    document.documentElement.setAttribute("titlemodifier", titlemodifier);
+    document.title = titlemodifier;
+  }
+
+  // initialize observers and listeners
+  var xw = lc.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
+             .treeOwner
+             .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+             .getInterface(Components.interfaces.nsIXULWindow);
   xw.XULBrowserWindow = window.XULBrowserWindow = new nsBrowserStatusHandler();
 
   if (Services.prefs.getBoolPref("browser.doorhanger.enabled")) {
     XPCOMUtils.defineLazyGetter(window, "PopupNotifications", function() {
       var tmp = {};
       Components.utils.import("resource://gre/modules/PopupNotifications.jsm", tmp);
       return XULBrowserWindow.popupNotifications = new tmp.PopupNotifications(
           getBrowser(),
@@ -612,17 +624,17 @@ function Startup()
     setTimeout(WindowFocusTimerCallback, 0, gURLBar);
   else
     setTimeout(WindowFocusTimerCallback, 0, content);
 
   // hook up browser access support
   window.browserDOMWindow = new nsBrowserAccess();
 
   // hook up remote support
-  if (REMOTESERVICE_CONTRACTID in Components.classes) {
+  if (!gPrivate && REMOTESERVICE_CONTRACTID in Components.classes) {
     var remoteService =
       Components.classes[REMOTESERVICE_CONTRACTID]
                 .getService(Components.interfaces.nsIRemoteService);
     remoteService.registerWindow(window);
   }
 
   // ensure login manager is loaded
   Components.classes["@mozilla.org/login-manager;1"].getService();
@@ -655,23 +667,25 @@ function Startup()
   getNavToolbox().customizeChange = BrowserToolboxCustomizeChange;
 
   PlacesToolbarHelper.init();
 
   gBrowser.mPanelContainer.addEventListener("InstallBrowserTheme", LightWeightThemeWebInstaller, false, true);
   gBrowser.mPanelContainer.addEventListener("PreviewBrowserTheme", LightWeightThemeWebInstaller, false, true);
   gBrowser.mPanelContainer.addEventListener("ResetBrowserThemePreview", LightWeightThemeWebInstaller, false, true);
 
-  DownloadTaskbarIntegration.onBrowserWindowLoad(window);
-
-  // initialize the sync UI
-  gSyncUI.init();
-
-  // initialize the session-restore service
-  setTimeout(InitSessionStoreCallback, 0);
+  if (!gPrivate) {
+    DownloadTaskbarIntegration.onBrowserWindowLoad(window);
+
+    // initialize the sync UI
+    gSyncUI.init();
+
+    // initialize the session-restore service
+    setTimeout(InitSessionStoreCallback, 0);
+  }
 
   // Bug 778855 - Perf regression if we do this here. To be addressed in bug 779008.
   setTimeout(function() { SafeBrowsing.init(); }, 2000);
 }
 
 function UpdateNavBar()
 {
   var elements = getNavToolbox().getElementsByClassName("nav-bar-class");
--- a/suite/browser/navigator.xul
+++ b/suite/browser/navigator.xul
@@ -25,16 +25,17 @@
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         onload="Startup()" onunload="Shutdown()"
         onclose="return WindowIsClosing();"
         contenttitlesetting="true"
         title="&mainWindow.title;" 
         titlemodifier="&mainWindow.titlemodifier;" 
         titlemenuseparator="&mainWindow.titlemodifiermenuseparator;"
+        titleprivate="&mainWindow.titleprivate;"
         toggletoolbar="true"
         lightweightthemes="true"
         lightweightthemesfooter="status-bar"
         windowtype="navigator:browser"
         macanimationtype="document"
         persist="screenX screenY width height sizemode"> 
 
   <!-- Generic Utility -->
--- a/suite/common/contentAreaClick.js
+++ b/suite/common/contentAreaClick.js
@@ -193,16 +193,19 @@
       }
       loadURI(url);
     }
     event.stopPropagation();
   }
 
   function addToUrlbarHistory(aUrlToAdd)
   {
+    if (gPrivate)
+      return;
+
     // Remove leading and trailing spaces first
     aUrlToAdd = aUrlToAdd.trim();
 
     if (!aUrlToAdd)
       return;
     if (aUrlToAdd.search(/[\x00-\x1F]/) != -1) // don't store bad URLs
       return;
 
--- a/suite/common/utilityOverlay.js
+++ b/suite/common/utilityOverlay.js
@@ -32,16 +32,17 @@ const kProxyManual = ["network.proxy.ftp
                       "network.proxy.socks",
                       "network.proxy.ssl"];
 const kExistingWindow = Components.interfaces.nsIBrowserDOMWindow.OPEN_CURRENTWINDOW;
 const kNewWindow = Components.interfaces.nsIBrowserDOMWindow.OPEN_NEWWINDOW;
 const kNewTab = Components.interfaces.nsIBrowserDOMWindow.OPEN_NEWTAB;
 var TAB_DROP_TYPE = "application/x-moz-tabbrowser-tab";
 var gShowBiDi = false;
 var gUtilityBundle = null;
+var gPrivate = null;
 
 function toggleOfflineStatus()
 {
   var checkfunc;
   try {
     checkfunc = document.getElementById("offline-status").getAttribute('checkfunc');
   }
   catch (ex) {
--- a/suite/debugQA/content/debugQANavigatorOverlay.xul
+++ b/suite/debugQA/content/debugQANavigatorOverlay.xul
@@ -15,19 +15,23 @@
     function debugQABuildIDOnLoad() {
       window.removeEventListener("load", debugQABuildIDOnLoad, true);
 
       var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
                               .getService(Components.interfaces.nsIXULAppInfo);
 
       var bundle = document.getElementById("debugQANavigatorBundle");
 
-      var titlemodifier = bundle.getFormattedString("titlemodifier",
-                                                    [appInfo.name,
-                                                     appInfo.appBuildID]);
+      var titlemodifier =
+          document.documentElement.getAttribute("titlemodifier") ||
+          document.documentElement.getAttribute("titledefault");
+
+      titlemodifier = bundle.getFormattedString("titlemodifier",
+                                                [titlemodifier,
+                                                 appInfo.appBuildID]);
 
       // On mac, with contenttitlesetting="true", the titlemodifier is removed
       // and replaced with a titledefault attribute that holds the value of the
       // titlemodifier attribute. We don't use titledefault, but let's remove
       // it since we're adding back the titlemodifier.
       document.documentElement.removeAttribute("titledefault");
 
       // Set the new title modifier
--- a/suite/locales/en-US/chrome/browser/navigator.dtd
+++ b/suite/locales/en-US/chrome/browser/navigator.dtd
@@ -9,16 +9,18 @@
 
 <!-- LOCALIZATION NOTE (mainWindow.title): DONT_TRANSLATE --> 
 <!ENTITY mainWindow.title "&brandShortName;">
 <!-- LOCALIZATION NOTE (mainWindow.titlemodifier) : DONT_TRANSLATE --> 
 <!ENTITY mainWindow.titlemodifier "&brandShortName;">
 <!-- LOCALIZATION NOTE (mainWindow.titlemodifiermenuseparator): DONT_TRANSLATE -->
 <!ENTITY mainWindow.titlemodifiermenuseparator " - ">
 
+<!ENTITY mainWindow.titleprivate "Private Browsing">
+
 <!ENTITY editPageCmd.label "Edit Page">
 <!ENTITY editPageCmd.accesskey "E">
 <!ENTITY editPageCmd.commandkey "e">
 
 <!ENTITY navbarCmd.label "Navigation Toolbar">
 <!ENTITY navbarCmd.accesskey "N">
 <!ENTITY bookmarksToolbarCmd.label     "Bookmarks Toolbar">
 <!ENTITY bookmarksToolbarCmd.accesskey "m">