2012-05-21 11:12:37 +00: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/. */
|
2003-01-22 05:52:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsCookiePromptService.h"
|
2003-10-11 22:13:05 +00:00
|
|
|
#include "nsICookie.h"
|
2003-01-22 05:52:33 +00:00
|
|
|
#include "nsICookieAcceptDialog.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2009-01-23 05:33:10 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2003-01-22 05:52:33 +00:00
|
|
|
#include "nsIWindowWatcher.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIDialogParamBlock.h"
|
2006-04-12 15:43:32 +00:00
|
|
|
#include "nsIMutableArray.h"
|
2014-08-13 15:55:28 +00:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2003-01-22 05:52:33 +00:00
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
************************ nsCookiePromptService *****************
|
|
|
|
****************************************************************/
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsCookiePromptService, nsICookiePromptService)
|
2003-01-22 05:52:33 +00:00
|
|
|
|
|
|
|
nsCookiePromptService::nsCookiePromptService() {
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCookiePromptService::~nsCookiePromptService() {
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCookiePromptService::CookieDialog(nsIDOMWindow *aParent,
|
|
|
|
nsICookie *aCookie,
|
|
|
|
const nsACString &aHostname,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aCookiesFromHost,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aChangingCookie,
|
|
|
|
bool *aRememberDecision,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t *aAccept)
|
2003-01-22 05:52:33 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDialogParamBlock> block = do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID,&rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
block->SetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, 1);
|
2006-02-03 14:18:39 +00:00
|
|
|
block->SetString(nsICookieAcceptDialog::HOSTNAME, NS_ConvertUTF8toUTF16(aHostname).get());
|
2003-01-22 05:52:33 +00:00
|
|
|
block->SetInt(nsICookieAcceptDialog::COOKIESFROMHOST, aCookiesFromHost);
|
2011-04-14 15:25:00 +00:00
|
|
|
block->SetInt(nsICookieAcceptDialog::CHANGINGCOOKIE, aChangingCookie ? 1 : 0);
|
2003-01-22 05:52:33 +00:00
|
|
|
|
2006-04-12 15:43:32 +00:00
|
|
|
nsCOMPtr<nsIMutableArray> objects =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
2003-01-22 05:52:33 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = objects->AppendElement(aCookie, false);
|
2003-01-22 05:52:33 +00: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-27 01:59:47 +00:00
|
|
|
|
2009-01-23 05:33:10 +00: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);
|
|
|
|
}
|
|
|
|
|
2014-08-13 15:55:28 +00:00
|
|
|
// We're opening a chrome window and passing in a nsIDialogParamBlock. Setting
|
|
|
|
// the nsIDialogParamBlock as the .arguments property on the chrome window
|
|
|
|
// requires system principals on the stack, so we use an AutoNoJSAPI for that.
|
|
|
|
mozilla::dom::AutoNoJSAPI nojsapi;
|
|
|
|
|
2009-01-23 05:33:10 +00:00
|
|
|
// 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-27 01:59:47 +00:00
|
|
|
"centerscreen,chrome,modal,titlebar", arguments,
|
|
|
|
getter_AddRefs(dialog));
|
2003-01-22 05:52:33 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// get back output parameters
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t tempValue;
|
2003-01-22 05:52:33 +00:00
|
|
|
block->GetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, &tempValue);
|
2004-01-29 03:34:58 +00:00
|
|
|
*aAccept = tempValue;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
// GetInt returns a int32_t; we need to sanitize it into bool
|
2003-01-22 05:52:33 +00:00
|
|
|
block->GetInt(nsICookieAcceptDialog::REMEMBER_DECISION, &tempValue);
|
2003-03-22 01:24:51 +00:00
|
|
|
*aRememberDecision = (tempValue == 1);
|
2003-01-22 05:52:33 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|