This source file includes following definitions.
- SetInternetZoneIdentifierDirectly
- AVScanFile
#include <shlobj.h>
#include <shobjidl.h>
#include "content/browser/safe_util_win.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/scoped_comptr.h"
#include "ui/base/win/shell.h"
#include "url/gurl.h"
namespace content {
namespace {
bool SetInternetZoneIdentifierDirectly(const base::FilePath& full_path) {
const DWORD kShare = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
std::wstring path = full_path.value() + L":Zone.Identifier";
HANDLE file = CreateFile(path.c_str(), GENERIC_WRITE, kShare, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == file)
return false;
static const char kIdentifier[] = "[ZoneTransfer]\r\nZoneId=3\r\n";
static const DWORD kIdentifierSize = arraysize(kIdentifier) - 1;
DWORD written = 0;
BOOL result = WriteFile(file, kIdentifier, kIdentifierSize, &written, NULL);
BOOL flush_result = FlushFileBuffers(file);
CloseHandle(file);
if (!result || !flush_result || written != kIdentifierSize) {
NOTREACHED();
return false;
}
return true;
}
}
HRESULT AVScanFile(const base::FilePath& full_path,
const std::string& source_url,
const GUID& client_guid) {
base::win::ScopedComPtr<IAttachmentExecute> attachment_services;
HRESULT hr = attachment_services.CreateInstance(CLSID_AttachmentServices);
if (FAILED(hr)) {
DCHECK_NE(CO_E_NOTINITIALIZED, hr);
SetInternetZoneIdentifierDirectly(full_path);
return hr;
}
if (!IsEqualGUID(client_guid, GUID_NULL)) {
hr = attachment_services->SetClientGuid(client_guid);
if (FAILED(hr))
return hr;
}
hr = attachment_services->SetLocalPath(full_path.value().c_str());
if (FAILED(hr))
return hr;
hr = attachment_services->SetSource(base::UTF8ToWide(source_url).c_str());
if (FAILED(hr))
return hr;
return attachment_services->Save();
}
}