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/sandbox_mount_point_provider.h" | 5 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_callback_factory.h" | 10 #include "base/memory/scoped_callback_factory.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
20 #include "webkit/fileapi/file_system_operation_context.h" | 20 #include "webkit/fileapi/file_system_operation_context.h" |
21 #include "webkit/fileapi/file_system_path_manager.h" | 21 #include "webkit/fileapi/file_system_options.h" |
22 #include "webkit/fileapi/file_system_types.h" | 22 #include "webkit/fileapi/file_system_types.h" |
23 #include "webkit/fileapi/file_system_usage_cache.h" | 23 #include "webkit/fileapi/file_system_usage_cache.h" |
24 #include "webkit/fileapi/file_system_util.h" | 24 #include "webkit/fileapi/file_system_util.h" |
25 #include "webkit/fileapi/obfuscated_file_util.h" | 25 #include "webkit/fileapi/obfuscated_file_util.h" |
26 #include "webkit/fileapi/quota_file_util.h" | 26 #include "webkit/fileapi/quota_file_util.h" |
27 #include "webkit/glue/webkit_glue.h" | 27 #include "webkit/glue/webkit_glue.h" |
28 #include "webkit/quota/quota_manager.h" | 28 #include "webkit/quota/quota_manager.h" |
29 | 29 |
30 using quota::QuotaManagerProxy; | 30 using quota::QuotaManagerProxy; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 static const FilePath::CharType kOldFileSystemUniqueNamePrefix[] = | 34 const char kChromeScheme[] = "chrome"; |
35 const char kExtensionScheme[] = "chrome-extension"; | |
36 | |
37 const FilePath::CharType kOldFileSystemUniqueNamePrefix[] = | |
35 FILE_PATH_LITERAL("chrome-"); | 38 FILE_PATH_LITERAL("chrome-"); |
36 static const int kOldFileSystemUniqueLength = 16; | 39 const int kOldFileSystemUniqueLength = 16; |
37 static const unsigned kOldFileSystemUniqueDirectoryNameLength = | 40 const unsigned kOldFileSystemUniqueDirectoryNameLength = |
38 kOldFileSystemUniqueLength + arraysize(kOldFileSystemUniqueNamePrefix) - 1; | 41 kOldFileSystemUniqueLength + arraysize(kOldFileSystemUniqueNamePrefix) - 1; |
tzik
2011/12/21 02:52:33
size_t?
kinuko
2011/12/21 13:00:50
Done.
| |
39 | 42 |
40 const char kOpenFileSystem[] = "FileSystem.OpenFileSystem"; | 43 const char kOpenFileSystem[] = "FileSystem.OpenFileSystem"; |
41 enum FileSystemError { | 44 enum FileSystemError { |
42 kOK = 0, | 45 kOK = 0, |
43 kIncognito, | 46 kIncognito, |
44 kInvalidScheme, | 47 kInvalidScheme, |
45 kCreateDirectoryError, | 48 kCreateDirectoryError, |
46 kFileSystemErrorMax, | 49 kFileSystemErrorMax, |
47 }; | 50 }; |
48 | 51 |
49 // Restricted names. | 52 // Restricted names. |
50 // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions | 53 // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions |
51 static const char* const kRestrictedNames[] = { | 54 const char* const kRestrictedNames[] = { |
52 ".", "..", | 55 ".", "..", |
53 }; | 56 }; |
54 | 57 |
55 // Restricted chars. | 58 // Restricted chars. |
56 static const FilePath::CharType kRestrictedChars[] = { | 59 const FilePath::CharType kRestrictedChars[] = { |
57 '/', '\\', | 60 '/', '\\', |
tzik
2011/12/21 02:52:33
FILE_PATH_LITERAL?
kinuko
2011/12/21 13:00:50
Done.
| |
58 }; | 61 }; |
59 | 62 |
60 inline std::string FilePathStringToASCII( | |
61 const FilePath::StringType& path_string) { | |
62 #if defined(OS_WIN) | |
63 return WideToASCII(path_string); | |
64 #elif defined(OS_POSIX) | |
65 return path_string; | |
66 #endif | |
67 } | |
68 | |
69 FilePath::StringType OldCreateUniqueDirectoryName(const GURL& origin_url) { | 63 FilePath::StringType OldCreateUniqueDirectoryName(const GURL& origin_url) { |
70 // This can be anything but need to be unpredictable. | 64 // This can be anything but need to be unpredictable. |
71 static const FilePath::CharType letters[] = FILE_PATH_LITERAL( | 65 static const FilePath::CharType letters[] = FILE_PATH_LITERAL( |
72 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); | 66 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); |
73 FilePath::StringType unique(kOldFileSystemUniqueNamePrefix); | 67 FilePath::StringType unique(kOldFileSystemUniqueNamePrefix); |
74 for (int i = 0; i < kOldFileSystemUniqueLength; ++i) | 68 for (int i = 0; i < kOldFileSystemUniqueLength; ++i) |
75 unique += letters[base::RandInt(0, arraysize(letters) - 2)]; | 69 unique += letters[base::RandInt(0, arraysize(letters) - 2)]; |
76 return unique; | 70 return unique; |
77 } | 71 } |
78 | 72 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 explicit OldSandboxOriginEnumerator(const FilePath& base_path) | 123 explicit OldSandboxOriginEnumerator(const FilePath& base_path) |
130 : enumerator_(base_path, false /* recursive */, | 124 : enumerator_(base_path, false /* recursive */, |
131 file_util::FileEnumerator::DIRECTORIES) {} | 125 file_util::FileEnumerator::DIRECTORIES) {} |
132 virtual ~OldSandboxOriginEnumerator() {} | 126 virtual ~OldSandboxOriginEnumerator() {} |
133 | 127 |
134 virtual GURL Next() OVERRIDE { | 128 virtual GURL Next() OVERRIDE { |
135 current_ = enumerator_.Next(); | 129 current_ = enumerator_.Next(); |
136 if (current_.empty()) | 130 if (current_.empty()) |
137 return GURL(); | 131 return GURL(); |
138 return fileapi::GetOriginURLFromIdentifier( | 132 return fileapi::GetOriginURLFromIdentifier( |
139 FilePathStringToASCII(current_.BaseName().value())); | 133 current_.BaseName().MaybeAsASCII()); |
140 } | 134 } |
141 | 135 |
142 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { | 136 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { |
143 if (current_.empty()) | 137 if (current_.empty()) |
144 return false; | 138 return false; |
145 std::string directory = | 139 std::string directory = GetFileSystemTypeString(type); |
146 fileapi::FileSystemPathManager::GetFileSystemTypeString(type); | |
147 DCHECK(!directory.empty()); | 140 DCHECK(!directory.empty()); |
148 return file_util::DirectoryExists(current_.AppendASCII(directory)); | 141 return file_util::DirectoryExists(current_.AppendASCII(directory)); |
149 } | 142 } |
150 | 143 |
151 private: | 144 private: |
152 file_util::FileEnumerator enumerator_; | 145 file_util::FileEnumerator enumerator_; |
153 FilePath current_; | 146 FilePath current_; |
154 }; | 147 }; |
155 | 148 |
156 FilePath OldGetBaseDirectoryForOrigin( | 149 FilePath OldGetBaseDirectoryForOrigin( |
157 const FilePath& old_base_path, | 150 const FilePath& old_base_path, |
158 const GURL& origin_url) { | 151 const GURL& origin_url) { |
159 std::string id = fileapi::GetOriginIdentifierFromURL(origin_url); | 152 std::string id = fileapi::GetOriginIdentifierFromURL(origin_url); |
160 if (!id.empty()) | 153 if (!id.empty()) |
161 return old_base_path.AppendASCII(id); | 154 return old_base_path.AppendASCII(id); |
162 return FilePath(); | 155 return FilePath(); |
163 } | 156 } |
164 | 157 |
165 FilePath OldGetBaseDirectoryForOriginAndType( | 158 FilePath OldGetBaseDirectoryForOriginAndType( |
166 const FilePath& old_base_path, | 159 const FilePath& old_base_path, |
167 const GURL& origin_url, fileapi::FileSystemType type) { | 160 const GURL& origin_url, fileapi::FileSystemType type) { |
168 std::string type_string = | 161 std::string type_string = GetFileSystemTypeString(type); |
169 fileapi::FileSystemPathManager::GetFileSystemTypeString(type); | |
170 if (type_string.empty()) { | 162 if (type_string.empty()) { |
171 NOTREACHED(); | 163 NOTREACHED(); |
172 return FilePath(); | 164 return FilePath(); |
173 } | 165 } |
174 FilePath base_path = OldGetBaseDirectoryForOrigin( | 166 FilePath base_path = OldGetBaseDirectoryForOrigin( |
175 old_base_path, origin_url); | 167 old_base_path, origin_url); |
176 if (base_path.empty()) { | 168 if (base_path.empty()) { |
177 NOTREACHED(); | 169 NOTREACHED(); |
178 return FilePath(); | 170 return FilePath(); |
179 } | 171 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 const FilePath::CharType SandboxMountPointProvider::kOldFileSystemDirectory[] = | 264 const FilePath::CharType SandboxMountPointProvider::kOldFileSystemDirectory[] = |
273 FILE_PATH_LITERAL("FileSystem"); | 265 FILE_PATH_LITERAL("FileSystem"); |
274 | 266 |
275 const FilePath::CharType SandboxMountPointProvider::kNewFileSystemDirectory[] = | 267 const FilePath::CharType SandboxMountPointProvider::kNewFileSystemDirectory[] = |
276 FILE_PATH_LITERAL("File System"); | 268 FILE_PATH_LITERAL("File System"); |
277 | 269 |
278 const FilePath::CharType | 270 const FilePath::CharType |
279 SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = | 271 SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = |
280 FILE_PATH_LITERAL("FS.old"); | 272 FILE_PATH_LITERAL("FS.old"); |
281 | 273 |
282 SandboxMountPointProvider::SandboxMountPointProvider( | |
283 FileSystemPathManager* path_manager, | |
284 scoped_refptr<base::MessageLoopProxy> file_message_loop, | |
285 const FilePath& profile_path) | |
286 : FileSystemQuotaUtil(file_message_loop), | |
287 path_manager_(path_manager), | |
288 file_message_loop_(file_message_loop), | |
289 profile_path_(profile_path), | |
290 sandbox_file_util_( | |
291 new ObfuscatedFileUtil( | |
292 profile_path.Append(kNewFileSystemDirectory), | |
293 QuotaFileUtil::CreateDefault())) { | |
294 } | |
295 | |
296 SandboxMountPointProvider::~SandboxMountPointProvider() { | |
297 if (!file_message_loop_->BelongsToCurrentThread()) | |
298 file_message_loop_->ReleaseSoon(FROM_HERE, sandbox_file_util_.release()); | |
299 } | |
300 | |
301 bool SandboxMountPointProvider::IsAccessAllowed(const GURL& origin_url, | |
302 FileSystemType type, | |
303 const FilePath& unused) { | |
304 if (type != kFileSystemTypeTemporary && type != kFileSystemTypePersistent) | |
305 return false; | |
306 // We essentially depend on quota to do our access controls. | |
307 return path_manager_->IsAllowedScheme(origin_url); | |
308 } | |
309 | |
310 class SandboxMountPointProvider::GetFileSystemRootPathTask | 274 class SandboxMountPointProvider::GetFileSystemRootPathTask |
311 : public base::RefCountedThreadSafe< | 275 : public base::RefCountedThreadSafe< |
312 SandboxMountPointProvider::GetFileSystemRootPathTask> { | 276 SandboxMountPointProvider::GetFileSystemRootPathTask> { |
313 public: | 277 public: |
314 GetFileSystemRootPathTask( | 278 GetFileSystemRootPathTask( |
315 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 279 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
316 const GURL& origin_url, | 280 const GURL& origin_url, |
317 FileSystemType type, | 281 FileSystemType type, |
318 ObfuscatedFileUtil* file_util, | 282 ObfuscatedFileUtil* file_util, |
319 const FilePath& old_base_path, | 283 const FilePath& old_base_path, |
320 const FileSystemPathManager::GetRootPathCallback& callback) | 284 const FileSystemMountPointProvider::GetRootPathCallback& callback) |
321 : file_message_loop_(file_message_loop), | 285 : file_message_loop_(file_message_loop), |
322 origin_message_loop_proxy_( | 286 origin_message_loop_proxy_( |
323 base::MessageLoopProxy::current()), | 287 base::MessageLoopProxy::current()), |
324 origin_url_(origin_url), | 288 origin_url_(origin_url), |
325 type_(type), | 289 type_(type), |
326 file_util_(file_util), | 290 file_util_(file_util), |
327 old_base_path_(old_base_path), | 291 old_base_path_(old_base_path), |
328 callback_(callback) { | 292 callback_(callback) { |
329 } | 293 } |
330 | 294 |
(...skipping 28 matching lines...) Expand all Loading... | |
359 kFileSystemErrorMax); | 323 kFileSystemErrorMax); |
360 } | 324 } |
361 origin_message_loop_proxy_->PostTask( | 325 origin_message_loop_proxy_->PostTask( |
362 FROM_HERE, | 326 FROM_HERE, |
363 base::Bind(&GetFileSystemRootPathTask::DispatchCallback, this, | 327 base::Bind(&GetFileSystemRootPathTask::DispatchCallback, this, |
364 root_path)); | 328 root_path)); |
365 } | 329 } |
366 | 330 |
367 void DispatchCallback(const FilePath& root_path) { | 331 void DispatchCallback(const FilePath& root_path) { |
368 std::string origin_identifier = GetOriginIdentifierFromURL(origin_url_); | 332 std::string origin_identifier = GetOriginIdentifierFromURL(origin_url_); |
369 std::string type_string = | 333 std::string type_string = GetFileSystemTypeString(type_); |
370 FileSystemPathManager::GetFileSystemTypeString(type_); | |
371 DCHECK(!type_string.empty()); | 334 DCHECK(!type_string.empty()); |
372 std::string name = origin_identifier + ":" + type_string; | 335 std::string name = origin_identifier + ":" + type_string; |
373 | 336 |
374 if (!root_path.empty()) | 337 if (!root_path.empty()) |
375 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, kOK, kFileSystemErrorMax); | 338 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, kOK, kFileSystemErrorMax); |
376 | 339 |
377 callback_.Run(!root_path.empty(), root_path, name); | 340 callback_.Run(!root_path.empty(), root_path, name); |
378 callback_.Reset(); | 341 callback_.Reset(); |
379 } | 342 } |
380 | 343 |
381 scoped_refptr<base::MessageLoopProxy> file_message_loop_; | 344 scoped_refptr<base::MessageLoopProxy> file_message_loop_; |
382 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; | 345 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
383 GURL origin_url_; | 346 GURL origin_url_; |
384 FileSystemType type_; | 347 FileSystemType type_; |
385 scoped_refptr<ObfuscatedFileUtil> file_util_; | 348 scoped_refptr<ObfuscatedFileUtil> file_util_; |
386 FilePath old_base_path_; | 349 FilePath old_base_path_; |
387 FileSystemPathManager::GetRootPathCallback callback_; | 350 FileSystemMountPointProvider::GetRootPathCallback callback_; |
388 }; | 351 }; |
389 | 352 |
390 FilePath SandboxMountPointProvider::old_base_path() const { | 353 SandboxMountPointProvider::SandboxMountPointProvider( |
391 return profile_path_.Append(kOldFileSystemDirectory); | 354 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
355 const FilePath& profile_path, | |
356 FileSystemOptions* file_system_options) | |
357 : FileSystemQuotaUtil(file_message_loop), | |
358 file_message_loop_(file_message_loop), | |
359 profile_path_(profile_path), | |
360 file_system_options_(file_system_options), | |
361 sandbox_file_util_( | |
362 new ObfuscatedFileUtil( | |
363 profile_path.Append(kNewFileSystemDirectory), | |
364 QuotaFileUtil::CreateDefault())) { | |
365 DCHECK(file_system_options); | |
392 } | 366 } |
393 | 367 |
394 FilePath SandboxMountPointProvider::new_base_path() const { | 368 SandboxMountPointProvider::~SandboxMountPointProvider() { |
395 return profile_path_.Append(kNewFileSystemDirectory); | 369 if (!file_message_loop_->BelongsToCurrentThread()) |
370 file_message_loop_->ReleaseSoon(FROM_HERE, sandbox_file_util_.release()); | |
396 } | 371 } |
397 | 372 |
398 FilePath SandboxMountPointProvider::renamed_old_base_path() const { | 373 bool SandboxMountPointProvider::IsAccessAllowed(const GURL& origin_url, |
399 return profile_path_.Append(kRenamedOldFileSystemDirectory); | 374 FileSystemType type, |
400 } | 375 const FilePath& unused) { |
401 | 376 if (type != kFileSystemTypeTemporary && type != kFileSystemTypePersistent) |
402 bool SandboxMountPointProvider::IsRestrictedFileName(const FilePath& filename) | |
403 const { | |
404 if (filename.value().empty()) | |
405 return false; | 377 return false; |
406 | 378 // We essentially depend on quota to do our access controls, so here |
407 std::string filename_lower = StringToLowerASCII( | 379 // we only check if the requested scheme is allowed or not. |
408 FilePathStringToASCII(filename.value())); | 380 return IsAllowedScheme(origin_url); |
409 | |
410 for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) { | |
411 // Exact match. | |
412 if (filename_lower == kRestrictedNames[i]) | |
413 return true; | |
414 } | |
415 | |
416 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { | |
417 if (filename.value().find(kRestrictedChars[i]) != | |
418 FilePath::StringType::npos) | |
419 return true; | |
420 } | |
421 | |
422 return false; | |
423 } | |
424 | |
425 std::vector<FilePath> SandboxMountPointProvider::GetRootDirectories() const { | |
426 NOTREACHED(); | |
427 // TODO(ericu): Implement this method and check for access permissions as | |
428 // fileBrowserPrivate extension API does. We currently have another mechanism, | |
429 // but we should switch over. This may also need to call MigrateIfNeeded(). | |
430 return std::vector<FilePath>(); | |
431 } | |
432 | |
433 SandboxMountPointProvider::OriginEnumerator* | |
434 SandboxMountPointProvider::CreateOriginEnumerator() const { | |
435 MigrateIfNeeded(sandbox_file_util_, old_base_path()); | |
436 return new ObfuscatedOriginEnumerator(sandbox_file_util_.get()); | |
437 } | 381 } |
438 | 382 |
439 void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( | 383 void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( |
440 const GURL& origin_url, fileapi::FileSystemType type, bool create, | 384 const GURL& origin_url, fileapi::FileSystemType type, bool create, |
441 const FileSystemPathManager::GetRootPathCallback& callback) { | 385 const FileSystemMountPointProvider::GetRootPathCallback& callback) { |
442 FilePath origin_base_path; | 386 FilePath origin_base_path; |
443 | 387 |
444 if (path_manager_->is_incognito()) { | 388 if (file_system_options_->is_incognito()) { |
445 // TODO(kinuko): return an isolated temporary directory. | 389 // TODO(kinuko): return an isolated temporary directory. |
446 callback.Run(false, FilePath(), std::string()); | 390 callback.Run(false, FilePath(), std::string()); |
447 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, | 391 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, |
448 kIncognito, | 392 kIncognito, |
449 kFileSystemErrorMax); | 393 kFileSystemErrorMax); |
450 return; | 394 return; |
451 } | 395 } |
452 | 396 |
453 if (!path_manager_->IsAllowedScheme(origin_url)) { | 397 if (!IsAllowedScheme(origin_url)) { |
454 callback.Run(false, FilePath(), std::string()); | 398 callback.Run(false, FilePath(), std::string()); |
455 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, | 399 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, |
456 kInvalidScheme, | 400 kInvalidScheme, |
457 kFileSystemErrorMax); | 401 kFileSystemErrorMax); |
458 return; | 402 return; |
459 } | 403 } |
460 | 404 |
461 scoped_refptr<GetFileSystemRootPathTask> task( | 405 scoped_refptr<GetFileSystemRootPathTask> task( |
462 new GetFileSystemRootPathTask( | 406 new GetFileSystemRootPathTask( |
463 file_message_loop_, origin_url, type, sandbox_file_util_.get(), | 407 file_message_loop_, origin_url, type, sandbox_file_util_.get(), |
464 old_base_path(), callback)); | 408 old_base_path(), callback)); |
465 task->Start(create); | 409 task->Start(create); |
466 }; | 410 }; |
467 | 411 |
468 FilePath | 412 FilePath |
469 SandboxMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread( | 413 SandboxMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread( |
470 const GURL& origin_url, FileSystemType type, const FilePath& unused, | 414 const GURL& origin_url, FileSystemType type, const FilePath& unused, |
471 bool create) { | 415 bool create) { |
472 if (path_manager_->is_incognito()) | 416 if (file_system_options_->is_incognito()) |
473 // TODO(kinuko): return an isolated temporary directory. | 417 // TODO(kinuko): return an isolated temporary directory. |
474 return FilePath(); | 418 return FilePath(); |
475 | 419 |
476 if (!path_manager_->IsAllowedScheme(origin_url)) | 420 if (!IsAllowedScheme(origin_url)) |
477 return FilePath(); | 421 return FilePath(); |
478 | 422 |
479 MigrateIfNeeded(sandbox_file_util_, old_base_path()); | 423 MigrateIfNeeded(sandbox_file_util_, old_base_path()); |
480 | 424 |
481 return sandbox_file_util_->GetDirectoryForOriginAndType( | 425 return sandbox_file_util_->GetDirectoryForOriginAndType( |
482 origin_url, type, create); | 426 origin_url, type, create); |
483 } | 427 } |
484 | 428 |
429 bool SandboxMountPointProvider::IsRestrictedFileName(const FilePath& filename) | |
430 const { | |
431 if (filename.value().empty()) | |
432 return false; | |
433 | |
434 std::string filename_lower = StringToLowerASCII(filename.MaybeAsASCII()); | |
tzik
2011/12/21 02:52:33
MaybeAsASCII will return empty string if filename
kinuko
2011/12/21 13:00:50
Good catch. Changed the code to use FilePath::Cha
| |
435 | |
436 for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) { | |
437 // Exact match. | |
438 if (filename_lower == kRestrictedNames[i]) | |
439 return true; | |
440 } | |
441 | |
442 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { | |
443 if (filename.value().find(kRestrictedChars[i]) != | |
444 FilePath::StringType::npos) | |
445 return true; | |
446 } | |
447 | |
448 return false; | |
449 } | |
450 | |
451 std::vector<FilePath> SandboxMountPointProvider::GetRootDirectories() const { | |
452 NOTREACHED(); | |
453 // TODO(ericu): Implement this method and check for access permissions as | |
454 // fileBrowserPrivate extension API does. We currently have another mechanism, | |
455 // but we should switch over. This may also need to call MigrateIfNeeded(). | |
456 return std::vector<FilePath>(); | |
457 } | |
458 | |
459 FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil() { | |
460 return sandbox_file_util_.get(); | |
461 } | |
462 | |
463 FilePath SandboxMountPointProvider::old_base_path() const { | |
464 return profile_path_.Append(kOldFileSystemDirectory); | |
465 } | |
466 | |
467 FilePath SandboxMountPointProvider::new_base_path() const { | |
468 return profile_path_.Append(kNewFileSystemDirectory); | |
469 } | |
470 | |
471 FilePath SandboxMountPointProvider::renamed_old_base_path() const { | |
472 return profile_path_.Append(kRenamedOldFileSystemDirectory); | |
473 } | |
474 | |
475 SandboxMountPointProvider::OriginEnumerator* | |
476 SandboxMountPointProvider::CreateOriginEnumerator() const { | |
477 MigrateIfNeeded(sandbox_file_util_, old_base_path()); | |
478 return new ObfuscatedOriginEnumerator(sandbox_file_util_.get()); | |
479 } | |
480 | |
485 FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType( | 481 FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType( |
486 const GURL& origin_url, fileapi::FileSystemType type, bool create) const { | 482 const GURL& origin_url, fileapi::FileSystemType type, bool create) const { |
487 | 483 |
488 MigrateIfNeeded(sandbox_file_util_, old_base_path()); | 484 MigrateIfNeeded(sandbox_file_util_, old_base_path()); |
489 | 485 |
490 return sandbox_file_util_->GetDirectoryForOriginAndType( | 486 return sandbox_file_util_->GetDirectoryForOriginAndType( |
491 origin_url, type, create); | 487 origin_url, type, create); |
492 } | 488 } |
493 | 489 |
494 bool SandboxMountPointProvider::DeleteOriginDataOnFileThread( | 490 bool SandboxMountPointProvider::DeleteOriginDataOnFileThread( |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 | 629 |
634 void SandboxMountPointProvider::InvalidateUsageCache( | 630 void SandboxMountPointProvider::InvalidateUsageCache( |
635 const GURL& origin_url, fileapi::FileSystemType type) { | 631 const GURL& origin_url, fileapi::FileSystemType type) { |
636 DCHECK(type == fileapi::kFileSystemTypeTemporary || | 632 DCHECK(type == fileapi::kFileSystemTypeTemporary || |
637 type == fileapi::kFileSystemTypePersistent); | 633 type == fileapi::kFileSystemTypePersistent); |
638 FilePath usage_file_path = GetUsageCachePathForOriginAndType( | 634 FilePath usage_file_path = GetUsageCachePathForOriginAndType( |
639 origin_url, type); | 635 origin_url, type); |
640 FileSystemUsageCache::IncrementDirty(usage_file_path); | 636 FileSystemUsageCache::IncrementDirty(usage_file_path); |
641 } | 637 } |
642 | 638 |
643 FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil() { | |
644 return sandbox_file_util_.get(); | |
645 } | |
646 | |
647 FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( | 639 FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( |
648 const GURL& origin_url, fileapi::FileSystemType type) const { | 640 const GURL& origin_url, fileapi::FileSystemType type) const { |
649 FilePath base_path = | 641 FilePath base_path = |
650 GetBaseDirectoryForOriginAndType(origin_url, type, false); | 642 GetBaseDirectoryForOriginAndType(origin_url, type, false); |
651 if (base_path.empty()) | 643 if (base_path.empty()) |
652 return FilePath(); | 644 return FilePath(); |
653 return base_path.AppendASCII(FileSystemUsageCache::kUsageFileName); | 645 return base_path.AppendASCII(FileSystemUsageCache::kUsageFileName); |
654 } | 646 } |
655 | 647 |
656 FilePath SandboxMountPointProvider::OldCreateFileSystemRootPath( | 648 FilePath SandboxMountPointProvider::OldCreateFileSystemRootPath( |
(...skipping 14 matching lines...) Expand all Loading... | |
671 return FilePath(); | 663 return FilePath(); |
672 | 664 |
673 // Creates the root directory. | 665 // Creates the root directory. |
674 root = origin_base_path.Append(OldCreateUniqueDirectoryName(origin_url)); | 666 root = origin_base_path.Append(OldCreateUniqueDirectoryName(origin_url)); |
675 if (!file_util::CreateDirectory(root)) | 667 if (!file_util::CreateDirectory(root)) |
676 return FilePath(); | 668 return FilePath(); |
677 | 669 |
678 return root; | 670 return root; |
679 } | 671 } |
680 | 672 |
673 bool SandboxMountPointProvider::IsAllowedScheme(const GURL& url) const { | |
674 // Basically we only accept http or https. We allow file:// URLs | |
675 // only if --allow-file-access-from-files flag is given. | |
676 return url.SchemeIs("http") || url.SchemeIs("https") || | |
677 url.SchemeIs(kExtensionScheme) || url.SchemeIs(kChromeScheme) || | |
678 (url.SchemeIsFile() && | |
679 file_system_options_->allow_file_access_from_files()); | |
680 } | |
681 | |
681 } // namespace fileapi | 682 } // namespace fileapi |
OLD | NEW |