OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 , m_clonable(false) | 66 , m_clonable(false) |
67 { | 67 { |
68 } | 68 } |
69 | 69 |
70 DOMFileSystemBase::~DOMFileSystemBase() | 70 DOMFileSystemBase::~DOMFileSystemBase() |
71 { | 71 { |
72 } | 72 } |
73 | 73 |
74 blink::WebFileSystem* DOMFileSystemBase::fileSystem() const | 74 blink::WebFileSystem* DOMFileSystemBase::fileSystem() const |
75 { | 75 { |
76 return blink::Platform::current()->fileSystem(); | 76 blink::Platform* platform = blink::Platform::current(); |
| 77 if (!platform) |
| 78 return nullptr; |
| 79 return platform->fileSystem(); |
77 } | 80 } |
78 | 81 |
79 SecurityOrigin* DOMFileSystemBase::securityOrigin() const | 82 SecurityOrigin* DOMFileSystemBase::securityOrigin() const |
80 { | 83 { |
81 return m_context->securityOrigin(); | 84 return m_context->securityOrigin(); |
82 } | 85 } |
83 | 86 |
84 bool DOMFileSystemBase::isValidType(FileSystemType type) | 87 bool DOMFileSystemBase::isValidType(FileSystemType type) |
85 { | 88 { |
86 return type == FileSystemTypeTemporary || type == FileSystemTypePersistent |
| type == FileSystemTypeIsolated || type == FileSystemTypeExternal; | 89 return type == FileSystemTypeTemporary || type == FileSystemTypePersistent |
| type == FileSystemTypeIsolated || type == FileSystemTypeExternal; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (pathPrefix == externalPathPrefix) { | 183 if (pathPrefix == externalPathPrefix) { |
181 type = FileSystemTypeExternal; | 184 type = FileSystemTypeExternal; |
182 return true; | 185 return true; |
183 } | 186 } |
184 | 187 |
185 return false; | 188 return false; |
186 } | 189 } |
187 | 190 |
188 void DOMFileSystemBase::getMetadata(const EntryBase* entry, PassOwnPtr<MetadataC
allback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousTy
pe synchronousType) | 191 void DOMFileSystemBase::getMetadata(const EntryBase* entry, PassOwnPtr<MetadataC
allback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousTy
pe synchronousType) |
189 { | 192 { |
| 193 if (!fileSystem()) { |
| 194 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); |
| 195 return; |
| 196 } |
| 197 |
190 OwnPtr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create(success
Callback, errorCallback, m_context, this)); | 198 OwnPtr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create(success
Callback, errorCallback, m_context, this)); |
191 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 199 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
192 fileSystem()->readMetadata(createFileSystemURL(entry), callbacks.release()); | 200 fileSystem()->readMetadata(createFileSystemURL(entry), callbacks.release()); |
193 } | 201 } |
194 | 202 |
195 static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, En
tryBase* parent, const String& newName, String& destinationPath) | 203 static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, En
tryBase* parent, const String& newName, String& destinationPath) |
196 { | 204 { |
197 ASSERT(source); | 205 ASSERT(source); |
198 | 206 |
199 if (!parent || !parent->isDirectory()) | 207 if (!parent || !parent->isDirectory()) |
(...skipping 16 matching lines...) Expand all Loading... |
216 if (!newName.isEmpty()) | 224 if (!newName.isEmpty()) |
217 destinationPath = DOMFilePath::append(destinationPath, newName); | 225 destinationPath = DOMFilePath::append(destinationPath, newName); |
218 else | 226 else |
219 destinationPath = DOMFilePath::append(destinationPath, source->name()); | 227 destinationPath = DOMFilePath::append(destinationPath, source->name()); |
220 | 228 |
221 return true; | 229 return true; |
222 } | 230 } |
223 | 231 |
224 void DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const S
tring& newName, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallb
ack> errorCallback, SynchronousType synchronousType) | 232 void DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const S
tring& newName, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallb
ack> errorCallback, SynchronousType synchronousType) |
225 { | 233 { |
| 234 if (!fileSystem()) { |
| 235 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); |
| 236 return; |
| 237 } |
| 238 |
226 String destinationPath; | 239 String destinationPath; |
227 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti
nationPath)) { | 240 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti
nationPath)) { |
228 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 241 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); |
229 return; | 242 return; |
230 } | 243 } |
231 | 244 |
232 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal
lback, errorCallback, m_context, parent->filesystem(), destinationPath, source->
isDirectory())); | 245 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal
lback, errorCallback, m_context, parent->filesystem(), destinationPath, source->
isDirectory())); |
233 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 246 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
234 | 247 |
235 fileSystem()->move(createFileSystemURL(source), parent->filesystem()->create
FileSystemURL(destinationPath), callbacks.release()); | 248 fileSystem()->move(createFileSystemURL(source), parent->filesystem()->create
FileSystemURL(destinationPath), callbacks.release()); |
236 } | 249 } |
237 | 250 |
238 void DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const S
tring& newName, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallb
ack> errorCallback, SynchronousType synchronousType) | 251 void DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const S
tring& newName, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallb
ack> errorCallback, SynchronousType synchronousType) |
239 { | 252 { |
| 253 if (!fileSystem()) { |
| 254 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); |
| 255 return; |
| 256 } |
| 257 |
240 String destinationPath; | 258 String destinationPath; |
241 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti
nationPath)) { | 259 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti
nationPath)) { |
242 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 260 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); |
243 return; | 261 return; |
244 } | 262 } |
245 | 263 |
246 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal
lback, errorCallback, m_context, parent->filesystem(), destinationPath, source->
isDirectory())); | 264 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal
lback, errorCallback, m_context, parent->filesystem(), destinationPath, source->
isDirectory())); |
247 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 265 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
248 | 266 |
249 fileSystem()->copy(createFileSystemURL(source), parent->filesystem()->create
FileSystemURL(destinationPath), callbacks.release()); | 267 fileSystem()->copy(createFileSystemURL(source), parent->filesystem()->create
FileSystemURL(destinationPath), callbacks.release()); |
250 } | 268 } |
251 | 269 |
252 void DOMFileSystemBase::remove(const EntryBase* entry, PassOwnPtr<VoidCallback>
successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchr
onousType) | 270 void DOMFileSystemBase::remove(const EntryBase* entry, PassOwnPtr<VoidCallback>
successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchr
onousType) |
253 { | 271 { |
| 272 if (!fileSystem()) { |
| 273 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); |
| 274 return; |
| 275 } |
| 276 |
254 ASSERT(entry); | 277 ASSERT(entry); |
255 // We don't allow calling remove() on the root directory. | 278 // We don't allow calling remove() on the root directory. |
256 if (entry->fullPath() == String(DOMFilePath::root)) { | 279 if (entry->fullPath() == String(DOMFilePath::root)) { |
257 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 280 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); |
258 return; | 281 return; |
259 } | 282 } |
260 | 283 |
261 OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCall
back, errorCallback, m_context, this)); | 284 OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCall
back, errorCallback, m_context, this)); |
262 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 285 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
263 | 286 |
264 fileSystem()->remove(createFileSystemURL(entry), callbacks.release()); | 287 fileSystem()->remove(createFileSystemURL(entry), callbacks.release()); |
265 } | 288 } |
266 | 289 |
267 void DOMFileSystemBase::removeRecursively(const EntryBase* entry, PassOwnPtr<Voi
dCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, Synchronous
Type synchronousType) | 290 void DOMFileSystemBase::removeRecursively(const EntryBase* entry, PassOwnPtr<Voi
dCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, Synchronous
Type synchronousType) |
268 { | 291 { |
| 292 if (!fileSystem()) { |
| 293 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); |
| 294 return; |
| 295 } |
| 296 |
269 ASSERT(entry && entry->isDirectory()); | 297 ASSERT(entry && entry->isDirectory()); |
270 // We don't allow calling remove() on the root directory. | 298 // We don't allow calling remove() on the root directory. |
271 if (entry->fullPath() == String(DOMFilePath::root)) { | 299 if (entry->fullPath() == String(DOMFilePath::root)) { |
272 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 300 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); |
273 return; | 301 return; |
274 } | 302 } |
275 | 303 |
276 OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCall
back, errorCallback, m_context, this)); | 304 OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCall
back, errorCallback, m_context, this)); |
277 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 305 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
278 | 306 |
279 fileSystem()->removeRecursively(createFileSystemURL(entry), callbacks.releas
e()); | 307 fileSystem()->removeRecursively(createFileSystemURL(entry), callbacks.releas
e()); |
280 } | 308 } |
281 | 309 |
282 void DOMFileSystemBase::getParent(const EntryBase* entry, PassOwnPtr<EntryCallba
ck> successCallback, PassOwnPtr<ErrorCallback> errorCallback) | 310 void DOMFileSystemBase::getParent(const EntryBase* entry, PassOwnPtr<EntryCallba
ck> successCallback, PassOwnPtr<ErrorCallback> errorCallback) |
283 { | 311 { |
| 312 if (!fileSystem()) { |
| 313 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); |
| 314 return; |
| 315 } |
| 316 |
284 ASSERT(entry); | 317 ASSERT(entry); |
285 String path = DOMFilePath::getDirectory(entry->fullPath()); | 318 String path = DOMFilePath::getDirectory(entry->fullPath()); |
| 319 |
286 fileSystem()->directoryExists(createFileSystemURL(path), EntryCallbacks::cre
ate(successCallback, errorCallback, m_context, this, path, true)); | 320 fileSystem()->directoryExists(createFileSystemURL(path), EntryCallbacks::cre
ate(successCallback, errorCallback, m_context, this, path, true)); |
287 } | 321 } |
288 | 322 |
289 void DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, cons
t FileSystemFlags& flags, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<
ErrorCallback> errorCallback, SynchronousType synchronousType) | 323 void DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, cons
t FileSystemFlags& flags, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<
ErrorCallback> errorCallback, SynchronousType synchronousType) |
290 { | 324 { |
| 325 if (!fileSystem()) { |
| 326 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); |
| 327 return; |
| 328 } |
| 329 |
291 String absolutePath; | 330 String absolutePath; |
292 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { | 331 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { |
293 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 332 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); |
294 return; | 333 return; |
295 } | 334 } |
296 | 335 |
297 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal
lback, errorCallback, m_context, this, absolutePath, false)); | 336 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal
lback, errorCallback, m_context, this, absolutePath, false)); |
298 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 337 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
299 | 338 |
300 if (flags.create) | 339 if (flags.create) |
301 fileSystem()->createFile(createFileSystemURL(absolutePath), flags.exclus
ive, callbacks.release()); | 340 fileSystem()->createFile(createFileSystemURL(absolutePath), flags.exclus
ive, callbacks.release()); |
302 else | 341 else |
303 fileSystem()->fileExists(createFileSystemURL(absolutePath), callbacks.re
lease()); | 342 fileSystem()->fileExists(createFileSystemURL(absolutePath), callbacks.re
lease()); |
304 } | 343 } |
305 | 344 |
306 void DOMFileSystemBase::getDirectory(const EntryBase* entry, const String& path,
const FileSystemFlags& flags, PassOwnPtr<EntryCallback> successCallback, PassOw
nPtr<ErrorCallback> errorCallback, SynchronousType synchronousType) | 345 void DOMFileSystemBase::getDirectory(const EntryBase* entry, const String& path,
const FileSystemFlags& flags, PassOwnPtr<EntryCallback> successCallback, PassOw
nPtr<ErrorCallback> errorCallback, SynchronousType synchronousType) |
307 { | 346 { |
| 347 if (!fileSystem()) { |
| 348 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); |
| 349 return; |
| 350 } |
| 351 |
308 String absolutePath; | 352 String absolutePath; |
309 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { | 353 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { |
310 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); | 354 reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICA
TION_ERR)); |
311 return; | 355 return; |
312 } | 356 } |
313 | 357 |
314 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal
lback, errorCallback, m_context, this, absolutePath, true)); | 358 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal
lback, errorCallback, m_context, this, absolutePath, true)); |
315 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 359 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
316 | 360 |
317 if (flags.create) | 361 if (flags.create) |
318 fileSystem()->createDirectory(createFileSystemURL(absolutePath), flags.e
xclusive, callbacks.release()); | 362 fileSystem()->createDirectory(createFileSystemURL(absolutePath), flags.e
xclusive, callbacks.release()); |
319 else | 363 else |
320 fileSystem()->directoryExists(createFileSystemURL(absolutePath), callbac
ks.release()); | 364 fileSystem()->directoryExists(createFileSystemURL(absolutePath), callbac
ks.release()); |
321 } | 365 } |
322 | 366 |
323 int DOMFileSystemBase::readDirectory(DirectoryReaderBase* reader, const String&
path, PassOwnPtr<EntriesCallback> successCallback, PassOwnPtr<ErrorCallback> err
orCallback, SynchronousType synchronousType) | 367 int DOMFileSystemBase::readDirectory(DirectoryReaderBase* reader, const String&
path, PassOwnPtr<EntriesCallback> successCallback, PassOwnPtr<ErrorCallback> err
orCallback, SynchronousType synchronousType) |
324 { | 368 { |
| 369 if (!fileSystem()) { |
| 370 reportError(errorCallback, FileError::create(FileError::ABORT_ERR)); |
| 371 return 0; |
| 372 } |
| 373 |
325 ASSERT(DOMFilePath::isAbsolute(path)); | 374 ASSERT(DOMFilePath::isAbsolute(path)); |
326 | 375 |
327 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create(successC
allback, errorCallback, m_context, reader, path)); | 376 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create(successC
allback, errorCallback, m_context, reader, path)); |
328 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); | 377 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); |
329 | 378 |
330 return fileSystem()->readDirectory(createFileSystemURL(path), callbacks.rele
ase()); | 379 return fileSystem()->readDirectory(createFileSystemURL(path), callbacks.rele
ase()); |
331 } | 380 } |
332 | 381 |
333 bool DOMFileSystemBase::waitForAdditionalResult(int callbacksId) | 382 bool DOMFileSystemBase::waitForAdditionalResult(int callbacksId) |
334 { | 383 { |
| 384 if (!fileSystem()) |
| 385 return false; |
335 return fileSystem()->waitForAdditionalResult(callbacksId); | 386 return fileSystem()->waitForAdditionalResult(callbacksId); |
336 } | 387 } |
337 | 388 |
338 } // namespace blink | 389 } // namespace blink |
OLD | NEW |