Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/download/download_exe.cc

Issue 5603008: Modify the "dangerous download" algorithm as follows. Original patch by Pier... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/download/download_extensions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include <set>
6 #include <string>
7
8 #include "chrome/browser/download/download_util.h"
9
10 #include "base/string_util.h"
11 #include "net/base/mime_util.h"
12 #include "net/base/net_util.h"
13
14 namespace download_util {
15
16 // For file extensions taken from mozilla:
17
18 /* ***** BEGIN LICENSE BLOCK *****
19 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
20 *
21 * The contents of this file are subject to the Mozilla Public License Version
22 * 1.1 (the "License"); you may not use this file except in compliance with
23 * the License. You may obtain a copy of the License at
24 * http://www.mozilla.org/MPL/
25 *
26 * Software distributed under the License is distributed on an "AS IS" basis,
27 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
28 * for the specific language governing rights and limitations under the
29 * License.
30 *
31 * The Original Code is Mozilla Communicator client code, released
32 * March 31, 1998.
33 *
34 * The Initial Developer of the Original Code is
35 * Netscape Communications Corporation.
36 * Portions created by the Initial Developer are Copyright (C) 1998-1999
37 * the Initial Developer. All Rights Reserved.
38 *
39 * Contributor(s):
40 * Doug Turner <dougt@netscape.com>
41 * Dean Tessman <dean_tessman@hotmail.com>
42 * Brodie Thiesfield <brofield@jellycan.com>
43 * Jungshik Shin <jshin@i18nl10n.com>
44 *
45 * Alternatively, the contents of this file may be used under the terms of
46 * either of the GNU General Public License Version 2 or later (the "GPL"),
47 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
48 * in which case the provisions of the GPL or the LGPL are applicable instead
49 * of those above. If you wish to allow use of your version of this file only
50 * under the terms of either the GPL or the LGPL, and not to allow others to
51 * use your version of this file under the terms of the MPL, indicate your
52 * decision by deleting the provisions above and replace them with the notice
53 * and other provisions required by the GPL or the LGPL. If you do not delete
54 * the provisions above, a recipient may use your version of this file under
55 * the terms of any one of the MPL, the GPL or the LGPL.
56 *
57 * ***** END LICENSE BLOCK ***** */
58
59 static const char* const g_executables[] = {
60 "class",
61 "htm",
62 "html",
63 "jar",
64 "pdf",
65 "pdfxml",
66 "mars",
67 "fdf",
68 "xfdf",
69 "xdp",
70 "xfd",
71 "pl",
72 "py",
73 "rb",
74 "shtm",
75 "shtml",
76 "svg",
77 "swf",
78 "xht",
79 "xhtm",
80 "xhtml",
81 "xml",
82 "xsl",
83 "xslt",
84 #if defined(OS_WIN)
85 "ad",
86 "ade",
87 "adp",
88 "app",
89 "application",
90 "asp",
91 "asx",
92 "bas",
93 "bat",
94 "chm",
95 "cmd",
96 "com",
97 "cpl",
98 "crt",
99 "dll",
100 "exe",
101 "fxp",
102 "hlp",
103 "hta",
104 "htt",
105 "inf",
106 "ins",
107 "isp",
108 "js",
109 "jse",
110 "lnk",
111 "mad",
112 "maf",
113 "mag",
114 "mam",
115 "maq",
116 "mar",
117 "mas",
118 "mat",
119 "mau",
120 "mav",
121 "maw",
122 "mda",
123 "mdb",
124 "mde",
125 "mdt",
126 "mdw",
127 "mdz",
128 "mht",
129 "mhtml",
130 "msc",
131 "msh",
132 "mshxml",
133 "msi",
134 "msp",
135 "mst",
136 "ocx",
137 "ops",
138 "pcd",
139 "pif",
140 "plg",
141 "prf",
142 "prg",
143 "pst",
144 "reg",
145 "scf",
146 "scr",
147 "sct",
148 "shb",
149 "shs",
150 "url",
151 "vb",
152 "vbe",
153 "vbs",
154 "vsd",
155 "vsmacros",
156 "vss",
157 "vst",
158 "vsw",
159 "ws",
160 "wsc",
161 "wsf",
162 "wsh",
163 "xbap",
164 #elif defined(OS_MACOSX)
165 // TODO(thakis): Figure out what makes sense here -- crbug.com/19096
166 "app",
167 "dmg",
168 #elif defined(OS_POSIX)
169 // TODO(estade): lengthen this list.
170 "bash",
171 "csh",
172 "deb",
173 "exe",
174 "ksh",
175 "rpm",
176 "sh",
177 "tcsh",
178 #endif
179 };
180
181 bool IsExecutableFile(const FilePath& path) {
182 return IsExecutableExtension(path.Extension());
183 }
184
185 bool IsExecutableExtension(const FilePath::StringType& extension) {
186 if (extension.empty())
187 return false;
188 if (!IsStringASCII(extension))
189 return false;
190 #if defined(OS_WIN)
191 std::string ascii_extension = WideToASCII(extension);
192 #elif defined(OS_POSIX)
193 std::string ascii_extension = extension;
194 #endif
195
196 // Strip out leading dot if it's still there
197 if (ascii_extension[0] == FilePath::kExtensionSeparator)
198 ascii_extension.erase(0, 1);
199
200 for (size_t i = 0; i < arraysize(g_executables); ++i) {
201 if (LowerCaseEqualsASCII(ascii_extension, g_executables[i]))
202 return true;
203 }
204 return false;
205 }
206
207 static const char* kExecutableWhiteList[] = {
208 // JavaScript is just as powerful as EXE.
209 "text/javascript",
210 "text/javascript;version=*",
211 "text/html",
212 // Registry files can cause critical changes to the MS OS behavior.
213 // Addition of this mimetype also addresses bug 7337.
214 "text/x-registry",
215 "text/x-sh",
216 // Some sites use binary/octet-stream to mean application/octet-stream.
217 // See http://code.google.com/p/chromium/issues/detail?id=1573
218 "binary/octet-stream"
219 };
220
221 static const char* kExecutableBlackList[] = {
222 // These application types are not executable.
223 "application/*+xml",
224 "application/xml"
225 };
226
227 bool IsExecutableMimeType(const std::string& mime_type) {
228 for (size_t i = 0; i < arraysize(kExecutableWhiteList); ++i) {
229 if (net::MatchesMimeType(kExecutableWhiteList[i], mime_type))
230 return true;
231 }
232 for (size_t i = 0; i < arraysize(kExecutableBlackList); ++i) {
233 if (net::MatchesMimeType(kExecutableBlackList[i], mime_type))
234 return false;
235 }
236 // We consider only other application types to be executable.
237 return net::MatchesMimeType("application/*", mime_type);
238 }
239
240
241 } // namespace download_util
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_extensions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698