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/file_path.h" | 8 #include "base/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" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 // Unknown type filesystem is requested. | 111 // Unknown type filesystem is requested. |
112 callbacks->didFail(WebKit::WebFileErrorSecurity); | 112 callbacks->didFail(WebKit::WebFileErrorSecurity); |
113 return; | 113 return; |
114 } | 114 } |
115 | 115 |
116 GURL origin_url(frame->document().securityOrigin().toString()); | 116 GURL origin_url(frame->document().securityOrigin().toString()); |
117 file_system_context_->OpenFileSystem( | 117 file_system_context_->OpenFileSystem( |
118 origin_url, type, create, OpenFileSystemHandler(callbacks)); | 118 origin_url, type, create, OpenFileSystemHandler(callbacks)); |
119 } | 119 } |
120 | 120 |
121 void SimpleFileSystem::DeleteFileSystem( | |
122 WebFrame* frame, WebFileSystem::Type web_filesystem_type, | |
123 WebFileSystemCallbacks* callbacks) { | |
124 if (!frame || !file_system_context_.get()) { | |
125 callbacks->didFail(WebKit::WebFileErrorSecurity); | |
126 return; | |
kinuko
2012/08/15 06:15:58
We silently return success in RenderViewImpl in th
tzik
2012/08/15 06:53:36
We return success in RVI if the origin is unique (
| |
127 } | |
128 | |
129 fileapi::FileSystemType type; | |
130 if (web_filesystem_type == WebFileSystem::TypeTemporary) | |
131 type = fileapi::kFileSystemTypeTemporary; | |
132 else if (web_filesystem_type == WebFileSystem::TypePersistent) | |
133 type = fileapi::kFileSystemTypePersistent; | |
134 else if (web_filesystem_type == WebFileSystem::TypeExternal) | |
135 type = fileapi::kFileSystemTypeExternal; | |
kinuko
2012/08/15 06:15:58
These explicit assignments are not really necessar
tzik
2012/08/15 06:53:36
Done.
| |
136 else { | |
137 // Unknown type filesystem is requested. | |
138 callbacks->didFail(WebKit::WebFileErrorSecurity); | |
139 return; | |
140 } | |
141 | |
142 GURL origin_url(frame->document().securityOrigin().toString()); | |
143 file_system_context_->DeleteFileSystem( | |
144 origin_url, type, DeleteFileSystemHandler(callbacks)); | |
145 } | |
146 | |
121 void SimpleFileSystem::move( | 147 void SimpleFileSystem::move( |
122 const WebURL& src_path, | 148 const WebURL& src_path, |
123 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { | 149 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { |
124 FileSystemURL src_url(src_path); | 150 FileSystemURL src_url(src_path); |
125 FileSystemURL dest_url(dest_path); | 151 FileSystemURL dest_url(dest_path); |
126 if (!HasFilePermission(src_url, FILE_PERMISSION_WRITE) || | 152 if (!HasFilePermission(src_url, FILE_PERMISSION_WRITE) || |
127 !HasFilePermission(dest_url, FILE_PERMISSION_CREATE)) { | 153 !HasFilePermission(dest_url, FILE_PERMISSION_CREATE)) { |
128 callbacks->didFail(WebKit::WebFileErrorSecurity); | 154 callbacks->didFail(WebKit::WebFileErrorSecurity); |
129 return; | 155 return; |
130 } | 156 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 return base::Bind(&SimpleFileSystem::DidGetMetadata, | 315 return base::Bind(&SimpleFileSystem::DidGetMetadata, |
290 AsWeakPtr(), base::Unretained(callbacks)); | 316 AsWeakPtr(), base::Unretained(callbacks)); |
291 } | 317 } |
292 | 318 |
293 FileSystemContext::OpenFileSystemCallback | 319 FileSystemContext::OpenFileSystemCallback |
294 SimpleFileSystem::OpenFileSystemHandler(WebFileSystemCallbacks* callbacks) { | 320 SimpleFileSystem::OpenFileSystemHandler(WebFileSystemCallbacks* callbacks) { |
295 return base::Bind(&SimpleFileSystem::DidOpenFileSystem, | 321 return base::Bind(&SimpleFileSystem::DidOpenFileSystem, |
296 AsWeakPtr(), base::Unretained(callbacks)); | 322 AsWeakPtr(), base::Unretained(callbacks)); |
297 } | 323 } |
298 | 324 |
325 FileSystemContext::DeleteFileSystemCallback | |
326 SimpleFileSystem::DeleteFileSystemHandler(WebFileSystemCallbacks* callbacks) { | |
327 return base::Bind(&SimpleFileSystem::DidDeleteFileSystem, | |
328 AsWeakPtr(), callbacks); | |
329 } | |
330 | |
299 FileSystemOperationInterface::SnapshotFileCallback | 331 FileSystemOperationInterface::SnapshotFileCallback |
300 SimpleFileSystem::SnapshotFileHandler(const GURL& blob_url, | 332 SimpleFileSystem::SnapshotFileHandler(const GURL& blob_url, |
301 WebFileSystemCallbacks* callbacks) { | 333 WebFileSystemCallbacks* callbacks) { |
302 return base::Bind(&SimpleFileSystem::DidCreateSnapshotFile, | 334 return base::Bind(&SimpleFileSystem::DidCreateSnapshotFile, |
303 AsWeakPtr(), blob_url, base::Unretained(callbacks)); | 335 AsWeakPtr(), blob_url, base::Unretained(callbacks)); |
304 } | 336 } |
305 | 337 |
306 void SimpleFileSystem::DidFinish(WebFileSystemCallbacks* callbacks, | 338 void SimpleFileSystem::DidFinish(WebFileSystemCallbacks* callbacks, |
307 base::PlatformFileError result) { | 339 base::PlatformFileError result) { |
308 if (result == base::PLATFORM_FILE_OK) | 340 if (result == base::PLATFORM_FILE_OK) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 if (result == base::PLATFORM_FILE_OK) { | 389 if (result == base::PLATFORM_FILE_OK) { |
358 if (!root.is_valid()) | 390 if (!root.is_valid()) |
359 callbacks->didFail(WebKit::WebFileErrorSecurity); | 391 callbacks->didFail(WebKit::WebFileErrorSecurity); |
360 else | 392 else |
361 callbacks->didOpenFileSystem(WebString::fromUTF8(name), root); | 393 callbacks->didOpenFileSystem(WebString::fromUTF8(name), root); |
362 } else { | 394 } else { |
363 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); | 395 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); |
364 } | 396 } |
365 } | 397 } |
366 | 398 |
399 void SimpleFileSystem::DidDeleteFileSystem( | |
400 WebFileSystemCallbacks* callbacks, | |
401 base::PlatformFileError result) { | |
402 if (result == base::PLATFORM_FILE_OK) | |
403 callbacks->didSucceed(); | |
404 else | |
405 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); | |
406 } | |
407 | |
367 void SimpleFileSystem::DidCreateSnapshotFile( | 408 void SimpleFileSystem::DidCreateSnapshotFile( |
368 const GURL& blob_url, | 409 const GURL& blob_url, |
369 WebFileSystemCallbacks* callbacks, | 410 WebFileSystemCallbacks* callbacks, |
370 base::PlatformFileError result, | 411 base::PlatformFileError result, |
371 const base::PlatformFileInfo& info, | 412 const base::PlatformFileInfo& info, |
372 const FilePath& platform_path, | 413 const FilePath& platform_path, |
373 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 414 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
374 DCHECK(g_io_thread); | 415 DCHECK(g_io_thread); |
375 if (result == base::PLATFORM_FILE_OK) { | 416 if (result == base::PLATFORM_FILE_OK) { |
376 g_io_thread->PostTask( | 417 g_io_thread->PostTask( |
377 FROM_HERE, | 418 FROM_HERE, |
378 base::Bind(&RegisterBlob, blob_url, platform_path)); | 419 base::Bind(&RegisterBlob, blob_url, platform_path)); |
379 } | 420 } |
380 DidGetMetadata(callbacks, result, info, platform_path); | 421 DidGetMetadata(callbacks, result, info, platform_path); |
381 } | 422 } |
OLD | NEW |