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.

276 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. HRESULT GetRealURL(LPWSTR *ppwszURL); // Gets URL accounting for any and all redirections (MemFree)
  119. HRESULT GetScript(IHTMLWindow2 **pWin); // Will cache an *additional* reference internally
  120. void ReleaseScript() { SAFERELEASE(m_pScript); } // Releases internal reference
  121. HRESULT GetDocument(IHTMLDocument2 **ppDoc);
  122. void DoneDownloading(); // Call before releasing. Will destroy browser and windows.
  123. void DestroyBrowser(); // Destroy hosted browser, leave all else alone
  124. // URL manipulation functions
  125. static HRESULT StripAnchor(LPWSTR lpURL);
  126. static BOOL IsHTMLURL(LPCWSTR lpURL); // TRUE (yes) or FALSE (maybe)
  127. static BOOL IsValidURL(LPCWSTR lpURL); // TRUE (get it) or FALSE (skip it)
  128. // Should only be called from CUrlDownloadMsgProc
  129. BOOL HandleMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  130. // IUnknown members
  131. STDMETHODIMP QueryInterface(REFIID riid, void **punk);
  132. STDMETHODIMP_(ULONG) AddRef(void);
  133. STDMETHODIMP_(ULONG) Release(void);
  134. // IDispatch (ambient properties)
  135. STDMETHODIMP GetTypeInfoCount(UINT *pctinfo);
  136. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo);
  137. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR **rgszNames, UINT cNames,
  138. LCID lcid, DISPID *rgdispid);
  139. STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
  140. DISPPARAMS *pdispparams, VARIANT *pvarResult,
  141. EXCEPINFO *pexcepinfo, UINT *puArgErr);
  142. // IOleClientSite
  143. STDMETHODIMP SaveObject(void);
  144. STDMETHODIMP GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk);
  145. STDMETHODIMP GetContainer(IOleContainer **ppContainer);
  146. STDMETHODIMP ShowObject(void);
  147. STDMETHODIMP OnShowWindow(BOOL fShow);
  148. STDMETHODIMP RequestNewObjectLayout(void);
  149. // IPropertyNotifySink
  150. STDMETHODIMP OnChanged(DISPID dispID);
  151. STDMETHODIMP OnRequestEdit(DISPID dispID);
  152. // IOleCommandTarget
  153. STDMETHODIMP QueryStatus(const GUID *pguidCmdGroup,
  154. ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText);
  155. STDMETHODIMP Exec(const GUID *pguidCmdGroup, DWORD nCmdID,
  156. DWORD nCmdexecopt, VARIANTARG *pvaIn,
  157. VARIANTARG *pvaOut);
  158. // IServiceProvider
  159. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppvObject);
  160. // IAuthenticate
  161. STDMETHODIMP Authenticate(HWND *phwnd, LPWSTR *pszUsername, LPWSTR *pszPassword);
  162. // IHlinkFrame
  163. STDMETHODIMP SetBrowseContext(IHlinkBrowseContext *pihlbc);
  164. STDMETHODIMP GetBrowseContext(IHlinkBrowseContext **ppihlbc);
  165. STDMETHODIMP Navigate(DWORD grfHLNF, LPBC pbc, IBindStatusCallback *pibsc, IHlink *pihlNavigate);
  166. STDMETHODIMP OnNavigate(DWORD grfHLNF, IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved);
  167. STDMETHODIMP UpdateHlink(ULONG uHLID, IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName);
  168. // IInternetSecurityManager
  169. STDMETHODIMP SetSecuritySite(IInternetSecurityMgrSite *pSite);
  170. STDMETHODIMP GetSecuritySite(IInternetSecurityMgrSite **ppSite);
  171. STDMETHODIMP MapUrlToZone(LPCWSTR pwszUrl, DWORD *pdwZone, DWORD dwFlags);
  172. STDMETHODIMP GetSecurityId(LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved);
  173. STDMETHODIMP ProcessUrlAction(LPCWSTR pwszUrl, DWORD dwAction, BYTE __RPC_FAR *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved);
  174. STDMETHODIMP QueryCustomPolicy(LPCWSTR pwszUrl, REFGUID guidKey, BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwReserved);
  175. STDMETHODIMP SetZoneMapping(DWORD dwZone, LPCWSTR lpszPattern, DWORD dwFlags);
  176. STDMETHODIMP GetZoneMappings(DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags);
  177. protected:
  178. // main object stuff
  179. ULONG m_cRef;
  180. HWND m_hwndMe;
  181. CThicketProgress* m_ptp;
  182. UINT m_cpDL;
  183. HRESULT *m_phr;
  184. DWORD m_dwProgMax;
  185. // GetBrowser/CleanUpBrowser (browser download data)
  186. IPersistMoniker *m_pPersistMk;
  187. IHTMLDocument2 *m_pDocument;
  188. IOleCommandTarget *m_pOleCmdTarget;
  189. BOOL m_fWaitingForReadyState;
  190. BOOL m_fFormSubmitted;
  191. IConnectionPoint *m_pCP; // connection point for DIID_DWebBrowserEvents
  192. BOOL m_fAdviseOn; // our sink is hooked up? (ConnectionCookie valid)
  193. DWORD m_dwConnectionCookie;
  194. BOOL m_fBrowserValid; // Browser pointing to 'current' URL?
  195. // General download data
  196. BDUMethod m_iMethod;
  197. BDUOptions m_iOptions;
  198. LPWSTR m_pwszURL; // gives us the current url after redirections
  199. BOOL m_fSetResync; // need RESYNCHRONIZE?
  200. DWORD m_dwMaxSize; // in bytes
  201. // IBrowseControl
  202. long m_lBindFlags;
  203. // allow caching GetScript calls
  204. IHTMLWindow2 *m_pScript;
  205. // Client pull
  206. LPWSTR m_pwszClientPullURL;
  207. int m_iNumClientPull;
  208. // other internal stuff
  209. HRESULT CreateMyWindow();
  210. HRESULT GetBrowser(); // Get browser and set us on connection point
  211. void UnAdviseMe(); // Unhook our advise sink
  212. void CleanUpBrowser();
  213. void CleanUp(); // Clean up, including releasing browser
  214. HRESULT BeginDownloadWithBrowser(LPCWSTR);
  215. HRESULT HandleRefresh(LPWSTR pwszEquivString, LPWSTR pwszContent, BOOL fDone);
  216. HRESULT OnDownloadComplete(int iError); // cancel timeout, send OnDownloadComplete
  217. HRESULT ProgressBytes(DWORD dwBytes); // Will abort if too many
  218. };
  219. #endif // _DWNLOAD_HXX_