Fixing bug 64248. Making the loading of external scripts pass the referrer to the server when requesting the script. r=gagan@netscape.com, sr=darin@netscape.com

This commit is contained in:
jst%netscape.com 2002-01-08 06:32:36 +00:00
Родитель e9bb146caf
Коммит 645c88322d
4 изменённых файлов: 43 добавлений и 9 удалений

Просмотреть файл

@ -43,6 +43,7 @@
#include "nsIScriptElement.h"
#include "nsIDocShell.h"
#include "jsapi.h"
#include "nsIHttpChannel.h"
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
@ -93,7 +94,12 @@ nsScriptLoadRequest::~nsScriptLoadRequest()
{
}
NS_IMPL_ISUPPORTS0(nsScriptLoadRequest)
// The nsScriptLoadRequest is passed as the context to necko, and thus
// it needs to be threadsafe. Necko won't do anything with this
// context, but it will AddRef and Release it on other threads.
NS_IMPL_THREADSAFE_ISUPPORTS0(nsScriptLoadRequest)
void
nsScriptLoadRequest::FireScriptAvailable(nsresult aResult,
@ -389,17 +395,22 @@ nsScriptLoader::ProcessScriptElement(nsIDOMHTMLScriptElement *aElement,
return FireErrorNotification(rv, aElement, aObserver);
}
// Get the referrer url from the document
nsCOMPtr<nsIURI> documentURI;
mDocument->GetDocumentURL(getter_AddRefs(documentURI));
nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell));
nsCOMPtr<nsIChannel> channel;
rv = NS_NewStreamLoader(getter_AddRefs(loader), scriptURI, this,
reqsup, loadGroup, prompter,
nsIChannel::LOAD_NORMAL);
nsIChannel::LOAD_NORMAL, documentURI,
nsIHttpChannel::REFERRER_INLINES);
if (NS_FAILED(rv)) {
mPendingRequests.RemoveElement(reqsup, 0);
return FireErrorNotification(rv, aElement, aObserver);
}
}
} else {
request->mLoading = PR_FALSE;
request->mIsInline = PR_TRUE;

Просмотреть файл

@ -62,7 +62,9 @@ interface nsIStreamLoader : nsISupports
in nsISupports ctxt,
in nsILoadGroup loadGroup,
in nsIInterfaceRequestor notificationCallbacks,
in nsLoadFlags loadAttributes);
in nsLoadFlags loadAttributes,
in nsIURI referrer,
in unsigned long refererFlags);
/**
* Gets the number of bytes read so far.

Просмотреть файл

@ -379,7 +379,9 @@ NS_NewStreamLoader(nsIStreamLoader* *result,
nsISupports* context = nsnull,
nsILoadGroup* loadGroup = nsnull,
nsIInterfaceRequestor* notificationCallbacks = nsnull,
nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIRequest::LOAD_NORMAL))
nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIRequest::LOAD_NORMAL),
nsIURI* referrer = nsnull,
PRUint32 referrerFlags = 0)
{
nsresult rv;
nsCOMPtr<nsIStreamLoader> loader;
@ -390,7 +392,8 @@ NS_NewStreamLoader(nsIStreamLoader* *result,
getter_AddRefs(loader));
if (NS_FAILED(rv)) return rv;
rv = loader->Init(uri, observer, context, loadGroup,
notificationCallbacks, loadAttributes);
notificationCallbacks, loadAttributes, referrer,
referrerFlags);
if (NS_FAILED(rv)) return rv;
*result = loader;

Просмотреть файл

@ -40,6 +40,7 @@
#include "nsIURL.h"
#include "nsNetUtil.h"
#include "nsIChannel.h"
#include "nsIHttpChannel.h"
#include "nsProxiedService.h"
static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
@ -50,12 +51,29 @@ nsStreamLoader::Init(nsIURI* aURL,
nsISupports* context,
nsILoadGroup* aGroup,
nsIInterfaceRequestor* notificationCallbacks,
nsLoadFlags loadAttributes)
nsLoadFlags loadAttributes,
nsIURI *referrer,
PRUint32 referrerFlags)
{
nsresult rv = NS_OK;
rv = NS_OpenURI(this, nsnull, aURL, nsnull, aGroup, notificationCallbacks,
loadAttributes);
nsCOMPtr<nsIChannel> channel;
rv = NS_OpenURI(getter_AddRefs(channel), aURL, nsnull, aGroup,
notificationCallbacks, loadAttributes);
if (NS_FAILED(rv)) return rv;
if (referrer) {
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
if (httpChannel) {
rv = httpChannel->SetReferrer(referrer, referrerFlags);
if (NS_FAILED(rv)) return rv;
}
}
rv = channel->AsyncOpen(this, context);
if (NS_FAILED(rv) && observer) {
// don't callback synchronously as it puts the caller
// in a recursive situation and breaks the asynchronous