| OLD | NEW |
| 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 if (!url.is_valid()) | 66 if (!url.is_valid()) |
| 67 return false; | 67 return false; |
| 68 | 68 |
| 69 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
| 70 std::string path; | 70 std::string path; |
| 71 std::string host = url.host(); | 71 std::string host = url.host(); |
| 72 if (host.empty()) { | 72 if (host.empty()) { |
| 73 // URL contains no host, the path is the filename. In this case, the path | 73 // URL contains no host, the path is the filename. In this case, the path |
| 74 // will probably be preceeded with a slash, as in "/C:/foo.txt", so we | 74 // will probably be preceeded with a slash, as in "/C:/foo.txt", so we |
| 75 // trim out that here. | 75 // trim out that here. |
| 76 path = url.path(); | 76 path = url.path().as_string(); |
| 77 size_t first_non_slash = path.find_first_not_of("/\\"); | 77 size_t first_non_slash = path.find_first_not_of("/\\"); |
| 78 if (first_non_slash != std::string::npos && first_non_slash > 0) | 78 if (first_non_slash != std::string::npos && first_non_slash > 0) |
| 79 path.erase(0, first_non_slash); | 79 path.erase(0, first_non_slash); |
| 80 } else { | 80 } else { |
| 81 // URL contains a host: this means it's UNC. We keep the preceeding slash | 81 // URL contains a host: this means it's UNC. We keep the preceeding slash |
| 82 // on the path. | 82 // on the path. |
| 83 path = "\\\\"; | 83 path = "\\\\"; |
| 84 path.append(host); | 84 path.append(host); |
| 85 path.append(url.path()); | 85 path.append(url.path().as_string()); |
| 86 } | 86 } |
| 87 std::replace(path.begin(), path.end(), '/', '\\'); | 87 std::replace(path.begin(), path.end(), '/', '\\'); |
| 88 #else // defined(OS_WIN) | 88 #else // defined(OS_WIN) |
| 89 // Firefox seems to ignore the "host" of a file url if there is one. That is, | 89 // Firefox seems to ignore the "host" of a file url if there is one. That is, |
| 90 // file://foo/bar.txt maps to /bar.txt. | 90 // file://foo/bar.txt maps to /bar.txt. |
| 91 // TODO(dhg): This should probably take into account UNCs which could | 91 // TODO(dhg): This should probably take into account UNCs which could |
| 92 // include a hostname other than localhost or blank | 92 // include a hostname other than localhost or blank |
| 93 std::string path = url.path(); | 93 std::string path = url.path().as_string(); |
| 94 #endif // !defined(OS_WIN) | 94 #endif // !defined(OS_WIN) |
| 95 | 95 |
| 96 if (path.empty()) | 96 if (path.empty()) |
| 97 return false; | 97 return false; |
| 98 | 98 |
| 99 // GURL stores strings as percent-encoded 8-bit, this will undo if possible. | 99 // GURL stores strings as percent-encoded 8-bit, this will undo if possible. |
| 100 path = UnescapeURLComponent( | 100 path = UnescapeURLComponent( |
| 101 path, UnescapeRule::SPACES | | 101 path, UnescapeRule::SPACES | |
| 102 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS); | 102 UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS); |
| 103 | 103 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 for (size_t i = 0; i < arraysize(magic_names); ++i) { | 190 for (size_t i = 0; i < arraysize(magic_names); ++i) { |
| 191 if (filename_lower == magic_names[i]) | 191 if (filename_lower == magic_names[i]) |
| 192 return true; | 192 return true; |
| 193 } | 193 } |
| 194 | 194 |
| 195 return false; | 195 return false; |
| 196 } | 196 } |
| 197 | 197 |
| 198 } // namespace net | 198 } // namespace net |
| OLD | NEW |