reload.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 11k
Category:

Windows Kernel

Development Platform:

Visual C++

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