Add .website to dangerous download extensions. Add .website and .url to safebrowsing...
[chromium-blink-merge.git] / chrome / common / safe_browsing / download_protection_util.cc
blob3358b893b1c90445d1e1468339a25e73348677ca
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/common/safe_browsing/download_protection_util.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
10 namespace safe_browsing {
11 namespace download_protection_util {
13 bool IsArchiveFile(const base::FilePath& file) {
14 // TODO(mattm): should .dmg be checked here instead of IsBinaryFile?
15 return file.MatchesExtension(FILE_PATH_LITERAL(".zip"));
18 bool IsBinaryFile(const base::FilePath& file) {
19 return (
20 // Executable extensions for MS Windows.
21 file.MatchesExtension(FILE_PATH_LITERAL(".bas")) ||
22 file.MatchesExtension(FILE_PATH_LITERAL(".bat")) ||
23 file.MatchesExtension(FILE_PATH_LITERAL(".cab")) ||
24 file.MatchesExtension(FILE_PATH_LITERAL(".cmd")) ||
25 file.MatchesExtension(FILE_PATH_LITERAL(".com")) ||
26 file.MatchesExtension(FILE_PATH_LITERAL(".exe")) ||
27 file.MatchesExtension(FILE_PATH_LITERAL(".hta")) ||
28 file.MatchesExtension(FILE_PATH_LITERAL(".msi")) ||
29 file.MatchesExtension(FILE_PATH_LITERAL(".pif")) ||
30 file.MatchesExtension(FILE_PATH_LITERAL(".reg")) ||
31 file.MatchesExtension(FILE_PATH_LITERAL(".scr")) ||
32 file.MatchesExtension(FILE_PATH_LITERAL(".url")) ||
33 file.MatchesExtension(FILE_PATH_LITERAL(".vb")) ||
34 file.MatchesExtension(FILE_PATH_LITERAL(".vbs")) ||
35 file.MatchesExtension(FILE_PATH_LITERAL(".website")) ||
36 // Chrome extensions and android APKs are also reported.
37 file.MatchesExtension(FILE_PATH_LITERAL(".crx")) ||
38 file.MatchesExtension(FILE_PATH_LITERAL(".apk")) ||
39 // Mac extensions.
40 file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) ||
41 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) ||
42 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) ||
43 file.MatchesExtension(FILE_PATH_LITERAL(".app")) ||
44 // Archives _may_ contain binaries, we'll check in ExtractFileFeatures.
45 IsArchiveFile(file));
48 ClientDownloadRequest::DownloadType GetDownloadType(
49 const base::FilePath& file) {
50 DCHECK(IsBinaryFile(file));
51 if (file.MatchesExtension(FILE_PATH_LITERAL(".apk")))
52 return ClientDownloadRequest::ANDROID_APK;
53 else if (file.MatchesExtension(FILE_PATH_LITERAL(".crx")))
54 return ClientDownloadRequest::CHROME_EXTENSION;
55 // For zip files, we use the ZIPPED_EXECUTABLE type since we will only send
56 // the pingback if we find an executable inside the zip archive.
57 else if (file.MatchesExtension(FILE_PATH_LITERAL(".zip")))
58 return ClientDownloadRequest::ZIPPED_EXECUTABLE;
59 else if (file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) ||
60 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) ||
61 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) ||
62 file.MatchesExtension(FILE_PATH_LITERAL(".app")))
63 return ClientDownloadRequest::MAC_EXECUTABLE;
64 return ClientDownloadRequest::WIN_EXECUTABLE;
67 } // namespace download_protection_util
68 } // namespace safe_browsing