Fix crash after Launcher drag/drop (take 3 - no unit test)
[chromium-blink-merge.git] / chrome / common / safe_browsing / download_protection_util.cc
bloba5a4befa3696ddcb9c723f5d9d97621a6a6cf14f
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(".vb")) ||
33 file.MatchesExtension(FILE_PATH_LITERAL(".vbs")) ||
34 // Chrome extensions and android APKs are also reported.
35 file.MatchesExtension(FILE_PATH_LITERAL(".crx")) ||
36 file.MatchesExtension(FILE_PATH_LITERAL(".apk")) ||
37 // Mac extensions.
38 file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) ||
39 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) ||
40 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) ||
41 file.MatchesExtension(FILE_PATH_LITERAL(".app")) ||
42 // Archives _may_ contain binaries, we'll check in ExtractFileFeatures.
43 IsArchiveFile(file));
46 ClientDownloadRequest::DownloadType GetDownloadType(
47 const base::FilePath& file) {
48 DCHECK(IsBinaryFile(file));
49 if (file.MatchesExtension(FILE_PATH_LITERAL(".apk")))
50 return ClientDownloadRequest::ANDROID_APK;
51 else if (file.MatchesExtension(FILE_PATH_LITERAL(".crx")))
52 return ClientDownloadRequest::CHROME_EXTENSION;
53 // For zip files, we use the ZIPPED_EXECUTABLE type since we will only send
54 // the pingback if we find an executable inside the zip archive.
55 else if (file.MatchesExtension(FILE_PATH_LITERAL(".zip")))
56 return ClientDownloadRequest::ZIPPED_EXECUTABLE;
57 else if (file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) ||
58 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) ||
59 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) ||
60 file.MatchesExtension(FILE_PATH_LITERAL(".app")))
61 return ClientDownloadRequest::MAC_EXECUTABLE;
62 return ClientDownloadRequest::WIN_EXECUTABLE;
65 } // namespace download_protection_util
66 } // namespace safe_browsing