Implement API to add a permission

This commit is contained in:
morse%netscape.com 2000-03-26 20:26:15 +00:00
Родитель 5378dcc162
Коммит e2002f766d
7 изменённых файлов: 108 добавлений и 6 удалений

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

@ -1448,12 +1448,29 @@ permission_Add(char * host, PRBool permission, PRInt32 type, PRBool save) {
}
}
/* create a type structure and attach it to the host structure */
/* see if host already has an entry for this type */
permission_TypeStruct * typeStruct;
typeStruct = PR_NEW(permission_TypeStruct);
typeStruct->type = type;
typeStruct->permission = permission;
hostStruct->permissionList->AppendElement(typeStruct);
PRBool typeFound = PR_FALSE;
PRInt32 count2 = hostStruct->permissionList->Count();
for (PRInt32 typeIndex=0; typeIndex<count2; typeIndex++) {
typeStruct = NS_STATIC_CAST
(permission_TypeStruct*, hostStruct->permissionList->ElementAt(typeIndex));
if (typeStruct->type == type) {
/* type found. Modify the corresponding permission */
typeStruct->permission = permission;
typeFound = PR_TRUE;
break;
}
}
/* create a type structure and attach it to the host structure */
if (!typeFound) {
typeStruct = PR_NEW(permission_TypeStruct);
typeStruct->type = type;
typeStruct->permission = permission;
hostStruct->permissionList->AppendElement(typeStruct);
}
/* write the changes out to a file */
if (save) {
@ -2741,6 +2758,19 @@ Image_Block(nsString imageURL) {
}
}
PUBLIC void
Permission_Add(nsString imageURL, PRBool permission, PRInt32 type) {
if (imageURL.Length() == 0) {
return;
}
char * imageURLCString = imageURL.ToNewCString();
char *host = cookie_ParseURL(imageURLCString, GET_HOST_PART);
Recycle(imageURLCString);
if (PL_strlen(host) != 0) {
permission_Add(host, permission, type, PR_TRUE);
}
}
/* Hack - Neeti remove this */
/* remove front and back white space
* modifies the original string

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

@ -52,6 +52,7 @@ 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 void Permission_Add(nsString imageURL, PRBool permission, PRInt32 type);
extern nsresult Image_CheckForPermission
(char * hostname, char * firstHostname, PRBool &permission);
#endif /* COOKIES_H */

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

@ -156,11 +156,16 @@ NS_IMETHODIMP nsCookieService::Cookie_GetPermissionListForViewer
}
NS_IMETHODIMP nsCookieService::Image_Block(nsAutoString imageURL) {
printf("entered nsCookieService.cpp\n");
::Image_Block(imageURL);
return NS_OK;
}
NS_IMETHODIMP nsCookieService::Permission_Add
(nsString imageURL, PRBool permission, PRInt32 type) {
::Permission_Add(imageURL, permission, type);
return NS_OK;
}
NS_IMETHODIMP nsCookieService::Image_CheckForPermission
(char * hostname, char * firstHostname, PRBool &permission) {
return ::Image_CheckForPermission(hostname, firstHostname, permission);

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

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

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

@ -95,6 +95,7 @@ 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 Permission_Add(nsString imageURL, PRBool permission, PRInt32 type)=0;
NS_IMETHOD Image_CheckForPermission
(char * hostname, char * firstHostname, PRBool &permission)=0;

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

@ -32,6 +32,9 @@
#include "nsIWebShellWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsCookieViewer.h"
#include "nsIDocShell.h"
#include "nsIPresShell.h"
#include "nsIDocument.h"
static NS_DEFINE_IID(kCookieServiceCID, NS_COOKIESERVICE_CID);
@ -118,3 +121,63 @@ CookieViewerImpl::BlockImage(const char* imageURL)
res = cookieservice->Image_Block(imageURLAutoString);
return res;
}
NS_IMETHODIMP
CookieViewerImpl::AddPermission(nsIDOMWindow* aWin, PRBool permission, PRInt32 type)
{
nsresult rv;
/* all the following is just to get the url of the window */
NS_PRECONDITION(aWin != nsnull, "null ptr");
if (!aWin) {
return NS_ERROR_NULL_POINTER;
}
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
scriptGlobalObject = do_QueryInterface(aWin);
if(!scriptGlobalObject) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDocShell> docShell;
rv = scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
if(NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIPresShell> presShell;
rv = docShell->GetPresShell(getter_AddRefs(presShell));
if(NS_FAILED(rv)) {
return rv;
}
nsIDocument* doc = nsnull;
rv = presShell->GetDocument(&doc);
if (NS_FAILED(rv)) {
return rv;
}
if (!doc) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIURI> docURL;
docURL = doc->GetDocumentURL();
if (!docURL) {
return NS_ERROR_FAILURE;
}
char* spec;
(void)docURL->GetSpec(&spec);
nsAutoString objectURLAutoString = spec;
Recycle(spec);
/* got the url at last, now pass it on to the Permission_Add routie */
NS_WITH_SERVICE(nsICookieService, cookieservice, kCookieServiceCID, &rv);
if (NS_FAILED(rv)) {
return rv;
}
rv = cookieservice->Permission_Add(objectURLAutoString, permission, type);
return rv;
}

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

@ -37,6 +37,7 @@ interface nsICookieViewer : nsISupports
{
void SetValue(in string aValue, in nsIDOMWindow win);
void BlockImage(in string imageURL);
void AddPermission(in nsIDOMWindow win, in PRBool permission, in PRInt32 type);
string GetCookieValue();
string GetPermissionValue(in PRInt32 type);