msvcrt/tests: Remove a space before a '\n'.
[wine/gsoc-2012-control.git] / dlls / mshtml / nsservice.c
bloba449274c12aee593568ebb8e9c7d286a1dda1299
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 HTMLWindow *window;
150 BSTR text;
152 TRACE("(%p %s %s)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText));
154 window = nswindow_to_window(aParent);
155 if(!window) {
156 WARN("Could not find HTMLWindow for nsIDOMWindow %p\n", aParent);
157 return NS_ERROR_UNEXPECTED;
160 text = SysAllocString(aText);
161 IHTMLWindow2_alert(HTMLWINDOW2(window), text);
162 SysFreeString(text);
164 return NS_OK;
167 static nsresult NSAPI nsPromptService_AlertCheck(nsIPromptService *iface,
168 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
169 const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState)
171 FIXME("(%p %s %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
172 debugstr_w(aCheckMsg), aCheckState);
173 return NS_ERROR_NOT_IMPLEMENTED;
176 static nsresult NSAPI nsPromptService_Confirm(nsIPromptService *iface,
177 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText,
178 PRBool *_retval)
180 FIXME("(%p %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), _retval);
181 return NS_ERROR_NOT_IMPLEMENTED;
184 static nsresult NSAPI nsPromptService_ConfirmCheck(nsIPromptService *iface,
185 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
186 const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState,
187 PRBool *_retval)
189 FIXME("(%p %s %s %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
190 debugstr_w(aCheckMsg), aCheckState, _retval);
191 return NS_ERROR_NOT_IMPLEMENTED;
194 static nsresult NSAPI nsPromptService_ConfirmEx(nsIPromptService *iface,
195 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
196 const PRUnichar *aText, PRUint32 aButtonFlags, const PRUnichar *aButton0Title,
197 const PRUnichar *aButton1Title, const PRUnichar *aButton2Title,
198 const PRUnichar *aCheckMsg, PRBool *aCheckState, PRInt32 *_retval)
200 static const PRUnichar wszContinue[] = {'C','o','n','t','i','n','u','e',0};
202 FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent, debugstr_w(aDialogTitle),
203 debugstr_w(aText), aButtonFlags, debugstr_w(aButton0Title),
204 debugstr_w(aButton1Title), debugstr_w(aButton2Title), debugstr_w(aCheckMsg),
205 aCheckState, _retval);
208 * FIXME:
209 * This is really very very ugly hack!!!
212 if(aButton0Title && !memcmp(aButton0Title, wszContinue, sizeof(wszContinue)))
213 *_retval = 0;
214 else if(aButton1Title && !memcmp(aButton1Title, wszContinue, sizeof(wszContinue)))
215 *_retval = 1;
216 else if(aButton2Title && !memcmp(aButton2Title, wszContinue, sizeof(wszContinue)))
217 *_retval = 2;
218 /* else
219 * let's hope that _retval is set to the default value */
221 return NS_OK;
224 static nsresult NSAPI nsPromptService_Prompt(nsIPromptService *iface,
225 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
226 const PRUnichar *aText, PRUnichar **aValue, const PRUnichar *aCheckMsg,
227 PRBool *aCheckState, PRBool *_retval)
229 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
230 aValue, debugstr_w(aCheckMsg), aCheckState, _retval);
231 return NS_ERROR_NOT_IMPLEMENTED;
234 static nsresult NSAPI nsPromptService_PromptUsernameAndPassword(nsIPromptService *iface,
235 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
236 const PRUnichar *aText, PRUnichar **aUsername, PRUnichar **aPassword,
237 const PRUnichar *aCheckMsg, PRBool *aCheckState, PRBool *_retval)
239 FIXME("(%p %s %s %p %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
240 debugstr_w(aText), aUsername, aPassword, debugstr_w(aCheckMsg), aCheckState,
241 _retval);
242 return NS_ERROR_NOT_IMPLEMENTED;
245 static nsresult NSAPI nsPromptService_PromptPassword(nsIPromptService *iface,
246 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
247 const PRUnichar *aText, PRUnichar **aPassword, const PRUnichar *aCheckMsg,
248 PRBool *aCheckState, PRBool *_retval)
250 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
251 debugstr_w(aText), aPassword, debugstr_w(aCheckMsg), aCheckState, _retval);
252 return NS_ERROR_NOT_IMPLEMENTED;
255 static nsresult NSAPI nsPromptService_Select(nsIPromptService *iface,
256 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
257 const PRUnichar *aText, PRUint32 aCount, const PRUnichar **aSelectList,
258 PRInt32 *aOutSelection, PRBool *_retval)
260 FIXME("(%p %s %s %d %p %p %p)\n", aParent, debugstr_w(aDialogTitle),
261 debugstr_w(aText), aCount, aSelectList, aOutSelection, _retval);
262 return NS_ERROR_NOT_IMPLEMENTED;
265 static const nsIPromptServiceVtbl PromptServiceVtbl = {
266 nsPromptService_QueryInterface,
267 nsPromptService_AddRef,
268 nsPromptService_Release,
269 nsPromptService_Alert,
270 nsPromptService_AlertCheck,
271 nsPromptService_Confirm,
272 nsPromptService_ConfirmCheck,
273 nsPromptService_ConfirmEx,
274 nsPromptService_Prompt,
275 nsPromptService_PromptUsernameAndPassword,
276 nsPromptService_PromptPassword,
277 nsPromptService_Select
280 static nsIPromptService nsPromptService = { &PromptServiceVtbl };
282 static nsresult NSAPI nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider *iface,
283 nsIIDRef riid, nsQIResult result)
285 *result = NULL;
287 if(IsEqualGUID(&IID_nsISupports, riid)) {
288 TRACE("(IID_nsISupports %p)\n", result);
289 *result = iface;
290 }else if(IsEqualGUID(&IID_nsITooltipTextProvider, riid)) {
291 TRACE("(IID_nsITooltipTextProvider %p)\n", result);
292 *result = iface;
295 if(*result) {
296 nsITooltipTextProvider_AddRef(iface);
297 return NS_OK;
300 WARN("(%s %p)\n", debugstr_guid(riid), result);
301 return NS_NOINTERFACE;
304 static nsrefcnt NSAPI nsTooltipTextProvider_AddRef(nsITooltipTextProvider *iface)
306 return 2;
309 static nsrefcnt NSAPI nsTooltipTextProvider_Release(nsITooltipTextProvider *iface)
311 return 1;
314 static nsresult NSAPI nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider *iface,
315 nsIDOMNode *aNode, PRUnichar **aText, PRBool *_retval)
317 nsIDOMHTMLElement *nselem;
318 nsIDOMNode *node = aNode, *parent;
319 nsAString title_str;
320 const PRUnichar *title = NULL;
321 nsresult nsres;
323 TRACE("(%p %p %p)\n", aNode, aText, _retval);
325 *aText = NULL;
327 nsAString_Init(&title_str, NULL);
329 do {
330 nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMHTMLElement, (void**)&nselem);
331 if(NS_SUCCEEDED(nsres)) {
332 title = NULL;
334 nsIDOMHTMLElement_GetTitle(nselem, &title_str);
335 nsIDOMHTMLElement_Release(nselem);
337 nsAString_GetData(&title_str, &title);
338 if(title && *title) {
339 if(node != aNode)
340 nsIDOMNode_Release(node);
341 break;
345 nsres = nsIDOMNode_GetParentNode(node, &parent);
346 if(NS_FAILED(nsres))
347 parent = NULL;
349 if(node != aNode)
350 nsIDOMNode_Release(node);
351 node = parent;
352 } while(node);
354 if(title && *title) {
355 int size = (strlenW(title)+1)*sizeof(PRUnichar);
357 *aText = nsalloc(size);
358 memcpy(*aText, title, size);
359 TRACE("aText = %s\n", debugstr_w(*aText));
361 *_retval = TRUE;
362 }else {
363 *_retval = FALSE;
366 nsAString_Finish(&title_str);
368 return NS_OK;
371 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl = {
372 nsTooltipTextProvider_QueryInterface,
373 nsTooltipTextProvider_AddRef,
374 nsTooltipTextProvider_Release,
375 nsTooltipTextProvider_GetNodeText
378 static nsITooltipTextProvider nsTooltipTextProvider = { &nsTooltipTextProviderVtbl };
380 typedef struct {
381 const nsIFactoryVtbl *lpFactoryVtbl;
382 nsISupports *service;
383 } nsServiceFactory;
385 #define NSFACTORY(x) ((nsIFactory*) &(x)->lpFactoryVtbl)
387 #define NSFACTORY_THIS(iface) DEFINE_THIS(nsServiceFactory, Factory, iface)
389 static nsresult NSAPI nsServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
390 nsQIResult result)
392 nsServiceFactory *This = NSFACTORY_THIS(iface);
394 *result = NULL;
396 if(IsEqualGUID(&IID_nsISupports, riid)) {
397 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
398 *result = NSFACTORY(This);
399 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
400 TRACE("(%p)->(IID_nsIFactory %p)\n", This, result);
401 *result = NSFACTORY(This);
404 if(*result)
405 return NS_OK;
407 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
408 return NS_NOINTERFACE;
411 static nsrefcnt NSAPI nsServiceFactory_AddRef(nsIFactory *iface)
413 return 2;
416 static nsrefcnt NSAPI nsServiceFactory_Release(nsIFactory *iface)
418 return 1;
421 static nsresult NSAPI nsServiceFactory_CreateInstance(nsIFactory *iface,
422 nsISupports *aOuter, const nsIID *iid, void **result)
424 nsServiceFactory *This = NSFACTORY_THIS(iface);
426 TRACE("(%p)->(%p %s %p)\n", This, aOuter, debugstr_guid(iid), result);
428 return nsISupports_QueryInterface(This->service, iid, result);
431 static nsresult NSAPI nsServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
433 nsServiceFactory *This = NSFACTORY_THIS(iface);
434 WARN("(%p)->(%x)\n", This, lock);
435 return NS_OK;
438 #undef NSFACTORY_THIS
440 static const nsIFactoryVtbl nsServiceFactoryVtbl = {
441 nsServiceFactory_QueryInterface,
442 nsServiceFactory_AddRef,
443 nsServiceFactory_Release,
444 nsServiceFactory_CreateInstance,
445 nsServiceFactory_LockFactory
448 static nsServiceFactory nsPromptServiceFactory = {
449 &nsServiceFactoryVtbl,
450 (nsISupports*)&nsPromptService
453 static nsServiceFactory nsTooltipTextFactory = {
454 &nsServiceFactoryVtbl,
455 (nsISupports*)&nsTooltipTextProvider
458 void register_nsservice(nsIComponentRegistrar *registrar, nsIServiceManager *service_manager)
460 nsIWindowWatcher *window_watcher;
461 nsresult nsres;
463 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_PROMPTSERVICE_CID,
464 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID, NSFACTORY(&nsPromptServiceFactory));
465 if(NS_FAILED(nsres))
466 ERR("RegisterFactory failed: %08x\n", nsres);
468 nsres = nsIServiceManager_GetServiceByContractID(service_manager, NS_WINDOWWATCHER_CONTRACTID,
469 &IID_nsIWindowWatcher, (void**)&window_watcher);
470 if(NS_SUCCEEDED(nsres)) {
471 nsres = nsIWindowWatcher_SetWindowCreator(window_watcher,
472 (nsIWindowCreator*)&nsWindowCreator);
473 if(NS_FAILED(nsres))
474 ERR("SetWindowCreator failed: %08x\n", nsres);
475 nsIWindowWatcher_Release(window_watcher);
476 }else {
477 ERR("Could not get WindowWatcher object: %08x\n", nsres);
480 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_TOOLTIPTEXTPROVIDER_CID,
481 NS_TOOLTIPTEXTPROVIDER_CLASSNAME, NS_TOOLTIPTEXTPROVIDER_CONTRACTID,
482 NSFACTORY(&nsTooltipTextFactory));
483 if(NS_FAILED(nsres))
484 ERR("RegisterFactory failed: %08x\n", nsres);