/toolkit/components/downloads/nsDownloadScanner.h

http://github.com/zpao/v8monkey · C Header · 124 lines · 85 code · 18 blank · 21 comment · 0 complexity · d187c42fddcc77f9f5b6e976ad0acc22 MD5 · raw file

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: se cin sw=2 ts=2 et : */
  3. #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN
  4. #ifndef nsDownloadScanner_h_
  5. #define nsDownloadScanner_h_
  6. #ifdef WIN32_LEAN_AND_MEAN
  7. #undef WIN32_LEAN_AND_MEAN
  8. #endif
  9. #define INITGUID
  10. #include <windows.h>
  11. #define AVVENDOR
  12. #include <msoav.h>
  13. // To cope with both msvs8 header and sdk6 header
  14. #ifdef _WIN32_IE_IE60SP2
  15. #undef _WIN32_IE
  16. #define _WIN32_IE _WIN32_IE_IE60SP2
  17. #endif
  18. #include <shlobj.h>
  19. #include "nsAutoPtr.h"
  20. #include "nsThreadUtils.h"
  21. #include "nsTArray.h"
  22. #include "nsIObserver.h"
  23. #include "nsIURI.h"
  24. enum AVScanState
  25. {
  26. AVSCAN_NOTSTARTED = 0,
  27. AVSCAN_SCANNING,
  28. AVSCAN_GOOD,
  29. AVSCAN_BAD,
  30. AVSCAN_UGLY,
  31. AVSCAN_FAILED,
  32. AVSCAN_TIMEDOUT
  33. };
  34. enum AVCheckPolicyState
  35. {
  36. AVPOLICY_DOWNLOAD,
  37. AVPOLICY_PROMPT,
  38. AVPOLICY_BLOCKED
  39. };
  40. // See nsDownloadScanner.cpp for declaration and definition
  41. class nsDownloadScannerWatchdog;
  42. class nsDownload;
  43. class nsDownloadScanner
  44. {
  45. public:
  46. nsDownloadScanner();
  47. ~nsDownloadScanner();
  48. nsresult Init();
  49. nsresult ScanDownload(nsDownload *download);
  50. AVCheckPolicyState CheckPolicy(nsIURI *aSource, nsIURI *aTarget);
  51. private:
  52. bool mAESExists;
  53. nsTArray<CLSID> mScanCLSID;
  54. bool IsAESAvailable();
  55. bool EnumerateOAVProviders();
  56. nsAutoPtr<nsDownloadScannerWatchdog> mWatchdog;
  57. static unsigned int __stdcall ScannerThreadFunction(void *p);
  58. class Scan : public nsRunnable
  59. {
  60. public:
  61. Scan(nsDownloadScanner *scanner, nsDownload *download);
  62. ~Scan();
  63. nsresult Start();
  64. // Returns the time that Start was called
  65. PRTime GetStartTime() const { return mStartTime; }
  66. // Returns a copy of the thread handle that can be waited on, but not
  67. // terminated
  68. // The caller is responsible for closing the handle
  69. // If the thread has terminated, then this will return the pseudo-handle
  70. // INVALID_HANDLE_VALUE
  71. HANDLE GetWaitableThreadHandle() const;
  72. // Called on a secondary thread to notify the scan that it has timed out
  73. // this is used only by the watchdog thread
  74. bool NotifyTimeout();
  75. private:
  76. nsDownloadScanner *mDLScanner;
  77. PRTime mStartTime;
  78. HANDLE mThread;
  79. nsRefPtr<nsDownload> mDownload;
  80. // Guards mStatus
  81. CRITICAL_SECTION mStateSync;
  82. AVScanState mStatus;
  83. nsString mPath;
  84. nsString mName;
  85. nsString mOrigin;
  86. // Also true if it is an ftp download
  87. bool mIsHttpDownload;
  88. bool mSkipSource;
  89. /* @summary Sets the Scan's state to newState if the current state is
  90. expectedState
  91. * @param newState The new state of the scan
  92. * @param expectedState The state that the caller expects the scan to be in
  93. * @return If the old state matched expectedState
  94. */
  95. bool CheckAndSetState(AVScanState newState, AVScanState expectedState);
  96. NS_IMETHOD Run();
  97. void DoScan();
  98. bool DoScanAES();
  99. bool DoScanOAV();
  100. friend unsigned int __stdcall nsDownloadScanner::ScannerThreadFunction(void *);
  101. };
  102. // Used to give access to Scan
  103. friend class nsDownloadScannerWatchdog;
  104. };
  105. #endif
  106. #endif // MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN