Make "Open in new Window" and "Open in new Tab" set referrer correctly.
Bug 48902, r=doron, sr=hyatt
This commit is contained in:
Родитель
67426cf190
Коммит
224730fe27
|
@ -2306,9 +2306,9 @@ nsDocShell::LoadURI(const PRUnichar * aURI,
|
|||
|
||||
loadInfo->SetLoadType(ConvertLoadTypeToDocShellLoadInfo(aLoadFlags));
|
||||
loadInfo->SetPostDataStream(aPostStream);
|
||||
loadInfo->SetReferrer(aReferingURI);
|
||||
|
||||
// XXX: Need to pass in the extra headers stream too...
|
||||
// XXX: Need to pass in referer...
|
||||
|
||||
rv = LoadURI(uri, loadInfo, 0);
|
||||
return rv;
|
||||
|
|
|
@ -386,7 +386,11 @@ function Startup()
|
|||
|
||||
if (uriToLoad && uriToLoad != "about:blank") {
|
||||
gURLBar.value = uriToLoad;
|
||||
loadURI(uriToLoad);
|
||||
if ("arguments" in window && window.arguments.length >= 4) {
|
||||
loadURI(uriToLoad, window.arguments[3]);
|
||||
} else {
|
||||
loadURI(uriToLoad);
|
||||
}
|
||||
}
|
||||
|
||||
// Close the window now, if it's for turbo mode startup.
|
||||
|
@ -896,10 +900,10 @@ function BrowserCloseWindow()
|
|||
window.close();
|
||||
}
|
||||
|
||||
function loadURI(uri)
|
||||
function loadURI(uri, referrer)
|
||||
{
|
||||
try {
|
||||
getWebNavigation().loadURI(uri, nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
|
||||
getWebNavigation().loadURI(uri, nsIWebNavigation.LOAD_FLAGS_NONE, referrer, null, null);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -109,11 +109,12 @@
|
|||
<!-- throws exception for unknown schemes -->
|
||||
<method name="loadURI">
|
||||
<parameter name="aURI"/>
|
||||
<parameter name="aReferrerURI"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
|
||||
const flags = nsIWebNavigation.LOAD_FLAGS_NONE;
|
||||
this.loadURIWithFlags(aURI, flags);
|
||||
this.loadURIWithFlags(aURI, flags, aReferrerURI);
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
@ -122,12 +123,13 @@
|
|||
<method name="loadURIWithFlags">
|
||||
<parameter name="aURI"/>
|
||||
<parameter name="aFlags"/>
|
||||
<parameter name="aReferrerURI"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
if (!aURI)
|
||||
aURI = "about:blank";
|
||||
|
||||
this.webNavigation.loadURI(aURI, aFlags, null, null, null);
|
||||
this.webNavigation.loadURI(aURI, aFlags, aReferrerURI, null, null);
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
|
|
@ -520,6 +520,7 @@
|
|||
|
||||
<method name="addTab">
|
||||
<parameter name="aURI"/>
|
||||
<parameter name="aReferrerURI"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var blank = (aURI == "about:blank");
|
||||
|
@ -588,9 +589,10 @@
|
|||
var tabListener = (this.mTabProgressListener)(this, t, blank);
|
||||
b.webProgress.addProgressListener(tabListener);
|
||||
this.mTabListeners[position] = tabListener;
|
||||
|
||||
|
||||
if (!blank)
|
||||
b.loadURI(aURI, nsIWebNavigation.LOAD_FLAGS_NONE);
|
||||
b.loadURIWithFlags(aURI, nsIWebNavigation.LOAD_FLAGS_NONE,
|
||||
aReferrerURI, null, null);
|
||||
|
||||
return t;
|
||||
]]>
|
||||
|
@ -942,9 +944,10 @@
|
|||
<!-- throws exception for unknown schemes -->
|
||||
<method name="loadURI">
|
||||
<parameter name="aURI"/>
|
||||
<parameter name="aReferrerURI"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
return this.mCurrentBrowser.loadURI(aURI);
|
||||
return this.mCurrentBrowser.loadURI(aURI, aReferrerURI);
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
@ -953,9 +956,10 @@
|
|||
<method name="loadURIWithFlags">
|
||||
<parameter name="aURI"/>
|
||||
<parameter name="aFlags"/>
|
||||
<parameter name="aReferrerURI"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
return this.mCurrentBrowser.loadURIWithFlags(aURI, aFlags);
|
||||
return this.mCurrentBrowser.loadURIWithFlags(aURI, aFlags, aReferrerURI);
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
|
Загрузка…
Ссылка в новой задаче