2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsCookiePromptService.h"
|
|
|
|
#include "nsICookie.h"
|
|
|
|
#include "nsICookieAcceptDialog.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2009-01-22 21:33:10 -08:00
|
|
|
#include "nsPIDOMWindow.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#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,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aCookiesFromHost,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aChangingCookie,
|
|
|
|
bool *aRememberDecision,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t *aAccept)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
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);
|
2011-04-14 08:25:00 -07:00
|
|
|
block->SetInt(nsICookieAcceptDialog::CHANGINGCOOKIE, aChangingCookie ? 1 : 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIMutableArray> objects =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = objects->AppendElement(aCookie, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
2008-11-26 17:59:47 -08:00
|
|
|
|
2009-01-22 21:33:10 -08:00
|
|
|
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",
|
2008-11-26 17:59:47 -08:00
|
|
|
"centerscreen,chrome,modal,titlebar", arguments,
|
|
|
|
getter_AddRefs(dialog));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// get back output parameters
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t tempValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
block->GetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, &tempValue);
|
|
|
|
*aAccept = tempValue;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
// GetInt returns a int32_t; we need to sanitize it into bool
|
2007-03-22 10:30:00 -07:00
|
|
|
block->GetInt(nsICookieAcceptDialog::REMEMBER_DECISION, &tempValue);
|
|
|
|
*aRememberDecision = (tempValue == 1);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|