Bug 179798 cookie confirm dialog no longer works in embedding (doesn't call nsIPrompt service)

patch by mvl@exedo.nl r=dwitte sr=darin
This commit is contained in:
timeless@mozdev.org
2003-01-22 05:52:33 +00:00
parent b5907325b5
commit 37175c7583
28 changed files with 607 additions and 270 deletions

View File

@@ -37,16 +37,36 @@
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
interface nsIMutableArray;
/**
* An interface to pass strings, integers and nsISupports to a dialog
*/
[scriptable, uuid(f76c0901-437a-11d3-b7a0-e35db351b4bc)]
interface nsIDialogParamBlock: nsISupports {
void SetNumberStrings( in PRInt32 inNumStrings );
/** Get or set an interger to pass.
* Index must be in the range 0..7
*/
PRInt32 GetInt( in PRInt32 inIndex );
void SetInt( in PRInt32 inIndex, in PRInt32 inInt );
/** Set the maximum number of strings to pass. Default is 16.
* Use before setting any string (If you want to change it from the default).
*/
void SetNumberStrings( in PRInt32 inNumStrings );
/** Get or set an string to pass.
* Index starts at 0
*/
wstring GetString( in PRInt32 inIndex );
void SetString( in PRInt32 inIndex, in wstring inString);
/**
* A place where you can store an nsIMutableArray to pass nsISupports
*/
attribute nsIMutableArray objects;
};
%{C++

View File

@@ -103,3 +103,19 @@ NS_IMETHODIMP nsDialogParamBlock::SetString(PRInt32 inIndex, const PRUnichar *in
return rv;
}
NS_IMETHODIMP
nsDialogParamBlock::GetObjects(nsIMutableArray * *aObjects)
{
NS_ENSURE_ARG_POINTER(aObjects);
NS_IF_ADDREF(*aObjects = mObjects);
return NS_OK;
}
NS_IMETHODIMP
nsDialogParamBlock::SetObjects(nsIMutableArray * aObjects)
{
mObjects = aObjects;
return NS_OK;
}

View File

@@ -40,6 +40,8 @@
#define __nsDialogParamBlock_h
#include "nsIDialogParamBlock.h"
#include "nsIArray.h"
#include "nsCOMPtr.h"
// {4E4AAE11-8901-46cc-8217-DAD7C5415873}
#define NS_DIALOGPARAMBLOCK_CID \
@@ -66,7 +68,8 @@ private:
PRInt32 mInt[kNumInts];
PRInt32 mNumStrings;
nsString* mString;
nsString* mString;
nsCOMPtr<nsIMutableArray> mObjects;
};
#endif

View File

@@ -338,7 +338,9 @@ nsPromptService::ConfirmEx(nsIDOMWindow *parent,
if (checkMsg && checkValue) {
block->SetString(eCheckboxMsg, checkMsg);
block->SetInt(eCheckboxState, *checkValue);
// since we're setting a PRInt32, we have to sanitize the PRBool first.
// (myBool != PR_FALSE) is guaranteed to return either 1 or 0.
block->SetInt(eCheckboxState, *checkValue != PR_FALSE);
}
/* perform the dialog */
@@ -352,8 +354,12 @@ nsPromptService::ConfirmEx(nsIDOMWindow *parent,
if (buttonPressed)
block->GetInt(eButtonPressed, buttonPressed);
if (checkMsg && checkValue)
block->GetInt(eCheckboxState, checkValue);
if (checkMsg && checkValue) {
// GetInt returns a PRInt32; we need to sanitize it into PRBool
PRInt32 tempValue;
block->GetInt(eCheckboxState, &tempValue);
*checkValue = (tempValue == 1);
}
return rv;
}

View File

@@ -5,3 +5,4 @@ nsIPermission.idl
nsIPermissionManager.idl
nsICookieConsent.idl
nsICookieAcceptDialog.idl
nsICookiePromptService.idl

View File

@@ -65,6 +65,7 @@ CPPSRCS = \
nsPermissions.cpp \
nsUtils.cpp \
nsCookieHTTPNotify.cpp \
nsCookiePromptService.cpp \
$(NULL)
SDK_XPIDLSRCS = \
@@ -77,7 +78,8 @@ XPIDLSRCS = \
nsIImgManager.idl \
nsIPermissionManager.idl \
nsIPermission.idl \
nsICookieAcceptDialog.idl \
nsICookieAcceptDialog.idl \
nsICookiePromptService.idl \
nsICookieManager2.idl \
$(NULL)

View File

@@ -1041,6 +1041,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsCookiePromptService.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPopupWindowManager.cpp</PATH>
@@ -1144,6 +1151,11 @@
<PATH>nsPermissionManager.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsCookiePromptService.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPopupWindowManager.cpp</PATH>
@@ -2149,6 +2161,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsCookiePromptService.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPopupWindowManager.cpp</PATH>
@@ -2252,6 +2271,11 @@
<PATH>nsPermissionManager.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsCookiePromptService.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPopupWindowManager.cpp</PATH>
@@ -2338,6 +2362,12 @@
<PATH>nsPermissionManager.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>Cookie.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsCookiePromptService.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>Cookie.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

View File

@@ -776,6 +776,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsICookiePromptSerice.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsICookieAcceptDialog.idl</PATH>
@@ -825,6 +832,11 @@
<PATH>nsIPermissionManager.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsICookiePromptService.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsICookieAcceptDialog.idl</PATH>
@@ -1555,6 +1567,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsICookiePromptService.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsICookieAcceptDialog.idl</PATH>
@@ -1605,6 +1624,11 @@
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsICookiePromptService.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsICookieAcceptDialog.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
@@ -1667,6 +1691,12 @@
<PATH>nsIPermissionManager.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>headers</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsICookiePromptService.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>headers</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

View File

@@ -56,11 +56,11 @@ nsCookie::nsCookie()
}
nsCookie::nsCookie
(char * name,
char * value,
(const nsACString &name,
const nsACString &value,
PRBool isDomain,
char * host,
char * path,
const nsACString &host,
const nsACString &path,
PRBool isSecure,
PRUint64 expires,
nsCookieStatus status,
@@ -78,30 +78,16 @@ nsCookie::nsCookie
}
nsCookie::~nsCookie(void) {
if (cookieName)
nsCRT::free(cookieName);
if (cookieValue)
nsCRT::free(cookieValue);
if (cookieHost)
nsCRT::free(cookieHost);
if (cookiePath)
nsCRT::free(cookiePath);
}
NS_IMETHODIMP nsCookie::GetName(nsACString& aName) {
if (cookieName) {
aName = cookieName;
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
aName = cookieName;
return NS_OK;
}
NS_IMETHODIMP nsCookie::GetValue(nsACString& aValue) {
if (cookieValue) {
aValue = cookieValue;
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
aValue = cookieValue;
return NS_OK;
}
NS_IMETHODIMP nsCookie::GetIsDomain(PRBool *aIsDomain) {
@@ -112,21 +98,15 @@ NS_IMETHODIMP nsCookie::GetIsDomain(PRBool *aIsDomain) {
NS_IMETHODIMP nsCookie::GetHost(nsACString& aHost) {
//NS_IMETHODIMP nsCookie::GetHost(nsAUTF8String& aHost) {
// using nsACString above instead of nsAUTF8String because the latter doesn't exist yet
if (cookieHost) {
aHost = cookieHost;
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
aHost = cookieHost;
return NS_OK;
}
NS_IMETHODIMP nsCookie::GetPath(nsACString& aPath) {
//NS_IMETHODIMP nsCookie::GetPath(nsAUTF8String& aPath) {
// using nsACString above instead of nsAUTF8String because the latter doesn't exist yet
if (cookiePath) {
aPath = cookiePath;
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
aPath = cookiePath;
return NS_OK;
}
NS_IMETHODIMP nsCookie::GetIsSecure(PRBool *aIsSecure) {

View File

@@ -41,6 +41,7 @@
#include "nsICookie.h"
#include "nsWeakReference.h"
#include "nsString.h"
////////////////////////////////////////////////////////////////////////////////
@@ -52,15 +53,12 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSICOOKIE
// 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,
(const nsACString &name,
const nsACString &value,
PRBool isDomain,
char * host,
char * path,
const nsACString &host,
const nsACString &path,
PRBool isSecure,
PRUint64 expires,
nsCookieStatus status,
@@ -70,15 +68,16 @@ public:
virtual ~nsCookie(void);
protected:
char * cookieName;
char * cookieValue;
nsCString cookieName;
nsCString cookieValue;
PRBool cookieIsDomain;
char * cookieHost;
char * cookiePath;
nsCString cookieHost;
nsCString cookiePath;
PRBool cookieIsSecure;
PRUint64 cookieExpires;
nsCookieStatus cookieStatus;
nsCookiePolicy cookiePolicy;
nsCookiePolicy cookiePolicy;
};
// {E9FCB9A4-D376-458f-B720-E65E7DF593BC}

View File

@@ -67,17 +67,17 @@ class nsCookieEnumerator : public nsISimpleEnumerator
NS_IMETHOD GetNext(nsISupports **result)
{
char *name;
char *value;
nsCAutoString name;
nsCAutoString value;
PRBool isDomain;
char * host;
char * path;
nsCAutoString host;
nsCAutoString path;
PRBool isSecure;
PRUint64 expires;
nsCookieStatus status;
nsCookiePolicy policy;
nsresult rv = COOKIE_Enumerate
(mCookieCount++, &name, &value, &isDomain, &host, &path, &isSecure, &expires,
(mCookieCount++, name, value, &isDomain, host, path, &isSecure, &expires,
&status, &policy);
if (NS_SUCCEEDED(rv)) {
nsICookie *cookie =

View File

@@ -0,0 +1,118 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 cookie manager code.
*
* The Initial Developer of the Original Code is
* Michiel van Leeuwen (mvl@exedo.nl).
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCookiePromptService.h"
#include "nsCookie.h"
#include "nsICookieAcceptDialog.h"
#include "nsIDOMWindow.h"
#include "nsIWindowWatcher.h"
#include "nsIServiceManager.h"
#include "nsString.h"
#include "nsIDialogParamBlock.h"
#include "nsArray.h"
/****************************************************************
************************ nsCookiePromptService *****************
****************************************************************/
NS_IMPL_ISUPPORTS1(nsCookiePromptService, nsICookiePromptService);
nsCookiePromptService::nsCookiePromptService() {
}
nsCookiePromptService::~nsCookiePromptService() {
}
NS_IMETHODIMP
nsCookiePromptService::CookieDialog(nsIDOMWindow *aParent,
nsICookie *aCookie,
const nsACString &aHostname,
PRInt32 aCookiesFromHost,
PRBool aChangingCookie,
PRBool *aCheckValue,
PRBool *aAccept)
{
nsresult rv;
nsCOMPtr<nsIDialogParamBlock> block = do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID,&rv);
if (NS_FAILED(rv)) return rv;
// since we're setting PRInt32's here, we have to sanitize the PRBool's first.
// (myBool != PR_FALSE) is guaranteed to return either 1 or 0.
block->SetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, 1);
block->SetInt(nsICookieAcceptDialog::REMEMBER_DECISION, *aCheckValue != PR_FALSE);
block->SetString(nsICookieAcceptDialog::HOSTNAME, NS_ConvertUTF8toUCS2(aHostname).get());
block->SetInt(nsICookieAcceptDialog::COOKIESFROMHOST, aCookiesFromHost);
block->SetInt(nsICookieAcceptDialog::CHANGINGCOOKIE, aChangingCookie != PR_FALSE);
nsCOMPtr<nsIMutableArray> objects;
rv = NS_NewArray(getter_AddRefs(objects));
if (NS_FAILED(rv)) return rv;
rv = objects->AppendElement(aCookie, PR_FALSE);
if (NS_FAILED(rv)) return rv;
block->SetObjects(objects);
nsCOMPtr<nsIWindowWatcher> wwatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMWindow> parent = aParent;
if (!parent) {
wwatcher->GetActiveWindow(getter_AddRefs(parent));
}
nsCOMPtr<nsISupports> arguments = do_QueryInterface(block);
nsCOMPtr<nsIDOMWindow> dialog;
rv = wwatcher->OpenWindow(parent, "chrome://cookie/content/cookieAcceptDialog.xul", "_blank",
"centerscreen,chrome,modal,titlebar", arguments,
getter_AddRefs(dialog));
if (NS_FAILED(rv)) return rv;
// get back output parameters
// GetInt returns a PRInt32; we need to sanitize it into PRBool
PRBool tempValue;
block->GetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, &tempValue);
*aAccept = (tempValue == 1);
block->GetInt(nsICookieAcceptDialog::REMEMBER_DECISION, &tempValue);
*aCheckValue = (tempValue == 1);
return rv;
}

View File

@@ -0,0 +1,60 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 cookie manager code.
*
* The Initial Developer of the Original Code is
* Michiel van Leeuwen (mvl@exedo.nl).
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsCookiePromptService_h__
#define nsCookiePromptService_h__
#include "nsICookiePromptService.h"
class nsCookiePromptService : public nsICookiePromptService {
public:
nsCookiePromptService();
virtual ~nsCookiePromptService();
NS_DECL_NSICOOKIEPROMPTSERVICE
NS_DECL_ISUPPORTS
private:
};
// {CE002B28-92B7-4701-8621-CC925866FB87}
#define NS_COOKIEPROMPTSERVICE_CID \
{0xCE002B28, 0x92B7, 0x4701, {0x86, 0x21, 0xCC, 0x92, 0x58, 0x66, 0xFB, 0x87}}
#endif

View File

@@ -1513,65 +1513,38 @@ cookie_SetCookieString(nsIURI * curURL, nsIPrompt *aPrompter, const char * setCo
CKutil_StrAllocCopy(name_from_header, "");
}
/* generate the message for the nag box */
int count = cookie_Count(host_from_header);
prev_cookie = cookie_CheckForPrevCookie
(path_from_header, host_from_header, name_from_header);
const char *message_string;
if (prev_cookie) {
message_string = "PermissionToModifyCookie";
} else if (count>1) {
message_string = "PermissionToSetAnotherCookie";
} else if (count==1){
message_string = "PermissionToSetSecondCookie";
} else {
message_string = "PermissionToSetACookie";
}
//TRACEMSG(("mkaccess.c: Setting cookie: %s for host: %s for path: %s",
// cookie_from_header, host_from_header, path_from_header));
/* construct a new (temporary) cookie_struct, for the nag box */
cookie_CookieStruct * this_cookie;
this_cookie = PR_NEW(cookie_CookieStruct);
if (!this_cookie) {
PR_FREEIF(path_from_header);
PR_FREEIF(host_from_header);
PR_FREEIF(name_from_header);
PR_FREEIF(cookie_from_header);
nsCRT::free(setCookieHeaderInternal);
#if defined(PR_LOGGING)
cookie_LogFailure(SET_COOKIE, curURL, setCookieHeader, "Unable to allocate memory for new cookie");
#endif
return;
}
// put the cookie information into the temporary struct.
// just copy pointers to the char * strings (cookie_from_header etc).
// we still own the strings, and we must free them if the cookie is
// rejected.
this_cookie->cookie = cookie_from_header;
this_cookie->name = name_from_header;
this_cookie->path = path_from_header;
this_cookie->host = host_from_header;
this_cookie->expires = cookie_TrimLifetime(timeToExpire);
this_cookie->isSecure = isSecure;
this_cookie->isDomain = isDomain;
this_cookie->lastAccessed = get_current_time();
this_cookie->status = status;
this_cookie->policy = cookie_GetPolicy(P3P_SitePolicy(curURL, aHttpChannel));
/* use common code to determine if we can set the cookie */
PRBool permission = PR_TRUE;
if (NS_SUCCEEDED(PERMISSION_Read())) {
PRBool modify = prev_cookie != nsnull;
// put the cookie information into the cookie structure.
nsICookie *thisCookie =
new nsCookie(nsDependentCString(name_from_header),
nsDependentCString(cookie_from_header),
isDomain,
nsDependentCString(host_from_header),
nsDependentCString(path_from_header),
isSecure,
cookie_TrimLifetime(timeToExpire),
status,
cookie_GetPolicy(P3P_SitePolicy(curURL, aHttpChannel)));
permission = Permission_Check(aPrompter, host_from_header, COOKIEPERMISSION,
// I believe this is the right place to eventually add the logic to ask
// about cookies that have excessive lifetimes, but it shouldn't be done
// until generalized per-site preferences are available.
//cookie_GetLifetimeAsk(timeToExpire) ||
cookie_GetWarningPref(),
this_cookie,
message_string, count);
thisCookie,
count, modify);
}
if (!permission) {
PR_FREEIF(path_from_header);
@@ -2060,11 +2033,11 @@ COOKIE_Count() {
PUBLIC nsresult
COOKIE_Enumerate
(PRInt32 count,
char **name,
char **value,
nsACString &name,
nsACString &value,
PRBool *isDomain,
char ** host,
char ** path,
nsACString &host,
nsACString &path,
PRBool * isSecure,
PRUint64 * expires,
nsCookieStatus * status,
@@ -2080,11 +2053,11 @@ COOKIE_Enumerate
cookie = NS_STATIC_CAST(cookie_CookieStruct*, cookie_list->ElementAt(count));
NS_ASSERTION(cookie, "corrupt cookie list");
*name = cookie_FixQuoted(cookie->name);
*value = cookie_FixQuoted(cookie->cookie);
name = cookie_FixQuoted(cookie->name);
value = cookie_FixQuoted(cookie->cookie);
*isDomain = cookie->isDomain;
*host = cookie_FixQuoted(cookie->host);
*path = cookie_FixQuoted(cookie->path);
host = cookie_FixQuoted(cookie->host);
path = cookie_FixQuoted(cookie->path);
*isSecure = cookie->isSecure;
// *expires = cookie->expires; -- no good on mac, using next line instead
LL_UI2L(*expires, cookie->expires);
@@ -2250,3 +2223,4 @@ cookie_ParseDate(char *date_string, time_t & date) {
}
return NS_ERROR_FAILURE;
}

View File

@@ -66,11 +66,11 @@ extern void COOKIE_DeletePersistentUserData(void);
extern PRInt32 COOKIE_Count();
extern nsresult COOKIE_Enumerate
(PRInt32 count,
char **name,
char **value,
PRBool *isDomain,
char ** host,
char ** path,
nsACString & name,
nsACString & value,
PRBool * isDomain,
nsACString & host,
nsACString & path,
PRBool * isSecure,
PRUint64 * expires,
nsCookieStatus * status,

View File

@@ -47,15 +47,7 @@ interface nsICookieAcceptDialog: nsISupports {
const short ACCEPT_COOKIE=0;
const short REMEMBER_DECISION=1;
const short MESSAGETEXT=2;
const short COOKIE_NAME=3;
const short COOKIE_VALUE=4;
const short COOKIE_HOST=5;
const short COOKIE_PATH=6;
// Continue at a lower number, as > 7 gives problems (max int number is 8),
// And you the next items are Int's and not Strings.
// Int's and Strings are separate, thay can have the same index
const short COOKIE_IS_SECURE=3;
const short COOKIE_EXPIRES=4;
const short COOKIE_IS_DOMAIN=5;
const short HOSTNAME=2;
const short COOKIESFROMHOST=3;
const short CHANGINGCOOKIE=4;
};

View File

@@ -0,0 +1,73 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 cookie manager code.
*
* The Initial Developer of the Original Code is
* Michiel van Leeuwen (mvl@exedo.nl).
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
/**
* An interface to open a dialog to ask to permission to accept the cookie.
*/
interface nsIDOMWindow;
interface nsICookie;
[scriptable, uuid(CE002B28-92B7-4701-8621-CC925866FB87)]
interface nsICookiePromptService : nsISupports
{
/* Open a dialog that asks for permission to accept a cookie
* Returns true when the permission is given.
* return values are not modified when something fails.
*
* @param parent
* @param cookie
* @param hostname the host that wants to set the cookie,
* not the domain: part of the cookie
* @param cookiesFromHost the number of cookies there are already for this host
* @param aChangingCookie are we changing this cookie?
* @param checkValue is the decision remembered?
*/
boolean cookieDialog(in nsIDOMWindow parent,
in nsICookie cookie,
in ACString hostname,
in long cookiesFromHost,
in boolean changingCookie,
inout boolean checkValue);
};
%{C++
#define NS_COOKIEPROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/cookieprompt-service;1"
%}

View File

@@ -198,7 +198,7 @@ IMAGE_CheckForPermission
if (NS_SUCCEEDED(PERMISSION_Read())) {
*permission = Permission_Check(0, hostname, IMAGEPERMISSION,
PR_FALSE /* gWarningPref */, nsnull,
"PermissionToAcceptImage", 0);
0, PR_FALSE);
} else {
*permission = PR_TRUE;
}

View File

@@ -52,6 +52,7 @@
#include "nsCookieHTTPNotify.h"
#include "nsICategoryManager.h"
#include "nsXPIDLString.h"
#include "nsCookiePromptService.h"
// Define the constructor function for the objects
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCookie)
@@ -62,6 +63,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsImgManager, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPermissionManager, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPopupWindowManager, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieHTTPNotify, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCookiePromptService)
static NS_METHOD
RegisterContentPolicy(nsIComponentManager *aCompMgr, nsIFile *aPath,
@@ -133,6 +135,11 @@ static const nsModuleComponentInfo components[] = {
NS_POPUPWINDOWMANAGER_CONTRACTID,
nsPopupWindowManagerConstructor
},
{ "CookiePromptService",
NS_COOKIEPROMPTSERVICE_CID,
NS_COOKIEPROMPTSERVICE_CONTRACTID,
nsCookiePromptServiceConstructor
},
{ NS_COOKIEHTTPNOTIFY_CLASSNAME,
NS_COOKIEHTTPNOTIFY_CID,
NS_COOKIEHTTPNOTIFY_CONTRACTID,

View File

@@ -46,10 +46,6 @@
#include "nsReadableUtils.h"
#include "nsIFileSpec.h"
#include "nsIPrompt.h"
#include "nsIWindowWatcher.h"
#include "nsIDOMWindow.h"
#include "nsIDOMWindowInternal.h"
#include "nsIDialogParamBlock.h"
#include "nsVoidArray.h"
#include "prmem.h"
#include "nsAppDirectoryServiceDefs.h"
@@ -58,8 +54,10 @@
#include "nsTextFormatter.h"
#include "nsIObserverService.h"
#include "nsComObsolete.h"
#include "nsIWindowWatcher.h"
#include "nsICookieAcceptDialog.h"
#include "nsCookiePromptService.h"
static const char *kCookiesPermFileName = "cookperm.txt";
@@ -82,63 +80,31 @@ PRIVATE PRBool window_rememberChecked;
PRIVATE nsVoidArray * permission_list=0;
PRBool
permission_CheckConfirmYN(nsIPrompt *aPrompter, PRUnichar * szMessage, PRUnichar * szCheckMessage, cookie_CookieStruct *cookie_s, PRBool* checkValue) {
permission_CheckConfirmYN(nsIPrompt *aPrompter,
nsICookie *aCookie,
const char *aHostname,
int aCookiesFromHost,
PRBool aChangingCookie,
PRBool* aCheckValue) {
nsresult res;
PRInt32 buttonPressed = 1; /* in case user exits dialog by clickin X */
PRUnichar * confirm_string = CKutil_Localize(NS_LITERAL_STRING("Confirm").get());
nsresult rv;
PRBool acceptThis = PR_TRUE;
if (cookie_s) {
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!wwatch) {
*checkValue = 0;
return PR_FALSE;
}
if (aCookie) {
nsCOMPtr<nsICookiePromptService> cookiePromptService = do_GetService(NS_COOKIEPROMPTSERVICE_CONTRACTID,&rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMWindowInternal> activeParent;
nsCOMPtr<nsIDOMWindow> active;
wwatch->GetActiveWindow(getter_AddRefs(active));
nsCOMPtr<nsIDialogParamBlock> block(do_CreateInstance("@mozilla.org/embedcomp/dialogparam;1"));
if (!block) {
*checkValue = 0;
buttonPressed = 1;
return PR_TRUE;
}
block->SetString(nsICookieAcceptDialog::MESSAGETEXT, szMessage);
block->SetInt(nsICookieAcceptDialog::REMEMBER_DECISION, *checkValue);
NS_ConvertASCIItoUCS2 cookieName(cookie_s->name);
NS_ConvertASCIItoUCS2 cookieValue(cookie_s->cookie);
NS_ConvertASCIItoUCS2 cookieHost(cookie_s->host);
NS_ConvertASCIItoUCS2 cookiePath(cookie_s->path);
block->SetString(nsICookieAcceptDialog::COOKIE_NAME, cookieName.get());
block->SetString(nsICookieAcceptDialog::COOKIE_VALUE, cookieValue.get());
block->SetString(nsICookieAcceptDialog::COOKIE_HOST, cookieHost.get());
block->SetString(nsICookieAcceptDialog::COOKIE_PATH, cookiePath.get());
block->SetInt(nsICookieAcceptDialog::COOKIE_IS_SECURE, cookie_s->isSecure);
block->SetInt(nsICookieAcceptDialog::COOKIE_EXPIRES, cookie_s->expires);
block->SetInt(nsICookieAcceptDialog::COOKIE_IS_DOMAIN, cookie_s->isDomain);
nsCOMPtr<nsIDOMWindow> dialogwin;
res = wwatch->OpenWindow(active, "chrome://cookie/content/cookieAcceptDialog.xul", "_blank",
"centerscreen,chrome,modal,titlebar", block,
getter_AddRefs(dialogwin));
if (NS_FAILED(res)) {
*checkValue = 0;
buttonPressed = 1;
}
else {
/* get back output parameters */
PRInt32 acceptCookie;
block->GetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, &acceptCookie);
buttonPressed = acceptCookie ? 0 : 1;
block->GetInt(nsICookieAcceptDialog::REMEMBER_DECISION, checkValue);
rv = cookiePromptService->
CookieDialog(nsnull, aCookie, nsDependentCString(aHostname),
aCookiesFromHost, aChangingCookie, aCheckValue,
&acceptThis);
if (NS_FAILED(rv)) {
*aCheckValue = PR_FALSE;
}
}
else {
nsCOMPtr<nsIPrompt> dialog;
PRInt32 buttonPressed = 1; /* In case the user closed the dialog using a window manager feature */
if (aPrompter)
dialog = aPrompter;
@@ -148,27 +114,34 @@ permission_CheckConfirmYN(nsIPrompt *aPrompter, PRUnichar * szMessage, PRUnichar
wwatch->GetNewPrompter(0, getter_AddRefs(dialog));
}
if (!dialog) {
*checkValue = 0;
*aCheckValue = PR_FALSE;
return PR_FALSE;
}
res = dialog->ConfirmEx(confirm_string, szMessage,
PRUnichar * confirm_string = CKutil_Localize(NS_LITERAL_STRING("Confirm").get());
PRUnichar * message_fmt = CKutil_Localize(NS_LITERAL_STRING("PermissionToAcceptImage").get());
PRUnichar * message = nsTextFormatter::smprintf(message_fmt,
aHostname ? aHostname : "", aCookiesFromHost);
PRUnichar * remember_string = CKutil_Localize(NS_LITERAL_STRING("RememberThisDecision").get());
rv = dialog->ConfirmEx(confirm_string, message,
(nsIPrompt::BUTTON_TITLE_YES * nsIPrompt::BUTTON_POS_0) +
(nsIPrompt::BUTTON_TITLE_NO * nsIPrompt::BUTTON_POS_1),
nsnull, nsnull, nsnull, szCheckMessage, checkValue, &buttonPressed);
nsnull, nsnull, nsnull, remember_string, aCheckValue, &buttonPressed);
if (NS_FAILED(res)) {
*checkValue = 0;
nsTextFormatter::smprintf_free(message);
nsMemory::Free(confirm_string);
nsMemory::Free(remember_string);
nsMemory::Free(message_fmt);
if (NS_FAILED(rv)) {
*aCheckValue = PR_FALSE;
}
acceptThis = (buttonPressed == 1);
}
if (*checkValue!=0 && *checkValue!=1) {
NS_ASSERTION(PR_FALSE, "Bad result from checkbox");
*checkValue = 0; /* this should never happen but it is happening!!! */
}
Recycle(confirm_string);
return (buttonPressed == 0);
return acceptThis;
}
/*
@@ -244,51 +217,43 @@ permission_SetRememberChecked(PRInt32 type, PRBool value) {
PUBLIC PRBool
Permission_Check(
nsIPrompt *aPrompter,
const char * hostname,
PRInt32 type,
PRBool warningPref,
cookie_CookieStruct *cookie_s,
const char * message_string,
int count_for_message)
const char *aHostname,
PRInt32 aType,
PRBool aWarningPref,
nsICookie *aCookie,
int aCookiesFromHost,
PRBool aChangingCookie)
{
PRBool permission;
/* try to make decision based on saved permissions */
if (NS_SUCCEEDED(permission_CheckFromList(hostname, permission, type))) {
if (NS_SUCCEEDED(permission_CheckFromList(aHostname, permission, aType))) {
return permission;
}
/* see if we need to prompt */
if(!warningPref) {
if(!aWarningPref) {
return PR_TRUE;
}
/* we need to prompt */
PRUnichar * message_fmt =
CKutil_Localize(NS_ConvertASCIItoUCS2(message_string).get());
PRUnichar * message = nsTextFormatter::smprintf(message_fmt,
hostname ? hostname : "", count_for_message);
PRBool rememberChecked = permission_GetRememberChecked(type);
PRUnichar * remember_string = CKutil_Localize(NS_LITERAL_STRING("RememberThisDecision").get());
permission = permission_CheckConfirmYN(aPrompter, message, remember_string, cookie_s, &rememberChecked);
nsTextFormatter::smprintf_free(message);
nsMemory::Free(message_fmt);
PRBool rememberChecked = permission_GetRememberChecked(aType);
permission = permission_CheckConfirmYN(aPrompter, aCookie, aHostname, aCookiesFromHost, aChangingCookie, &rememberChecked);
/* see if we need to remember this decision */
if (rememberChecked) {
/* ignore leading periods in host name */
const char * hostnameAfterDot = hostname;
const char * hostnameAfterDot = aHostname;
while (hostnameAfterDot && (*hostnameAfterDot == '.')) {
hostnameAfterDot++;
}
Permission_AddHost(nsDependentCString(hostnameAfterDot), permission, type, PR_TRUE);
Permission_AddHost(nsDependentCString(hostnameAfterDot), permission, aType, PR_TRUE);
}
if (rememberChecked != permission_GetRememberChecked(type)) {
permission_SetRememberChecked(type, rememberChecked);
if (rememberChecked != permission_GetRememberChecked(aType)) {
permission_SetRememberChecked(aType, rememberChecked);
permission_changed = PR_TRUE;
Permission_Save(PR_TRUE);
}
Recycle(remember_string);
return permission;
}

View File

@@ -73,8 +73,8 @@ extern nsresult PERMISSION_Enumerate
extern void PERMISSION_Remove(const nsACString & host, PRInt32 type);
extern PRBool Permission_Check
(nsIPrompt *aPrompter, const char * hostname, PRInt32 type,
PRBool warningPref, cookie_CookieStruct * cookie_s, const char * message_string, int count_for_message);
(nsIPrompt *aPrompter, const char *aHostname, PRInt32 aType,
PRBool aWarningPref, nsICookie *aCookie, int aCookiesFromHost, PRBool aChangingCookie);
extern nsresult Permission_AddHost
(const nsAFlatCString &host, PRBool permission, PRInt32 type, PRBool save);
extern nsresult permission_CheckFromList

View File

@@ -34,8 +34,9 @@
*
* ***** END LICENSE BLOCK ***** */
const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
const nsICookieAcceptDialog = Components.interfaces.nsICookieAcceptDialog;
const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
const nsICookie = Components.interfaces.nsICookie;
var params;
var cookieBundle;
@@ -76,8 +77,31 @@ function onload()
if ("arguments" in window && window.arguments.length >= 1 && window.arguments[0]) {
try {
params = window.arguments[0].QueryInterface(nsIDialogParamBlock);
var objects = params.objects;
var cookie = params.objects.queryElementAt(0,nsICookie);
var cookiesFromHost = params.GetInt(nsICookieAcceptDialog.COOKIESFROMHOST);
var messageFormat;
if (params.GetInt(nsICookieAcceptDialog.CHANGINGCOOKIE))
messageFormat = 'permissionToModifyCookie';
else if (cookiesFromHost > 1)
messageFormat = 'permissionToSetAnotherCookie';
else if (cookiesFromHost == 1)
messageFormat = 'permissionToSetSecondCookie';
else
messageFormat = 'permissionToSetACookie';
var hostname = params.GetString(nsICookieAcceptDialog.HOSTNAME);
var messageText;
if (cookie)
messageText = cookieBundle.getFormattedString(messageFormat,[cookie.host,cookiesFromHost]);
else
// No cookies means something went wrong. Bring up the dialog anyway
// to not make the mess worse.
messageText = cookieBundle.getFormattedString(messageFormat,["",cookiesFromHost]);
var messageText = params.GetString(nsICookieAcceptDialog.MESSAGETEXT);
var messageParent = document.getElementById("info.box");
var messageParagraphs = messageText.split("\n");
@@ -90,23 +114,23 @@ function onload()
document.getElementById('persistDomainAcceptance').checked = params.GetInt(nsICookieAcceptDialog.REMEMBER_DECISION) > 0;
document.getElementById('ifl_name').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_NAME));
document.getElementById('ifl_value').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_VALUE));
document.getElementById('ifl_host').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_HOST));
document.getElementById('ifl_path').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_PATH));
document.getElementById('ifl_isSecure').setAttribute("value",
params.GetInt(nsICookieAcceptDialog.COOKIE_IS_SECURE) ?
cookieBundle.getString("yes") : cookieBundle.getString("no")
if (cookie) {
document.getElementById('ifl_name').setAttribute("value",cookie.name);
document.getElementById('ifl_value').setAttribute("value",cookie.value);
document.getElementById('ifl_host').setAttribute("value",cookie.host);
document.getElementById('ifl_path').setAttribute("value",cookie.path);
document.getElementById('ifl_isSecure').setAttribute("value",
cookie.isSecure ?
cookieBundle.getString("yes") : cookieBundle.getString("no")
);
document.getElementById('ifl_expires').setAttribute("value",GetExpiresString(params.GetInt(nsICookieAcceptDialog.COOKIE_EXPIRES)));
document.getElementById('ifl_isDomain').setAttribute("value",
params.GetInt(nsICookieAcceptDialog.COOKIE_IS_DOMAIN) ?
cookieBundle.getString("domainColon") : cookieBundle.getString("hostColon")
);
// set default result to cancelled
params.SetInt(eAcceptCookie, 0);
document.getElementById('ifl_expires').setAttribute("value",GetExpiresString(cookie.expires));
document.getElementById('ifl_isDomain').setAttribute("value",
cookie.isDomain ?
cookieBundle.getString("domainColon") : cookieBundle.getString("hostColon")
);
}
// set default result to not accept the cookie
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 0);
} catch (e) {
}
}

View File

@@ -26,14 +26,5 @@ AtEndOfSession = at end of session
Confirm = Confirm
# LOCALIZATION NOTE (PermissionToSetACookie) : Be careful about %1$s. Do Not localize it.
PermissionToSetACookie = The site %1$s wants to set a cookie. Do you want to allow it?
# LOCALIZATION NOTE (PermissionToSetSecondCookie): Be careful about %1$s. Do Not localize it.
PermissionToSetSecondCookie = The site %1$s wants to set a second cookie. Do you want to allow it?
# LOCALIZATION NOTE (PermissionToSetAnotherCookie): Be careful about %1$s, %2$d. Do Not localize them.
PermissionToSetAnotherCookie = The site %1$s wants permission to set another cookie. You already have %2$d cookies from this site. Do you want to allow it?
# LOCALIZATION NOTE (PermissionToModifyCookie): Be careful about %1$s. Do Not localize it.
PermissionToModifyCookie = The site %1$s wants to modify an existing cookie. Do you want to allow it?
# LOCALIZATION NOTE (PermissionToModifyCookie): Be careful about %1$s. Do Not localize it.
PermissionToAcceptImage = The site %1$s wants to load an image. Do you want to allow it?
PermissionToAcceptImage = The site %s wants to load an image. Do you want to allow it?
RememberThisDecision = Remember this decision

View File

@@ -6,3 +6,11 @@ atEndOfSession=at end of session
showDetails=Show Details
hideDetails=Hide Details
permissionToSetACookie = The site %S wants to set a cookie. Do you want to allow it?
permissionToSetSecondCookie = The site %S wants to set a second cookie. Do you want to allow it?
# LOCALIZATION NOTE (PermissionToSetAnotherCookie): First %S: sitename, second %S: number of cookies already present for that site
permissionToSetAnotherCookie = The site %S wants permission to set another cookie. You already have %S cookies from this site. Do you want to allow it?
permissionToModifyCookie = The site %S wants to modify an existing cookie. Do you want to allow it?
permissionToAcceptImage = The site %S wants to load an image. Do you want to allow it?
rememberThisDecision = Remember this decision

View File

@@ -36,6 +36,7 @@
#include "nsPKIParamBlock.h"
#include "nsIServiceManager.h"
#include "nsIDialogParamBlock.h"
#include "nsIArray.h"
NS_IMPL_THREADSAFE_ISUPPORTS2(nsPKIParamBlock, nsIPKIParamBlock,
nsIDialogParamBlock)
@@ -87,6 +88,20 @@ nsPKIParamBlock::SetString(PRInt32 inIndex, const PRUnichar *inString)
return mDialogParamBlock->SetString(inIndex, inString);
}
NS_IMETHODIMP
nsPKIParamBlock::GetObjects(nsIMutableArray * *aObjects)
{
return mDialogParamBlock->GetObjects(aObjects);
}
NS_IMETHODIMP
nsPKIParamBlock::SetObjects(nsIMutableArray * aObjects)
{
return mDialogParamBlock->SetObjects(aObjects);
}
/* void setISupportAtIndex (in PRInt32 index, in nsISupports object); */
NS_IMETHODIMP
nsPKIParamBlock::SetISupportAtIndex(PRInt32 index, nsISupports *object)

View File

@@ -34,8 +34,9 @@
*
* ***** END LICENSE BLOCK ***** */
const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
const nsICookieAcceptDialog = Components.interfaces.nsICookieAcceptDialog;
const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
const nsICookie = Components.interfaces.nsICookie;
var params;
var cookieBundle;
@@ -76,8 +77,31 @@ function onload()
if ("arguments" in window && window.arguments.length >= 1 && window.arguments[0]) {
try {
params = window.arguments[0].QueryInterface(nsIDialogParamBlock);
var objects = params.objects;
var cookie = params.objects.queryElementAt(0,nsICookie);
var cookiesFromHost = params.GetInt(nsICookieAcceptDialog.COOKIESFROMHOST);
var messageFormat;
if (params.GetInt(nsICookieAcceptDialog.CHANGINGCOOKIE))
messageFormat = 'permissionToModifyCookie';
else if (cookiesFromHost > 1)
messageFormat = 'permissionToSetAnotherCookie';
else if (cookiesFromHost == 1)
messageFormat = 'permissionToSetSecondCookie';
else
messageFormat = 'permissionToSetACookie';
var hostname = params.GetString(nsICookieAcceptDialog.HOSTNAME);
var messageText;
if (cookie)
messageText = cookieBundle.getFormattedString(messageFormat,[cookie.host,cookiesFromHost]);
else
// No cookies means something went wrong. Bring up the dialog anyway
// to not make the mess worse.
messageText = cookieBundle.getFormattedString(messageFormat,["",cookiesFromHost]);
var messageText = params.GetString(nsICookieAcceptDialog.MESSAGETEXT);
var messageParent = document.getElementById("info.box");
var messageParagraphs = messageText.split("\n");
@@ -90,23 +114,23 @@ function onload()
document.getElementById('persistDomainAcceptance').checked = params.GetInt(nsICookieAcceptDialog.REMEMBER_DECISION) > 0;
document.getElementById('ifl_name').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_NAME));
document.getElementById('ifl_value').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_VALUE));
document.getElementById('ifl_host').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_HOST));
document.getElementById('ifl_path').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_PATH));
document.getElementById('ifl_isSecure').setAttribute("value",
params.GetInt(nsICookieAcceptDialog.COOKIE_IS_SECURE) ?
cookieBundle.getString("yes") : cookieBundle.getString("no")
if (cookie) {
document.getElementById('ifl_name').setAttribute("value",cookie.name);
document.getElementById('ifl_value').setAttribute("value",cookie.value);
document.getElementById('ifl_host').setAttribute("value",cookie.host);
document.getElementById('ifl_path').setAttribute("value",cookie.path);
document.getElementById('ifl_isSecure').setAttribute("value",
cookie.isSecure ?
cookieBundle.getString("yes") : cookieBundle.getString("no")
);
document.getElementById('ifl_expires').setAttribute("value",GetExpiresString(params.GetInt(nsICookieAcceptDialog.COOKIE_EXPIRES)));
document.getElementById('ifl_isDomain').setAttribute("value",
params.GetInt(nsICookieAcceptDialog.COOKIE_IS_DOMAIN) ?
cookieBundle.getString("domainColon") : cookieBundle.getString("hostColon")
);
// set default result to cancelled
params.SetInt(eAcceptCookie, 0);
document.getElementById('ifl_expires').setAttribute("value",GetExpiresString(cookie.expires));
document.getElementById('ifl_isDomain').setAttribute("value",
cookie.isDomain ?
cookieBundle.getString("domainColon") : cookieBundle.getString("hostColon")
);
}
// set default result to not accept the cookie
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 0);
} catch (e) {
}
}

