From e8f9ff7e9c2ef703d546b1ef31451c82b80c2f43 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Thu, 24 Jan 2002 02:35:16 +0000 Subject: [PATCH] Make "Open in new Window" and "Open in new Tab" set referrer correctly. Bug 48902, r=doron, sr=hyatt git-svn-id: svn://10.0.0.236/trunk@112628 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 2 +- .../browser/resources/content/navigator.js | 10 ++++++--- .../resources/content/contentAreaClick.js | 5 +++-- .../resources/content/contentAreaUtils.js | 22 ++++++++++++++++--- .../resources/content/bindings/browser.xml | 6 +++-- .../resources/content/bindings/tabbrowser.xml | 12 ++++++---- 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 3b47eb5c813..ad2c0e9f67c 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -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; diff --git a/mozilla/xpfe/browser/resources/content/navigator.js b/mozilla/xpfe/browser/resources/content/navigator.js index 284e3544360..cf2ed76a6ef 100644 --- a/mozilla/xpfe/browser/resources/content/navigator.js +++ b/mozilla/xpfe/browser/resources/content/navigator.js @@ -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) { } } diff --git a/mozilla/xpfe/communicator/resources/content/contentAreaClick.js b/mozilla/xpfe/communicator/resources/content/contentAreaClick.js index 667753d782e..a4b6714ae88 100644 --- a/mozilla/xpfe/communicator/resources/content/contentAreaClick.js +++ b/mozilla/xpfe/communicator/resources/content/contentAreaClick.js @@ -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(); diff --git a/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js b/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js index d2b71c79889..f30ac67a3c1 100644 --- a/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js +++ b/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js @@ -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; } diff --git a/mozilla/xpfe/global/resources/content/bindings/browser.xml b/mozilla/xpfe/global/resources/content/bindings/browser.xml index cfab4d6727c..6b56f0d148f 100644 --- a/mozilla/xpfe/global/resources/content/bindings/browser.xml +++ b/mozilla/xpfe/global/resources/content/bindings/browser.xml @@ -109,11 +109,12 @@ + @@ -122,12 +123,13 @@ + diff --git a/mozilla/xpfe/global/resources/content/bindings/tabbrowser.xml b/mozilla/xpfe/global/resources/content/bindings/tabbrowser.xml index 48d4b9b17b7..c110ea8c7b0 100644 --- a/mozilla/xpfe/global/resources/content/bindings/tabbrowser.xml +++ b/mozilla/xpfe/global/resources/content/bindings/tabbrowser.xml @@ -520,6 +520,7 @@ + @@ -942,9 +944,10 @@ + @@ -953,9 +956,10 @@ +