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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 GURL origin_url(frame->document().securityOrigin().toString()); | 117 GURL origin_url(frame->document().securityOrigin().toString()); |
118 file_system_context_->DeleteFileSystem( | 118 file_system_context_->DeleteFileSystem( |
119 origin_url, static_cast<fileapi::FileSystemType>(type), | 119 origin_url, static_cast<fileapi::FileSystemType>(type), |
120 DeleteFileSystemHandler(callbacks)); | 120 DeleteFileSystemHandler(callbacks)); |
121 } | 121 } |
122 | 122 |
123 void SimpleFileSystem::move( | 123 void SimpleFileSystem::move( |
124 const WebURL& src_path, | 124 const WebURL& src_path, |
125 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { | 125 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { |
126 FileSystemURL src_url(src_path); | 126 FileSystemURL src_url(file_system_context()->CrackURL(src_path)); |
127 FileSystemURL dest_url(dest_path); | 127 FileSystemURL dest_url(file_system_context()->CrackURL(dest_path)); |
128 if (!HasFilePermission(src_url, FILE_PERMISSION_WRITE) || | 128 if (!HasFilePermission(src_url, FILE_PERMISSION_WRITE) || |
129 !HasFilePermission(dest_url, FILE_PERMISSION_CREATE)) { | 129 !HasFilePermission(dest_url, FILE_PERMISSION_CREATE)) { |
130 callbacks->didFail(WebKit::WebFileErrorSecurity); | 130 callbacks->didFail(WebKit::WebFileErrorSecurity); |
131 return; | 131 return; |
132 } | 132 } |
133 GetNewOperation(src_url)->Move(src_url, dest_url, | 133 GetNewOperation(src_url)->Move(src_url, dest_url, |
134 FinishHandler(callbacks)); | 134 FinishHandler(callbacks)); |
135 } | 135 } |
136 | 136 |
137 void SimpleFileSystem::copy( | 137 void SimpleFileSystem::copy( |
138 const WebURL& src_path, const WebURL& dest_path, | 138 const WebURL& src_path, const WebURL& dest_path, |
139 WebFileSystemCallbacks* callbacks) { | 139 WebFileSystemCallbacks* callbacks) { |
140 FileSystemURL src_url(src_path); | 140 FileSystemURL src_url(file_system_context()->CrackURL(src_path)); |
141 FileSystemURL dest_url(dest_path); | 141 FileSystemURL dest_url(file_system_context()->CrackURL(dest_path)); |
142 if (!HasFilePermission(src_url, FILE_PERMISSION_READ) || | 142 if (!HasFilePermission(src_url, FILE_PERMISSION_READ) || |
143 !HasFilePermission(dest_url, FILE_PERMISSION_CREATE)) { | 143 !HasFilePermission(dest_url, FILE_PERMISSION_CREATE)) { |
144 callbacks->didFail(WebKit::WebFileErrorSecurity); | 144 callbacks->didFail(WebKit::WebFileErrorSecurity); |
145 return; | 145 return; |
146 } | 146 } |
147 GetNewOperation(src_url)->Copy(src_url, dest_url, | 147 GetNewOperation(src_url)->Copy(src_url, dest_url, |
148 FinishHandler(callbacks)); | 148 FinishHandler(callbacks)); |
149 } | 149 } |
150 | 150 |
151 void SimpleFileSystem::remove( | 151 void SimpleFileSystem::remove( |
152 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 152 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
153 FileSystemURL url(path); | 153 FileSystemURL url(file_system_context()->CrackURL(path)); |
154 if (!HasFilePermission(url, FILE_PERMISSION_WRITE)) { | 154 if (!HasFilePermission(url, FILE_PERMISSION_WRITE)) { |
155 callbacks->didFail(WebKit::WebFileErrorSecurity); | 155 callbacks->didFail(WebKit::WebFileErrorSecurity); |
156 return; | 156 return; |
157 } | 157 } |
158 GetNewOperation(url)->Remove(url, false /* recursive */, | 158 GetNewOperation(url)->Remove(url, false /* recursive */, |
159 FinishHandler(callbacks)); | 159 FinishHandler(callbacks)); |
160 } | 160 } |
161 | 161 |
162 void SimpleFileSystem::removeRecursively( | 162 void SimpleFileSystem::removeRecursively( |
163 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 163 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
164 FileSystemURL url(path); | 164 FileSystemURL url(file_system_context()->CrackURL(path)); |
165 if (!HasFilePermission(url, FILE_PERMISSION_WRITE)) { | 165 if (!HasFilePermission(url, FILE_PERMISSION_WRITE)) { |
166 callbacks->didFail(WebKit::WebFileErrorSecurity); | 166 callbacks->didFail(WebKit::WebFileErrorSecurity); |
167 return; | 167 return; |
168 } | 168 } |
169 GetNewOperation(url)->Remove(url, true /* recursive */, | 169 GetNewOperation(url)->Remove(url, true /* recursive */, |
170 FinishHandler(callbacks)); | 170 FinishHandler(callbacks)); |
171 } | 171 } |
172 | 172 |
173 void SimpleFileSystem::readMetadata( | 173 void SimpleFileSystem::readMetadata( |
174 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 174 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
175 FileSystemURL url(path); | 175 FileSystemURL url(file_system_context()->CrackURL(path)); |
176 if (!HasFilePermission(url, FILE_PERMISSION_READ)) { | 176 if (!HasFilePermission(url, FILE_PERMISSION_READ)) { |
177 callbacks->didFail(WebKit::WebFileErrorSecurity); | 177 callbacks->didFail(WebKit::WebFileErrorSecurity); |
178 return; | 178 return; |
179 } | 179 } |
180 GetNewOperation(url)->GetMetadata(url, GetMetadataHandler(callbacks)); | 180 GetNewOperation(url)->GetMetadata(url, GetMetadataHandler(callbacks)); |
181 } | 181 } |
182 | 182 |
183 void SimpleFileSystem::createFile( | 183 void SimpleFileSystem::createFile( |
184 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 184 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
185 FileSystemURL url(path); | 185 FileSystemURL url(file_system_context()->CrackURL(path)); |
186 if (!HasFilePermission(url, FILE_PERMISSION_CREATE)) { | 186 if (!HasFilePermission(url, FILE_PERMISSION_CREATE)) { |
187 callbacks->didFail(WebKit::WebFileErrorSecurity); | 187 callbacks->didFail(WebKit::WebFileErrorSecurity); |
188 return; | 188 return; |
189 } | 189 } |
190 GetNewOperation(url)->CreateFile(url, exclusive, FinishHandler(callbacks)); | 190 GetNewOperation(url)->CreateFile(url, exclusive, FinishHandler(callbacks)); |
191 } | 191 } |
192 | 192 |
193 void SimpleFileSystem::createDirectory( | 193 void SimpleFileSystem::createDirectory( |
194 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 194 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
195 FileSystemURL url(path); | 195 FileSystemURL url(file_system_context()->CrackURL(path)); |
196 if (!HasFilePermission(url, FILE_PERMISSION_CREATE)) { | 196 if (!HasFilePermission(url, FILE_PERMISSION_CREATE)) { |
197 callbacks->didFail(WebKit::WebFileErrorSecurity); | 197 callbacks->didFail(WebKit::WebFileErrorSecurity); |
198 return; | 198 return; |
199 } | 199 } |
200 GetNewOperation(url)->CreateDirectory(url, exclusive, false, | 200 GetNewOperation(url)->CreateDirectory(url, exclusive, false, |
201 FinishHandler(callbacks)); | 201 FinishHandler(callbacks)); |
202 } | 202 } |
203 | 203 |
204 void SimpleFileSystem::fileExists( | 204 void SimpleFileSystem::fileExists( |
205 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 205 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
206 FileSystemURL url(path); | 206 FileSystemURL url(file_system_context()->CrackURL(path)); |
207 if (!HasFilePermission(url, FILE_PERMISSION_READ)) { | 207 if (!HasFilePermission(url, FILE_PERMISSION_READ)) { |
208 callbacks->didFail(WebKit::WebFileErrorSecurity); | 208 callbacks->didFail(WebKit::WebFileErrorSecurity); |
209 return; | 209 return; |
210 } | 210 } |
211 GetNewOperation(url)->FileExists(url, FinishHandler(callbacks)); | 211 GetNewOperation(url)->FileExists(url, FinishHandler(callbacks)); |
212 } | 212 } |
213 | 213 |
214 void SimpleFileSystem::directoryExists( | 214 void SimpleFileSystem::directoryExists( |
215 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 215 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
216 FileSystemURL url(path); | 216 FileSystemURL url(file_system_context()->CrackURL(path)); |
217 if (!HasFilePermission(url, FILE_PERMISSION_READ)) { | 217 if (!HasFilePermission(url, FILE_PERMISSION_READ)) { |
218 callbacks->didFail(WebKit::WebFileErrorSecurity); | 218 callbacks->didFail(WebKit::WebFileErrorSecurity); |
219 return; | 219 return; |
220 } | 220 } |
221 GetNewOperation(url)->DirectoryExists(url, FinishHandler(callbacks)); | 221 GetNewOperation(url)->DirectoryExists(url, FinishHandler(callbacks)); |
222 } | 222 } |
223 | 223 |
224 void SimpleFileSystem::readDirectory( | 224 void SimpleFileSystem::readDirectory( |
225 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 225 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
226 FileSystemURL url(path); | 226 FileSystemURL url(file_system_context()->CrackURL(path)); |
227 if (!HasFilePermission(url, FILE_PERMISSION_READ)) { | 227 if (!HasFilePermission(url, FILE_PERMISSION_READ)) { |
228 callbacks->didFail(WebKit::WebFileErrorSecurity); | 228 callbacks->didFail(WebKit::WebFileErrorSecurity); |
229 return; | 229 return; |
230 } | 230 } |
231 GetNewOperation(url)->ReadDirectory(url, ReadDirectoryHandler(callbacks)); | 231 GetNewOperation(url)->ReadDirectory(url, ReadDirectoryHandler(callbacks)); |
232 } | 232 } |
233 | 233 |
234 WebFileWriter* SimpleFileSystem::createFileWriter( | 234 WebFileWriter* SimpleFileSystem::createFileWriter( |
235 const WebURL& path, WebFileWriterClient* client) { | 235 const WebURL& path, WebFileWriterClient* client) { |
236 return new SimpleFileWriter(path, client, file_system_context_.get()); | 236 return new SimpleFileWriter(path, client, file_system_context_.get()); |
237 } | 237 } |
238 | 238 |
239 void SimpleFileSystem::createSnapshotFileAndReadMetadata( | 239 void SimpleFileSystem::createSnapshotFileAndReadMetadata( |
240 const WebURL& blobURL, | 240 const WebURL& blobURL, |
241 const WebURL& path, | 241 const WebURL& path, |
242 WebFileSystemCallbacks* callbacks) { | 242 WebFileSystemCallbacks* callbacks) { |
243 FileSystemURL url(path); | 243 FileSystemURL url(file_system_context()->CrackURL(path)); |
244 if (!HasFilePermission(url, FILE_PERMISSION_READ)) { | 244 if (!HasFilePermission(url, FILE_PERMISSION_READ)) { |
245 callbacks->didFail(WebKit::WebFileErrorSecurity); | 245 callbacks->didFail(WebKit::WebFileErrorSecurity); |
246 return; | 246 return; |
247 } | 247 } |
248 GetNewOperation(url)->CreateSnapshotFile( | 248 GetNewOperation(url)->CreateSnapshotFile( |
249 url, SnapshotFileHandler(blobURL, callbacks)); | 249 url, SnapshotFileHandler(blobURL, callbacks)); |
250 } | 250 } |
251 | 251 |
252 // static | 252 // static |
253 void SimpleFileSystem::InitializeOnIOThread( | 253 void SimpleFileSystem::InitializeOnIOThread( |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 const FilePath& platform_path, | 389 const FilePath& platform_path, |
390 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 390 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
391 DCHECK(g_io_thread); | 391 DCHECK(g_io_thread); |
392 if (result == base::PLATFORM_FILE_OK) { | 392 if (result == base::PLATFORM_FILE_OK) { |
393 g_io_thread->PostTask( | 393 g_io_thread->PostTask( |
394 FROM_HERE, | 394 FROM_HERE, |
395 base::Bind(&RegisterBlob, blob_url, platform_path)); | 395 base::Bind(&RegisterBlob, blob_url, platform_path)); |
396 } | 396 } |
397 DidGetMetadata(callbacks, result, info, platform_path); | 397 DidGetMetadata(callbacks, result, info, platform_path); |
398 } | 398 } |
OLD | NEW |