kernelbase: Ignore URL_PARTFLAG_KEEPSCHEME when used with URL_PART_SCHEME or URL_PART...
[wine.git] / dlls / mshtml / nsservice.c
blob55a65cfeae684cb5dcf2cf09e1dddfd622b0d410
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 <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "winreg.h"
27 #include "ole2.h"
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 #define NS_PROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/prompt-service;1"
36 #define NS_TOOLTIPTEXTPROVIDER_CONTRACTID "@mozilla.org/embedcomp/tooltiptextprovider;1"
38 #define NS_TOOLTIPTEXTPROVIDER_CLASSNAME "nsTooltipTextProvider"
40 static const nsIID NS_PROMPTSERVICE_CID =
41 {0xa2112d6a,0x0e28,0x421f,{0xb4,0x6a,0x25,0xc0,0xb3,0x8,0xcb,0xd0}};
42 static const nsIID NS_TOOLTIPTEXTPROVIDER_CID =
43 {0x0b666e3e,0x569a,0x462c,{0xa7,0xf0,0xb1,0x6b,0xb1,0x5d,0x42,0xff}};
45 static nsresult NSAPI nsPromptService_QueryInterface(nsIPromptService *iface,
46 nsIIDRef riid, void **result)
48 *result = NULL;
50 if(IsEqualGUID(&IID_nsISupports, riid)) {
51 TRACE("(IID_nsISupports %p)\n", result);
52 *result = iface;
53 }else if(IsEqualGUID(&IID_nsIPromptService, riid)) {
54 TRACE("(IID_nsIPromptService %p)\n", result);
55 *result = iface;
58 if(*result)
59 return NS_OK;
61 TRACE("(%s %p)\n", debugstr_guid(riid), result);
62 return NS_NOINTERFACE;
65 static nsrefcnt NSAPI nsPromptService_AddRef(nsIPromptService *iface)
67 return 2;
70 static nsrefcnt NSAPI nsPromptService_Release(nsIPromptService *iface)
72 return 1;
75 static nsresult NSAPI nsPromptService_Alert(nsIPromptService *iface, mozIDOMWindowProxy *aParent,
76 const PRUnichar *aDialogTitle, const PRUnichar *aText)
78 HTMLOuterWindow *window;
79 BSTR text;
81 TRACE("(%p %s %s)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText));
83 window = mozwindow_to_window(aParent);
84 if(!window) {
85 WARN("Could not find HTMLWindow for mozIDOMWindowProxy %p\n", aParent);
86 return NS_ERROR_UNEXPECTED;
89 text = SysAllocString(aText);
90 IHTMLWindow2_alert(&window->base.IHTMLWindow2_iface, text);
91 SysFreeString(text);
93 return NS_OK;
96 static nsresult NSAPI nsPromptService_AlertCheck(nsIPromptService *iface,
97 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
98 const PRUnichar *aText, const PRUnichar *aCheckMsg, cpp_bool *aCheckState)
100 FIXME("(%p %s %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
101 debugstr_w(aCheckMsg), aCheckState);
102 return NS_ERROR_NOT_IMPLEMENTED;
105 static nsresult NSAPI nsPromptService_Confirm(nsIPromptService *iface,
106 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText,
107 cpp_bool *_retval)
109 FIXME("(%p %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), _retval);
110 return NS_ERROR_NOT_IMPLEMENTED;
113 static nsresult NSAPI nsPromptService_ConfirmCheck(nsIPromptService *iface,
114 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
115 const PRUnichar *aText, const PRUnichar *aCheckMsg, cpp_bool *aCheckState,
116 cpp_bool *_retval)
118 FIXME("(%p %s %s %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
119 debugstr_w(aCheckMsg), aCheckState, _retval);
120 return NS_ERROR_NOT_IMPLEMENTED;
123 static nsresult NSAPI nsPromptService_ConfirmEx(nsIPromptService *iface,
124 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
125 const PRUnichar *aText, UINT32 aButtonFlags, const PRUnichar *aButton0Title,
126 const PRUnichar *aButton1Title, const PRUnichar *aButton2Title,
127 const PRUnichar *aCheckMsg, cpp_bool *aCheckState, LONG *_retval)
129 FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent, debugstr_w(aDialogTitle),
130 debugstr_w(aText), aButtonFlags, debugstr_w(aButton0Title),
131 debugstr_w(aButton1Title), debugstr_w(aButton2Title), debugstr_w(aCheckMsg),
132 aCheckState, _retval);
135 * FIXME:
136 * This is really very very ugly hack!!!
139 if(aButton0Title && !memcmp(aButton0Title, L"Continue", sizeof(L"Continue")))
140 *_retval = 0;
141 else if(aButton1Title && !memcmp(aButton1Title, L"Continue", sizeof(L"Continue")))
142 *_retval = 1;
143 else if(aButton2Title && !memcmp(aButton2Title, L"Continue", sizeof(L"Continue")))
144 *_retval = 2;
145 /* else
146 * let's hope that _retval is set to the default value */
148 return NS_OK;
151 static nsresult NSAPI nsPromptService_Prompt(nsIPromptService *iface,
152 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
153 const PRUnichar *aText, PRUnichar **aValue, const PRUnichar *aCheckMsg,
154 cpp_bool *aCheckState, cpp_bool *_retval)
156 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
157 aValue, debugstr_w(aCheckMsg), aCheckState, _retval);
158 return NS_ERROR_NOT_IMPLEMENTED;
161 static nsresult NSAPI nsPromptService_PromptUsernameAndPassword(nsIPromptService *iface,
162 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
163 const PRUnichar *aText, PRUnichar **aUsername, PRUnichar **aPassword,
164 const PRUnichar *aCheckMsg, cpp_bool *aCheckState, cpp_bool *_retval)
166 FIXME("(%p %s %s %p %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
167 debugstr_w(aText), aUsername, aPassword, debugstr_w(aCheckMsg), aCheckState,
168 _retval);
169 return NS_ERROR_NOT_IMPLEMENTED;
172 static nsresult NSAPI nsPromptService_PromptPassword(nsIPromptService *iface,
173 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
174 const PRUnichar *aText, PRUnichar **aPassword, const PRUnichar *aCheckMsg,
175 cpp_bool *aCheckState, cpp_bool *_retval)
177 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
178 debugstr_w(aText), aPassword, debugstr_w(aCheckMsg), aCheckState, _retval);
179 return NS_ERROR_NOT_IMPLEMENTED;
182 static nsresult NSAPI nsPromptService_Select(nsIPromptService *iface,
183 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
184 const PRUnichar *aText, UINT32 aCount, const PRUnichar **aSelectList,
185 LONG *aOutSelection, cpp_bool *_retval)
187 FIXME("(%p %s %s %d %p %p %p)\n", aParent, debugstr_w(aDialogTitle),
188 debugstr_w(aText), aCount, aSelectList, aOutSelection, _retval);
189 return NS_ERROR_NOT_IMPLEMENTED;
192 static const nsIPromptServiceVtbl PromptServiceVtbl = {
193 nsPromptService_QueryInterface,
194 nsPromptService_AddRef,
195 nsPromptService_Release,
196 nsPromptService_Alert,
197 nsPromptService_AlertCheck,
198 nsPromptService_Confirm,
199 nsPromptService_ConfirmCheck,
200 nsPromptService_ConfirmEx,
201 nsPromptService_Prompt,
202 nsPromptService_PromptUsernameAndPassword,
203 nsPromptService_PromptPassword,
204 nsPromptService_Select
207 static nsIPromptService nsPromptService = { &PromptServiceVtbl };
209 static nsresult NSAPI nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider *iface,
210 nsIIDRef riid, void **result)
212 *result = NULL;
214 if(IsEqualGUID(&IID_nsISupports, riid)) {
215 TRACE("(IID_nsISupports %p)\n", result);
216 *result = iface;
217 }else if(IsEqualGUID(&IID_nsITooltipTextProvider, riid)) {
218 TRACE("(IID_nsITooltipTextProvider %p)\n", result);
219 *result = iface;
222 if(*result) {
223 nsITooltipTextProvider_AddRef(iface);
224 return NS_OK;
227 WARN("(%s %p)\n", debugstr_guid(riid), result);
228 return NS_NOINTERFACE;
231 static nsrefcnt NSAPI nsTooltipTextProvider_AddRef(nsITooltipTextProvider *iface)
233 return 2;
236 static nsrefcnt NSAPI nsTooltipTextProvider_Release(nsITooltipTextProvider *iface)
238 return 1;
241 static nsresult NSAPI nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider *iface,
242 nsIDOMNode *aNode, PRUnichar **aText, cpp_bool *_retval)
244 nsIDOMHTMLElement *nselem;
245 nsIDOMNode *node = aNode, *parent;
246 nsAString title_str;
247 const PRUnichar *title = NULL;
248 nsresult nsres;
250 TRACE("(%p %p %p)\n", aNode, aText, _retval);
252 *aText = NULL;
254 nsAString_Init(&title_str, NULL);
256 do {
257 nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMHTMLElement, (void**)&nselem);
258 if(NS_SUCCEEDED(nsres)) {
259 title = NULL;
261 nsIDOMHTMLElement_GetTitle(nselem, &title_str);
262 nsIDOMHTMLElement_Release(nselem);
264 nsAString_GetData(&title_str, &title);
265 if(title && *title) {
266 if(node != aNode)
267 nsIDOMNode_Release(node);
268 break;
272 nsres = nsIDOMNode_GetParentNode(node, &parent);
273 if(NS_FAILED(nsres))
274 parent = NULL;
276 if(node != aNode)
277 nsIDOMNode_Release(node);
278 node = parent;
279 } while(node);
281 if(title && *title) {
282 int size = (lstrlenW(title)+1)*sizeof(PRUnichar);
284 *aText = nsalloc(size);
285 memcpy(*aText, title, size);
286 TRACE("aText = %s\n", debugstr_w(*aText));
288 *_retval = TRUE;
289 }else {
290 *_retval = FALSE;
293 nsAString_Finish(&title_str);
295 return NS_OK;
298 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl = {
299 nsTooltipTextProvider_QueryInterface,
300 nsTooltipTextProvider_AddRef,
301 nsTooltipTextProvider_Release,
302 nsTooltipTextProvider_GetNodeText
305 static nsITooltipTextProvider nsTooltipTextProvider = { &nsTooltipTextProviderVtbl };
307 typedef struct {
308 nsIFactory nsIFactory_iface;
309 nsISupports *service;
310 } nsServiceFactory;
312 static inline nsServiceFactory *impl_from_nsIFactory(nsIFactory *iface)
314 return CONTAINING_RECORD(iface, nsServiceFactory, nsIFactory_iface);
317 static nsresult NSAPI nsServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
318 void **result)
320 nsServiceFactory *This = impl_from_nsIFactory(iface);
322 *result = NULL;
324 if(IsEqualGUID(&IID_nsISupports, riid)) {
325 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
326 *result = &This->nsIFactory_iface;
327 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
328 TRACE("(%p)->(IID_nsIFactory %p)\n", This, result);
329 *result = &This->nsIFactory_iface;
332 if(*result)
333 return NS_OK;
335 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
336 return NS_NOINTERFACE;
339 static nsrefcnt NSAPI nsServiceFactory_AddRef(nsIFactory *iface)
341 return 2;
344 static nsrefcnt NSAPI nsServiceFactory_Release(nsIFactory *iface)
346 return 1;
349 static nsresult NSAPI nsServiceFactory_CreateInstance(nsIFactory *iface,
350 nsISupports *aOuter, const nsIID *iid, void **result)
352 nsServiceFactory *This = impl_from_nsIFactory(iface);
354 TRACE("(%p)->(%p %s %p)\n", This, aOuter, debugstr_guid(iid), result);
356 return nsISupports_QueryInterface(This->service, iid, result);
359 static nsresult NSAPI nsServiceFactory_LockFactory(nsIFactory *iface, cpp_bool lock)
361 nsServiceFactory *This = impl_from_nsIFactory(iface);
362 WARN("(%p)->(%x)\n", This, lock);
363 return NS_OK;
366 static const nsIFactoryVtbl nsServiceFactoryVtbl = {
367 nsServiceFactory_QueryInterface,
368 nsServiceFactory_AddRef,
369 nsServiceFactory_Release,
370 nsServiceFactory_CreateInstance,
371 nsServiceFactory_LockFactory
374 static nsServiceFactory nsPromptServiceFactory = {
375 { &nsServiceFactoryVtbl },
376 (nsISupports*)&nsPromptService
379 static nsServiceFactory nsTooltipTextFactory = {
380 { &nsServiceFactoryVtbl },
381 (nsISupports*)&nsTooltipTextProvider
384 void register_nsservice(nsIComponentRegistrar *registrar, nsIServiceManager *service_manager)
386 nsresult nsres;
388 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_PROMPTSERVICE_CID,
389 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID, &nsPromptServiceFactory.nsIFactory_iface);
390 if(NS_FAILED(nsres))
391 ERR("RegisterFactory failed: %08x\n", nsres);
393 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_TOOLTIPTEXTPROVIDER_CID,
394 NS_TOOLTIPTEXTPROVIDER_CLASSNAME, NS_TOOLTIPTEXTPROVIDER_CONTRACTID,
395 &nsTooltipTextFactory.nsIFactory_iface);
396 if(NS_FAILED(nsres))
397 ERR("RegisterFactory failed: %08x\n", nsres);