| 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/tools/test_shell/simple_file_system.h" | 5 #include "webkit/tools/test_shell/simple_file_system.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/memory/scoped_callback_factory.h" | 8 #include "base/memory/scoped_callback_factory.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 "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemEntry.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemEntry.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
| 20 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 21 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 21 #include "webkit/fileapi/file_system_context.h" | 22 #include "webkit/fileapi/file_system_context.h" |
| 22 #include "webkit/fileapi/file_system_file_util.h" | 23 #include "webkit/fileapi/file_system_file_util.h" |
| 23 #include "webkit/fileapi/file_system_operation.h" | 24 #include "webkit/fileapi/file_system_operation.h" |
| 24 #include "webkit/fileapi/file_system_path_manager.h" | 25 #include "webkit/fileapi/file_system_path_manager.h" |
| 25 #include "webkit/fileapi/file_system_types.h" | 26 #include "webkit/fileapi/file_system_types.h" |
| 26 #include "webkit/glue/webkit_glue.h" | 27 #include "webkit/glue/webkit_glue.h" |
| 27 #include "webkit/tools/test_shell/simple_file_writer.h" | 28 #include "webkit/tools/test_shell/simple_file_writer.h" |
| 28 | 29 |
| 29 using base::WeakPtr; | 30 using base::WeakPtr; |
| 30 | 31 |
| 31 using WebKit::WebFileInfo; | 32 using WebKit::WebFileInfo; |
| 32 using WebKit::WebFileSystem; | 33 using WebKit::WebFileSystem; |
| 33 using WebKit::WebFileSystemCallbacks; | 34 using WebKit::WebFileSystemCallbacks; |
| 34 using WebKit::WebFileSystemEntry; | 35 using WebKit::WebFileSystemEntry; |
| 35 using WebKit::WebFileWriter; | 36 using WebKit::WebFileWriter; |
| 36 using WebKit::WebFileWriterClient; | 37 using WebKit::WebFileWriterClient; |
| 37 using WebKit::WebFrame; | 38 using WebKit::WebFrame; |
| 38 using WebKit::WebSecurityOrigin; | 39 using WebKit::WebSecurityOrigin; |
| 39 using WebKit::WebString; | 40 using WebKit::WebString; |
| 41 using WebKit::WebURL; |
| 40 using WebKit::WebVector; | 42 using WebKit::WebVector; |
| 41 | 43 |
| 42 using fileapi::FileSystemCallbackDispatcher; | 44 using fileapi::FileSystemCallbackDispatcher; |
| 43 using fileapi::FileSystemContext; | 45 using fileapi::FileSystemContext; |
| 44 using fileapi::FileSystemFileUtil; | 46 using fileapi::FileSystemFileUtil; |
| 45 using fileapi::FileSystemOperation; | 47 using fileapi::FileSystemOperation; |
| 46 | 48 |
| 47 namespace { | 49 namespace { |
| 48 | 50 |
| 49 class SimpleFileSystemCallbackDispatcher | 51 class SimpleFileSystemCallbackDispatcher |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 web_entries_vector; | 95 web_entries_vector; |
| 94 callbacks_->didReadDirectory(web_entries, has_more); | 96 callbacks_->didReadDirectory(web_entries, has_more); |
| 95 } | 97 } |
| 96 | 98 |
| 97 virtual void DidOpenFileSystem( | 99 virtual void DidOpenFileSystem( |
| 98 const std::string& name, const GURL& root) { | 100 const std::string& name, const GURL& root) { |
| 99 DCHECK(file_system_); | 101 DCHECK(file_system_); |
| 100 if (!root.is_valid()) | 102 if (!root.is_valid()) |
| 101 callbacks_->didFail(WebKit::WebFileErrorSecurity); | 103 callbacks_->didFail(WebKit::WebFileErrorSecurity); |
| 102 else | 104 else |
| 105 // Temporary hack to ease a 4-phase Chromium/WebKit commit. |
| 106 #ifdef WEBFILESYSTEMCALLBACKS_USE_URL_NOT_STRING |
| 107 callbacks_->didOpenFileSystem(WebString::fromUTF8(name), root); |
| 108 #else |
| 103 callbacks_->didOpenFileSystem( | 109 callbacks_->didOpenFileSystem( |
| 104 WebString::fromUTF8(name), WebString::fromUTF8(root.spec())); | 110 WebString::fromUTF8(name), WebString::fromUTF8(root.spec())); |
| 111 #endif |
| 105 } | 112 } |
| 106 | 113 |
| 107 virtual void DidFail(base::PlatformFileError error_code) { | 114 virtual void DidFail(base::PlatformFileError error_code) { |
| 108 DCHECK(file_system_); | 115 DCHECK(file_system_); |
| 109 callbacks_->didFail( | 116 callbacks_->didFail( |
| 110 webkit_glue::PlatformFileErrorToWebFileError(error_code)); | 117 webkit_glue::PlatformFileErrorToWebFileError(error_code)); |
| 111 } | 118 } |
| 112 | 119 |
| 113 virtual void DidWrite(int64, bool) { | 120 virtual void DidWrite(int64, bool) { |
| 114 NOTREACHED(); | 121 NOTREACHED(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 else { | 169 else { |
| 163 // Unknown type filesystem is requested. | 170 // Unknown type filesystem is requested. |
| 164 callbacks->didFail(WebKit::WebFileErrorSecurity); | 171 callbacks->didFail(WebKit::WebFileErrorSecurity); |
| 165 return; | 172 return; |
| 166 } | 173 } |
| 167 | 174 |
| 168 GURL origin_url(frame->securityOrigin().toString()); | 175 GURL origin_url(frame->securityOrigin().toString()); |
| 169 GetNewOperation(callbacks)->OpenFileSystem(origin_url, type, create); | 176 GetNewOperation(callbacks)->OpenFileSystem(origin_url, type, create); |
| 170 } | 177 } |
| 171 | 178 |
| 179 void SimpleFileSystem::move(const WebString& src_path, |
| 180 const WebString& dest_path, |
| 181 WebFileSystemCallbacks* callbacks) { |
| 182 move(GURL(src_path), GURL(dest_path), callbacks); |
| 183 } |
| 184 |
| 185 void SimpleFileSystem::copy(const WebString& src_path, |
| 186 const WebString& dest_path, |
| 187 WebFileSystemCallbacks* callbacks) { |
| 188 copy(GURL(src_path), GURL(dest_path), callbacks); |
| 189 } |
| 190 |
| 191 void SimpleFileSystem::remove(const WebString& path, |
| 192 WebFileSystemCallbacks* callbacks) { |
| 193 remove(GURL(path), callbacks); |
| 194 } |
| 195 |
| 196 void SimpleFileSystem::removeRecursively(const WebString& path, |
| 197 WebFileSystemCallbacks* callbacks) { |
| 198 removeRecursively(GURL(path), callbacks); |
| 199 } |
| 200 |
| 201 void SimpleFileSystem::readMetadata(const WebString& path, |
| 202 WebFileSystemCallbacks* callbacks) { |
| 203 readMetadata(GURL(path), callbacks); |
| 204 } |
| 205 |
| 206 void SimpleFileSystem::createFile(const WebString& path, |
| 207 bool exclusive, |
| 208 WebFileSystemCallbacks* callbacks) { |
| 209 createFile(GURL(path), exclusive, callbacks); |
| 210 } |
| 211 |
| 212 void SimpleFileSystem::createDirectory(const WebString& path, |
| 213 bool exclusive, |
| 214 WebFileSystemCallbacks* callbacks) { |
| 215 createDirectory(GURL(path), exclusive, callbacks); |
| 216 } |
| 217 |
| 218 void SimpleFileSystem::fileExists(const WebString& path, |
| 219 WebFileSystemCallbacks* callbacks) { |
| 220 fileExists(GURL(path), callbacks); |
| 221 } |
| 222 |
| 223 void SimpleFileSystem::directoryExists(const WebString& path, |
| 224 WebFileSystemCallbacks* callbacks) { |
| 225 directoryExists(GURL(path), callbacks); |
| 226 } |
| 227 |
| 228 void SimpleFileSystem::readDirectory(const WebString& path, |
| 229 WebFileSystemCallbacks* callbacks) { |
| 230 readDirectory(GURL(path), callbacks); |
| 231 } |
| 232 |
| 233 WebKit::WebFileWriter* SimpleFileSystem::createFileWriter( |
| 234 const WebString& path, WebKit::WebFileWriterClient* client) { |
| 235 return createFileWriter(GURL(path), client); |
| 236 } |
| 237 |
| 172 void SimpleFileSystem::move( | 238 void SimpleFileSystem::move( |
| 173 const WebString& src_path, | 239 const WebURL& src_path, |
| 174 const WebString& dest_path, WebFileSystemCallbacks* callbacks) { | 240 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { |
| 175 GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path)); | 241 GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path)); |
| 176 } | 242 } |
| 177 | 243 |
| 178 void SimpleFileSystem::copy( | 244 void SimpleFileSystem::copy( |
| 179 const WebString& src_path, const WebString& dest_path, | 245 const WebURL& src_path, const WebURL& dest_path, |
| 180 WebFileSystemCallbacks* callbacks) { | 246 WebFileSystemCallbacks* callbacks) { |
| 181 GetNewOperation(callbacks)->Copy(GURL(src_path), GURL(dest_path)); | 247 GetNewOperation(callbacks)->Copy(GURL(src_path), GURL(dest_path)); |
| 182 } | 248 } |
| 183 | 249 |
| 184 void SimpleFileSystem::remove( | 250 void SimpleFileSystem::remove( |
| 185 const WebString& path, WebFileSystemCallbacks* callbacks) { | 251 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 186 GetNewOperation(callbacks)->Remove(GURL(path), false /* recursive */); | 252 GetNewOperation(callbacks)->Remove(path, false /* recursive */); |
| 187 } | 253 } |
| 188 | 254 |
| 189 void SimpleFileSystem::removeRecursively( | 255 void SimpleFileSystem::removeRecursively( |
| 190 const WebString& path, WebFileSystemCallbacks* callbacks) { | 256 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 191 GetNewOperation(callbacks)->Remove(GURL(path), true /* recursive */); | 257 GetNewOperation(callbacks)->Remove(path, true /* recursive */); |
| 192 } | 258 } |
| 193 | 259 |
| 194 void SimpleFileSystem::readMetadata( | 260 void SimpleFileSystem::readMetadata( |
| 195 const WebString& path, WebFileSystemCallbacks* callbacks) { | 261 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 196 GetNewOperation(callbacks)->GetMetadata(GURL(path)); | 262 GetNewOperation(callbacks)->GetMetadata(path); |
| 197 } | 263 } |
| 198 | 264 |
| 199 void SimpleFileSystem::createFile( | 265 void SimpleFileSystem::createFile( |
| 200 const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 266 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
| 201 GetNewOperation(callbacks)->CreateFile(GURL(path), exclusive); | 267 GetNewOperation(callbacks)->CreateFile(path, exclusive); |
| 202 } | 268 } |
| 203 | 269 |
| 204 void SimpleFileSystem::createDirectory( | 270 void SimpleFileSystem::createDirectory( |
| 205 const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 271 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
| 206 GetNewOperation(callbacks)->CreateDirectory(GURL(path), exclusive, false); | 272 GetNewOperation(callbacks)->CreateDirectory(path, exclusive, false); |
| 207 } | 273 } |
| 208 | 274 |
| 209 void SimpleFileSystem::fileExists( | 275 void SimpleFileSystem::fileExists( |
| 210 const WebString& path, WebFileSystemCallbacks* callbacks) { | 276 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 211 GetNewOperation(callbacks)->FileExists(GURL(path)); | 277 GetNewOperation(callbacks)->FileExists(path); |
| 212 } | 278 } |
| 213 | 279 |
| 214 void SimpleFileSystem::directoryExists( | 280 void SimpleFileSystem::directoryExists( |
| 215 const WebString& path, WebFileSystemCallbacks* callbacks) { | 281 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 216 GetNewOperation(callbacks)->DirectoryExists(GURL(path)); | 282 GetNewOperation(callbacks)->DirectoryExists(path); |
| 217 } | 283 } |
| 218 | 284 |
| 219 void SimpleFileSystem::readDirectory( | 285 void SimpleFileSystem::readDirectory( |
| 220 const WebString& path, WebFileSystemCallbacks* callbacks) { | 286 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 221 GetNewOperation(callbacks)->ReadDirectory(GURL(path)); | 287 GetNewOperation(callbacks)->ReadDirectory(path); |
| 222 } | 288 } |
| 223 | 289 |
| 224 WebFileWriter* SimpleFileSystem::createFileWriter( | 290 WebFileWriter* SimpleFileSystem::createFileWriter( |
| 225 const WebString& path, WebFileWriterClient* client) { | 291 const WebURL& path, WebFileWriterClient* client) { |
| 226 return new SimpleFileWriter(GURL(path), client, file_system_context_.get()); | 292 return new SimpleFileWriter(path, client, file_system_context_.get()); |
| 227 } | 293 } |
| 228 | 294 |
| 229 FileSystemOperation* SimpleFileSystem::GetNewOperation( | 295 FileSystemOperation* SimpleFileSystem::GetNewOperation( |
| 230 WebFileSystemCallbacks* callbacks) { | 296 WebFileSystemCallbacks* callbacks) { |
| 231 SimpleFileSystemCallbackDispatcher* dispatcher = | 297 SimpleFileSystemCallbackDispatcher* dispatcher = |
| 232 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); | 298 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); |
| 233 FileSystemOperation* operation = new FileSystemOperation( | 299 FileSystemOperation* operation = new FileSystemOperation( |
| 234 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(), | 300 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(), |
| 235 file_system_context_.get(), NULL); | 301 file_system_context_.get(), NULL); |
| 236 return operation; | 302 return operation; |
| 237 } | 303 } |
| OLD | NEW |