| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 if (first_non_slash != std::string::npos && first_non_slash > 0) | 85 if (first_non_slash != std::string::npos && first_non_slash > 0) |
| 86 path.erase(0, first_non_slash); | 86 path.erase(0, first_non_slash); |
| 87 } else { | 87 } else { |
| 88 // URL contains a host: this means it's UNC. We keep the preceeding slash | 88 // URL contains a host: this means it's UNC. We keep the preceeding slash |
| 89 // on the path. | 89 // on the path. |
| 90 path = "\\\\"; | 90 path = "\\\\"; |
| 91 path.append(host); | 91 path.append(host); |
| 92 path.append(url.path()); | 92 path.append(url.path()); |
| 93 } | 93 } |
| 94 std::replace(path.begin(), path.end(), '/', '\\'); | 94 std::replace(path.begin(), path.end(), '/', '\\'); |
| 95 #else // defined(OS_WIN) | 95 #else // defined(OS_WIN) |
| 96 // Firefox seems to ignore the "host" of a file url if there is one. That is, | 96 // Firefox seems to ignore the "host" of a file url if there is one. That is, |
| 97 // file://foo/bar.txt maps to /bar.txt. | 97 // file://foo/bar.txt maps to /bar.txt. |
| 98 // TODO(dhg): This should probably take into account UNCs which could | 98 // TODO(dhg): This should probably take into account UNCs which could |
| 99 // include a hostname other than localhost or blank | 99 // include a hostname other than localhost or blank |
| 100 std::string path = url.path(); | 100 std::string path = url.path(); |
| 101 #endif // !defined(OS_WIN) | 101 #endif // !defined(OS_WIN) |
| 102 | 102 |
| 103 if (path.empty()) | 103 if (path.empty()) |
| 104 return false; | 104 return false; |
| 105 | 105 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 116 // If the check passed, we converted the result to UTF-8. | 116 // If the check passed, we converted the result to UTF-8. |
| 117 // Otherwise, we treated the result as the native OS encoding. | 117 // Otherwise, we treated the result as the native OS encoding. |
| 118 // However, that led to http://crbug.com/4619 and http://crbug.com/14153 | 118 // However, that led to http://crbug.com/4619 and http://crbug.com/14153 |
| 119 } else { | 119 } else { |
| 120 // Not UTF-8, assume encoding is native codepage and we're done. We know we | 120 // Not UTF-8, assume encoding is native codepage and we're done. We know we |
| 121 // are giving the conversion function a nonempty string, and it may fail if | 121 // are giving the conversion function a nonempty string, and it may fail if |
| 122 // the given string is not in the current encoding and give us an empty | 122 // the given string is not in the current encoding and give us an empty |
| 123 // string back. We detect this and report failure. | 123 // string back. We detect this and report failure. |
| 124 file_path_str = base::SysNativeMBToWide(path); | 124 file_path_str = base::SysNativeMBToWide(path); |
| 125 } | 125 } |
| 126 #else // defined(OS_WIN) | 126 #else // defined(OS_WIN) |
| 127 // Collapse multiple path slashes into a single path slash. | 127 // Collapse multiple path slashes into a single path slash. |
| 128 std::string new_path; | 128 std::string new_path; |
| 129 do { | 129 do { |
| 130 new_path = path; | 130 new_path = path; |
| 131 ReplaceSubstringsAfterOffset(&new_path, 0, "//", "/"); | 131 ReplaceSubstringsAfterOffset(&new_path, 0, "//", "/"); |
| 132 path.swap(new_path); | 132 path.swap(new_path); |
| 133 } while (new_path != path); | 133 } while (new_path != path); |
| 134 | 134 |
| 135 file_path_str.assign(path); | 135 file_path_str.assign(path); |
| 136 #endif // !defined(OS_WIN) | 136 #endif // !defined(OS_WIN) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 154 if (file_path->value() == base::FilePath::kCurrentDirectory) { | 154 if (file_path->value() == base::FilePath::kCurrentDirectory) { |
| 155 *file_path = base::FilePath(leaf_name); | 155 *file_path = base::FilePath(leaf_name); |
| 156 } else { | 156 } else { |
| 157 *file_path = file_path->Append(leaf_name); | 157 *file_path = file_path->Append(leaf_name); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 #endif | 160 #endif |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace net | 163 } // namespace net |
| OLD | NEW |