made functions and variables static in some testcases.
[wine/hacks.git] / dlls / mshtml / nsservice.c
blob76887b2c238cb02ba2acbef50be0f917bb8c2044
1 /*
2 * Copyright 2005 Jacek Caban
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "ole2.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define NS_PROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/prompt-service;1"
39 #define NS_WINDOWWATCHER_CONTRACTID "@mozilla.org/embedcomp/window-watcher;1"
40 #define NS_TOOLTIPTEXTPROVIDER_CONTRACTID "@mozilla.org/embedcomp/tooltiptextprovider;1"
42 #define NS_TOOLTIPTEXTPROVIDER_CLASSNAME "nsTooltipTextProvider"
44 static const nsIID NS_PROMPTSERVICE_CID =
45 {0xa2112d6a,0x0e28,0x421f,{0xb4,0x6a,0x25,0xc0,0xb3,0x8,0xcb,0xd0}};
46 static const nsIID NS_TOOLTIPTEXTPROVIDER_CID =
47 {0x0b666e3e,0x569a,0x462c,{0xa7,0xf0,0xb1,0x6b,0xb1,0x5d,0x42,0xff}};
49 static nsresult NSAPI nsWindowCreator_QueryInterface(nsIWindowCreator2 *iface, nsIIDRef riid,
50 nsQIResult result)
52 *result = NULL;
54 if(IsEqualGUID(&IID_nsISupports, riid)) {
55 TRACE("(IID_nsISupports %p)\n", result);
56 *result = iface;
57 }else if(IsEqualGUID(&IID_nsIWindowCreator, riid)) {
58 TRACE("(IID_nsIWindowCreator %p)\n", result);
59 *result = iface;
60 }else if(IsEqualGUID(&IID_nsIWindowCreator2, riid)) {
61 TRACE("(IID_nsIWindowCreator2 %p)\n", result);
62 *result = iface;
65 if(*result) {
66 nsIWindowCreator_AddRef(iface);
67 return NS_OK;
70 WARN("(%s %p)\n", debugstr_guid(riid), result);
71 return NS_NOINTERFACE;
74 static nsrefcnt NSAPI nsWindowCreator_AddRef(nsIWindowCreator2 *iface)
76 return 2;
79 static nsrefcnt NSAPI nsWindowCreator_Release(nsIWindowCreator2 *iface)
81 return 1;
84 static nsresult NSAPI nsWindowCreator_CreateChromeWindow(nsIWindowCreator2 *iface,
85 nsIWebBrowserChrome *parent, PRUint32 chromeFlags, nsIWebBrowserChrome **_retval)
87 TRACE("(%p %08x %p)\n", parent, chromeFlags, _retval);
88 return nsIWindowCreator2_CreateChromeWindow2(iface, parent, chromeFlags, 0, NULL,
89 NULL, _retval);
92 static nsresult NSAPI nsWindowCreator_CreateChromeWindow2(nsIWindowCreator2 *iface,
93 nsIWebBrowserChrome *parent, PRUint32 chromeFlags, PRUint32 contextFlags,
94 nsIURI *uri, PRBool *cancel, nsIWebBrowserChrome **_retval)
96 TRACE("(%p %08x %08x %p %p %p)\n", parent, chromeFlags, contextFlags, uri,
97 cancel, _retval);
99 if(cancel)
100 *cancel = FALSE;
102 *_retval = NSWBCHROME(NSContainer_Create(NULL, (NSContainer*)parent));
103 return NS_OK;
106 static const nsIWindowCreator2Vtbl nsWindowCreatorVtbl = {
107 nsWindowCreator_QueryInterface,
108 nsWindowCreator_AddRef,
109 nsWindowCreator_Release,
110 nsWindowCreator_CreateChromeWindow,
111 nsWindowCreator_CreateChromeWindow2
114 static nsIWindowCreator2 nsWindowCreator = { &nsWindowCreatorVtbl };
116 static nsresult NSAPI nsPromptService_QueryInterface(nsIPromptService *iface,
117 nsIIDRef riid, nsQIResult result)
119 *result = NULL;
121 if(IsEqualGUID(&IID_nsISupports, riid)) {
122 TRACE("(IID_nsISupports %p)\n", result);
123 *result = iface;
124 }else if(IsEqualGUID(&IID_nsIPromptService, riid)) {
125 TRACE("(IID_nsIPromptService %p)\n", result);
126 *result = iface;
129 if(*result)
130 return NS_OK;
132 TRACE("(%s %p)\n", debugstr_guid(riid), result);
133 return NS_NOINTERFACE;
136 static nsrefcnt NSAPI nsPromptService_AddRef(nsIPromptService *iface)
138 return 2;
141 static nsrefcnt NSAPI nsPromptService_Release(nsIPromptService *iface)
143 return 1;
146 static nsresult NSAPI nsPromptService_Alert(nsIPromptService *iface, nsIDOMWindow *aParent,
147 const PRUnichar *aDialogTitle, const PRUnichar *aText)
149 FIXME("(%p %s %s)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText));
150 return NS_ERROR_NOT_IMPLEMENTED;
153 static nsresult NSAPI nsPromptService_AlertCheck(nsIPromptService *iface,
154 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
155 const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState)
157 FIXME("(%p %s %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
158 debugstr_w(aCheckMsg), aCheckState);
159 return NS_ERROR_NOT_IMPLEMENTED;
162 static nsresult NSAPI nsPromptService_Confirm(nsIPromptService *iface,
163 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText,
164 PRBool *_retval)
166 FIXME("(%p %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), _retval);
167 return NS_ERROR_NOT_IMPLEMENTED;
170 static nsresult NSAPI nsPromptService_ConfirmCheck(nsIPromptService *iface,
171 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
172 const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState,
173 PRBool *_retval)
175 FIXME("(%p %s %s %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
176 debugstr_w(aCheckMsg), aCheckState, _retval);
177 return NS_ERROR_NOT_IMPLEMENTED;
180 static nsresult NSAPI nsPromptService_ConfirmEx(nsIPromptService *iface,
181 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
182 const PRUnichar *aText, PRUint32 aButtonFlags, const PRUnichar *aButton0Title,
183 const PRUnichar *aButton1Title, const PRUnichar *aButton2Title,
184 const PRUnichar *aCheckMsg, PRBool *aCheckState, PRInt32 *_retval)
186 static const PRUnichar wszContinue[] = {'C','o','n','t','i','n','u','e',0};
188 FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent, debugstr_w(aDialogTitle),
189 debugstr_w(aText), aButtonFlags, debugstr_w(aButton0Title),
190 debugstr_w(aButton1Title), debugstr_w(aButton2Title), debugstr_w(aCheckMsg),
191 aCheckState, _retval);
194 * FIXME:
195 * This is really very very ugly hack!!!
198 if(aButton0Title && !memcmp(aButton0Title, wszContinue, sizeof(wszContinue)))
199 *_retval = 0;
200 else if(aButton1Title && !memcmp(aButton1Title, wszContinue, sizeof(wszContinue)))
201 *_retval = 1;
202 else if(aButton2Title && !memcmp(aButton2Title, wszContinue, sizeof(wszContinue)))
203 *_retval = 2;
204 /* else
205 * let's hope that _retval is set to the default value */
207 return NS_OK;
210 static nsresult NSAPI nsPromptService_Prompt(nsIPromptService *iface,
211 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
212 const PRUnichar *aText, PRUnichar **aValue, const PRUnichar *aCheckMsg,
213 PRBool *aCheckState, PRBool *_retval)
215 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
216 aValue, debugstr_w(aCheckMsg), aCheckState, _retval);
217 return NS_ERROR_NOT_IMPLEMENTED;
220 static nsresult NSAPI nsPromptService_PromptUsernameAndPassword(nsIPromptService *iface,
221 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
222 const PRUnichar *aText, PRUnichar **aUsername, PRUnichar **aPassword,
223 const PRUnichar *aCheckMsg, PRBool *aCheckState, PRBool *_retval)
225 FIXME("(%p %s %s %p %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
226 debugstr_w(aText), aUsername, aPassword, debugstr_w(aCheckMsg), aCheckState,
227 _retval);
228 return NS_ERROR_NOT_IMPLEMENTED;
231 static nsresult NSAPI nsPromptService_PromptPassword(nsIPromptService *iface,
232 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
233 const PRUnichar *aText, PRUnichar **aPassword, const PRUnichar *aCheckMsg,
234 PRBool *aCheckState, PRBool *_retval)
236 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
237 debugstr_w(aText), aPassword, debugstr_w(aCheckMsg), aCheckState, _retval);
238 return NS_ERROR_NOT_IMPLEMENTED;
241 static nsresult NSAPI nsPromptService_Select(nsIPromptService *iface,
242 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
243 const PRUnichar *aText, PRUint32 aCount, const PRUnichar **aSelectList,
244 PRInt32 *aOutSelection, PRBool *_retval)
246 FIXME("(%p %s %s %d %p %p %p)\n", aParent, debugstr_w(aDialogTitle),
247 debugstr_w(aText), aCount, aSelectList, aOutSelection, _retval);
248 return NS_ERROR_NOT_IMPLEMENTED;
251 static const nsIPromptServiceVtbl PromptServiceVtbl = {
252 nsPromptService_QueryInterface,
253 nsPromptService_AddRef,
254 nsPromptService_Release,
255 nsPromptService_Alert,
256 nsPromptService_AlertCheck,
257 nsPromptService_Confirm,
258 nsPromptService_ConfirmCheck,
259 nsPromptService_ConfirmEx,
260 nsPromptService_Prompt,
261 nsPromptService_PromptUsernameAndPassword,
262 nsPromptService_PromptPassword,
263 nsPromptService_Select
266 static nsIPromptService nsPromptService = { &PromptServiceVtbl };
268 static nsresult NSAPI nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider *iface,
269 nsIIDRef riid, nsQIResult result)
271 *result = NULL;
273 if(IsEqualGUID(&IID_nsISupports, riid)) {
274 TRACE("(IID_nsISupports %p)\n", result);
275 *result = iface;
276 }else if(IsEqualGUID(&IID_nsITooltipTextProvider, riid)) {
277 TRACE("(IID_nsITooltipTextProvider %p)\n", result);
278 *result = iface;
281 if(*result) {
282 nsITooltipTextProvider_AddRef(iface);
283 return NS_OK;
286 WARN("(%s %p)\n", debugstr_guid(riid), result);
287 return NS_NOINTERFACE;
290 static nsrefcnt NSAPI nsTooltipTextProvider_AddRef(nsITooltipTextProvider *iface)
292 return 2;
295 static nsrefcnt NSAPI nsTooltipTextProvider_Release(nsITooltipTextProvider *iface)
297 return 1;
300 static nsresult NSAPI nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider *iface,
301 nsIDOMNode *aNode, PRUnichar **aText, PRBool *_retval)
303 nsIDOMHTMLElement *nselem;
304 nsIDOMNode *node = aNode, *parent;
305 nsAString title_str;
306 const PRUnichar *title = NULL;
307 nsresult nsres;
309 TRACE("(%p %p %p)\n", aNode, aText, _retval);
311 *aText = NULL;
313 nsAString_Init(&title_str, NULL);
315 do {
316 nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMHTMLElement, (void**)&nselem);
317 if(NS_SUCCEEDED(nsres)) {
318 title = NULL;
320 nsIDOMHTMLElement_GetTitle(nselem, &title_str);
321 nsIDOMHTMLElement_Release(nselem);
323 nsAString_GetData(&title_str, &title, NULL);
324 if(title && *title) {
325 if(node != aNode)
326 nsIDOMNode_Release(node);
327 break;
331 nsres = nsIDOMNode_GetParentNode(node, &parent);
332 if(NS_FAILED(nsres))
333 parent = NULL;
335 if(node != aNode)
336 nsIDOMNode_Release(node);
337 node = parent;
338 } while(node);
340 if(title && *title) {
341 int size = (strlenW(title)+1)*sizeof(PRUnichar);
343 *aText = nsalloc(size);
344 memcpy(*aText, title, size);
345 TRACE("aText = %s\n", debugstr_w(*aText));
347 *_retval = TRUE;
348 }else {
349 *_retval = FALSE;
352 nsAString_Finish(&title_str);
354 return NS_OK;
357 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl = {
358 nsTooltipTextProvider_QueryInterface,
359 nsTooltipTextProvider_AddRef,
360 nsTooltipTextProvider_Release,
361 nsTooltipTextProvider_GetNodeText
364 static nsITooltipTextProvider nsTooltipTextProvider = { &nsTooltipTextProviderVtbl };
366 typedef struct {
367 const nsIFactoryVtbl *lpFactoryVtbl;
368 nsISupports *service;
369 } nsServiceFactory;
371 #define NSFACTORY(x) ((nsIFactory*) &(x)->lpFactoryVtbl)
373 #define NSFACTORY_THIS(iface) DEFINE_THIS(nsServiceFactory, Factory, iface)
375 static nsresult NSAPI nsServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
376 nsQIResult result)
378 nsServiceFactory *This = NSFACTORY_THIS(iface);
380 *result = NULL;
382 if(IsEqualGUID(&IID_nsISupports, riid)) {
383 TRACE("(%p)->(IID_nsISupoprts %p)\n", This, result);
384 *result = NSFACTORY(This);
385 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
386 TRACE("(%p)->(IID_nsIFactory %p)\n", This, result);
387 *result = NSFACTORY(This);
390 if(*result)
391 return NS_OK;
393 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
394 return NS_NOINTERFACE;
397 static nsrefcnt NSAPI nsServiceFactory_AddRef(nsIFactory *iface)
399 return 2;
402 static nsrefcnt NSAPI nsServiceFactory_Release(nsIFactory *iface)
404 return 1;
407 static nsresult NSAPI nsServiceFactory_CreateInstance(nsIFactory *iface,
408 nsISupports *aOuter, const nsIID *iid, void **result)
410 nsServiceFactory *This = NSFACTORY_THIS(iface);
412 TRACE("(%p)->(%p %s %p)\n", This, aOuter, debugstr_guid(iid), result);
414 return nsISupports_QueryInterface(This->service, iid, result);
417 static nsresult NSAPI nsServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
419 nsServiceFactory *This = NSFACTORY_THIS(iface);
420 WARN("(%p)->(%x)\n", This, lock);
421 return NS_OK;
424 #undef NSFACTORY_THIS
426 static const nsIFactoryVtbl nsServiceFactoryVtbl = {
427 nsServiceFactory_QueryInterface,
428 nsServiceFactory_AddRef,
429 nsServiceFactory_Release,
430 nsServiceFactory_CreateInstance,
431 nsServiceFactory_LockFactory
434 static nsServiceFactory nsPromptServiceFactory = {
435 &nsServiceFactoryVtbl,
436 (nsISupports*)&nsPromptService
439 static nsServiceFactory nsTooltipTextFactory = {
440 &nsServiceFactoryVtbl,
441 (nsISupports*)&nsTooltipTextProvider
444 void register_nsservice(nsIComponentRegistrar *registrar, nsIServiceManager *service_manager)
446 nsIWindowWatcher *window_watcher;
447 nsresult nsres;
449 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_PROMPTSERVICE_CID,
450 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID, NSFACTORY(&nsPromptServiceFactory));
451 if(NS_FAILED(nsres))
452 ERR("RegisterFactory failed: %08x\n", nsres);
454 nsres = nsIServiceManager_GetServiceByContactID(service_manager, NS_WINDOWWATCHER_CONTRACTID,
455 &IID_nsIWindowWatcher, (void**)&window_watcher);
456 if(NS_SUCCEEDED(nsres)) {
457 nsres = nsIWindowWatcher_SetWindowCreator(window_watcher,
458 (nsIWindowCreator*)&nsWindowCreator);
459 if(NS_FAILED(nsres))
460 ERR("SetWindowCreator failed: %08x\n", nsres);
461 nsIWindowWatcher_Release(window_watcher);
462 }else {
463 ERR("Could not get WindowWatcher object: %08x\n", nsres);
466 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_TOOLTIPTEXTPROVIDER_CID,
467 NS_TOOLTIPTEXTPROVIDER_CLASSNAME, NS_TOOLTIPTEXTPROVIDER_CONTRACTID,
468 NSFACTORY(&nsTooltipTextFactory));
469 if(NS_FAILED(nsres))
470 ERR("RegisterFactory failed: %08x\n", nsres);