OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "chrome/browser/download/download_util.h" | 8 #include "chrome/browser/download/download_util.h" |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "net/base/mime_util.h" |
| 13 #include "net/base/net_util.h" |
12 | 14 |
13 namespace download_util { | 15 namespace download_util { |
14 | 16 |
15 // For file extensions taken from mozilla: | 17 // For file extensions taken from mozilla: |
16 | 18 |
17 /* ***** BEGIN LICENSE BLOCK ***** | 19 /* ***** BEGIN LICENSE BLOCK ***** |
18 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 20 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
19 * | 21 * |
20 * The contents of this file are subject to the Mozilla Public License Version | 22 * The contents of this file are subject to the Mozilla Public License Version |
21 * 1.1 (the "License"); you may not use this file except in compliance with | 23 * 1.1 (the "License"); you may not use this file except in compliance with |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 "ksh", | 161 "ksh", |
160 "pl", | 162 "pl", |
161 "py", | 163 "py", |
162 "rb", | 164 "rb", |
163 "rpm", | 165 "rpm", |
164 "sh", | 166 "sh", |
165 "tcsh", | 167 "tcsh", |
166 #endif | 168 #endif |
167 }; | 169 }; |
168 | 170 |
169 bool IsExecutableExtension(const std::string& extension) { | 171 bool IsExecutableExtension(const FilePath::StringType& extension) { |
| 172 if (extension.empty()) |
| 173 return false; |
| 174 if (!IsStringASCII(extension)) |
| 175 return false; |
| 176 #if defined(OS_WIN) |
| 177 std::string ascii_extension = WideToASCII(extension); |
| 178 #elif defined(OS_POSIX) |
| 179 std::string ascii_extension = extension; |
| 180 #endif |
| 181 |
| 182 // Strip out leading dot if it's still there |
| 183 if (ascii_extension[0] == FilePath::kExtensionSeparator) |
| 184 ascii_extension.erase(0, 1); |
| 185 |
170 for (size_t i = 0; i < arraysize(g_executables); ++i) { | 186 for (size_t i = 0; i < arraysize(g_executables); ++i) { |
171 if (LowerCaseEqualsASCII(extension, g_executables[i])) | 187 if (LowerCaseEqualsASCII(ascii_extension, g_executables[i])) |
172 return true; | 188 return true; |
173 } | 189 } |
174 return false; | 190 return false; |
175 } | 191 } |
176 | 192 |
| 193 static const char* kExecutableWhiteList[] = { |
| 194 // JavaScript is just as powerful as EXE. |
| 195 "text/javascript", |
| 196 "text/javascript;version=*", |
| 197 // Registry files can cause critical changes to the MS OS behavior. |
| 198 // Addition of this mimetype also addresses bug 7337. |
| 199 "text/x-registry", |
| 200 // Some sites use binary/octet-stream to mean application/octet-stream. |
| 201 // See http://code.google.com/p/chromium/issues/detail?id=1573 |
| 202 "binary/octet-stream" |
| 203 }; |
| 204 |
| 205 static const char* kExecutableBlackList[] = { |
| 206 // These application types are not executable. |
| 207 "application/*+xml", |
| 208 "application/xml" |
| 209 }; |
| 210 |
| 211 bool IsExecutableMimeType(const std::string& mime_type) { |
| 212 for (size_t i = 0; i < arraysize(kExecutableWhiteList); ++i) { |
| 213 if (net::MatchesMimeType(kExecutableWhiteList[i], mime_type)) |
| 214 return true; |
| 215 } |
| 216 for (size_t i = 0; i < arraysize(kExecutableBlackList); ++i) { |
| 217 if (net::MatchesMimeType(kExecutableBlackList[i], mime_type)) |
| 218 return false; |
| 219 } |
| 220 // We consider only other application types to be executable. |
| 221 return net::MatchesMimeType("application/*", mime_type); |
| 222 } |
| 223 |
| 224 |
177 } // namespace download_util | 225 } // namespace download_util |
OLD | NEW |