Expose the image's principal on its imgIRequest. Bug 389188, r=pavlov, sr=biesi, a=pavlov.

This commit is contained in:
bzbarsky@mit.edu 2007-09-25 08:46:39 -07:00
Родитель 18d0dd0444
Коммит 8f798c6fe0
6 изменённых файлов: 54 добавлений и 1 удалений

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

@ -58,6 +58,9 @@ REQUIRES = xpcom \
necko \ necko \
nkcache \ nkcache \
gfx \ gfx \
caps \
xpconnect \
js \
$(JPEG_REQUIRES) \ $(JPEG_REQUIRES) \
$(PNG_REQUIRES) \ $(PNG_REQUIRES) \
$(ZLIB_REQUIRES) \ $(ZLIB_REQUIRES) \

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

@ -43,6 +43,7 @@
interface imgIContainer; interface imgIContainer;
interface imgIDecoderObserver; interface imgIDecoderObserver;
interface nsIURI; interface nsIURI;
interface nsIPrincipal;
/** /**
* imgIRequest interface * imgIRequest interface
@ -51,7 +52,7 @@ interface nsIURI;
* @version 0.1 * @version 0.1
* @see imagelib2 * @see imagelib2
*/ */
[scriptable, uuid(ccf705f6-1dd1-11b2-82ef-e18eccf7f7ec)] [scriptable, uuid(a297d3fa-5e0c-4e59-9f30-a01c9d4f3f8b)]
interface imgIRequest : nsIRequest interface imgIRequest : nsIRequest
{ {
/** /**
@ -80,6 +81,11 @@ interface imgIRequest : nsIRequest
*/ */
readonly attribute unsigned long imageStatus; 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 nsIURI URI;
readonly attribute imgIDecoderObserver decoderObserver; readonly attribute imgIDecoderObserver decoderObserver;
@ -93,5 +99,10 @@ interface imgIRequest : nsIRequest
* for this image load. * for this image load.
*/ */
imgIRequest clone(in imgIDecoderObserver aObserver); imgIRequest clone(in imgIDecoderObserver aObserver);
/**
* The principal gotten from the channel the image was loaded from.
*/
readonly attribute nsIPrincipal imagePrincipal;
}; };

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

@ -56,6 +56,9 @@ REQUIRES = xpcom \
gfx \ gfx \
thebes \ thebes \
cairo \ cairo \
caps \
xpconnect \
js \
$(NULL) $(NULL)
CPPSRCS = \ CPPSRCS = \

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

@ -61,6 +61,7 @@
#include "nsIProxyObjectManager.h" #include "nsIProxyObjectManager.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsISupportsPrimitives.h" #include "nsISupportsPrimitives.h"
#include "nsIScriptSecurityManager.h"
#include "nsString.h" #include "nsString.h"
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
@ -307,6 +308,17 @@ nsresult imgRequest::GetURI(nsIURI **aURI)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsresult imgRequest::GetPrincipal(nsIPrincipal **aPrincipal)
{
LOG_FUNC(gImgLog, "imgRequest::GetPrincipal");
if (mPrincipal) {
NS_ADDREF(*aPrincipal = mPrincipal);
}
return NS_ERROR_FAILURE;
}
void imgRequest::RemoveFromCache() void imgRequest::RemoveFromCache()
{ {
LOG_SCOPE(gImgLog, "imgRequest::RemoveFromCache"); LOG_SCOPE(gImgLog, "imgRequest::RemoveFromCache");
@ -599,7 +611,19 @@ NS_IMETHODIMP imgRequest::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt
proxy->OnStartRequest(aRequest, ctxt); proxy->OnStartRequest(aRequest, ctxt);
} }
/* Get our principal */
nsCOMPtr<nsIChannel> chan(do_QueryInterface(aRequest)); nsCOMPtr<nsIChannel> chan(do_QueryInterface(aRequest));
if (chan) {
nsCOMPtr<nsIScriptSecurityManager> 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 */ /* get the expires info */
if (mCacheEntry) { if (mCacheEntry) {

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

@ -52,6 +52,7 @@
#include "nsIProperties.h" #include "nsIProperties.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "nsIPrincipal.h"
#include "nsCategoryCache.h" #include "nsCategoryCache.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -121,6 +122,7 @@ private:
inline nsresult GetResultFromImageStatus(PRUint32 aStatus) const; inline nsresult GetResultFromImageStatus(PRUint32 aStatus) const;
void Cancel(nsresult aStatus); void Cancel(nsresult aStatus);
nsresult GetURI(nsIURI **aURI); nsresult GetURI(nsIURI **aURI);
nsresult GetPrincipal(nsIPrincipal **aPrincipal);
void RemoveFromCache(); void RemoveFromCache();
inline const char *GetMimeType() const { inline const char *GetMimeType() const {
return mContentType.get(); return mContentType.get();
@ -151,6 +153,7 @@ public:
private: private:
nsCOMPtr<nsIRequest> mRequest; nsCOMPtr<nsIRequest> mRequest;
nsCOMPtr<nsIURI> mURI; nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCOMPtr<imgIContainer> mImage; nsCOMPtr<imgIContainer> mImage;
nsCOMPtr<imgIDecoder> mDecoder; nsCOMPtr<imgIDecoder> mDecoder;
nsCOMPtr<nsIProperties> mProperties; nsCOMPtr<nsIProperties> mProperties;

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

@ -342,6 +342,15 @@ NS_IMETHODIMP imgRequestProxy::Clone(imgIDecoderObserver* aObserver,
return NS_OK; 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 **/ /** nsISupportsPriority methods **/
NS_IMETHODIMP imgRequestProxy::GetPriority(PRInt32 *priority) NS_IMETHODIMP imgRequestProxy::GetPriority(PRInt32 *priority)