| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/net_util.h" | 5 #include "net/base/net_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <unicode/ucnv.h> | 9 #include <unicode/ucnv.h> |
| 10 #include <unicode/uidna.h> | 10 #include <unicode/uidna.h> |
| (...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 FILE_PATH_LITERAL("download"); | 1074 FILE_PATH_LITERAL("download"); |
| 1075 | 1075 |
| 1076 // about: and data: URLs don't have file names, but esp. data: URLs may | 1076 // about: and data: URLs don't have file names, but esp. data: URLs may |
| 1077 // contain parts that look like ones (i.e., contain a slash). | 1077 // contain parts that look like ones (i.e., contain a slash). |
| 1078 // Therefore we don't attempt to divine a file name out of them. | 1078 // Therefore we don't attempt to divine a file name out of them. |
| 1079 if (url.SchemeIs("about") || url.SchemeIs("data")) { | 1079 if (url.SchemeIs("about") || url.SchemeIs("data")) { |
| 1080 return default_name.empty() ? FilePath(kFinalFallbackName) : default_name; | 1080 return default_name.empty() ? FilePath(kFinalFallbackName) : default_name; |
| 1081 } | 1081 } |
| 1082 | 1082 |
| 1083 const std::string filename_from_cd = GetFileNameFromCD(content_disposition, | 1083 const std::string filename_from_cd = GetFileNameFromCD(content_disposition, |
| 1084 referrer_charset); | 1084 referrer_charset); |
| 1085 #if defined(OS_WIN) | 1085 #if defined(OS_WIN) |
| 1086 FilePath::StringType filename = UTF8ToWide(filename_from_cd); | 1086 FilePath::StringType filename = UTF8ToWide(filename_from_cd); |
| 1087 #elif defined(OS_POSIX) | 1087 #elif defined(OS_POSIX) |
| 1088 FilePath::StringType filename = filename_from_cd; | 1088 FilePath::StringType filename = filename_from_cd; |
| 1089 #endif | 1089 #endif |
| 1090 | 1090 |
| 1091 if (!filename.empty()) { | 1091 if (!filename.empty()) { |
| 1092 // Remove any path information the server may have sent, take the name | 1092 // Remove any path information the server may have sent, take the name |
| 1093 // only. | 1093 // only. |
| 1094 filename = FilePath(filename).BaseName().value(); | 1094 filename = FilePath(filename).BaseName().value(); |
| 1095 | 1095 |
| 1096 // Next, remove "." from the beginning and end of the file name to avoid | 1096 // Next, remove "." from the beginning and end of the file name to avoid |
| 1097 // tricks with hidden files, "..", and "." | 1097 // tricks with hidden files, "..", and "." |
| 1098 TrimString(filename, FILE_PATH_LITERAL("."), &filename); | 1098 TrimString(filename, FILE_PATH_LITERAL("."), &filename); |
| 1099 } | 1099 } |
| 1100 if (filename.empty()) { | 1100 if (filename.empty()) { |
| 1101 if (url.is_valid()) { | 1101 if (url.is_valid()) { |
| 1102 const std::string unescaped_url_filename = UnescapeURLComponent( | 1102 const std::string unescaped_url_filename = UnescapeURLComponent( |
| 1103 url.ExtractFileName(), | 1103 url.ExtractFileName(), |
| 1104 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); | 1104 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); |
| 1105 | |
| 1106 // The URL should be escaped UTF-8, but may not be. | |
| 1107 std::string decoded_filename; | |
| 1108 bool ignore; | |
| 1109 DecodeWord(unescaped_url_filename, referrer_charset, &ignore, | |
| 1110 &decoded_filename); | |
| 1111 | |
| 1112 #if defined(OS_WIN) | 1105 #if defined(OS_WIN) |
| 1113 filename = UTF8ToWide(decoded_filename); | 1106 filename = UTF8ToWide(unescaped_url_filename); |
| 1114 #elif defined(OS_POSIX) | 1107 #elif defined(OS_POSIX) |
| 1115 filename = decoded_filename; | 1108 filename = unescaped_url_filename; |
| 1116 #endif | 1109 #endif |
| 1117 } | 1110 } |
| 1118 } | 1111 } |
| 1119 | 1112 |
| 1120 #if defined(OS_WIN) | 1113 #if defined(OS_WIN) |
| 1121 { // Handle CreateFile() stripping trailing dots and spaces on filenames | 1114 { // Handle CreateFile() stripping trailing dots and spaces on filenames |
| 1122 // http://support.microsoft.com/kb/115827 | 1115 // http://support.microsoft.com/kb/115827 |
| 1123 std::string::size_type pos = filename.find_last_not_of(L" ."); | 1116 std::string::size_type pos = filename.find_last_not_of(L" ."); |
| 1124 if (pos == std::string::npos) | 1117 if (pos == std::string::npos) |
| 1125 filename.resize(0); | 1118 filename.resize(0); |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1867 unsigned char mask = 0xFF << (8 - remaining_bits); | 1860 unsigned char mask = 0xFF << (8 - remaining_bits); |
| 1868 int i = num_entire_bytes_in_prefix; | 1861 int i = num_entire_bytes_in_prefix; |
| 1869 if ((ip_number[i] & mask) != (ip_prefix[i] & mask)) | 1862 if ((ip_number[i] & mask) != (ip_prefix[i] & mask)) |
| 1870 return false; | 1863 return false; |
| 1871 } | 1864 } |
| 1872 | 1865 |
| 1873 return true; | 1866 return true; |
| 1874 } | 1867 } |
| 1875 | 1868 |
| 1876 } // namespace net | 1869 } // namespace net |
| OLD | NEW |