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 *_retval
= NSWBCHROME(NSContainer_Create(NULL
, (NSContainer
*)parent
));
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
)
121 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
122 TRACE("(IID_nsISupports %p)\n", result
);
124 }else if(IsEqualGUID(&IID_nsIPromptService
, riid
)) {
125 TRACE("(IID_nsIPromptService %p)\n", result
);
132 TRACE("(%s %p)\n", debugstr_guid(riid
), result
);
133 return NS_NOINTERFACE
;
136 static nsrefcnt NSAPI
nsPromptService_AddRef(nsIPromptService
*iface
)
141 static nsrefcnt NSAPI
nsPromptService_Release(nsIPromptService
*iface
)
146 static nsresult NSAPI
nsPromptService_Alert(nsIPromptService
*iface
, nsIDOMWindow
*aParent
,
147 const PRUnichar
*aDialogTitle
, const PRUnichar
*aText
)
152 TRACE("(%p %s %s)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
));
154 window
= nswindow_to_window(aParent
);
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
);
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
,
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
,
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
);
209 * This is really very very ugly hack!!!
212 if(aButton0Title
&& !memcmp(aButton0Title
, wszContinue
, sizeof(wszContinue
)))
214 else if(aButton1Title
&& !memcmp(aButton1Title
, wszContinue
, sizeof(wszContinue
)))
216 else if(aButton2Title
&& !memcmp(aButton2Title
, wszContinue
, sizeof(wszContinue
)))
219 * let's hope that _retval is set to the default value */
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
,
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
)
287 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
288 TRACE("(IID_nsISupports %p)\n", result
);
290 }else if(IsEqualGUID(&IID_nsITooltipTextProvider
, riid
)) {
291 TRACE("(IID_nsITooltipTextProvider %p)\n", result
);
296 nsITooltipTextProvider_AddRef(iface
);
300 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
301 return NS_NOINTERFACE
;
304 static nsrefcnt NSAPI
nsTooltipTextProvider_AddRef(nsITooltipTextProvider
*iface
)
309 static nsrefcnt NSAPI
nsTooltipTextProvider_Release(nsITooltipTextProvider
*iface
)
314 static nsresult NSAPI
nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider
*iface
,
315 nsIDOMNode
*aNode
, PRUnichar
**aText
, PRBool
*_retval
)
317 nsIDOMHTMLElement
*nselem
;
318 nsIDOMNode
*node
= aNode
, *parent
;
320 const PRUnichar
*title
= NULL
;
323 TRACE("(%p %p %p)\n", aNode
, aText
, _retval
);
327 nsAString_Init(&title_str
, NULL
);
330 nsres
= nsIDOMNode_QueryInterface(node
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
331 if(NS_SUCCEEDED(nsres
)) {
334 nsIDOMHTMLElement_GetTitle(nselem
, &title_str
);
335 nsIDOMHTMLElement_Release(nselem
);
337 nsAString_GetData(&title_str
, &title
);
338 if(title
&& *title
) {
340 nsIDOMNode_Release(node
);
345 nsres
= nsIDOMNode_GetParentNode(node
, &parent
);
350 nsIDOMNode_Release(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
));
366 nsAString_Finish(&title_str
);
371 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl
= {
372 nsTooltipTextProvider_QueryInterface
,
373 nsTooltipTextProvider_AddRef
,
374 nsTooltipTextProvider_Release
,
375 nsTooltipTextProvider_GetNodeText
378 static nsITooltipTextProvider nsTooltipTextProvider
= { &nsTooltipTextProviderVtbl
};
381 const nsIFactoryVtbl
*lpFactoryVtbl
;
382 nsISupports
*service
;
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
,
392 nsServiceFactory
*This
= NSFACTORY_THIS(iface
);
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
);
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
= 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
);
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
;
463 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_PROMPTSERVICE_CID
,
464 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID
, NSFACTORY(&nsPromptServiceFactory
));
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
);
474 ERR("SetWindowCreator failed: %08x\n", nsres
);
475 nsIWindowWatcher_Release(window_watcher
);
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
));
484 ERR("RegisterFactory failed: %08x\n", nsres
);