Leaked source code of windows server 2003
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.

335 lines
9.2 KiB

  1. #ifndef _WEBJIT_H_
  2. #define _WEBJIT_H_
  3. #include <commctrl.h>
  4. #define WM_DOWNLOAD_DONE WM_USER + 11
  5. #define WM_SETUP_ERROR WM_USER + 12
  6. #define WM_DOWNLOAD_ERROR WM_USER + 13
  7. #define WM_PROCESS_ERROR WM_USER + 14
  8. #define WM_INTERNAL_ERROR WM_USER + 15
  9. #define WM_START_TIMER WM_USER + 16
  10. #define WM_DONT_WAIT WM_USER + 17
  11. #define WM_DATA_AVAILABLE WM_USER + 18
  12. #define SUCCESS 0 // Component successfully downloaded and installed
  13. #define CANCELLED 2 // User canceled dialog
  14. #define NEVERASK 3 // User requested never to be asked to d/l this component again
  15. #define NO_MIME_MATCH 11
  16. #define NO_EXT_MATCH 12
  17. #define EXEC_ERROR 13
  18. #define TIMER_EXEC_POLL 1
  19. #define TIMER_EXEC_POLL_INTERVAL 1000
  20. #define TIMER_DOWNLOAD 2
  21. #define TIMER_DOWNLOAD_INTERVAL 10
  22. typedef enum
  23. {
  24. WJSTATE_INIT, // obj constructed
  25. WJSTATE_BINDING, // download in progress
  26. WJSTATE_DOWNLOADED, // OnStopBinding called
  27. WJSTATE_FINISHED_READ, // all data read
  28. WJSTATE_VERIFYING, // into VerifyTrust call
  29. WJSTATE_READY_TO_EXEC, // read to shell exec.
  30. WJSTATE_WAITING_PROCESS, // Start DoSetup
  31. WJSTATE_DONE, // all done, ready to free obj
  32. } WJSTATE;
  33. class CWebJit;
  34. typedef struct _WebJitParam
  35. {
  36. LPCSTR lpszResource;
  37. DWORD dwFlags;
  38. LPCWSTR pwszComponentId;
  39. CWebJit* pWebJit;
  40. HWND hWndParent;
  41. QUERYCONTEXT *pQueryInstalled;
  42. }
  43. WEBJIT_PARAM;
  44. extern IInternetSecurityManager* g_pSecurityManager;
  45. class CWebJit : public IBindStatusCallback
  46. , public IAuthenticate
  47. , public IInternetHostSecurityManager
  48. {
  49. private:
  50. // data members
  51. BOOL m_fInited;
  52. HMODULE m_hWintrustMod;
  53. BOOL m_fInitedCC;
  54. HMODULE m_hComCtlMod;
  55. DWORD m_dwFlags;
  56. LPCWSTR m_pwszComponentId;
  57. HWND m_hWndParent;
  58. QUERYCONTEXT* m_pQueryInstalled;
  59. DWORD m_cRef;
  60. DWORD m_dwTotal;
  61. DWORD m_dwCurrent;
  62. LPCSTR m_szResource; //don't own: don't free.
  63. LPWSTR m_pwszUrl;
  64. DWORD m_dwDownloadSpeed;
  65. IBindCtx* m_pbc;
  66. IMoniker* m_pMk;
  67. IStream* m_pStm;
  68. IBinding* m_pBinding;
  69. HWND m_hDialog;
  70. HANDLE m_hProcess;
  71. HANDLE m_hCacheFile;
  72. DWORD m_dwRetVal;
  73. HRESULT m_hDownloadResult;
  74. BOOL m_fResultIn;
  75. WJSTATE m_State;
  76. BOOL m_fAborted;
  77. BOOL m_fCalledAbort;
  78. HRESULT m_hrInternal;
  79. LPWSTR m_pwszMimeType;
  80. LPWSTR m_pwszRedirectUrl;
  81. LPWSTR m_pwszCacheFile;
  82. BOOL m_fHtml;
  83. BOOL m_fDownloadInited;
  84. #define TEMPREADBUFFERSIZE 8192
  85. CHAR* m_pTempBuffer;
  86. BOOL m_bReading;
  87. BOOL m_bStartedReadTimer;
  88. public:
  89. // constructors/destructors
  90. CWebJit(WEBJIT_PARAM* pWebJitParam);
  91. ~CWebJit();
  92. VOID ReleaseAll();
  93. // IUnknown methods
  94. STDMETHODIMP QueryInterface(REFIID riid, void ** ppv);
  95. STDMETHODIMP_(ULONG) AddRef();
  96. STDMETHODIMP_(ULONG) Release();
  97. // IBindStatusCallback methods
  98. STDMETHODIMP OnStartBinding(DWORD dwReserved, IBinding* pbinding);
  99. STDMETHODIMP GetPriority(LONG* pnPriority)
  100. {
  101. return S_OK;
  102. }
  103. STDMETHODIMP OnLowResource(DWORD dwReserved)
  104. {
  105. return S_OK;
  106. }
  107. STDMETHODIMP OnProgress(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR pwzStatusText);
  108. STDMETHODIMP OnStopBinding(HRESULT hrResult, LPCWSTR szError);
  109. STDMETHODIMP GetBindInfo(DWORD* pgrfBINDF, BINDINFO* pbindInfo);
  110. STDMETHODIMP OnDataAvailable(DWORD grfBSCF, DWORD dwSize, FORMATETC *pfmtetc, STGMEDIUM* pstgmed);
  111. STDMETHODIMP OnObjectAvailable(REFIID riid, IUnknown* punk);
  112. // IAuthenticate methods
  113. STDMETHODIMP Authenticate(HWND* phwnd, LPWSTR *pszUsername,LPWSTR *pszPassword);
  114. // IInternetHostSecurityManager
  115. STDMETHODIMP GetSecurityId( BYTE *pbSecurityId,
  116. DWORD *pcbSecurityId,
  117. DWORD_PTR dwReserved)
  118. {
  119. DEBUG_ENTER((DBG_DOWNLOAD,
  120. Hresult,
  121. "CWebJit::GetSecurityId",
  122. "this=%#x",
  123. this
  124. ));
  125. HRESULT hr = E_FAIL;
  126. IInternetSecurityManager *pSecMgr = g_pSecurityManager;
  127. if (pSecMgr)
  128. {
  129. hr = pSecMgr->GetSecurityId(m_pwszUrl, pbSecurityId,
  130. pcbSecurityId, dwReserved);
  131. }
  132. DEBUG_LEAVE(hr);
  133. return hr;
  134. }
  135. STDMETHODIMP ProcessUrlAction( DWORD dwAction,
  136. BYTE *pPolicy,
  137. DWORD cbPolicy,
  138. BYTE *pContext,
  139. DWORD cbContext,
  140. DWORD dwFlags,
  141. DWORD dwReserved)
  142. {
  143. DEBUG_ENTER((DBG_DOWNLOAD,
  144. Hresult,
  145. "CWebJit::ProcessUrlAction",
  146. "this=%#x, %d(%#x)",
  147. this, dwAction, dwAction
  148. ));
  149. HRESULT hr = E_FAIL;
  150. IInternetSecurityManager *pSecMgr = g_pSecurityManager;
  151. if (pSecMgr)
  152. {
  153. hr = pSecMgr->ProcessUrlAction(m_pwszUrl, dwAction, pPolicy,
  154. cbPolicy, pContext, cbContext,
  155. dwFlags, dwReserved);
  156. }
  157. DEBUG_LEAVE(hr);
  158. return hr;
  159. }
  160. STDMETHODIMP QueryCustomPolicy( REFGUID guidKey,
  161. BYTE **ppPolicy,
  162. DWORD *pcbPolicy,
  163. BYTE *pContext,
  164. DWORD cbContext,
  165. DWORD dwReserved)
  166. {
  167. DEBUG_ENTER((DBG_DOWNLOAD,
  168. Hresult,
  169. "CWebJit::ProcessUrlAction",
  170. "this=%#x",
  171. this
  172. ));
  173. HRESULT hr = E_FAIL;
  174. IInternetSecurityManager *pSecMgr = g_pSecurityManager;
  175. if (pSecMgr)
  176. {
  177. hr = pSecMgr->QueryCustomPolicy(m_pwszUrl, guidKey, ppPolicy,
  178. pcbPolicy, pContext, cbContext,
  179. dwReserved);
  180. }
  181. DEBUG_LEAVE(hr);
  182. return hr;
  183. }
  184. VOID UpdateDownloadResult(HRESULT hr, BOOL fFromOnStopBinding);
  185. VOID ProcessFile();
  186. HRESULT SetupDownload();
  187. HRESULT StartDownload();
  188. HRESULT ExecFile();
  189. HRESULT DisplayError(HRESULT hr, UINT nMsgError);
  190. HRESULT VerifyMimeAndExtension();
  191. BOOL NeedHostSecMgr();
  192. HRESULT VerifyTrust(BOOL fUseHostSecMgr);
  193. BOOL IsConnected(BOOL* pfIsOffline);
  194. VOID ProcessAbort();
  195. VOID Terminate(DWORD iRetVal);
  196. HRESULT CanWebJit();
  197. BOOL SetupWindow();
  198. DWORD GetDownloadSpeed();
  199. BOOL UpdateProgressUI();
  200. VOID UpdateStatusString();
  201. VOID ReadData();
  202. BOOL IsReadTimerStarted()
  203. {
  204. return m_bStartedReadTimer;
  205. }
  206. VOID SetReadTimerStarted()
  207. {
  208. m_bStartedReadTimer = TRUE;
  209. }
  210. VOID SetState(WJSTATE state)
  211. {
  212. m_State = state;
  213. }
  214. WJSTATE GetState()
  215. {
  216. return m_State;
  217. }
  218. HANDLE GetProcessHandle()
  219. {
  220. return m_hProcess;
  221. }
  222. VOID SetWindowHandle(HWND hDlg)
  223. {
  224. m_hDialog = hDlg;
  225. }
  226. DWORD GetResult()
  227. {
  228. return m_dwRetVal;
  229. }
  230. LPCWSTR GetComponentIdName()
  231. {
  232. return m_pwszComponentId;
  233. }
  234. BOOL IsDownloadInited()
  235. {
  236. return m_fDownloadInited;
  237. }
  238. VOID SetDownloadInited()
  239. {
  240. m_fDownloadInited = TRUE;
  241. }
  242. BOOL IsAborted()
  243. {
  244. return m_fAborted;
  245. }
  246. // to delayload InitCommonControlsEx
  247. HRESULT InitCC(void);
  248. #define DELAYCCAPI(_fn, _args, _nargs, ret) \
  249. ret _fn _args \
  250. { \
  251. HRESULT hres; \
  252. ret retval = 0; \
  253. hres = InitCC(); \
  254. if (SUCCEEDED(hres) && (_pfn##_fn)) \
  255. { \
  256. retval = _pfn##_fn _nargs; \
  257. } \
  258. return retval; \
  259. } \
  260. ret (STDAPICALLTYPE* _pfn##_fn) _args;
  261. DELAYCCAPI(InitCommonControlsEx,
  262. (LPINITCOMMONCONTROLSEX lpInitCtrls),
  263. (lpInitCtrls),
  264. BOOL);
  265. BOOL CWebJit::InitCommonControlsForWebJit();
  266. // to delayload WinVerifyTrust
  267. HRESULT Init(void);
  268. #define DELAYWVTAPI(_fn, _args, _nargs) \
  269. HRESULT _fn _args { \
  270. HRESULT hres = Init(); \
  271. if (SUCCEEDED(hres)) { \
  272. hres = _pfn##_fn _nargs; \
  273. } \
  274. return hres; } \
  275. HRESULT (STDAPICALLTYPE* _pfn##_fn) _args;
  276. DELAYWVTAPI(WinVerifyTrust,
  277. (HWND hwnd, GUID * ActionID, LPVOID ActionData),
  278. (hwnd, ActionID, ActionData));
  279. };
  280. INT_PTR CALLBACK WebJitProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  281. #endif _WEBJIT_H_