mshtml: Added hack to allow pass post data to IPersistMoniker::Load.
[wine] / dlls / mshtml / nsservice.c
1 /*
2  * Copyright 2005 Jacek Caban
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "ole2.h"
30
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33
34 #include "mshtml_private.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37
38 #define NS_PROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/prompt-service;1"
39
40 static const nsIID NS_PROMPTSERVICE_CID =
41     {0xa2112d6a,0x0e28,0x421f,{0xb4,0x6a,0x25,0xc0,0xb3,0x8,0xcb,0xd0}};
42
43 static nsresult NSAPI nsPromptService_QueryInterface(nsIPromptService *iface,
44                                                      nsIIDRef riid, nsQIResult result)
45 {
46     *result = NULL;
47
48     if(IsEqualGUID(&IID_nsISupports, riid)) {
49         TRACE("(IID_nsISupports %p)\n", result);
50         *result = iface;
51     }else if(IsEqualGUID(&IID_nsIPromptService, riid)) {
52         TRACE("(IID_nsIPromptService %p)\n", result);
53         *result = iface;
54     }
55
56     if(*result)
57         return NS_OK;
58
59     TRACE("(%s %p)\n", debugstr_guid(riid), result);
60     return NS_NOINTERFACE;
61 }
62
63 static nsrefcnt NSAPI nsPromptService_AddRef(nsIPromptService *iface)
64 {
65     return 2;
66 }
67
68 static nsrefcnt NSAPI nsPromptService_Release(nsIPromptService *iface)
69 {
70     return 1;
71 }
72
73 static nsresult NSAPI nsPromptService_Alert(nsIPromptService *iface, nsIDOMWindow *aParent,
74         const PRUnichar *aDialogTitle, const PRUnichar *aText)
75 {
76     FIXME("(%p %s %s)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText));
77     return NS_ERROR_NOT_IMPLEMENTED;
78 }
79
80 static nsresult NSAPI nsPromptService_AlertCheck(nsIPromptService *iface,
81         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
82         const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState)
83 {
84     FIXME("(%p %s %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
85           debugstr_w(aCheckMsg), aCheckState);
86     return NS_ERROR_NOT_IMPLEMENTED;
87 }
88
89 static nsresult NSAPI nsPromptService_Confirm(nsIPromptService *iface,
90         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText,
91         PRBool *_retval)
92 {
93     FIXME("(%p %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), _retval);
94     return NS_ERROR_NOT_IMPLEMENTED;
95 }
96
97 static nsresult NSAPI nsPromptService_ConfirmCheck(nsIPromptService *iface,
98         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
99         const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState,
100         PRBool *_retval)
101 {
102     FIXME("(%p %s %s %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
103         debugstr_w(aCheckMsg), aCheckState, _retval);
104     return NS_ERROR_NOT_IMPLEMENTED;
105 }
106
107 static nsresult NSAPI nsPromptService_ConfirmEx(nsIPromptService *iface,
108         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
109         const PRUnichar *aText, PRUint32 aButtonFlags, const PRUnichar *aButton0Title,
110         const PRUnichar *aButton1Title, const PRUnichar *aButton2Title,
111         const PRUnichar *aCheckMsg, PRBool *aCheckState, PRInt32 *_retval)
112 {
113     static const PRUnichar wszContinue[] = {'C','o','n','t','i','n','u','e',0};
114
115     FIXME("(%p %s %s %08lx %s %s %s %s %p %p) hack!\n", aParent, debugstr_w(aDialogTitle),
116           debugstr_w(aText), aButtonFlags, debugstr_w(aButton0Title),
117           debugstr_w(aButton1Title), debugstr_w(aButton2Title), debugstr_w(aCheckMsg),
118           aCheckState, _retval);
119
120     /*
121      * FIXME:
122      * This is really very very ugly hack!!!
123      */
124
125     if(!memcmp(aButton0Title, wszContinue, sizeof(wszContinue)))
126         *_retval = 0;
127     else if(!memcmp(aButton1Title, wszContinue, sizeof(wszContinue)))
128         *_retval = 1;
129     else if(!memcmp(aButton2Title, wszContinue, sizeof(wszContinue)))
130         *_retval = 2;
131     else
132         *_retval = 0;
133
134     return NS_OK;
135 }
136
137 static nsresult NSAPI nsPromptService_Prompt(nsIPromptService *iface,
138         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
139         const PRUnichar *aText, PRUnichar **aValue, const PRUnichar *aCheckMsg,
140         PRBool *aCheckState, PRBool *_retval)
141 {
142     FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
143           aValue, debugstr_w(aCheckMsg), aCheckState, _retval);
144     return NS_ERROR_NOT_IMPLEMENTED;
145 }
146
147 static nsresult NSAPI nsPromptService_PromptUsernameAndPassword(nsIPromptService *iface,
148         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
149         const PRUnichar *aText, PRUnichar **aUsername, PRUnichar **aPassword,
150         const PRUnichar *aCheckMsg, PRBool *aCheckState, PRBool *_retval)
151 {
152     FIXME("(%p %s %s %p %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
153         debugstr_w(aText), aUsername, aPassword, debugstr_w(aCheckMsg), aCheckState,
154         _retval);
155     return NS_ERROR_NOT_IMPLEMENTED;
156 }
157
158 static nsresult NSAPI nsPromptService_PromptPassword(nsIPromptService *iface,
159         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
160         const PRUnichar *aText, PRUnichar **aPassword, const PRUnichar *aCheckMsg,
161         PRBool *aCheckState, PRBool *_retval)
162 {
163     FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
164           debugstr_w(aText), aPassword, debugstr_w(aCheckMsg), aCheckState, _retval);
165     return NS_ERROR_NOT_IMPLEMENTED;
166 }
167
168 static nsresult NSAPI nsPromptService_Select(nsIPromptService *iface,
169         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
170         const PRUnichar *aText, PRUint32 aCount, const PRUnichar **aSelectList,
171         PRInt32 *aOutSelection, PRBool *_retval)
172 {
173     FIXME("(%p %s %s %ld %p %p %p)\n", aParent, debugstr_w(aDialogTitle),
174         debugstr_w(aText), aCount, aSelectList, aOutSelection, _retval);
175     return NS_ERROR_NOT_IMPLEMENTED;
176 }
177
178 static const nsIPromptServiceVtbl PromptServiceVtbl = {
179     nsPromptService_QueryInterface,
180     nsPromptService_AddRef,
181     nsPromptService_Release,
182     nsPromptService_Alert,
183     nsPromptService_AlertCheck,
184     nsPromptService_Confirm,
185     nsPromptService_ConfirmCheck,
186     nsPromptService_ConfirmEx,
187     nsPromptService_Prompt,
188     nsPromptService_PromptUsernameAndPassword,
189     nsPromptService_PromptPassword,
190     nsPromptService_Select
191 };
192
193 static nsIPromptService nsPromptService = { &PromptServiceVtbl };
194
195 typedef struct {
196     const nsIFactoryVtbl *lpFactoryVtbl;
197     nsISupports *service;
198 } nsServiceFactory;
199
200 #define NSFACTORY(x)  ((nsIFactory*)  &(x)->lpFactoryVtbl)
201
202 #define NSFACTORY_THIS(iface) DEFINE_THIS(nsServiceFactory, Factory, iface)
203
204 static nsresult NSAPI nsServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
205                                                     nsQIResult result)
206 {
207     nsServiceFactory *This = NSFACTORY_THIS(iface);
208
209     *result = NULL;
210
211     if(IsEqualGUID(&IID_nsISupports, riid)) {
212         TRACE("(%p)->(IID_nsISupoprts %p)\n", This, result);
213         *result = NSFACTORY(This);
214     }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
215         TRACE("(%p)->(IID_nsIFactory %p)\n", This, result);
216         *result = NSFACTORY(This);
217     }
218
219     if(*result)
220         return NS_OK;
221
222     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
223     return NS_NOINTERFACE;
224 }
225
226 static nsrefcnt NSAPI nsServiceFactory_AddRef(nsIFactory *iface)
227 {
228     return 2;
229 }
230
231 static nsrefcnt NSAPI nsServiceFactory_Release(nsIFactory *iface)
232 {
233     return 1;
234 }
235
236 static nsresult NSAPI nsServiceFactory_CreateInstance(nsIFactory *iface,
237         nsISupports *aOuter, const nsIID *iid, void **result)
238 {
239     nsServiceFactory *This = NSFACTORY_THIS(iface);
240
241     TRACE("(%p)->(%p %s %p)\n", This, aOuter, debugstr_guid(iid), result);
242
243     return nsISupports_QueryInterface(This->service, iid, result);
244 }
245
246 static nsresult NSAPI nsServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
247 {
248     nsServiceFactory *This = NSFACTORY_THIS(iface);
249     WARN("(%p)->(%x)\n", This, lock);
250     return NS_OK;
251 }
252
253 #undef NSFACTORY_THIS
254
255 static const nsIFactoryVtbl nsServiceFactoryVtbl = {
256     nsServiceFactory_QueryInterface,
257     nsServiceFactory_AddRef,
258     nsServiceFactory_Release,
259     nsServiceFactory_CreateInstance,
260     nsServiceFactory_LockFactory
261 };
262
263 static nsServiceFactory PromptServiceFactory = {
264     &nsServiceFactoryVtbl,
265     (nsISupports*)&nsPromptService
266 };
267
268 void register_nsservice(nsIComponentRegistrar *registrar)
269 {
270     nsresult nsres;
271
272     nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_PROMPTSERVICE_CID,
273             "Prompt Service", NS_PROMPTSERVICE_CONTRACTID, NSFACTORY(&PromptServiceFactory));
274     if(NS_FAILED(nsres))
275         ERR("RegisterFactory failed: %08lx\n", nsres);
276 }