Skip to content

Commit

Permalink
Update DownloadDangerLevel to use style compliant enums.
Browse files Browse the repository at this point in the history
BUG=none

Review URL: https://chromiumcodereview.appspot.com/16359015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204334 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
asanka@chromium.org committed Jun 5, 2013
1 parent 28a4536 commit b42beb7
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 160 deletions.
282 changes: 141 additions & 141 deletions chrome/browser/download/download_extensions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,169 +63,169 @@ static const struct Executables {
// Chrome OS does not suffer from some of the problems of older OS'es.
#if !defined(OS_CHROMEOS)
// Relating to Java.
{ "class", Dangerous },
{ "jar", Dangerous },
{ "jnlp", Dangerous },
{ "class", DANGEROUS },
{ "jar", DANGEROUS },
{ "jnlp", DANGEROUS },
// Relating to PDF.
{ "pdf", AllowOnUserGesture },
{ "pdfxml", AllowOnUserGesture },
{ "mars", AllowOnUserGesture },
{ "fdf", AllowOnUserGesture },
{ "xfdf", AllowOnUserGesture },
{ "xdp", AllowOnUserGesture },
{ "xfd", AllowOnUserGesture },
{ "pdf", ALLOW_ON_USER_GESTURE },
{ "pdfxml", ALLOW_ON_USER_GESTURE },
{ "mars", ALLOW_ON_USER_GESTURE },
{ "fdf", ALLOW_ON_USER_GESTURE },
{ "xfdf", ALLOW_ON_USER_GESTURE },
{ "xdp", ALLOW_ON_USER_GESTURE },
{ "xfd", ALLOW_ON_USER_GESTURE },
// Relating to scripting languages.
{ "pl", AllowOnUserGesture },
{ "py", AllowOnUserGesture },
{ "pyw", AllowOnUserGesture },
{ "rb", AllowOnUserGesture },
{ "pl", ALLOW_ON_USER_GESTURE },
{ "py", ALLOW_ON_USER_GESTURE },
{ "pyw", ALLOW_ON_USER_GESTURE },
{ "rb", ALLOW_ON_USER_GESTURE },
#endif
// Some files are dangerous on all platforms.
// Flash files downloaded locally can sometimes access the local filesystem.
{ "swf", AllowOnUserGesture },
{ "swf", ALLOW_ON_USER_GESTURE },
// Chrome extensions should be obtained through the web store.
{ "crx", AllowOnUserGesture },
{ "crx", ALLOW_ON_USER_GESTURE },
// These types can run JavaScript (e.g. HTML and HTML-like).
// TODO(cevans): work out whether our restrictions on file:/// are strong
// enough to mark these types as no longer dangerous.
{ "htm", AllowOnUserGesture },
{ "html", AllowOnUserGesture },
{ "shtm", AllowOnUserGesture },
{ "shtml", AllowOnUserGesture },
{ "svg", AllowOnUserGesture },
{ "xht", AllowOnUserGesture },
{ "xhtm", AllowOnUserGesture },
{ "xhtml", AllowOnUserGesture },
{ "xml", AllowOnUserGesture },
{ "xsl", AllowOnUserGesture },
{ "xslt", AllowOnUserGesture },
{ "htm", ALLOW_ON_USER_GESTURE },
{ "html", ALLOW_ON_USER_GESTURE },
{ "shtm", ALLOW_ON_USER_GESTURE },
{ "shtml", ALLOW_ON_USER_GESTURE },
{ "svg", ALLOW_ON_USER_GESTURE },
{ "xht", ALLOW_ON_USER_GESTURE },
{ "xhtm", ALLOW_ON_USER_GESTURE },
{ "xhtml", ALLOW_ON_USER_GESTURE },
{ "xml", ALLOW_ON_USER_GESTURE },
{ "xsl", ALLOW_ON_USER_GESTURE },
{ "xslt", ALLOW_ON_USER_GESTURE },
#if defined(OS_WIN)
{ "ad", AllowOnUserGesture },
{ "ade", AllowOnUserGesture },
{ "adp", AllowOnUserGesture },
{ "app", AllowOnUserGesture },
{ "application", AllowOnUserGesture },
{ "asp", AllowOnUserGesture },
{ "asx", AllowOnUserGesture },
{ "bas", AllowOnUserGesture },
{ "bat", AllowOnUserGesture },
{ "cfg", Dangerous },
{ "chi", AllowOnUserGesture },
{ "chm", AllowOnUserGesture },
{ "cmd", AllowOnUserGesture },
{ "com", AllowOnUserGesture },
{ "cpl", AllowOnUserGesture },
{ "crt", AllowOnUserGesture },
{ "dll", Dangerous },
{ "drv", Dangerous },
{ "exe", AllowOnUserGesture },
{ "fxp", AllowOnUserGesture },
{ "grp", Dangerous },
{ "hlp", AllowOnUserGesture },
{ "hta", AllowOnUserGesture },
{ "htt", AllowOnUserGesture },
{ "inf", AllowOnUserGesture },
{ "ini", Dangerous },
{ "ins", AllowOnUserGesture },
{ "isp", AllowOnUserGesture },
{ "js", AllowOnUserGesture },
{ "jse", AllowOnUserGesture },
{ "lnk", AllowOnUserGesture },
{ "local", Dangerous },
{ "mad", AllowOnUserGesture },
{ "maf", AllowOnUserGesture },
{ "mag", AllowOnUserGesture },
{ "mam", AllowOnUserGesture },
{ "manifest", Dangerous },
{ "maq", AllowOnUserGesture },
{ "mar", AllowOnUserGesture },
{ "mas", AllowOnUserGesture },
{ "mat", AllowOnUserGesture },
{ "mau", AllowOnUserGesture },
{ "mav", AllowOnUserGesture },
{ "maw", AllowOnUserGesture },
{ "mda", AllowOnUserGesture },
{ "mdb", AllowOnUserGesture },
{ "mde", AllowOnUserGesture },
{ "mdt", AllowOnUserGesture },
{ "mdw", AllowOnUserGesture },
{ "mdz", AllowOnUserGesture },
{ "mht", AllowOnUserGesture },
{ "mhtml", AllowOnUserGesture },
{ "mmc", AllowOnUserGesture },
{ "mof", Dangerous },
{ "msc", AllowOnUserGesture },
{ "msh", AllowOnUserGesture },
{ "mshxml", AllowOnUserGesture },
{ "msi", AllowOnUserGesture },
{ "msp", AllowOnUserGesture },
{ "mst", AllowOnUserGesture },
{ "ocx", Dangerous },
{ "ops", AllowOnUserGesture },
{ "pcd", AllowOnUserGesture },
{ "pif", AllowOnUserGesture },
{ "plg", AllowOnUserGesture },
{ "prf", AllowOnUserGesture },
{ "prg", AllowOnUserGesture },
{ "pst", AllowOnUserGesture },
{ "reg", AllowOnUserGesture },
{ "scf", AllowOnUserGesture },
{ "scr", AllowOnUserGesture },
{ "sct", AllowOnUserGesture },
{ "shb", AllowOnUserGesture },
{ "shs", AllowOnUserGesture },
{ "sys", Dangerous },
{ "url", AllowOnUserGesture },
{ "ad", ALLOW_ON_USER_GESTURE },
{ "ade", ALLOW_ON_USER_GESTURE },
{ "adp", ALLOW_ON_USER_GESTURE },
{ "app", ALLOW_ON_USER_GESTURE },
{ "application", ALLOW_ON_USER_GESTURE },
{ "asp", ALLOW_ON_USER_GESTURE },
{ "asx", ALLOW_ON_USER_GESTURE },
{ "bas", ALLOW_ON_USER_GESTURE },
{ "bat", ALLOW_ON_USER_GESTURE },
{ "cfg", DANGEROUS },
{ "chi", ALLOW_ON_USER_GESTURE },
{ "chm", ALLOW_ON_USER_GESTURE },
{ "cmd", ALLOW_ON_USER_GESTURE },
{ "com", ALLOW_ON_USER_GESTURE },
{ "cpl", ALLOW_ON_USER_GESTURE },
{ "crt", ALLOW_ON_USER_GESTURE },
{ "dll", DANGEROUS },
{ "drv", DANGEROUS },
{ "exe", ALLOW_ON_USER_GESTURE },
{ "fxp", ALLOW_ON_USER_GESTURE },
{ "grp", DANGEROUS },
{ "hlp", ALLOW_ON_USER_GESTURE },
{ "hta", ALLOW_ON_USER_GESTURE },
{ "htt", ALLOW_ON_USER_GESTURE },
{ "inf", ALLOW_ON_USER_GESTURE },
{ "ini", DANGEROUS },
{ "ins", ALLOW_ON_USER_GESTURE },
{ "isp", ALLOW_ON_USER_GESTURE },
{ "js", ALLOW_ON_USER_GESTURE },
{ "jse", ALLOW_ON_USER_GESTURE },
{ "lnk", ALLOW_ON_USER_GESTURE },
{ "local", DANGEROUS },
{ "mad", ALLOW_ON_USER_GESTURE },
{ "maf", ALLOW_ON_USER_GESTURE },
{ "mag", ALLOW_ON_USER_GESTURE },
{ "mam", ALLOW_ON_USER_GESTURE },
{ "manifest", DANGEROUS },
{ "maq", ALLOW_ON_USER_GESTURE },
{ "mar", ALLOW_ON_USER_GESTURE },
{ "mas", ALLOW_ON_USER_GESTURE },
{ "mat", ALLOW_ON_USER_GESTURE },
{ "mau", ALLOW_ON_USER_GESTURE },
{ "mav", ALLOW_ON_USER_GESTURE },
{ "maw", ALLOW_ON_USER_GESTURE },
{ "mda", ALLOW_ON_USER_GESTURE },
{ "mdb", ALLOW_ON_USER_GESTURE },
{ "mde", ALLOW_ON_USER_GESTURE },
{ "mdt", ALLOW_ON_USER_GESTURE },
{ "mdw", ALLOW_ON_USER_GESTURE },
{ "mdz", ALLOW_ON_USER_GESTURE },
{ "mht", ALLOW_ON_USER_GESTURE },
{ "mhtml", ALLOW_ON_USER_GESTURE },
{ "mmc", ALLOW_ON_USER_GESTURE },
{ "mof", DANGEROUS },
{ "msc", ALLOW_ON_USER_GESTURE },
{ "msh", ALLOW_ON_USER_GESTURE },
{ "mshxml", ALLOW_ON_USER_GESTURE },
{ "msi", ALLOW_ON_USER_GESTURE },
{ "msp", ALLOW_ON_USER_GESTURE },
{ "mst", ALLOW_ON_USER_GESTURE },
{ "ocx", DANGEROUS },
{ "ops", ALLOW_ON_USER_GESTURE },
{ "pcd", ALLOW_ON_USER_GESTURE },
{ "pif", ALLOW_ON_USER_GESTURE },
{ "plg", ALLOW_ON_USER_GESTURE },
{ "prf", ALLOW_ON_USER_GESTURE },
{ "prg", ALLOW_ON_USER_GESTURE },
{ "pst", ALLOW_ON_USER_GESTURE },
{ "reg", ALLOW_ON_USER_GESTURE },
{ "scf", ALLOW_ON_USER_GESTURE },
{ "scr", ALLOW_ON_USER_GESTURE },
{ "sct", ALLOW_ON_USER_GESTURE },
{ "shb", ALLOW_ON_USER_GESTURE },
{ "shs", ALLOW_ON_USER_GESTURE },
{ "sys", DANGEROUS },
{ "url", ALLOW_ON_USER_GESTURE },
// TODO(davidben): Remove this when double-extensions are no longer
// a nuisance.
{ "user.js", AllowOnUserGesture },
{ "vb", AllowOnUserGesture },
{ "vbe", AllowOnUserGesture },
{ "vbs", AllowOnUserGesture },
{ "vsd", AllowOnUserGesture },
{ "vsmacros", AllowOnUserGesture },
{ "vss", AllowOnUserGesture },
{ "vst", AllowOnUserGesture },
{ "vsw", AllowOnUserGesture },
{ "ws", AllowOnUserGesture },
{ "wsc", AllowOnUserGesture },
{ "wsf", AllowOnUserGesture },
{ "wsh", AllowOnUserGesture },
{ "xbap", Dangerous },
{ "user.js", ALLOW_ON_USER_GESTURE },
{ "vb", ALLOW_ON_USER_GESTURE },
{ "vbe", ALLOW_ON_USER_GESTURE },
{ "vbs", ALLOW_ON_USER_GESTURE },
{ "vsd", ALLOW_ON_USER_GESTURE },
{ "vsmacros", ALLOW_ON_USER_GESTURE },
{ "vss", ALLOW_ON_USER_GESTURE },
{ "vst", ALLOW_ON_USER_GESTURE },
{ "vsw", ALLOW_ON_USER_GESTURE },
{ "ws", ALLOW_ON_USER_GESTURE },
{ "wsc", ALLOW_ON_USER_GESTURE },
{ "wsf", ALLOW_ON_USER_GESTURE },
{ "wsh", ALLOW_ON_USER_GESTURE },
{ "xbap", DANGEROUS },
#elif defined(OS_MACOSX)
{ "bash", AllowOnUserGesture },
{ "command", AllowOnUserGesture },
{ "csh", AllowOnUserGesture },
{ "ksh", AllowOnUserGesture },
{ "pkg", AllowOnUserGesture },
{ "sh", AllowOnUserGesture },
{ "shar", AllowOnUserGesture },
{ "tcsh", AllowOnUserGesture },
{ "bash", ALLOW_ON_USER_GESTURE },
{ "command", ALLOW_ON_USER_GESTURE },
{ "csh", ALLOW_ON_USER_GESTURE },
{ "ksh", ALLOW_ON_USER_GESTURE },
{ "pkg", ALLOW_ON_USER_GESTURE },
{ "sh", ALLOW_ON_USER_GESTURE },
{ "shar", ALLOW_ON_USER_GESTURE },
{ "tcsh", ALLOW_ON_USER_GESTURE },
#elif defined(OS_POSIX)
// TODO(estade): lengthen this list.
{ "bash", AllowOnUserGesture },
{ "csh", AllowOnUserGesture },
{ "deb", AllowOnUserGesture },
{ "exe", AllowOnUserGesture },
{ "ksh", AllowOnUserGesture },
{ "rpm", AllowOnUserGesture },
{ "sh", AllowOnUserGesture },
{ "shar", AllowOnUserGesture },
{ "tcsh", AllowOnUserGesture },
{ "bash", ALLOW_ON_USER_GESTURE },
{ "csh", ALLOW_ON_USER_GESTURE },
{ "deb", ALLOW_ON_USER_GESTURE },
{ "exe", ALLOW_ON_USER_GESTURE },
{ "ksh", ALLOW_ON_USER_GESTURE },
{ "rpm", ALLOW_ON_USER_GESTURE },
{ "sh", ALLOW_ON_USER_GESTURE },
{ "shar", ALLOW_ON_USER_GESTURE },
{ "tcsh", ALLOW_ON_USER_GESTURE },
#elif defined(OS_ANDROID)
{ "apk", AllowOnUserGesture },
{ "sh", AllowOnUserGesture },
{ "shar", AllowOnUserGesture },
{ "dex", AllowOnUserGesture },
{ "apk", ALLOW_ON_USER_GESTURE },
{ "sh", ALLOW_ON_USER_GESTURE },
{ "shar", ALLOW_ON_USER_GESTURE },
{ "dex", ALLOW_ON_USER_GESTURE },
#endif
};

