mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-23 21:17:52 +00:00
bug 46783, reorg cookies module for embedding, r=valeski, sr=alecf
This commit is contained in:
parent
f0faad3250
commit
d8762db686
@ -115,6 +115,8 @@
|
||||
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsWeakReference.h"//nshtmlelementfactory supports weak references
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
|
||||
#ifdef ALLOW_ASYNCH_STYLE_SHEETS
|
||||
const PRBool kBlockByDefault=PR_FALSE;
|
||||
@ -4500,8 +4502,18 @@ HTMLContentSink::ProcessHeaderData(nsIAtom* aHeader,nsString& aValue,nsIHTMLCont
|
||||
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(docShell);
|
||||
rv = webNav->GetCurrentURI(getter_AddRefs(baseURI));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = cookieServ->SetCookieString(baseURI, mDocument, aValue);
|
||||
char *cookie = aValue.ToNewCString();
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObj;
|
||||
nsCOMPtr<nsIPrompt> prompt;
|
||||
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj));
|
||||
if (globalObj) {
|
||||
nsCOMPtr<nsIDOMWindowInternal> window (do_QueryInterface(globalObj));
|
||||
if (window) {
|
||||
window->GetPrompter(getter_AddRefs(prompt));
|
||||
}
|
||||
}
|
||||
rv = cookieServ->SetCookieString(baseURI, prompt, cookie);
|
||||
nsCRT::free(cookie);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
} // END set-cookie
|
||||
|
||||
|
@ -112,6 +112,7 @@
|
||||
#include "nsHTMLParts.h" //for createelementNS
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsContentCID.h"
|
||||
#include "nsIPrompt.h"
|
||||
|
||||
#define DETECTOR_CONTRACTID_MAX 127
|
||||
static char g_detector_contractid[DETECTOR_CONTRACTID_MAX + 1];
|
||||
@ -2043,8 +2044,16 @@ nsHTMLDocument::GetCookie(nsAWritableString& aCookie)
|
||||
nsresult result = NS_OK;
|
||||
nsAutoString str;
|
||||
NS_WITH_SERVICE(nsICookieService, service, kCookieServiceCID, &result);
|
||||
char * cookie;
|
||||
if ((NS_OK == result) && (nsnull != service) && (nsnull != mDocumentURL)) {
|
||||
result = service->GetCookieString(mDocumentURL, str);
|
||||
result = service->GetCookieString(mDocumentURL, &cookie);
|
||||
}
|
||||
if (nsnull != cookie) {
|
||||
str.AssignWithConversion(cookie);
|
||||
nsCRT::free(cookie);
|
||||
} else {
|
||||
// No Cookie isn't an error condition.
|
||||
aCookie.Truncate();
|
||||
}
|
||||
aCookie.Assign(str);
|
||||
return result;
|
||||
@ -2056,7 +2065,18 @@ nsHTMLDocument::SetCookie(const nsAReadableString& aCookie)
|
||||
nsresult result = NS_OK;
|
||||
NS_WITH_SERVICE(nsICookieService, service, kCookieServiceCID, &result);
|
||||
if ((NS_OK == result) && (nsnull != service) && (nsnull != mDocumentURL)) {
|
||||
result = service->SetCookieString(mDocumentURL, this, nsAutoString(aCookie));
|
||||
char *cookie = nsString(aCookie).ToNewCString();
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObj;
|
||||
nsCOMPtr<nsIPrompt> prompt;
|
||||
this->GetScriptGlobalObject(getter_AddRefs(globalObj));
|
||||
if (globalObj) {
|
||||
nsCOMPtr<nsIDOMWindowInternal> window (do_QueryInterface(globalObj));
|
||||
if (window) {
|
||||
window->GetPrompter(getter_AddRefs(prompt));
|
||||
}
|
||||
}
|
||||
result = service->SetCookieString(mDocumentURL, prompt, cookie);
|
||||
nsCRT::free(cookie);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -55,7 +55,6 @@
|
||||
#include "nsIContent.h"
|
||||
#include "nsIContentViewerFile.h"
|
||||
#include "nsIContentViewerEdit.h"
|
||||
#include "nsICookieService.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocShellLoadInfo.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
@ -112,7 +111,6 @@ static PRInt32 gRefCnt = 0;
|
||||
// CIDs
|
||||
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
static NS_DEFINE_IID(kCookieServiceCID, NS_COOKIESERVICE_CID);
|
||||
static NS_DEFINE_CID(kHTTPHandlerCID, NS_IHTTPHANDLER_CID);
|
||||
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
|
||||
static NS_DEFINE_CID(kCharsetConverterManagerCID,
|
||||
@ -4239,13 +4237,20 @@ NS_IMETHODIMP NavigatorImpl::GetCookieEnabled(PRBool *aCookieEnabled)
|
||||
nsresult rv = NS_OK;
|
||||
*aCookieEnabled = PR_FALSE;
|
||||
|
||||
NS_WITH_SERVICE(nsICookieService, service, kCookieServiceCID, &rv);
|
||||
if (NS_FAILED(rv) || service == nsnull)
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
||||
if (NS_FAILED(rv) || prefs == nsnull)
|
||||
return rv;
|
||||
|
||||
return service->CookieEnabled(aCookieEnabled);
|
||||
}
|
||||
PRInt32 cookieBehaviorPref;
|
||||
rv = prefs->GetIntPref("network.cookie.cookieBehavior", &cookieBehaviorPref);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
const PRInt32 DONT_USE = 2;
|
||||
*aCookieEnabled = (cookieBehaviorPref != DONT_USE);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP NavigatorImpl::JavaEnabled(PRBool *aReturn)
|
||||
{
|
||||
|
@ -36,15 +36,31 @@ DIRS = tests
|
||||
endif
|
||||
|
||||
CPPSRCS = \
|
||||
nsCookieService.cpp \
|
||||
nsModuleFactory.cpp \
|
||||
nsCookie.cpp \
|
||||
nsPermission.cpp \
|
||||
nsCookieManager.cpp \
|
||||
nsCookieService.cpp \
|
||||
nsImgManager.cpp \
|
||||
nsPermissionManager.cpp \
|
||||
nsCookies.cpp \
|
||||
nsImages.cpp \
|
||||
nsPermissions.cpp \
|
||||
nsUtils.cpp \
|
||||
nsCookieHTTPNotify.cpp \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsICookieManager.idl \
|
||||
nsIImgManager.idl \
|
||||
nsIPermissionManager.idl \
|
||||
nsICookieService.idl \
|
||||
nsICookie.idl \
|
||||
nsIPermission.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsICookieService.h \
|
||||
nsCookieHTTPNotify.h \
|
||||
nsCookie.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
@ -25,24 +25,43 @@ include <$(DEPTH)/config/config.mak>
|
||||
DEFINES=-D_IMPL_NS_COOKIE -DWIN32_LEAN_AND_MEAN
|
||||
MODULE=cookie
|
||||
|
||||
EXPORTS = nsICookieService.h nsCookieHTTPNotify.h nsCookie.h
|
||||
|
||||
CSRCS= \
|
||||
$(NULL)
|
||||
EXPORTS = nsCookieHTTPNotify.h
|
||||
|
||||
CPPSRCS= \
|
||||
nsCookieService.cpp \
|
||||
nsModuleFactory.cpp \
|
||||
nsCookie.cpp \
|
||||
nsPermission.cpp \
|
||||
nsCookieManager.cpp \
|
||||
nsCookieService.cpp \
|
||||
nsImgManager.cpp \
|
||||
nsPermissionManager.cpp \
|
||||
nsCookies.cpp \
|
||||
nsImages.cpp \
|
||||
nsPermissions.cpp \
|
||||
nsUtils.cpp \
|
||||
nsCookieHTTPNotify.cpp \
|
||||
$(NULL)
|
||||
|
||||
C_OBJS= \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS= .\nsICookieManager.idl \
|
||||
.\nsIImgManager.idl \
|
||||
.\nsIPermissionManager.idl \
|
||||
.\nsICookieService.idl \
|
||||
.\nsICookie.idl \
|
||||
.\nsIPermission.idl \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsModuleFactory.obj \
|
||||
.\$(OBJDIR)\nsCookie.obj \
|
||||
.\$(OBJDIR)\nsPermission.obj \
|
||||
.\$(OBJDIR)\nsCookieManager.obj \
|
||||
.\$(OBJDIR)\nsCookieService.obj \
|
||||
.\$(OBJDIR)\nsCookie.obj \
|
||||
.\$(OBJDIR)\nsImgManager.obj \
|
||||
.\$(OBJDIR)\nsPermissionManager.obj \
|
||||
.\$(OBJDIR)\nsCookies.obj \
|
||||
.\$(OBJDIR)\nsImages.obj \
|
||||
.\$(OBJDIR)\nsPermissions.obj \
|
||||
.\$(OBJDIR)\nsUtils.obj \
|
||||
.\$(OBJDIR)\nsCookieHTTPNotify.obj \
|
||||
$(NULL)
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
@ -20,42 +20,44 @@
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef COOKIES_H
|
||||
#define COOKIES_H
|
||||
#ifndef nsCookie_h__
|
||||
#define nsCookie_h__
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsError.h"
|
||||
#include "nsString.h"
|
||||
#include "nsICookie.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
#ifdef _IMPL_NS_COOKIE
|
||||
#define NS_COOKIE NS_EXPORT
|
||||
#else
|
||||
#define NS_COOKIE NS_IMPORT
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsCookie : public nsICookie,
|
||||
public nsSupportsWeakReference {
|
||||
public:
|
||||
|
||||
typedef enum {
|
||||
COOKIE_Accept,
|
||||
COOKIE_DontAcceptForeign,
|
||||
COOKIE_DontUse
|
||||
} COOKIE_BehaviorEnum;
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICOOKIE
|
||||
|
||||
class nsIPrompt;
|
||||
// Note: following constructor takes ownership of the four strings (name, value
|
||||
// host, and path) passed to it so the caller of the constructor must not
|
||||
// free them
|
||||
nsCookie
|
||||
(char * name,
|
||||
char * value,
|
||||
PRBool isDomain,
|
||||
char * host,
|
||||
char * path,
|
||||
PRBool isSecure,
|
||||
PRUint64 expires);
|
||||
nsCookie();
|
||||
virtual ~nsCookie(void);
|
||||
|
||||
protected:
|
||||
char * cookieName;
|
||||
char * cookieValue;
|
||||
PRBool cookieIsDomain;
|
||||
char * cookieHost;
|
||||
char * cookiePath;
|
||||
PRBool cookieIsSecure;
|
||||
PRUint64 cookieExpires;
|
||||
};
|
||||
|
||||
extern char * COOKIE_GetCookie(char * address);
|
||||
extern char * COOKIE_GetCookieFromHttp(char * address, char * firstAddress);
|
||||
extern void COOKIE_SetCookieString(char * cur_url, nsIPrompt *aPrompter, char * set_cookie_header);
|
||||
extern int COOKIE_ReadCookies();
|
||||
extern void COOKIE_RegisterCookiePrefCallbacks(void);
|
||||
extern void COOKIE_RemoveAllCookies(void);
|
||||
extern void COOKIE_DeletePersistentUserData(void);
|
||||
extern void COOKIE_SetCookieStringFromHttp(char * cur_url, char * first_url, nsIPrompt *aPRompter, char * set_cookie_header, char * server_date);
|
||||
extern void COOKIE_GetCookieListForViewer (nsString& aCookieList);
|
||||
extern void COOKIE_GetPermissionListForViewer (nsString& aPermissionList, PRInt32 type);
|
||||
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 */
|
||||
#endif /* nsCookie_h__ */
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "nsCookieService.h" /* don't remove -- needed for mac build */
|
||||
#include "nsCookieHTTPNotify.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIHTTPChannel.h"
|
||||
@ -64,7 +65,7 @@ NS_METHOD nsCookieHTTPNotify::RegisterProc(nsIComponentManager *aCompMgr,
|
||||
{
|
||||
// Register ourselves into the NS_CATEGORY_HTTP_STARTUP
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman = do_GetService("@mozilla.org/categorymanager;1", &rv);
|
||||
nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString prevEntry;
|
||||
@ -81,7 +82,7 @@ NS_METHOD nsCookieHTTPNotify::UnregisterProc(nsIComponentManager *aCompMgr,
|
||||
const nsModuleComponentInfo *info)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman = do_GetService("@mozilla.org/categorymanager;1", &rv);
|
||||
nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString prevEntry;
|
||||
@ -182,19 +183,14 @@ nsCookieHTTPNotify::ModifyRequest(nsISupports *aContext)
|
||||
rv = SetupCookieService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString cookie;
|
||||
rv = mCookieService->GetCookieStringFromHTTP(pURL, pFirstURL, cookie);
|
||||
char * cookie;
|
||||
rv = mCookieService->GetCookieStringFromHttp(pURL, pFirstURL, &cookie);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Set the cookie into the request headers
|
||||
// XXX useless convertion from nsString to char * again
|
||||
const char *cookieRaw = cookie.ToNewCString();
|
||||
if (!cookieRaw) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// only set a cookie header if we have a value to send
|
||||
if (*cookieRaw)
|
||||
rv = pHTTPConnection->SetRequestHeader(mCookieHeader, cookieRaw);
|
||||
nsMemory::Free((void *)cookieRaw);
|
||||
if (cookie && *cookie)
|
||||
rv = pHTTPConnection->SetRequestHeader(mCookieHeader, cookie);
|
||||
nsMemory::Free((void *)cookie);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
121
extensions/cookie/nsCookieManager.cpp
Normal file
121
extensions/cookie/nsCookieManager.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCookieManager.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsCookies.h"
|
||||
#include "nsCookie.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsCookieEnumerator : public nsISimpleEnumerator
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsCookieEnumerator() : mCookieCount(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
NS_IMETHOD HasMoreElements(PRBool *result)
|
||||
{
|
||||
*result = COOKIE_Count() > mCookieCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetNext(nsISupports **result)
|
||||
{
|
||||
char *name;
|
||||
char *value;
|
||||
PRBool isDomain;
|
||||
char * host;
|
||||
char * path;
|
||||
PRBool isSecure;
|
||||
PRUint64 expires;
|
||||
(void) COOKIE_Enumerate
|
||||
(mCookieCount++, &name, &value, &isDomain, &host, &path, &isSecure, &expires);
|
||||
nsICookie *cookie =
|
||||
new nsCookie(name, value, isDomain, host, path, isSecure, expires);
|
||||
*result = cookie;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
virtual ~nsCookieEnumerator()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
PRInt32 mCookieCount;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCookieEnumerator, nsISimpleEnumerator);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsCookieManager Implementation
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsCookieManager, nsICookieManager, nsISupportsWeakReference);
|
||||
|
||||
nsCookieManager::nsCookieManager()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsCookieManager::~nsCookieManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsCookieManager::Init()
|
||||
{
|
||||
COOKIE_Read();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookieManager::RemoveAll(void) {
|
||||
::COOKIE_RemoveAll();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookieManager::GetEnumerator(nsISimpleEnumerator * *entries)
|
||||
{
|
||||
*entries = nsnull;
|
||||
|
||||
nsCookieEnumerator* cookieEnum = new nsCookieEnumerator();
|
||||
if (cookieEnum == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(cookieEnum);
|
||||
*entries = cookieEnum;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookieManager::Remove
|
||||
(const char* host, const char* name, const char* path, const PRBool permanent) {
|
||||
::COOKIE_Remove(host, name, path, permanent);
|
||||
return NS_OK;
|
||||
}
|
45
extensions/cookie/nsCookieManager.h
Normal file
45
extensions/cookie/nsCookieManager.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsCookieManager_h__
|
||||
#define nsCookieManager_h__
|
||||
|
||||
#include "nsICookieManager.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsCookieManager : public nsICookieManager,
|
||||
public nsSupportsWeakReference {
|
||||
public:
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICOOKIEMANAGER
|
||||
|
||||
nsCookieManager();
|
||||
virtual ~nsCookieManager(void);
|
||||
nsresult Init();
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsCookieManager_h__ */
|
@ -24,13 +24,17 @@
|
||||
#include "nsCookieService.h"
|
||||
#include "nsCookieHTTPNotify.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsCookie.h"
|
||||
#include "nsCookies.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsCURILoader.h"
|
||||
|
||||
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -38,101 +42,114 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsCookieService Implementation
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsCookieService, nsICookieService, nsIObserver, nsISupportsWeakReference);
|
||||
NS_IMPL_ISUPPORTS4(nsCookieService, nsICookieService,
|
||||
nsIObserver, nsIDocumentLoaderObserver, nsISupportsWeakReference);
|
||||
|
||||
nsCookieService::nsCookieService()
|
||||
: mInitted(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsCookieService::~nsCookieService(void)
|
||||
{
|
||||
COOKIE_RemoveAllCookies();
|
||||
COOKIE_Write(); /* in case any deleted cookies didn't get removed from file yet */
|
||||
COOKIE_RemoveAll();
|
||||
}
|
||||
|
||||
nsresult nsCookieService::Init()
|
||||
{
|
||||
// make sure we're not initted twice, because this has the serious
|
||||
// consequence of reading the cookies file twice
|
||||
if (mInitted)
|
||||
{
|
||||
NS_ASSERTION(0, "Baking the cookies twice. Doesn't that make them biscuits?");
|
||||
return NS_ERROR_ALREADY_INITIALIZED;
|
||||
}
|
||||
|
||||
COOKIE_RegisterCookiePrefCallbacks();
|
||||
COOKIE_ReadCookies();
|
||||
|
||||
COOKIE_RegisterPrefCallbacks();
|
||||
COOKIE_Read();
|
||||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
|
||||
if (observerService) {
|
||||
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
|
||||
observerService->AddObserver(this, NS_LITERAL_STRING("profile-do-change").get());
|
||||
}
|
||||
|
||||
mInitted = PR_TRUE;
|
||||
|
||||
// Register as an observer for the document loader
|
||||
NS_WITH_SERVICE(nsIDocumentLoader, docLoaderService, kDocLoaderServiceCID, &rv)
|
||||
if (NS_SUCCEEDED(rv) && docLoaderService) {
|
||||
docLoaderService->AddObserver((nsIDocumentLoaderObserver*)this);
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "Could not get nsIDocumentLoader");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::OnStartDocumentLoad(nsIDocumentLoader* aLoader, nsIURI* aURL, const char* aCommand)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::OnEndDocumentLoad(nsIDocumentLoader* aLoader, nsIRequest *request, nsresult aStatus)
|
||||
{
|
||||
COOKIE_Write();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::OnStartURLLoad
|
||||
(nsIDocumentLoader* loader, nsIRequest *request)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::OnProgressURLLoad
|
||||
(nsIDocumentLoader* loader, nsIRequest *request, PRUint32 aProgress, PRUint32 aProgressMax)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::OnStatusURLLoad
|
||||
(nsIDocumentLoader* loader, nsIRequest *request, nsString& aMsg)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::GetCookieString(nsIURI *aURL, nsString& aCookie) {
|
||||
nsCookieService::OnEndURLLoad
|
||||
(nsIDocumentLoader* loader, nsIRequest *request, nsresult aStatus)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::GetCookieString(nsIURI *aURL, char ** aCookie) {
|
||||
nsXPIDLCString spec;
|
||||
nsresult rv = aURL->GetSpec(getter_Copies(spec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
char *cookie = COOKIE_GetCookie((char *)(const char *)spec);
|
||||
if (nsnull != cookie) {
|
||||
aCookie.AssignWithConversion(cookie);
|
||||
nsCRT::free(cookie);
|
||||
} else {
|
||||
// No Cookie isn't an error condition.
|
||||
aCookie.Truncate();
|
||||
}
|
||||
*aCookie = COOKIE_GetCookie((char *)(const char *)spec);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::GetCookieStringFromHTTP(nsIURI *aURL, nsIURI *aFirstURL, nsString& aCookie) {
|
||||
nsCookieService::GetCookieStringFromHttp(nsIURI *aURL, nsIURI *aFirstURL, char ** aCookie) {
|
||||
nsXPIDLCString spec;
|
||||
nsresult rv = aURL->GetSpec(getter_Copies(spec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsXPIDLCString firstSpec;
|
||||
rv = aFirstURL->GetSpec(getter_Copies(firstSpec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
char *cookie = COOKIE_GetCookieFromHttp((char *)(const char *)spec, (char *)(const char *)firstSpec);
|
||||
if (nsnull != cookie) {
|
||||
aCookie.AssignWithConversion(cookie);
|
||||
nsCRT::free(cookie);
|
||||
} else {
|
||||
// No Cookie isn't an error condition.
|
||||
aCookie.Truncate();
|
||||
}
|
||||
*aCookie = COOKIE_GetCookieFromHttp((char *)(const char *)spec, (char *)(const char *)firstSpec);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::SetCookieString(nsIURI *aURL, nsIDocument* aDoc, const nsString& aCookie) {
|
||||
nsCookieService::SetCookieString(nsIURI *aURL, nsIPrompt* aPrompt, const char * aCookie) {
|
||||
char *spec = NULL;
|
||||
nsresult result = aURL->GetSpec(&spec);
|
||||
NS_ASSERTION(result == NS_OK, "deal with this");
|
||||
char *cookie = aCookie.ToNewCString();
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObj;
|
||||
nsCOMPtr<nsIPrompt> prompt;
|
||||
if (aDoc) {
|
||||
aDoc->GetScriptGlobalObject(getter_AddRefs(globalObj));
|
||||
if (globalObj) {
|
||||
nsCOMPtr<nsIDOMWindowInternal> window (do_QueryInterface(globalObj));
|
||||
if (window) {
|
||||
window->GetPrompter(getter_AddRefs(prompt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
COOKIE_SetCookieString((char *)spec, prompt, cookie);
|
||||
COOKIE_SetCookieString(spec, aPrompt, aCookie);
|
||||
nsCRT::free(spec);
|
||||
nsCRT::free(cookie);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -142,114 +159,38 @@ nsCookieService::SetCookieStringFromHttp(nsIURI *aURL, nsIURI *aFirstURL, nsIPro
|
||||
nsresult rv = aURL->GetSpec(&spec);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
char *firstSpec = NULL;
|
||||
rv = aFirstURL->GetSpec(&firstSpec); if (NS_FAILED(rv)) return rv;
|
||||
rv = aFirstURL->GetSpec(&firstSpec);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
COOKIE_SetCookieStringFromHttp(spec, firstSpec, aPrompter, (char *)aCookie, (char *)aExpires);
|
||||
nsCRT::free(spec);
|
||||
nsCRT::free(firstSpec);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookieService::Cookie_RemoveAllCookies(void) {
|
||||
::COOKIE_RemoveAllCookies();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookieService::Cookie_CookieViewerReturn(nsAutoString results) {
|
||||
::COOKIE_CookieViewerReturn(results);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookieService::Cookie_GetCookieListForViewer(nsString& aCookieList) {
|
||||
::COOKIE_GetCookieListForViewer(aCookieList);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookieService::Cookie_GetPermissionListForViewer
|
||||
(nsString& aPermissionList, PRInt32 type) {
|
||||
::COOKIE_GetPermissionListForViewer(aPermissionList, type);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookieService::Image_Block(nsAutoString imageURL) {
|
||||
::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);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCookieService::CookieEnabled(PRBool* aEnabled)
|
||||
{
|
||||
*aEnabled = (COOKIE_GetBehaviorPref() != COOKIE_DontUse);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCookieService::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get())) {
|
||||
// The profile is about to change.
|
||||
|
||||
// Dump current cookies. This will be done by calling
|
||||
// COOKIE_RemoveAllCookies which clears the memory-resident
|
||||
// COOKIE_RemoveAll which clears the memory-resident
|
||||
// cookie table. The reason the cookie file does not
|
||||
// need to be updated is because the file was updated every time
|
||||
// the memory-resident table changed (i.e., whenever a new cookie
|
||||
// was accepted). If this condition ever changes, the cookie
|
||||
// file would need to be updated here.
|
||||
|
||||
COOKIE_RemoveAllCookies();
|
||||
COOKIE_RemoveAll();
|
||||
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get()))
|
||||
COOKIE_DeletePersistentUserData();
|
||||
}
|
||||
else if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-do-change").get())) {
|
||||
// The profile has aleady changed.
|
||||
// Now just read them from the new profile location.
|
||||
COOKIE_ReadCookies();
|
||||
COOKIE_Read();
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Define the contructor function for the objects
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieService, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieHTTPNotify, Init)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Define a table of CIDs implemented by this module along with other
|
||||
// information like the function to create an instance, contractid, and
|
||||
// class name.
|
||||
//
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ "CookieService", NS_COOKIESERVICE_CID,
|
||||
NS_COOKIESERVICE_CONTRACTID, nsCookieServiceConstructor, }, // XXX Singleton
|
||||
{ NS_COOKIEHTTPNOTIFY_CLASSNAME,
|
||||
NS_COOKIEHTTPNOTIFY_CID,
|
||||
NS_COOKIEHTTPNOTIFY_CONTRACTID,
|
||||
nsCookieHTTPNotifyConstructor,
|
||||
nsCookieHTTPNotify::RegisterProc,
|
||||
nsCookieHTTPNotify::UnregisterProc
|
||||
},
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Implement the NSGetModule() exported function for your module
|
||||
// and the entire implementation of the module object.
|
||||
//
|
||||
NS_IMPL_NSGETMODULE("nsCookieModule", components)
|
||||
|
@ -25,39 +25,27 @@
|
||||
|
||||
#include "nsICookieService.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsCookieService : public nsICookieService,
|
||||
public nsIObserver,
|
||||
public nsIDocumentLoaderObserver,
|
||||
public nsSupportsWeakReference {
|
||||
public:
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
NS_IMETHOD GetCookieString(nsIURI *aURL, nsString& aCookie);
|
||||
NS_IMETHOD GetCookieStringFromHTTP(nsIURI *aURL, nsIURI *aFirstURL, nsString& aCookie);
|
||||
NS_IMETHOD SetCookieString(nsIURI *aURL, nsIDocument* aDoc, const nsString& aCookie);
|
||||
NS_IMETHOD SetCookieStringFromHttp(nsIURI *aURL, nsIURI *aFirstURL, nsIPrompt *aPrompter, const char *aCookie, const char *aExpires);
|
||||
NS_IMETHOD Cookie_RemoveAllCookies(void);
|
||||
NS_IMETHOD Cookie_CookieViewerReturn(nsAutoString results);
|
||||
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);
|
||||
NS_DECL_NSIDOCUMENTLOADEROBSERVER
|
||||
NS_DECL_NSICOOKIESERVICE
|
||||
|
||||
nsCookieService();
|
||||
virtual ~nsCookieService(void);
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
PRBool mInitted;
|
||||
};
|
||||
|
||||
#endif /* nsCookieService_h__ */
|
||||
|
1492
extensions/cookie/nsCookies.cpp
Normal file
1492
extensions/cookie/nsCookies.cpp
Normal file
File diff suppressed because it is too large
Load Diff
60
extensions/cookie/nsCookies.h
Normal file
60
extensions/cookie/nsCookies.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef COOKIES_H
|
||||
#define COOKIES_H
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
#ifdef _IMPL_NS_COOKIE
|
||||
#define NS_COOKIE NS_EXPORT
|
||||
#else
|
||||
#define NS_COOKIE NS_IMPORT
|
||||
#endif
|
||||
|
||||
|
||||
class nsIPrompt;
|
||||
|
||||
extern nsresult COOKIE_Read();
|
||||
extern nsresult COOKIE_Write();
|
||||
extern char * COOKIE_GetCookie(char * address);
|
||||
extern char * COOKIE_GetCookieFromHttp(char * address, char * firstAddress);
|
||||
extern void COOKIE_SetCookieString(char * cur_url, nsIPrompt *aPrompter, const char * set_cookie_header);
|
||||
extern void COOKIE_SetCookieStringFromHttp(char * cur_url, char * first_url, nsIPrompt *aPRompter, char * set_cookie_header, char * server_date);
|
||||
extern void COOKIE_RegisterPrefCallbacks(void);
|
||||
|
||||
extern void COOKIE_RemoveAll(void);
|
||||
extern void COOKIE_DeletePersistentUserData(void);
|
||||
extern PRInt32 COOKIE_Count();
|
||||
extern void COOKIE_Enumerate
|
||||
(PRInt32 count,
|
||||
char **name,
|
||||
char **value,
|
||||
PRBool *isDomain,
|
||||
char ** host,
|
||||
char ** path,
|
||||
PRBool * isSecure,
|
||||
PRUint64 * expires);
|
||||
extern void COOKIE_Remove
|
||||
(const char* host, const char* name, const char* path, const PRBool permanent);
|
||||
|
||||
#endif /* COOKIES_H */
|
60
extensions/cookie/nsICookie.idl
Normal file
60
extensions/cookie/nsICookie.idl
Normal file
@ -0,0 +1,60 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
|
||||
* The Original Code is mozilla.org code.
|
||||
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 2001, Mozilla. All Rights Reserved.
|
||||
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(E9FCB9A4-D376-458f-B720-E65E7DF593BC)]
|
||||
|
||||
/**
|
||||
This interface represents a HTTP or Javascript "cookie" object.
|
||||
*/
|
||||
|
||||
interface nsICookie : nsISupports {
|
||||
|
||||
/* the name of the cookie */
|
||||
readonly attribute string name;
|
||||
|
||||
/* the cookie value */
|
||||
readonly attribute string value;
|
||||
|
||||
/* true if the cookie is a domain cookie, false otherwise */
|
||||
readonly attribute boolean isDomain;
|
||||
|
||||
/* the host (possibly fully qualified) of the cookie */
|
||||
readonly attribute string host;
|
||||
|
||||
/* the path pertaining to the cookie */
|
||||
readonly attribute string path;
|
||||
|
||||
/* true if the cookie was transmitted over ssl, false otherwise */
|
||||
readonly attribute boolean isSecure;
|
||||
|
||||
/* expiration time (local timezone) expressed as number of seconds since Jan 1, 1970 */
|
||||
readonly attribute PRUint64 expires;
|
||||
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// {E9FCB9A4-D376-458f-B720-E65E7DF593BC}
|
||||
#define NS_COOKIE_CID \
|
||||
{ 0xe9fcb9a4, 0xd376, 0x458f, { 0xb7, 0x20, 0xe6, 0x5e, 0x7d, 0xf5, 0x93, 0xbc } }
|
||||
#define NS_COOKIE_CONTRACTID "@mozilla.org/cookie;1"
|
||||
%}
|
45
extensions/cookie/nsICookieManager.idl
Normal file
45
extensions/cookie/nsICookieManager.idl
Normal file
@ -0,0 +1,45 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file contains an interface to the Cookie Manager.
|
||||
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIEnumerator.idl"
|
||||
|
||||
[scriptable, uuid(AAAB6710-0F2C-11d5-A53B-0010A401EB10)]
|
||||
interface nsICookieManager : nsISupports
|
||||
{
|
||||
void removeAll();
|
||||
readonly attribute nsISimpleEnumerator enumerator;
|
||||
void remove(in string domain, in string name, in string path, in boolean permanent);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// {AAAB6710-0F2C-11d5-A53B-0010A401EB10}
|
||||
#define NS_COOKIEMANAGER_CID \
|
||||
{ 0xaaab6710, 0xf2c, 0x11d5, { 0xa5, 0x3b, 0x0, 0x10, 0xa4, 0x1, 0xeb, 0x10 } }
|
||||
#define NS_COOKIEMANAGER_CONTRACTID "@mozilla.org/cookiemanager;1"
|
||||
%}
|
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
@ -20,32 +20,19 @@
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsICookieService_h__
|
||||
#define nsICookieService_h__
|
||||
/*
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIDocument.h"
|
||||
This file contains an interface to the Cookie Service.
|
||||
|
||||
// {AB397774-12D3-11d3-8AD1-00105A1B8860}
|
||||
#define NS_COOKIESERVICE_CID \
|
||||
{ 0xab397774, 0x12d3, 0x11d3, { 0x8a, 0xd1, 0x0, 0x10, 0x5a, 0x1b, 0x88, 0x60 } }
|
||||
*/
|
||||
|
||||
/* ContractID prefixes for Cookie DLL registration. */
|
||||
#define NS_COOKIESERVICE_CONTRACTID "@mozilla.org/cookie;1"
|
||||
|
||||
// {AB397772-12D3-11d3-8AD1-00105A1B8860}
|
||||
#define NS_ICOOKIESERVICE_IID \
|
||||
{ 0xab397772, 0x12d3, 0x11d3, { 0x8a, 0xd1, 0x0, 0x10, 0x5a, 0x1b, 0x88, 0x60 } }
|
||||
|
||||
class nsIPrompt;
|
||||
|
||||
class nsICookieService : public nsISupports {
|
||||
public:
|
||||
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_ICOOKIESERVICE_IID; return iid; }
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIURI.idl"
|
||||
#include "nsIPrompt.idl"
|
||||
|
||||
[scriptable, uuid(AB397774-12D3-11d3-8AD1-00105A1B8860)]
|
||||
interface nsICookieService : nsISupports
|
||||
{
|
||||
/*
|
||||
* Get the complete cookie string associated with the URL
|
||||
*
|
||||
@ -53,7 +40,7 @@ public:
|
||||
* @param aCookie The string object which will hold the result
|
||||
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||
*/
|
||||
NS_IMETHOD GetCookieString(nsIURI *aURL, nsString& aCookie)=0;
|
||||
string getCookieString(in nsIURI aURL);
|
||||
|
||||
/*
|
||||
* Get the complete cookie string associated with the URL
|
||||
@ -63,7 +50,7 @@ public:
|
||||
* @param aCookie The string object which will hold the result
|
||||
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||
*/
|
||||
NS_IMETHOD GetCookieStringFromHTTP(nsIURI *aURL, nsIURI *aFirstURL, nsString& aCookie)=0;
|
||||
string getCookieStringFromHttp(in nsIURI aURL, in nsIURI aFirstURL);
|
||||
|
||||
/*
|
||||
* Set the cookie string associated with the URL
|
||||
@ -72,7 +59,7 @@ public:
|
||||
* @param aCookie The string to set
|
||||
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||
*/
|
||||
NS_IMETHOD SetCookieString(nsIURI *aURL, nsIDocument* aDoc, const nsString& aCookie)=0;
|
||||
void setCookieString(in nsIURI aURL, in nsIPrompt aPrompt, in string aCookie);
|
||||
|
||||
/*
|
||||
* Set the cookie string and expires associated with the URL
|
||||
@ -85,31 +72,13 @@ public:
|
||||
* @param aExpires The expiry information of the cookie
|
||||
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||
*/
|
||||
NS_IMETHOD SetCookieStringFromHttp(nsIURI *aURL, nsIURI *aFirstURL, nsIPrompt *aPrompter, const char *aCookie, const char *aExpires)=0;
|
||||
void setCookieStringFromHttp(in nsIURI aURL, in nsIURI aFirstURL, in nsIPrompt aPrompter, in string aCookie, in string aExpires);
|
||||
|
||||
/*
|
||||
* Blows away all permissions currently in the cookie permissions list,
|
||||
* and then blows away all cookies currently in the cookie list.
|
||||
*/
|
||||
NS_IMETHOD Cookie_RemoveAllCookies(void)=0;
|
||||
|
||||
/*
|
||||
* Interface routines for cookie viewer
|
||||
*/
|
||||
NS_IMETHOD Cookie_CookieViewerReturn(nsAutoString results)=0;
|
||||
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;
|
||||
|
||||
/*
|
||||
* Specifies whether cookies will be accepted or not.
|
||||
* XXX This method can be refined to return more specific information
|
||||
* (i.e. whether we accept foreign cookies or not, etc.) if necessary.
|
||||
*/
|
||||
NS_IMETHOD CookieEnabled(PRBool* aEnabled)=0;
|
||||
};
|
||||
|
||||
#endif /* nsICookieService_h__ */
|
||||
%{ C++
|
||||
// {AB397774-12D3-11d3-8AD1-00105A1B8860}
|
||||
#define NS_COOKIESERVICE_CID \
|
||||
{ 0xab397774, 0x12d3, 0x11d3, { 0x8a, 0xd1, 0x0, 0x10, 0x5a, 0x1b, 0x88, 0x60 } }
|
||||
#define NS_COOKIESERVICE_CONTRACTID "@mozilla.org/cookieService;1"
|
||||
%}
|
43
extensions/cookie/nsIImgManager.idl
Normal file
43
extensions/cookie/nsIImgManager.idl
Normal file
@ -0,0 +1,43 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file contains an interface to the Image Manager.
|
||||
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(D60B3710-166D-11d5-A542-0010A401EB10)]
|
||||
interface nsIImgManager : nsISupports
|
||||
{
|
||||
void block(in string imageURL);
|
||||
boolean checkForPermission(in string hostname, in string firstHostname);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// {D60B3710-166D-11d5-A542-0010A401EB10}
|
||||
#define NS_IMGMANAGER_CID \
|
||||
{ 0xd60b3710, 0x166d, 0x11d5, { 0xa5, 0x42, 0x0, 0x10, 0xa4, 0x1, 0xeb, 0x10 } }
|
||||
#define NS_IMGMANAGER_CONTRACTID "@mozilla.org/imgmanager;1"
|
||||
%}
|
47
extensions/cookie/nsIPermission.idl
Normal file
47
extensions/cookie/nsIPermission.idl
Normal file
@ -0,0 +1,47 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
|
||||
* The Original Code is mozilla.org code.
|
||||
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 2001, Mozilla. All Rights Reserved.
|
||||
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(28F16D80-157B-11d5-A542-0010A401EB10)]
|
||||
|
||||
/**
|
||||
This interface represents a "permission" object.
|
||||
*/
|
||||
|
||||
interface nsIPermission : nsISupports {
|
||||
|
||||
/* the name of the host */
|
||||
readonly attribute string host;
|
||||
|
||||
/* the type of permission (e.g., cookie, image, etc) */
|
||||
readonly attribute PRInt32 type;
|
||||
|
||||
/* the permission */
|
||||
readonly attribute boolean capability;
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// {28F16D80-157B-11d5-A542-0010A401EB10}
|
||||
#define NS_PERMISSION_CID \
|
||||
{ 0x28f16d80, 0x157b, 0x11d5, { 0xa5, 0x42, 0x0, 0x10, 0xa4, 0x1, 0xeb, 0x10 } }
|
||||
#define NS_PERMISSION_CONTRACTID "@mozilla.org/permission;1"
|
||||
%}
|
46
extensions/cookie/nsIPermissionManager.idl
Normal file
46
extensions/cookie/nsIPermissionManager.idl
Normal file
@ -0,0 +1,46 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file contains an interface to the Permission Manager.
|
||||
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIEnumerator.idl"
|
||||
|
||||
[scriptable, uuid(4F6B5E00-0C36-11d5-A535-0010A401EB10)]
|
||||
interface nsIPermissionManager : nsISupports
|
||||
{
|
||||
void add(in string objectURL, in boolean permission, in PRInt32 type);
|
||||
void removeAll();
|
||||
readonly attribute nsISimpleEnumerator enumerator;
|
||||
void remove(in string host, in PRInt32 type);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// {4F6B5E00-0C36-11d5-A535-0010A401EB10}
|
||||
#define NS_PERMISSIONMANAGER_CID \
|
||||
{ 0x4f6b5e00, 0xc36, 0x11d5, { 0xa5, 0x35, 0x0, 0x10, 0xa4, 0x1, 0xeb, 0x10 } }
|
||||
#define NS_PERMISSIONMANAGER_CONTRACTID "@mozilla.org/permissionmanager;1"
|
||||
%}
|
186
extensions/cookie/nsImages.cpp
Normal file
186
extensions/cookie/nsImages.cpp
Normal file
@ -0,0 +1,186 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsPermissions.h"
|
||||
#include "nsUtils.h"
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
#include "xp_core.h"
|
||||
#include "prmem.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsTextFormatter.h"
|
||||
|
||||
#define image_behaviorPref "network.image.imageBehavior"
|
||||
#define image_warningPref "network.image.warnAboutImages"
|
||||
|
||||
typedef struct _permission_HostStruct {
|
||||
char * host;
|
||||
nsVoidArray * permissionList;
|
||||
} permission_HostStruct;
|
||||
|
||||
typedef struct _permission_TypeStruct {
|
||||
PRInt32 type;
|
||||
PRBool permission;
|
||||
} permission_TypeStruct;
|
||||
|
||||
PRIVATE PERMISSION_BehaviorEnum image_behavior = PERMISSION_Accept;
|
||||
PRIVATE PRBool image_warning = PR_FALSE;
|
||||
|
||||
PRIVATE void
|
||||
image_SetBehaviorPref(PERMISSION_BehaviorEnum x) {
|
||||
image_behavior = x;
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
image_SetWarningPref(PRBool x) {
|
||||
image_warning = x;
|
||||
}
|
||||
|
||||
PRIVATE PERMISSION_BehaviorEnum
|
||||
image_GetBehaviorPref() {
|
||||
return image_behavior;
|
||||
}
|
||||
|
||||
PRIVATE PRBool
|
||||
image_GetWarningPref() {
|
||||
return image_warning;
|
||||
}
|
||||
|
||||
MODULE_PRIVATE int PR_CALLBACK
|
||||
image_BehaviorPrefChanged(const char * newpref, void * data) {
|
||||
PRInt32 n;
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_FAILED(prefs->GetIntPref(image_behaviorPref, &n))) {
|
||||
image_SetBehaviorPref(PERMISSION_Accept);
|
||||
} else {
|
||||
image_SetBehaviorPref((PERMISSION_BehaviorEnum)n);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
MODULE_PRIVATE int PR_CALLBACK
|
||||
image_WarningPrefChanged(const char * newpref, void * data) {
|
||||
PRBool x;
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_FAILED(prefs->GetBoolPref(image_warningPref, &x))) {
|
||||
x = PR_FALSE;
|
||||
}
|
||||
image_SetWarningPref(x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
IMAGE_RegisterPrefCallbacks(void) {
|
||||
PRInt32 n;
|
||||
PRBool x;
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
|
||||
// Initialize for image_behaviorPref
|
||||
if (NS_FAILED(prefs->GetIntPref(image_behaviorPref, &n))) {
|
||||
n = PERMISSION_Accept;
|
||||
}
|
||||
image_SetBehaviorPref((PERMISSION_BehaviorEnum)n);
|
||||
prefs->RegisterCallback(image_behaviorPref, image_BehaviorPrefChanged, NULL);
|
||||
|
||||
// Initialize for image_warningPref
|
||||
if (NS_FAILED(prefs->GetBoolPref(image_warningPref, &x))) {
|
||||
x = PR_FALSE;
|
||||
}
|
||||
image_SetWarningPref(x);
|
||||
prefs->RegisterCallback(image_warningPref, image_WarningPrefChanged, NULL);
|
||||
}
|
||||
|
||||
PUBLIC nsresult
|
||||
IMAGE_CheckForPermission
|
||||
(const char * hostname, const char * firstHostname, PRBool *permission) {
|
||||
|
||||
/* exit if imageblocker is not enabled */
|
||||
nsresult rv;
|
||||
PRBool prefvalue = PR_FALSE;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv) ||
|
||||
NS_FAILED(prefs->GetBoolPref("imageblocker.enabled", &prefvalue)) ||
|
||||
!prefvalue) {
|
||||
*permission = (image_GetBehaviorPref() != PERMISSION_DontUse);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* try to make a decision based on pref settings */
|
||||
if ((image_GetBehaviorPref() == PERMISSION_DontUse)) {
|
||||
*permission = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
if (image_GetBehaviorPref() == PERMISSION_DontAcceptForeign) {
|
||||
/* compare tails of names checking to see if they have a common domain */
|
||||
/* we do this by comparing the tails of both names where each tail includes at least one dot */
|
||||
PRInt32 dotcount = 0;
|
||||
const char * tailHostname = hostname + PL_strlen(hostname) - 1;
|
||||
while (tailHostname > hostname) {
|
||||
if (*tailHostname == '.') {
|
||||
dotcount++;
|
||||
}
|
||||
if (dotcount == 2) {
|
||||
tailHostname++;
|
||||
break;
|
||||
}
|
||||
tailHostname--;
|
||||
}
|
||||
dotcount = 0;
|
||||
const char * tailFirstHostname = firstHostname + PL_strlen(firstHostname) - 1;
|
||||
while (tailFirstHostname > firstHostname) {
|
||||
if (*tailFirstHostname == '.') {
|
||||
dotcount++;
|
||||
}
|
||||
if (dotcount == 2) {
|
||||
tailFirstHostname++;
|
||||
break;
|
||||
}
|
||||
tailFirstHostname--;
|
||||
}
|
||||
if (PL_strcmp(tailFirstHostname, tailHostname)) {
|
||||
*permission = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* use common routine to make decision */
|
||||
PRUnichar * message = CKutil_Localize(NS_LITERAL_STRING("PermissionToAcceptImage").get());
|
||||
PRUnichar * new_string = nsTextFormatter::smprintf(message, hostname ? hostname : "");
|
||||
*permission = Permission_Check(0, hostname, IMAGEPERMISSION,
|
||||
image_GetWarningPref(), new_string);
|
||||
PR_FREEIF(new_string);
|
||||
Recycle(message);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PUBLIC nsresult
|
||||
IMAGE_Block(const char* imageURL) {
|
||||
if (!imageURL || !(*imageURL)) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
char *host = CKutil_ParseURL(imageURL, GET_HOST_PART);
|
||||
Permission_AddHost(host, PR_FALSE, IMAGEPERMISSION, PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
33
extensions/cookie/nsImages.h
Normal file
33
extensions/cookie/nsImages.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef IMAGES_H
|
||||
#define IMAGES_H
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
extern nsresult IMAGE_CheckForPermission
|
||||
(const char * hostname, const char * firstHostname, PRBool *permission);
|
||||
extern nsresult IMAGE_Block(const char * imageURL);
|
||||
extern void IMAGE_RegisterPrefCallbacks(void);
|
||||
|
||||
#endif /* IMAGES_H */
|
58
extensions/cookie/nsImgManager.cpp
Normal file
58
extensions/cookie/nsImgManager.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsImgManager.h"
|
||||
#include "nsImages.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsImgManager Implementation
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsImgManager, nsIImgManager);
|
||||
|
||||
nsImgManager::nsImgManager()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsImgManager::~nsImgManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsImgManager::Init()
|
||||
{
|
||||
IMAGE_RegisterPrefCallbacks();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImgManager::Block(const char * imageURL) {
|
||||
::IMAGE_Block(imageURL);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImgManager::CheckForPermission
|
||||
(const char * hostname, const char * firstHostname, PRBool *permission) {
|
||||
return ::IMAGE_CheckForPermission(hostname, firstHostname, permission);
|
||||
}
|
43
extensions/cookie/nsImgManager.h
Normal file
43
extensions/cookie/nsImgManager.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsImgManager_h__
|
||||
#define nsImgManager_h__
|
||||
|
||||
#include "nsIImgManager.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsImgManager : public nsIImgManager {
|
||||
public:
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMGMANAGER
|
||||
|
||||
nsImgManager();
|
||||
virtual ~nsImgManager(void);
|
||||
nsresult Init();
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsImgManager_h__ */
|
84
extensions/cookie/nsModuleFactory.cpp
Normal file
84
extensions/cookie/nsModuleFactory.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
|
||||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsCookie.h"
|
||||
#include "nsPermission.h"
|
||||
#include "nsCookieManager.h"
|
||||
#include "nsCookieService.h"
|
||||
#include "nsImgManager.h"
|
||||
#include "nsPermissionManager.h"
|
||||
#include "nsCookieHTTPNotify.h"
|
||||
|
||||
// Define the constructor function for the objects
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCookie)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPermission)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieManager, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieService, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsImgManager, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPermissionManager, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieHTTPNotify, Init)
|
||||
|
||||
// The list of components we register
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ "Cookie",
|
||||
NS_COOKIE_CID,
|
||||
NS_COOKIE_CONTRACTID,
|
||||
nsCookieConstructor
|
||||
},
|
||||
{ "Permission",
|
||||
NS_PERMISSION_CID,
|
||||
NS_PERMISSION_CONTRACTID,
|
||||
nsPermissionConstructor
|
||||
},
|
||||
{ "CookieManager",
|
||||
NS_COOKIEMANAGER_CID,
|
||||
NS_COOKIEMANAGER_CONTRACTID,
|
||||
nsCookieManagerConstructor
|
||||
},
|
||||
{ "CookieService",
|
||||
NS_COOKIESERVICE_CID,
|
||||
NS_COOKIESERVICE_CONTRACTID,
|
||||
nsCookieServiceConstructor
|
||||
},
|
||||
{ "ImgManager",
|
||||
NS_IMGMANAGER_CID,
|
||||
NS_IMGMANAGER_CONTRACTID,
|
||||
nsImgManagerConstructor
|
||||
},
|
||||
{ "PermissionManager",
|
||||
NS_PERMISSIONMANAGER_CID,
|
||||
NS_PERMISSIONMANAGER_CONTRACTID,
|
||||
nsPermissionManagerConstructor
|
||||
},
|
||||
{ NS_COOKIEHTTPNOTIFY_CLASSNAME,
|
||||
NS_COOKIEHTTPNOTIFY_CID,
|
||||
NS_COOKIEHTTPNOTIFY_CONTRACTID,
|
||||
nsCookieHTTPNotifyConstructor,
|
||||
nsCookieHTTPNotify::RegisterProc,
|
||||
nsCookieHTTPNotify::UnregisterProc
|
||||
},
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsCookieModule", components)
|
65
extensions/cookie/nsPermission.cpp
Normal file
65
extensions/cookie/nsPermission.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsPermission.h"
|
||||
#include "nsString.h"
|
||||
#include "prmem.h"
|
||||
|
||||
// nsPermission Implementation
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsPermission, nsIPermission, nsISupportsWeakReference);
|
||||
|
||||
nsPermission::nsPermission() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsPermission::nsPermission
|
||||
(char * host,
|
||||
PRInt32 type,
|
||||
PRBool capability) {
|
||||
permissionHost = host;
|
||||
permissionType = type;
|
||||
permissionCapability = capability;
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsPermission::~nsPermission(void) {
|
||||
nsCRT::free(permissionHost);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPermission::GetHost(char * *aHost) {
|
||||
if (permissionHost) {
|
||||
*aHost = (char *) nsMemory::Clone(permissionHost, nsCRT::strlen(permissionHost) + 1);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPermission::GetType(PRInt32 *aType) {
|
||||
*aType = permissionType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPermission::GetCapability(PRBool *aCapability) {
|
||||
*aCapability = permissionCapability;
|
||||
return NS_OK;
|
||||
}
|
51
extensions/cookie/nsPermission.h
Normal file
51
extensions/cookie/nsPermission.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsPermission_h__
|
||||
#define nsPermission_h__
|
||||
|
||||
#include "nsIPermission.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsPermission : public nsIPermission,
|
||||
public nsSupportsWeakReference {
|
||||
public:
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPERMISSION
|
||||
|
||||
// Note: following constructor takes ownership of the host string so the caller
|
||||
// of the constructor must not free them
|
||||
nsPermission(char * host, PRInt32 type, PRBool capability);
|
||||
nsPermission();
|
||||
virtual ~nsPermission(void);
|
||||
|
||||
protected:
|
||||
char * permissionHost;
|
||||
PRInt32 permissionType;
|
||||
PRBool permissionCapability;
|
||||
};
|
||||
|
||||
#endif /* nsPermission_h__ */
|
166
extensions/cookie/nsPermissionManager.cpp
Normal file
166
extensions/cookie/nsPermissionManager.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsPermissionManager.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsPermissions.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsPermission.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsPermissionEnumerator : public nsISimpleEnumerator
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsPermissionEnumerator() : mHostCount(0), mTypeCount(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
NS_IMETHOD HasMoreElements(PRBool *result)
|
||||
{
|
||||
*result = PERMISSION_HostCount() > mHostCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetNext(nsISupports **result)
|
||||
{
|
||||
char *host;
|
||||
PRBool capability;
|
||||
PRInt32 type;
|
||||
(void) PERMISSION_Enumerate
|
||||
(mHostCount, mTypeCount++, &host, &type, &capability);
|
||||
if (mTypeCount == PERMISSION_TypeCount(mHostCount)) {
|
||||
mTypeCount = 0;
|
||||
mHostCount++;
|
||||
}
|
||||
nsIPermission *permission =
|
||||
new nsPermission(host, type, capability);
|
||||
*result = permission;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
virtual ~nsPermissionEnumerator()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
PRInt32 mHostCount;
|
||||
PRInt32 mTypeCount;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsPermissionEnumerator, nsISimpleEnumerator);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsPermissionManager Implementation
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsPermissionManager, nsIPermissionManager, nsIObserver, nsISupportsWeakReference);
|
||||
|
||||
nsPermissionManager::nsPermissionManager()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsPermissionManager::~nsPermissionManager(void)
|
||||
{
|
||||
PERMISSION_RemoveAll();
|
||||
}
|
||||
|
||||
nsresult nsPermissionManager::Init()
|
||||
{
|
||||
PERMISSION_Read();
|
||||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
|
||||
if (observerService) {
|
||||
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
|
||||
observerService->AddObserver(this, NS_LITERAL_STRING("profile-do-change").get());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPermissionManager::Add
|
||||
(const char * objectURL, PRBool permission, PRInt32 type) {
|
||||
::PERMISSION_Add(objectURL, permission, type);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPermissionManager::RemoveAll(void) {
|
||||
::PERMISSION_RemoveAll();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPermissionManager::GetEnumerator(nsISimpleEnumerator * *entries)
|
||||
{
|
||||
*entries = nsnull;
|
||||
|
||||
nsPermissionEnumerator* permissionEnum = new nsPermissionEnumerator();
|
||||
if (permissionEnum == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(permissionEnum);
|
||||
*entries = permissionEnum;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPermissionManager::Remove(const char* host, PRInt32 type) {
|
||||
::PERMISSION_Remove(host, type);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPermissionManager::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get())) {
|
||||
// The profile is about to change.
|
||||
|
||||
// Dump current permission. This will be done by calling
|
||||
// PERMISSION_RemoveAll which clears the memory-resident
|
||||
// permission table. The reason the permission file does not
|
||||
// need to be updated is because the file was updated every time
|
||||
// the memory-resident table changed (i.e., whenever a new permission
|
||||
// was accepted). If this condition ever changes, the permission
|
||||
// file would need to be updated here.
|
||||
|
||||
PERMISSION_RemoveAll();
|
||||
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get()))
|
||||
PERMISSION_DeletePersistentUserData();
|
||||
}
|
||||
else if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-do-change").get())) {
|
||||
// The profile has aleady changed.
|
||||
// Now just read them from the new profile location.
|
||||
PERMISSION_Read();
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
48
extensions/cookie/nsPermissionManager.h
Normal file
48
extensions/cookie/nsPermissionManager.h
Normal file
@ -0,0 +1,48 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsPermissionManager_h__
|
||||
#define nsPermissionManager_h__
|
||||
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsPermissionManager : public nsIPermissionManager,
|
||||
public nsIObserver,
|
||||
public nsSupportsWeakReference {
|
||||
public:
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPERMISSIONMANAGER
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
nsPermissionManager();
|
||||
virtual ~nsPermissionManager(void);
|
||||
nsresult Init();
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsPermissionManager_h__ */
|
697
extensions/cookie/nsPermissions.cpp
Normal file
697
extensions/cookie/nsPermissions.cpp
Normal file
@ -0,0 +1,697 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
* Henrik Gemal <gemal@gemal.dk>
|
||||
*/
|
||||
|
||||
#define alphabetize 1
|
||||
|
||||
#include "nsPermissions.h"
|
||||
#include "nsUtils.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsINetSupportDialogService.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "xp_core.h"
|
||||
#include "prmem.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
|
||||
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
||||
static const char *kCookiesPermFileName = "cookperm.txt";
|
||||
|
||||
typedef struct _permission_HostStruct {
|
||||
char * host;
|
||||
nsVoidArray * permissionList;
|
||||
} permission_HostStruct;
|
||||
|
||||
typedef struct _permission_TypeStruct {
|
||||
PRInt32 type;
|
||||
PRBool permission;
|
||||
} permission_TypeStruct;
|
||||
|
||||
PRIVATE PRBool permission_changed = PR_FALSE;
|
||||
|
||||
PRIVATE PRBool cookie_rememberChecked;
|
||||
PRIVATE PRBool image_rememberChecked;
|
||||
|
||||
PRIVATE nsVoidArray * permission_list=0;
|
||||
|
||||
PRBool
|
||||
permission_CheckConfirmYN(nsIPrompt *aPrompter, PRUnichar * szMessage, PRUnichar * szCheckMessage, PRBool* checkValue) {
|
||||
|
||||
nsresult res;
|
||||
nsCOMPtr<nsIPrompt> dialog;
|
||||
|
||||
if (aPrompter)
|
||||
dialog = aPrompter;
|
||||
else
|
||||
dialog = do_GetService(kNetSupportDialogCID);
|
||||
if (!dialog) {
|
||||
*checkValue = 0;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRInt32 buttonPressed = 1; /* in case user exits dialog by clickin X */
|
||||
PRUnichar * yes_string = CKutil_Localize(NS_LITERAL_STRING("Yes").get());
|
||||
PRUnichar * no_string = CKutil_Localize(NS_LITERAL_STRING("No").get());
|
||||
PRUnichar * confirm_string = CKutil_Localize(NS_LITERAL_STRING("Confirm").get());
|
||||
|
||||
nsAutoString tempStr; tempStr.AssignWithConversion("chrome://global/skin/question-icon.gif");
|
||||
res = dialog->UniversalDialog(
|
||||
NULL, /* title message */
|
||||
confirm_string, /* title text in top line of window */
|
||||
szMessage, /* this is the main message */
|
||||
szCheckMessage, /* This is the checkbox message */
|
||||
yes_string, /* first button text */
|
||||
no_string, /* second button text */
|
||||
NULL, /* third button text */
|
||||
NULL, /* fourth button text */
|
||||
NULL, /* first edit field label */
|
||||
NULL, /* second edit field label */
|
||||
NULL, /* first edit field initial and final value */
|
||||
NULL, /* second edit field initial and final value */
|
||||
tempStr.GetUnicode() ,
|
||||
checkValue, /* initial and final value of checkbox */
|
||||
2, /* number of buttons */
|
||||
0, /* number of edit fields */
|
||||
0, /* is first edit field a password field */
|
||||
&buttonPressed);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
*checkValue = 0;
|
||||
}
|
||||
if (*checkValue!=0 && *checkValue!=1) {
|
||||
*checkValue = 0; /* this should never happen but it is happening!!! */
|
||||
}
|
||||
Recycle(yes_string);
|
||||
Recycle(no_string);
|
||||
Recycle(confirm_string);
|
||||
return (buttonPressed == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* search if permission already exists
|
||||
*/
|
||||
nsresult
|
||||
permission_CheckFromList(const char * hostname, PRBool &permission, PRInt32 type) {
|
||||
permission_HostStruct * hostStruct;
|
||||
permission_TypeStruct * typeStruct;
|
||||
|
||||
/* ignore leading period in host name */
|
||||
while (hostname && (*hostname == '.')) {
|
||||
hostname++;
|
||||
}
|
||||
|
||||
/* return if permission_list does not exist */
|
||||
if (permission_list == nsnull) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/* find host name within list */
|
||||
PRInt32 hostCount = permission_list->Count();
|
||||
for (PRInt32 i = 0; i < hostCount; ++i) {
|
||||
hostStruct = NS_STATIC_CAST(permission_HostStruct*, permission_list->ElementAt(i));
|
||||
if (hostStruct) {
|
||||
if(hostname && hostStruct->host && !PL_strcasecmp(hostname, hostStruct->host)) {
|
||||
|
||||
/* search for type in the permission list for this host */
|
||||
PRInt32 typeCount = hostStruct->permissionList->Count();
|
||||
for (PRInt32 typeIndex=0; typeIndex<typeCount; typeIndex++) {
|
||||
typeStruct = NS_STATIC_CAST
|
||||
(permission_TypeStruct*, hostStruct->permissionList->ElementAt(typeIndex));
|
||||
if (typeStruct->type == type) {
|
||||
|
||||
/* type found. Obtain the corresponding permission */
|
||||
permission = typeStruct->permission;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* type not found, return failure */
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* not found, return failure */
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
permission_GetRememberChecked(PRInt32 type) {
|
||||
if (type == COOKIEPERMISSION) {
|
||||
return cookie_rememberChecked;
|
||||
} else if (type == IMAGEPERMISSION) {
|
||||
return image_rememberChecked;
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
permission_SetRememberChecked(PRInt32 type, PRBool value) {
|
||||
if (type == COOKIEPERMISSION) {
|
||||
cookie_rememberChecked = value;
|
||||
} else if (type == IMAGEPERMISSION) {
|
||||
image_rememberChecked = value;
|
||||
}
|
||||
}
|
||||
|
||||
PUBLIC PRBool
|
||||
Permission_Check(
|
||||
nsIPrompt *aPrompter,
|
||||
const char * hostname,
|
||||
PRInt32 type,
|
||||
PRBool warningPref,
|
||||
PRUnichar * message)
|
||||
{
|
||||
PRBool permission;
|
||||
|
||||
/* try to make decision based on saved permissions */
|
||||
if (NS_SUCCEEDED(permission_CheckFromList(hostname, permission, type))) {
|
||||
return permission;
|
||||
}
|
||||
|
||||
/* see if we need to prompt */
|
||||
if(!warningPref) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/* we need to prompt */
|
||||
PRBool rememberChecked = permission_GetRememberChecked(type);
|
||||
PRUnichar * remember_string = CKutil_Localize(NS_LITERAL_STRING("RememberThisDecision").get());
|
||||
permission = permission_CheckConfirmYN(aPrompter, message, remember_string, &rememberChecked);
|
||||
|
||||
/* see if we need to remember this decision */
|
||||
if (rememberChecked) {
|
||||
char * hostname2 = NULL;
|
||||
/* ignore leading periods in host name */
|
||||
const char * hostnameAfterDot = hostname;
|
||||
while (hostnameAfterDot && (*hostnameAfterDot == '.')) {
|
||||
hostnameAfterDot++;
|
||||
}
|
||||
CKutil_StrAllocCopy(hostname2, hostnameAfterDot);
|
||||
Permission_AddHost(hostname2, permission, type, PR_TRUE);
|
||||
}
|
||||
if (rememberChecked != permission_GetRememberChecked(type)) {
|
||||
permission_SetRememberChecked(type, rememberChecked);
|
||||
permission_changed = PR_TRUE;
|
||||
Permission_Save();
|
||||
}
|
||||
return permission;
|
||||
}
|
||||
|
||||
PUBLIC nsresult
|
||||
Permission_AddHost(char * host, PRBool permission, PRInt32 type, PRBool save) {
|
||||
/* create permission list if it does not yet exist */
|
||||
if(!permission_list) {
|
||||
permission_list = new nsVoidArray();
|
||||
if(!permission_list) {
|
||||
Recycle(host);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/* find existing entry for host */
|
||||
permission_HostStruct * hostStruct;
|
||||
PRBool HostFound = PR_FALSE;
|
||||
PRInt32 hostCount = permission_list->Count();
|
||||
PRInt32 i;
|
||||
for (i = 0; i < hostCount; ++i) {
|
||||
hostStruct = NS_STATIC_CAST(permission_HostStruct*, permission_list->ElementAt(i));
|
||||
if (hostStruct) {
|
||||
if (PL_strcasecmp(host,hostStruct->host)==0) {
|
||||
|
||||
/* host found in list */
|
||||
Recycle(host);
|
||||
HostFound = PR_TRUE;
|
||||
break;
|
||||
#ifdef alphabetize
|
||||
} else if (PL_strcasecmp(host, hostStruct->host) < 0) {
|
||||
|
||||
/* need to insert new entry here */
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!HostFound) {
|
||||
|
||||
/* create a host structure for the host */
|
||||
hostStruct = PR_NEW(permission_HostStruct);
|
||||
if (!hostStruct) {
|
||||
Recycle(host);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
hostStruct->host = host;
|
||||
hostStruct->permissionList = new nsVoidArray();
|
||||
if(!hostStruct->permissionList) {
|
||||
PR_Free(hostStruct);
|
||||
Recycle(host);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/* insert host structure into the list */
|
||||
if (i == permission_list->Count()) {
|
||||
permission_list->AppendElement(hostStruct);
|
||||
} else {
|
||||
permission_list->InsertElementAt(hostStruct, i);
|
||||
}
|
||||
}
|
||||
|
||||
/* see if host already has an entry for this type */
|
||||
permission_TypeStruct * typeStruct;
|
||||
PRBool typeFound = PR_FALSE;
|
||||
PRInt32 typeCount = hostStruct->permissionList->Count();
|
||||
for (PRInt32 typeIndex=0; typeIndex<typeCount; 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) {
|
||||
permission_changed = PR_TRUE;
|
||||
Permission_Save();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
permission_Unblock(char * host, PRInt32 type) {
|
||||
|
||||
/* nothing to do if permission list does not exist */
|
||||
if(!permission_list) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* find existing entry for host */
|
||||
permission_HostStruct * hostStruct;
|
||||
PRInt32 hostCount = permission_list->Count();
|
||||
for (PRInt32 hostIndex = 0; hostIndex < hostCount; ++hostIndex) {
|
||||
hostStruct = NS_STATIC_CAST(permission_HostStruct*, permission_list->ElementAt(hostIndex));
|
||||
if (hostStruct && PL_strcasecmp(host, hostStruct->host)==0) {
|
||||
/* host found in list, see if it has an entry for this type */
|
||||
permission_TypeStruct * typeStruct;
|
||||
PRInt32 typeCount = hostStruct->permissionList->Count();
|
||||
for (PRInt32 typeIndex=0; typeIndex<typeCount; typeIndex++) {
|
||||
typeStruct = NS_STATIC_CAST
|
||||
(permission_TypeStruct*, hostStruct->permissionList->ElementAt(typeIndex));
|
||||
if (typeStruct && typeStruct->type == type) {
|
||||
/* type found. Remove the permission if it is PR_FALSE */
|
||||
if (typeStruct->permission == PR_FALSE) {
|
||||
hostStruct->permissionList->RemoveElementAt(typeIndex);
|
||||
/* if no more types are present, remove the entry */
|
||||
typeCount = hostStruct->permissionList->Count();
|
||||
if (typeCount == 0) {
|
||||
PR_FREEIF(hostStruct->permissionList);
|
||||
permission_list->RemoveElementAt(hostIndex);
|
||||
PR_FREEIF(hostStruct->host);
|
||||
PR_Free(hostStruct);
|
||||
}
|
||||
permission_changed = PR_TRUE;
|
||||
Permission_Save();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* saves the permissions to disk */
|
||||
PUBLIC void
|
||||
Permission_Save() {
|
||||
permission_HostStruct * hostStruct;
|
||||
permission_TypeStruct * typeStruct;
|
||||
|
||||
if (!permission_changed) {
|
||||
return;
|
||||
}
|
||||
if (permission_list == nsnull) {
|
||||
return;
|
||||
}
|
||||
nsFileSpec dirSpec;
|
||||
nsresult rval = CKutil_ProfileDirectory(dirSpec);
|
||||
if (NS_FAILED(rval)) {
|
||||
return;
|
||||
}
|
||||
nsOutputFileStream strm(dirSpec + kCookiesPermFileName);
|
||||
if (!strm.is_open()) {
|
||||
return;
|
||||
}
|
||||
|
||||
strm.write("# HTTP Permission File\n", 30);
|
||||
strm.write("# http://www.netscape.com/newsref/std/cookie_spec.html\n", 55);
|
||||
strm.write("# This is a generated file! Do not edit.\n\n", 43);
|
||||
|
||||
/* format shall be:
|
||||
* host \t permission \t permission ... \n
|
||||
*/
|
||||
|
||||
|
||||
PRInt32 hostCount = permission_list->Count();
|
||||
for (PRInt32 i = 0; i < hostCount; ++i) {
|
||||
hostStruct = NS_STATIC_CAST(permission_HostStruct*, permission_list->ElementAt(i));
|
||||
if (hostStruct) {
|
||||
strm.write(hostStruct->host, nsCRT::strlen(hostStruct->host));
|
||||
|
||||
PRInt32 typeCount = hostStruct->permissionList->Count();
|
||||
for (PRInt32 typeIndex=0; typeIndex<typeCount; typeIndex++) {
|
||||
typeStruct = NS_STATIC_CAST
|
||||
(permission_TypeStruct*, hostStruct->permissionList->ElementAt(typeIndex));
|
||||
strm.write("\t", 1);
|
||||
nsCAutoString tmp; tmp.AppendInt(typeStruct->type);
|
||||
strm.write(tmp.get(), tmp.Length());
|
||||
if (typeStruct->permission) {
|
||||
strm.write("T", 1);
|
||||
} else {
|
||||
strm.write("F", 1);
|
||||
}
|
||||
}
|
||||
strm.write("\n", 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* save current state of nag boxs' checkmarks */
|
||||
strm.write("@@@@", 4);
|
||||
for (PRInt32 type = 0; type < NUMBER_OF_PERMISSIONS; type++) {
|
||||
strm.write("\t", 1);
|
||||
nsCAutoString tmp; tmp.AppendInt(type);
|
||||
strm.write(tmp.get(), tmp.Length());
|
||||
if (permission_GetRememberChecked(type)) {
|
||||
strm.write("T", 1);
|
||||
} else {
|
||||
strm.write("F", 1);
|
||||
}
|
||||
}
|
||||
|
||||
strm.write("\n", 1);
|
||||
|
||||
permission_changed = PR_FALSE;
|
||||
strm.flush();
|
||||
strm.close();
|
||||
}
|
||||
|
||||
/* reads the permissions from disk */
|
||||
PUBLIC nsresult
|
||||
PERMISSION_Read() {
|
||||
if (permission_list) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsAutoString buffer;
|
||||
nsFileSpec dirSpec;
|
||||
nsresult rv = CKutil_ProfileDirectory(dirSpec);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
nsInputFileStream strm(dirSpec + kCookiesPermFileName);
|
||||
if (!strm.is_open()) {
|
||||
/* file doesn't exist -- that's not an error */
|
||||
for (PRInt32 type=0; type<NUMBER_OF_PERMISSIONS; type++) {
|
||||
permission_SetRememberChecked(type, PR_FALSE);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* format is:
|
||||
* host \t number permission \t number permission ... \n
|
||||
* if this format isn't respected we move onto the next line in the file.
|
||||
*/
|
||||
while(CKutil_GetLine(strm,buffer) != -1) {
|
||||
if ( !buffer.IsEmpty() ) {
|
||||
PRUnichar firstChar = buffer.CharAt(0);
|
||||
if (firstChar == '#' || firstChar == CR ||
|
||||
firstChar == LF || firstChar == 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int hostIndex, permissionIndex;
|
||||
PRUint32 nextPermissionIndex = 0;
|
||||
hostIndex = 0;
|
||||
|
||||
if ((permissionIndex=buffer.FindChar('\t', PR_FALSE, hostIndex)+1) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* ignore leading periods in host name */
|
||||
while (hostIndex < permissionIndex && (buffer.CharAt(hostIndex) == '.')) {
|
||||
hostIndex++;
|
||||
}
|
||||
|
||||
nsAutoString host;
|
||||
buffer.Mid(host, hostIndex, permissionIndex-hostIndex-1);
|
||||
|
||||
nsAutoString permissionString;
|
||||
for (;;) {
|
||||
if (nextPermissionIndex == buffer.Length()+1) {
|
||||
break;
|
||||
}
|
||||
if ((nextPermissionIndex=buffer.FindChar('\t', PR_FALSE, permissionIndex)+1) == 0) {
|
||||
nextPermissionIndex = buffer.Length()+1;
|
||||
}
|
||||
buffer.Mid(permissionString, permissionIndex, nextPermissionIndex-permissionIndex-1);
|
||||
permissionIndex = nextPermissionIndex;
|
||||
|
||||
PRInt32 type = 0;
|
||||
PRUint32 index = 0;
|
||||
|
||||
if (permissionString.IsEmpty()) {
|
||||
continue; /* empty permission entry -- should never happen */
|
||||
}
|
||||
char c = (char)permissionString.CharAt(index);
|
||||
while (index < permissionString.Length() && c >= '0' && c <= '9') {
|
||||
type = 10*type + (c-'0');
|
||||
c = (char)permissionString.CharAt(++index);
|
||||
}
|
||||
if (index >= permissionString.Length()) {
|
||||
continue; /* bad format for this permission entry */
|
||||
}
|
||||
PRBool permission = (permissionString.CharAt(index) == 'T');
|
||||
|
||||
/*
|
||||
* a host value of "@@@@" is a special code designating the
|
||||
* state of the nag-box's checkmark
|
||||
*/
|
||||
if (host.EqualsWithConversion("@@@@")) {
|
||||
if (!permissionString.IsEmpty()) {
|
||||
permission_SetRememberChecked(type, permission);
|
||||
}
|
||||
} else {
|
||||
if (!permissionString.IsEmpty()) {
|
||||
rv = Permission_AddHost(host.ToNewCString(), permission, type, PR_FALSE);
|
||||
if (NS_FAILED(rv)) {
|
||||
strm.close();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
strm.close();
|
||||
permission_changed = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PUBLIC PRInt32
|
||||
PERMISSION_HostCount() {
|
||||
if (!permission_list) {
|
||||
return 0;
|
||||
}
|
||||
return permission_list->Count();
|
||||
}
|
||||
|
||||
PUBLIC PRInt32
|
||||
PERMISSION_TypeCount(PRInt32 host) {
|
||||
if (!permission_list) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
permission_HostStruct *hostStruct;
|
||||
hostStruct = NS_STATIC_CAST(permission_HostStruct*, permission_list->ElementAt(host));
|
||||
NS_ASSERTION(hostStruct, "corrupt permission list");
|
||||
return hostStruct->permissionList->Count();
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
PERMISSION_Enumerate
|
||||
(PRInt32 hostNumber, PRInt32 typeNumber, char **host, PRInt32 *type, PRBool *capability) {
|
||||
permission_HostStruct *hostStruct;
|
||||
permission_TypeStruct * typeStruct;
|
||||
|
||||
hostStruct = NS_STATIC_CAST(permission_HostStruct*, permission_list->ElementAt(hostNumber));
|
||||
NS_ASSERTION(hostStruct, "corrupt permission list");
|
||||
char * copyOfHost = NULL;
|
||||
CKutil_StrAllocCopy(copyOfHost, hostStruct->host);
|
||||
*host = copyOfHost;
|
||||
|
||||
typeStruct = NS_STATIC_CAST
|
||||
(permission_TypeStruct*, hostStruct->permissionList->ElementAt(typeNumber));
|
||||
*capability = typeStruct->permission;
|
||||
*type = typeStruct->type;
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
permission_remove (PRInt32 hostNumber, PRInt32 type) {
|
||||
if (!permission_list) {
|
||||
return;
|
||||
}
|
||||
permission_HostStruct * hostStruct;
|
||||
hostStruct =
|
||||
NS_STATIC_CAST(permission_HostStruct*, permission_list->ElementAt(hostNumber));
|
||||
if (!hostStruct) {
|
||||
return;
|
||||
}
|
||||
permission_TypeStruct * typeStruct;
|
||||
typeStruct =
|
||||
NS_STATIC_CAST(permission_TypeStruct*, hostStruct->permissionList->ElementAt(type));
|
||||
if (!typeStruct) {
|
||||
return;
|
||||
}
|
||||
hostStruct->permissionList->RemoveElementAt(type);
|
||||
permission_changed = PR_TRUE;
|
||||
|
||||
/* if no types are present, remove the entry */
|
||||
PRInt32 typeCount = hostStruct->permissionList->Count();
|
||||
if (typeCount == 0) {
|
||||
PR_FREEIF(hostStruct->permissionList);
|
||||
permission_list->RemoveElementAt(hostNumber);
|
||||
PR_FREEIF(hostStruct->host);
|
||||
PR_Free(hostStruct);
|
||||
}
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
PERMISSION_Remove(const char* host, PRInt32 type) {
|
||||
|
||||
/* get to the indicated host in the list */
|
||||
if (permission_list) {
|
||||
PRInt32 hostCount = permission_list->Count();
|
||||
permission_HostStruct * hostStruct;
|
||||
while (hostCount>0) {
|
||||
hostCount--;
|
||||
hostStruct =
|
||||
NS_STATIC_CAST(permission_HostStruct*, permission_list->ElementAt(hostCount));
|
||||
NS_ASSERTION(hostStruct, "corrupt permission list");
|
||||
if ((PL_strcmp(hostStruct->host, host) == 0)) {
|
||||
|
||||
/* get to the indicated permission in the list */
|
||||
PRInt32 typeCount = hostStruct->permissionList->Count();
|
||||
permission_TypeStruct * typeStruct;
|
||||
while (typeCount>0) {
|
||||
typeCount--;
|
||||
typeStruct =
|
||||
NS_STATIC_CAST
|
||||
(permission_TypeStruct*, hostStruct->permissionList->ElementAt(typeCount));
|
||||
NS_ASSERTION(typeStruct, "corrupt permission list");
|
||||
if (typeStruct->type == type) {
|
||||
permission_remove(hostCount, typeCount);
|
||||
permission_changed = PR_TRUE;
|
||||
Permission_Save();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* blows away all permissions currently in the list */
|
||||
PUBLIC void
|
||||
PERMISSION_RemoveAll() {
|
||||
|
||||
if (permission_list) {
|
||||
permission_HostStruct * hostStruct;
|
||||
PRInt32 hostCount = permission_list->Count();
|
||||
for (PRInt32 i = hostCount-1; i >=0; i--) {
|
||||
hostStruct = NS_STATIC_CAST(permission_HostStruct*, permission_list->ElementAt(i));
|
||||
PRInt32 typeCount = hostStruct->permissionList->Count();
|
||||
for (PRInt32 typeIndex = typeCount-1; typeIndex >=0; typeIndex--) {
|
||||
permission_remove(hostCount, typeCount);
|
||||
}
|
||||
}
|
||||
delete permission_list;
|
||||
permission_list = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
PERMISSION_DeletePersistentUserData(void)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
nsCOMPtr<nsIFile> cookiesPermFile;
|
||||
res = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(cookiesPermFile));
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = cookiesPermFile->Append(kCookiesPermFileName);
|
||||
if (NS_SUCCEEDED(res))
|
||||
(void) cookiesPermFile->Delete(PR_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
PERMISSION_Add(const char * objectURL, PRBool permission, PRInt32 type) {
|
||||
if (!objectURL) {
|
||||
return;
|
||||
}
|
||||
char *host = CKutil_ParseURL(objectURL, GET_HOST_PART);
|
||||
|
||||
/*
|
||||
* if permission is false, it will be added to the permission list
|
||||
* if permission is true, any false permissions will be removed rather than a
|
||||
* true permission being added
|
||||
*/
|
||||
if (permission) {
|
||||
char * hostPtr = host;
|
||||
while (PR_TRUE) {
|
||||
permission_Unblock(hostPtr, type);
|
||||
hostPtr = PL_strchr(hostPtr, '.');
|
||||
if (!hostPtr) {
|
||||
break;
|
||||
}
|
||||
hostPtr++; /* get passed the period */
|
||||
}
|
||||
Recycle(host);
|
||||
return;
|
||||
}
|
||||
Permission_AddHost(host, permission, type, PR_TRUE);
|
||||
}
|
59
extensions/cookie/nsPermissions.h
Normal file
59
extensions/cookie/nsPermissions.h
Normal file
@ -0,0 +1,59 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef PERMISSIONS_H
|
||||
#define PERMISSIONS_H
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
#define COOKIEPERMISSION 0
|
||||
#define IMAGEPERMISSION 1
|
||||
#define NUMBER_OF_PERMISSIONS 2
|
||||
|
||||
typedef enum {
|
||||
PERMISSION_Accept,
|
||||
PERMISSION_DontAcceptForeign,
|
||||
PERMISSION_DontUse
|
||||
} PERMISSION_BehaviorEnum;
|
||||
|
||||
class nsIPrompt;
|
||||
|
||||
extern nsresult PERMISSION_Read();
|
||||
extern void PERMISSION_Add(const char * objectURL, PRBool permission, PRInt32 type);
|
||||
extern void PERMISSION_RemoveAll();
|
||||
extern void PERMISSION_DeletePersistentUserData(void);
|
||||
|
||||
extern PRInt32 PERMISSION_HostCount();
|
||||
extern PRInt32 PERMISSION_TypeCount(PRInt32 host);
|
||||
extern void PERMISSION_Enumerate
|
||||
(PRInt32 hostNumber, PRInt32 typeNumber, char **host, PRInt32 *type, PRBool *capability);
|
||||
extern void PERMISSION_Remove(const char* host, PRInt32 type);
|
||||
|
||||
extern PRBool Permission_Check
|
||||
(nsIPrompt *aPrompter, const char * hostname, PRInt32 type,
|
||||
PRBool warningPref, PRUnichar * message);
|
||||
extern nsresult Permission_AddHost
|
||||
(char * host, PRBool permission, PRInt32 type, PRBool save);
|
||||
//extern void Permission_Free(PRInt32 hostNumber, PRInt32 type, PRBool save);
|
||||
extern void Permission_Save();
|
||||
|
||||
#endif /* PERMISSIONS_H */
|
331
extensions/cookie/nsUtils.cpp
Normal file
331
extensions/cookie/nsUtils.cpp
Normal file
@ -0,0 +1,331 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsUtils.h"
|
||||
#include "xp_core.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "prmem.h"
|
||||
|
||||
static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
|
||||
#define MAX_HOST_NAME_LEN 64
|
||||
#define BUFSIZE 128
|
||||
#define LOCALIZATION "chrome://communicator/locale/wallet/cookie.properties"
|
||||
|
||||
nsresult
|
||||
ckutil_getChar(nsInputFileStream& strm, char& c) {
|
||||
static char buffer[BUFSIZE];
|
||||
static PRInt32 next = BUFSIZE, count = BUFSIZE;
|
||||
|
||||
if (next == count) {
|
||||
if (BUFSIZE > count) { // never say "count < ..." vc6.0 thinks this is a template beginning and crashes
|
||||
next = BUFSIZE;
|
||||
count = BUFSIZE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
count = strm.read(buffer, BUFSIZE);
|
||||
next = 0;
|
||||
if (count == 0) {
|
||||
next = BUFSIZE;
|
||||
count = BUFSIZE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
c = buffer[next++];
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* get a line from a file
|
||||
* return -1 if end of file reached
|
||||
* strip carriage returns and line feeds from end of line
|
||||
*/
|
||||
PUBLIC PRInt32
|
||||
CKutil_GetLine(nsInputFileStream& strm, nsString& aLine) {
|
||||
|
||||
/* read the line */
|
||||
aLine.Truncate();
|
||||
char c;
|
||||
for (;;) {
|
||||
if NS_FAILED(ckutil_getChar(strm, c)) {
|
||||
return -1;
|
||||
}
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (c != '\r') {
|
||||
aLine.AppendWithConversion(c);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PUBLIC char *
|
||||
CKutil_ParseURL (const char *url, int parts_requested) {
|
||||
char *rv=0,*colon, *slash, *ques_mark, *hash_mark;
|
||||
char *atSign, *host, *passwordColon, *gtThan;
|
||||
assert(url);
|
||||
if(!url) {
|
||||
return(CKutil_StrAllocCat(rv, ""));
|
||||
}
|
||||
colon = PL_strchr(url, ':'); /* returns a const char */
|
||||
/* Get the protocol part, not including anything beyond the colon */
|
||||
if (parts_requested & GET_PROTOCOL_PART) {
|
||||
if(colon) {
|
||||
char val = *(colon+1);
|
||||
*(colon+1) = '\0';
|
||||
CKutil_StrAllocCopy(rv, url);
|
||||
*(colon+1) = val;
|
||||
/* If the user wants more url info, tack on extra slashes. */
|
||||
if( (parts_requested & GET_HOST_PART)
|
||||
|| (parts_requested & GET_USERNAME_PART)
|
||||
|| (parts_requested & GET_PASSWORD_PART)) {
|
||||
if( *(colon+1) == '/' && *(colon+2) == '/') {
|
||||
CKutil_StrAllocCat(rv, "//");
|
||||
}
|
||||
/* If there's a third slash consider it file:/// and tack on the last slash. */
|
||||
if( *(colon+3) == '/' ) {
|
||||
CKutil_StrAllocCat(rv, "/");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the username if one exists */
|
||||
if (parts_requested & GET_USERNAME_PART) {
|
||||
if (colon && (*(colon+1) == '/') && (*(colon+2) == '/') && (*(colon+3) != '\0')) {
|
||||
if ( (slash = PL_strchr(colon+3, '/')) != NULL) {
|
||||
*slash = '\0';
|
||||
}
|
||||
if ( (atSign = PL_strchr(colon+3, '@')) != NULL) {
|
||||
*atSign = '\0';
|
||||
if ( (passwordColon = PL_strchr(colon+3, ':')) != NULL) {
|
||||
*passwordColon = '\0';
|
||||
}
|
||||
CKutil_StrAllocCat(rv, colon+3);
|
||||
|
||||
/* Get the password if one exists */
|
||||
if (parts_requested & GET_PASSWORD_PART) {
|
||||
if (passwordColon) {
|
||||
CKutil_StrAllocCat(rv, ":");
|
||||
CKutil_StrAllocCat(rv, passwordColon+1);
|
||||
}
|
||||
}
|
||||
if (parts_requested & GET_HOST_PART) {
|
||||
CKutil_StrAllocCat(rv, "@");
|
||||
}
|
||||
if (passwordColon) {
|
||||
*passwordColon = ':';
|
||||
}
|
||||
*atSign = '@';
|
||||
}
|
||||
if (slash) {
|
||||
*slash = '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the host part */
|
||||
if (parts_requested & GET_HOST_PART) {
|
||||
if(colon) {
|
||||
if(*(colon+1) == '/' && *(colon+2) == '/') {
|
||||
slash = PL_strchr(colon+3, '/');
|
||||
if(slash) {
|
||||
*slash = '\0';
|
||||
}
|
||||
if( (atSign = PL_strchr(colon+3, '@')) != NULL) {
|
||||
host = atSign+1;
|
||||
} else {
|
||||
host = colon+3;
|
||||
}
|
||||
ques_mark = PL_strchr(host, '?');
|
||||
if(ques_mark) {
|
||||
*ques_mark = '\0';
|
||||
}
|
||||
gtThan = PL_strchr(host, '>');
|
||||
if (gtThan) {
|
||||
*gtThan = '\0';
|
||||
}
|
||||
|
||||
/* limit hostnames to within MAX_HOST_NAME_LEN characters to keep from crashing */
|
||||
if(PL_strlen(host) > MAX_HOST_NAME_LEN) {
|
||||
char * cp;
|
||||
char old_char;
|
||||
cp = host+MAX_HOST_NAME_LEN;
|
||||
old_char = *cp;
|
||||
*cp = '\0';
|
||||
CKutil_StrAllocCat(rv, host);
|
||||
*cp = old_char;
|
||||
} else {
|
||||
CKutil_StrAllocCat(rv, host);
|
||||
}
|
||||
if(slash) {
|
||||
*slash = '/';
|
||||
}
|
||||
if(ques_mark) {
|
||||
*ques_mark = '?';
|
||||
}
|
||||
if (gtThan) {
|
||||
*gtThan = '>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the path part */
|
||||
if (parts_requested & GET_PATH_PART) {
|
||||
if(colon) {
|
||||
if(*(colon+1) == '/' && *(colon+2) == '/') {
|
||||
/* skip host part */
|
||||
slash = PL_strchr(colon+3, '/');
|
||||
} else {
|
||||
/* path is right after the colon */
|
||||
slash = colon+1;
|
||||
}
|
||||
if(slash) {
|
||||
ques_mark = PL_strchr(slash, '?');
|
||||
hash_mark = PL_strchr(slash, '#');
|
||||
if(ques_mark) {
|
||||
*ques_mark = '\0';
|
||||
}
|
||||
if(hash_mark) {
|
||||
*hash_mark = '\0';
|
||||
}
|
||||
CKutil_StrAllocCat(rv, slash);
|
||||
if(ques_mark) {
|
||||
*ques_mark = '?';
|
||||
}
|
||||
if(hash_mark) {
|
||||
*hash_mark = '#';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(parts_requested & GET_HASH_PART) {
|
||||
hash_mark = PL_strchr(url, '#'); /* returns a const char * */
|
||||
if(hash_mark) {
|
||||
ques_mark = PL_strchr(hash_mark, '?');
|
||||
if(ques_mark) {
|
||||
*ques_mark = '\0';
|
||||
}
|
||||
CKutil_StrAllocCat(rv, hash_mark);
|
||||
if(ques_mark) {
|
||||
*ques_mark = '?';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(parts_requested & GET_SEARCH_PART) {
|
||||
ques_mark = PL_strchr(url, '?'); /* returns a const char * */
|
||||
if(ques_mark) {
|
||||
hash_mark = PL_strchr(ques_mark, '#');
|
||||
if(hash_mark) {
|
||||
*hash_mark = '\0';
|
||||
}
|
||||
CKutil_StrAllocCat(rv, ques_mark);
|
||||
if(hash_mark) {
|
||||
*hash_mark = '#';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* copy in a null string if nothing was copied in */
|
||||
if(!rv) {
|
||||
CKutil_StrAllocCopy(rv, "");
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRUnichar *
|
||||
CKutil_Localize(const PRUnichar *genericString) {
|
||||
nsresult ret;
|
||||
PRUnichar *ptrv = nsnull;
|
||||
NS_WITH_SERVICE(nsIStringBundleService, pStringService, kStringBundleServiceCID, &ret);
|
||||
if (NS_SUCCEEDED(ret) && (nsnull != pStringService)) {
|
||||
nsCOMPtr<nsILocale> locale;
|
||||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
ret = pStringService->CreateBundle(LOCALIZATION, locale, getter_AddRefs(bundle));
|
||||
if (NS_SUCCEEDED(ret) && bundle) {
|
||||
ret = bundle->GetStringFromName(genericString, &ptrv);
|
||||
if ( NS_SUCCEEDED(ret) && (ptrv) ) {
|
||||
return ptrv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nsCRT::strdup(genericString);
|
||||
}
|
||||
|
||||
PUBLIC nsresult
|
||||
CKutil_ProfileDirectory(nsFileSpec& dirSpec) {
|
||||
nsresult res;
|
||||
nsCOMPtr<nsIFile> aFile;
|
||||
nsCOMPtr<nsIFileSpec> tempSpec;
|
||||
|
||||
res = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(aFile));
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
// TODO: When the calling code can take an nsIFile,
|
||||
// this conversion to nsFileSpec can be avoided.
|
||||
nsXPIDLCString pathBuf;
|
||||
aFile->GetPath(getter_Copies(pathBuf));
|
||||
res = NS_NewFileSpec(getter_AddRefs(tempSpec));
|
||||
if (NS_FAILED(res)) return res;
|
||||
res = tempSpec->SetNativePath(pathBuf);
|
||||
if (NS_FAILED(res)) return res;
|
||||
res = tempSpec->GetFileSpec(&dirSpec);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
PUBLIC char *
|
||||
CKutil_StrAllocCopy(char *&destination, const char *source) {
|
||||
if(destination) {
|
||||
PL_strfree(destination);
|
||||
destination = 0;
|
||||
}
|
||||
destination = PL_strdup(source);
|
||||
return destination;
|
||||
}
|
||||
|
||||
PUBLIC char *
|
||||
CKutil_StrAllocCat(char *&destination, const char *source) {
|
||||
if (source && *source) {
|
||||
if (destination) {
|
||||
int length = PL_strlen (destination);
|
||||
destination = (char *) PR_Realloc(destination, length + PL_strlen(source) + 1);
|
||||
if (destination == NULL) {
|
||||
return(NULL);
|
||||
}
|
||||
PL_strcpy (destination + length, source);
|
||||
} else {
|
||||
destination = PL_strdup(source);
|
||||
}
|
||||
}
|
||||
return destination;
|
||||
}
|
45
extensions/cookie/nsUtils.h
Normal file
45
extensions/cookie/nsUtils.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsFileStream.h"
|
||||
|
||||
//#define GET_ALL_PARTS 127
|
||||
#define GET_PASSWORD_PART 64
|
||||
#define GET_USERNAME_PART 32
|
||||
#define GET_PROTOCOL_PART 16
|
||||
#define GET_HOST_PART 8
|
||||
#define GET_PATH_PART 4
|
||||
#define GET_HASH_PART 2
|
||||
#define GET_SEARCH_PART 1
|
||||
|
||||
extern PRInt32 CKutil_GetLine(nsInputFileStream& strm, nsString& aLine);
|
||||
extern char * CKutil_ParseURL (const char *url, int parts_requested);
|
||||
extern PRUnichar* CKutil_Localize(const PRUnichar *genericString);
|
||||
extern nsresult CKutil_ProfileDirectory(nsFileSpec& dirSpec);
|
||||
extern char * CKutil_StrAllocCopy(char *&destination, const char *source);
|
||||
extern char * CKutil_StrAllocCat(char *&destination, const char *source);
|
||||
|
||||
#endif /* UTILS_H */
|
@ -54,33 +54,39 @@
|
||||
}
|
||||
|
||||
/* determine if image is already being blocked */
|
||||
var cookieViewer = contextMenu.createInstance
|
||||
("@mozilla.org/cookieviewer/cookieviewer-world;1", "nsICookieViewer");
|
||||
var list = cookieViewer.GetPermissionValue(1);
|
||||
var permissionList = list.split(list[0]);
|
||||
for(var i = 1; i < permissionList.length; i+=2) {
|
||||
var permStr = permissionList[i+1];
|
||||
var type = permStr.substring(0,1);
|
||||
if (type == "-") {
|
||||
/* some host is being blocked, need to find out if it's our image's host */
|
||||
var host = permStr.substring(1,permStr.length);
|
||||
var permissionmanager =
|
||||
Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService().QueryInterface(Components.interfaces.nsIPermissionManager);
|
||||
|
||||
|
||||
var enumerator = permissionmanager.enumerator;
|
||||
while (enumerator.hasMoreElements()) {
|
||||
var nextPermission = enumerator.getNext();
|
||||
nextPermission = nextPermission.QueryInterface(Components.interfaces.nsIPermission);
|
||||
var imageType = 1;
|
||||
if (nextPermission.type == imageType &&
|
||||
!nextPermission.capability) {
|
||||
/* some image host is being blocked, need to find out if it's our image's host */
|
||||
var host = nextPermission.host;
|
||||
if(host.charAt(0) == ".") { // get rid of the ugly dot on the start of some domains
|
||||
host = host.substring(1,host.length);
|
||||
}
|
||||
if (host && contextMenu.imageURL.search(host) != -1) {
|
||||
/* it's our image's host that's being blocked */
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* image is not already being blocked, so "Block Image" can appear on the menu */
|
||||
return true;
|
||||
},
|
||||
|
||||
// Block image from loading in the future.
|
||||
blockImage : function () {
|
||||
var cookieViewer =
|
||||
contextMenu.createInstance("@mozilla.org/cookieviewer/cookieviewer-world;1",
|
||||
"nsICookieViewer" );
|
||||
cookieViewer.BlockImage(contextMenu.imageURL);
|
||||
var imgmanager =
|
||||
Components.classes["@mozilla.org/imgmanager;1"]
|
||||
.getService().QueryInterface(Components.interfaces.nsIImgManager);
|
||||
imgmanager.block(contextMenu.imageURL);
|
||||
},
|
||||
|
||||
initImageBlocking : function () {
|
||||
|
@ -40,16 +40,26 @@
|
||||
element.setAttribute("disabled","true" );
|
||||
}
|
||||
|
||||
// for some unexplainable reason, CheckForImage() keeps getting called repeatedly
|
||||
// as we mouse over the task menu. IMO, that shouldn't be happening. To avoid
|
||||
// taking a performance hit due to this, we will set the following flag to avoid
|
||||
// reexecuting the routine
|
||||
var alreadyCheckedForImage = false;
|
||||
|
||||
// determine if we need to remove the image entries from the task menu
|
||||
function CheckForImage()
|
||||
{
|
||||
if (alreadyCheckedForImage) {
|
||||
return;
|
||||
}
|
||||
alreadyCheckedForImage = true;
|
||||
// remove image functions (unless overruled by the "imageblocker.enabled" pref)
|
||||
try {
|
||||
if (!this.pref.GetBoolPref("imageblocker.enabled")) {
|
||||
HideImage();
|
||||
}
|
||||
} catch(e) {
|
||||
HideImage();
|
||||
HideImage();
|
||||
dump("imageblocker.enabled pref is missing from all.js\n");
|
||||
}
|
||||
}
|
||||
@ -57,31 +67,33 @@
|
||||
// perform a Cookie or Image action
|
||||
function CookieImageAction(action) {
|
||||
|
||||
var cookieViewer =
|
||||
Components.classes["@mozilla.org/cookieviewer/cookieviewer-world;1"]
|
||||
.createInstance(Components.interfaces["nsICookieViewer"]);
|
||||
|
||||
var permissionmanager =
|
||||
Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService().QueryInterface(Components.interfaces.nsIPermissionManager);
|
||||
if (!permissionmanager) {
|
||||
return;
|
||||
}
|
||||
var COOKIEPERMISSION = 0;
|
||||
var IMAGEPERMISSION = 1;
|
||||
|
||||
var element;
|
||||
switch (action) {
|
||||
case "cookieAllow":
|
||||
cookieViewer.AddPermission(window._content, true, COOKIEPERMISSION);
|
||||
permissionmanager.add(window._content.location, true, COOKIEPERMISSION);
|
||||
element = document.getElementById("AllowCookies");
|
||||
alert(element.getAttribute("msg"));
|
||||
break;
|
||||
case "cookieBlock":
|
||||
cookieViewer.AddPermission(window._content, false, COOKIEPERMISSION);
|
||||
permissionmanager.add(window._content.location, false, COOKIEPERMISSION);
|
||||
element = document.getElementById("BlockCookies");
|
||||
alert(element.getAttribute("msg"));
|
||||
break;
|
||||
case "imageAllow":
|
||||
cookieViewer.AddPermission(window._content, true, IMAGEPERMISSION);
|
||||
permissionmanager.add(window._content.location, true, IMAGEPERMISSION);
|
||||
element = document.getElementById("AllowImages");
|
||||
alert(element.getAttribute("msg"));
|
||||
break;
|
||||
case "imageBlock":
|
||||
cookieViewer.AddPermission(window._content, false, IMAGEPERMISSION);
|
||||
permissionmanager.add(window._content.location, false, IMAGEPERMISSION);
|
||||
element = document.getElementById("BlockImages");
|
||||
alert(element.getAttribute("msg"));
|
||||
break;
|
||||
@ -93,7 +105,9 @@
|
||||
</script>
|
||||
|
||||
<!-- tasksOverlay menu items -->
|
||||
<menupopup id="personalManagers">
|
||||
<menupopup id="taskPopup" oncreate="CheckForImage()"/>
|
||||
|
||||
<menupopup id="personalManagers">
|
||||
<menu label="&cookieCookieManager.label;"
|
||||
accesskey="&cookieCookieManager.accesskey;"
|
||||
position="1">
|
||||
@ -112,9 +126,10 @@
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menu label="&cookieImageManager.label;"
|
||||
accesskey="&cookieImageManager.accesskey;" id="image"
|
||||
accesskey="&cookieImageManager.accesskey;"
|
||||
id="image"
|
||||
position="2">
|
||||
<menupopup oncreate="CheckForImage()">
|
||||
<menupopup>
|
||||
<menuitem label="&cookieDisplayImagesCmd.label;"
|
||||
accesskey="&cookieDisplayImagesCmd.accesskey;"
|
||||
oncommand="viewImages();"/>
|
||||
|
@ -40,10 +40,8 @@ void SetACookie(nsICookieService *cookieService, const char* aSpec, const char*
|
||||
(void)NS_NewURI(getter_AddRefs(uri), aSpec);
|
||||
NS_ASSERTION(uri, "malformed uri");
|
||||
|
||||
nsString cookie;
|
||||
cookie.AssignWithConversion(aCookieString);
|
||||
printf("setting cookie for \"%s\" : ", aSpec);
|
||||
nsresult rv = cookieService->SetCookieString(uri, nsnull, cookie);
|
||||
nsresult rv = cookieService->SetCookieString(uri, nsnull, (char *)aCookieString);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("NOT-SET\n");
|
||||
} else {
|
||||
@ -57,16 +55,15 @@ void GetACookie(nsICookieService *cookieService, const char* aSpec, char* *aCook
|
||||
(void)NS_NewURI(getter_AddRefs(uri), aSpec);
|
||||
NS_ASSERTION(uri, "malformed uri");
|
||||
|
||||
nsString cookie;
|
||||
char * cookieString;
|
||||
printf("retrieving cookie(s) for \"%s\" : ", aSpec);
|
||||
nsresult rv = cookieService->GetCookieString(uri, cookie);
|
||||
nsresult rv = cookieService->GetCookieString(uri, &cookieString);
|
||||
if (NS_FAILED(rv)) printf("XXX GetCookieString() failed!\n");
|
||||
|
||||
if (cookie.IsEmpty()) {
|
||||
if (!cookieString) {
|
||||
printf("NOT-FOUND\n");
|
||||
} else {
|
||||
printf("FOUND: ");
|
||||
char *cookieString = cookie.ToNewCString();
|
||||
printf("%s\n", cookieString);
|
||||
nsCRT::free(cookieString);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src editor signonviewer cookieviewer walletpreview build
|
||||
DIRS = public src editor signonviewer walletpreview build
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
@ -35,14 +35,12 @@ REQUIRES = xpcom string dom js
|
||||
CPPSRCS = nsWalletViewerFactory.cpp
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
-I$(srcdir)/../cookieviewer \
|
||||
-I$(srcdir)/../editor \
|
||||
-I$(srcdir)/../signonviewer \
|
||||
-I$(srcdir)/../walletpreview \
|
||||
$(NULL)
|
||||
|
||||
SHARED_LIBRARY_LIBS = \
|
||||
$(DIST)/lib/libcookieviewer_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/libsignonviewer_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/libwalletpreview_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/libwalleteditor_s.$(LIB_SUFFIX) \
|
||||
|
@ -27,7 +27,7 @@ MODULE = walletviewers
|
||||
LIBNAME = .\$(OBJDIR)\wlltvwrs
|
||||
DLL = $(LIBNAME).dll
|
||||
|
||||
LINCS = -I..\cookieviewer \
|
||||
LINCS = \
|
||||
-I..\editor \
|
||||
-I..\signonviewer \
|
||||
-I..\walletpreview \
|
||||
@ -38,7 +38,6 @@ CPP_OBJS = \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(DIST)\lib\cookieviewer_s.lib \
|
||||
$(DIST)\lib\signonviewer_s.lib \
|
||||
$(DIST)\lib\walletpreview_s.lib \
|
||||
$(DIST)\lib\walleteditor_s.lib \
|
||||
|
@ -26,12 +26,10 @@
|
||||
|
||||
#include "nsWalletPreview.h"
|
||||
#include "nsSignonViewer.h"
|
||||
#include "nsCookieViewer.h"
|
||||
#include "nsWalletEditor.h"
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(WalletPreviewImpl)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(SignonViewerImpl)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(CookieViewerImpl)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(WalletEditorImpl)
|
||||
|
||||
// The list of components we register
|
||||
@ -40,8 +38,6 @@ static nsModuleComponentInfo components[] = {
|
||||
"@mozilla.org/walletpreview/walletpreview-world;1", WalletPreviewImplConstructor },
|
||||
{ "SignonViewer World Component", NS_SIGNONVIEWER_CID,
|
||||
"@mozilla.org/signonviewer/signonviewer-world;1", SignonViewerImplConstructor },
|
||||
{ "CookieViewer World Component", NS_COOKIEVIEWER_CID,
|
||||
"@mozilla.org/cookieviewer/cookieviewer-world;1", CookieViewerImplConstructor },
|
||||
{ "WalletEditor World Component", NS_WALLETEDITOR_CID,
|
||||
"@mozilla.org/walleteditor/walleteditor-world;1", WalletEditorImplConstructor },
|
||||
};
|
||||
|
@ -18,39 +18,27 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Contributor(s):
|
||||
* Ben Goodger
|
||||
*/
|
||||
|
||||
/*
|
||||
* The cookieList is a sequence of items separated by the BREAK character. These
|
||||
* items are:
|
||||
* empty
|
||||
* number for first cookie
|
||||
* name for first cookie
|
||||
* value for first cookie
|
||||
* domain indicator ("Domain" or "Host") for first cookie
|
||||
* domain or host name for first cookie
|
||||
* path for first cookie
|
||||
* secure indicator ("Yes" or "No") for first cookie
|
||||
* expiration for first cookie
|
||||
* with the eight items above repeated for each successive cookie
|
||||
*/
|
||||
|
||||
// global variables
|
||||
var cookieviewer = null; // cookieviewer interface
|
||||
var cookieList = []; // array of cookies (OLD STREAM)
|
||||
var cookies = []; // array of cookeis (NEW OBJECT)
|
||||
var permissionList = []; // array of permissions (OLD STREAM)
|
||||
var permissions = []; // array of permissions (NEW OBJECT)
|
||||
var imageList = []; // array of images (OLD STREAM)
|
||||
var cookiemanager = null; // cookiemanager interface
|
||||
var permissionmanager = null; // permissionmanager interface
|
||||
var cookies = []; // array of cookies
|
||||
var permissions = []; // array of permissions
|
||||
var images = []; // array of images (NEW OBJECT)
|
||||
var deleted_cookies = [];
|
||||
var deleted_permissions = [];
|
||||
var deleted_images = [];
|
||||
var deleted_cookies_count = 0;
|
||||
var deleted_permissions_count = 0;
|
||||
var deleted_images_count = 0;
|
||||
var deleted_cookies_count = 0;
|
||||
var deleted_cookie_permissions_count = 0;
|
||||
var deleted_image_permissions_count = 0;
|
||||
var cookie_permissions_count = 0;
|
||||
var image_permissions_count = 0;
|
||||
var cookieType = 0;
|
||||
var imageType = 1;
|
||||
|
||||
// for dealing with the interface:
|
||||
var gone_c = "";
|
||||
var gone_p = "";
|
||||
@ -58,16 +46,19 @@ var gone_i = "";
|
||||
// string bundle
|
||||
var bundle = null;
|
||||
// CHANGE THIS WHEN MOVING FILES - strings localization file!
|
||||
var JS_STRINGS_FILE = "chrome://communicator/locale/wallet/CookieViewer.properties";
|
||||
|
||||
var JS_STRINGS_FILE = "chrome://communicator/locale/wallet/CookieViewer.properties";
|
||||
|
||||
// function : <CookieViewer.js>::Startup();
|
||||
// purpose : initialises the cookie viewer dialog
|
||||
function Startup()
|
||||
{
|
||||
// xpconnect to cookieviewer interface
|
||||
cookieviewer = Components.classes["@mozilla.org/cookieviewer/cookieviewer-world;1"].createInstance();
|
||||
cookieviewer = cookieviewer.QueryInterface(Components.interfaces.nsICookieViewer);
|
||||
// intialise string bundle for
|
||||
// xpconnect to cookiemanager interface
|
||||
cookiemanager = Components.classes["@mozilla.org/cookiemanager;1"].getService();
|
||||
cookiemanager = cookiemanager.QueryInterface(Components.interfaces.nsICookieManager);
|
||||
// xpconnect to permissionmanager interface
|
||||
permissionmanager = Components.classes["@mozilla.org/permissionmanager;1"].getService();
|
||||
permissionmanager = permissionmanager.QueryInterface(Components.interfaces.nsIPermissionManager);
|
||||
// intialise string bundle
|
||||
bundle = srGetStrBundle(JS_STRINGS_FILE);
|
||||
|
||||
// install imageblocker tab if instructed to do so by the "imageblocker.enabled" pref
|
||||
@ -80,9 +71,9 @@ function Startup()
|
||||
if (pref.GetBoolPref("imageblocker.enabled")) {
|
||||
var element;
|
||||
element = document.getElementById("imagesTab");
|
||||
element.setAttribute("style","display: inline;" );
|
||||
element.setAttribute("hidden","false" );
|
||||
element = document.getElementById("images");
|
||||
element.setAttribute("style","display: inline;" );
|
||||
element.setAttribute("hidden","false" );
|
||||
}
|
||||
} catch(e) {
|
||||
}
|
||||
@ -94,6 +85,8 @@ function Startup()
|
||||
element2.selectedTab = element;
|
||||
element = document.getElementById("panel");
|
||||
element.setAttribute("index","0" );
|
||||
element = document.getElementById("imagesTab");
|
||||
element.setAttribute("hidden","true" );
|
||||
} else {
|
||||
element = document.getElementById("cookieviewer");
|
||||
element.setAttribute("title", bundle.GetStringFromName("imageTitle"));
|
||||
@ -101,6 +94,10 @@ function Startup()
|
||||
element2.selectedTab = element;
|
||||
element = document.getElementById("panel");
|
||||
element.setAttribute("index","2" );
|
||||
element = document.getElementById("serversTab");
|
||||
element.setAttribute("hidden","true" );
|
||||
element = document.getElementById("cookiesTab");
|
||||
element.setAttribute("hidden","true" );
|
||||
}
|
||||
} catch(e) {
|
||||
}
|
||||
@ -109,48 +106,41 @@ function Startup()
|
||||
pref = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
loadCookies();
|
||||
loadPermissions();
|
||||
loadImages();
|
||||
doSetOKCancel(onOK, null);
|
||||
window.sizeToContent();
|
||||
}
|
||||
|
||||
/*** =================== COOKIES CODE =================== ***/
|
||||
|
||||
// function : <CookieViewer.js>::CreateCookieList();
|
||||
// purpose : creates an array of cookie objects from the cookie stream
|
||||
function CreateCookieList()
|
||||
{
|
||||
var count = 0;
|
||||
for(var i = 1; i < cookieList.length; i+=8)
|
||||
{
|
||||
cookies[count] = new Cookie();
|
||||
cookies[count].number = cookieList[i+0];
|
||||
cookies[count].name = cookieList[i+1];
|
||||
cookies[count].value = cookieList[i+2];
|
||||
cookies[count].domaintype = cookieList[i+3];
|
||||
cookies[count].domain = cookieList[i+4];
|
||||
cookies[count].path = cookieList[i+5];
|
||||
cookies[count].secure = cookieList[i+6];
|
||||
cookies[count].expire = cookieList[i+7];
|
||||
count++;
|
||||
}
|
||||
// function : <CookieViewer.js>::AddCookieToList();
|
||||
// purpose : creates an array of cookie objects
|
||||
function AddCookieToList(count, name, value, isDomain, host, path, isSecure, expires) {
|
||||
cookies[count] = new Cookie();
|
||||
cookies[count].number = count;
|
||||
cookies[count].name = name;
|
||||
cookies[count].value = value;
|
||||
cookies[count].isDomain = isDomain;
|
||||
cookies[count].host = host;
|
||||
cookies[count].path = path;
|
||||
cookies[count].isSecure = isSecure;
|
||||
cookies[count].expires = expires;
|
||||
}
|
||||
|
||||
// function : <CookieViewer.js>::Cookie();
|
||||
// purpose : an home-brewed object that represents a individual cookie in the stream
|
||||
function Cookie(number,name,value,domaintype,domain,path,secure,expire)
|
||||
function Cookie(number,name,value,isDomain,host,path,isSecure,expires)
|
||||
{
|
||||
this.number = ( number ) ? number : null;
|
||||
this.name = ( name ) ? name : null;
|
||||
this.value = ( value ) ? value : null;
|
||||
this.domaintype = ( domaintype ) ? domaintype : null;
|
||||
this.domain = ( domain ) ? domain : null;
|
||||
this.isDomain = ( isDomain ) ? isDomain : null;
|
||||
this.host = ( host ) ? host : null;
|
||||
this.path = ( path ) ? path : null;
|
||||
this.secure = ( secure ) ? secure : null;
|
||||
this.expire = ( expire ) ? expire : null;
|
||||
this.isSecure = ( isSecure ) ? isSecure : null;
|
||||
this.expires = ( expires ) ? expires : null;
|
||||
}
|
||||
|
||||
|
||||
@ -158,26 +148,39 @@ function Cookie(number,name,value,domaintype,domain,path,secure,expire)
|
||||
// purpose : loads the list of cookies into the cookie list treeview
|
||||
function loadCookies()
|
||||
{
|
||||
// get cookies into an array
|
||||
var list = cookieviewer.GetCookieValue();
|
||||
var BREAK = list.substring(0,1);
|
||||
cookieList = list.split(BREAK);
|
||||
CreateCookieList(); // builds an object array from cookiestream
|
||||
for(var i = 0; i < cookies.length; i++)
|
||||
{
|
||||
var domain = cookies[i].domain;
|
||||
if(domain.charAt(0) == ".") // get rid of the ugly dot on the start of some domains
|
||||
domain = domain.substring(1,domain.length);
|
||||
AddItem("cookielist", [domain,cookies[i].name], "tree_", cookies[i].number);
|
||||
var cookieString;
|
||||
var cookieArray = [];
|
||||
|
||||
var enumerator = cookiemanager.enumerator;
|
||||
var count = 0;
|
||||
while (enumerator.hasMoreElements()) {
|
||||
var nextCookie = enumerator.getNext();
|
||||
nextCookie = nextCookie.QueryInterface(Components.interfaces.nsICookie);
|
||||
|
||||
var name = nextCookie.name;
|
||||
var value = nextCookie.value;
|
||||
var isDomain = nextCookie.isDomain;
|
||||
var host = nextCookie.host;
|
||||
var path = nextCookie.path;
|
||||
var isSecure = nextCookie.isSecure;
|
||||
var expires = nextCookie.expires;
|
||||
|
||||
AddCookieToList
|
||||
(count, name, value, isDomain, host, path, isSecure, expires);
|
||||
if(host.charAt(0) == ".") { // get rid of the ugly dot on the start of some domains
|
||||
host = host.substring(1,host.length);
|
||||
}
|
||||
AddItem("cookieList", [host, name], "cookietree_", count++);
|
||||
}
|
||||
if (cookies.length == 0) {
|
||||
Wallet_ColumnSort('0', 'cookieList');
|
||||
if (count == 0) {
|
||||
document.getElementById("removeAllCookies").setAttribute("disabled","true");
|
||||
}
|
||||
}
|
||||
|
||||
// function : <CookieViewer.js>::ViewSelectedCookie();
|
||||
// purpose : displays information about the selected cookie in the info fieldset
|
||||
function ViewCookieSelected( e )
|
||||
function ViewCookieSelected( e )
|
||||
{
|
||||
var cookie = null;
|
||||
var cookietree = document.getElementById("cookietree");
|
||||
@ -188,37 +191,50 @@ function ViewCookieSelected( e )
|
||||
selItemsMax = true;
|
||||
if( cookietree.selectedItems.length )
|
||||
document.getElementById("removeCookies").removeAttribute("disabled","true");
|
||||
|
||||
|
||||
if( ( e.type == "keypress" || e.type == "select" ) && e.target.selectedItems.length )
|
||||
cookie = cookietree.selectedItems[0];
|
||||
if( e.type == "click" )
|
||||
if( e.type == "click" )
|
||||
cookie = e.target.parentNode.parentNode;
|
||||
|
||||
if( !cookie || cookie.getAttribute("id").indexOf("tree_") == -1)
|
||||
if( !cookie || cookie.getAttribute("id").indexOf("cookietree_") == -1)
|
||||
return false;
|
||||
var idx = parseInt(cookie.getAttribute("id").substring(5,cookie.getAttribute("id").length));
|
||||
var idx = parseInt(cookie.getAttribute("id").substring("cookietree_".length,cookie.getAttribute("id").length));
|
||||
for (var x=0; x<cookies.length; x++) {
|
||||
if (cookies[x].number == idx) {
|
||||
idx = x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var props = [cookies[idx].number, cookies[idx].name, cookies[idx].value,
|
||||
cookies[idx].domaintype, cookies[idx].domain, cookies[idx].path,
|
||||
cookies[idx].secure, cookies[idx].expire];
|
||||
var props = [cookies[idx].number, cookies[idx].name, cookies[idx].value,
|
||||
cookies[idx].isDomain, cookies[idx].host, cookies[idx].path,
|
||||
cookies[idx].isSecure, cookies[idx].expires];
|
||||
|
||||
var rows =
|
||||
[null,"ifl_name","ifl_value","ifl_domaintype","ifl_domain","ifl_path","ifl_secure","ifl_expires"];
|
||||
[null,"ifl_name","ifl_value","ifl_isDomain","ifl_host","ifl_path","ifl_isSecure","ifl_expires"];
|
||||
var value;
|
||||
var field;
|
||||
for(var i = 1; i < props.length; i++)
|
||||
{
|
||||
if(i == 3) {
|
||||
var dtypecell = document.getElementById("ifl_domaintype");
|
||||
dtypecell.setAttribute("label", cookies[idx].domaintype+":");
|
||||
continue;
|
||||
if(rows[i] == "ifl_isDomain") {
|
||||
field = document.getElementById("ifl_isDomain");
|
||||
value = cookies[idx].isDomain ?
|
||||
bundle.GetStringFromName("domainColon") :
|
||||
bundle.GetStringFromName("hostColon");
|
||||
} else if (rows[i] == "ifl_isSecure") {
|
||||
field = document.getElementById("ifl_isSecure");
|
||||
value = cookies[idx].isSecure ?
|
||||
bundle.GetStringFromName("yes") : bundle.GetStringFromName("no");
|
||||
} else if (rows[i] == "ifl_expires") {
|
||||
field = document.getElementById("ifl_expires");
|
||||
var date = new Date(1000*cookies[idx].expires);
|
||||
value = cookies[idx].expires
|
||||
? date.toLocaleString()
|
||||
: bundle.GetStringFromName("AtEndOfSession");
|
||||
} else {
|
||||
field = document.getElementById(rows[i]);
|
||||
value = ( !selItemsMax ) ? props[i] : ""; // multiple selections clear fields.
|
||||
}
|
||||
var field = document.getElementById(rows[i]);
|
||||
var content = props[i];
|
||||
var value = ( !selItemsMax ) ? content : ""; // multiple selections clear fields.
|
||||
field.setAttribute("value", value);
|
||||
if(rows[i] == "ifl_expires") break;
|
||||
}
|
||||
@ -230,10 +246,10 @@ function ViewCookieSelected( e )
|
||||
function DeleteCookieSelected() {
|
||||
// delete selected item
|
||||
deleted_cookies_count += document.getElementById("cookietree").selectedItems.length;
|
||||
gone_c += DeleteItemSelected("cookietree", "tree_", "cookielist");
|
||||
gone_c += DeleteItemSelected("cookietree", "cookietree_", "cookieList");
|
||||
// set fields
|
||||
rows = ["ifl_name","ifl_value","ifl_domain","ifl_path","ifl_secure","ifl_expires"];
|
||||
for(k = 0; k < rows.length; k++)
|
||||
var rows = ["ifl_name","ifl_value","ifl_host","ifl_path","ifl_isSecure","ifl_expires"];
|
||||
for(var k = 0; k < rows.length; k++)
|
||||
{
|
||||
var row = document.getElementById(rows[k]);
|
||||
row.setAttribute("label","");
|
||||
@ -252,10 +268,10 @@ function DeleteCookieSelected() {
|
||||
// purpose : deletes all the cookies
|
||||
function DeleteAllCookies() {
|
||||
// delete selected item
|
||||
gone_c += DeleteAllItems(cookies.length, "tree_", "cookielist");
|
||||
gone_c += DeleteAllItems(cookies.length, "cookietree_", "cookieList");
|
||||
// set fields
|
||||
var rows = ["ifl_name","ifl_value","ifl_domain","ifl_path","ifl_secure","ifl_expires"];
|
||||
for(var k = 0; k < rows.length; k++)
|
||||
var rows = ["ifl_name","ifl_value","ifl_host","ifl_path","ifl_isSecure","ifl_expires"];
|
||||
for(var k = 0; k < rows.length; k++)
|
||||
{
|
||||
var row = document.getElementById(rows[k]);
|
||||
row.setAttribute("label","");
|
||||
@ -286,86 +302,96 @@ function HandleKeyPress( e )
|
||||
// will restore deleted cookies when I get around to filling it in.
|
||||
function RestoreCookies()
|
||||
{
|
||||
// todo
|
||||
// todo
|
||||
}
|
||||
|
||||
/*** =================== PERMISSIONS CODE =================== ***/
|
||||
|
||||
// function : <CookieViewer.js>::CreatePermissionList();
|
||||
// purpose : creates an array of permission objects from the permission stream
|
||||
function CreatePermissionList()
|
||||
{
|
||||
var count = 0;
|
||||
for(var i = 1; i < permissionList.length; i+=2)
|
||||
{
|
||||
permissions[count] = new Permission();
|
||||
permissions[count].number = permissionList[i];
|
||||
var permStr = permissionList[i+1];
|
||||
permissions[count].type = permStr.substring(0,1);
|
||||
permissions[count].domain = permStr.substring(1,permStr.length);
|
||||
count++;
|
||||
}
|
||||
// function : <CookieViewer.js>::AddPermissionToList();
|
||||
// purpose : creates an array of permission objects
|
||||
function AddPermissionToList(count, host, type, capability) {
|
||||
permissions[count] = new Permission();
|
||||
permissions[count].number = count;
|
||||
permissions[count].host = host;
|
||||
permissions[count].type = type;
|
||||
permissions[count].capability = capability;
|
||||
}
|
||||
|
||||
// function : <CookieViewer.js>::Permission();
|
||||
// purpose : an home-brewed object that represents a individual permission in the stream
|
||||
function Permission(number,type,domain)
|
||||
function Permission(number, host, type, capability)
|
||||
{
|
||||
this.number = (number) ? number : null;
|
||||
this.host = (host) ? host : null;
|
||||
this.type = (type) ? type : null;
|
||||
this.domain = (domain) ? domain : null;
|
||||
this.capability = (capability) ? capability : null;
|
||||
}
|
||||
|
||||
// function : <CookieViewer.js>::loadPermissions();
|
||||
// purpose : loads the list of permissions into the permission list treeview
|
||||
function loadPermissions()
|
||||
{
|
||||
// get permissions into an array
|
||||
var list = cookieviewer.GetPermissionValue(0);
|
||||
var BREAK = list.substring(0,1);
|
||||
permissionList = list.split(BREAK);
|
||||
CreatePermissionList(); // builds an object array from permissionstream
|
||||
for(var i = 0; i < permissions.length; i++)
|
||||
{
|
||||
var contentStr;
|
||||
var domain = permissions[i].domain;
|
||||
if(domain.charAt(0) == ".") // get rid of the ugly dot on the start of some domains
|
||||
domain = domain.substring(1,domain.length);
|
||||
if(permissions[i].type == "+")
|
||||
var permissionString;
|
||||
var permissionArray = [];
|
||||
|
||||
var enumerator = permissionmanager.enumerator;
|
||||
var contentStr;
|
||||
while (enumerator.hasMoreElements()) {
|
||||
var nextPermission = enumerator.getNext();
|
||||
nextPermission = nextPermission.QueryInterface(Components.interfaces.nsIPermission);
|
||||
|
||||
var host = nextPermission.host;
|
||||
var type = nextPermission.type;
|
||||
var capability = nextPermission.capability;
|
||||
if(host.charAt(0) == ".") { // get rid of the ugly dot on the start of some domains
|
||||
host = host.substring(1,host.length);
|
||||
}
|
||||
if(capability) {
|
||||
contentStr = bundle.GetStringFromName("can");
|
||||
else if(permissions[i].type == "-")
|
||||
contentStr = bundle.GetStringFromName("cannot");
|
||||
AddItem("permissionslist",[domain,contentStr],"permtree_",permissions[i].number)
|
||||
} else {
|
||||
contentStr = bundle.GetStringFromName("cannot");
|
||||
}
|
||||
if (type == cookieType) {
|
||||
AddPermissionToList(cookie_permissions_count, host, type, capability);
|
||||
AddItem("cookiePermList", [host, contentStr], "cookiepermtree_", cookie_permissions_count++);
|
||||
} else if (type == imageType) {
|
||||
AddPermissionToList(image_permissions_count, host, type, capability);
|
||||
AddItem("imagePermList", [host, contentStr], "imagepermtree_", image_permissions_count++);
|
||||
}
|
||||
}
|
||||
if (permissions.length == 0) {
|
||||
if (cookie_permissions_count == 0) {
|
||||
document.getElementById("removeAllPermissions").setAttribute("disabled","true");
|
||||
}
|
||||
if (image_permissions_count == 0) {
|
||||
document.getElementById("removeAllImages").setAttribute("disabled","true");
|
||||
}
|
||||
}
|
||||
|
||||
function ViewPermissionSelected()
|
||||
function ViewCookiePermissionSelected()
|
||||
{
|
||||
var permissiontree = document.getElementById("permissionstree");
|
||||
if( permissiontree.selectedItems.length )
|
||||
var cookiepermtree = document.getElementById("cookiepermissionstree");
|
||||
if( cookiepermtree.selectedItems.length )
|
||||
document.getElementById("removePermissions").removeAttribute("disabled","true");
|
||||
}
|
||||
|
||||
function DeletePermissionSelected()
|
||||
function DeleteCookiePermissionSelected()
|
||||
{
|
||||
deleted_permissions_count += document.getElementById("permissionstree").selectedItems.length;
|
||||
gone_p += DeleteItemSelected('permissionstree', 'permtree_', 'permissionslist');
|
||||
if( !document.getElementById("permissionstree").selectedItems.length ) {
|
||||
deleted_cookie_permissions_count +=
|
||||
document.getElementById("cookiepermissionstree").selectedItems.length;
|
||||
gone_p += DeleteItemSelected('cookiepermissionstree', 'cookiepermtree_', 'cookiePermList');
|
||||
if( !document.getElementById("cookiepermissionstree").selectedItems.length ) {
|
||||
if( !document.getElementById("removePermissions").disabled ) {
|
||||
document.getElementById("removePermissions").setAttribute("disabled", "true")
|
||||
}
|
||||
}
|
||||
if (deleted_permissions_count >= permissions.length) {
|
||||
if (deleted_cookie_permissions_count >= cookie_permissions_count) {
|
||||
document.getElementById("removeAllPermissions").setAttribute("disabled","true");
|
||||
}
|
||||
}
|
||||
|
||||
function DeleteAllPermissions() {
|
||||
function DeleteAllCookiePermissions() {
|
||||
// delete selected item
|
||||
gone_p += DeleteAllItems(permissions.length, "permtree_", "permissionslist");
|
||||
gone_p += DeleteAllItems(cookie_permissions_count, "cookiepermtree_", "cookiePermList");
|
||||
if( !document.getElementById("removePermissions").disabled ) {
|
||||
document.getElementById("removePermissions").setAttribute("disabled", "true")
|
||||
}
|
||||
@ -374,79 +400,31 @@ function DeleteAllPermissions() {
|
||||
|
||||
/*** =================== IMAGES CODE =================== ***/
|
||||
|
||||
// function : <CookieViewer.js>::CreateImageList();
|
||||
// purpose : creates an array of image objects from the image stream
|
||||
function CreateImageList()
|
||||
function ViewImagePermissionSelected()
|
||||
{
|
||||
var count = 0;
|
||||
for(var i = 1; i < imageList.length; i+=2)
|
||||
{
|
||||
images[count] = new Image();
|
||||
images[count].number = imageList[i];
|
||||
var imgStr = imageList[i+1];
|
||||
images[count].type = imgStr.substring(0,1);
|
||||
images[count].domain = imgStr.substring(1,imgStr.length);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
// function : <CookieViewer.js>::Image();
|
||||
// purpose : an home-brewed object that represents a individual image in the stream
|
||||
function Image(number,type,domain)
|
||||
{
|
||||
this.number = (number) ? number : null;
|
||||
this.type = (type) ? type : null;
|
||||
this.domain = (domain) ? domain : null;
|
||||
}
|
||||
|
||||
// function : <CookieViewer.js>::loadImages();
|
||||
// purpose : loads the list of images into the image list treeview
|
||||
function loadImages()
|
||||
{
|
||||
// get images into an array
|
||||
var list = cookieviewer.GetPermissionValue(1);
|
||||
var BREAK = list.substring(0,1);
|
||||
imageList = list.split(BREAK);
|
||||
CreateImageList(); // builds an object array from imagestream
|
||||
for(var i = 0; i < images.length; i++)
|
||||
{
|
||||
var contentStr;
|
||||
var domain = images[i].domain;
|
||||
if(images[i].type == "+")
|
||||
contentStr = bundle.GetStringFromName("canImages");
|
||||
else if(images[i].type == "-")
|
||||
contentStr = bundle.GetStringFromName("cannotImages");
|
||||
AddItem("imageslist",[domain,contentStr],"imgtree_",images[i].number)
|
||||
}
|
||||
if (images.length == 0) {
|
||||
document.getElementById("removeAllImages").setAttribute("disabled","true");
|
||||
}
|
||||
}
|
||||
|
||||
function ViewImageSelected()
|
||||
{
|
||||
var imagetree = document.getElementById("imagestree");
|
||||
if( imagetree.selectedItems.length )
|
||||
var imagepermtree = document.getElementById("imagepermissionstree");
|
||||
if( imagepermtree.selectedItems.length )
|
||||
document.getElementById("removeImages").removeAttribute("disabled","true");
|
||||
}
|
||||
|
||||
function DeleteImageSelected()
|
||||
function DeleteImagePermissionSelected()
|
||||
{
|
||||
deleted_images_count += document.getElementById("imagestree").selectedItems.length;
|
||||
gone_i += DeleteItemSelected('imagestree', 'imgtree_', 'imageslist');
|
||||
if( !document.getElementById("imagestree").selectedItems.length ) {
|
||||
deleted_image_permissions_count
|
||||
+= document.getElementById("imagepermissionstree").selectedItems.length;
|
||||
gone_i += DeleteItemSelected('imagepermissionstree', 'imagepermtree_', 'imagePermList');
|
||||
if( !document.getElementById("imagepermissionstree").selectedItems.length ) {
|
||||
if( !document.getElementById("removeImages").disabled ) {
|
||||
document.getElementById("removeImages").setAttribute("disabled", "true")
|
||||
}
|
||||
}
|
||||
if (deleted_images_count >= images.length) {
|
||||
if (deleted_image_permissions_count >= image_permissions_count) {
|
||||
document.getElementById("removeAllImages").setAttribute("disabled","true");
|
||||
}
|
||||
}
|
||||
|
||||
function DeleteAllImages() {
|
||||
function DeleteAllImagePermissions() {
|
||||
// delete selected item
|
||||
gone_i += DeleteAllItems(images.length, "imgtree_", "imageslist");
|
||||
gone_i += DeleteAllItems(image_permissions_count, "imagepermtree_", "imagePermList");
|
||||
if( !document.getElementById("removeImages").disabled ) {
|
||||
document.getElementById("removeImages").setAttribute("disabled", "true")
|
||||
}
|
||||
@ -458,9 +436,36 @@ function DeleteAllImages() {
|
||||
// function : <CookieViewer.js>::doOKButton();
|
||||
// purpose : saves the changed settings and closes the dialog.
|
||||
function onOK(){
|
||||
var result = "|goneC|" + gone_c + "|goneP|" + gone_p + "|goneI|" + gone_i +
|
||||
"|block|" + document.getElementById("checkbox").checked +"|";
|
||||
cookieviewer.SetValue(result, window);
|
||||
|
||||
var deletedCookies = [];
|
||||
deletedCookies = gone_c.split(",");
|
||||
var cookieCount;
|
||||
for (cookieCount=0; cookieCount<deletedCookies.length-1; cookieCount++) {
|
||||
cookiemanager.remove(cookies[deletedCookies[cookieCount]].host,
|
||||
cookies[deletedCookies[cookieCount]].name,
|
||||
cookies[deletedCookies[cookieCount]].path,
|
||||
document.getElementById("checkbox").checked);
|
||||
}
|
||||
|
||||
var deletedCookiePermissions = [];
|
||||
deletedCookiePermissions = gone_p.split(",");
|
||||
var cperm_count;
|
||||
for (cperm_count=0;
|
||||
cperm_count<deletedCookiePermissions.length-1;
|
||||
cperm_count++) {
|
||||
permissionmanager.remove
|
||||
(permissions[deletedCookiePermissions[cperm_count]].host, cookieType);
|
||||
}
|
||||
|
||||
var deletedImagePermissions = [];
|
||||
deletedImagePermissions = gone_i.split(",");
|
||||
var iperm_count;
|
||||
for (iperm_count=0;
|
||||
iperm_count<deletedImagePermissions.length-1;
|
||||
iperm_count++) {
|
||||
permissionmanager.remove
|
||||
(permissions[deletedImagePermissions[iperm_count]].host, imageType);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -493,14 +498,14 @@ function DeleteItemSelected(tree, prefix, kids) {
|
||||
var rv = "";
|
||||
var cookietree = document.getElementById(tree);
|
||||
var selitems = cookietree.selectedItems;
|
||||
for(i = 0; i < selitems.length; i++)
|
||||
{
|
||||
for(i = 0; i < selitems.length; i++)
|
||||
{
|
||||
delnarray[i] = document.getElementById(selitems[i].getAttribute("id"));
|
||||
var itemid = parseInt(selitems[i].getAttribute("id").substring(prefix.length,selitems[i].getAttribute("id").length));
|
||||
rv += (itemid + ",");
|
||||
}
|
||||
for(i = 0; i < delnarray.length; i++)
|
||||
{
|
||||
for(i = 0; i < delnarray.length; i++)
|
||||
{
|
||||
document.getElementById(kids).removeChild(delnarray[i]);
|
||||
}
|
||||
return rv;
|
||||
@ -511,8 +516,8 @@ function DeleteItemSelected(tree, prefix, kids) {
|
||||
function DeleteAllItems(length, prefix, kids) {
|
||||
var delnarray = [];
|
||||
var rv = "";
|
||||
for(var i = 0; i < length; i++)
|
||||
{
|
||||
for(var i = 0; i < length; i++)
|
||||
{
|
||||
if (document.getElementById(prefix+i) != null) {
|
||||
document.getElementById(kids).removeChild(document.getElementById(prefix+i));
|
||||
rv += (i + ",");
|
||||
|
@ -27,3 +27,8 @@ cannotImages=site cannot load images
|
||||
domain=Domain for which this cookie applies:
|
||||
host=Server which set the cookie:
|
||||
imageTitle=Image Manager
|
||||
hostColon=host:
|
||||
domainColon=domain:
|
||||
yes=yes
|
||||
no=no
|
||||
AtEndOfSession = at end of session
|
||||
|
@ -47,8 +47,8 @@
|
||||
<tabcontrol id="tabcontrol" flex="1" orient="vertical">
|
||||
<tabbox>
|
||||
<tab id="cookiesTab" label="&tab.cookiesonsystem.label;"/>
|
||||
<tab label="&tab.bannedservers.label;"/>
|
||||
<tab id="imagesTab" style="display:none" label="&tab.bannedimages.label;"/>
|
||||
<tab id="serversTab" label="&tab.bannedservers.label;"/>
|
||||
<tab id="imagesTab" hidden="true" label="&tab.bannedimages.label;"/>
|
||||
</tabbox>
|
||||
<tabpanel id="panel" flex="1">
|
||||
<box class="tabpanel" id="system" flex="1" orient="vertical">
|
||||
@ -67,14 +67,14 @@
|
||||
<treerow>
|
||||
<treecell class="treecell-header sortDirectionIndicator"
|
||||
label="&treehead.cookiedomain.label;"
|
||||
onclick="return Wallet_ColumnSort('0', 'cookielist');"/>
|
||||
onclick="return Wallet_ColumnSort('0', 'cookieList');"/>
|
||||
<treecell class="treecell-header
|
||||
sortDirectionIndicator"
|
||||
label="&treehead.cookiename.label;"
|
||||
onclick="return Wallet_ColumnSort('1', 'cookielist');"/>
|
||||
onclick="return Wallet_ColumnSort('1', 'cookieList');"/>
|
||||
</treerow>
|
||||
</treehead>
|
||||
<treechildren id="cookielist" flex="1"/>
|
||||
<treechildren id="cookieList" flex="1"/>
|
||||
</tree>
|
||||
<titledbox>
|
||||
<label value="&treehead.infoselected.label;"/>
|
||||
@ -94,8 +94,8 @@
|
||||
<textbox id="ifl_value" readonly="true"/>
|
||||
</row>
|
||||
<row>
|
||||
<text id="ifl_domaintype" value="&props.domain.label;"/>
|
||||
<textbox id="ifl_domain" readonly="true"/>
|
||||
<text id="ifl_isDomain" value="&props.domain.label;"/>
|
||||
<textbox id="ifl_host" readonly="true"/>
|
||||
</row>
|
||||
<row>
|
||||
<text value="&props.path.label;"/>
|
||||
@ -103,7 +103,7 @@
|
||||
</row>
|
||||
<row>
|
||||
<text value="&props.secure.label;"/>
|
||||
<textbox id="ifl_secure" readonly="true"/>
|
||||
<textbox id="ifl_isSecure" readonly="true"/>
|
||||
</row>
|
||||
<row>
|
||||
<text value="&props.expires.label;"/>
|
||||
@ -130,9 +130,9 @@
|
||||
<box class="tabpanel" id="servers" flex="1" orient="vertical">
|
||||
<text class="label" value="&div.bannedservers.label;"/>
|
||||
<separator class="thin"/>
|
||||
<tree id="permissionstree" class="inset" flex="1"
|
||||
onkeypress="if(event.which == 46) gone_p += DeleteItemSelected('permissionstree', 'permtree_', 'permissionslist');"
|
||||
multiple="true" onclick="ViewPermissionSelected();">
|
||||
<tree id="cookiepermissionstree" class="inset" flex="1"
|
||||
onkeypress="if(event.which == 46) gone_p += DeleteItemSelected('cookiepermissionstree', 'permtree_', 'cookiePermList');"
|
||||
multiple="true" onclick="ViewCookiePermissionSelected();">
|
||||
<treecolgroup>
|
||||
<treecol flex="5" width="0"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
@ -142,30 +142,30 @@
|
||||
<treerow>
|
||||
<treecell class="treecell-header sortDirectionIndicator"
|
||||
label="&treehead.sitename.label;"
|
||||
onclick="return Wallet_ColumnSort('0', 'permissionslist');"/>
|
||||
onclick="return Wallet_ColumnSort('0', 'cookiePermList');"/>
|
||||
<treecell class="treecell-header sortDirectionIndicator"
|
||||
label="&treehead.status.label;"
|
||||
onclick="return Wallet_ColumnSort('1', 'permissionslist');"/>
|
||||
onclick="return Wallet_ColumnSort('1', 'cookiePermList');"/>
|
||||
</treerow>
|
||||
</treehead>
|
||||
<treechildren flex="1" id="permissionslist"/>
|
||||
<treechildren flex="1" id="cookiePermList"/>
|
||||
</tree>
|
||||
<box>
|
||||
<button id="removePermissions" class="dialog push" disabled="true"
|
||||
label="&removepermission.label;"
|
||||
oncommand="DeletePermissionSelected();"/>
|
||||
oncommand="DeleteCookiePermissionSelected();"/>
|
||||
<button id="removeAllPermissions" class="dialog push"
|
||||
label="&removeallpermissions.label;"
|
||||
oncommand="DeleteAllPermissions();"/>
|
||||
oncommand="DeleteAllCookiePermissions();"/>
|
||||
</box>
|
||||
</box>
|
||||
|
||||
<box class="tabpanel" id="images" style="display:none" flex="1" orient="vertical">
|
||||
<box class="tabpanel" id="images" hidden="true" flex="1" orient="vertical">
|
||||
<text class="label" value="&div.bannedimages.label;"/>
|
||||
<separator class="thin"/>
|
||||
<tree id="imagestree" class="inset" flex="1" style="height: 0px;"
|
||||
onkeypress="if(event.which == 46) gone_i += DeleteItemSelected('imagestree', 'imgtree_', 'imageslist');"
|
||||
multiple="true" onclick="ViewImageSelected();">
|
||||
<tree id="imagepermissionstree" class="inset" flex="1" style="height: 0px;"
|
||||
onkeypress="if(event.which == 46) gone_i += DeleteItemSelected('imagepermisionstree', 'imgtree_', 'imagePermList');"
|
||||
multiple="true" onclick="ViewImagePermissionSelected();">
|
||||
<treecolgroup>
|
||||
<treecol flex="5" width="0"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
@ -175,21 +175,21 @@
|
||||
<treerow>
|
||||
<treecell class="treecell-header sortDirectionIndicator"
|
||||
label="&treehead.sitename.label;"
|
||||
onclick="return Wallet_ColumnSort('0', 'imageslist');"/>
|
||||
onclick="return Wallet_ColumnSort('0', 'imagePermList');"/>
|
||||
<treecell class="treecell-header sortDirectionIndicator"
|
||||
label="&treehead.status.label;"
|
||||
onclick="return Wallet_ColumnSort('1', 'imageslist');"/>
|
||||
onclick="return Wallet_ColumnSort('1', 'imagePermList');"/>
|
||||
</treerow>
|
||||
</treehead>
|
||||
<treechildren flex="1" id="imageslist"/>
|
||||
<treechildren flex="1" id="imagePermList"/>
|
||||
</tree>
|
||||
<box>
|
||||
<button id="removeImages" class="dialog push" disabled="true"
|
||||
label="&removeimage.label;"
|
||||
oncommand="DeleteImageSelected();"/>
|
||||
oncommand="DeleteImagePermissionSelected();"/>
|
||||
<button id="removeAllImages" class="dialog push"
|
||||
label="&removeallimages.label;"
|
||||
oncommand="DeleteAllImages();"/>
|
||||
oncommand="DeleteAllImagePermissions();"/>
|
||||
</box>
|
||||
</box>
|
||||
|
||||
|
@ -23,7 +23,7 @@ DEPTH=..\..
|
||||
|
||||
|
||||
|
||||
DIRS=public src editor signonviewer cookieviewer walletpreview build
|
||||
DIRS=public src editor signonviewer walletpreview build
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
|
@ -38,9 +38,10 @@
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsICookieService.h"
|
||||
#include "nsIImgManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIURL.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#define HOWMANY(x, r) (((x) + ((r) - 1)) / (r))
|
||||
#define ROUNDUP(x, r) (HOWMANY(x, r) * (r))
|
||||
@ -55,7 +56,7 @@ PRLogModuleInfo *il_log_module = NULL;
|
||||
/* Global list of image group contexts. */
|
||||
static IL_GroupContext *il_global_img_cx_list = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kCookieServiceCID, NS_COOKIESERVICE_CID);
|
||||
static NS_DEFINE_IID(kImgManagerCID, NS_IMGMANAGER_CID);
|
||||
|
||||
/*-----------------------------------------*/
|
||||
NS_IMETHODIMP ImgDCallbk::ImgDCBSetupColorspaceConverter()
|
||||
@ -1738,7 +1739,6 @@ il_hash(const char *ubuf)
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
/* block certain hosts from loading images */
|
||||
PRBool il_PermitLoad(const char * image_url, nsIImageRequestObserver * aObserver) {
|
||||
@ -1798,14 +1798,14 @@ PRBool il_PermitLoad(const char * image_url, nsIImageRequestObserver * aObserver
|
||||
}
|
||||
|
||||
/* check to see if we need to block image from loading */
|
||||
NS_WITH_SERVICE(nsICookieService, cookieservice, kCookieServiceCID, &rv);
|
||||
NS_WITH_SERVICE(nsIImgManager, imgmanager, kImgManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
Recycle(host);
|
||||
Recycle(firstHost);
|
||||
return PR_TRUE;
|
||||
}
|
||||
PRBool permission;
|
||||
rv = cookieservice->Image_CheckForPermission(host, firstHost, permission);
|
||||
rv = imgmanager->CheckForPermission(host, firstHost, &permission);
|
||||
Recycle(host);
|
||||
Recycle(firstHost);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -4251,18 +4251,15 @@ NS_IMETHODIMP nsPluginHostImpl::GetCookie(const char* inCookieURL, void* inOutCo
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = cookieService->GetCookieString(uriIn, cookieString);
|
||||
rv = cookieService->GetCookieString(uriIn, &bufPtr);
|
||||
|
||||
if (NS_FAILED(rv) ||
|
||||
(inOutCookieSize < cookieString.Length())) {
|
||||
if (NS_FAILED(rv) || (nsnull == bufPtr) ||
|
||||
(inOutCookieSize < PL_strlen(bufPtr))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
bufPtr = cookieString.ToCString((char *) inOutCookieBuffer,
|
||||
inOutCookieSize);
|
||||
if (nsnull == bufPtr) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
inOutCookieSize = cookieString.Length();
|
||||
inOutCookieSize = PL_strlen(bufPtr);
|
||||
rv = NS_OK;
|
||||
|
||||
return rv;
|
||||
@ -4271,7 +4268,6 @@ NS_IMETHODIMP nsPluginHostImpl::GetCookie(const char* inCookieURL, void* inOutCo
|
||||
NS_IMETHODIMP nsPluginHostImpl::SetCookie(const char* inCookieURL, const void* inCookieBuffer, PRUint32 inCookieSize)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
nsString cookieString;
|
||||
nsCOMPtr<nsIURI> uriIn;
|
||||
|
||||
if ((nsnull == inCookieURL) || (nsnull == inCookieBuffer) ||
|
||||
@ -4296,10 +4292,12 @@ NS_IMETHODIMP nsPluginHostImpl::SetCookie(const char* inCookieURL, const void* i
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
cookieString.AssignWithConversion((const char *) inCookieBuffer,(PRInt32) inCookieSize);
|
||||
|
||||
rv = cookieService->SetCookieString(uriIn, nsnull, cookieString); // needs an nsHTMLDocument parameter
|
||||
|
||||
char * cookie = (char *)inCookieBuffer;
|
||||
char c = cookie[inCookieSize];
|
||||
cookie[inCookieSize] = '\0';
|
||||
rv = cookieService->SetCookieString(uriIn, nsnull, cookie); // needs an nsIPrompt parameter
|
||||
cookie[inCookieSize] = c;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -4251,18 +4251,15 @@ NS_IMETHODIMP nsPluginHostImpl::GetCookie(const char* inCookieURL, void* inOutCo
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = cookieService->GetCookieString(uriIn, cookieString);
|
||||
rv = cookieService->GetCookieString(uriIn, &bufPtr);
|
||||
|
||||
if (NS_FAILED(rv) ||
|
||||
(inOutCookieSize < cookieString.Length())) {
|
||||
if (NS_FAILED(rv) || (nsnull == bufPtr) ||
|
||||
(inOutCookieSize < PL_strlen(bufPtr))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
bufPtr = cookieString.ToCString((char *) inOutCookieBuffer,
|
||||
inOutCookieSize);
|
||||
if (nsnull == bufPtr) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
inOutCookieSize = cookieString.Length();
|
||||
inOutCookieSize = PL_strlen(bufPtr);
|
||||
rv = NS_OK;
|
||||
|
||||
return rv;
|
||||
@ -4271,7 +4268,6 @@ NS_IMETHODIMP nsPluginHostImpl::GetCookie(const char* inCookieURL, void* inOutCo
|
||||
NS_IMETHODIMP nsPluginHostImpl::SetCookie(const char* inCookieURL, const void* inCookieBuffer, PRUint32 inCookieSize)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
nsString cookieString;
|
||||
nsCOMPtr<nsIURI> uriIn;
|
||||
|
||||
if ((nsnull == inCookieURL) || (nsnull == inCookieBuffer) ||
|
||||
@ -4296,10 +4292,12 @@ NS_IMETHODIMP nsPluginHostImpl::SetCookie(const char* inCookieURL, const void* i
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
cookieString.AssignWithConversion((const char *) inCookieBuffer,(PRInt32) inCookieSize);
|
||||
|
||||
rv = cookieService->SetCookieString(uriIn, nsnull, cookieString); // needs an nsHTMLDocument parameter
|
||||
|
||||
char * cookie = (char *)inCookieBuffer;
|
||||
char c = cookie[inCookieSize];
|
||||
cookie[inCookieSize] = '\0';
|
||||
rv = cookieService->SetCookieString(uriIn, nsnull, cookie); // needs an nsIPrompt parameter
|
||||
cookie[inCookieSize] = c;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -40,16 +40,26 @@
|
||||
element.setAttribute("disabled","true" );
|
||||
}
|
||||
|
||||
// for some unexplainable reason, CheckForImage() keeps getting called repeatedly
|
||||
// as we mouse over the task menu. IMO, that shouldn't be happening. To avoid
|
||||
// taking a performance hit due to this, we will set the following flag to avoid
|
||||
// reexecuting the routine
|
||||
var alreadyCheckedForImage = false;
|
||||
|
||||
// determine if we need to remove the image entries from the task menu
|
||||
function CheckForImage()
|
||||
{
|
||||
if (alreadyCheckedForImage) {
|
||||
return;
|
||||
}
|
||||
alreadyCheckedForImage = true;
|
||||
// remove image functions (unless overruled by the "imageblocker.enabled" pref)
|
||||
try {
|
||||
if (!this.pref.GetBoolPref("imageblocker.enabled")) {
|
||||
HideImage();
|
||||
}
|
||||
} catch(e) {
|
||||
HideImage();
|
||||
HideImage();
|
||||
dump("imageblocker.enabled pref is missing from all.js\n");
|
||||
}
|
||||
}
|
||||
@ -57,31 +67,33 @@
|
||||
// perform a Cookie or Image action
|
||||
function CookieImageAction(action) {
|
||||
|
||||
var cookieViewer =
|
||||
Components.classes["@mozilla.org/cookieviewer/cookieviewer-world;1"]
|
||||
.createInstance(Components.interfaces["nsICookieViewer"]);
|
||||
|
||||
var permissionmanager =
|
||||
Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService().QueryInterface(Components.interfaces.nsIPermissionManager);
|
||||
if (!permissionmanager) {
|
||||
return;
|
||||
}
|
||||
var COOKIEPERMISSION = 0;
|
||||
var IMAGEPERMISSION = 1;
|
||||
|
||||
var element;
|
||||
switch (action) {
|
||||
case "cookieAllow":
|
||||
cookieViewer.AddPermission(window._content, true, COOKIEPERMISSION);
|
||||
permissionmanager.add(window._content.location, true, COOKIEPERMISSION);
|
||||
element = document.getElementById("AllowCookies");
|
||||
alert(element.getAttribute("msg"));
|
||||
break;
|
||||
case "cookieBlock":
|
||||
cookieViewer.AddPermission(window._content, false, COOKIEPERMISSION);
|
||||
permissionmanager.add(window._content.location, false, COOKIEPERMISSION);
|
||||
element = document.getElementById("BlockCookies");
|
||||
alert(element.getAttribute("msg"));
|
||||
break;
|
||||
case "imageAllow":
|
||||
cookieViewer.AddPermission(window._content, true, IMAGEPERMISSION);
|
||||
permissionmanager.add(window._content.location, true, IMAGEPERMISSION);
|
||||
element = document.getElementById("AllowImages");
|
||||
alert(element.getAttribute("msg"));
|
||||
break;
|
||||
case "imageBlock":
|
||||
cookieViewer.AddPermission(window._content, false, IMAGEPERMISSION);
|
||||
permissionmanager.add(window._content.location, false, IMAGEPERMISSION);
|
||||
element = document.getElementById("BlockImages");
|
||||
alert(element.getAttribute("msg"));
|
||||
break;
|
||||
@ -93,7 +105,9 @@
|
||||
</script>
|
||||
|
||||
<!-- tasksOverlay menu items -->
|
||||
<menupopup id="personalManagers">
|
||||
<menupopup id="taskPopup" oncreate="CheckForImage()"/>
|
||||
|
||||
<menupopup id="personalManagers">
|
||||
<menu label="&cookieCookieManager.label;"
|
||||
accesskey="&cookieCookieManager.accesskey;"
|
||||
position="1">
|
||||
@ -112,9 +126,10 @@
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menu label="&cookieImageManager.label;"
|
||||
accesskey="&cookieImageManager.accesskey;" id="image"
|
||||
accesskey="&cookieImageManager.accesskey;"
|
||||
id="image"
|
||||
position="2">
|
||||
<menupopup oncreate="CheckForImage()">
|
||||
<menupopup>
|
||||
<menuitem label="&cookieDisplayImagesCmd.label;"
|
||||
accesskey="&cookieDisplayImagesCmd.accesskey;"
|
||||
oncommand="viewImages();"/>
|
||||
|
@ -54,33 +54,39 @@
|
||||
}
|
||||
|
||||
/* determine if image is already being blocked */
|
||||
var cookieViewer = contextMenu.createInstance
|
||||
("@mozilla.org/cookieviewer/cookieviewer-world;1", "nsICookieViewer");
|
||||
var list = cookieViewer.GetPermissionValue(1);
|
||||
var permissionList = list.split(list[0]);
|
||||
for(var i = 1; i < permissionList.length; i+=2) {
|
||||
var permStr = permissionList[i+1];
|
||||
var type = permStr.substring(0,1);
|
||||
if (type == "-") {
|
||||
/* some host is being blocked, need to find out if it's our image's host */
|
||||
var host = permStr.substring(1,permStr.length);
|
||||
var permissionmanager =
|
||||
Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService().QueryInterface(Components.interfaces.nsIPermissionManager);
|
||||
|
||||
|
||||
var enumerator = permissionmanager.enumerator;
|
||||
while (enumerator.hasMoreElements()) {
|
||||
var nextPermission = enumerator.getNext();
|
||||
nextPermission = nextPermission.QueryInterface(Components.interfaces.nsIPermission);
|
||||
var imageType = 1;
|
||||
if (nextPermission.type == imageType &&
|
||||
!nextPermission.capability) {
|
||||
/* some image host is being blocked, need to find out if it's our image's host */
|
||||
var host = nextPermission.host;
|
||||
if(host.charAt(0) == ".") { // get rid of the ugly dot on the start of some domains
|
||||
host = host.substring(1,host.length);
|
||||
}
|
||||
if (host && contextMenu.imageURL.search(host) != -1) {
|
||||
/* it's our image's host that's being blocked */
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* image is not already being blocked, so "Block Image" can appear on the menu */
|
||||
return true;
|
||||
},
|
||||
|
||||
// Block image from loading in the future.
|
||||
blockImage : function () {
|
||||
var cookieViewer =
|
||||
contextMenu.createInstance("@mozilla.org/cookieviewer/cookieviewer-world;1",
|
||||
"nsICookieViewer" );
|
||||
cookieViewer.BlockImage(contextMenu.imageURL);
|
||||
var imgmanager =
|
||||
Components.classes["@mozilla.org/imgmanager;1"]
|
||||
.getService().QueryInterface(Components.interfaces.nsIImgManager);
|
||||
imgmanager.block(contextMenu.imageURL);
|
||||
},
|
||||
|
||||
initImageBlocking : function () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user