15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <set> 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/download/download_extensions.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_util.h" 11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/mime_util.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_util.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace download_util { 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// For file extensions taken from mozilla: 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* ***** BEGIN LICENSE BLOCK ***** 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Version: MPL 1.1/GPL 2.0/LGPL 2.1 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The contents of this file are subject to the Mozilla Public License Version 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 1.1 (the "License"); you may not use this file except in compliance with 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * the License. You may obtain a copy of the License at 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * http://www.mozilla.org/MPL/ 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Software distributed under the License is distributed on an "AS IS" basis, 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * for the specific language governing rights and limitations under the 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * License. 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The Original Code is Mozilla Communicator client code, released 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * March 31, 1998. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The Initial Developer of the Original Code is 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Netscape Communications Corporation. 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Portions created by the Initial Developer are Copyright (C) 1998-1999 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * the Initial Developer. All Rights Reserved. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Contributor(s): 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Doug Turner <dougt@netscape.com> 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Dean Tessman <dean_tessman@hotmail.com> 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Brodie Thiesfield <brofield@jellycan.com> 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Jungshik Shin <jshin@i18nl10n.com> 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Alternatively, the contents of this file may be used under the terms of 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * either of the GNU General Public License Version 2 or later (the "GPL"), 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * in which case the provisions of the GPL or the LGPL are applicable instead 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * of those above. If you wish to allow use of your version of this file only 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * under the terms of either the GPL or the LGPL, and not to allow others to 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * use your version of this file under the terms of the MPL, indicate your 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * decision by deleting the provisions above and replace them with the notice 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * and other provisions required by the GPL or the LGPL. If you do not delete 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * the provisions above, a recipient may use your version of this file under 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * the terms of any one of the MPL, the GPL or the LGPL. 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * ***** END LICENSE BLOCK ***** */ 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static const struct Executables { 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* extension; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DownloadDangerLevel level; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} g_executables[] = { 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Some files are dangerous on all platforms. 65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Flash files downloaded locally can sometimes access the local filesystem. 67a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "swf", DANGEROUS }, 68a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "spl", DANGEROUS }, 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Chrome extensions should be obtained through the web store. 70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "crx", ALLOW_ON_USER_GESTURE }, 71a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 72a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Windows, all file categories. 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN) 74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "ad", ALLOW_ON_USER_GESTURE }, 75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "ade", ALLOW_ON_USER_GESTURE }, 76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "adp", ALLOW_ON_USER_GESTURE }, 77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "app", ALLOW_ON_USER_GESTURE }, 78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "application", ALLOW_ON_USER_GESTURE }, 79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "asp", ALLOW_ON_USER_GESTURE }, 80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "asx", ALLOW_ON_USER_GESTURE }, 81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "bas", ALLOW_ON_USER_GESTURE }, 82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "bat", ALLOW_ON_USER_GESTURE }, 83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "cfg", DANGEROUS }, 84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "chi", ALLOW_ON_USER_GESTURE }, 85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "chm", ALLOW_ON_USER_GESTURE }, 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "cmd", ALLOW_ON_USER_GESTURE }, 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "com", ALLOW_ON_USER_GESTURE }, 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "cpl", ALLOW_ON_USER_GESTURE }, 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "crt", ALLOW_ON_USER_GESTURE }, 90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "dll", DANGEROUS }, 91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "drv", DANGEROUS }, 92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "exe", ALLOW_ON_USER_GESTURE }, 93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "fxp", ALLOW_ON_USER_GESTURE }, 94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "grp", DANGEROUS }, 95868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "hlp", ALLOW_ON_USER_GESTURE }, 96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "hta", ALLOW_ON_USER_GESTURE }, 97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "htt", ALLOW_ON_USER_GESTURE }, 98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "inf", ALLOW_ON_USER_GESTURE }, 99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "ini", DANGEROUS }, 100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "ins", ALLOW_ON_USER_GESTURE }, 101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "isp", ALLOW_ON_USER_GESTURE }, 102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "js", ALLOW_ON_USER_GESTURE }, 103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "jse", ALLOW_ON_USER_GESTURE }, 104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "lnk", ALLOW_ON_USER_GESTURE }, 105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "local", DANGEROUS }, 106868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mad", ALLOW_ON_USER_GESTURE }, 107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "maf", ALLOW_ON_USER_GESTURE }, 108868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mag", ALLOW_ON_USER_GESTURE }, 109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mam", ALLOW_ON_USER_GESTURE }, 110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "manifest", DANGEROUS }, 111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "maq", ALLOW_ON_USER_GESTURE }, 112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mar", ALLOW_ON_USER_GESTURE }, 113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mas", ALLOW_ON_USER_GESTURE }, 114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mat", ALLOW_ON_USER_GESTURE }, 115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mau", ALLOW_ON_USER_GESTURE }, 116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mav", ALLOW_ON_USER_GESTURE }, 117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "maw", ALLOW_ON_USER_GESTURE }, 118868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mda", ALLOW_ON_USER_GESTURE }, 119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mdb", ALLOW_ON_USER_GESTURE }, 120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mde", ALLOW_ON_USER_GESTURE }, 121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mdt", ALLOW_ON_USER_GESTURE }, 122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mdw", ALLOW_ON_USER_GESTURE }, 123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mdz", ALLOW_ON_USER_GESTURE }, 124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mht", ALLOW_ON_USER_GESTURE }, 125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mhtml", ALLOW_ON_USER_GESTURE }, 126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mmc", ALLOW_ON_USER_GESTURE }, 127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mof", DANGEROUS }, 128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "msc", ALLOW_ON_USER_GESTURE }, 129868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "msh", ALLOW_ON_USER_GESTURE }, 130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mshxml", ALLOW_ON_USER_GESTURE }, 131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "msi", ALLOW_ON_USER_GESTURE }, 132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "msp", ALLOW_ON_USER_GESTURE }, 133868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "mst", ALLOW_ON_USER_GESTURE }, 134868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "ocx", DANGEROUS }, 135868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "ops", ALLOW_ON_USER_GESTURE }, 136868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "pcd", ALLOW_ON_USER_GESTURE }, 137868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "pif", ALLOW_ON_USER_GESTURE }, 138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "plg", ALLOW_ON_USER_GESTURE }, 139868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "prf", ALLOW_ON_USER_GESTURE }, 140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "prg", ALLOW_ON_USER_GESTURE }, 141868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "pst", ALLOW_ON_USER_GESTURE }, 142868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "reg", ALLOW_ON_USER_GESTURE }, 143868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "scf", ALLOW_ON_USER_GESTURE }, 144868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "scr", ALLOW_ON_USER_GESTURE }, 145868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "sct", ALLOW_ON_USER_GESTURE }, 146868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "shb", ALLOW_ON_USER_GESTURE }, 147868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "shs", ALLOW_ON_USER_GESTURE }, 148868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "sys", DANGEROUS }, 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { "url", DANGEROUS }, 150868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "vb", ALLOW_ON_USER_GESTURE }, 151868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "vbe", ALLOW_ON_USER_GESTURE }, 152868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "vbs", ALLOW_ON_USER_GESTURE }, 153868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "vsd", ALLOW_ON_USER_GESTURE }, 154868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "vsmacros", ALLOW_ON_USER_GESTURE }, 155868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "vss", ALLOW_ON_USER_GESTURE }, 156868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "vst", ALLOW_ON_USER_GESTURE }, 157868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "vsw", ALLOW_ON_USER_GESTURE }, 158868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "ws", ALLOW_ON_USER_GESTURE }, 159868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "wsc", ALLOW_ON_USER_GESTURE }, 160868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "wsf", ALLOW_ON_USER_GESTURE }, 161868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "wsh", ALLOW_ON_USER_GESTURE }, 162868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "xbap", DANGEROUS }, 163a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif // OS_WIN 164a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 165a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Java. 166a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if !defined(OS_CHROMEOS) 167a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "class", DANGEROUS }, 168a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "jar", DANGEROUS }, 169a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "jnlp", DANGEROUS }, 170a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 171a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 172a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Scripting languages. (Shells are handled below.) 173a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) 174a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "pl", ALLOW_ON_USER_GESTURE }, 175a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "py", ALLOW_ON_USER_GESTURE }, 176a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "pyc", ALLOW_ON_USER_GESTURE }, 177a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "pyw", ALLOW_ON_USER_GESTURE }, 178a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "rb", ALLOW_ON_USER_GESTURE }, 179a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 180a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 181a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Shell languages. (OS_ANDROID is OS_POSIX.) OS_WIN shells are handled above. 182a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_POSIX) 183868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "bash", ALLOW_ON_USER_GESTURE }, 184868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "csh", ALLOW_ON_USER_GESTURE }, 185868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "ksh", ALLOW_ON_USER_GESTURE }, 186868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "sh", ALLOW_ON_USER_GESTURE }, 187868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "shar", ALLOW_ON_USER_GESTURE }, 188868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "tcsh", ALLOW_ON_USER_GESTURE }, 189a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 190a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_MACOSX) 191a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "command", ALLOW_ON_USER_GESTURE }, 192a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 193a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 194a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Package management formats. OS_WIN package formats are handled above. 195a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_MACOSX) || defined(OS_LINUX) 196a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "pkg", ALLOW_ON_USER_GESTURE }, 197a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_LINUX) 199868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "deb", ALLOW_ON_USER_GESTURE }, 200868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) { "rpm", ALLOW_ON_USER_GESTURE }, 201a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 202a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_ANDROID) 203a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) { "dex", ALLOW_ON_USER_GESTURE }, // Really an executable format. 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)DownloadDangerLevel GetFileDangerLevel(const base::FilePath& path) { 208a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::FilePath::StringType extension(path.FinalExtension()); 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (extension.empty()) 210868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return NOT_DANGEROUS; 211010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (!base::IsStringASCII(extension)) 212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return NOT_DANGEROUS; 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN) 214a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::string ascii_extension = base::UTF16ToASCII(extension); 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(OS_POSIX) 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string ascii_extension = extension; 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Strip out leading dot if it's still there 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (ascii_extension[0] == base::FilePath::kExtensionSeparator) 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ascii_extension.erase(0, 1); 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < arraysize(g_executables); ++i) { 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (LowerCaseEqualsASCII(ascii_extension, g_executables[i].extension)) 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return g_executables[i].level; 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 227868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return NOT_DANGEROUS; 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static const char* kExecutableWhiteList[] = { 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // JavaScript is just as powerful as EXE. 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "text/javascript", 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "text/javascript;version=*", 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "text/html", 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Registry files can cause critical changes to the MS OS behavior. 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Addition of this mimetype also addresses bug 7337. 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "text/x-registry", 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "text/x-sh", 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Some sites use binary/octet-stream to mean application/octet-stream. 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // See http://code.google.com/p/chromium/issues/detail?id=1573 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "binary/octet-stream" 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static const char* kExecutableBlackList[] = { 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These application types are not executable. 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "application/*+xml", 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "application/xml" 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsExecutableMimeType(const std::string& mime_type) { 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < arraysize(kExecutableWhiteList); ++i) { 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (net::MatchesMimeType(kExecutableWhiteList[i], mime_type)) 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < arraysize(kExecutableBlackList); ++i) { 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (net::MatchesMimeType(kExecutableBlackList[i], mime_type)) 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We consider only other application types to be executable. 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return net::MatchesMimeType("application/*", mime_type); 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace download_util 265