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"
33 #include "mshtml_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37 #define NS_PROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/prompt-service;1"
38 #define NS_WINDOWWATCHER_CONTRACTID "@mozilla.org/embedcomp/window-watcher;1"
39 #define NS_TOOLTIPTEXTPROVIDER_CONTRACTID "@mozilla.org/embedcomp/tooltiptextprovider;1"
41 #define NS_TOOLTIPTEXTPROVIDER_CLASSNAME "nsTooltipTextProvider"
43 static const nsIID NS_PROMPTSERVICE_CID =
44 {0xa2112d6a,0x0e28,0x421f,{0xb4,0x6a,0x25,0xc0,0xb3,0x8,0xcb,0xd0}};
45 static const nsIID NS_TOOLTIPTEXTPROVIDER_CID =
46 {0x0b666e3e,0x569a,0x462c,{0xa7,0xf0,0xb1,0x6b,0xb1,0x5d,0x42,0xff}};
48 static nsresult NSAPI nsWindowCreator_QueryInterface(nsIWindowCreator2 *iface, nsIIDRef riid,
53 if(IsEqualGUID(&IID_nsISupports, riid)) {
54 TRACE("(IID_nsISupports %p)\n", result);
56 }else if(IsEqualGUID(&IID_nsIWindowCreator, riid)) {
57 TRACE("(IID_nsIWindowCreator %p)\n", result);
59 }else if(IsEqualGUID(&IID_nsIWindowCreator2, riid)) {
60 TRACE("(IID_nsIWindowCreator2 %p)\n", result);
65 nsIWindowCreator_AddRef(iface);
69 WARN("(%s %p)\n", debugstr_guid(riid), result);
70 return NS_NOINTERFACE;
73 static nsrefcnt NSAPI nsWindowCreator_AddRef(nsIWindowCreator2 *iface)
78 static nsrefcnt NSAPI nsWindowCreator_Release(nsIWindowCreator2 *iface)
83 static nsresult NSAPI nsWindowCreator_CreateChromeWindow(nsIWindowCreator2 *iface,
84 nsIWebBrowserChrome *parent, PRUint32 chromeFlags, nsIWebBrowserChrome **_retval)
86 TRACE("(%p %08x %p)\n", parent, chromeFlags, _retval);
87 return nsIWindowCreator2_CreateChromeWindow2(iface, parent, chromeFlags, 0, NULL,
91 static nsresult NSAPI nsWindowCreator_CreateChromeWindow2(nsIWindowCreator2 *iface,
92 nsIWebBrowserChrome *parent, PRUint32 chromeFlags, PRUint32 contextFlags,
93 nsIURI *uri, PRBool *cancel, nsIWebBrowserChrome **_retval)
95 TRACE("(%p %08x %08x %p %p %p)\n", parent, chromeFlags, contextFlags, uri,
101 return create_chrome_window(parent, _retval);
104 static const nsIWindowCreator2Vtbl nsWindowCreatorVtbl = {
105 nsWindowCreator_QueryInterface,
106 nsWindowCreator_AddRef,
107 nsWindowCreator_Release,
108 nsWindowCreator_CreateChromeWindow,
109 nsWindowCreator_CreateChromeWindow2
112 static nsIWindowCreator2 nsWindowCreator = { &nsWindowCreatorVtbl };
114 static nsresult NSAPI nsPromptService_QueryInterface(nsIPromptService *iface,
115 nsIIDRef riid, void **result)
119 if(IsEqualGUID(&IID_nsISupports, riid)) {
120 TRACE("(IID_nsISupports %p)\n", result);
122 }else if(IsEqualGUID(&IID_nsIPromptService, riid)) {
123 TRACE("(IID_nsIPromptService %p)\n", result);
130 TRACE("(%s %p)\n", debugstr_guid(riid), result);
131 return NS_NOINTERFACE;
134 static nsrefcnt NSAPI nsPromptService_AddRef(nsIPromptService *iface)
139 static nsrefcnt NSAPI nsPromptService_Release(nsIPromptService *iface)
144 static nsresult NSAPI nsPromptService_Alert(nsIPromptService *iface, nsIDOMWindow *aParent,
145 const PRUnichar *aDialogTitle, const PRUnichar *aText)
150 TRACE("(%p %s %s)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText));
152 window = nswindow_to_window(aParent);
154 WARN("Could not find HTMLWindow for nsIDOMWindow %p\n", aParent);
155 return NS_ERROR_UNEXPECTED;
158 text = SysAllocString(aText);
159 IHTMLWindow2_alert(&window->IHTMLWindow2_iface, text);
165 static nsresult NSAPI nsPromptService_AlertCheck(nsIPromptService *iface,
166 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
167 const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState)
169 FIXME("(%p %s %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
170 debugstr_w(aCheckMsg), aCheckState);
171 return NS_ERROR_NOT_IMPLEMENTED;
174 static nsresult NSAPI nsPromptService_Confirm(nsIPromptService *iface,
175 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText,
178 FIXME("(%p %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), _retval);
179 return NS_ERROR_NOT_IMPLEMENTED;
182 static nsresult NSAPI nsPromptService_ConfirmCheck(nsIPromptService *iface,
183 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
184 const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState,
187 FIXME("(%p %s %s %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
188 debugstr_w(aCheckMsg), aCheckState, _retval);
189 return NS_ERROR_NOT_IMPLEMENTED;
192 static nsresult NSAPI nsPromptService_ConfirmEx(nsIPromptService *iface,
193 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
194 const PRUnichar *aText, PRUint32 aButtonFlags, const PRUnichar *aButton0Title,
195 const PRUnichar *aButton1Title, const PRUnichar *aButton2Title,
196 const PRUnichar *aCheckMsg, PRBool *aCheckState, PRInt32 *_retval)
198 static const PRUnichar wszContinue[] = {'C','o','n','t','i','n','u','e',0};
200 FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent, debugstr_w(aDialogTitle),
201 debugstr_w(aText), aButtonFlags, debugstr_w(aButton0Title),
202 debugstr_w(aButton1Title), debugstr_w(aButton2Title), debugstr_w(aCheckMsg),
203 aCheckState, _retval);
207 * This is really very very ugly hack!!!
210 if(aButton0Title && !memcmp(aButton0Title, wszContinue, sizeof(wszContinue)))
212 else if(aButton1Title && !memcmp(aButton1Title, wszContinue, sizeof(wszContinue)))
214 else if(aButton2Title && !memcmp(aButton2Title, wszContinue, sizeof(wszContinue)))
217 * let's hope that _retval is set to the default value */
222 static nsresult NSAPI nsPromptService_Prompt(nsIPromptService *iface,
223 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
224 const PRUnichar *aText, PRUnichar **aValue, const PRUnichar *aCheckMsg,
225 PRBool *aCheckState, PRBool *_retval)
227 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
228 aValue, debugstr_w(aCheckMsg), aCheckState, _retval);
229 return NS_ERROR_NOT_IMPLEMENTED;
232 static nsresult NSAPI nsPromptService_PromptUsernameAndPassword(nsIPromptService *iface,
233 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
234 const PRUnichar *aText, PRUnichar **aUsername, PRUnichar **aPassword,
235 const PRUnichar *aCheckMsg, PRBool *aCheckState, PRBool *_retval)
237 FIXME("(%p %s %s %p %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
238 debugstr_w(aText), aUsername, aPassword, debugstr_w(aCheckMsg), aCheckState,
240 return NS_ERROR_NOT_IMPLEMENTED;
243 static nsresult NSAPI nsPromptService_PromptPassword(nsIPromptService *iface,
244 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
245 const PRUnichar *aText, PRUnichar **aPassword, const PRUnichar *aCheckMsg,
246 PRBool *aCheckState, PRBool *_retval)
248 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
249 debugstr_w(aText), aPassword, debugstr_w(aCheckMsg), aCheckState, _retval);
250 return NS_ERROR_NOT_IMPLEMENTED;
253 static nsresult NSAPI nsPromptService_Select(nsIPromptService *iface,
254 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
255 const PRUnichar *aText, PRUint32 aCount, const PRUnichar **aSelectList,
256 PRInt32 *aOutSelection, PRBool *_retval)
258 FIXME("(%p %s %s %d %p %p %p)\n", aParent, debugstr_w(aDialogTitle),
259 debugstr_w(aText), aCount, aSelectList, aOutSelection, _retval);
260 return NS_ERROR_NOT_IMPLEMENTED;
263 static const nsIPromptServiceVtbl PromptServiceVtbl = {
264 nsPromptService_QueryInterface,
265 nsPromptService_AddRef,
266 nsPromptService_Release,
267 nsPromptService_Alert,
268 nsPromptService_AlertCheck,
269 nsPromptService_Confirm,
270 nsPromptService_ConfirmCheck,
271 nsPromptService_ConfirmEx,
272 nsPromptService_Prompt,
273 nsPromptService_PromptUsernameAndPassword,
274 nsPromptService_PromptPassword,
275 nsPromptService_Select
278 static nsIPromptService nsPromptService = { &PromptServiceVtbl };
280 static nsresult NSAPI nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider *iface,
281 nsIIDRef riid, void **result)
285 if(IsEqualGUID(&IID_nsISupports, riid)) {
286 TRACE("(IID_nsISupports %p)\n", result);
288 }else if(IsEqualGUID(&IID_nsITooltipTextProvider, riid)) {
289 TRACE("(IID_nsITooltipTextProvider %p)\n", result);
294 nsITooltipTextProvider_AddRef(iface);
298 WARN("(%s %p)\n", debugstr_guid(riid), result);
299 return NS_NOINTERFACE;
302 static nsrefcnt NSAPI nsTooltipTextProvider_AddRef(nsITooltipTextProvider *iface)
307 static nsrefcnt NSAPI nsTooltipTextProvider_Release(nsITooltipTextProvider *iface)
312 static nsresult NSAPI nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider *iface,
313 nsIDOMNode *aNode, PRUnichar **aText, PRBool *_retval)
315 nsIDOMHTMLElement *nselem;
316 nsIDOMNode *node = aNode, *parent;
318 const PRUnichar *title = NULL;
321 TRACE("(%p %p %p)\n", aNode, aText, _retval);
325 nsAString_Init(&title_str, NULL);
328 nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMHTMLElement, (void**)&nselem);
329 if(NS_SUCCEEDED(nsres)) {
332 nsIDOMHTMLElement_GetTitle(nselem, &title_str);
333 nsIDOMHTMLElement_Release(nselem);
335 nsAString_GetData(&title_str, &title);
336 if(title && *title) {
338 nsIDOMNode_Release(node);
343 nsres = nsIDOMNode_GetParentNode(node, &parent);
348 nsIDOMNode_Release(node);
352 if(title && *title) {
353 int size = (strlenW(title)+1)*sizeof(PRUnichar);
355 *aText = nsalloc(size);
356 memcpy(*aText, title, size);
357 TRACE("aText = %s\n", debugstr_w(*aText));
364 nsAString_Finish(&title_str);
369 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl = {
370 nsTooltipTextProvider_QueryInterface,
371 nsTooltipTextProvider_AddRef,
372 nsTooltipTextProvider_Release,
373 nsTooltipTextProvider_GetNodeText
376 static nsITooltipTextProvider nsTooltipTextProvider = { &nsTooltipTextProviderVtbl };
379 nsIFactory nsIFactory_iface;
380 nsISupports *service;
383 static inline nsServiceFactory *impl_from_nsIFactory(nsIFactory *iface)
385 return CONTAINING_RECORD(iface, nsServiceFactory, nsIFactory_iface);
388 static nsresult NSAPI nsServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
391 nsServiceFactory *This = impl_from_nsIFactory(iface);
395 if(IsEqualGUID(&IID_nsISupports, riid)) {
396 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
397 *result = &This->nsIFactory_iface;
398 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
399 TRACE("(%p)->(IID_nsIFactory %p)\n", This, result);
400 *result = &This->nsIFactory_iface;
406 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
407 return NS_NOINTERFACE;
410 static nsrefcnt NSAPI nsServiceFactory_AddRef(nsIFactory *iface)
415 static nsrefcnt NSAPI nsServiceFactory_Release(nsIFactory *iface)
420 static nsresult NSAPI nsServiceFactory_CreateInstance(nsIFactory *iface,
421 nsISupports *aOuter, const nsIID *iid, void **result)
423 nsServiceFactory *This = impl_from_nsIFactory(iface);
425 TRACE("(%p)->(%p %s %p)\n", This, aOuter, debugstr_guid(iid), result);
427 return nsISupports_QueryInterface(This->service, iid, result);
430 static nsresult NSAPI nsServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
432 nsServiceFactory *This = impl_from_nsIFactory(iface);
433 WARN("(%p)->(%x)\n", This, lock);
437 static const nsIFactoryVtbl nsServiceFactoryVtbl = {
438 nsServiceFactory_QueryInterface,
439 nsServiceFactory_AddRef,
440 nsServiceFactory_Release,
441 nsServiceFactory_CreateInstance,
442 nsServiceFactory_LockFactory
445 static nsServiceFactory nsPromptServiceFactory = {
446 { &nsServiceFactoryVtbl },
447 (nsISupports*)&nsPromptService
450 static nsServiceFactory nsTooltipTextFactory = {
451 { &nsServiceFactoryVtbl },
452 (nsISupports*)&nsTooltipTextProvider
455 void register_nsservice(nsIComponentRegistrar *registrar, nsIServiceManager *service_manager)
457 nsIWindowWatcher *window_watcher;
460 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_PROMPTSERVICE_CID,
461 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID, &nsPromptServiceFactory.nsIFactory_iface);
463 ERR("RegisterFactory failed: %08x\n", nsres);
465 nsres = nsIServiceManager_GetServiceByContractID(service_manager, NS_WINDOWWATCHER_CONTRACTID,
466 &IID_nsIWindowWatcher, (void**)&window_watcher);
467 if(NS_SUCCEEDED(nsres)) {
468 nsres = nsIWindowWatcher_SetWindowCreator(window_watcher,
469 (nsIWindowCreator*)&nsWindowCreator);
471 ERR("SetWindowCreator failed: %08x\n", nsres);
472 nsIWindowWatcher_Release(window_watcher);
474 ERR("Could not get WindowWatcher object: %08x\n", nsres);
477 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_TOOLTIPTEXTPROVIDER_CID,
478 NS_TOOLTIPTEXTPROVIDER_CLASSNAME, NS_TOOLTIPTEXTPROVIDER_CONTRACTID,
479 &nsTooltipTextFactory.nsIFactory_iface);
481 ERR("RegisterFactory failed: %08x\n", nsres);