| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 // Prefix to prepend to get a file URL. | 22 // Prefix to prepend to get a file URL. |
| 23 static const base::FilePath::CharType kFileURLPrefix[] = | 23 static const base::FilePath::CharType kFileURLPrefix[] = |
| 24 FILE_PATH_LITERAL("file:///"); | 24 FILE_PATH_LITERAL("file:///"); |
| 25 | 25 |
| 26 GURL FilePathToFileURL(const base::FilePath& path) { | 26 GURL FilePathToFileURL(const base::FilePath& path) { |
| 27 // Produce a URL like "file:///C:/foo" for a regular file, or | 27 // Produce a URL like "file:///C:/foo" for a regular file, or |
| 28 // "file://///server/path" for UNC. The URL canonicalizer will fix up the | 28 // "file://///server/path" for UNC. The URL canonicalizer will fix up the |
| 29 // latter case to be the canonical UNC form: "file://server/path" | 29 // latter case to be the canonical UNC form: "file://server/path" |
| 30 base::FilePath::StringType url_string(kFileURLPrefix); | 30 base::FilePath::StringType url_string(kFileURLPrefix); |
| 31 if (!path.IsAbsolute()) { | |
| 32 base::FilePath current_dir; | |
| 33 PathService::Get(base::DIR_CURRENT, ¤t_dir); | |
| 34 url_string.append(current_dir.value()); | |
| 35 url_string.push_back(base::FilePath::kSeparators[0]); | |
| 36 } | |
| 37 url_string.append(path.value()); | 31 url_string.append(path.value()); |
| 38 | 32 |
| 39 // Now do replacement of some characters. Since we assume the input is a | 33 // Now do replacement of some characters. Since we assume the input is a |
| 40 // literal filename, anything the URL parser might consider special should | 34 // literal filename, anything the URL parser might consider special should |
| 41 // be escaped here. | 35 // be escaped here. |
| 42 | 36 |
| 43 // must be the first substitution since others will introduce percents as the | 37 // must be the first substitution since others will introduce percents as the |
| 44 // escape character | 38 // escape character |
| 45 ReplaceSubstringsAfterOffset( | 39 ReplaceSubstringsAfterOffset( |
| 46 &url_string, 0, FILE_PATH_LITERAL("%"), FILE_PATH_LITERAL("%25")); | 40 &url_string, 0, FILE_PATH_LITERAL("%"), FILE_PATH_LITERAL("%25")); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 if (file_path->value() == base::FilePath::kCurrentDirectory) { | 147 if (file_path->value() == base::FilePath::kCurrentDirectory) { |
| 154 *file_path = base::FilePath(leaf_name); | 148 *file_path = base::FilePath(leaf_name); |
| 155 } else { | 149 } else { |
| 156 *file_path = file_path->Append(leaf_name); | 150 *file_path = file_path->Append(leaf_name); |
| 157 } | 151 } |
| 158 } | 152 } |
| 159 #endif | 153 #endif |
| 160 } | 154 } |
| 161 | 155 |
| 162 } // namespace net | 156 } // namespace net |
| OLD | NEW |