OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/fileapi/file_system_util.h" | 5 #include "webkit/fileapi/file_system_util.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" |
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
18 #include "webkit/fileapi/file_system_types.h" | 18 #include "webkit/fileapi/file_system_types.h" |
19 | 19 |
20 namespace fileapi { | 20 namespace fileapi { |
21 | 21 |
22 const char kPersistentDir[] = "/persistent"; | 22 const char kPersistentDir[] = "/persistent"; |
23 const char kTemporaryDir[] = "/temporary"; | 23 const char kTemporaryDir[] = "/temporary"; |
24 const char kIsolatedDir[] = "/isolated"; | 24 const char kIsolatedDir[] = "/isolated"; |
25 const char kExternalDir[] = "/external"; | 25 const char kExternalDir[] = "/external"; |
26 const char kTestDir[] = "/test"; | 26 const char kTestDir[] = "/test"; |
27 | 27 |
28 const FilePath::CharType VirtualPath::kRoot[] = FILE_PATH_LITERAL("/"); | 28 const base::FilePath::CharType VirtualPath::kRoot[] = FILE_PATH_LITERAL("/"); |
29 const FilePath::CharType VirtualPath::kSeparator = FILE_PATH_LITERAL('/'); | 29 const base::FilePath::CharType VirtualPath::kSeparator = FILE_PATH_LITERAL('/'); |
30 | 30 |
31 // TODO(ericu): Consider removing support for '\', even on Windows, if possible. | 31 // TODO(ericu): Consider removing support for '\', even on Windows, if possible. |
32 // There's a lot of test code that will need reworking, and we may have trouble | 32 // There's a lot of test code that will need reworking, and we may have trouble |
33 // with base::FilePath elsewhere [e.g. DirName and other methods may also need | 33 // with base::FilePath elsewhere [e.g. DirName and other methods may also need |
34 // replacement]. | 34 // replacement]. |
35 base::FilePath VirtualPath::BaseName(const base::FilePath& virtual_path) { | 35 base::FilePath VirtualPath::BaseName(const base::FilePath& virtual_path) { |
36 base::FilePath::StringType path = virtual_path.value(); | 36 base::FilePath::StringType path = virtual_path.value(); |
37 | 37 |
38 // Keep everything after the final separator, but if the pathname is only | 38 // Keep everything after the final separator, but if the pathname is only |
39 // one character and it's a separator, leave it alone. | 39 // one character and it's a separator, leave it alone. |
(...skipping 26 matching lines...) Expand all Loading... |
66 while (current != current.DirName()) { | 66 while (current != current.DirName()) { |
67 base = BaseName(current); | 67 base = BaseName(current); |
68 ret_val.push_back(base.value()); | 68 ret_val.push_back(base.value()); |
69 current = current.DirName(); | 69 current = current.DirName(); |
70 } | 70 } |
71 | 71 |
72 *components = | 72 *components = |
73 std::vector<base::FilePath::StringType>(ret_val.rbegin(), ret_val.rend()); | 73 std::vector<base::FilePath::StringType>(ret_val.rbegin(), ret_val.rend()); |
74 } | 74 } |
75 | 75 |
76 FilePath::StringType VirtualPath::GetNormalizedFilePath(const FilePath& path) { | 76 base::FilePath::StringType VirtualPath::GetNormalizedFilePath( |
77 FilePath::StringType normalized_path = path.value(); | 77 const base::FilePath& path) { |
78 const size_t num_separators = FilePath::StringType( | 78 base::FilePath::StringType normalized_path = path.value(); |
79 FilePath::kSeparators).length(); | 79 const size_t num_separators = base::FilePath::StringType( |
| 80 base::FilePath::kSeparators).length(); |
80 for (size_t i = 1; i < num_separators; ++i) { | 81 for (size_t i = 1; i < num_separators; ++i) { |
81 std::replace(normalized_path.begin(), normalized_path.end(), | 82 std::replace(normalized_path.begin(), normalized_path.end(), |
82 FilePath::kSeparators[i], kSeparator); | 83 base::FilePath::kSeparators[i], kSeparator); |
83 } | 84 } |
84 | 85 |
85 return (IsAbsolute(normalized_path)) ? | 86 return (IsAbsolute(normalized_path)) ? |
86 normalized_path : FilePath::StringType(kRoot) + normalized_path; | 87 normalized_path : base::FilePath::StringType(kRoot) + normalized_path; |
87 } | 88 } |
88 | 89 |
89 bool VirtualPath::IsAbsolute(const FilePath::StringType& path) { | 90 bool VirtualPath::IsAbsolute(const base::FilePath::StringType& path) { |
90 return path.find(kRoot) == 0; | 91 return path.find(kRoot) == 0; |
91 } | 92 } |
92 | 93 |
93 GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type) { | 94 GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type) { |
94 // origin_url is based on a security origin, so http://foo.com or file:/// | 95 // origin_url is based on a security origin, so http://foo.com or file:/// |
95 // instead of the corresponding filesystem URL. | 96 // instead of the corresponding filesystem URL. |
96 DCHECK(!origin_url.SchemeIsFileSystem()); | 97 DCHECK(!origin_url.SchemeIsFileSystem()); |
97 | 98 |
98 std::string url = "filesystem:" + origin_url.GetWithEmptyPath().spec(); | 99 std::string url = "filesystem:" + origin_url.GetWithEmptyPath().spec(); |
99 switch (type) { | 100 switch (type) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 root.append("/"); | 328 root.append("/"); |
328 if (!optional_root_name.empty()) { | 329 if (!optional_root_name.empty()) { |
329 DCHECK(!base::FilePath::FromUTF8Unsafe(optional_root_name).ReferencesParent(
)); | 330 DCHECK(!base::FilePath::FromUTF8Unsafe(optional_root_name).ReferencesParent(
)); |
330 root.append(optional_root_name); | 331 root.append(optional_root_name); |
331 root.append("/"); | 332 root.append("/"); |
332 } | 333 } |
333 return root; | 334 return root; |
334 } | 335 } |
335 | 336 |
336 } // namespace fileapi | 337 } // namespace fileapi |
OLD | NEW |