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