2012-02-17 15:51:20 +01:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
2010-10-03 22:35:06 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/browser_file_system.h"
|
|
|
|
#include "libcef/browser_file_writer.h"
|
2012-10-01 23:49:08 +02:00
|
|
|
#include "libcef/cef_context.h"
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/cef_thread.h"
|
2010-10-03 22:35:06 +02:00
|
|
|
|
2012-02-18 01:19:52 +01:00
|
|
|
#include "base/bind.h"
|
2013-02-28 22:54:02 +01:00
|
|
|
#include "base/files/file_path.h"
|
2010-12-16 22:54:42 +01:00
|
|
|
#include "base/message_loop.h"
|
2010-10-03 22:35:06 +02:00
|
|
|
#include "base/message_loop_proxy.h"
|
|
|
|
#include "base/time.h"
|
2010-12-16 22:54:42 +01:00
|
|
|
#include "base/utf_string_conversions.h"
|
|
|
|
#include "googleurl/src/gurl.h"
|
2012-04-05 00:32:24 +02:00
|
|
|
#include "net/base/mime_util.h"
|
2013-02-28 22:54:02 +01:00
|
|
|
#include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h"
|
2013-02-26 00:44:37 +01:00
|
|
|
#include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
|
|
|
|
#include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h"
|
2011-07-03 02:03:30 +02:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemEntry.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
|
2012-11-06 18:13:58 +01:00
|
|
|
#include "webkit/base/file_path_string_conversions.h"
|
2012-04-05 00:32:24 +02:00
|
|
|
#include "webkit/blob/blob_storage_controller.h"
|
2013-02-26 00:44:37 +01:00
|
|
|
#include "webkit/fileapi/external_mount_points.h"
|
2013-02-28 22:54:02 +01:00
|
|
|
#include "webkit/fileapi/file_permission_policy.h"
|
|
|
|
#include "webkit/fileapi/file_system_mount_point_provider.h"
|
2012-08-29 22:11:26 +02:00
|
|
|
#include "webkit/fileapi/file_system_task_runners.h"
|
2012-08-07 15:58:35 +02:00
|
|
|
#include "webkit/fileapi/file_system_url.h"
|
2012-06-21 22:35:13 +02:00
|
|
|
#include "webkit/fileapi/file_system_util.h"
|
2012-02-17 15:51:20 +01:00
|
|
|
#include "webkit/fileapi/mock_file_system_options.h"
|
2010-10-03 22:35:06 +02:00
|
|
|
|
2010-12-16 22:54:42 +01:00
|
|
|
using base::WeakPtr;
|
|
|
|
|
2010-10-03 22:35:06 +02:00
|
|
|
using WebKit::WebFileInfo;
|
2010-12-16 22:54:42 +01:00
|
|
|
using WebKit::WebFileSystem;
|
2010-10-03 22:35:06 +02:00
|
|
|
using WebKit::WebFileSystemCallbacks;
|
|
|
|
using WebKit::WebFileSystemEntry;
|
2010-10-15 20:37:25 +02:00
|
|
|
using WebKit::WebFileWriter;
|
|
|
|
using WebKit::WebFileWriterClient;
|
2010-12-16 22:54:42 +01:00
|
|
|
using WebKit::WebFrame;
|
|
|
|
using WebKit::WebSecurityOrigin;
|
2010-10-03 22:35:06 +02:00
|
|
|
using WebKit::WebString;
|
2011-07-03 02:03:30 +02:00
|
|
|
using WebKit::WebURL;
|
2010-10-03 22:35:06 +02:00
|
|
|
using WebKit::WebVector;
|
|
|
|
|
2012-04-05 00:32:24 +02:00
|
|
|
using webkit_blob::BlobData;
|
|
|
|
using webkit_blob::BlobStorageController;
|
2011-02-15 19:07:24 +01:00
|
|
|
using fileapi::FileSystemContext;
|
2012-08-29 22:11:26 +02:00
|
|
|
using fileapi::FileSystemOperation;
|
|
|
|
using fileapi::FileSystemTaskRunners;
|
|
|
|
using fileapi::FileSystemURL;
|
2010-12-16 22:54:42 +01:00
|
|
|
|
2012-04-05 00:32:24 +02:00
|
|
|
namespace {
|
|
|
|
MessageLoop* g_io_thread;
|
|
|
|
webkit_blob::BlobStorageController* g_blob_storage_controller;
|
|
|
|
|
2013-02-26 00:44:37 +01:00
|
|
|
void RegisterBlob(const GURL& blob_url, const base::FilePath& file_path) {
|
2012-04-05 00:32:24 +02:00
|
|
|
DCHECK(g_blob_storage_controller);
|
|
|
|
|
2013-02-26 00:44:37 +01:00
|
|
|
base::FilePath::StringType extension = file_path.Extension();
|
2012-04-05 00:32:24 +02:00
|
|
|
if (!extension.empty())
|
|
|
|
extension = extension.substr(1); // Strip leading ".".
|
|
|
|
|
|
|
|
// This may fail, but then we'll be just setting the empty mime type.
|
|
|
|
std::string mime_type;
|
|
|
|
net::GetWellKnownMimeTypeFromExtension(extension, &mime_type);
|
|
|
|
|
|
|
|
BlobData::Item item;
|
2012-08-29 22:11:26 +02:00
|
|
|
item.SetToFilePathRange(file_path, 0, -1, base::Time());
|
2012-04-05 00:32:24 +02:00
|
|
|
g_blob_storage_controller->StartBuildingBlob(blob_url);
|
|
|
|
g_blob_storage_controller->AppendBlobDataItem(blob_url, item);
|
|
|
|
g_blob_storage_controller->FinishBuildingBlob(blob_url, mime_type);
|
2011-12-06 11:16:51 +01:00
|
|
|
}
|
|
|
|
|
2012-04-05 00:32:24 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
BrowserFileSystem::BrowserFileSystem() {
|
2011-12-06 11:16:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::CreateContext() {
|
|
|
|
if (file_system_context_.get())
|
|
|
|
return;
|
2012-10-01 23:49:08 +02:00
|
|
|
std::vector<std::string> additional_allowed_schemes;
|
|
|
|
additional_allowed_schemes.push_back("file");
|
|
|
|
|
|
|
|
file_system_context_ = new FileSystemContext(
|
|
|
|
make_scoped_ptr(new FileSystemTaskRunners(
|
|
|
|
CefThread::GetMessageLoopProxyForThread(CefThread::IO),
|
|
|
|
CefThread::GetMessageLoopProxyForThread(CefThread::FILE),
|
|
|
|
CefThread::GetMessageLoopProxyForThread(CefThread::FILE))),
|
2013-02-26 00:44:37 +01:00
|
|
|
fileapi::ExternalMountPoints::CreateRefCounted().get(),
|
2012-10-01 23:49:08 +02:00
|
|
|
NULL /* special storage policy */,
|
|
|
|
NULL /* quota manager */,
|
|
|
|
_Context->cache_path(),
|
|
|
|
fileapi::FileSystemOptions(
|
|
|
|
fileapi::FileSystemOptions::PROFILE_MODE_NORMAL,
|
|
|
|
additional_allowed_schemes));
|
2010-12-16 22:54:42 +01:00
|
|
|
}
|
2010-10-03 22:35:06 +02:00
|
|
|
|
2012-04-05 00:32:24 +02:00
|
|
|
BrowserFileSystem::~BrowserFileSystem() {
|
|
|
|
}
|
|
|
|
|
2010-12-16 22:54:42 +01:00
|
|
|
void BrowserFileSystem::OpenFileSystem(
|
2012-08-29 22:11:26 +02:00
|
|
|
WebFrame* frame, WebFileSystem::Type type,
|
2012-01-10 00:46:23 +01:00
|
|
|
long long, bool create, // NOLINT(runtime/int)
|
2010-12-16 22:54:42 +01:00
|
|
|
WebFileSystemCallbacks* callbacks) {
|
2011-02-15 19:07:24 +01:00
|
|
|
if (!frame || !file_system_context_.get()) {
|
2010-12-16 22:54:42 +01:00
|
|
|
// The FileSystem temp directory was not initialized successfully.
|
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-29 22:11:26 +02:00
|
|
|
GURL origin_url(frame->document().securityOrigin().toString());
|
|
|
|
file_system_context_->OpenFileSystem(
|
|
|
|
origin_url, static_cast<fileapi::FileSystemType>(type), create,
|
|
|
|
OpenFileSystemHandler(callbacks));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::DeleteFileSystem(
|
|
|
|
WebFrame* frame, WebFileSystem::Type type,
|
|
|
|
WebFileSystemCallbacks* callbacks) {
|
|
|
|
if (!frame || !file_system_context_.get()) {
|
2010-12-16 22:54:42 +01:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-03 02:03:30 +02:00
|
|
|
GURL origin_url(frame->document().securityOrigin().toString());
|
2012-08-29 22:11:26 +02:00
|
|
|
file_system_context_->DeleteFileSystem(
|
|
|
|
origin_url, static_cast<fileapi::FileSystemType>(type),
|
|
|
|
DeleteFileSystemHandler(callbacks));
|
2010-10-03 22:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::move(
|
2011-07-03 02:03:30 +02:00
|
|
|
const WebURL& src_path,
|
|
|
|
const WebURL& dest_path, WebFileSystemCallbacks* callbacks) {
|
2013-02-26 00:44:37 +01:00
|
|
|
FileSystemURL src_url(file_system_context()->CrackURL(src_path));
|
|
|
|
FileSystemURL dest_url(file_system_context()->CrackURL(dest_path));
|
2013-02-28 22:54:02 +01:00
|
|
|
if (!HasFilePermission(src_url, fileapi::kWriteFilePermissions) ||
|
|
|
|
!HasFilePermission(dest_url, fileapi::kCreateFilePermissions)) {
|
2012-08-07 15:58:35 +02:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(src_url)->Move(src_url, dest_url,
|
|
|
|
FinishHandler(callbacks));
|
2010-10-03 22:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::copy(
|
2011-07-03 02:03:30 +02:00
|
|
|
const WebURL& src_path, const WebURL& dest_path,
|
2010-10-03 22:35:06 +02:00
|
|
|
WebFileSystemCallbacks* callbacks) {
|
2013-02-26 00:44:37 +01:00
|
|
|
FileSystemURL src_url(file_system_context()->CrackURL(src_path));
|
|
|
|
FileSystemURL dest_url(file_system_context()->CrackURL(dest_path));
|
2013-02-28 22:54:02 +01:00
|
|
|
if (!HasFilePermission(src_url, fileapi::kReadFilePermissions) ||
|
|
|
|
!HasFilePermission(dest_url, fileapi::kCreateFilePermissions)) {
|
2012-08-07 15:58:35 +02:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(src_url)->Copy(src_url, dest_url,
|
|
|
|
FinishHandler(callbacks));
|
2010-10-03 22:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::remove(
|
2011-07-03 02:03:30 +02:00
|
|
|
const WebURL& path, WebFileSystemCallbacks* callbacks) {
|
2013-02-26 00:44:37 +01:00
|
|
|
FileSystemURL url(file_system_context()->CrackURL(path));
|
2013-02-28 22:54:02 +01:00
|
|
|
if (!HasFilePermission(url, fileapi::kWriteFilePermissions)) {
|
2012-08-07 15:58:35 +02:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(url)->Remove(url, false /* recursive */,
|
|
|
|
FinishHandler(callbacks));
|
2010-10-15 20:37:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::removeRecursively(
|
2011-07-03 02:03:30 +02:00
|
|
|
const WebURL& path, WebFileSystemCallbacks* callbacks) {
|
2013-02-26 00:44:37 +01:00
|
|
|
FileSystemURL url(file_system_context()->CrackURL(path));
|
2013-02-28 22:54:02 +01:00
|
|
|
if (!HasFilePermission(url, fileapi::kWriteFilePermissions)) {
|
2012-08-07 15:58:35 +02:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(url)->Remove(url, true /* recursive */,
|
|
|
|
FinishHandler(callbacks));
|
2010-10-03 22:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::readMetadata(
|
2011-07-03 02:03:30 +02:00
|
|
|
const WebURL& path, WebFileSystemCallbacks* callbacks) {
|
2013-02-26 00:44:37 +01:00
|
|
|
FileSystemURL url(file_system_context()->CrackURL(path));
|
2013-02-28 22:54:02 +01:00
|
|
|
if (!HasFilePermission(url, fileapi::kReadFilePermissions)) {
|
2012-08-07 15:58:35 +02:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(url)->GetMetadata(url, GetMetadataHandler(callbacks));
|
2010-10-03 22:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::createFile(
|
2011-07-03 02:03:30 +02:00
|
|
|
const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) {
|
2013-02-26 00:44:37 +01:00
|
|
|
FileSystemURL url(file_system_context()->CrackURL(path));
|
2013-02-28 22:54:02 +01:00
|
|
|
if (!HasFilePermission(url, fileapi::kCreateFilePermissions)) {
|
2012-08-07 15:58:35 +02:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(url)->CreateFile(url, exclusive, FinishHandler(callbacks));
|
2010-10-03 22:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::createDirectory(
|
2011-07-03 02:03:30 +02:00
|
|
|
const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) {
|
2013-02-26 00:44:37 +01:00
|
|
|
FileSystemURL url(file_system_context()->CrackURL(path));
|
2013-02-28 22:54:02 +01:00
|
|
|
if (!HasFilePermission(url, fileapi::kCreateFilePermissions)) {
|
2012-08-07 15:58:35 +02:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(url)->CreateDirectory(url, exclusive, false,
|
|
|
|
FinishHandler(callbacks));
|
2010-10-03 22:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::fileExists(
|
2011-07-03 02:03:30 +02:00
|
|
|
const WebURL& path, WebFileSystemCallbacks* callbacks) {
|
2013-02-26 00:44:37 +01:00
|
|
|
FileSystemURL url(file_system_context()->CrackURL(path));
|
2013-02-28 22:54:02 +01:00
|
|
|
if (!HasFilePermission(url, fileapi::kReadFilePermissions)) {
|
2012-08-07 15:58:35 +02:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(url)->FileExists(url, FinishHandler(callbacks));
|
2010-10-03 22:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::directoryExists(
|
2011-07-03 02:03:30 +02:00
|
|
|
const WebURL& path, WebFileSystemCallbacks* callbacks) {
|
2013-02-26 00:44:37 +01:00
|
|
|
FileSystemURL url(file_system_context()->CrackURL(path));
|
2013-02-28 22:54:02 +01:00
|
|
|
if (!HasFilePermission(url, fileapi::kReadFilePermissions)) {
|
2012-08-07 15:58:35 +02:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(url)->DirectoryExists(url, FinishHandler(callbacks));
|
2010-10-03 22:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::readDirectory(
|
2011-07-03 02:03:30 +02:00
|
|
|
const WebURL& path, WebFileSystemCallbacks* callbacks) {
|
2013-02-26 00:44:37 +01:00
|
|
|
FileSystemURL url(file_system_context()->CrackURL(path));
|
2013-02-28 22:54:02 +01:00
|
|
|
if (!HasFilePermission(url, fileapi::kReadFilePermissions)) {
|
2012-08-07 15:58:35 +02:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(url)->ReadDirectory(url, ReadDirectoryHandler(callbacks));
|
2010-10-03 22:35:06 +02:00
|
|
|
}
|
|
|
|
|
2010-10-15 20:37:25 +02:00
|
|
|
WebFileWriter* BrowserFileSystem::createFileWriter(
|
2011-07-03 02:03:30 +02:00
|
|
|
const WebURL& path, WebFileWriterClient* client) {
|
|
|
|
return new BrowserFileWriter(path, client, file_system_context_.get());
|
2010-10-15 20:37:25 +02:00
|
|
|
}
|
|
|
|
|
2013-02-28 22:54:02 +01:00
|
|
|
void BrowserFileSystem::createSnapshotFileAndReadMetadata(
|
|
|
|
const WebURL& path,
|
|
|
|
WebFileSystemCallbacks* callbacks) {
|
|
|
|
FileSystemURL url(file_system_context()->CrackURL(path));
|
|
|
|
if (!HasFilePermission(url, fileapi::kReadFilePermissions)) {
|
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(url)->CreateSnapshotFile(
|
|
|
|
url, SnapshotFileHandler(callbacks));
|
|
|
|
}
|
|
|
|
|
|
|
|
// DEPRECATED
|
2012-04-05 00:32:24 +02:00
|
|
|
void BrowserFileSystem::createSnapshotFileAndReadMetadata(
|
|
|
|
const WebURL& blobURL,
|
|
|
|
const WebURL& path,
|
|
|
|
WebFileSystemCallbacks* callbacks) {
|
2013-02-26 00:44:37 +01:00
|
|
|
FileSystemURL url(file_system_context()->CrackURL(path));
|
2013-02-28 22:54:02 +01:00
|
|
|
if (!HasFilePermission(url, fileapi::kReadFilePermissions)) {
|
2012-08-07 15:58:35 +02:00
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetNewOperation(url)->CreateSnapshotFile(
|
2013-02-28 22:54:02 +01:00
|
|
|
url, SnapshotFileHandler_Deprecated(blobURL, callbacks));
|
2012-04-05 00:32:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void BrowserFileSystem::InitializeOnIOThread(
|
|
|
|
webkit_blob::BlobStorageController* blob_storage_controller) {
|
|
|
|
g_io_thread = MessageLoop::current();
|
|
|
|
g_blob_storage_controller = blob_storage_controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void BrowserFileSystem::CleanupOnIOThread() {
|
|
|
|
g_io_thread = NULL;
|
|
|
|
g_blob_storage_controller = NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-07 15:58:35 +02:00
|
|
|
bool BrowserFileSystem::HasFilePermission(
|
2013-02-28 22:54:02 +01:00
|
|
|
const fileapi::FileSystemURL& url, int permissions) {
|
|
|
|
if (!url.is_valid())
|
|
|
|
return false;
|
|
|
|
fileapi::FileSystemMountPointProvider* mount_point_provider =
|
|
|
|
file_system_context_->GetMountPointProvider(url.type());
|
|
|
|
DCHECK(mount_point_provider);
|
|
|
|
// In test_shell we don't perform further detailed security checks if it's
|
|
|
|
// not specifically forbidden by ALWAYS_DENY.
|
|
|
|
return (mount_point_provider->GetPermissionPolicy(url, permissions)
|
|
|
|
!= fileapi::FILE_PERMISSION_ALWAYS_DENY);
|
2012-08-07 15:58:35 +02:00
|
|
|
}
|
|
|
|
|
2012-08-29 22:11:26 +02:00
|
|
|
FileSystemOperation* BrowserFileSystem::GetNewOperation(
|
2012-08-07 15:58:35 +02:00
|
|
|
const fileapi::FileSystemURL& url) {
|
2012-10-03 23:50:01 +02:00
|
|
|
return file_system_context_->CreateFileSystemOperation(url, NULL);
|
2011-09-11 00:05:55 +02:00
|
|
|
}
|
2012-02-18 01:19:52 +01:00
|
|
|
|
2012-08-29 22:11:26 +02:00
|
|
|
FileSystemOperation::StatusCallback
|
2012-02-18 01:19:52 +01:00
|
|
|
BrowserFileSystem::FinishHandler(WebFileSystemCallbacks* callbacks) {
|
|
|
|
return base::Bind(&BrowserFileSystem::DidFinish,
|
|
|
|
AsWeakPtr(), base::Unretained(callbacks));
|
|
|
|
}
|
|
|
|
|
2012-08-29 22:11:26 +02:00
|
|
|
FileSystemOperation::ReadDirectoryCallback
|
2012-02-18 01:19:52 +01:00
|
|
|
BrowserFileSystem::ReadDirectoryHandler(WebFileSystemCallbacks* callbacks) {
|
|
|
|
return base::Bind(&BrowserFileSystem::DidReadDirectory,
|
|
|
|
AsWeakPtr(), base::Unretained(callbacks));
|
|
|
|
}
|
|
|
|
|
2012-08-29 22:11:26 +02:00
|
|
|
FileSystemOperation::GetMetadataCallback
|
2012-02-18 01:19:52 +01:00
|
|
|
BrowserFileSystem::GetMetadataHandler(WebFileSystemCallbacks* callbacks) {
|
|
|
|
return base::Bind(&BrowserFileSystem::DidGetMetadata,
|
|
|
|
AsWeakPtr(), base::Unretained(callbacks));
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSystemContext::OpenFileSystemCallback
|
|
|
|
BrowserFileSystem::OpenFileSystemHandler(WebFileSystemCallbacks* callbacks) {
|
|
|
|
return base::Bind(&BrowserFileSystem::DidOpenFileSystem,
|
|
|
|
AsWeakPtr(), base::Unretained(callbacks));
|
|
|
|
}
|
|
|
|
|
2012-08-29 22:11:26 +02:00
|
|
|
FileSystemContext::DeleteFileSystemCallback
|
|
|
|
BrowserFileSystem::DeleteFileSystemHandler(WebFileSystemCallbacks* callbacks) {
|
|
|
|
return base::Bind(&BrowserFileSystem::DidDeleteFileSystem,
|
|
|
|
AsWeakPtr(), callbacks);
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSystemOperation::SnapshotFileCallback
|
2013-02-28 22:54:02 +01:00
|
|
|
BrowserFileSystem::SnapshotFileHandler(
|
|
|
|
WebFileSystemCallbacks* callbacks) {
|
2012-04-05 00:32:24 +02:00
|
|
|
return base::Bind(&BrowserFileSystem::DidCreateSnapshotFile,
|
2013-02-28 22:54:02 +01:00
|
|
|
AsWeakPtr(), base::Unretained(callbacks));
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSystemOperation::SnapshotFileCallback
|
|
|
|
BrowserFileSystem::SnapshotFileHandler_Deprecated(
|
|
|
|
const GURL& blob_url,
|
|
|
|
WebFileSystemCallbacks* callbacks) {
|
|
|
|
return base::Bind(&BrowserFileSystem::DidCreateSnapshotFile_Deprecated,
|
2012-04-05 00:32:24 +02:00
|
|
|
AsWeakPtr(), blob_url, base::Unretained(callbacks));
|
|
|
|
}
|
|
|
|
|
2012-02-18 01:19:52 +01:00
|
|
|
void BrowserFileSystem::DidFinish(WebFileSystemCallbacks* callbacks,
|
|
|
|
base::PlatformFileError result) {
|
|
|
|
if (result == base::PLATFORM_FILE_OK)
|
|
|
|
callbacks->didSucceed();
|
|
|
|
else
|
2012-06-21 22:35:13 +02:00
|
|
|
callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result));
|
2012-02-18 01:19:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::DidGetMetadata(WebFileSystemCallbacks* callbacks,
|
|
|
|
base::PlatformFileError result,
|
|
|
|
const base::PlatformFileInfo& info,
|
2013-02-26 00:44:37 +01:00
|
|
|
const base::FilePath& platform_path) {
|
2012-02-18 01:19:52 +01:00
|
|
|
if (result == base::PLATFORM_FILE_OK) {
|
|
|
|
WebFileInfo web_file_info;
|
|
|
|
web_file_info.length = info.size;
|
|
|
|
web_file_info.modificationTime = info.last_modified.ToDoubleT();
|
|
|
|
web_file_info.type = info.is_directory ?
|
|
|
|
WebFileInfo::TypeDirectory : WebFileInfo::TypeFile;
|
|
|
|
web_file_info.platformPath =
|
2012-11-06 18:13:58 +01:00
|
|
|
webkit_base::FilePathToWebString(platform_path);
|
2012-02-18 01:19:52 +01:00
|
|
|
callbacks->didReadMetadata(web_file_info);
|
|
|
|
} else {
|
2012-06-21 22:35:13 +02:00
|
|
|
callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result));
|
2012-02-18 01:19:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::DidReadDirectory(
|
|
|
|
WebFileSystemCallbacks* callbacks,
|
|
|
|
base::PlatformFileError result,
|
|
|
|
const std::vector<base::FileUtilProxy::Entry>& entries,
|
|
|
|
bool has_more) {
|
|
|
|
if (result == base::PLATFORM_FILE_OK) {
|
|
|
|
std::vector<WebFileSystemEntry> web_entries_vector;
|
|
|
|
for (std::vector<base::FileUtilProxy::Entry>::const_iterator it =
|
|
|
|
entries.begin(); it != entries.end(); ++it) {
|
|
|
|
WebFileSystemEntry entry;
|
2012-11-06 18:13:58 +01:00
|
|
|
entry.name = webkit_base::FilePathStringToWebString(it->name);
|
2012-02-18 01:19:52 +01:00
|
|
|
entry.isDirectory = it->is_directory;
|
|
|
|
web_entries_vector.push_back(entry);
|
|
|
|
}
|
|
|
|
WebVector<WebKit::WebFileSystemEntry> web_entries = web_entries_vector;
|
|
|
|
callbacks->didReadDirectory(web_entries, has_more);
|
|
|
|
} else {
|
2012-06-21 22:35:13 +02:00
|
|
|
callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result));
|
2012-02-18 01:19:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::DidOpenFileSystem(
|
|
|
|
WebFileSystemCallbacks* callbacks,
|
|
|
|
base::PlatformFileError result,
|
|
|
|
const std::string& name, const GURL& root) {
|
|
|
|
if (result == base::PLATFORM_FILE_OK) {
|
|
|
|
if (!root.is_valid())
|
|
|
|
callbacks->didFail(WebKit::WebFileErrorSecurity);
|
|
|
|
else
|
|
|
|
callbacks->didOpenFileSystem(WebString::fromUTF8(name), root);
|
|
|
|
} else {
|
2012-06-21 22:35:13 +02:00
|
|
|
callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result));
|
2012-02-18 01:19:52 +01:00
|
|
|
}
|
|
|
|
}
|
2012-04-05 00:32:24 +02:00
|
|
|
|
2012-08-29 22:11:26 +02:00
|
|
|
void BrowserFileSystem::DidDeleteFileSystem(
|
|
|
|
WebFileSystemCallbacks* callbacks,
|
|
|
|
base::PlatformFileError result) {
|
|
|
|
if (result == base::PLATFORM_FILE_OK)
|
|
|
|
callbacks->didSucceed();
|
|
|
|
else
|
|
|
|
callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result));
|
|
|
|
}
|
|
|
|
|
2012-04-05 00:32:24 +02:00
|
|
|
void BrowserFileSystem::DidCreateSnapshotFile(
|
2013-02-28 22:54:02 +01:00
|
|
|
WebFileSystemCallbacks* callbacks,
|
|
|
|
base::PlatformFileError result,
|
|
|
|
const base::PlatformFileInfo& info,
|
|
|
|
const base::FilePath& platform_path,
|
|
|
|
const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
|
|
|
|
if (result == base::PLATFORM_FILE_OK) {
|
|
|
|
WebFileInfo web_file_info;
|
|
|
|
web_file_info.length = info.size;
|
|
|
|
web_file_info.modificationTime = info.last_modified.ToDoubleT();
|
|
|
|
web_file_info.type = info.is_directory ?
|
|
|
|
WebFileInfo::TypeDirectory : WebFileInfo::TypeFile;
|
|
|
|
web_file_info.platformPath =
|
|
|
|
webkit_base::FilePathToWebString(platform_path);
|
|
|
|
callbacks->didCreateSnapshotFile(web_file_info);
|
|
|
|
} else {
|
|
|
|
callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserFileSystem::DidCreateSnapshotFile_Deprecated(
|
2012-04-05 00:32:24 +02:00
|
|
|
const GURL& blob_url,
|
|
|
|
WebFileSystemCallbacks* callbacks,
|
|
|
|
base::PlatformFileError result,
|
|
|
|
const base::PlatformFileInfo& info,
|
2013-02-26 00:44:37 +01:00
|
|
|
const base::FilePath& platform_path,
|
2012-04-05 00:32:24 +02:00
|
|
|
const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
|
|
|
|
DCHECK(g_io_thread);
|
|
|
|
if (result == base::PLATFORM_FILE_OK) {
|
|
|
|
g_io_thread->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
base::Bind(&RegisterBlob, blob_url, platform_path));
|
|
|
|
}
|
|
|
|
DidGetMetadata(callbacks, result, info, platform_path);
|
|
|
|
}
|