Relanding bug 389188. r=pavlov, sr=biesi

This commit is contained in:
bzbarsky@mit.edu 2007-11-08 18:55:41 -08:00
parent 9c51aee920
commit edbcbf98d3
6 changed files with 55 additions and 1 deletions

View File

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

View File

@ -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;
};

View File

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

View File

@ -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<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 */
if (mCacheEntry) {

View File

@ -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<nsIRequest> mRequest;
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCOMPtr<imgIContainer> mImage;
nsCOMPtr<imgIDecoder> mDecoder;
nsCOMPtr<nsIProperties> mProperties;

View File

@ -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)