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 static const PRUnichar wszContinue
[] = {'C','o','n','t','i','n','u','e',0};
131 FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent
, debugstr_w(aDialogTitle
),
132 debugstr_w(aText
), aButtonFlags
, debugstr_w(aButton0Title
),
133 debugstr_w(aButton1Title
), debugstr_w(aButton2Title
), debugstr_w(aCheckMsg
),
134 aCheckState
, _retval
);
138 * This is really very very ugly hack!!!
141 if(aButton0Title
&& !memcmp(aButton0Title
, wszContinue
, sizeof(wszContinue
)))
143 else if(aButton1Title
&& !memcmp(aButton1Title
, wszContinue
, sizeof(wszContinue
)))
145 else if(aButton2Title
&& !memcmp(aButton2Title
, wszContinue
, sizeof(wszContinue
)))
148 * let's hope that _retval is set to the default value */
153 static nsresult NSAPI
nsPromptService_Prompt(nsIPromptService
*iface
,
154 mozIDOMWindowProxy
*aParent
, const PRUnichar
*aDialogTitle
,
155 const PRUnichar
*aText
, PRUnichar
**aValue
, const PRUnichar
*aCheckMsg
,
156 cpp_bool
*aCheckState
, cpp_bool
*_retval
)
158 FIXME("(%p %s %s %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
),
159 aValue
, debugstr_w(aCheckMsg
), aCheckState
, _retval
);
160 return NS_ERROR_NOT_IMPLEMENTED
;
163 static nsresult NSAPI
nsPromptService_PromptUsernameAndPassword(nsIPromptService
*iface
,
164 mozIDOMWindowProxy
*aParent
, const PRUnichar
*aDialogTitle
,
165 const PRUnichar
*aText
, PRUnichar
**aUsername
, PRUnichar
**aPassword
,
166 const PRUnichar
*aCheckMsg
, cpp_bool
*aCheckState
, cpp_bool
*_retval
)
168 FIXME("(%p %s %s %p %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
169 debugstr_w(aText
), aUsername
, aPassword
, debugstr_w(aCheckMsg
), aCheckState
,
171 return NS_ERROR_NOT_IMPLEMENTED
;
174 static nsresult NSAPI
nsPromptService_PromptPassword(nsIPromptService
*iface
,
175 mozIDOMWindowProxy
*aParent
, const PRUnichar
*aDialogTitle
,
176 const PRUnichar
*aText
, PRUnichar
**aPassword
, const PRUnichar
*aCheckMsg
,
177 cpp_bool
*aCheckState
, cpp_bool
*_retval
)
179 FIXME("(%p %s %s %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
180 debugstr_w(aText
), aPassword
, debugstr_w(aCheckMsg
), aCheckState
, _retval
);
181 return NS_ERROR_NOT_IMPLEMENTED
;
184 static nsresult NSAPI
nsPromptService_Select(nsIPromptService
*iface
,
185 mozIDOMWindowProxy
*aParent
, const PRUnichar
*aDialogTitle
,
186 const PRUnichar
*aText
, UINT32 aCount
, const PRUnichar
**aSelectList
,
187 LONG
*aOutSelection
, cpp_bool
*_retval
)
189 FIXME("(%p %s %s %d %p %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
190 debugstr_w(aText
), aCount
, aSelectList
, aOutSelection
, _retval
);
191 return NS_ERROR_NOT_IMPLEMENTED
;
194 static const nsIPromptServiceVtbl PromptServiceVtbl
= {
195 nsPromptService_QueryInterface
,
196 nsPromptService_AddRef
,
197 nsPromptService_Release
,
198 nsPromptService_Alert
,
199 nsPromptService_AlertCheck
,
200 nsPromptService_Confirm
,
201 nsPromptService_ConfirmCheck
,
202 nsPromptService_ConfirmEx
,
203 nsPromptService_Prompt
,
204 nsPromptService_PromptUsernameAndPassword
,
205 nsPromptService_PromptPassword
,
206 nsPromptService_Select
209 static nsIPromptService nsPromptService
= { &PromptServiceVtbl
};
211 static nsresult NSAPI
nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider
*iface
,
212 nsIIDRef riid
, void **result
)
216 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
217 TRACE("(IID_nsISupports %p)\n", result
);
219 }else if(IsEqualGUID(&IID_nsITooltipTextProvider
, riid
)) {
220 TRACE("(IID_nsITooltipTextProvider %p)\n", result
);
225 nsITooltipTextProvider_AddRef(iface
);
229 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
230 return NS_NOINTERFACE
;
233 static nsrefcnt NSAPI
nsTooltipTextProvider_AddRef(nsITooltipTextProvider
*iface
)
238 static nsrefcnt NSAPI
nsTooltipTextProvider_Release(nsITooltipTextProvider
*iface
)
243 static nsresult NSAPI
nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider
*iface
,
244 nsIDOMNode
*aNode
, PRUnichar
**aText
, cpp_bool
*_retval
)
246 nsIDOMHTMLElement
*nselem
;
247 nsIDOMNode
*node
= aNode
, *parent
;
249 const PRUnichar
*title
= NULL
;
252 TRACE("(%p %p %p)\n", aNode
, aText
, _retval
);
256 nsAString_Init(&title_str
, NULL
);
259 nsres
= nsIDOMNode_QueryInterface(node
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
260 if(NS_SUCCEEDED(nsres
)) {
263 nsIDOMHTMLElement_GetTitle(nselem
, &title_str
);
264 nsIDOMHTMLElement_Release(nselem
);
266 nsAString_GetData(&title_str
, &title
);
267 if(title
&& *title
) {
269 nsIDOMNode_Release(node
);
274 nsres
= nsIDOMNode_GetParentNode(node
, &parent
);
279 nsIDOMNode_Release(node
);
283 if(title
&& *title
) {
284 int size
= (lstrlenW(title
)+1)*sizeof(PRUnichar
);
286 *aText
= nsalloc(size
);
287 memcpy(*aText
, title
, size
);
288 TRACE("aText = %s\n", debugstr_w(*aText
));
295 nsAString_Finish(&title_str
);
300 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl
= {
301 nsTooltipTextProvider_QueryInterface
,
302 nsTooltipTextProvider_AddRef
,
303 nsTooltipTextProvider_Release
,
304 nsTooltipTextProvider_GetNodeText
307 static nsITooltipTextProvider nsTooltipTextProvider
= { &nsTooltipTextProviderVtbl
};
310 nsIFactory nsIFactory_iface
;
311 nsISupports
*service
;
314 static inline nsServiceFactory
*impl_from_nsIFactory(nsIFactory
*iface
)
316 return CONTAINING_RECORD(iface
, nsServiceFactory
, nsIFactory_iface
);
319 static nsresult NSAPI
nsServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
322 nsServiceFactory
*This
= impl_from_nsIFactory(iface
);
326 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
327 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
328 *result
= &This
->nsIFactory_iface
;
329 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
330 TRACE("(%p)->(IID_nsIFactory %p)\n", This
, result
);
331 *result
= &This
->nsIFactory_iface
;
337 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
338 return NS_NOINTERFACE
;
341 static nsrefcnt NSAPI
nsServiceFactory_AddRef(nsIFactory
*iface
)
346 static nsrefcnt NSAPI
nsServiceFactory_Release(nsIFactory
*iface
)
351 static nsresult NSAPI
nsServiceFactory_CreateInstance(nsIFactory
*iface
,
352 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
354 nsServiceFactory
*This
= impl_from_nsIFactory(iface
);
356 TRACE("(%p)->(%p %s %p)\n", This
, aOuter
, debugstr_guid(iid
), result
);
358 return nsISupports_QueryInterface(This
->service
, iid
, result
);
361 static nsresult NSAPI
nsServiceFactory_LockFactory(nsIFactory
*iface
, cpp_bool lock
)
363 nsServiceFactory
*This
= impl_from_nsIFactory(iface
);
364 WARN("(%p)->(%x)\n", This
, lock
);
368 static const nsIFactoryVtbl nsServiceFactoryVtbl
= {
369 nsServiceFactory_QueryInterface
,
370 nsServiceFactory_AddRef
,
371 nsServiceFactory_Release
,
372 nsServiceFactory_CreateInstance
,
373 nsServiceFactory_LockFactory
376 static nsServiceFactory nsPromptServiceFactory
= {
377 { &nsServiceFactoryVtbl
},
378 (nsISupports
*)&nsPromptService
381 static nsServiceFactory nsTooltipTextFactory
= {
382 { &nsServiceFactoryVtbl
},
383 (nsISupports
*)&nsTooltipTextProvider
386 void register_nsservice(nsIComponentRegistrar
*registrar
, nsIServiceManager
*service_manager
)
390 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_PROMPTSERVICE_CID
,
391 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID
, &nsPromptServiceFactory
.nsIFactory_iface
);
393 ERR("RegisterFactory failed: %08x\n", nsres
);
395 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_TOOLTIPTEXTPROVIDER_CID
,
396 NS_TOOLTIPTEXTPROVIDER_CLASSNAME
, NS_TOOLTIPTEXTPROVIDER_CONTRACTID
,
397 &nsTooltipTextFactory
.nsIFactory_iface
);
399 ERR("RegisterFactory failed: %08x\n", nsres
);