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.

270 lines
11 KiB

  1. #ifndef _DOWNLD_HXX_
  2. #define _DOWNLD_HXX_
  3. #include <mshtmdid.h>
  4. #include <mshtml.h>
  5. #include <hlink.h>
  6. #include "packager.h"
  7. #ifndef GUIDSTR_MAX
  8. // GUIDSTR_MAX is 39 and includes the terminating zero.
  9. // == Copied from OLE source code =================================
  10. // format for string form of GUID is (leading identifier ????)
  11. // ????{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}
  12. #define GUIDSTR_MAX (1+ 8 + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 12 + 1 + 1)
  13. // ================================================================
  14. #endif
  15. // Trace and debug flags
  16. #define TF_WEBCHECKCORE 0x00001000
  17. //#define TF_SCHEDULER 0x00002000
  18. #define TF_WEBCRAWL 0x00004000
  19. //#define TF_FAVORITES 0x00008000
  20. #define TF_CDFAGENT 0x00010000
  21. #define TF_STRINGLIST 0x00020000
  22. #define TF_URLDOWNLOAD 0x00040000
  23. #define TF_DOWNLD 0x00080000
  24. #define TF_DIALMON 0x00100000
  25. #define TF_MAILAGENT 0x00200000
  26. #define TF_TRAYAGENT 0x00400000
  27. #define TF_SUBSFOLDER 0x00800000
  28. #define TF_MEMORY 0x01000000
  29. #define TF_UPDATEAGENT 0x02000000
  30. #define TF_POSTAGENT 0x04000000
  31. #define TF_DELAGENT 0x08000000
  32. #define TF_TRACKCACHE 0x10000000
  33. #define TF_SYNCMGR 0x20000000
  34. #define TF_THROTTLER 0x40000000
  35. #define PSM_QUERYSIBLINGS_WPARAM_RESCHEDULE 0XF000
  36. #undef DBG
  37. #define DBG(sz) TraceMsg(TF_THISMODULE, sz)
  38. #define DBG2(sz1, sz2) TraceMsg(TF_THISMODULE, sz1, sz2)
  39. #define DBG_WARN(sz) TraceMsg(TF_WARNING, sz)
  40. #define DBG_WARN2(sz1, sz2) TraceMsg(TF_WARNING, sz1, sz2)
  41. #ifdef DEBUG
  42. #define DBGASSERT(expr,sz) do { if (!(expr)) TraceMsg(TF_WARNING, (sz)); } while (0)
  43. #define DBGIID(sz,iid) DumpIID(sz,iid)
  44. #else
  45. #define DBGASSERT(expr,sz) ((void)0)
  46. #define DBGIID(sz,iid) ((void)0)
  47. #endif
  48. // shorthand
  49. #ifndef SAFERELEASE
  50. #define SAFERELEASE(p) if ((p) != NULL) { (p)->Release(); (p) = NULL; } else
  51. #endif
  52. #ifndef ATOMICRELEASE
  53. #define ATOMICRELEASET(p,type) { type* punkT=p; p=NULL; punkT->Release(); }
  54. #define ATOMICRELEASE(p) ATOMICRELEASET(p, IUnknown)
  55. #endif
  56. #ifndef SAFEFREEBSTR
  57. #define SAFEFREEBSTR(p) if ((p) != NULL) { SysFreeString(p); (p) = NULL; } else
  58. #endif
  59. #ifndef SAFEFREEOLESTR
  60. #define SAFEFREEOLESTR(p) if ((p) != NULL) { CoTaskMemFree(p); (p) = NULL; } else
  61. #endif
  62. #ifndef SAFELOCALFREE
  63. #define SAFELOCALFREE(p) if ((p) != NULL) { LocalFree(p); (p) = NULL; } else
  64. #endif
  65. #ifndef SAFEDELETE
  66. #define SAFEDELETE(p) if ((p) != NULL) { delete (p); (p) = NULL; } else
  67. #endif
  68. #define URLDL_WNDCLASS TEXT("TridentThicketUrlDlClass")
  69. #define ACCEPT_LANG_MAX 256
  70. // Options for BeginDownloadURL2
  71. typedef enum {
  72. BDU2_BROWSER // always download into the browser
  73. } BDUMethod;
  74. typedef DWORD BDUOptions;
  75. // BDUOptions
  76. #define BDU2_NONE 0
  77. #define BDU2_NEEDSTREAM 1 // keep an istream around from bdu2_urlmon download
  78. // OnDownloadComplete error codes
  79. #define BDU2_ERROR_NONE 0
  80. #define BDU2_ERROR_GENERAL 1
  81. #define BDU2_ERROR_ABORT 2
  82. #define BDU2_ERROR_MAXSIZE 3
  83. #define BDU2_ERROR_TIMEOUT 4
  84. // CUrlDowload hosts one browser and can handle one download at a time.
  85. //
  86. // Use of class CUrlDownload:
  87. //
  88. // 1) Create and AddRef it
  89. // 1.5) call put_Flags() to set the bind status callback IBrowseControl::Flags
  90. // 2) Call BeginDownloadURL2 to start a download
  91. // 3) Call BeginDownloadURL2 to start another download, reusing browser
  92. // 4) Call DoneDownloading() when finished
  93. // 5) Release()
  94. // DoneDownloading() must be called before Release() or the CUrlDownload instance may
  95. // continue to receive notifications from the browser and attempt to pass them to
  96. // the parent. It unhooks itself as soon as OnProgress(-1) is received. But be safe.
  97. // See webcrawl.h and webcrawl.cpp for example
  98. class CUrlDownload : public IOleClientSite // e_notimpl
  99. , public IPropertyNotifySink // for readystate change notifications
  100. , public IOleCommandTarget // for client pull callbacks
  101. , public IDispatch // for ambient properties
  102. , public IServiceProvider // for IAuthenticate and IHlinkFrame
  103. , public IAuthenticate // for Basic and NTLM authentication
  104. , public IHlinkFrame // for catching the post of a form
  105. , public IInternetSecurityManager // for allowing the post of a form
  106. {
  107. public:
  108. CUrlDownload( CThicketProgress *ptp, HRESULT *phr, UINT cpDL );
  109. ~CUrlDownload();
  110. void SetFormSubmitted(BOOL fFormSubmitted) { m_fFormSubmitted = fFormSubmitted; }
  111. BOOL GetFormSubmitted(void) { return m_fFormSubmitted; }
  112. // An E_ return code from this function may be ignored if desired. The
  113. // client's OnDownloadComplete will be called with fAborted==TRUE after this
  114. // function returns with an error value.
  115. HRESULT BeginDownloadURL2(LPCWSTR, BDUMethod, BDUOptions, LPTSTR, DWORD);
  116. HRESULT SetDLCTL(long lFlags); // DLCTL flags used for browser control
  117. HRESULT AbortDownload(int iErrorCode=-1); // S_OK, S_FALSE, E_FAIL
  118. void ReleaseScript() { SAFERELEASE(m_pScript); } // Releases internal reference
  119. HRESULT GetDocument(IHTMLDocument2 **ppDoc);
  120. void DoneDownloading(); // Call before releasing. Will destroy browser and windows.
  121. // URL manipulation functions
  122. static HRESULT StripAnchor(LPWSTR lpURL);
  123. // Should only be called from CUrlDownloadMsgProc
  124. BOOL HandleMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  125. // IUnknown members
  126. STDMETHODIMP QueryInterface(REFIID riid, void **punk);
  127. STDMETHODIMP_(ULONG) AddRef(void);
  128. STDMETHODIMP_(ULONG) Release(void);
  129. // IDispatch (ambient properties)
  130. STDMETHODIMP GetTypeInfoCount(UINT *pctinfo);
  131. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo);
  132. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR **rgszNames, UINT cNames,
  133. LCID lcid, DISPID *rgdispid);
  134. STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
  135. DISPPARAMS *pdispparams, VARIANT *pvarResult,
  136. EXCEPINFO *pexcepinfo, UINT *puArgErr);
  137. // IOleClientSite
  138. STDMETHODIMP SaveObject(void);
  139. STDMETHODIMP GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk);
  140. STDMETHODIMP GetContainer(IOleContainer **ppContainer);
  141. STDMETHODIMP ShowObject(void);
  142. STDMETHODIMP OnShowWindow(BOOL fShow);
  143. STDMETHODIMP RequestNewObjectLayout(void);
  144. // IPropertyNotifySink
  145. STDMETHODIMP OnChanged(DISPID dispID);
  146. STDMETHODIMP OnRequestEdit(DISPID dispID);
  147. // IOleCommandTarget
  148. STDMETHODIMP QueryStatus(const GUID *pguidCmdGroup,
  149. ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText);
  150. STDMETHODIMP Exec(const GUID *pguidCmdGroup, DWORD nCmdID,
  151. DWORD nCmdexecopt, VARIANTARG *pvaIn,
  152. VARIANTARG *pvaOut);
  153. // IServiceProvider
  154. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppvObject);
  155. // IAuthenticate
  156. STDMETHODIMP Authenticate(HWND *phwnd, LPWSTR *pszUsername, LPWSTR *pszPassword);
  157. // IHlinkFrame
  158. STDMETHODIMP SetBrowseContext(IHlinkBrowseContext *pihlbc);
  159. STDMETHODIMP GetBrowseContext(IHlinkBrowseContext **ppihlbc);
  160. STDMETHODIMP Navigate(DWORD grfHLNF, LPBC pbc, IBindStatusCallback *pibsc, IHlink *pihlNavigate);
  161. STDMETHODIMP OnNavigate(DWORD grfHLNF, IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved);
  162. STDMETHODIMP UpdateHlink(ULONG uHLID, IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName);
  163. // IInternetSecurityManager
  164. STDMETHODIMP SetSecuritySite(IInternetSecurityMgrSite *pSite);
  165. STDMETHODIMP GetSecuritySite(IInternetSecurityMgrSite **ppSite);
  166. STDMETHODIMP MapUrlToZone(LPCWSTR pwszUrl, DWORD *pdwZone, DWORD dwFlags);
  167. STDMETHODIMP GetSecurityId(LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved);
  168. STDMETHODIMP ProcessUrlAction(LPCWSTR pwszUrl, DWORD dwAction, BYTE __RPC_FAR *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved);
  169. STDMETHODIMP QueryCustomPolicy(LPCWSTR pwszUrl, REFGUID guidKey, BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwReserved);
  170. STDMETHODIMP SetZoneMapping(DWORD dwZone, LPCWSTR lpszPattern, DWORD dwFlags);
  171. STDMETHODIMP GetZoneMappings(DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags);
  172. protected:
  173. // main object stuff
  174. ULONG m_cRef;
  175. HWND m_hwndMe;
  176. CThicketProgress* m_ptp;
  177. UINT m_cpDL;
  178. HRESULT *m_phr;
  179. DWORD m_dwProgMax;
  180. // GetBrowser/CleanUpBrowser (browser download data)
  181. IPersistMoniker *m_pPersistMk;
  182. IHTMLDocument2 *m_pDocument;
  183. IOleCommandTarget *m_pOleCmdTarget;
  184. BOOL m_fWaitingForReadyState;
  185. BOOL m_fFormSubmitted;
  186. IConnectionPoint *m_pCP; // connection point for DIID_DWebBrowserEvents
  187. BOOL m_fAdviseOn; // our sink is hooked up? (ConnectionCookie valid)
  188. DWORD m_dwConnectionCookie;
  189. BOOL m_fBrowserValid; // Browser pointing to 'current' URL?
  190. // General download data
  191. BDUMethod m_iMethod;
  192. BDUOptions m_iOptions;
  193. LPWSTR m_pwszURL; // gives us the current url after redirections
  194. BOOL m_fSetResync; // need RESYNCHRONIZE?
  195. DWORD m_dwMaxSize; // in bytes
  196. // IBrowseControl
  197. long m_lBindFlags;
  198. // allow caching GetScript calls
  199. IHTMLWindow2 *m_pScript;
  200. // Client pull
  201. LPWSTR m_pwszClientPullURL;
  202. int m_iNumClientPull;
  203. // other internal stuff
  204. HRESULT CreateMyWindow();
  205. HRESULT GetBrowser(); // Get browser and set us on connection point
  206. void UnAdviseMe(); // Unhook our advise sink
  207. void CleanUpBrowser();
  208. void CleanUp(); // Clean up, including releasing browser
  209. HRESULT BeginDownloadWithBrowser(LPCWSTR);
  210. HRESULT HandleRefresh(LPWSTR pwszEquivString, LPWSTR pwszContent, BOOL fDone);
  211. HRESULT OnDownloadComplete(int iError); // cancel timeout, send OnDownloadComplete
  212. HRESULT ProgressBytes(DWORD dwBytes); // Will abort if too many
  213. };
  214. #endif // _DWNLOAD_HXX_