1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/downloads/nsDownloadScanner.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* vim: se cin sw=2 ts=2 et : */ 1.10 + 1.11 +#ifndef nsDownloadScanner_h_ 1.12 +#define nsDownloadScanner_h_ 1.13 + 1.14 +#ifdef WIN32_LEAN_AND_MEAN 1.15 +#undef WIN32_LEAN_AND_MEAN 1.16 +#endif 1.17 +#include <windows.h> 1.18 +#define AVVENDOR 1.19 +#include <objidl.h> 1.20 +#include <msoav.h> 1.21 +#include <shlobj.h> 1.22 + 1.23 +#include "nsAutoPtr.h" 1.24 +#include "nsThreadUtils.h" 1.25 +#include "nsTArray.h" 1.26 +#include "nsIObserver.h" 1.27 +#include "nsIURI.h" 1.28 + 1.29 +enum AVScanState 1.30 +{ 1.31 + AVSCAN_NOTSTARTED = 0, 1.32 + AVSCAN_SCANNING, 1.33 + AVSCAN_GOOD, 1.34 + AVSCAN_BAD, 1.35 + AVSCAN_UGLY, 1.36 + AVSCAN_FAILED, 1.37 + AVSCAN_TIMEDOUT 1.38 +}; 1.39 + 1.40 +enum AVCheckPolicyState 1.41 +{ 1.42 + AVPOLICY_DOWNLOAD, 1.43 + AVPOLICY_PROMPT, 1.44 + AVPOLICY_BLOCKED 1.45 +}; 1.46 + 1.47 +// See nsDownloadScanner.cpp for declaration and definition 1.48 +class nsDownloadScannerWatchdog; 1.49 +class nsDownload; 1.50 + 1.51 +class nsDownloadScanner 1.52 +{ 1.53 +public: 1.54 + nsDownloadScanner(); 1.55 + ~nsDownloadScanner(); 1.56 + nsresult Init(); 1.57 + nsresult ScanDownload(nsDownload *download); 1.58 + AVCheckPolicyState CheckPolicy(nsIURI *aSource, nsIURI *aTarget); 1.59 + 1.60 +private: 1.61 + bool mAESExists; 1.62 + nsTArray<CLSID> mScanCLSID; 1.63 + bool IsAESAvailable(); 1.64 + bool EnumerateOAVProviders(); 1.65 + 1.66 + nsAutoPtr<nsDownloadScannerWatchdog> mWatchdog; 1.67 + 1.68 + static unsigned int __stdcall ScannerThreadFunction(void *p); 1.69 + class Scan : public nsRunnable 1.70 + { 1.71 + public: 1.72 + Scan(nsDownloadScanner *scanner, nsDownload *download); 1.73 + ~Scan(); 1.74 + nsresult Start(); 1.75 + 1.76 + // Returns the time that Start was called 1.77 + PRTime GetStartTime() const { return mStartTime; } 1.78 + // Returns a copy of the thread handle that can be waited on, but not 1.79 + // terminated 1.80 + // The caller is responsible for closing the handle 1.81 + // If the thread has terminated, then this will return the pseudo-handle 1.82 + // INVALID_HANDLE_VALUE 1.83 + HANDLE GetWaitableThreadHandle() const; 1.84 + 1.85 + // Called on a secondary thread to notify the scan that it has timed out 1.86 + // this is used only by the watchdog thread 1.87 + bool NotifyTimeout(); 1.88 + 1.89 + private: 1.90 + nsDownloadScanner *mDLScanner; 1.91 + PRTime mStartTime; 1.92 + HANDLE mThread; 1.93 + nsRefPtr<nsDownload> mDownload; 1.94 + // Guards mStatus 1.95 + CRITICAL_SECTION mStateSync; 1.96 + AVScanState mStatus; 1.97 + nsString mPath; 1.98 + nsString mName; 1.99 + nsString mOrigin; 1.100 + // Also true if it is an ftp download 1.101 + bool mIsHttpDownload; 1.102 + bool mSkipSource; 1.103 + 1.104 + /* @summary Sets the Scan's state to newState if the current state is 1.105 + expectedState 1.106 + * @param newState The new state of the scan 1.107 + * @param expectedState The state that the caller expects the scan to be in 1.108 + * @return If the old state matched expectedState 1.109 + */ 1.110 + bool CheckAndSetState(AVScanState newState, AVScanState expectedState); 1.111 + 1.112 + NS_IMETHOD Run(); 1.113 + 1.114 + void DoScan(); 1.115 + bool DoScanAES(); 1.116 + bool DoScanOAV(); 1.117 + 1.118 + friend unsigned int __stdcall nsDownloadScanner::ScannerThreadFunction(void *); 1.119 + }; 1.120 + // Used to give access to Scan 1.121 + friend class nsDownloadScannerWatchdog; 1.122 +}; 1.123 +#endif 1.124 +