DownloadDangerLevel GetFileDangerLevel(const base::FilePath& path) {
base::FilePath::StringType extension(path.Extension());
if (extension.empty())
return NotDangerous;
return NOT_DANGEROUS;
if (!IsStringASCII(extension))
return NotDangerous;
return NOT_DANGEROUS;
#if defined(OS_WIN)
std::string ascii_extension = WideToASCII(extension);
#elif defined(OS_POSIX)
Expand All @@ -240,7 +240,7 @@ DownloadDangerLevel GetFileDangerLevel(const base::FilePath& path) {
if (LowerCaseEqualsASCII(ascii_extension, g_executables[i].extension))
return g_executables[i].level;
}
return NotDangerous;
return NOT_DANGEROUS;
}

static const char* kExecutableWhiteList[] = {
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/download/download_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace download_util {

enum DownloadDangerLevel {
NotDangerous,
AllowOnUserGesture,
Dangerous
NOT_DANGEROUS,
ALLOW_ON_USER_GESTURE,
DANGEROUS
};

// Determine the download danger level of a file.
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/download/download_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ DownloadPrefs::DownloadPrefs(Profile* profile) : profile_(profile) {
base::FilePath path(UTF8ToWide(extensions[i]));
#endif
if (!extensions[i].empty() &&
download_util::GetFileDangerLevel(path) == download_util::NotDangerous)
download_util::GetFileDangerLevel(path) == download_util::NOT_DANGEROUS)
auto_open_.insert(path.value());
}
}
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/download/download_target_determiner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,10 @@ bool DownloadTargetDeterminer::IsDangerousFile(PriorVisitsToReferrer visits) {
return false;

switch (download_util::GetFileDangerLevel(virtual_path_.BaseName())) {
case download_util::NotDangerous:
case download_util::NOT_DANGEROUS:
return false;

case download_util::AllowOnUserGesture:
case download_util::ALLOW_ON_USER_GESTURE:
// "Allow on user gesture" is OK when we have a user gesture and the
// hosting page has been visited before today.
if (download_->GetTransitionType() &
Expand All @@ -617,7 +617,7 @@ bool DownloadTargetDeterminer::IsDangerousFile(PriorVisitsToReferrer visits) {
}
return !download_->HasUserGesture() || visits == NO_VISITS_TO_REFERRER;

case download_util::Dangerous:
case download_util::DANGEROUS:
return true;
}
NOTREACHED();
Expand Down
Loading

0 comments on commit b42beb7

Please sign in to comment.