Backout 30bfb150da06 (bug 449315) due to unit test timeouts.
[wine-gecko.git] / extensions / cookie / nsCookiePromptService.cpp
blob5f1cdff95b270ad77c5cba33fa53964617a53f31
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is cookie manager code.
16 * The Initial Developer of the Original Code is
17 * Michiel van Leeuwen (mvl@exedo.nl).
18 * Portions created by the Initial Developer are Copyright (C) 2003
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
38 #include "nsCookiePromptService.h"
39 #include "nsICookie.h"
40 #include "nsICookieAcceptDialog.h"
41 #include "nsIDOMWindow.h"
42 #include "nsIWindowWatcher.h"
43 #include "nsIServiceManager.h"
44 #include "nsString.h"
45 #include "nsIDialogParamBlock.h"
46 #include "nsIMutableArray.h"
48 /****************************************************************
49 ************************ nsCookiePromptService *****************
50 ****************************************************************/
52 NS_IMPL_ISUPPORTS1(nsCookiePromptService, nsICookiePromptService)
54 nsCookiePromptService::nsCookiePromptService() {
57 nsCookiePromptService::~nsCookiePromptService() {
60 NS_IMETHODIMP
61 nsCookiePromptService::CookieDialog(nsIDOMWindow *aParent,
62 nsICookie *aCookie,
63 const nsACString &aHostname,
64 PRInt32 aCookiesFromHost,
65 PRBool aChangingCookie,
66 PRBool *aRememberDecision,
67 PRInt32 *aAccept)
69 nsresult rv;
71 nsCOMPtr<nsIDialogParamBlock> block = do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID,&rv);
72 if (NS_FAILED(rv)) return rv;
74 // since we're setting PRInt32's here, we have to sanitize the PRBool's first.
75 // (myBool != PR_FALSE) is guaranteed to return either 1 or 0.
76 block->SetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, 1);
77 block->SetString(nsICookieAcceptDialog::HOSTNAME, NS_ConvertUTF8toUTF16(aHostname).get());
78 block->SetInt(nsICookieAcceptDialog::COOKIESFROMHOST, aCookiesFromHost);
79 block->SetInt(nsICookieAcceptDialog::CHANGINGCOOKIE, aChangingCookie != PR_FALSE);
81 nsCOMPtr<nsIMutableArray> objects =
82 do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
83 if (NS_FAILED(rv)) return rv;
85 rv = objects->AppendElement(aCookie, PR_FALSE);
86 if (NS_FAILED(rv)) return rv;
88 block->SetObjects(objects);
90 nsCOMPtr<nsIWindowWatcher> wwatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
91 if (NS_FAILED(rv)) return rv;
93 nsCOMPtr<nsIDOMWindow> parent = aParent;
94 if (!parent) {
95 wwatcher->GetActiveWindow(getter_AddRefs(parent));
98 nsCOMPtr<nsISupports> arguments = do_QueryInterface(block);
99 nsCOMPtr<nsIDOMWindow> dialog;
100 rv = wwatcher->OpenWindow(parent, "chrome://cookie/content/cookieAcceptDialog.xul", "_blank",
101 "centerscreen,chrome,modal,titlebar", arguments,
102 getter_AddRefs(dialog));
104 if (NS_FAILED(rv)) return rv;
106 // get back output parameters
107 PRBool tempValue;
108 block->GetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, &tempValue);
109 *aAccept = tempValue;
111 // GetInt returns a PRInt32; we need to sanitize it into PRBool
112 block->GetInt(nsICookieAcceptDialog::REMEMBER_DECISION, &tempValue);
113 *aRememberDecision = (tempValue == 1);
115 return rv;