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

Side by Side Diff: net/base/filename_util_internal.cc

Issue 448853002: Move StringToLowerASCII to base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months 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 | « net/base/data_url.cc ('k') | net/base/filename_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/base/filename_util.h" 5 #include "net/base/filename_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // If the URL contains a (possibly empty) query, assume it is a generator, and 82 // If the URL contains a (possibly empty) query, assume it is a generator, and
83 // allow the determined extension to be overwritten. 83 // allow the determined extension to be overwritten.
84 *should_overwrite_extension = !decoded_filename.empty() && url.has_query(); 84 *should_overwrite_extension = !decoded_filename.empty() && url.has_query();
85 85
86 return decoded_filename; 86 return decoded_filename;
87 } 87 }
88 88
89 // Returns whether the specified extension is automatically integrated into the 89 // Returns whether the specified extension is automatically integrated into the
90 // windows shell. 90 // windows shell.
91 bool IsShellIntegratedExtension(const base::FilePath::StringType& extension) { 91 bool IsShellIntegratedExtension(const base::FilePath::StringType& extension) {
92 base::FilePath::StringType extension_lower = StringToLowerASCII(extension); 92 base::FilePath::StringType extension_lower =
93 base::StringToLowerASCII(extension);
93 94
94 // http://msdn.microsoft.com/en-us/library/ms811694.aspx 95 // http://msdn.microsoft.com/en-us/library/ms811694.aspx
95 // Right-clicking on shortcuts can be magical. 96 // Right-clicking on shortcuts can be magical.
96 if ((extension_lower == FILE_PATH_LITERAL("local")) || 97 if ((extension_lower == FILE_PATH_LITERAL("local")) ||
97 (extension_lower == FILE_PATH_LITERAL("lnk"))) 98 (extension_lower == FILE_PATH_LITERAL("lnk")))
98 return true; 99 return true;
99 100
100 // http://www.juniper.net/security/auto/vulnerabilities/vuln2612.html 101 // http://www.juniper.net/security/auto/vulnerabilities/vuln2612.html
101 // Files become magical if they end in a CLSID, so block such extensions. 102 // Files become magical if they end in a CLSID, so block such extensions.
102 if (!extension_lower.empty() && 103 if (!extension_lower.empty() &&
103 (extension_lower[0] == FILE_PATH_LITERAL('{')) && 104 (extension_lower[0] == FILE_PATH_LITERAL('{')) &&
104 (extension_lower[extension_lower.length() - 1] == FILE_PATH_LITERAL('}'))) 105 (extension_lower[extension_lower.length() - 1] == FILE_PATH_LITERAL('}')))
105 return true; 106 return true;
106 return false; 107 return false;
107 } 108 }
108 109
109 // Returns whether the specified file name is a reserved name on windows. 110 // Returns whether the specified file name is a reserved name on windows.
110 // This includes names like "com2.zip" (which correspond to devices) and 111 // This includes names like "com2.zip" (which correspond to devices) and
111 // desktop.ini and thumbs.db which have special meaning to the windows shell. 112 // desktop.ini and thumbs.db which have special meaning to the windows shell.
112 bool IsReservedName(const base::FilePath::StringType& filename) { 113 bool IsReservedName(const base::FilePath::StringType& filename) {
113 // This list is taken from the MSDN article "Naming a file" 114 // This list is taken from the MSDN article "Naming a file"
114 // http://msdn2.microsoft.com/en-us/library/aa365247(VS.85).aspx 115 // http://msdn2.microsoft.com/en-us/library/aa365247(VS.85).aspx
115 // I also added clock$ because GetSaveFileName seems to consider it as a 116 // I also added clock$ because GetSaveFileName seems to consider it as a
116 // reserved name too. 117 // reserved name too.
117 static const char* const known_devices[] = { 118 static const char* const known_devices[] = {
118 "con", "prn", "aux", "nul", "com1", "com2", "com3", "com4", 119 "con", "prn", "aux", "nul", "com1", "com2", "com3", "com4",
119 "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3", 120 "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3",
120 "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9", "clock$"}; 121 "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9", "clock$"};
121 #if defined(OS_WIN) 122 #if defined(OS_WIN)
122 std::string filename_lower = StringToLowerASCII(base::WideToUTF8(filename)); 123 std::string filename_lower =
124 base::StringToLowerASCII(base::WideToUTF8(filename));
123 #elif defined(OS_POSIX) 125 #elif defined(OS_POSIX)
124 std::string filename_lower = StringToLowerASCII(filename); 126 std::string filename_lower = base::StringToLowerASCII(filename);
125 #endif 127 #endif
126 128
127 for (size_t i = 0; i < arraysize(known_devices); ++i) { 129 for (size_t i = 0; i < arraysize(known_devices); ++i) {
128 // Exact match. 130 // Exact match.
129 if (filename_lower == known_devices[i]) 131 if (filename_lower == known_devices[i])
130 return true; 132 return true;
131 // Starts with "DEVICE.". 133 // Starts with "DEVICE.".
132 if (filename_lower.find(std::string(known_devices[i]) + ".") == 0) 134 if (filename_lower.find(std::string(known_devices[i]) + ".") == 0)
133 return true; 135 return true;
134 } 136 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 base::FilePath generated_name( 311 base::FilePath generated_name(
310 base::SysWideToNativeMB(base::UTF16ToWide(file_name))); 312 base::SysWideToNativeMB(base::UTF16ToWide(file_name)));
311 #endif 313 #endif
312 314
313 DCHECK(!generated_name.empty()); 315 DCHECK(!generated_name.empty());
314 316
315 return generated_name; 317 return generated_name;
316 } 318 }
317 319
318 } // namespace net 320 } // namespace net
OLDNEW
« no previous file with comments | « net/base/data_url.cc ('k') | net/base/filename_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698