Make "Open in new Window" and "Open in new Tab" set referrer correctly.

Bug 48902, r=doron, sr=hyatt
This commit is contained in:
bzbarsky%mit.edu 2006-07-29 05:39:18 +00:00
parent 11e8102f13
commit 8b00a952bf
2 changed files with 22 additions and 5 deletions

View File

@ -187,7 +187,8 @@
if (event.metaKey || event.ctrlKey) { // and meta or ctrl are down
if (pref && pref.getBoolPref("browser.tabs.opentabfor.middleclick") && getBrowser &&
getBrowser() && getBrowser().localName == "tabbrowser") {
theTab = getBrowser().addTab(href); // open link in new tab
theTab = getBrowser().addTab(href, getReferrer(document)); // open link in new tab
if (!event.shiftKey && !pref.getBoolPref("browser.tabs.loadInBackground"))
getBrowser().selectedTab = theTab;
event.preventBubble();
@ -220,7 +221,7 @@
case 1: // if middle button clicked
if (pref && pref.getBoolPref("browser.tabs.opentabfor.middleclick") && getBrowser &&
getBrowser() && getBrowser().localName == "tabbrowser") {
theTab = getBrowser().addTab(href); // open link in new tab
theTab = getBrowser().addTab(href, getReferrer(document)); // open link in new tab
if (!event.shiftKey && !pref.getBoolPref("browser.tabs.loadInBackground"))
getBrowser().selectedTab = theTab;
event.preventBubble();

View File

@ -67,11 +67,26 @@ function urlSecurityCheck(url, doc)
}
}
function getReferrer(doc)
{
var focusedWindow = doc.commandDispatcher.focusedWindow;
var sourceURL =
isDocumentFrame(focusedWindow) ? focusedWindow.location.href : focusedWindow._content.location.href;
try {
var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI);
uri.spec = sourceURL;
return uri;
} catch (e) {
return null;
}
}
function openNewWindowWith(url)
{
urlSecurityCheck(url, document);
var newWin;
var wintype = document.firstChild.getAttribute('windowtype');
var referrer = getReferrer(document);
// if and only if the current window is a browser window and it has a document with a character
// set, then extract the current charset menu setting from the current document and use it to
@ -82,10 +97,10 @@ function openNewWindowWith(url)
var charsetArg = "charset="+DocCharset;
//we should "inherit" the charset menu setting in a new window
newWin = window.openDialog( getBrowserURL(), "_blank", "chrome,all,dialog=no", url, charsetArg, true );
newWin = window.openDialog( getBrowserURL(), "_blank", "chrome,all,dialog=no", url, charsetArg, true, referrer );
}
else { // forget about the charset information.
newWin = window.openDialog( getBrowserURL(), "_blank", "chrome,all,dialog=no", url, null, true );
newWin = window.openDialog( getBrowserURL(), "_blank", "chrome,all,dialog=no", url, null, true, referrer );
}
}
@ -93,10 +108,11 @@ function openNewTabWith(url)
{
urlSecurityCheck(url, document);
var wintype = document.firstChild.getAttribute('windowtype');
var referrer = getReferrer(document);
if (window && (wintype == "navigator:browser")) {
var browser = getBrowser();
var t = browser.addTab(url); // open link in new tab
var t = browser.addTab(url, referrer); // open link in new tab
if (pref && !pref.getBoolPref("browser.tabs.loadInBackground"))
browser.selectedTab = t;
}