Bug 595483 Port duplicateTabIn introduced in bug 448546. r=Neil sr=Neil
authorPhilip Chee <philip.chee@gmail.com>
Fri, 24 Sep 2010 23:40:28 +0800
changeset 6421 ae798bbc39654b825d4de4c789e7bcaeabca1818
parent 6420 ad8d5126223de46b7d2d2d4d955ec8b64d7bcdcc
child 6422 4d36594ea0e87798e4d4e7737c5b489b96229eba
push idunknown
push userunknown
push dateunknown
reviewersNeil, Neil
bugs595483, 448546
Bug 595483 Port duplicateTabIn introduced in bug 448546. r=Neil sr=Neil
suite/browser/navigator.js
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -64,21 +64,16 @@ var gLastValidURLStr = "";
 var gLastValidURL = null;
 var gClickSelectsAll = false;
 var gClickAtEndSelects = false;
 var gIgnoreFocus = false;
 var gIgnoreClick = false;
 var gURIFixup = null;
 var gThemes = [];
 
-var gInitialPages = [
-  "about:blank",
-  "about:sessionrestore"
-];
-
 //cached elements
 var gBrowser = null;
 
 function ReloadThemes()
 {
   AddonManager.getAddonsByTypes(["theme"], function(themes) {
     gThemes = themes.sort(function(a, b) {
       return a.name.localeCompare(b.name);
@@ -720,22 +715,23 @@ function Translate()
   // if we're already viewing a translated page, then just reload
   if (targetURI.indexOf(serviceDomain) >= 0)
     BrowserReload();
   else {
     loadURI(encodeURI(service + targetURI));
   }
 }
 
-function OpenSessionHistoryIn(aWhere, aDelta)
+function OpenSessionHistoryIn(aWhere, aDelta, aTab)
 {
   var win = aWhere == "window" ? null : window;
-  var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
-                     .getService(Components.interfaces.nsISessionStore);
-  var tab = ss.duplicateTab(win, gBrowser.selectedTab, aDelta, true);
+  aTab = aTab || getBrowser().selectedTab;
+  var tab = Components.classes["@mozilla.org/suite/sessionstore;1"]
+                      .getService(Components.interfaces.nsISessionStore)
+                      .duplicateTab(win, aTab, aDelta, true);
 
   var loadInBackground = getBoolPref("browser.tabs.loadInBackground", false);
 
   switch (aWhere) {
   case "tabfocused":
     // forces tab to be focused
     loadInBackground = true;
     // fall through
@@ -745,16 +741,39 @@ function OpenSessionHistoryIn(aWhere, aD
   case "tab":
     if (!loadInBackground) {
       getBrowser().selectedTab = tab;
       window.content.focus();
     }
   }
 }
 
+/* Firefox compatibility shim *
+ * duplicateTabIn duplicates tab in a place specified by the parameter |where|.
+ *
+ * |where| can be:
+ *  "tab"         new tab
+ *  "tabshifted"  same as "tab" but in background if default is to select new
+ *                tabs, and vice versa
+ *  "tabfocused"  same as "tab" but override any background preferences and
+ *                focus the new tab
+ *  "window"      new window
+ *
+ * historyIndex is a history index to set the page to when the new tab is
+ * created and loaded, it can for example be used to go back one page for the
+ * duplicated tab.
+ */
+function duplicateTabIn(aTab, aWhere, aHistoryIndex)
+{
+  aTab = aTab || getBrowser().selectedTab;
+  var currentIndex = aTab.linkedBrowser.sessionHistory.index;
+  var delta = aHistoryIndex == null ? 0 : aHistoryIndex - currentIndex;
+  OpenSessionHistoryIn(aWhere, delta, aTab)
+}
+
 function gotoHistoryIndex(aEvent)
 {
   var index = aEvent.target.getAttribute("index");
   if (!index)
     return false;
 
   var where = whereToOpenLink(aEvent);
   if (where == "current") {
@@ -1841,18 +1860,18 @@ function URLBarSetURI(aURI, aValid) {
     gURIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
                           .getService(Components.interfaces.nsIURIFixup);
   try {
     uri = gURIFixup.createExposableURI(uri);
   } catch (ex) {}
 
   // Replace "about:blank" with an empty string
   // only if there's no opener (bug 370555).
-  if (gInitialPages.indexOf(uri.spec) != -1)
-    value = (content.opener || getWebNavigation().canGoBack) ? uri.spec : "";
+  if (uri.spec == "about:blank")
+    value = content.opener || getWebNavigation().canGoBack ? "about:blank" : "";
   else
     value = losslessDecodeURI(uri);
 
   gURLBar.value = value;
   // In some cases, setting the urlBar value causes userTypedValue to
   // become set because of oninput, so reset it to null.
   getBrowser().userTypedValue = null;