nsresult nsDownloadScanner::Init() { // This CoInitialize/CoUninitialize pattern seems to be common in the Mozilla // codebase. All other COM calls/objects are made on different threads. nsresult rv = NS_OK; CoInitialize(nullptr); if (!IsAESAvailable()) { CoUninitialize(); return NS_ERROR_NOT_AVAILABLE; } mAESExists = true; // Initialize scanning mWatchdog = new nsDownloadScannerWatchdog(); if (mWatchdog) { rv = mWatchdog->Init(); if (FAILED(rv)) mWatchdog = nullptr; } else { rv = NS_ERROR_OUT_OF_MEMORY; } if (NS_FAILED(rv)) return rv; return rv; }
nsresult nsDownloadScanner::Init() { // This CoInitialize/CoUninitialize pattern seems to be common in the Mozilla // codebase. All other COM calls/objects are made on different threads. nsresult rv = NS_OK; CoInitialize(NULL); // Check for the existence of IAE mAESExists = IsAESAvailable(); // Init OAV scanner list mOAVExists = EnumerateOAVProviders(); CoUninitialize(); if (!mAESExists && !mOAVExists) return NS_ERROR_NOT_AVAILABLE; if (mAESExists) mUseAttachmentExecute = PR_TRUE; // Initialize scanning mWatchdog = new nsDownloadScannerWatchdog(); if (mWatchdog) { rv = mWatchdog->Init(); if (FAILED(rv)) mWatchdog = nsnull; } else { rv = NS_ERROR_OUT_OF_MEMORY; } if (NS_FAILED(rv)) return rv; // If skipWinSecurityPolicyChecks is set, do not use attachement execute, // fall back on the older interface. AE does virus scanning, applies // security policy checks, and also adds security meta data to downloaded // content. PRBool skipPolicy = PR_FALSE; nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (prefs) (void)prefs->GetBoolPref(PREF_BDM_SKIPWINPOLICYCHECKS, &skipPolicy); if (skipPolicy) mUseAttachmentExecute = PR_FALSE; // Setup a pref change even for the policy check pref. nsCOMPtr<nsIPrefBranch2> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); if (prefBranch) (void)prefBranch->AddObserver(PREF_BDM_SKIPWINPOLICYCHECKS, this, PR_FALSE); nsCOMPtr<nsIObserverService> observerService = do_GetService(NS_OBSERVERSERVICE_CONTRACTID); if (observerService) (void)observerService->AddObserver(this, "quit-application", PR_FALSE); return rv; }