Bug 619786 - System titlebar seen at all times [r=mbrubeck]
authorMark Finkle <mfinkle@mozilla.com>
Mon, 03 Jan 2011 16:08:54 -0500
changeset 67200 49fc3ddc19eb68301321734bf6a4c39239e21090
parent 67199 19abf479910b095c0f9457cd2c4ab65141d18be9
child 67201 096154dce06b94652329f4b677b0efd0712d3b84
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs619786
Bug 619786 - System titlebar seen at all times [r=mbrubeck]
mobile/chrome/content/browser.js
mobile/components/BrowserCLH.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -361,29 +361,33 @@ var Browser = {
 
     // Login Manager and Form History initialization
     Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
     Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
 
     // Make sure we're online before attempting to load
     Util.forceOnline();
 
-    let homeURL = this.getHomePage();
-    let commandURL;
+    // If this is an intial window launch the commandline handler passes us the default
+    // page as an argument. commandURL _should_ never be empty, but we protect against it
+    // below. However, we delay trying to get the fallback homepage until we really need it.
+    let commandURL = null;
     if (window.arguments && window.arguments[0])
       commandURL = window.arguments[0];
 
     // Should we restore the previous session (crash or some other event)
     let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
     if (ss.shouldRestore()) {
       ss.restoreLastSession();
-      if (commandURL)
+
+      // Also open any commandline URLs, except the homepage
+      if (commandURL && commandURL != this.getHomePage())
         this.addTab(commandURL, true);
     } else {
-      this.addTab(commandURL || homeURL, true);
+      this.addTab(commandURL || this.getHomePage(), true);
     }
 
     // JavaScript Error Console
     if (Services.prefs.getBoolPref("browser.console.showInPanel")){
       let button = document.getElementById("tool-console");
       button.hidden = false;
     }
 
--- a/mobile/components/BrowserCLH.js
+++ b/mobile/components/BrowserCLH.js
@@ -100,16 +100,26 @@ function needHomepageOverride() {
     Services.prefs.setCharPref("browser.startup.homepage_override.mstone", ourmstone);
 
     return (savedmstone ? "new version" : "new profile");
   }
 
   return "none";
 }
 
+function getHomePage() {
+  let url = "about:home";
+  try {
+    url = Services.prefs.getComplexValue("browser.startup.homepage", Ci.nsIPrefLocalizedString).data;
+  } catch (e) { }
+
+  return url;
+}
+
+
 function BrowserCLH() { }
 
 BrowserCLH.prototype = {
   //
   // nsICommandLineHandler
   //
   handle: function fs_handle(aCmdLine) {
     // Instantiate the search service so the search engine cache is created now
@@ -167,17 +177,18 @@ BrowserCLH.prototype = {
         uris.push(uri);
     }
 
     // Open the main browser window, if we don't already have one
     let win;
     try {
       win = Services.wm.getMostRecentWindow("navigator:browser");
       if (!win) {
-        let defaultURL;
+        // Default to the saved homepage
+        let defaultURL = getHomePage();
 
         // Override the default if we have a new profile
         if (needHomepageOverride() == "new profile")
             defaultURL = "about:firstrun";
 
         // Override the default if we have a URL passed on command line
         if (uris.length > 0) {
           defaultURL = uris[0].spec;
@@ -190,25 +201,26 @@ BrowserCLH.prototype = {
       win.focus();
 
       // Stop the normal commandline processing from continuing. We just opened the main browser window
       aCmdLine.preventDefault = true;
     } catch (e) { }
 
     // Assumption: All remaining command line arguments have been sent remotely (browser is already running)
     // Action: Open any URLs we find into an existing browser window
+    if (uris.length == 0)
+      return;
 
     // First, get a browserDOMWindow object
     while (!win.browserDOMWindow)
       Services.tm.currentThread.processNextEvent(true);
 
     // Open any URIs into new tabs
     for (let i = 0; i < uris.length; i++)
-      win.browserDOMWindow.openURI(uris[i], null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
-                                   Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
+      win.browserDOMWindow.openURI(uris[i], null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
   },
 
   // QI
   QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
 
   // XPCOMUtils factory
   classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}"),
 };