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
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,
54 if(IsEqualGUID(&IID_nsISupports, riid)) {
55 TRACE("(IID_nsISupports %p)\n", result);
57 }else if(IsEqualGUID(&IID_nsIWindowCreator, riid)) {
58 TRACE("(IID_nsIWindowCreator %p)\n", result);
60 }else if(IsEqualGUID(&IID_nsIWindowCreator2, riid)) {
61 TRACE("(IID_nsIWindowCreator2 %p)\n", result);
66 nsIWindowCreator_AddRef(iface);
70 WARN("(%s %p)\n", debugstr_guid(riid), result);
71 return NS_NOINTERFACE;
74 static nsrefcnt NSAPI nsWindowCreator_AddRef(nsIWindowCreator2 *iface)
79 static nsrefcnt NSAPI nsWindowCreator_Release(nsIWindowCreator2 *iface)
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,
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,
102 return create_chrome_window(parent, _retval);
105 static const nsIWindowCreator2Vtbl nsWindowCreatorVtbl = {
106 nsWindowCreator_QueryInterface,
107 nsWindowCreator_AddRef,
108 nsWindowCreator_Release,
109 nsWindowCreator_CreateChromeWindow,
110 nsWindowCreator_CreateChromeWindow2
113 static nsIWindowCreator2 nsWindowCreator = { &nsWindowCreatorVtbl };
115 static nsresult NSAPI nsPromptService_QueryInterface(nsIPromptService *iface,
116 nsIIDRef riid, void **result)
120 if(IsEqualGUID(&IID_nsISupports, riid)) {
121 TRACE("(IID_nsISupports %p)\n", result);
123 }else if(IsEqualGUID(&IID_nsIPromptService, riid)) {
124 TRACE("(IID_nsIPromptService %p)\n", result);
131 TRACE("(%s %p)\n", debugstr_guid(riid), result);
132 return NS_NOINTERFACE;
135 static nsrefcnt NSAPI nsPromptService_AddRef(nsIPromptService *iface)
140 static nsrefcnt NSAPI nsPromptService_Release(nsIPromptService *iface)
145 static nsresult NSAPI nsPromptService_Alert(nsIPromptService *iface, nsIDOMWindow *aParent,
146 const PRUnichar *aDialogTitle, const PRUnichar *aText)
151 TRACE("(%p %s %s)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText));
153 window = nswindow_to_window(aParent);
155 WARN("Could not find HTMLWindow for nsIDOMWindow %p\n", aParent);
156 return NS_ERROR_UNEXPECTED;
159 text = SysAllocString(aText);
160 IHTMLWindow2_alert(&window->IHTMLWindow2_iface, text);
166 static nsresult NSAPI nsPromptService_AlertCheck(nsIPromptService *iface,
167 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
168 const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState)
170 FIXME("(%p %s %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
171 debugstr_w(aCheckMsg), aCheckState);
172 return NS_ERROR_NOT_IMPLEMENTED;
175 static nsresult NSAPI nsPromptService_Confirm(nsIPromptService *iface,
176 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText,
179 FIXME("(%p %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), _retval);
180 return NS_ERROR_NOT_IMPLEMENTED;
183 static nsresult NSAPI nsPromptService_ConfirmCheck(nsIPromptService *iface,
184 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
185 const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState,
188 FIXME("(%p %s %s %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
189 debugstr_w(aCheckMsg), aCheckState, _retval);
190 return NS_ERROR_NOT_IMPLEMENTED;
193 static nsresult NSAPI nsPromptService_ConfirmEx(nsIPromptService *iface,
194 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
195 const PRUnichar *aText, PRUint32 aButtonFlags, const PRUnichar *aButton0Title,
196 const PRUnichar *aButton1Title, const PRUnichar *aButton2Title,
197 const PRUnichar *aCheckMsg, PRBool *aCheckState, PRInt32 *_retval)
199 static const PRUnichar wszContinue[] = {'C','o','n','t','i','n','u','e',0};
201 FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent, debugstr_w(aDialogTitle),
202 debugstr_w(aText), aButtonFlags, debugstr_w(aButton0Title),
203 debugstr_w(aButton1Title), debugstr_w(aButton2Title), debugstr_w(aCheckMsg),
204 aCheckState, _retval);
208 * This is really very very ugly hack!!!
211 if(aButton0Title && !memcmp(aButton0Title, wszContinue, sizeof(wszContinue)))
213 else if(aButton1Title && !memcmp(aButton1Title, wszContinue, sizeof(wszContinue)))
215 else if(aButton2Title && !memcmp(aButton2Title, wszContinue, sizeof(wszContinue)))
218 * let's hope that _retval is set to the default value */
223 static nsresult NSAPI nsPromptService_Prompt(nsIPromptService *iface,
224 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
225 const PRUnichar *aText, PRUnichar **aValue, const PRUnichar *aCheckMsg,
226 PRBool *aCheckState, PRBool *_retval)
228 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
229 aValue, debugstr_w(aCheckMsg), aCheckState, _retval);
230 return NS_ERROR_NOT_IMPLEMENTED;
233 static nsresult NSAPI nsPromptService_PromptUsernameAndPassword(nsIPromptService *iface,
234 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
235 const PRUnichar *aText, PRUnichar **aUsername, PRUnichar **aPassword,
236 const PRUnichar *aCheckMsg, PRBool *aCheckState, PRBool *_retval)
238 FIXME("(%p %s %s %p %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
239 debugstr_w(aText), aUsername, aPassword, debugstr_w(aCheckMsg), aCheckState,
241 return NS_ERROR_NOT_IMPLEMENTED;
244 static nsresult NSAPI nsPromptService_PromptPassword(nsIPromptService *iface,
245 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
246 const PRUnichar *aText, PRUnichar **aPassword, const PRUnichar *aCheckMsg,
247 PRBool *aCheckState, PRBool *_retval)
249 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
250 debugstr_w(aText), aPassword, debugstr_w(aCheckMsg), aCheckState, _retval);
251 return NS_ERROR_NOT_IMPLEMENTED;
254 static nsresult NSAPI nsPromptService_Select(nsIPromptService *iface,
255 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
256 const PRUnichar *aText, PRUint32 aCount, const PRUnichar **aSelectList,
257 PRInt32 *aOutSelection, PRBool *_retval)
259 FIXME("(%p %s %s %d %p %p %p)\n", aParent, debugstr_w(aDialogTitle),
260 debugstr_w(aText), aCount, aSelectList, aOutSelection, _retval);
261 return NS_ERROR_NOT_IMPLEMENTED;
264 static const nsIPromptServiceVtbl PromptServiceVtbl = {
265 nsPromptService_QueryInterface,
266 nsPromptService_AddRef,
267 nsPromptService_Release,
268 nsPromptService_Alert,
269 nsPromptService_AlertCheck,
270 nsPromptService_Confirm,
271 nsPromptService_ConfirmCheck,
272 nsPromptService_ConfirmEx,
273 nsPromptService_Prompt,
274 nsPromptService_PromptUsernameAndPassword,
275 nsPromptService_PromptPassword,
276 nsPromptService_Select
279 static nsIPromptService nsPromptService = { &PromptServiceVtbl };
281 static nsresult NSAPI nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider *iface,
282 nsIIDRef riid, void **result)
286 if(IsEqualGUID(&IID_nsISupports, riid)) {
287 TRACE("(IID_nsISupports %p)\n", result);
289 }else if(IsEqualGUID(&IID_nsITooltipTextProvider, riid)) {
290 TRACE("(IID_nsITooltipTextProvider %p)\n", result);
295 nsITooltipTextProvider_AddRef(iface);
299 WARN("(%s %p)\n", debugstr_guid(riid), result);
300 return NS_NOINTERFACE;
303 static nsrefcnt NSAPI nsTooltipTextProvider_AddRef(nsITooltipTextProvider *iface)
308 static nsrefcnt NSAPI nsTooltipTextProvider_Release(nsITooltipTextProvider *iface)
313 static nsresult NSAPI nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider *iface,
314 nsIDOMNode *aNode, PRUnichar **aText, PRBool *_retval)
316 nsIDOMHTMLElement *nselem;
317 nsIDOMNode *node = aNode, *parent;
319 const PRUnichar *title = NULL;
322 TRACE("(%p %p %p)\n", aNode, aText, _retval);
326 nsAString_Init(&title_str, NULL);
329 nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMHTMLElement, (void**)&nselem);
330 if(NS_SUCCEEDED(nsres)) {
333 nsIDOMHTMLElement_GetTitle(nselem, &title_str);
334 nsIDOMHTMLElement_Release(nselem);
336 nsAString_GetData(&title_str, &title);
337 if(title && *title) {
339 nsIDOMNode_Release(node);
344 nsres = nsIDOMNode_GetParentNode(node, &parent);
349 nsIDOMNode_Release(node);
353 if(title && *title) {
354 int size = (strlenW(title)+1)*sizeof(PRUnichar);
356 *aText = nsalloc(size);
357 memcpy(*aText, title, size);
358 TRACE("aText = %s\n", debugstr_w(*aText));
365 nsAString_Finish(&title_str);
370 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl = {
371 nsTooltipTextProvider_QueryInterface,
372 nsTooltipTextProvider_AddRef,
373 nsTooltipTextProvider_Release,
374 nsTooltipTextProvider_GetNodeText
377 static nsITooltipTextProvider nsTooltipTextProvider = { &nsTooltipTextProviderVtbl };
380 nsIFactory nsIFactory_iface;
381 nsISupports *service;
384 static inline nsServiceFactory *impl_from_nsIFactory(nsIFactory *iface)
386 return CONTAINING_RECORD(iface, nsServiceFactory, nsIFactory_iface);
389 static nsresult NSAPI nsServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
392 nsServiceFactory *This = impl_from_nsIFactory(iface);
396 if(IsEqualGUID(&IID_nsISupports, riid)) {
397 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
398 *result = &This->nsIFactory_iface;
399 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
400 TRACE("(%p)->(IID_nsIFactory %p)\n", This, result);
401 *result = &This->nsIFactory_iface;
407 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
408 return NS_NOINTERFACE;
411 static nsrefcnt NSAPI nsServiceFactory_AddRef(nsIFactory *iface)
416 static nsrefcnt NSAPI nsServiceFactory_Release(nsIFactory *iface)
421 static nsresult NSAPI nsServiceFactory_CreateInstance(nsIFactory *iface,
422 nsISupports *aOuter, const nsIID *iid, void **result)
424 nsServiceFactory *This = impl_from_nsIFactory(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 = impl_from_nsIFactory(iface);
434 WARN("(%p)->(%x)\n", This, lock);
438 static const nsIFactoryVtbl nsServiceFactoryVtbl = {
439 nsServiceFactory_QueryInterface,
440 nsServiceFactory_AddRef,
441 nsServiceFactory_Release,
442 nsServiceFactory_CreateInstance,
443 nsServiceFactory_LockFactory
446 static nsServiceFactory nsPromptServiceFactory = {
447 { &nsServiceFactoryVtbl },
448 (nsISupports*)&nsPromptService
451 static nsServiceFactory nsTooltipTextFactory = {
452 { &nsServiceFactoryVtbl },
453 (nsISupports*)&nsTooltipTextProvider
456 void register_nsservice(nsIComponentRegistrar *registrar, nsIServiceManager *service_manager)
458 nsIWindowWatcher *window_watcher;
461 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_PROMPTSERVICE_CID,
462 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID, &nsPromptServiceFactory.nsIFactory_iface);
464 ERR("RegisterFactory failed: %08x\n", nsres);
466 nsres = nsIServiceManager_GetServiceByContractID(service_manager, NS_WINDOWWATCHER_CONTRACTID,
467 &IID_nsIWindowWatcher, (void**)&window_watcher);
468 if(NS_SUCCEEDED(nsres)) {
469 nsres = nsIWindowWatcher_SetWindowCreator(window_watcher,
470 (nsIWindowCreator*)&nsWindowCreator);
472 ERR("SetWindowCreator failed: %08x\n", nsres);
473 nsIWindowWatcher_Release(window_watcher);
475 ERR("Could not get WindowWatcher object: %08x\n", nsres);
478 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_TOOLTIPTEXTPROVIDER_CID,
479 NS_TOOLTIPTEXTPROVIDER_CLASSNAME, NS_TOOLTIPTEXTPROVIDER_CONTRACTID,
480 &nsTooltipTextFactory.nsIFactory_iface);
482 ERR("RegisterFactory failed: %08x\n", nsres);