gecko/extensions/cookie/nsCookiePromptService.cpp
Ehsan Akhgari 0fd9123eac Bug 579517 - Part 1: Automated conversion of NSPR numeric types to stdint types in Gecko; r=bsmedberg
This patch was generated by a script.  Here's the source of the script for
future reference:

function convert() {
echo "Converting $1 to $2..."
find . ! -wholename "*nsprpub*" \
       ! -wholename "*security/nss*" \
       ! -wholename "*/.hg*" \
       ! -wholename "obj-ff-dbg*" \
       ! -name nsXPCOMCID.h \
       ! -name prtypes.h \
         -type f \
      \( -iname "*.cpp" \
         -o -iname "*.h" \
         -o -iname "*.c" \
         -o -iname "*.cc" \
         -o -iname "*.idl" \
         -o -iname "*.ipdl" \
         -o -iname "*.ipdlh" \
         -o -iname "*.mm" \) | \
    xargs -n 1 sed -i -e "s/\b$1\b/$2/g"
}

convert PRInt8 int8_t
convert PRUint8 uint8_t
convert PRInt16 int16_t
convert PRUint16 uint16_t
convert PRInt32 int32_t
convert PRUint32 uint32_t
convert PRInt64 int64_t
convert PRUint64 uint64_t

convert PRIntn int
convert PRUintn unsigned

convert PRSize size_t

convert PROffset32 int32_t
convert PROffset64 int64_t

convert PRPtrdiff ptrdiff_t

convert PRFloat64 double
2012-08-22 11:56:38 -04:00

96 lines
3.4 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCookiePromptService.h"
#include "nsICookie.h"
#include "nsICookieAcceptDialog.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include "nsIWindowWatcher.h"
#include "nsIServiceManager.h"
#include "nsString.h"
#include "nsIDialogParamBlock.h"
#include "nsIMutableArray.h"
/****************************************************************
************************ nsCookiePromptService *****************
****************************************************************/
NS_IMPL_ISUPPORTS1(nsCookiePromptService, nsICookiePromptService)
nsCookiePromptService::nsCookiePromptService() {
}
nsCookiePromptService::~nsCookiePromptService() {
}
NS_IMETHODIMP
nsCookiePromptService::CookieDialog(nsIDOMWindow *aParent,
nsICookie *aCookie,
const nsACString &aHostname,
int32_t aCookiesFromHost,
bool aChangingCookie,
bool *aRememberDecision,
int32_t *aAccept)
{
nsresult rv;
nsCOMPtr<nsIDialogParamBlock> block = do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID,&rv);
if (NS_FAILED(rv)) return rv;
block->SetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, 1);
block->SetString(nsICookieAcceptDialog::HOSTNAME, NS_ConvertUTF8toUTF16(aHostname).get());
block->SetInt(nsICookieAcceptDialog::COOKIESFROMHOST, aCookiesFromHost);
block->SetInt(nsICookieAcceptDialog::CHANGINGCOOKIE, aChangingCookie ? 1 : 0);
nsCOMPtr<nsIMutableArray> objects =
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
rv = objects->AppendElement(aCookie, 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<nsISupports> arguments = do_QueryInterface(block);
nsCOMPtr<nsIDOMWindow> dialog;
nsCOMPtr<nsIDOMWindow> parent(aParent);
if (!parent) // if no parent provided, consult the window watcher:
wwatcher->GetActiveWindow(getter_AddRefs(parent));
if (parent) {
nsCOMPtr<nsPIDOMWindow> privateParent(do_QueryInterface(parent));
if (privateParent)
privateParent = privateParent->GetPrivateRoot();
parent = do_QueryInterface(privateParent);
}
// The cookie dialog will be modal for the root chrome window rather than the
// tab containing the permission-requesting page. This removes confusion
// about which monitor is displaying the dialog (see bug 470356), but also
// avoids unwanted tab switches (see bug 405239).
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
int32_t tempValue;
block->GetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, &tempValue);
*aAccept = tempValue;
// GetInt returns a int32_t; we need to sanitize it into bool
block->GetInt(nsICookieAcceptDialog::REMEMBER_DECISION, &tempValue);
*aRememberDecision = (tempValue == 1);
return rv;
}