Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygennsservice.c
Go to the documentation of this file.
00001 /* 00002 * Copyright 2005 Jacek Caban 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00017 */ 00018 00019 #include "config.h" 00020 00021 #include <stdarg.h> 00022 00023 #define COBJMACROS 00024 00025 #include "windef.h" 00026 #include "winbase.h" 00027 #include "winuser.h" 00028 #include "winreg.h" 00029 #include "ole2.h" 00030 00031 #include "wine/debug.h" 00032 #include "wine/unicode.h" 00033 00034 #include "mshtml_private.h" 00035 00036 WINE_DEFAULT_DEBUG_CHANNEL(mshtml); 00037 00038 #define NS_PROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/prompt-service;1" 00039 #define NS_WINDOWWATCHER_CONTRACTID "@mozilla.org/embedcomp/window-watcher;1" 00040 #define NS_TOOLTIPTEXTPROVIDER_CONTRACTID "@mozilla.org/embedcomp/tooltiptextprovider;1" 00041 00042 #define NS_TOOLTIPTEXTPROVIDER_CLASSNAME "nsTooltipTextProvider" 00043 00044 static const nsIID NS_PROMPTSERVICE_CID = 00045 {0xa2112d6a,0x0e28,0x421f,{0xb4,0x6a,0x25,0xc0,0xb3,0x8,0xcb,0xd0}}; 00046 static const nsIID NS_TOOLTIPTEXTPROVIDER_CID = 00047 {0x0b666e3e,0x569a,0x462c,{0xa7,0xf0,0xb1,0x6b,0xb1,0x5d,0x42,0xff}}; 00048 00049 static nsresult NSAPI nsWindowCreator_QueryInterface(nsIWindowCreator2 *iface, nsIIDRef riid, 00050 nsQIResult result) 00051 { 00052 *result = NULL; 00053 00054 if(IsEqualGUID(&IID_nsISupports, riid)) { 00055 TRACE("(IID_nsISupports %p)\n", result); 00056 *result = iface; 00057 }else if(IsEqualGUID(&IID_nsIWindowCreator, riid)) { 00058 TRACE("(IID_nsIWindowCreator %p)\n", result); 00059 *result = iface; 00060 }else if(IsEqualGUID(&IID_nsIWindowCreator2, riid)) { 00061 TRACE("(IID_nsIWindowCreator2 %p)\n", result); 00062 *result = iface; 00063 } 00064 00065 if(*result) { 00066 nsIWindowCreator_AddRef(iface); 00067 return NS_OK; 00068 } 00069 00070 WARN("(%s %p)\n", debugstr_guid(riid), result); 00071 return NS_NOINTERFACE; 00072 } 00073 00074 static nsrefcnt NSAPI nsWindowCreator_AddRef(nsIWindowCreator2 *iface) 00075 { 00076 return 2; 00077 } 00078 00079 static nsrefcnt NSAPI nsWindowCreator_Release(nsIWindowCreator2 *iface) 00080 { 00081 return 1; 00082 } 00083 00084 static nsresult NSAPI nsWindowCreator_CreateChromeWindow(nsIWindowCreator2 *iface, 00085 nsIWebBrowserChrome *parent, PRUint32 chromeFlags, nsIWebBrowserChrome **_retval) 00086 { 00087 TRACE("(%p %08x %p)\n", parent, chromeFlags, _retval); 00088 return nsIWindowCreator2_CreateChromeWindow2(iface, parent, chromeFlags, 0, NULL, 00089 NULL, _retval); 00090 } 00091 00092 static nsresult NSAPI nsWindowCreator_CreateChromeWindow2(nsIWindowCreator2 *iface, 00093 nsIWebBrowserChrome *parent, PRUint32 chromeFlags, PRUint32 contextFlags, 00094 nsIURI *uri, PRBool *cancel, nsIWebBrowserChrome **_retval) 00095 { 00096 TRACE("(%p %08x %08x %p %p %p)\n", parent, chromeFlags, contextFlags, uri, 00097 cancel, _retval); 00098 00099 if(cancel) 00100 *cancel = FALSE; 00101 00102 *_retval = NSWBCHROME(NSContainer_Create(NULL, (NSContainer*)parent)); 00103 return NS_OK; 00104 } 00105 00106 static const nsIWindowCreator2Vtbl nsWindowCreatorVtbl = { 00107 nsWindowCreator_QueryInterface, 00108 nsWindowCreator_AddRef, 00109 nsWindowCreator_Release, 00110 nsWindowCreator_CreateChromeWindow, 00111 nsWindowCreator_CreateChromeWindow2 00112 }; 00113 00114 static nsIWindowCreator2 nsWindowCreator = { &nsWindowCreatorVtbl }; 00115 00116 static nsresult NSAPI nsPromptService_QueryInterface(nsIPromptService *iface, 00117 nsIIDRef riid, nsQIResult result) 00118 { 00119 *result = NULL; 00120 00121 if(IsEqualGUID(&IID_nsISupports, riid)) { 00122 TRACE("(IID_nsISupports %p)\n", result); 00123 *result = iface; 00124 }else if(IsEqualGUID(&IID_nsIPromptService, riid)) { 00125 TRACE("(IID_nsIPromptService %p)\n", result); 00126 *result = iface; 00127 } 00128 00129 if(*result) 00130 return NS_OK; 00131 00132 TRACE("(%s %p)\n", debugstr_guid(riid), result); 00133 return NS_NOINTERFACE; 00134 } 00135 00136 static nsrefcnt NSAPI nsPromptService_AddRef(nsIPromptService *iface) 00137 { 00138 return 2; 00139 } 00140 00141 static nsrefcnt NSAPI nsPromptService_Release(nsIPromptService *iface) 00142 { 00143 return 1; 00144 } 00145 00146 static nsresult NSAPI nsPromptService_Alert(nsIPromptService *iface, nsIDOMWindow *aParent, 00147 const PRUnichar *aDialogTitle, const PRUnichar *aText) 00148 { 00149 HTMLWindow *window; 00150 BSTR text; 00151 00152 TRACE("(%p %s %s)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText)); 00153 00154 window = nswindow_to_window(aParent); 00155 if(!window) { 00156 WARN("Could not find HTMLWindow for nsIDOMWindow %p\n", aParent); 00157 return NS_ERROR_UNEXPECTED; 00158 } 00159 00160 text = SysAllocString(aText); 00161 IHTMLWindow2_alert(HTMLWINDOW2(window), text); 00162 SysFreeString(text); 00163 00164 return NS_OK; 00165 } 00166 00167 static nsresult NSAPI nsPromptService_AlertCheck(nsIPromptService *iface, 00168 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, 00169 const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState) 00170 { 00171 FIXME("(%p %s %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), 00172 debugstr_w(aCheckMsg), aCheckState); 00173 return NS_ERROR_NOT_IMPLEMENTED; 00174 } 00175 00176 static nsresult NSAPI nsPromptService_Confirm(nsIPromptService *iface, 00177 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText, 00178 PRBool *_retval) 00179 { 00180 FIXME("(%p %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), _retval); 00181 return NS_ERROR_NOT_IMPLEMENTED; 00182 } 00183 00184 static nsresult NSAPI nsPromptService_ConfirmCheck(nsIPromptService *iface, 00185 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, 00186 const PRUnichar *aText, const PRUnichar *aCheckMsg, PRBool *aCheckState, 00187 PRBool *_retval) 00188 { 00189 FIXME("(%p %s %s %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), 00190 debugstr_w(aCheckMsg), aCheckState, _retval); 00191 return NS_ERROR_NOT_IMPLEMENTED; 00192 } 00193 00194 static nsresult NSAPI nsPromptService_ConfirmEx(nsIPromptService *iface, 00195 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, 00196 const PRUnichar *aText, PRUint32 aButtonFlags, const PRUnichar *aButton0Title, 00197 const PRUnichar *aButton1Title, const PRUnichar *aButton2Title, 00198 const PRUnichar *aCheckMsg, PRBool *aCheckState, PRInt32 *_retval) 00199 { 00200 static const PRUnichar wszContinue[] = {'C','o','n','t','i','n','u','e',0}; 00201 00202 FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent, debugstr_w(aDialogTitle), 00203 debugstr_w(aText), aButtonFlags, debugstr_w(aButton0Title), 00204 debugstr_w(aButton1Title), debugstr_w(aButton2Title), debugstr_w(aCheckMsg), 00205 aCheckState, _retval); 00206 00207 /* 00208 * FIXME: 00209 * This is really very very ugly hack!!! 00210 */ 00211 00212 if(aButton0Title && !memcmp(aButton0Title, wszContinue, sizeof(wszContinue))) 00213 *_retval = 0; 00214 else if(aButton1Title && !memcmp(aButton1Title, wszContinue, sizeof(wszContinue))) 00215 *_retval = 1; 00216 else if(aButton2Title && !memcmp(aButton2Title, wszContinue, sizeof(wszContinue))) 00217 *_retval = 2; 00218 /* else 00219 * let's hope that _retval is set to the default value */ 00220 00221 return NS_OK; 00222 } 00223 00224 static nsresult NSAPI nsPromptService_Prompt(nsIPromptService *iface, 00225 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, 00226 const PRUnichar *aText, PRUnichar **aValue, const PRUnichar *aCheckMsg, 00227 PRBool *aCheckState, PRBool *_retval) 00228 { 00229 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), 00230 aValue, debugstr_w(aCheckMsg), aCheckState, _retval); 00231 return NS_ERROR_NOT_IMPLEMENTED; 00232 } 00233 00234 static nsresult NSAPI nsPromptService_PromptUsernameAndPassword(nsIPromptService *iface, 00235 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, 00236 const PRUnichar *aText, PRUnichar **aUsername, PRUnichar **aPassword, 00237 const PRUnichar *aCheckMsg, PRBool *aCheckState, PRBool *_retval) 00238 { 00239 FIXME("(%p %s %s %p %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), 00240 debugstr_w(aText), aUsername, aPassword, debugstr_w(aCheckMsg), aCheckState, 00241 _retval); 00242 return NS_ERROR_NOT_IMPLEMENTED; 00243 } 00244 00245 static nsresult NSAPI nsPromptService_PromptPassword(nsIPromptService *iface, 00246 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, 00247 const PRUnichar *aText, PRUnichar **aPassword, const PRUnichar *aCheckMsg, 00248 PRBool *aCheckState, PRBool *_retval) 00249 { 00250 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), 00251 debugstr_w(aText), aPassword, debugstr_w(aCheckMsg), aCheckState, _retval); 00252 return NS_ERROR_NOT_IMPLEMENTED; 00253 } 00254 00255 static nsresult NSAPI nsPromptService_Select(nsIPromptService *iface, 00256 nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, 00257 const PRUnichar *aText, PRUint32 aCount, const PRUnichar **aSelectList, 00258 PRInt32 *aOutSelection, PRBool *_retval) 00259 { 00260 FIXME("(%p %s %s %d %p %p %p)\n", aParent, debugstr_w(aDialogTitle), 00261 debugstr_w(aText), aCount, aSelectList, aOutSelection, _retval); 00262 return NS_ERROR_NOT_IMPLEMENTED; 00263 } 00264 00265 static const nsIPromptServiceVtbl PromptServiceVtbl = { 00266 nsPromptService_QueryInterface, 00267 nsPromptService_AddRef, 00268 nsPromptService_Release, 00269 nsPromptService_Alert, 00270 nsPromptService_AlertCheck, 00271 nsPromptService_Confirm, 00272 nsPromptService_ConfirmCheck, 00273 nsPromptService_ConfirmEx, 00274 nsPromptService_Prompt, 00275 nsPromptService_PromptUsernameAndPassword, 00276 nsPromptService_PromptPassword, 00277 nsPromptService_Select 00278 }; 00279 00280 static nsIPromptService nsPromptService = { &PromptServiceVtbl }; 00281 00282 static nsresult NSAPI nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider *iface, 00283 nsIIDRef riid, nsQIResult result) 00284 { 00285 *result = NULL; 00286 00287 if(IsEqualGUID(&IID_nsISupports, riid)) { 00288 TRACE("(IID_nsISupports %p)\n", result); 00289 *result = iface; 00290 }else if(IsEqualGUID(&IID_nsITooltipTextProvider, riid)) { 00291 TRACE("(IID_nsITooltipTextProvider %p)\n", result); 00292 *result = iface; 00293 } 00294 00295 if(*result) { 00296 nsITooltipTextProvider_AddRef(iface); 00297 return NS_OK; 00298 } 00299 00300 WARN("(%s %p)\n", debugstr_guid(riid), result); 00301 return NS_NOINTERFACE; 00302 } 00303 00304 static nsrefcnt NSAPI nsTooltipTextProvider_AddRef(nsITooltipTextProvider *iface) 00305 { 00306 return 2; 00307 } 00308 00309 static nsrefcnt NSAPI nsTooltipTextProvider_Release(nsITooltipTextProvider *iface) 00310 { 00311 return 1; 00312 } 00313 00314 static nsresult NSAPI nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider *iface, 00315 nsIDOMNode *aNode, PRUnichar **aText, PRBool *_retval) 00316 { 00317 nsIDOMHTMLElement *nselem; 00318 nsIDOMNode *node = aNode, *parent; 00319 nsAString title_str; 00320 const PRUnichar *title = NULL; 00321 nsresult nsres; 00322 00323 TRACE("(%p %p %p)\n", aNode, aText, _retval); 00324 00325 *aText = NULL; 00326 00327 nsAString_Init(&title_str, NULL); 00328 00329 do { 00330 nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMHTMLElement, (void**)&nselem); 00331 if(NS_SUCCEEDED(nsres)) { 00332 title = NULL; 00333 00334 nsIDOMHTMLElement_GetTitle(nselem, &title_str); 00335 nsIDOMHTMLElement_Release(nselem); 00336 00337 nsAString_GetData(&title_str, &title); 00338 if(title && *title) { 00339 if(node != aNode) 00340 nsIDOMNode_Release(node); 00341 break; 00342 } 00343 } 00344 00345 nsres = nsIDOMNode_GetParentNode(node, &parent); 00346 if(NS_FAILED(nsres)) 00347 parent = NULL; 00348 00349 if(node != aNode) 00350 nsIDOMNode_Release(node); 00351 node = parent; 00352 } while(node); 00353 00354 if(title && *title) { 00355 int size = (strlenW(title)+1)*sizeof(PRUnichar); 00356 00357 *aText = nsalloc(size); 00358 memcpy(*aText, title, size); 00359 TRACE("aText = %s\n", debugstr_w(*aText)); 00360 00361 *_retval = TRUE; 00362 }else { 00363 *_retval = FALSE; 00364 } 00365 00366 nsAString_Finish(&title_str); 00367 00368 return NS_OK; 00369 } 00370 00371 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl = { 00372 nsTooltipTextProvider_QueryInterface, 00373 nsTooltipTextProvider_AddRef, 00374 nsTooltipTextProvider_Release, 00375 nsTooltipTextProvider_GetNodeText 00376 }; 00377 00378 static nsITooltipTextProvider nsTooltipTextProvider = { &nsTooltipTextProviderVtbl }; 00379 00380 typedef struct { 00381 const nsIFactoryVtbl *lpFactoryVtbl; 00382 nsISupports *service; 00383 } nsServiceFactory; 00384 00385 #define NSFACTORY(x) ((nsIFactory*) &(x)->lpFactoryVtbl) 00386 00387 #define NSFACTORY_THIS(iface) DEFINE_THIS(nsServiceFactory, Factory, iface) 00388 00389 static nsresult NSAPI nsServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid, 00390 nsQIResult result) 00391 { 00392 nsServiceFactory *This = NSFACTORY_THIS(iface); 00393 00394 *result = NULL; 00395 00396 if(IsEqualGUID(&IID_nsISupports, riid)) { 00397 TRACE("(%p)->(IID_nsISupports %p)\n", This, result); 00398 *result = NSFACTORY(This); 00399 }else if(IsEqualGUID(&IID_nsIFactory, riid)) { 00400 TRACE("(%p)->(IID_nsIFactory %p)\n", This, result); 00401 *result = NSFACTORY(This); 00402 } 00403 00404 if(*result) 00405 return NS_OK; 00406 00407 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result); 00408 return NS_NOINTERFACE; 00409 } 00410 00411 static nsrefcnt NSAPI nsServiceFactory_AddRef(nsIFactory *iface) 00412 { 00413 return 2; 00414 } 00415 00416 static nsrefcnt NSAPI nsServiceFactory_Release(nsIFactory *iface) 00417 { 00418 return 1; 00419 } 00420 00421 static nsresult NSAPI nsServiceFactory_CreateInstance(nsIFactory *iface, 00422 nsISupports *aOuter, const nsIID *iid, void **result) 00423 { 00424 nsServiceFactory *This = NSFACTORY_THIS(iface); 00425 00426 TRACE("(%p)->(%p %s %p)\n", This, aOuter, debugstr_guid(iid), result); 00427 00428 return nsISupports_QueryInterface(This->service, iid, result); 00429 } 00430 00431 static nsresult NSAPI nsServiceFactory_LockFactory(nsIFactory *iface, PRBool lock) 00432 { 00433 nsServiceFactory *This = NSFACTORY_THIS(iface); 00434 WARN("(%p)->(%x)\n", This, lock); 00435 return NS_OK; 00436 } 00437 00438 #undef NSFACTORY_THIS 00439 00440 static const nsIFactoryVtbl nsServiceFactoryVtbl = { 00441 nsServiceFactory_QueryInterface, 00442 nsServiceFactory_AddRef, 00443 nsServiceFactory_Release, 00444 nsServiceFactory_CreateInstance, 00445 nsServiceFactory_LockFactory 00446 }; 00447 00448 static nsServiceFactory nsPromptServiceFactory = { 00449 &nsServiceFactoryVtbl, 00450 (nsISupports*)&nsPromptService 00451 }; 00452 00453 static nsServiceFactory nsTooltipTextFactory = { 00454 &nsServiceFactoryVtbl, 00455 (nsISupports*)&nsTooltipTextProvider 00456 }; 00457 00458 void register_nsservice(nsIComponentRegistrar *registrar, nsIServiceManager *service_manager) 00459 { 00460 nsIWindowWatcher *window_watcher; 00461 nsresult nsres; 00462 00463 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_PROMPTSERVICE_CID, 00464 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID, NSFACTORY(&nsPromptServiceFactory)); 00465 if(NS_FAILED(nsres)) 00466 ERR("RegisterFactory failed: %08x\n", nsres); 00467 00468 nsres = nsIServiceManager_GetServiceByContractID(service_manager, NS_WINDOWWATCHER_CONTRACTID, 00469 &IID_nsIWindowWatcher, (void**)&window_watcher); 00470 if(NS_SUCCEEDED(nsres)) { 00471 nsres = nsIWindowWatcher_SetWindowCreator(window_watcher, 00472 (nsIWindowCreator*)&nsWindowCreator); 00473 if(NS_FAILED(nsres)) 00474 ERR("SetWindowCreator failed: %08x\n", nsres); 00475 nsIWindowWatcher_Release(window_watcher); 00476 }else { 00477 ERR("Could not get WindowWatcher object: %08x\n", nsres); 00478 } 00479 00480 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_TOOLTIPTEXTPROVIDER_CID, 00481 NS_TOOLTIPTEXTPROVIDER_CLASSNAME, NS_TOOLTIPTEXTPROVIDER_CONTRACTID, 00482 NSFACTORY(&nsTooltipTextFactory)); 00483 if(NS_FAILED(nsres)) 00484 ERR("RegisterFactory failed: %08x\n", nsres); 00485 } Generated on Sun May 27 2012 04:25:06 for ReactOS by
1.7.6.1
|