OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_path_manager.h" | 5 #include "webkit/fileapi/file_system_path_manager.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 FilePath::StringType CreateUniqueDirectoryName(const GURL& origin_url) { | 68 FilePath::StringType CreateUniqueDirectoryName(const GURL& origin_url) { |
69 // This can be anything but need to be unpredictable. | 69 // This can be anything but need to be unpredictable. |
70 static const FilePath::CharType letters[] = FILE_PATH_LITERAL( | 70 static const FilePath::CharType letters[] = FILE_PATH_LITERAL( |
71 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); | 71 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); |
72 FilePath::StringType unique(kFileSystemUniqueNamePrefix); | 72 FilePath::StringType unique(kFileSystemUniqueNamePrefix); |
73 for (int i = 0; i < kFileSystemUniqueLength; ++i) | 73 for (int i = 0; i < kFileSystemUniqueLength; ++i) |
74 unique += letters[base::RandInt(0, arraysize(letters) - 2)]; | 74 unique += letters[base::RandInt(0, arraysize(letters) - 2)]; |
75 return unique; | 75 return unique; |
76 } | 76 } |
77 | 77 |
| 78 static const char kExtensionScheme[] = "chrome-extension"; |
| 79 |
78 } // anonymous namespace | 80 } // anonymous namespace |
79 | 81 |
80 class FileSystemPathManager::GetFileSystemRootPathTask | 82 class FileSystemPathManager::GetFileSystemRootPathTask |
81 : public base::RefCountedThreadSafe< | 83 : public base::RefCountedThreadSafe< |
82 FileSystemPathManager::GetFileSystemRootPathTask> { | 84 FileSystemPathManager::GetFileSystemRootPathTask> { |
83 public: | 85 public: |
84 GetFileSystemRootPathTask( | 86 GetFileSystemRootPathTask( |
85 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 87 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
86 const std::string& name, | 88 const std::string& name, |
87 FileSystemPathManager::GetRootPathCallback* callback) | 89 FileSystemPathManager::GetRootPathCallback* callback) |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 return true; | 315 return true; |
314 } | 316 } |
315 | 317 |
316 return false; | 318 return false; |
317 } | 319 } |
318 | 320 |
319 bool FileSystemPathManager::IsAllowedScheme(const GURL& url) const { | 321 bool FileSystemPathManager::IsAllowedScheme(const GURL& url) const { |
320 // Basically we only accept http or https. We allow file:// URLs | 322 // Basically we only accept http or https. We allow file:// URLs |
321 // only if --allow-file-access-from-files flag is given. | 323 // only if --allow-file-access-from-files flag is given. |
322 return url.SchemeIs("http") || url.SchemeIs("https") || | 324 return url.SchemeIs("http") || url.SchemeIs("https") || |
| 325 url.SchemeIs(kExtensionScheme) || |
323 (url.SchemeIsFile() && allow_file_access_from_files_); | 326 (url.SchemeIsFile() && allow_file_access_from_files_); |
324 } | 327 } |
325 | 328 |
326 std::string FileSystemPathManager::GetStorageIdentifierFromURL( | 329 std::string FileSystemPathManager::GetStorageIdentifierFromURL( |
327 const GURL& url) { | 330 const GURL& url) { |
328 WebKit::WebSecurityOrigin web_security_origin = | 331 WebKit::WebSecurityOrigin web_security_origin = |
329 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); | 332 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); |
330 return web_security_origin.databaseIdentifier().utf8(); | 333 return web_security_origin.databaseIdentifier().utf8(); |
331 } | 334 } |
332 | 335 |
333 } // namespace fileapi | 336 } // namespace fileapi |
334 | 337 |
335 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ | 338 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ |
336 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); | 339 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); |
337 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ | 340 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ |
338 int(fileapi::kFileSystemTypePersistent), mismatching_enums); | 341 int(fileapi::kFileSystemTypePersistent), mismatching_enums); |
OLD | NEW |