implement test for detecting foreign images

git-svn-id: svn://10.0.0.236/trunk@63439 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
morse%netscape.com
2000-03-19 16:58:35 +00:00
parent b3ec199cf9
commit ca45affe0e
8 changed files with 58 additions and 28 deletions

View File

@@ -1067,7 +1067,7 @@ permission_Check
}
PUBLIC nsresult
Image_CheckForPermission(char * hostname, PRBool &permission) {
Image_CheckForPermission(char * hostname, char * firstHostname, PRBool &permission) {
/* exit if imageblocker is not enabled */
nsresult rv;
@@ -1082,7 +1082,8 @@ Image_CheckForPermission(char * hostname, PRBool &permission) {
/* try to make a decision based on pref settings */
if ((image_GetBehaviorPref() == COOKIE_DontUse) ||
(image_GetBehaviorPref() == COOKIE_DontAcceptForeign /* && foreign */)) { //???
(image_GetBehaviorPref() == COOKIE_DontAcceptForeign &&
PL_strcmp(hostname, firstHostname))) {
permission = PR_FALSE;
return NS_OK;
}

View File

@@ -52,5 +52,6 @@ extern void COOKIE_GetPermissionListForViewer (nsString& aPermissionList, PRInt3
extern void COOKIE_CookieViewerReturn(nsAutoString results);
extern COOKIE_BehaviorEnum COOKIE_GetBehaviorPref();
extern void Image_Block(nsString imageURL);
extern nsresult Image_CheckForPermission(char * hostname, PRBool &permission);
extern nsresult Image_CheckForPermission
(char * hostname, char * firstHostname, PRBool &permission);
#endif /* COOKIES_H */

View File

@@ -162,8 +162,8 @@ NS_IMETHODIMP nsCookieService::Image_Block(nsAutoString imageURL) {
}
NS_IMETHODIMP nsCookieService::Image_CheckForPermission
(char * hostname, PRBool &permission) {
return ::Image_CheckForPermission(hostname, permission);
(char * hostname, char * firstHostname, PRBool &permission) {
return ::Image_CheckForPermission(hostname, firstHostname, permission);
}

View File

@@ -42,7 +42,8 @@ public:
NS_IMETHOD Cookie_GetCookieListForViewer(nsString& aCookieList);
NS_IMETHOD Cookie_GetPermissionListForViewer(nsString& aPermissionList, PRInt32 type);
NS_IMETHOD Image_Block(nsAutoString imageURL);
NS_IMETHOD Image_CheckForPermission(char * hostname, PRBool &permission);
NS_IMETHOD Image_CheckForPermission
(char * hostname, char * firstHostname, PRBool &permission);
NS_IMETHOD CookieEnabled(PRBool* aEnabled);
nsCookieService();

View File

@@ -95,7 +95,8 @@ public:
NS_IMETHOD Cookie_GetCookieListForViewer(nsString& aCookieList)=0;
NS_IMETHOD Cookie_GetPermissionListForViewer(nsString& aPermissionList, PRInt32 type)=0;
NS_IMETHOD Image_Block(nsAutoString imageURL)=0;
NS_IMETHOD Image_CheckForPermission(char * hostname, PRBool &permission)=0;
NS_IMETHOD Image_CheckForPermission
(char * hostname, char * firstHostname, PRBool &permission)=0;
/*
* Specifies whether cookies will be accepted or not.

View File

@@ -254,11 +254,11 @@ ImageRequestImpl::Init(IL_GroupContext *aGroupContext,
((aFlags & IL_STICKY) ? nsImageLoadFlags_kSticky : 0) |
((aFlags & IL_BYPASS_CACHE) ? nsImageLoadFlags_kBypassCache : 0) |
((aFlags & IL_ONLY_FROM_CACHE) ? nsImageLoadFlags_kOnlyFromCache : 0);
mImageReq = IL_GetImage(aUrl, aGroupContext, mXPObserver,
nsnull == aBackgroundColor ? nsnull : &bgcolor,
aWidth, aHeight, flags, (void *)aNetContext);
aWidth, aHeight, flags, (void *)aNetContext, aObserver);
if (mImageReq == nsnull) {
XP_DisposeObserverList(mXPObserver);
mXPObserver = nsnull;

View File

@@ -22,7 +22,7 @@
/* -*- Mode: C; tab-width: 4 -*-
* libimg.h --- API calls to the Image Library.
* $Id: libimg.h,v 3.6 1999-11-13 22:37:35 cls%seawood.org Exp $
* $Id: libimg.h,v 3.7 2000-03-19 16:58:09 morse%netscape.com Exp $
*/
@@ -36,6 +36,7 @@
#include "ilISystemServices.h"
#include "ilIImageRenderer.h"
#include "nsIImageObserver.h"
/*********************** Observers and Observables ***************************/
@@ -147,7 +148,8 @@ IL_GetImage(const char* url,
IL_IRGB *background_color,
PRUint32 width, PRUint32 height,
PRUint32 flags,
void *net_context);
void *net_context,
nsIImageRequestObserver * aObserver);
/* Release a reference to an image lib request. If there are no other
clients of the request's associated pixmap, any related netlib

View File

@@ -37,6 +37,10 @@
#include "prprf.h"
#include "nsCRT.h"
#include "nsIPresContext.h"
#include "nsICookieService.h"
#include "nsIServiceManager.h"
PR_BEGIN_EXTERN_C
extern int XP_MSG_IMAGE_PIXELS;
@@ -52,6 +56,8 @@ int il_debug=0;
/* Global list of image group contexts. */
static IL_GroupContext *il_global_img_cx_list = NULL;
static NS_DEFINE_IID(kCookieServiceCID, NS_COOKIESERVICE_CID);
/*-----------------------------------------*/
NS_IMETHODIMP ImgDCallbk::ImgDCBSetupColorspaceConverter()
{
@@ -1871,13 +1877,8 @@ il_internal_image(const char *image_url)
return 0;
}
#include "nsICookieService.h"
#include "nsIServiceManager.h"
static NS_DEFINE_IID(kCookieServiceCID, NS_COOKIESERVICE_CID);
/* block certain hosts from loading images */
PRBool il_PermitLoad(const char * image_url) {
PRBool il_PermitLoad(const char * image_url, nsIImageRequestObserver * aObserver) {
/* convert image_url to an nsIURL so we can extract host and scheme */
nsresult rv;
@@ -1905,26 +1906,48 @@ PRBool il_PermitLoad(const char * image_url) {
return PR_TRUE;
}
/* check to see if we need to block image from loading */
NS_WITH_SERVICE(nsICookieService, cookieservice, kCookieServiceCID, &rv);
/* obtain first url from aObserver */
if (!aObserver) {
Recycle(host);
return PR_TRUE;
}
/* 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 = nsnull;
rv = firstUri->GetHost(&firstHost);
NS_RELEASE(firstUri);
if (NS_FAILED(rv)) {
Recycle(host);
return PR_TRUE;
}
/* check to see if we need to block image from loading */
NS_WITH_SERVICE(nsICookieService, cookieservice, kCookieServiceCID, &rv);
if (NS_FAILED(rv)) {
Recycle(host);
Recycle(firstHost);
return PR_TRUE;
}
PRBool permission;
rv = cookieservice->Image_CheckForPermission(host, permission);
rv = cookieservice->Image_CheckForPermission(host, firstHost, permission);
Recycle(host);
Recycle(firstHost);
if (NS_FAILED(rv)) {
return PR_TRUE;
}
return permission;
}
#include "nsWeakPtr.h"
#include "nsILoadGroup.h"
#include "ilIURL.h"
#include "nsIHTTPChannel.h"
IL_IMPLEMENT(IL_ImageReq *)
IL_GetImage(const char* image_url,
IL_GroupContext *img_cx,
@@ -1932,10 +1955,11 @@ IL_GetImage(const char* image_url,
NI_IRGB *background_color,
PRUint32 req_width, PRUint32 req_height,
PRUint32 flags,
void *opaque_cx)
void *opaque_cx,
nsIImageRequestObserver * aObserver)
{
/* block certain hosts from loading images */
if (!il_PermitLoad(image_url)) {
if (!il_PermitLoad(image_url, aObserver)) {
return NULL;
}