Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

457 lines
12 KiB

  1. /*****************************************************************************\
  2. FILE: ftpwebvw.h
  3. DESCRIPTION:
  4. This file exists so WebView can automate the Ftp Shell Extension and get
  5. information like the MessageOfTheDay.
  6. \*****************************************************************************/
  7. #include "priv.h"
  8. #include "ftpwebvw.h"
  9. #include "msieftp.h"
  10. #include <shlguid.h>
  11. //===========================
  12. // *** IDispatch Interface ***
  13. //===========================
  14. STDMETHODIMP CFtpWebView::GetTypeInfoCount(UINT * pctinfo)
  15. {
  16. return CImpIDispatch::GetTypeInfoCount(pctinfo);
  17. }
  18. STDMETHODIMP CFtpWebView::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo * * pptinfo)
  19. {
  20. return CImpIDispatch::GetTypeInfo(itinfo, lcid, pptinfo);
  21. }
  22. STDMETHODIMP CFtpWebView::GetIDsOfNames(REFIID riid, OLECHAR * * rgszNames, UINT cNames, LCID lcid, DISPID * rgdispid)
  23. {
  24. return CImpIDispatch::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid);
  25. }
  26. STDMETHODIMP CFtpWebView::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, UINT * puArgErr)
  27. {
  28. return CImpIDispatch::Invoke(dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
  29. }
  30. //===========================
  31. // *** IFtpWebView Interface ***
  32. //===========================
  33. // IID_IShellFolderView added locally for doj compliance. It's a private interface, but not used on w2k or above
  34. // so it doesn't haved to be doc'ed.
  35. #include <initguid.h>
  36. // 37A378C0-F82D-11CE-AE65-08002B2E1262
  37. DEFINE_GUID(IID_IShellFolderView, 0x37A378C0L, 0xF82D, 0x11CE, 0xAE, 0x65, 0x08, 0x00, 0x2B, 0x2E, 0x12, 0x62);
  38. /*****************************************************************************\
  39. FUNCTION: _GetIFtpWebView
  40. DESCRIPTION:
  41. \*****************************************************************************/
  42. HRESULT CFtpWebView::_GetIFtpWebView(IFtpWebView ** ppfwb)
  43. {
  44. IShellFolderViewCB * psfvcb = NULL;
  45. HRESULT hr = S_FALSE;
  46. ASSERT(_punkSite);
  47. if (EVAL(ppfwb))
  48. *ppfwb = NULL;
  49. IUnknown_QueryService(_punkSite, SID_ShellFolderViewCB, IID_IShellFolderViewCB, (LPVOID *) &psfvcb);
  50. // IE4's shell32 doesn't support QS(SID_ShellFolderViewCB, IID_IShellFolderViewCB), so we need to
  51. // QS(SID_ShellFolderViewCB, IShellFolderView) and then use IShellFolderView::SetCallback()
  52. if (!psfvcb)
  53. {
  54. IDefViewFrame * pdvf = NULL;
  55. IUnknown_QueryService(_punkSite, SID_DefView, IID_IDefViewFrame, (LPVOID *) &pdvf);
  56. if (EVAL(pdvf))
  57. {
  58. IShellFolderView * psfv = NULL;
  59. pdvf->QueryInterface(IID_IShellFolderView, (LPVOID *) &psfv);
  60. if (EVAL(psfv))
  61. {
  62. if (EVAL(SUCCEEDED(psfv->SetCallback(NULL, &psfvcb))))
  63. {
  64. IShellFolderViewCB * psfvcbTemp = NULL;
  65. if (SUCCEEDED(psfv->SetCallback(psfvcb, &psfvcbTemp)) && psfvcbTemp)
  66. {
  67. // We should get NULL back but if not, release the ref instead of leaking.
  68. psfvcbTemp->Release();
  69. }
  70. }
  71. psfv->Release();
  72. }
  73. pdvf->Release();
  74. }
  75. }
  76. if (EVAL(psfvcb))
  77. {
  78. if (EVAL(SUCCEEDED(psfvcb->QueryInterface(IID_IFtpWebView, (LPVOID *) ppfwb))))
  79. hr = S_OK;
  80. psfvcb->Release();
  81. }
  82. return hr;
  83. }
  84. /*****************************************************************************\
  85. FUNCTION: IFtpWebView::get_MessageOfTheDay
  86. DESCRIPTION:
  87. \*****************************************************************************/
  88. HRESULT CFtpWebView::get_MessageOfTheDay(BSTR * pbstr)
  89. {
  90. IFtpWebView * pfwb;
  91. HRESULT hr = _GetIFtpWebView(&pfwb);
  92. if (EVAL(S_OK == hr))
  93. {
  94. ASSERT(pfwb);
  95. hr = pfwb->get_MessageOfTheDay(pbstr);
  96. pfwb->Release();
  97. }
  98. return hr;
  99. }
  100. /*****************************************************************************\
  101. FUNCTION: IFtpWebView::get_UserName
  102. DESCRIPTION:
  103. \*****************************************************************************/
  104. HRESULT CFtpWebView::get_UserName(BSTR * pbstr)
  105. {
  106. IFtpWebView * pfwb;
  107. HRESULT hr = _GetIFtpWebView(&pfwb);
  108. if (EVAL(S_OK == hr))
  109. {
  110. ASSERT(pfwb);
  111. hr = pfwb->get_UserName(pbstr);
  112. pfwb->Release();
  113. }
  114. return hr;
  115. }
  116. /*****************************************************************************\
  117. FUNCTION: IFtpWebView::get_Server
  118. DESCRIPTION:
  119. \*****************************************************************************/
  120. HRESULT CFtpWebView::get_Server(BSTR * pbstr)
  121. {
  122. IFtpWebView * pfwb;
  123. HRESULT hr = _GetIFtpWebView(&pfwb);
  124. if (EVAL(S_OK == hr))
  125. {
  126. ASSERT(pfwb);
  127. hr = pfwb->get_Server(pbstr);
  128. pfwb->Release();
  129. }
  130. return hr;
  131. }
  132. /*****************************************************************************\
  133. FUNCTION: IFtpWebView::get_Directory
  134. DESCRIPTION:
  135. \*****************************************************************************/
  136. HRESULT CFtpWebView::get_Directory(BSTR * pbstr)
  137. {
  138. IFtpWebView * pfwb;
  139. HRESULT hr = _GetIFtpWebView(&pfwb);
  140. if (EVAL(S_OK == hr))
  141. {
  142. ASSERT(pfwb);
  143. hr = pfwb->get_Directory(pbstr);
  144. pfwb->Release();
  145. }
  146. return hr;
  147. }
  148. /*****************************************************************************\
  149. FUNCTION: IFtpWebView::get_PasswordLength
  150. DESCRIPTION:
  151. \*****************************************************************************/
  152. HRESULT CFtpWebView::get_PasswordLength(long * plLength)
  153. {
  154. IFtpWebView * pfwb;
  155. HRESULT hr = _GetIFtpWebView(&pfwb);
  156. if (EVAL(S_OK == hr))
  157. {
  158. ASSERT(pfwb);
  159. hr = pfwb->get_PasswordLength(plLength);
  160. pfwb->Release();
  161. }
  162. return hr;
  163. }
  164. /*****************************************************************************\
  165. FUNCTION: IFtpWebView::get_EmailAddress
  166. DESCRIPTION:
  167. \*****************************************************************************/
  168. HRESULT CFtpWebView::get_EmailAddress(BSTR * pbstr)
  169. {
  170. IFtpWebView * pfwb;
  171. HRESULT hr = _GetIFtpWebView(&pfwb);
  172. if (EVAL(S_OK == hr))
  173. {
  174. ASSERT(pfwb);
  175. hr = pfwb->get_EmailAddress(pbstr);
  176. pfwb->Release();
  177. }
  178. return hr;
  179. }
  180. /*****************************************************************************\
  181. FUNCTION: IFtpWebView::put_EmailAddress
  182. DESCRIPTION:
  183. \*****************************************************************************/
  184. HRESULT CFtpWebView::put_EmailAddress(BSTR bstr)
  185. {
  186. IFtpWebView * pfwb;
  187. HRESULT hr = _GetIFtpWebView(&pfwb);
  188. if (EVAL(S_OK == hr))
  189. {
  190. ASSERT(pfwb);
  191. hr = pfwb->put_EmailAddress(bstr);
  192. pfwb->Release();
  193. }
  194. return hr;
  195. }
  196. /*****************************************************************************\
  197. FUNCTION: IFtpWebView::get_CurrentLoginAnonymous
  198. DESCRIPTION:
  199. \*****************************************************************************/
  200. HRESULT CFtpWebView::get_CurrentLoginAnonymous(VARIANT_BOOL * pfAnonymousLogin)
  201. {
  202. IFtpWebView * pfwb;
  203. HRESULT hr = _GetIFtpWebView(&pfwb);
  204. if (EVAL(S_OK == hr))
  205. {
  206. ASSERT(pfwb);
  207. hr = pfwb->get_CurrentLoginAnonymous(pfAnonymousLogin);
  208. pfwb->Release();
  209. }
  210. return hr;
  211. }
  212. /*****************************************************************************\
  213. FUNCTION: IFtpWebView::LoginAnonymously
  214. DESCRIPTION:
  215. \*****************************************************************************/
  216. HRESULT CFtpWebView::LoginAnonymously(void)
  217. {
  218. IFtpWebView * pfwb;
  219. HRESULT hr = _GetIFtpWebView(&pfwb);
  220. if (EVAL(S_OK == hr))
  221. {
  222. ASSERT(pfwb);
  223. hr = pfwb->LoginAnonymously();
  224. pfwb->Release();
  225. }
  226. return hr;
  227. }
  228. /*****************************************************************************\
  229. FUNCTION: IFtpWebView::LoginWithPassword
  230. DESCRIPTION:
  231. \*****************************************************************************/
  232. HRESULT CFtpWebView::LoginWithPassword(BSTR bUserName, BSTR bPassword)
  233. {
  234. IFtpWebView * pfwb;
  235. HRESULT hr = _GetIFtpWebView(&pfwb);
  236. if (EVAL(S_OK == hr))
  237. {
  238. ASSERT(pfwb);
  239. hr = pfwb->LoginWithPassword(bUserName, bPassword);
  240. pfwb->Release();
  241. }
  242. return hr;
  243. }
  244. /*****************************************************************************\
  245. FUNCTION: IFtpWebView::LoginWithoutPassword
  246. DESCRIPTION:
  247. \*****************************************************************************/
  248. HRESULT CFtpWebView::LoginWithoutPassword(BSTR bUserName)
  249. {
  250. IFtpWebView * pfwb;
  251. HRESULT hr = _GetIFtpWebView(&pfwb);
  252. if (EVAL(S_OK == hr))
  253. {
  254. ASSERT(pfwb);
  255. hr = pfwb->LoginWithoutPassword(bUserName);
  256. pfwb->Release();
  257. }
  258. return hr;
  259. }
  260. /*****************************************************************************\
  261. FUNCTION: IFtpWebView::InvokeHelp
  262. DESCRIPTION:
  263. \*****************************************************************************/
  264. HRESULT CFtpWebView::InvokeHelp(void)
  265. {
  266. IFtpWebView * pfwb;
  267. HRESULT hr = _GetIFtpWebView(&pfwb);
  268. if (EVAL(S_OK == hr))
  269. {
  270. ASSERT(pfwb);
  271. hr = pfwb->InvokeHelp();
  272. pfwb->Release();
  273. }
  274. return hr;
  275. }
  276. /*****************************************************************************\
  277. FUNCTION: CFtpWebView_Create
  278. DESCRIPTION:
  279. \*****************************************************************************/
  280. HRESULT CFtpWebView_Create(REFIID riid, LPVOID * ppv)
  281. {
  282. HRESULT hr = E_OUTOFMEMORY;
  283. CFtpWebView * pfwv = new CFtpWebView();
  284. if (pfwv)
  285. {
  286. hr = pfwv->QueryInterface(riid, ppv);
  287. pfwv->Release();
  288. }
  289. return hr;
  290. }
  291. /****************************************************\
  292. Constructor
  293. \****************************************************/
  294. CFtpWebView::CFtpWebView() : m_cRef(1), CImpIDispatch(&IID_IFtpWebView)
  295. {
  296. DllAddRef();
  297. // This needs to be allocated in Zero Inited Memory.
  298. // Assert that all Member Variables are inited to Zero.
  299. LEAK_ADDREF(LEAK_CFtpWebView);
  300. }
  301. /****************************************************\
  302. Destructor
  303. \****************************************************/
  304. /*****************************************************************************
  305. *
  306. * FtpView_OnRelease (from shell32.IShellView)
  307. *
  308. * When the view is released, clean up various stuff.
  309. *
  310. * (Note that there is a race here, because this->hwndOwner
  311. * doesn't get zero'd out on the OnWindowDestroy because the shell
  312. * doesn't give us a pdvsci...)
  313. *
  314. * We release the psf before triggering the timeout, which is a
  315. * signal to the trigger not to do anything.
  316. *
  317. * _UNDOCUMENTED_: This callback and its parameters are not documented.
  318. *
  319. *****************************************************************************/
  320. CFtpWebView::~CFtpWebView()
  321. {
  322. DllRelease();
  323. LEAK_DELREF(LEAK_CFtpWebView);
  324. }
  325. //===========================
  326. // *** IUnknown Interface ***
  327. //===========================
  328. ULONG CFtpWebView::AddRef()
  329. {
  330. m_cRef++;
  331. return m_cRef;
  332. }
  333. ULONG CFtpWebView::Release()
  334. {
  335. ASSERT(m_cRef > 0);
  336. m_cRef--;
  337. if (m_cRef > 0)
  338. return m_cRef;
  339. delete this;
  340. return 0;
  341. }
  342. HRESULT CFtpWebView::QueryInterface(REFIID riid, void **ppvObj)
  343. {
  344. static const QITAB qit[] = {
  345. QITABENT(CFtpWebView, IObjectWithSite),
  346. QITABENT(CFtpWebView, IDispatch),
  347. QITABENT(CFtpWebView, IObjectWithSite),
  348. QITABENT(CFtpWebView, IObjectSafety),
  349. QITABENT(CFtpWebView, IFtpWebView),
  350. { 0 },
  351. };
  352. return QISearch(this, qit, riid, ppvObj);
  353. }