Send the stylesheet as the HTTP Referer header for images loaded from CSS stylesheets. b=249168 r=bzbarsky sr=darin

This commit is contained in:
dbaron%dbaron.org 2004-07-14 21:56:23 +00:00
parent 4075eaa0ad
commit a5d71df614
10 changed files with 25 additions and 16 deletions

View File

@ -329,6 +329,7 @@ public:
*/
static nsresult LoadImage(nsIURI* aURI,
nsIDocument* aLoadingDocument,
nsIURI* aReferrer,
imgIDecoderObserver* aObserver,
PRInt32 aLoadFlags,
imgIRequest** aRequest);

View File

@ -1671,7 +1671,7 @@ nsContentUtils::CanLoadImage(nsIURI* aURI, nsISupports* aContext,
nsresult
nsContentUtils::LoadImage(nsIURI* aURI, nsIDocument* aLoadingDocument,
imgIDecoderObserver* aObserver,
nsIURI* aReferrer, imgIDecoderObserver* aObserver,
PRInt32 aLoadFlags, imgIRequest** aRequest)
{
NS_PRECONDITION(aURI, "Must have a URI");
@ -1692,7 +1692,7 @@ nsContentUtils::LoadImage(nsIURI* aURI, nsIDocument* aLoadingDocument,
// right, but the best we can do here...
return sImgLoader->LoadImage(aURI, /* uri to load */
documentURI, /* initialDocumentURI */
documentURI, /* referrer */
aReferrer, /* referrer */
loadGroup, /* loadgroup */
aObserver, /* imgIDecoderObserver */
aLoadingDocument, /* uniquification key */

View File

@ -473,7 +473,8 @@ nsImageLoadingContent::ImageURIChanged(const nsACString& aNewURI)
// that have changed to alt text on us yet.
PRBool mayNeedReframe = mHaveHadObserver && !mCurrentRequest;
rv = nsContentUtils::LoadImage(imageURI, doc, this, nsIRequest::LOAD_NORMAL,
rv = nsContentUtils::LoadImage(imageURI, doc, doc->GetDocumentURI(),
this, nsIRequest::LOAD_NORMAL,
getter_AddRefs(req));
// If we now have a current request, we don't need to store the URI, since
// we can get it off the request. Release it.

View File

@ -3002,7 +3002,8 @@ nsGenericHTMLElement::MapBackgroundAttributesInto(const nsMappedAttributes* aAtt
nsresult rv = nsContentUtils::NewURIWithDocumentCharset(
getter_AddRefs(uri), spec, doc, doc->GetBaseURI());
if (NS_SUCCEEDED(rv)) {
nsCSSValue::Image *img = new nsCSSValue::Image(uri, spec.get(), doc);
nsCSSValue::Image *img =
new nsCSSValue::Image(uri, spec.get(), doc->GetDocumentURI(), doc);
if (img) {
if (img->mString) {
aData->mColorData->mBackImage.SetImageValue(img);

View File

@ -3654,7 +3654,7 @@ PRBool CSSParserImpl::ParseURL(nsresult& aErrorCode, nsCSSValue& aValue)
if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
// Set a null value on failure. Most failure cases should be
// NS_ERROR_MALFORMED_URI.
nsCSSValue::URL *url = new nsCSSValue::URL(uri, tk->mIdent.get());
nsCSSValue::URL *url = new nsCSSValue::URL(uri, tk->mIdent.get(), mURL);
if (!url || !url->mString) {
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
delete url;

View File

@ -348,6 +348,7 @@ void nsCSSValue::StartImageLoad(nsIDocument* aDocument) const
nsCSSValue::Image* image =
new nsCSSValue::Image(mValue.mURL->mURI,
mValue.mURL->mString,
mValue.mURL->mReferrer,
aDocument);
if (image) {
if (image->mString) {
@ -360,8 +361,8 @@ void nsCSSValue::StartImageLoad(nsIDocument* aDocument) const
}
nsCSSValue::Image::Image(nsIURI* aURI, const PRUnichar* aString,
nsIDocument* aDocument)
: URL(aURI, aString)
nsIURI* aReferrer, nsIDocument* aDocument)
: URL(aURI, aString, aReferrer)
{
MOZ_COUNT_CTOR(nsCSSValue::Image);
@ -377,7 +378,7 @@ nsCSSValue::Image::Image(nsIURI* aURI, const PRUnichar* aString,
if (mURI &&
nsContentUtils::CanLoadImage(mURI, aDocument, aDocument)) {
nsContentUtils::LoadImage(mURI, aDocument, nsnull,
nsContentUtils::LoadImage(mURI, aDocument, aReferrer, nsnull,
loadFlag,
getter_AddRefs(mRequest));
}

View File

@ -275,9 +275,10 @@ public:
struct URL {
// Caller must delete this object immediately if the allocation of
// |mString| fails.
URL(nsIURI* aURI, const PRUnichar* aString)
URL(nsIURI* aURI, const PRUnichar* aString, nsIURI* aReferrer)
: mURI(aURI),
mString(nsCRT::strdup(aString)),
mReferrer(aReferrer),
mRefCnt(0)
{
MOZ_COUNT_CTOR(nsCSSValue::URL);
@ -304,6 +305,7 @@ public:
nsCOMPtr<nsIURI> mURI; // null == invalid URL
PRUnichar* mString;
nsCOMPtr<nsIURI> mReferrer;
void AddRef() { ++mRefCnt; }
void Release() { if (--mRefCnt == 0) delete this; }
@ -317,7 +319,7 @@ public:
// Not making the constructor and destructor inline because that would
// force us to include imgIRequest.h, which leads to REQUIRES hell, since
// this header is included all over.
Image(nsIURI* aURI, const PRUnichar* aString,
Image(nsIURI* aURI, const PRUnichar* aString, nsIURI* aReferrer,
nsIDocument* aDocument) NS_HIDDEN;
~Image() NS_HIDDEN;

View File

@ -3654,7 +3654,7 @@ PRBool CSSParserImpl::ParseURL(nsresult& aErrorCode, nsCSSValue& aValue)
if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
// Set a null value on failure. Most failure cases should be
// NS_ERROR_MALFORMED_URI.
nsCSSValue::URL *url = new nsCSSValue::URL(uri, tk->mIdent.get());
nsCSSValue::URL *url = new nsCSSValue::URL(uri, tk->mIdent.get(), mURL);
if (!url || !url->mString) {
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
delete url;

View File

@ -348,6 +348,7 @@ void nsCSSValue::StartImageLoad(nsIDocument* aDocument) const
nsCSSValue::Image* image =
new nsCSSValue::Image(mValue.mURL->mURI,
mValue.mURL->mString,
mValue.mURL->mReferrer,
aDocument);
if (image) {
if (image->mString) {
@ -360,8 +361,8 @@ void nsCSSValue::StartImageLoad(nsIDocument* aDocument) const
}
nsCSSValue::Image::Image(nsIURI* aURI, const PRUnichar* aString,
nsIDocument* aDocument)
: URL(aURI, aString)
nsIURI* aReferrer, nsIDocument* aDocument)
: URL(aURI, aString, aReferrer)
{
MOZ_COUNT_CTOR(nsCSSValue::Image);
@ -377,7 +378,7 @@ nsCSSValue::Image::Image(nsIURI* aURI, const PRUnichar* aString,
if (mURI &&
nsContentUtils::CanLoadImage(mURI, aDocument, aDocument)) {
nsContentUtils::LoadImage(mURI, aDocument, nsnull,
nsContentUtils::LoadImage(mURI, aDocument, aReferrer, nsnull,
loadFlag,
getter_AddRefs(mRequest));
}

View File

@ -275,9 +275,10 @@ public:
struct URL {
// Caller must delete this object immediately if the allocation of
// |mString| fails.
URL(nsIURI* aURI, const PRUnichar* aString)
URL(nsIURI* aURI, const PRUnichar* aString, nsIURI* aReferrer)
: mURI(aURI),
mString(nsCRT::strdup(aString)),
mReferrer(aReferrer),
mRefCnt(0)
{
MOZ_COUNT_CTOR(nsCSSValue::URL);
@ -304,6 +305,7 @@ public:
nsCOMPtr<nsIURI> mURI; // null == invalid URL
PRUnichar* mString;
nsCOMPtr<nsIURI> mReferrer;
void AddRef() { ++mRefCnt; }
void Release() { if (--mRefCnt == 0) delete this; }
@ -317,7 +319,7 @@ public:
// Not making the constructor and destructor inline because that would
// force us to include imgIRequest.h, which leads to REQUIRES hell, since
// this header is included all over.
Image(nsIURI* aURI, const PRUnichar* aString,
Image(nsIURI* aURI, const PRUnichar* aString, nsIURI* aReferrer,
nsIDocument* aDocument) NS_HIDDEN;
~Image() NS_HIDDEN;