OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
14 #include "webkit/fileapi/file_system_types.h" | 14 #include "webkit/fileapi/file_system_types.h" |
15 | 15 |
16 namespace fileapi { | 16 namespace fileapi { |
17 | 17 |
18 static const char kPersistentDir[] = "/persistent/"; | 18 static const char kPersistentDir[] = "/persistent/"; |
19 static const char kTemporaryDir[] = "/temporary/"; | 19 static const char kTemporaryDir[] = "/temporary/"; |
20 static const char kLocalDir[] = "/local/"; | 20 static const char kExternalDir[] = "/external/"; |
21 | 21 |
22 bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, | 22 bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, |
23 FilePath* file_path) { | 23 FilePath* file_path) { |
24 GURL origin; | 24 GURL origin; |
25 FileSystemType file_system_type; | 25 FileSystemType file_system_type; |
26 | 26 |
27 if (url.scheme() != "filesystem") | 27 if (url.scheme() != "filesystem") |
28 return false; | 28 return false; |
29 | 29 |
30 std::string temp = url.path(); | 30 std::string temp = url.path(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 return false; | 70 return false; |
71 | 71 |
72 std::string path = UnescapeURLComponent(bare_url.path(), | 72 std::string path = UnescapeURLComponent(bare_url.path(), |
73 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); | 73 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); |
74 if (path.compare(0, strlen(kPersistentDir), kPersistentDir) == 0) { | 74 if (path.compare(0, strlen(kPersistentDir), kPersistentDir) == 0) { |
75 file_system_type = kFileSystemTypePersistent; | 75 file_system_type = kFileSystemTypePersistent; |
76 path = path.substr(strlen(kPersistentDir)); | 76 path = path.substr(strlen(kPersistentDir)); |
77 } else if (path.compare(0, strlen(kTemporaryDir), kTemporaryDir) == 0) { | 77 } else if (path.compare(0, strlen(kTemporaryDir), kTemporaryDir) == 0) { |
78 file_system_type = kFileSystemTypeTemporary; | 78 file_system_type = kFileSystemTypeTemporary; |
79 path = path.substr(strlen(kTemporaryDir)); | 79 path = path.substr(strlen(kTemporaryDir)); |
80 } else if (path.compare(0, strlen(kLocalDir), kLocalDir) == 0) { | 80 } else if (path.compare(0, strlen(kExternalDir), kExternalDir) == 0) { |
81 file_system_type = kFileSystemTypeLocal; | 81 file_system_type = kFileSystemTypeExternal; |
82 path = path.substr(strlen(kLocalDir)); | 82 path = path.substr(strlen(kExternalDir)); |
83 } else { | 83 } else { |
84 return false; | 84 return false; |
85 } | 85 } |
86 | 86 |
87 // Ensure the path is relative. | 87 // Ensure the path is relative. |
88 while (!path.empty() && path[0] == '/') | 88 while (!path.empty() && path[0] == '/') |
89 path.erase(0, 1); | 89 path.erase(0, 1); |
90 | 90 |
91 if (origin_url) | 91 if (origin_url) |
92 *origin_url = origin; | 92 *origin_url = origin; |
(...skipping 14 matching lines...) Expand all Loading... |
107 const GURL& origin_url, fileapi::FileSystemType type) { | 107 const GURL& origin_url, fileapi::FileSystemType type) { |
108 std::string path("filesystem:"); | 108 std::string path("filesystem:"); |
109 path += origin_url.spec(); | 109 path += origin_url.spec(); |
110 switch (type) { | 110 switch (type) { |
111 case kFileSystemTypeTemporary: | 111 case kFileSystemTypeTemporary: |
112 path += (kTemporaryDir + 1); // We don't want the leading slash. | 112 path += (kTemporaryDir + 1); // We don't want the leading slash. |
113 break; | 113 break; |
114 case kFileSystemTypePersistent: | 114 case kFileSystemTypePersistent: |
115 path += (kPersistentDir + 1); // We don't want the leading slash. | 115 path += (kPersistentDir + 1); // We don't want the leading slash. |
116 break; | 116 break; |
117 case kFileSystemTypeLocal: | 117 case kFileSystemTypeExternal: |
118 path += (kLocalDir + 1); // We don't want the leading slash. | 118 path += (kExternalDir + 1); // We don't want the leading slash. |
119 break; | 119 break; |
120 default: | 120 default: |
121 NOTREACHED(); | 121 NOTREACHED(); |
122 return GURL(); | 122 return GURL(); |
123 } | 123 } |
124 return GURL(path); | 124 return GURL(path); |
125 } | 125 } |
126 | 126 |
127 } // namespace fileapi | 127 } // namespace fileapi |
OLD | NEW |