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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 %08lx %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 %08lx %08lx %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
)
149 FIXME("(%p %s %s)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
));
150 return NS_ERROR_NOT_IMPLEMENTED
;
153 static nsresult NSAPI
nsPromptService_AlertCheck(nsIPromptService
*iface
,
154 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
155 const PRUnichar
*aText
, const PRUnichar
*aCheckMsg
, PRBool
*aCheckState
)
157 FIXME("(%p %s %s %s %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
),
158 debugstr_w(aCheckMsg
), aCheckState
);
159 return NS_ERROR_NOT_IMPLEMENTED
;
162 static nsresult NSAPI
nsPromptService_Confirm(nsIPromptService
*iface
,
163 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
, const PRUnichar
*aText
,
166 FIXME("(%p %s %s %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
), _retval
);
167 return NS_ERROR_NOT_IMPLEMENTED
;
170 static nsresult NSAPI
nsPromptService_ConfirmCheck(nsIPromptService
*iface
,
171 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
172 const PRUnichar
*aText
, const PRUnichar
*aCheckMsg
, PRBool
*aCheckState
,
175 FIXME("(%p %s %s %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
),
176 debugstr_w(aCheckMsg
), aCheckState
, _retval
);
177 return NS_ERROR_NOT_IMPLEMENTED
;
180 static nsresult NSAPI
nsPromptService_ConfirmEx(nsIPromptService
*iface
,
181 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
182 const PRUnichar
*aText
, PRUint32 aButtonFlags
, const PRUnichar
*aButton0Title
,
183 const PRUnichar
*aButton1Title
, const PRUnichar
*aButton2Title
,
184 const PRUnichar
*aCheckMsg
, PRBool
*aCheckState
, PRInt32
*_retval
)
186 static const PRUnichar wszContinue
[] = {'C','o','n','t','i','n','u','e',0};
188 FIXME("(%p %s %s %08lx %s %s %s %s %p %p) hack!\n", aParent
, debugstr_w(aDialogTitle
),
189 debugstr_w(aText
), aButtonFlags
, debugstr_w(aButton0Title
),
190 debugstr_w(aButton1Title
), debugstr_w(aButton2Title
), debugstr_w(aCheckMsg
),
191 aCheckState
, _retval
);
195 * This is really very very ugly hack!!!
198 if(aButton0Title
&& !memcmp(aButton0Title
, wszContinue
, sizeof(wszContinue
)))
200 else if(aButton1Title
&& !memcmp(aButton1Title
, wszContinue
, sizeof(wszContinue
)))
202 else if(aButton2Title
&& !memcmp(aButton2Title
, wszContinue
, sizeof(wszContinue
)))
205 * let's hope that _retval is set to the default value */
210 static nsresult NSAPI
nsPromptService_Prompt(nsIPromptService
*iface
,
211 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
212 const PRUnichar
*aText
, PRUnichar
**aValue
, const PRUnichar
*aCheckMsg
,
213 PRBool
*aCheckState
, PRBool
*_retval
)
215 FIXME("(%p %s %s %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
),
216 aValue
, debugstr_w(aCheckMsg
), aCheckState
, _retval
);
217 return NS_ERROR_NOT_IMPLEMENTED
;
220 static nsresult NSAPI
nsPromptService_PromptUsernameAndPassword(nsIPromptService
*iface
,
221 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
222 const PRUnichar
*aText
, PRUnichar
**aUsername
, PRUnichar
**aPassword
,
223 const PRUnichar
*aCheckMsg
, PRBool
*aCheckState
, PRBool
*_retval
)
225 FIXME("(%p %s %s %p %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
226 debugstr_w(aText
), aUsername
, aPassword
, debugstr_w(aCheckMsg
), aCheckState
,
228 return NS_ERROR_NOT_IMPLEMENTED
;
231 static nsresult NSAPI
nsPromptService_PromptPassword(nsIPromptService
*iface
,
232 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
233 const PRUnichar
*aText
, PRUnichar
**aPassword
, const PRUnichar
*aCheckMsg
,
234 PRBool
*aCheckState
, PRBool
*_retval
)
236 FIXME("(%p %s %s %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
237 debugstr_w(aText
), aPassword
, debugstr_w(aCheckMsg
), aCheckState
, _retval
);
238 return NS_ERROR_NOT_IMPLEMENTED
;
241 static nsresult NSAPI
nsPromptService_Select(nsIPromptService
*iface
,
242 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
243 const PRUnichar
*aText
, PRUint32 aCount
, const PRUnichar
**aSelectList
,
244 PRInt32
*aOutSelection
, PRBool
*_retval
)
246 FIXME("(%p %s %s %ld %p %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
247 debugstr_w(aText
), aCount
, aSelectList
, aOutSelection
, _retval
);
248 return NS_ERROR_NOT_IMPLEMENTED
;
251 static const nsIPromptServiceVtbl PromptServiceVtbl
= {
252 nsPromptService_QueryInterface
,
253 nsPromptService_AddRef
,
254 nsPromptService_Release
,
255 nsPromptService_Alert
,
256 nsPromptService_AlertCheck
,
257 nsPromptService_Confirm
,
258 nsPromptService_ConfirmCheck
,
259 nsPromptService_ConfirmEx
,
260 nsPromptService_Prompt
,
261 nsPromptService_PromptUsernameAndPassword
,
262 nsPromptService_PromptPassword
,
263 nsPromptService_Select
266 static nsIPromptService nsPromptService
= { &PromptServiceVtbl
};
268 static nsresult NSAPI
nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider
*iface
,
269 nsIIDRef riid
, nsQIResult result
)
273 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
274 TRACE("(IID_nsISupports %p)\n", result
);
276 }else if(IsEqualGUID(&IID_nsITooltipTextProvider
, riid
)) {
277 TRACE("(IID_nsITooltipTextProvider %p)\n", result
);
282 nsITooltipTextProvider_AddRef(iface
);
286 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
287 return NS_NOINTERFACE
;
290 static nsrefcnt NSAPI
nsTooltipTextProvider_AddRef(nsITooltipTextProvider
*iface
)
295 static nsrefcnt NSAPI
nsTooltipTextProvider_Release(nsITooltipTextProvider
*iface
)
300 static nsresult NSAPI
nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider
*iface
,
301 nsIDOMNode
*aNode
, PRUnichar
**aText
, PRBool
*_retval
)
303 nsIDOMHTMLElement
*nselem
;
304 nsIDOMNode
*node
= aNode
, *parent
;
306 const PRUnichar
*title
= NULL
;
309 TRACE("(%p %p %p)\n", aNode
, aText
, _retval
);
313 nsAString_Init(&title_str
, NULL
);
316 nsres
= nsIDOMNode_QueryInterface(node
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
317 if(NS_SUCCEEDED(nsres
)) {
320 nsIDOMHTMLElement_GetTitle(nselem
, &title_str
);
321 nsIDOMHTMLElement_Release(nselem
);
323 nsAString_GetData(&title_str
, &title
, NULL
);
324 if(title
&& *title
) {
326 nsIDOMNode_Release(node
);
331 nsres
= nsIDOMNode_GetParentNode(node
, &parent
);
336 nsIDOMNode_Release(node
);
340 if(title
&& *title
) {
341 int size
= (strlenW(title
)+1)*sizeof(PRUnichar
);
343 *aText
= nsalloc(size
);
344 memcpy(*aText
, title
, size
);
345 TRACE("aText = %s\n", debugstr_w(*aText
));
352 nsAString_Finish(&title_str
);
357 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl
= {
358 nsTooltipTextProvider_QueryInterface
,
359 nsTooltipTextProvider_AddRef
,
360 nsTooltipTextProvider_Release
,
361 nsTooltipTextProvider_GetNodeText
364 static nsITooltipTextProvider nsTooltipTextProvider
= { &nsTooltipTextProviderVtbl
};
367 const nsIFactoryVtbl
*lpFactoryVtbl
;
368 nsISupports
*service
;
371 #define NSFACTORY(x) ((nsIFactory*) &(x)->lpFactoryVtbl)
373 #define NSFACTORY_THIS(iface) DEFINE_THIS(nsServiceFactory, Factory, iface)
375 static nsresult NSAPI
nsServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
378 nsServiceFactory
*This
= NSFACTORY_THIS(iface
);
382 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
383 TRACE("(%p)->(IID_nsISupoprts %p)\n", This
, result
);
384 *result
= NSFACTORY(This
);
385 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
386 TRACE("(%p)->(IID_nsIFactory %p)\n", This
, result
);
387 *result
= NSFACTORY(This
);
393 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
394 return NS_NOINTERFACE
;
397 static nsrefcnt NSAPI
nsServiceFactory_AddRef(nsIFactory
*iface
)
402 static nsrefcnt NSAPI
nsServiceFactory_Release(nsIFactory
*iface
)
407 static nsresult NSAPI
nsServiceFactory_CreateInstance(nsIFactory
*iface
,
408 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
410 nsServiceFactory
*This
= NSFACTORY_THIS(iface
);
412 TRACE("(%p)->(%p %s %p)\n", This
, aOuter
, debugstr_guid(iid
), result
);
414 return nsISupports_QueryInterface(This
->service
, iid
, result
);
417 static nsresult NSAPI
nsServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
419 nsServiceFactory
*This
= NSFACTORY_THIS(iface
);
420 WARN("(%p)->(%x)\n", This
, lock
);
424 #undef NSFACTORY_THIS
426 static const nsIFactoryVtbl nsServiceFactoryVtbl
= {
427 nsServiceFactory_QueryInterface
,
428 nsServiceFactory_AddRef
,
429 nsServiceFactory_Release
,
430 nsServiceFactory_CreateInstance
,
431 nsServiceFactory_LockFactory
434 static nsServiceFactory nsPromptServiceFactory
= {
435 &nsServiceFactoryVtbl
,
436 (nsISupports
*)&nsPromptService
439 static nsServiceFactory nsTooltipTextFactory
= {
440 &nsServiceFactoryVtbl
,
441 (nsISupports
*)&nsTooltipTextProvider
444 void register_nsservice(nsIComponentRegistrar
*registrar
, nsIServiceManager
*service_manager
)
446 nsIWindowWatcher
*window_watcher
;
449 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_PROMPTSERVICE_CID
,
450 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID
, NSFACTORY(&nsPromptServiceFactory
));
452 ERR("RegisterFactory failed: %08lx\n", nsres
);
454 nsres
= nsIServiceManager_GetServiceByContactID(service_manager
, NS_WINDOWWATCHER_CONTRACTID
,
455 &IID_nsIWindowWatcher
, (void**)&window_watcher
);
456 if(NS_SUCCEEDED(nsres
)) {
457 nsres
= nsIWindowWatcher_SetWindowCreator(window_watcher
,
458 (nsIWindowCreator
*)&nsWindowCreator
);
460 ERR("SetWindowCreator failed: %08lx\n", nsres
);
461 nsIWindowWatcher_Release(window_watcher
);
463 ERR("Could not get WindowWatcher object: %08lx\n", nsres
);
466 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_TOOLTIPTEXTPROVIDER_CID
,
467 NS_TOOLTIPTEXTPROVIDER_CLASSNAME
, NS_TOOLTIPTEXTPROVIDER_CONTRACTID
,
468 NSFACTORY(&nsTooltipTextFactory
));
470 ERR("RegisterFactory failed: %08lx\n", nsres
);