From edbcbf98d39bb9a3df820c2dcd10108c2cd83636 Mon Sep 17 00:00:00 2001 From: "bzbarsky@mit.edu" Date: Thu, 8 Nov 2007 18:55:41 -0800 Subject: [PATCH] Relanding bug 389188. r=pavlov, sr=biesi --- modules/libpr0n/build/Makefile.in | 3 +++ modules/libpr0n/public/imgIRequest.idl | 13 ++++++++++++- modules/libpr0n/src/Makefile.in | 3 +++ modules/libpr0n/src/imgRequest.cpp | 25 +++++++++++++++++++++++++ modules/libpr0n/src/imgRequest.h | 3 +++ modules/libpr0n/src/imgRequestProxy.cpp | 9 +++++++++ 6 files changed, 55 insertions(+), 1 deletion(-) diff --git a/modules/libpr0n/build/Makefile.in b/modules/libpr0n/build/Makefile.in index 4a851f2c7bf8..eec0fcf5ccde 100644 --- a/modules/libpr0n/build/Makefile.in +++ b/modules/libpr0n/build/Makefile.in @@ -58,6 +58,9 @@ REQUIRES = xpcom \ necko \ nkcache \ gfx \ + caps \ + xpconnect \ + js \ $(JPEG_REQUIRES) \ $(PNG_REQUIRES) \ $(ZLIB_REQUIRES) \ diff --git a/modules/libpr0n/public/imgIRequest.idl b/modules/libpr0n/public/imgIRequest.idl index d9e053f6525c..11b32a02e46a 100644 --- a/modules/libpr0n/public/imgIRequest.idl +++ b/modules/libpr0n/public/imgIRequest.idl @@ -43,6 +43,7 @@ interface imgIContainer; interface imgIDecoderObserver; interface nsIURI; +interface nsIPrincipal; /** * imgIRequest interface @@ -51,7 +52,7 @@ interface nsIURI; * @version 0.1 * @see imagelib2 */ -[scriptable, uuid(ccf705f6-1dd1-11b2-82ef-e18eccf7f7ec)] +[scriptable, uuid(a297d3fa-5e0c-4e59-9f30-a01c9d4f3f8b)] interface imgIRequest : nsIRequest { /** @@ -80,6 +81,11 @@ interface imgIRequest : nsIRequest */ readonly attribute unsigned long imageStatus; + /** + * The URI the image load was started with. Note that this might not be the + * actual URI for the image (e.g. if HTTP redirects happened during the + * load). + */ readonly attribute nsIURI URI; readonly attribute imgIDecoderObserver decoderObserver; @@ -93,5 +99,10 @@ interface imgIRequest : nsIRequest * for this image load. */ imgIRequest clone(in imgIDecoderObserver aObserver); + + /** + * The principal gotten from the channel the image was loaded from. + */ + readonly attribute nsIPrincipal imagePrincipal; }; diff --git a/modules/libpr0n/src/Makefile.in b/modules/libpr0n/src/Makefile.in index 5db38f8088be..2f85dbff4357 100644 --- a/modules/libpr0n/src/Makefile.in +++ b/modules/libpr0n/src/Makefile.in @@ -56,6 +56,9 @@ REQUIRES = xpcom \ gfx \ thebes \ cairo \ + caps \ + xpconnect \ + js \ $(NULL) CPPSRCS = \ diff --git a/modules/libpr0n/src/imgRequest.cpp b/modules/libpr0n/src/imgRequest.cpp index 3e267150c0dd..282c4feacc4c 100644 --- a/modules/libpr0n/src/imgRequest.cpp +++ b/modules/libpr0n/src/imgRequest.cpp @@ -61,6 +61,7 @@ #include "nsIProxyObjectManager.h" #include "nsIServiceManager.h" #include "nsISupportsPrimitives.h" +#include "nsIScriptSecurityManager.h" #include "nsString.h" #include "nsXPIDLString.h" @@ -307,6 +308,18 @@ nsresult imgRequest::GetURI(nsIURI **aURI) return NS_ERROR_FAILURE; } +nsresult imgRequest::GetPrincipal(nsIPrincipal **aPrincipal) +{ + LOG_FUNC(gImgLog, "imgRequest::GetPrincipal"); + + if (mPrincipal) { + NS_ADDREF(*aPrincipal = mPrincipal); + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + void imgRequest::RemoveFromCache() { LOG_SCOPE(gImgLog, "imgRequest::RemoveFromCache"); @@ -599,7 +612,19 @@ NS_IMETHODIMP imgRequest::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt proxy->OnStartRequest(aRequest, ctxt); } + /* Get our principal */ nsCOMPtr chan(do_QueryInterface(aRequest)); + if (chan) { + nsCOMPtr secMan = + do_GetService("@mozilla.org/scriptsecuritymanager;1"); + if (secMan) { + nsresult rv = secMan->GetChannelPrincipal(chan, + getter_AddRefs(mPrincipal)); + if (NS_FAILED(rv)) { + return rv; + } + } + } /* get the expires info */ if (mCacheEntry) { diff --git a/modules/libpr0n/src/imgRequest.h b/modules/libpr0n/src/imgRequest.h index 3de9607f59db..67fbf833d176 100644 --- a/modules/libpr0n/src/imgRequest.h +++ b/modules/libpr0n/src/imgRequest.h @@ -52,6 +52,7 @@ #include "nsIProperties.h" #include "nsIStreamListener.h" #include "nsIURI.h" +#include "nsIPrincipal.h" #include "nsCategoryCache.h" #include "nsCOMPtr.h" @@ -121,6 +122,7 @@ private: inline nsresult GetResultFromImageStatus(PRUint32 aStatus) const; void Cancel(nsresult aStatus); nsresult GetURI(nsIURI **aURI); + nsresult GetPrincipal(nsIPrincipal **aPrincipal); void RemoveFromCache(); inline const char *GetMimeType() const { return mContentType.get(); @@ -151,6 +153,7 @@ public: private: nsCOMPtr mRequest; nsCOMPtr mURI; + nsCOMPtr mPrincipal; nsCOMPtr mImage; nsCOMPtr mDecoder; nsCOMPtr mProperties; diff --git a/modules/libpr0n/src/imgRequestProxy.cpp b/modules/libpr0n/src/imgRequestProxy.cpp index f960a28f736c..23e93ac4a51a 100644 --- a/modules/libpr0n/src/imgRequestProxy.cpp +++ b/modules/libpr0n/src/imgRequestProxy.cpp @@ -342,6 +342,15 @@ NS_IMETHODIMP imgRequestProxy::Clone(imgIDecoderObserver* aObserver, return NS_OK; } +/* readonly attribute nsIPrincipal imagePrincipal; */ +NS_IMETHODIMP imgRequestProxy::GetImagePrincipal(nsIPrincipal **aPrincipal) +{ + if (!mOwner) + return NS_ERROR_FAILURE; + + return mOwner->GetPrincipal(aPrincipal); +} + /** nsISupportsPriority methods **/ NS_IMETHODIMP imgRequestProxy::GetPriority(PRInt32 *priority)