View File

@@ -26,14 +26,5 @@ AtEndOfSession = at end of session
Confirm = Confirm
# LOCALIZATION NOTE (PermissionToSetACookie) : Be careful about %1$s. Do Not localize it.
PermissionToSetACookie = The site %1$s wants to set a cookie. Do you want to allow it?
# LOCALIZATION NOTE (PermissionToSetSecondCookie): Be careful about %1$s. Do Not localize it.
PermissionToSetSecondCookie = The site %1$s wants to set a second cookie. Do you want to allow it?
# LOCALIZATION NOTE (PermissionToSetAnotherCookie): Be careful about %1$s, %2$d. Do Not localize them.
PermissionToSetAnotherCookie = The site %1$s wants permission to set another cookie. You already have %2$d cookies from this site. Do you want to allow it?
# LOCALIZATION NOTE (PermissionToModifyCookie): Be careful about %1$s. Do Not localize it.
PermissionToModifyCookie = The site %1$s wants to modify an existing cookie. Do you want to allow it?
# LOCALIZATION NOTE (PermissionToModifyCookie): Be careful about %1$s. Do Not localize it.
PermissionToAcceptImage = The site %1$s wants to load an image. Do you want to allow it?
PermissionToAcceptImage = The site %s wants to load an image. Do you want to allow it?
RememberThisDecision = Remember this decision

View File

@@ -6,3 +6,11 @@ atEndOfSession=at end of session
showDetails=Show Details
hideDetails=Hide Details
permissionToSetACookie = The site %S wants to set a cookie. Do you want to allow it?
permissionToSetSecondCookie = The site %S wants to set a second cookie. Do you want to allow it?
# LOCALIZATION NOTE (PermissionToSetAnotherCookie): First %S: sitename, second %S: number of cookies already present for that site
permissionToSetAnotherCookie = The site %S wants permission to set another cookie. You already have %S cookies from this site. Do you want to allow it?
permissionToModifyCookie = The site %S wants to modify an existing cookie. Do you want to allow it?
permissionToAcceptImage = The site %S wants to load an image. Do you want to allow it?
rememberThisDecision = Remember this decision