| 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 "net/base/escape.h" | 15 #include "net/base/escape.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.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 "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 19 #include "webkit/fileapi/file_system_types.h" | 19 #include "webkit/fileapi/file_system_types.h" |
| 20 | 20 |
| 21 namespace fileapi { | 21 namespace fileapi { |
| 22 | 22 |
| 23 const char kPersistentDir[] = "/persistent"; | 23 const char kPersistentDir[] = "/persistent"; |
| 24 const char kTemporaryDir[] = "/temporary"; | 24 const char kTemporaryDir[] = "/temporary"; |
| 25 const char kIsolatedDir[] = "/isolated"; | 25 const char kIsolatedDir[] = "/isolated"; |
| 26 const char kExternalDir[] = "/external"; | 26 const char kExternalDir[] = "/external"; |
| 27 const char kTestDir[] = "/test"; |
| 27 | 28 |
| 28 const char kPersistentName[] = "Persistent"; | 29 const char kPersistentName[] = "Persistent"; |
| 29 const char kTemporaryName[] = "Temporary"; | 30 const char kTemporaryName[] = "Temporary"; |
| 30 const char kIsolatedName[] = "Isolated"; | 31 const char kIsolatedName[] = "Isolated"; |
| 31 const char kExternalName[] = "External"; | 32 const char kExternalName[] = "External"; |
| 33 const char kTestName[] = "Test"; |
| 32 | 34 |
| 33 bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, | 35 bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, |
| 34 FilePath* file_path) { | 36 FilePath* file_path) { |
| 35 GURL origin; | 37 GURL origin; |
| 36 FileSystemType file_system_type = kFileSystemTypeUnknown; | 38 FileSystemType file_system_type = kFileSystemTypeUnknown; |
| 37 | 39 |
| 38 if (!url.is_valid() || !url.SchemeIsFileSystem()) | 40 if (!url.is_valid() || !url.SchemeIsFileSystem()) |
| 39 return false; | 41 return false; |
| 40 DCHECK(url.inner_url()); | 42 DCHECK(url.inner_url()); |
| 41 | 43 |
| 42 std::string inner_path = url.inner_url()->path(); | 44 std::string inner_path = url.inner_url()->path(); |
| 43 | 45 |
| 44 const struct { | 46 const struct { |
| 45 FileSystemType type; | 47 FileSystemType type; |
| 46 const char* dir; | 48 const char* dir; |
| 47 } kValidTypes[] = { | 49 } kValidTypes[] = { |
| 48 { kFileSystemTypePersistent, kPersistentDir }, | 50 { kFileSystemTypePersistent, kPersistentDir }, |
| 49 { kFileSystemTypeTemporary, kTemporaryDir }, | 51 { kFileSystemTypeTemporary, kTemporaryDir }, |
| 50 { kFileSystemTypeIsolated, kIsolatedDir }, | 52 { kFileSystemTypeIsolated, kIsolatedDir }, |
| 51 { kFileSystemTypeExternal, kExternalDir }, | 53 { kFileSystemTypeExternal, kExternalDir }, |
| 54 { kFileSystemTypeTest, kTestDir }, |
| 52 }; | 55 }; |
| 53 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kValidTypes); ++i) { | 56 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kValidTypes); ++i) { |
| 54 if (StartsWithASCII(inner_path, kValidTypes[i].dir, true)) { | 57 if (StartsWithASCII(inner_path, kValidTypes[i].dir, true)) { |
| 55 file_system_type = kValidTypes[i].type; | 58 file_system_type = kValidTypes[i].type; |
| 56 break; | 59 break; |
| 57 } | 60 } |
| 58 } | 61 } |
| 59 | 62 |
| 60 if (file_system_type == kFileSystemTypeUnknown) | 63 if (file_system_type == kFileSystemTypeUnknown) |
| 61 return false; | 64 return false; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 switch (type) { | 142 switch (type) { |
| 140 case kFileSystemTypeTemporary: | 143 case kFileSystemTypeTemporary: |
| 141 url += (kTemporaryDir + 1); // We don't want the leading slash. | 144 url += (kTemporaryDir + 1); // We don't want the leading slash. |
| 142 return GURL(url + "/"); | 145 return GURL(url + "/"); |
| 143 case kFileSystemTypePersistent: | 146 case kFileSystemTypePersistent: |
| 144 url += (kPersistentDir + 1); // We don't want the leading slash. | 147 url += (kPersistentDir + 1); // We don't want the leading slash. |
| 145 return GURL(url + "/"); | 148 return GURL(url + "/"); |
| 146 case kFileSystemTypeExternal: | 149 case kFileSystemTypeExternal: |
| 147 url += (kExternalDir + 1); // We don't want the leading slash. | 150 url += (kExternalDir + 1); // We don't want the leading slash. |
| 148 return GURL(url + "/"); | 151 return GURL(url + "/"); |
| 152 case kFileSystemTypeTest: |
| 153 url += (kTestDir + 1); // We don't want the leading slash. |
| 154 return GURL(url + "/"); |
| 149 case kFileSystemTypeIsolated: | 155 case kFileSystemTypeIsolated: |
| 150 // Falling through; we won't call this for isolated filesystems. | 156 // Falling through; we won't call this for isolated filesystems. |
| 151 case kFileSystemTypeUnknown: | 157 case kFileSystemTypeUnknown: |
| 152 NOTREACHED(); | 158 NOTREACHED(); |
| 153 } | 159 } |
| 154 NOTREACHED(); | 160 NOTREACHED(); |
| 155 return GURL(); | 161 return GURL(); |
| 156 } | 162 } |
| 157 | 163 |
| 158 std::string GetFileSystemName(const GURL& origin_url, FileSystemType type) { | 164 std::string GetFileSystemName(const GURL& origin_url, FileSystemType type) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 215 } |
| 210 | 216 |
| 211 std::string GetFileSystemTypeString(FileSystemType type) { | 217 std::string GetFileSystemTypeString(FileSystemType type) { |
| 212 switch (type) { | 218 switch (type) { |
| 213 case kFileSystemTypeTemporary: | 219 case kFileSystemTypeTemporary: |
| 214 return fileapi::kTemporaryName; | 220 return fileapi::kTemporaryName; |
| 215 case kFileSystemTypePersistent: | 221 case kFileSystemTypePersistent: |
| 216 return fileapi::kPersistentName; | 222 return fileapi::kPersistentName; |
| 217 case kFileSystemTypeExternal: | 223 case kFileSystemTypeExternal: |
| 218 return fileapi::kExternalName; | 224 return fileapi::kExternalName; |
| 225 case kFileSystemTypeTest: |
| 226 return fileapi::kTestName; |
| 219 case kFileSystemTypeUnknown: | 227 case kFileSystemTypeUnknown: |
| 220 default: | 228 default: |
| 221 return std::string(); | 229 return std::string(); |
| 222 } | 230 } |
| 223 } | 231 } |
| 224 | 232 |
| 225 std::string FilePathToString(const FilePath& file_path) { | 233 std::string FilePathToString(const FilePath& file_path) { |
| 226 #if defined(OS_WIN) | 234 #if defined(OS_WIN) |
| 227 return UTF16ToUTF8(file_path.value()); | 235 return UTF16ToUTF8(file_path.value()); |
| 228 #elif defined(OS_POSIX) | 236 #elif defined(OS_POSIX) |
| 229 return file_path.value(); | 237 return file_path.value(); |
| 230 #endif | 238 #endif |
| 231 } | 239 } |
| 232 | 240 |
| 233 FilePath StringToFilePath(const std::string& file_path_string) { | 241 FilePath StringToFilePath(const std::string& file_path_string) { |
| 234 #if defined(OS_WIN) | 242 #if defined(OS_WIN) |
| 235 return FilePath(UTF8ToUTF16(file_path_string)); | 243 return FilePath(UTF8ToUTF16(file_path_string)); |
| 236 #elif defined(OS_POSIX) | 244 #elif defined(OS_POSIX) |
| 237 return FilePath(file_path_string); | 245 return FilePath(file_path_string); |
| 238 #endif | 246 #endif |
| 239 } | 247 } |
| 240 | 248 |
| 241 } // namespace fileapi | 249 } // namespace fileapi |
| OLD | NEW |