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/tools/test_shell/simple_file_system.h" | 5 #include "webkit/tools/test_shell/simple_file_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
14 #include "net/base/mime_util.h" | 14 #include "net/base/mime_util.h" |
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h" |
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemEntry.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemEntry.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
23 #include "webkit/base/file_path_string_conversions.h" | 23 #include "webkit/base/file_path_string_conversions.h" |
24 #include "webkit/blob/blob_storage_controller.h" | |
25 #include "webkit/fileapi/external_mount_points.h" | 24 #include "webkit/fileapi/external_mount_points.h" |
26 #include "webkit/fileapi/file_permission_policy.h" | 25 #include "webkit/fileapi/file_permission_policy.h" |
27 #include "webkit/fileapi/file_system_mount_point_provider.h" | 26 #include "webkit/fileapi/file_system_mount_point_provider.h" |
28 #include "webkit/fileapi/file_system_task_runners.h" | 27 #include "webkit/fileapi/file_system_task_runners.h" |
29 #include "webkit/fileapi/file_system_url.h" | 28 #include "webkit/fileapi/file_system_url.h" |
30 #include "webkit/fileapi/file_system_util.h" | 29 #include "webkit/fileapi/file_system_util.h" |
31 #include "webkit/fileapi/mock_file_system_options.h" | 30 #include "webkit/fileapi/mock_file_system_options.h" |
32 #include "webkit/tools/test_shell/simple_file_writer.h" | 31 #include "webkit/tools/test_shell/simple_file_writer.h" |
33 | 32 |
34 using base::WeakPtr; | 33 using base::WeakPtr; |
35 | 34 |
36 using WebKit::WebFileInfo; | 35 using WebKit::WebFileInfo; |
37 using WebKit::WebFileSystem; | 36 using WebKit::WebFileSystem; |
38 using WebKit::WebFileSystemCallbacks; | 37 using WebKit::WebFileSystemCallbacks; |
39 using WebKit::WebFileSystemEntry; | 38 using WebKit::WebFileSystemEntry; |
40 using WebKit::WebFileWriter; | 39 using WebKit::WebFileWriter; |
41 using WebKit::WebFileWriterClient; | 40 using WebKit::WebFileWriterClient; |
42 using WebKit::WebFrame; | 41 using WebKit::WebFrame; |
43 using WebKit::WebSecurityOrigin; | 42 using WebKit::WebSecurityOrigin; |
44 using WebKit::WebString; | 43 using WebKit::WebString; |
45 using WebKit::WebURL; | 44 using WebKit::WebURL; |
46 using WebKit::WebVector; | 45 using WebKit::WebVector; |
47 | 46 |
48 using webkit_blob::BlobData; | |
49 using webkit_blob::BlobStorageController; | |
50 using fileapi::FileSystemContext; | 47 using fileapi::FileSystemContext; |
51 using fileapi::FileSystemOperation; | 48 using fileapi::FileSystemOperation; |
52 using fileapi::FileSystemTaskRunners; | 49 using fileapi::FileSystemTaskRunners; |
53 using fileapi::FileSystemURL; | 50 using fileapi::FileSystemURL; |
54 | 51 |
| 52 // DEPRECAED start |
| 53 /* |
55 namespace { | 54 namespace { |
56 MessageLoop* g_io_thread; | 55 MessageLoop* g_io_thread; |
57 webkit_blob::BlobStorageController* g_blob_storage_controller; | 56 webkit_blob::BlobStorageController* g_blob_storage_controller; |
58 | 57 |
59 void RegisterBlob(const GURL& blob_url, const base::FilePath& file_path) { | 58 void RegisterBlob(const GURL& blob_url, const base::FilePath& file_path) { |
60 DCHECK(g_blob_storage_controller); | 59 DCHECK(g_blob_storage_controller); |
61 | 60 |
62 base::FilePath::StringType extension = file_path.Extension(); | 61 base::FilePath::StringType extension = file_path.Extension(); |
63 if (!extension.empty()) | 62 if (!extension.empty()) |
64 extension = extension.substr(1); // Strip leading ".". | 63 extension = extension.substr(1); // Strip leading ".". |
65 | 64 |
66 // This may fail, but then we'll be just setting the empty mime type. | 65 // This may fail, but then we'll be just setting the empty mime type. |
67 std::string mime_type; | 66 std::string mime_type; |
68 net::GetWellKnownMimeTypeFromExtension(extension, &mime_type); | 67 net::GetWellKnownMimeTypeFromExtension(extension, &mime_type); |
69 | 68 |
70 BlobData::Item item; | 69 BlobData::Item item; |
71 item.SetToFilePathRange(file_path, 0, -1, base::Time()); | 70 item.SetToFilePathRange(file_path, 0, -1, base::Time()); |
72 g_blob_storage_controller->StartBuildingBlob(blob_url); | 71 g_blob_storage_controller->StartBuildingBlob(blob_url); |
73 g_blob_storage_controller->AppendBlobDataItem(blob_url, item); | 72 g_blob_storage_controller->AppendBlobDataItem(blob_url, item); |
74 g_blob_storage_controller->FinishBuildingBlob(blob_url, mime_type); | 73 g_blob_storage_controller->FinishBuildingBlob(blob_url, mime_type); |
75 } | 74 } |
76 | |
77 } // namespace | 75 } // namespace |
| 76 */ |
| 77 // DEPRECAED - end |
78 | 78 |
79 SimpleFileSystem::SimpleFileSystem() { | 79 SimpleFileSystem::SimpleFileSystem() { |
80 if (file_system_dir_.CreateUniqueTempDir()) { | 80 if (file_system_dir_.CreateUniqueTempDir()) { |
81 file_system_context_ = new FileSystemContext( | 81 file_system_context_ = new FileSystemContext( |
82 FileSystemTaskRunners::CreateMockTaskRunners(), | 82 FileSystemTaskRunners::CreateMockTaskRunners(), |
83 fileapi::ExternalMountPoints::CreateRefCounted().get(), | 83 fileapi::ExternalMountPoints::CreateRefCounted().get(), |
84 NULL /* special storage policy */, | 84 NULL /* special storage policy */, |
85 NULL /* quota manager */, | 85 NULL /* quota manager */, |
86 file_system_dir_.path(), | 86 file_system_dir_.path(), |
87 fileapi::CreateAllowFileAccessOptions()); | 87 fileapi::CreateAllowFileAccessOptions()); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 WebFileSystemCallbacks* callbacks) { | 259 WebFileSystemCallbacks* callbacks) { |
260 FileSystemURL url(file_system_context()->CrackURL(path)); | 260 FileSystemURL url(file_system_context()->CrackURL(path)); |
261 if (!HasFilePermission(url, fileapi::kReadFilePermissions)) { | 261 if (!HasFilePermission(url, fileapi::kReadFilePermissions)) { |
262 callbacks->didFail(WebKit::WebFileErrorSecurity); | 262 callbacks->didFail(WebKit::WebFileErrorSecurity); |
263 return; | 263 return; |
264 } | 264 } |
265 GetNewOperation(url)->CreateSnapshotFile( | 265 GetNewOperation(url)->CreateSnapshotFile( |
266 url, SnapshotFileHandler_Deprecated(blobURL, callbacks)); | 266 url, SnapshotFileHandler_Deprecated(blobURL, callbacks)); |
267 } | 267 } |
268 | 268 |
| 269 /* |
| 270 // DEPRECATED - start |
269 // static | 271 // static |
270 void SimpleFileSystem::InitializeOnIOThread( | 272 void SimpleFileSystem::InitializeOnIOThread( |
271 webkit_blob::BlobStorageController* blob_storage_controller) { | 273 webkit_blob::BlobStorageController* blob_storage_controller) { |
272 g_io_thread = MessageLoop::current(); | 274 g_io_thread = MessageLoop::current(); |
273 g_blob_storage_controller = blob_storage_controller; | 275 g_blob_storage_controller = blob_storage_controller; |
274 } | 276 } |
275 | 277 |
276 // static | 278 // static |
277 void SimpleFileSystem::CleanupOnIOThread() { | 279 void SimpleFileSystem::CleanupOnIOThread() { |
278 g_io_thread = NULL; | 280 g_io_thread = NULL; |
279 g_blob_storage_controller = NULL; | 281 g_blob_storage_controller = NULL; |
280 } | 282 } |
| 283 // DEPRECATED - end |
| 284 */ |
281 | 285 |
282 bool SimpleFileSystem::HasFilePermission( | 286 bool SimpleFileSystem::HasFilePermission( |
283 const fileapi::FileSystemURL& url, int permissions) { | 287 const fileapi::FileSystemURL& url, int permissions) { |
284 if (!url.is_valid()) | 288 if (!url.is_valid()) |
285 return false; | 289 return false; |
286 fileapi::FileSystemMountPointProvider* mount_point_provider = | 290 fileapi::FileSystemMountPointProvider* mount_point_provider = |
287 file_system_context_->GetMountPointProvider(url.type()); | 291 file_system_context_->GetMountPointProvider(url.type()); |
288 DCHECK(mount_point_provider); | 292 DCHECK(mount_point_provider); |
289 // In test_shell we don't perform further detailed security checks if it's | 293 // In test_shell we don't perform further detailed security checks if it's |
290 // not specifically forbidden by ALWAYS_DENY. | 294 // not specifically forbidden by ALWAYS_DENY. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 web_file_info.type = info.is_directory ? | 429 web_file_info.type = info.is_directory ? |
426 WebFileInfo::TypeDirectory : WebFileInfo::TypeFile; | 430 WebFileInfo::TypeDirectory : WebFileInfo::TypeFile; |
427 web_file_info.platformPath = | 431 web_file_info.platformPath = |
428 webkit_base::FilePathToWebString(platform_path); | 432 webkit_base::FilePathToWebString(platform_path); |
429 callbacks->didCreateSnapshotFile(web_file_info); | 433 callbacks->didCreateSnapshotFile(web_file_info); |
430 } else { | 434 } else { |
431 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); | 435 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); |
432 } | 436 } |
433 } | 437 } |
434 | 438 |
| 439 /* |
435 void SimpleFileSystem::DidCreateSnapshotFile_Deprecated( | 440 void SimpleFileSystem::DidCreateSnapshotFile_Deprecated( |
436 const GURL& blob_url, | 441 const GURL& blob_url, |
437 WebFileSystemCallbacks* callbacks, | 442 WebFileSystemCallbacks* callbacks, |
438 base::PlatformFileError result, | 443 base::PlatformFileError result, |
439 const base::PlatformFileInfo& info, | 444 const base::PlatformFileInfo& info, |
440 const base::FilePath& platform_path, | 445 const base::FilePath& platform_path, |
441 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 446 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
442 DCHECK(g_io_thread); | 447 DCHECK(g_io_thread); |
443 if (result == base::PLATFORM_FILE_OK) { | 448 if (result == base::PLATFORM_FILE_OK) { |
444 g_io_thread->PostTask( | 449 g_io_thread->PostTask( |
445 FROM_HERE, | 450 FROM_HERE, |
446 base::Bind(&RegisterBlob, blob_url, platform_path)); | 451 base::Bind(&RegisterBlob, blob_url, platform_path)); |
447 } | 452 } |
448 DidGetMetadata(callbacks, result, info, platform_path); | 453 DidGetMetadata(callbacks, result, info, platform_path); |
449 } | 454 } |
| 455 */ |
| 456 |
OLD | NEW |