| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "platform/weborigin/SecurityOrigin.h" | 47 #include "platform/weborigin/SecurityOrigin.h" |
| 48 #include "public/platform/WebFileSystem.h" | 48 #include "public/platform/WebFileSystem.h" |
| 49 #include "public/platform/WebFileSystemCallbacks.h" | 49 #include "public/platform/WebFileSystemCallbacks.h" |
| 50 #include "wtf/OwnPtr.h" | 50 #include "wtf/OwnPtr.h" |
| 51 #include "wtf/text/StringBuilder.h" | 51 #include "wtf/text/StringBuilder.h" |
| 52 #include "wtf/text/WTFString.h" | 52 #include "wtf/text/WTFString.h" |
| 53 | 53 |
| 54 namespace WebCore { | 54 namespace WebCore { |
| 55 | 55 |
| 56 // static | 56 // static |
| 57 PassRefPtr<DOMFileSystem> DOMFileSystem::create(ExecutionContext* context, const
String& name, FileSystemType type, const KURL& rootURL) | 57 PassRefPtrWillBeRawPtr<DOMFileSystem> DOMFileSystem::create(ExecutionContext* co
ntext, const String& name, FileSystemType type, const KURL& rootURL) |
| 58 { | 58 { |
| 59 RefPtr<DOMFileSystem> fileSystem(adoptRef(new DOMFileSystem(context, name, t
ype, rootURL))); | 59 RefPtrWillBeRawPtr<DOMFileSystem> fileSystem(adoptRefWillBeRefCountedGarbage
Collected(new DOMFileSystem(context, name, type, rootURL))); |
| 60 fileSystem->suspendIfNeeded(); | 60 fileSystem->suspendIfNeeded(); |
| 61 return fileSystem.release(); | 61 return fileSystem.release(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 PassRefPtr<DOMFileSystem> DOMFileSystem::createIsolatedFileSystem(ExecutionConte
xt* context, const String& filesystemId) | 64 PassRefPtrWillBeRawPtr<DOMFileSystem> DOMFileSystem::createIsolatedFileSystem(Ex
ecutionContext* context, const String& filesystemId) |
| 65 { | 65 { |
| 66 if (filesystemId.isEmpty()) | 66 if (filesystemId.isEmpty()) |
| 67 return nullptr; | 67 return nullptr; |
| 68 | 68 |
| 69 StringBuilder filesystemName; | 69 StringBuilder filesystemName; |
| 70 filesystemName.append(createDatabaseIdentifierFromSecurityOrigin(context->se
curityOrigin())); | 70 filesystemName.append(createDatabaseIdentifierFromSecurityOrigin(context->se
curityOrigin())); |
| 71 filesystemName.append(":Isolated_"); | 71 filesystemName.append(":Isolated_"); |
| 72 filesystemName.append(filesystemId); | 72 filesystemName.append(filesystemId); |
| 73 | 73 |
| 74 // The rootURL created here is going to be attached to each filesystem reque
st and | 74 // The rootURL created here is going to be attached to each filesystem reque
st and |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 return DOMFileSystem::create(context, filesystemName.toString(), FileSystemT
ypeIsolated, KURL(ParsedURLString, rootURL.toString())); | 85 return DOMFileSystem::create(context, filesystemName.toString(), FileSystemT
ypeIsolated, KURL(ParsedURLString, rootURL.toString())); |
| 86 } | 86 } |
| 87 | 87 |
| 88 DOMFileSystem::DOMFileSystem(ExecutionContext* context, const String& name, File
SystemType type, const KURL& rootURL) | 88 DOMFileSystem::DOMFileSystem(ExecutionContext* context, const String& name, File
SystemType type, const KURL& rootURL) |
| 89 : DOMFileSystemBase(context, name, type, rootURL) | 89 : DOMFileSystemBase(context, name, type, rootURL) |
| 90 , ActiveDOMObject(context) | 90 , ActiveDOMObject(context) |
| 91 { | 91 { |
| 92 ScriptWrappable::init(this); | 92 ScriptWrappable::init(this); |
| 93 } | 93 } |
| 94 | 94 |
| 95 PassRefPtr<DirectoryEntry> DOMFileSystem::root() | 95 PassRefPtrWillBeRawPtr<DirectoryEntry> DOMFileSystem::root() |
| 96 { | 96 { |
| 97 return DirectoryEntry::create(this, DOMFilePath::root); | 97 return DirectoryEntry::create(this, DOMFilePath::root); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void DOMFileSystem::addPendingCallbacks() | 100 void DOMFileSystem::addPendingCallbacks() |
| 101 { | 101 { |
| 102 setPendingActivity(this); | 102 setPendingActivity(this); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void DOMFileSystem::removePendingCallbacks() | 105 void DOMFileSystem::removePendingCallbacks() |
| (...skipping 26 matching lines...) Expand all Loading... |
| 132 } | 132 } |
| 133 OwnPtr<FileWriterCallback> m_callback; | 133 OwnPtr<FileWriterCallback> m_callback; |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 } | 136 } |
| 137 | 137 |
| 138 void DOMFileSystem::createWriter(const FileEntry* fileEntry, PassOwnPtr<FileWrit
erCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback) | 138 void DOMFileSystem::createWriter(const FileEntry* fileEntry, PassOwnPtr<FileWrit
erCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback) |
| 139 { | 139 { |
| 140 ASSERT(fileEntry); | 140 ASSERT(fileEntry); |
| 141 | 141 |
| 142 RefPtr<FileWriter> fileWriter = FileWriter::create(executionContext()); | 142 RefPtrWillBeRawPtr<FileWriter> fileWriter = FileWriter::create(executionCont
ext()); |
| 143 OwnPtr<FileWriterBaseCallback> conversionCallback = ConvertToFileWriterCallb
ack::create(successCallback); | 143 OwnPtr<FileWriterBaseCallback> conversionCallback = ConvertToFileWriterCallb
ack::create(successCallback); |
| 144 OwnPtr<AsyncFileSystemCallbacks> callbacks = FileWriterBaseCallbacks::create
(fileWriter, conversionCallback.release(), errorCallback); | 144 OwnPtr<AsyncFileSystemCallbacks> callbacks = FileWriterBaseCallbacks::create
(fileWriter, conversionCallback.release(), errorCallback); |
| 145 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter.ge
t(), callbacks.release()); | 145 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter.ge
t(), callbacks.release()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 namespace { | 148 namespace { |
| 149 | 149 |
| 150 class SnapshotFileCallback : public FileSystemCallbacksBase { | 150 class SnapshotFileCallback : public FileSystemCallbacksBase { |
| 151 public: | 151 public: |
| 152 static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtr<DOMFileSystem>
filesystem, const String& name, const KURL& url, PassOwnPtr<FileCallback> succe
ssCallback, PassOwnPtr<ErrorCallback> errorCallback) | 152 static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtrWillBeRawPtr<DO
MFileSystem> filesystem, const String& name, const KURL& url, PassOwnPtr<FileCal
lback> successCallback, PassOwnPtr<ErrorCallback> errorCallback) |
| 153 { | 153 { |
| 154 return adoptPtr(static_cast<AsyncFileSystemCallbacks*>(new SnapshotFileC
allback(filesystem, name, url, successCallback, errorCallback))); | 154 return adoptPtr(static_cast<AsyncFileSystemCallbacks*>(new SnapshotFileC
allback(filesystem, name, url, successCallback, errorCallback))); |
| 155 } | 155 } |
| 156 | 156 |
| 157 virtual void didCreateSnapshotFile(const FileMetadata& metadata, PassRefPtr<
BlobDataHandle> snapshot) | 157 virtual void didCreateSnapshotFile(const FileMetadata& metadata, PassRefPtr<
BlobDataHandle> snapshot) |
| 158 { | 158 { |
| 159 if (!m_successCallback) | 159 if (!m_successCallback) |
| 160 return; | 160 return; |
| 161 | 161 |
| 162 // We can't directly use the snapshot blob data handle because the conte
nt type on it hasn't been set. | 162 // We can't directly use the snapshot blob data handle because the conte
nt type on it hasn't been set. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 175 m_successCallback->handleEvent(File::createForFileSystemFile(m_name,
metadata).get()); | 175 m_successCallback->handleEvent(File::createForFileSystemFile(m_name,
metadata).get()); |
| 176 } else { | 176 } else { |
| 177 // Otherwise create a File from the FileSystem URL. | 177 // Otherwise create a File from the FileSystem URL. |
| 178 m_successCallback->handleEvent(File::createForFileSystemFile(m_url,
metadata).get()); | 178 m_successCallback->handleEvent(File::createForFileSystemFile(m_url,
metadata).get()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 m_successCallback.release(); | 181 m_successCallback.release(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 private: | 184 private: |
| 185 SnapshotFileCallback(PassRefPtr<DOMFileSystem> filesystem, const String& nam
e, const KURL& url, PassOwnPtr<FileCallback> successCallback, PassOwnPtr<ErrorC
allback> errorCallback) | 185 SnapshotFileCallback(PassRefPtrWillBeRawPtr<DOMFileSystem> filesystem, const
String& name, const KURL& url, PassOwnPtr<FileCallback> successCallback, PassOw
nPtr<ErrorCallback> errorCallback) |
| 186 : FileSystemCallbacksBase(errorCallback, filesystem.get()) | 186 : FileSystemCallbacksBase(errorCallback, filesystem.get()) |
| 187 , m_name(name) | 187 , m_name(name) |
| 188 , m_url(url) | 188 , m_url(url) |
| 189 , m_successCallback(successCallback) | 189 , m_successCallback(successCallback) |
| 190 { | 190 { |
| 191 } | 191 } |
| 192 | 192 |
| 193 String m_name; | 193 String m_name; |
| 194 KURL m_url; | 194 KURL m_url; |
| 195 OwnPtr<FileCallback> m_successCallback; | 195 OwnPtr<FileCallback> m_successCallback; |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 } // namespace | 198 } // namespace |
| 199 | 199 |
| 200 void DOMFileSystem::createFile(const FileEntry* fileEntry, PassOwnPtr<FileCallba
ck> successCallback, PassOwnPtr<ErrorCallback> errorCallback) | 200 void DOMFileSystem::createFile(const FileEntry* fileEntry, PassOwnPtr<FileCallba
ck> successCallback, PassOwnPtr<ErrorCallback> errorCallback) |
| 201 { | 201 { |
| 202 KURL fileSystemURL = createFileSystemURL(fileEntry); | 202 KURL fileSystemURL = createFileSystemURL(fileEntry); |
| 203 fileSystem()->createSnapshotFileAndReadMetadata(fileSystemURL, SnapshotFileC
allback::create(this, fileEntry->name(), fileSystemURL, successCallback, errorCa
llback)); | 203 fileSystem()->createSnapshotFileAndReadMetadata(fileSystemURL, SnapshotFileC
allback::create(this, fileEntry->name(), fileSystemURL, successCallback, errorCa
llback)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace WebCore | 206 } // namespace WebCore |
| OLD | NEW |