From c784518ba23a8582fbbd75a6663efe2132761ce7 Mon Sep 17 00:00:00 2001 From: "timeless%mozdev.org" Date: Wed, 22 Jan 2003 05:52:33 +0000 Subject: [PATCH] Bug 179798 cookie confirm dialog no longer works in embedding (doesn't call nsIPrompt service) patch by mvl@exedo.nl r=dwitte sr=darin git-svn-id: svn://10.0.0.236/trunk@136820 18797224-902f-48f8-a5cc-f745e15eee43 --- .../public/nsIDialogParamBlock.idl | 22 ++- .../windowwatcher/src/nsDialogParamBlock.cpp | 16 ++ .../windowwatcher/src/nsDialogParamBlock.h | 5 +- .../windowwatcher/src/nsPromptService.cpp | 12 +- mozilla/extensions/cookie/MANIFEST_IDL | 1 + mozilla/extensions/cookie/Makefile.in | 4 +- mozilla/extensions/cookie/macbuild/cookie.xml | 30 ++++ .../extensions/cookie/macbuild/cookieIDL.xml | 30 ++++ mozilla/extensions/cookie/nsCookie.cpp | 44 ++---- mozilla/extensions/cookie/nsCookie.h | 23 ++- mozilla/extensions/cookie/nsCookieManager.cpp | 10 +- .../cookie/nsCookiePromptService.cpp | 118 +++++++++++++++ .../extensions/cookie/nsCookiePromptService.h | 60 ++++++++ mozilla/extensions/cookie/nsCookies.cpp | 78 ++++------ mozilla/extensions/cookie/nsCookies.h | 10 +- .../cookie/nsICookieAcceptDialog.idl | 14 +- .../cookie/nsICookiePromptService.idl | 73 +++++++++ mozilla/extensions/cookie/nsImages.cpp | 2 +- mozilla/extensions/cookie/nsModuleFactory.cpp | 7 + mozilla/extensions/cookie/nsPermissions.cpp | 141 +++++++----------- mozilla/extensions/cookie/nsPermissions.h | 4 +- .../resources/content/cookieAcceptDialog.js | 60 +++++--- .../resources/locale/en-US/cookie.properties | 11 +- .../en-US/cookieAcceptDialog.properties | 8 + .../manager/pki/src/nsPKIParamBlock.cpp | 15 ++ .../cookie/content/cookieAcceptDialog.js | 60 +++++--- .../en-US/chrome/cookie/cookie.properties | 11 +- .../cookie/cookieAcceptDialog.properties | 8 + 28 files changed, 607 insertions(+), 270 deletions(-) create mode 100644 mozilla/extensions/cookie/nsCookiePromptService.cpp create mode 100644 mozilla/extensions/cookie/nsCookiePromptService.h create mode 100644 mozilla/extensions/cookie/nsICookiePromptService.idl diff --git a/mozilla/embedding/components/windowwatcher/public/nsIDialogParamBlock.idl b/mozilla/embedding/components/windowwatcher/public/nsIDialogParamBlock.idl index f221b057d28..c045c5f0438 100644 --- a/mozilla/embedding/components/windowwatcher/public/nsIDialogParamBlock.idl +++ b/mozilla/embedding/components/windowwatcher/public/nsIDialogParamBlock.idl @@ -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++ diff --git a/mozilla/embedding/components/windowwatcher/src/nsDialogParamBlock.cpp b/mozilla/embedding/components/windowwatcher/src/nsDialogParamBlock.cpp index 9a0e9e1f27a..c9b85202faf 100644 --- a/mozilla/embedding/components/windowwatcher/src/nsDialogParamBlock.cpp +++ b/mozilla/embedding/components/windowwatcher/src/nsDialogParamBlock.cpp @@ -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; +} + + diff --git a/mozilla/embedding/components/windowwatcher/src/nsDialogParamBlock.h b/mozilla/embedding/components/windowwatcher/src/nsDialogParamBlock.h index 359346b0489..d60be05384f 100644 --- a/mozilla/embedding/components/windowwatcher/src/nsDialogParamBlock.h +++ b/mozilla/embedding/components/windowwatcher/src/nsDialogParamBlock.h @@ -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 mObjects; }; #endif diff --git a/mozilla/embedding/components/windowwatcher/src/nsPromptService.cpp b/mozilla/embedding/components/windowwatcher/src/nsPromptService.cpp index 0200a0cec91..a38451d943d 100644 --- a/mozilla/embedding/components/windowwatcher/src/nsPromptService.cpp +++ b/mozilla/embedding/components/windowwatcher/src/nsPromptService.cpp @@ -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; } diff --git a/mozilla/extensions/cookie/MANIFEST_IDL b/mozilla/extensions/cookie/MANIFEST_IDL index 8910e1040e3..bd0b0599c52 100644 --- a/mozilla/extensions/cookie/MANIFEST_IDL +++ b/mozilla/extensions/cookie/MANIFEST_IDL @@ -5,3 +5,4 @@ nsIPermission.idl nsIPermissionManager.idl nsICookieConsent.idl nsICookieAcceptDialog.idl +nsICookiePromptService.idl diff --git a/mozilla/extensions/cookie/Makefile.in b/mozilla/extensions/cookie/Makefile.in index 216523433fe..2bcd85857a9 100644 --- a/mozilla/extensions/cookie/Makefile.in +++ b/mozilla/extensions/cookie/Makefile.in @@ -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) diff --git a/mozilla/extensions/cookie/macbuild/cookie.xml b/mozilla/extensions/cookie/macbuild/cookie.xml index b05c523c084..46a7fd201aa 100644 --- a/mozilla/extensions/cookie/macbuild/cookie.xml +++ b/mozilla/extensions/cookie/macbuild/cookie.xml @@ -1041,6 +1041,13 @@ Text Debug + + Name + nsCookiePromptService.cpp + MacOS + Text + Debug + Name nsPopupWindowManager.cpp @@ -1144,6 +1151,11 @@ nsPermissionManager.cpp MacOS + + Name + nsCookiePromptService.cpp + MacOS + Name nsPopupWindowManager.cpp @@ -2149,6 +2161,13 @@ Text Debug + + Name + nsCookiePromptService.cpp + MacOS + Text + Debug + Name nsPopupWindowManager.cpp @@ -2252,6 +2271,11 @@ nsPermissionManager.cpp MacOS + + Name + nsCookiePromptService.cpp + MacOS + Name nsPopupWindowManager.cpp @@ -2338,6 +2362,12 @@ nsPermissionManager.cpp MacOS + + Cookie.shlb + Name + nsCookiePromptService.cpp + MacOS + Cookie.shlb Name diff --git a/mozilla/extensions/cookie/macbuild/cookieIDL.xml b/mozilla/extensions/cookie/macbuild/cookieIDL.xml index 97e9183e0bb..ab9b3ded7fb 100644 --- a/mozilla/extensions/cookie/macbuild/cookieIDL.xml +++ b/mozilla/extensions/cookie/macbuild/cookieIDL.xml @@ -776,6 +776,13 @@ Text + + Name + nsICookiePromptSerice.idl + MacOS + Text + + Name nsICookieAcceptDialog.idl @@ -825,6 +832,11 @@ nsIPermissionManager.idl MacOS + + Name + nsICookiePromptService.idl + MacOS + Name nsICookieAcceptDialog.idl @@ -1555,6 +1567,13 @@ Text + + Name + nsICookiePromptService.idl + MacOS + Text + + Name nsICookieAcceptDialog.idl @@ -1605,6 +1624,11 @@ MacOS + Name + nsICookiePromptService.idl + MacOS + + Name nsICookieAcceptDialog.idl MacOS @@ -1667,6 +1691,12 @@ nsIPermissionManager.idl MacOS + + headers + Name + nsICookiePromptService.idl + MacOS + headers Name diff --git a/mozilla/extensions/cookie/nsCookie.cpp b/mozilla/extensions/cookie/nsCookie.cpp index 9f4f9c8c0dc..effb4ba86e7 100644 --- a/mozilla/extensions/cookie/nsCookie.cpp +++ b/mozilla/extensions/cookie/nsCookie.cpp @@ -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) { diff --git a/mozilla/extensions/cookie/nsCookie.h b/mozilla/extensions/cookie/nsCookie.h index 29ae8d1c766..5b827b58b33 100644 --- a/mozilla/extensions/cookie/nsCookie.h +++ b/mozilla/extensions/cookie/nsCookie.h @@ -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} diff --git a/mozilla/extensions/cookie/nsCookieManager.cpp b/mozilla/extensions/cookie/nsCookieManager.cpp index 8aeba10af19..6d279782f39 100644 --- a/mozilla/extensions/cookie/nsCookieManager.cpp +++ b/mozilla/extensions/cookie/nsCookieManager.cpp @@ -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 = diff --git a/mozilla/extensions/cookie/nsCookiePromptService.cpp b/mozilla/extensions/cookie/nsCookiePromptService.cpp new file mode 100644 index 00000000000..d475d2bbba5 --- /dev/null +++ b/mozilla/extensions/cookie/nsCookiePromptService.cpp @@ -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 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 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 wwatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr parent = aParent; + if (!parent) { + wwatcher->GetActiveWindow(getter_AddRefs(parent)); + } + + nsCOMPtr arguments = do_QueryInterface(block); + nsCOMPtr 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; +} + diff --git a/mozilla/extensions/cookie/nsCookiePromptService.h b/mozilla/extensions/cookie/nsCookiePromptService.h new file mode 100644 index 00000000000..4f312a3c6c6 --- /dev/null +++ b/mozilla/extensions/cookie/nsCookiePromptService.h @@ -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 diff --git a/mozilla/extensions/cookie/nsCookies.cpp b/mozilla/extensions/cookie/nsCookies.cpp index 76abe71126b..7c0c601e348 100644 --- a/mozilla/extensions/cookie/nsCookies.cpp +++ b/mozilla/extensions/cookie/nsCookies.cpp @@ -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; } + diff --git a/mozilla/extensions/cookie/nsCookies.h b/mozilla/extensions/cookie/nsCookies.h index 78610a822d6..6c64505ba8a 100644 --- a/mozilla/extensions/cookie/nsCookies.h +++ b/mozilla/extensions/cookie/nsCookies.h @@ -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, diff --git a/mozilla/extensions/cookie/nsICookieAcceptDialog.idl b/mozilla/extensions/cookie/nsICookieAcceptDialog.idl index 1192400346c..e178c441fe2 100644 --- a/mozilla/extensions/cookie/nsICookieAcceptDialog.idl +++ b/mozilla/extensions/cookie/nsICookieAcceptDialog.idl @@ -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; }; diff --git a/mozilla/extensions/cookie/nsICookiePromptService.idl b/mozilla/extensions/cookie/nsICookiePromptService.idl new file mode 100644 index 00000000000..6a448f054de --- /dev/null +++ b/mozilla/extensions/cookie/nsICookiePromptService.idl @@ -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" +%} diff --git a/mozilla/extensions/cookie/nsImages.cpp b/mozilla/extensions/cookie/nsImages.cpp index 354926fd77c..019db112100 100644 --- a/mozilla/extensions/cookie/nsImages.cpp +++ b/mozilla/extensions/cookie/nsImages.cpp @@ -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; } diff --git a/mozilla/extensions/cookie/nsModuleFactory.cpp b/mozilla/extensions/cookie/nsModuleFactory.cpp index b27b66a1593..4d277638dcc 100644 --- a/mozilla/extensions/cookie/nsModuleFactory.cpp +++ b/mozilla/extensions/cookie/nsModuleFactory.cpp @@ -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, diff --git a/mozilla/extensions/cookie/nsPermissions.cpp b/mozilla/extensions/cookie/nsPermissions.cpp index 559520a2a83..8cdf6d3ac98 100644 --- a/mozilla/extensions/cookie/nsPermissions.cpp +++ b/mozilla/extensions/cookie/nsPermissions.cpp @@ -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 wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (!wwatch) { - *checkValue = 0; - return PR_FALSE; - } + if (aCookie) { + nsCOMPtr cookiePromptService = do_GetService(NS_COOKIEPROMPTSERVICE_CONTRACTID,&rv); + if (NS_FAILED(rv)) return rv; - nsCOMPtr activeParent; - nsCOMPtr active; - wwatch->GetActiveWindow(getter_AddRefs(active)); - - nsCOMPtr 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 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 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; } diff --git a/mozilla/extensions/cookie/nsPermissions.h b/mozilla/extensions/cookie/nsPermissions.h index 1caac2bd2ab..86253ab17f6 100644 --- a/mozilla/extensions/cookie/nsPermissions.h +++ b/mozilla/extensions/cookie/nsPermissions.h @@ -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 diff --git a/mozilla/extensions/cookie/resources/content/cookieAcceptDialog.js b/mozilla/extensions/cookie/resources/content/cookieAcceptDialog.js index 1181ccf1cad..609d7bd48e6 100644 --- a/mozilla/extensions/cookie/resources/content/cookieAcceptDialog.js +++ b/mozilla/extensions/cookie/resources/content/cookieAcceptDialog.js @@ -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) { } } diff --git a/mozilla/extensions/cookie/resources/locale/en-US/cookie.properties b/mozilla/extensions/cookie/resources/locale/en-US/cookie.properties index 3f97b914325..3b0d09934ab 100644 --- a/mozilla/extensions/cookie/resources/locale/en-US/cookie.properties +++ b/mozilla/extensions/cookie/resources/locale/en-US/cookie.properties @@ -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 diff --git a/mozilla/extensions/cookie/resources/locale/en-US/cookieAcceptDialog.properties b/mozilla/extensions/cookie/resources/locale/en-US/cookieAcceptDialog.properties index 62b5dc1c390..43d7eeb8845 100644 --- a/mozilla/extensions/cookie/resources/locale/en-US/cookieAcceptDialog.properties +++ b/mozilla/extensions/cookie/resources/locale/en-US/cookieAcceptDialog.properties @@ -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 diff --git a/mozilla/security/manager/pki/src/nsPKIParamBlock.cpp b/mozilla/security/manager/pki/src/nsPKIParamBlock.cpp index 069666167a4..0acb3c24df5 100644 --- a/mozilla/security/manager/pki/src/nsPKIParamBlock.cpp +++ b/mozilla/security/manager/pki/src/nsPKIParamBlock.cpp @@ -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) diff --git a/mozilla/toolkit/components/cookie/content/cookieAcceptDialog.js b/mozilla/toolkit/components/cookie/content/cookieAcceptDialog.js index 1181ccf1cad..609d7bd48e6 100644 --- a/mozilla/toolkit/components/cookie/content/cookieAcceptDialog.js +++ b/mozilla/toolkit/components/cookie/content/cookieAcceptDialog.js @@ -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) { } } diff --git a/mozilla/toolkit/locales/en-US/chrome/cookie/cookie.properties b/mozilla/toolkit/locales/en-US/chrome/cookie/cookie.properties index 3f97b914325..3b0d09934ab 100644 --- a/mozilla/toolkit/locales/en-US/chrome/cookie/cookie.properties +++ b/mozilla/toolkit/locales/en-US/chrome/cookie/cookie.properties @@ -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 diff --git a/mozilla/toolkit/locales/en-US/chrome/cookie/cookieAcceptDialog.properties b/mozilla/toolkit/locales/en-US/chrome/cookie/cookieAcceptDialog.properties index 62b5dc1c390..43d7eeb8845 100644 --- a/mozilla/toolkit/locales/en-US/chrome/cookie/cookieAcceptDialog.properties +++ b/mozilla/toolkit/locales/en-US/chrome/cookie/cookieAcceptDialog.properties @@ -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