nsDownloadScanner.h 3.1 KB

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