fix bug 32374, block foreign images

This commit is contained in:
morse%netscape.com 2000-03-25 07:09:25 +00:00
parent 20412a1b14
commit c15ec9e970
4 changed files with 23 additions and 21 deletions

View File

@ -55,6 +55,8 @@ typedef nsresult (*nsIFrameImageLoaderCB)(nsIPresContext* aPresContext,
*/
class nsIFrameImageLoader : public nsISupports {
public:
static const nsIID& GetIID() {static nsIID iid = NS_IFRAME_IMAGE_LOADER_IID; return iid;}
NS_IMETHOD Init(nsIPresContext* aPresContext,
nsIImageGroup* aGroup,
const nsString& aURL,
@ -81,6 +83,7 @@ public:
NS_IMETHOD SafeToDestroy(PRBool* aResult) = 0;
NS_IMETHOD GetURL(nsString& aResult) = 0;
NS_IMETHOD GetPresContext(nsIPresContext** aPresContext) = 0;
NS_IMETHOD GetImage(nsIImage** aResult) = 0;

View File

@ -355,6 +355,13 @@ nsFrameImageLoader::GetURL(nsString& aResult)
return NS_OK;
}
NS_IMETHODIMP
nsFrameImageLoader::GetPresContext(nsIPresContext** aPresContext)
{
NS_IF_ADDREF(*aPresContext = mPresContext);
return NS_OK;
}
NS_IMETHODIMP
nsFrameImageLoader::GetImage(nsIImage** aResult)
{

View File

@ -80,6 +80,7 @@ public:
NS_IMETHOD SafeToDestroy(PRBool* aResult);
NS_IMETHOD GetURL(nsString& aResult);
NS_IMETHOD GetPresContext(nsIPresContext** aPresContext);
NS_IMETHOD GetImage(nsIImage** aResult);

View File

@ -1907,33 +1907,24 @@ PRBool il_PermitLoad(const char * image_url, nsIImageRequestObserver * aObserver
}
/* obtain first url from aObserver */
if (!aObserver) {
Recycle(host);
return PR_TRUE;
}
#ifdef xxx
/* real ugly hack until I figure out the right way to get the presContext from aObserver */
nsIPresContext* presContext = (nsIPresContext*)(((PRInt32 *)aObserver)[3]);
nsIURI * firstUri;
rv = presContext->GetBaseURL(&firstUri);
if (NS_FAILED(rv) || !firstUri) {
Recycle(host);
return PR_TRUE;
char* firstHost = 0;
nsCOMPtr<nsIFrameImageLoader> frameImageLoader = do_QueryInterface(aObserver);
if (frameImageLoader) {
nsCOMPtr<nsIPresContext> presContext;
rv = frameImageLoader->GetPresContext(getter_AddRefs(presContext));
if (presContext) {
nsCOMPtr<nsIURI> firstURI;
presContext->GetBaseURL(getter_AddRefs(firstURI));
rv = firstURI->GetHost(&firstHost);
}
}
char* firstHost = nsnull;
rv = firstUri->GetHost(&firstHost);
NS_RELEASE(firstUri);
if (NS_FAILED(rv)) {
Recycle(host);
return PR_TRUE;
if (!firstHost) {
firstHost = PL_strdup(host);
}
#else
char* firstHost = PL_strdup(host);
#endif
/* check to see if we need to block image from loading */
NS_WITH_SERVICE(nsICookieService, cookieservice, kCookieServiceCID, &rv);