michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* vim: se cin sw=2 ts=2 et : */ michael@0: michael@0: #ifndef nsDownloadScanner_h_ michael@0: #define nsDownloadScanner_h_ michael@0: michael@0: #ifdef WIN32_LEAN_AND_MEAN michael@0: #undef WIN32_LEAN_AND_MEAN michael@0: #endif michael@0: #include michael@0: #define AVVENDOR michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "nsAutoPtr.h" michael@0: #include "nsThreadUtils.h" michael@0: #include "nsTArray.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsIURI.h" michael@0: michael@0: enum AVScanState michael@0: { michael@0: AVSCAN_NOTSTARTED = 0, michael@0: AVSCAN_SCANNING, michael@0: AVSCAN_GOOD, michael@0: AVSCAN_BAD, michael@0: AVSCAN_UGLY, michael@0: AVSCAN_FAILED, michael@0: AVSCAN_TIMEDOUT michael@0: }; michael@0: michael@0: enum AVCheckPolicyState michael@0: { michael@0: AVPOLICY_DOWNLOAD, michael@0: AVPOLICY_PROMPT, michael@0: AVPOLICY_BLOCKED michael@0: }; michael@0: michael@0: // See nsDownloadScanner.cpp for declaration and definition michael@0: class nsDownloadScannerWatchdog; michael@0: class nsDownload; michael@0: michael@0: class nsDownloadScanner michael@0: { michael@0: public: michael@0: nsDownloadScanner(); michael@0: ~nsDownloadScanner(); michael@0: nsresult Init(); michael@0: nsresult ScanDownload(nsDownload *download); michael@0: AVCheckPolicyState CheckPolicy(nsIURI *aSource, nsIURI *aTarget); michael@0: michael@0: private: michael@0: bool mAESExists; michael@0: nsTArray mScanCLSID; michael@0: bool IsAESAvailable(); michael@0: bool EnumerateOAVProviders(); michael@0: michael@0: nsAutoPtr mWatchdog; michael@0: michael@0: static unsigned int __stdcall ScannerThreadFunction(void *p); michael@0: class Scan : public nsRunnable michael@0: { michael@0: public: michael@0: Scan(nsDownloadScanner *scanner, nsDownload *download); michael@0: ~Scan(); michael@0: nsresult Start(); michael@0: michael@0: // Returns the time that Start was called michael@0: PRTime GetStartTime() const { return mStartTime; } michael@0: // Returns a copy of the thread handle that can be waited on, but not michael@0: // terminated michael@0: // The caller is responsible for closing the handle michael@0: // If the thread has terminated, then this will return the pseudo-handle michael@0: // INVALID_HANDLE_VALUE michael@0: HANDLE GetWaitableThreadHandle() const; michael@0: michael@0: // Called on a secondary thread to notify the scan that it has timed out michael@0: // this is used only by the watchdog thread michael@0: bool NotifyTimeout(); michael@0: michael@0: private: michael@0: nsDownloadScanner *mDLScanner; michael@0: PRTime mStartTime; michael@0: HANDLE mThread; michael@0: nsRefPtr mDownload; michael@0: // Guards mStatus michael@0: CRITICAL_SECTION mStateSync; michael@0: AVScanState mStatus; michael@0: nsString mPath; michael@0: nsString mName; michael@0: nsString mOrigin; michael@0: // Also true if it is an ftp download michael@0: bool mIsHttpDownload; michael@0: bool mSkipSource; michael@0: michael@0: /* @summary Sets the Scan's state to newState if the current state is michael@0: expectedState michael@0: * @param newState The new state of the scan michael@0: * @param expectedState The state that the caller expects the scan to be in michael@0: * @return If the old state matched expectedState michael@0: */ michael@0: bool CheckAndSetState(AVScanState newState, AVScanState expectedState); michael@0: michael@0: NS_IMETHOD Run(); michael@0: michael@0: void DoScan(); michael@0: bool DoScanAES(); michael@0: bool DoScanOAV(); michael@0: michael@0: friend unsigned int __stdcall nsDownloadScanner::ScannerThreadFunction(void *); michael@0: }; michael@0: // Used to give access to Scan michael@0: friend class nsDownloadScannerWatchdog; michael@0: }; michael@0: #endif michael@0: