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
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
)
50 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
51 TRACE("(IID_nsISupports %p)\n", result
);
53 }else if(IsEqualGUID(&IID_nsIPromptService
, riid
)) {
54 TRACE("(IID_nsIPromptService %p)\n", result
);
61 TRACE("(%s %p)\n", debugstr_guid(riid
), result
);
62 return NS_NOINTERFACE
;
65 static nsrefcnt NSAPI
nsPromptService_AddRef(nsIPromptService
*iface
)
70 static nsrefcnt NSAPI
nsPromptService_Release(nsIPromptService
*iface
)
75 static nsresult NSAPI
nsPromptService_Alert(nsIPromptService
*iface
, mozIDOMWindowProxy
*aParent
,
76 const PRUnichar
*aDialogTitle
, const PRUnichar
*aText
)
78 HTMLOuterWindow
*window
;
81 TRACE("(%p %s %s)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
));
83 window
= mozwindow_to_window(aParent
);
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
);
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
,
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
,
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
);
136 * This is really very very ugly hack!!!
139 if(aButton0Title
&& !memcmp(aButton0Title
, L
"Continue", sizeof(L
"Continue")))
141 else if(aButton1Title
&& !memcmp(aButton1Title
, L
"Continue", sizeof(L
"Continue")))
143 else if(aButton2Title
&& !memcmp(aButton2Title
, L
"Continue", sizeof(L
"Continue")))
146 * let's hope that _retval is set to the default value */
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
,
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
)
214 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
215 TRACE("(IID_nsISupports %p)\n", result
);
217 }else if(IsEqualGUID(&IID_nsITooltipTextProvider
, riid
)) {
218 TRACE("(IID_nsITooltipTextProvider %p)\n", result
);
223 nsITooltipTextProvider_AddRef(iface
);
227 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
228 return NS_NOINTERFACE
;
231 static nsrefcnt NSAPI
nsTooltipTextProvider_AddRef(nsITooltipTextProvider
*iface
)
236 static nsrefcnt NSAPI
nsTooltipTextProvider_Release(nsITooltipTextProvider
*iface
)
241 static nsresult NSAPI
nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider
*iface
,
242 nsIDOMNode
*aNode
, PRUnichar
**aText
, cpp_bool
*_retval
)
244 nsIDOMHTMLElement
*nselem
;
245 nsIDOMNode
*node
= aNode
, *parent
;
247 const PRUnichar
*title
= NULL
;
250 TRACE("(%p %p %p)\n", aNode
, aText
, _retval
);
254 nsAString_Init(&title_str
, NULL
);
257 nsres
= nsIDOMNode_QueryInterface(node
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
258 if(NS_SUCCEEDED(nsres
)) {
261 nsIDOMHTMLElement_GetTitle(nselem
, &title_str
);
262 nsIDOMHTMLElement_Release(nselem
);
264 nsAString_GetData(&title_str
, &title
);
265 if(title
&& *title
) {
267 nsIDOMNode_Release(node
);
272 nsres
= nsIDOMNode_GetParentNode(node
, &parent
);
277 nsIDOMNode_Release(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
));
293 nsAString_Finish(&title_str
);
298 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl
= {
299 nsTooltipTextProvider_QueryInterface
,
300 nsTooltipTextProvider_AddRef
,
301 nsTooltipTextProvider_Release
,
302 nsTooltipTextProvider_GetNodeText
305 static nsITooltipTextProvider nsTooltipTextProvider
= { &nsTooltipTextProviderVtbl
};
308 nsIFactory nsIFactory_iface
;
309 nsISupports
*service
;
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
,
320 nsServiceFactory
*This
= impl_from_nsIFactory(iface
);
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
;
335 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
336 return NS_NOINTERFACE
;
339 static nsrefcnt NSAPI
nsServiceFactory_AddRef(nsIFactory
*iface
)
344 static nsrefcnt NSAPI
nsServiceFactory_Release(nsIFactory
*iface
)
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
);
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
)
388 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_PROMPTSERVICE_CID
,
389 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID
, &nsPromptServiceFactory
.nsIFactory_iface
);
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
);
397 ERR("RegisterFactory failed: %08x\n", nsres
);