diff options
author | hamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-12 13:54:19 +0000 |
---|---|---|
committer | hamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-12 13:54:19 +0000 |
commit | b275654c52912f71c07583f18ac42489917f010e (patch) | |
tree | dccf38968911548c0065758bca36f8654d79c507 | |
parent | 4863d5d37c640d6cce19314fc05f459925715c0c (diff) | |
download | chromium_src-b275654c52912f71c07583f18ac42489917f010e.zip chromium_src-b275654c52912f71c07583f18ac42489917f010e.tar.gz chromium_src-b275654c52912f71c07583f18ac42489917f010e.tar.bz2 |
Allow RequestOSFileHandle if an app has unlimited storage
When FileIO::Open is called and renderer gets file handle from process,
the IPC also passes the info of quota limit.
BUG=224123, 224753
TEST=browser_tests, trybots
Review URL: https://chromiumcodereview.appspot.com/13508005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193914 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/ppapi/ppapi_test.cc | 3 | ||||
-rw-r--r-- | content/browser/fileapi/fileapi_message_filter.cc | 22 | ||||
-rw-r--r-- | content/common/fileapi/file_system_dispatcher.cc | 7 | ||||
-rw-r--r-- | content/common/fileapi/file_system_dispatcher.h | 4 | ||||
-rw-r--r-- | content/common/fileapi/file_system_messages.h | 7 | ||||
-rw-r--r-- | content/renderer/pepper/pepper_directory_reader_host.cc | 3 | ||||
-rw-r--r-- | content/renderer/pepper/pepper_file_io_host.cc | 12 | ||||
-rw-r--r-- | content/renderer/pepper/pepper_file_io_host.h | 4 | ||||
-rw-r--r-- | content/renderer/pepper/pepper_plugin_delegate_impl.cc | 5 | ||||
-rw-r--r-- | webkit/fileapi/file_system_callback_dispatcher.cc | 2 | ||||
-rw-r--r-- | webkit/fileapi/file_system_callback_dispatcher.h | 5 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 1 | ||||
-rw-r--r-- | webkit/quota/quota_types.h | 6 |
13 files changed, 63 insertions, 18 deletions
diff --git a/chrome/test/ppapi/ppapi_test.cc b/chrome/test/ppapi/ppapi_test.cc index 4cc99f4..d0ab8da 100644 --- a/chrome/test/ppapi/ppapi_test.cc +++ b/chrome/test/ppapi/ppapi_test.cc @@ -133,8 +133,7 @@ void PPAPITestBase::SetUpCommandLine(CommandLine* command_line) { command_line->AppendSwitch(switches::kDisableSmoothScrolling); // For TestRequestOSFileHandle. - command_line->AppendSwitchASCII(switches::kAllowRequestOSFileHandleAPI, - "127.0.0.1"); + command_line->AppendSwitch(switches::kUnlimitedStorage); } void PPAPITestBase::SetUpOnMainThread() { diff --git a/content/browser/fileapi/fileapi_message_filter.cc b/content/browser/fileapi/fileapi_message_filter.cc index 7472115..ac81220 100644 --- a/content/browser/fileapi/fileapi_message_filter.cc +++ b/content/browser/fileapi/fileapi_message_filter.cc @@ -35,6 +35,7 @@ #include "webkit/fileapi/isolated_context.h" #include "webkit/fileapi/local_file_system_operation.h" #include "webkit/fileapi/sandbox_mount_point_provider.h" +#include "webkit/quota/quota_manager.h" using fileapi::FileSystemFileUtil; using fileapi::FileSystemMountPointProvider; @@ -691,9 +692,26 @@ void FileAPIMessageFilter::DidOpenFile(int request_id, IPC::GetFileHandleForProcess(file, peer_handle, true) : IPC::InvalidPlatformFileForTransit(); open_filesystem_urls_.insert(path); - Send(new FileSystemMsg_DidOpenFile(request_id, file_for_transit)); + + quota::QuotaLimitType quota_policy = quota::kQuotaLimitTypeUnknown; + quota::QuotaManagerProxy* quota_manager_proxy = + context_->quota_manager_proxy(); + CHECK(quota_manager_proxy); + CHECK(quota_manager_proxy->quota_manager()); + FileSystemURL url = context_->CrackURL(path); + if (quota_manager_proxy->quota_manager()->IsStorageUnlimited( + url.origin(), FileSystemTypeToQuotaStorageType(url.type()))) { + quota_policy = quota::kQuotaLimitTypeUnlimited; + } else { + quota_policy = quota::kQuotaLimitTypeLimited; + } + + Send(new FileSystemMsg_DidOpenFile(request_id, + file_for_transit, + quota_policy)); } else { - Send(new FileSystemMsg_DidFail(request_id, result)); + Send(new FileSystemMsg_DidFail(request_id, + result)); } UnregisterOperation(request_id); } diff --git a/content/common/fileapi/file_system_dispatcher.cc b/content/common/fileapi/file_system_dispatcher.cc index e80bc04..447df4a 100644 --- a/content/common/fileapi/file_system_dispatcher.cc +++ b/content/common/fileapi/file_system_dispatcher.cc @@ -351,11 +351,14 @@ void FileSystemDispatcher::OnDidWrite( } void FileSystemDispatcher::OnDidOpenFile( - int request_id, IPC::PlatformFileForTransit file) { + int request_id, + IPC::PlatformFileForTransit file, + quota::QuotaLimitType quota_policy) { fileapi::FileSystemCallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); DCHECK(dispatcher); - dispatcher->DidOpenFile(IPC::PlatformFileForTransitToPlatformFile(file)); + dispatcher->DidOpenFile(IPC::PlatformFileForTransitToPlatformFile(file), + quota_policy); dispatchers_.Remove(request_id); } diff --git a/content/common/fileapi/file_system_dispatcher.h b/content/common/fileapi/file_system_dispatcher.h index 9732b09..1940c9e 100644 --- a/content/common/fileapi/file_system_dispatcher.h +++ b/content/common/fileapi/file_system_dispatcher.h @@ -16,6 +16,7 @@ #include "ipc/ipc_platform_file.h" #include "webkit/fileapi/file_system_callback_dispatcher.h" #include "webkit/fileapi/file_system_types.h" +#include "webkit/quota/quota_types.h" namespace base { class FilePath; @@ -119,7 +120,8 @@ class FileSystemDispatcher : public IPC::Listener { void OnDidWrite(int request_id, int64 bytes, bool complete); void OnDidOpenFile( int request_id, - IPC::PlatformFileForTransit file); + IPC::PlatformFileForTransit file, + quota::QuotaLimitType quota_policy); IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer> dispatchers_; diff --git a/content/common/fileapi/file_system_messages.h b/content/common/fileapi/file_system_messages.h index ef2f8bb..7eb3ef3 100644 --- a/content/common/fileapi/file_system_messages.h +++ b/content/common/fileapi/file_system_messages.h @@ -10,6 +10,7 @@ #include "ipc/ipc_message_macros.h" #include "ipc/ipc_platform_file.h" #include "webkit/fileapi/file_system_types.h" +#include "webkit/quota/quota_types.h" #define IPC_MESSAGE_START FileSystemMsgStart @@ -19,6 +20,7 @@ IPC_STRUCT_TRAITS_BEGIN(base::FileUtilProxy::Entry) IPC_STRUCT_TRAITS_END() IPC_ENUM_TRAITS(fileapi::FileSystemType) +IPC_ENUM_TRAITS(quota::QuotaLimitType) // File system messages sent from the browser to the child process. @@ -47,9 +49,10 @@ IPC_MESSAGE_CONTROL3(FileSystemMsg_DidWrite, int /* request_id */, int64 /* byte count */, bool /* complete */) -IPC_MESSAGE_CONTROL2(FileSystemMsg_DidOpenFile, +IPC_MESSAGE_CONTROL3(FileSystemMsg_DidOpenFile, int /* request_id */, - IPC::PlatformFileForTransit) + IPC::PlatformFileForTransit, + quota::QuotaLimitType /* quota_policy */) IPC_MESSAGE_CONTROL2(FileSystemMsg_DidFail, int /* request_id */, base::PlatformFileError /* error_code */) diff --git a/content/renderer/pepper/pepper_directory_reader_host.cc b/content/renderer/pepper/pepper_directory_reader_host.cc index 2c3846c..c44127c 100644 --- a/content/renderer/pepper/pepper_directory_reader_host.cc +++ b/content/renderer/pepper/pepper_directory_reader_host.cc @@ -94,7 +94,8 @@ class ReadDirectoryCallback : public fileapi::FileSystemCallbackDispatcher { NOTREACHED(); } - virtual void DidOpenFile(base::PlatformFile file) OVERRIDE { + virtual void DidOpenFile(base::PlatformFile file, + quota::QuotaLimitType quota_policy) OVERRIDE { NOTREACHED(); } diff --git a/content/renderer/pepper/pepper_file_io_host.cc b/content/renderer/pepper/pepper_file_io_host.cc index b96edf5..78d6c05 100644 --- a/content/renderer/pepper/pepper_file_io_host.cc +++ b/content/renderer/pepper/pepper_file_io_host.cc @@ -89,7 +89,8 @@ class PlatformGeneralCallbackTranslator NOTREACHED(); } - virtual void DidOpenFile(base::PlatformFile file) OVERRIDE { + virtual void DidOpenFile(base::PlatformFile file, + quota::QuotaLimitType quota_policy) OVERRIDE { NOTREACHED(); } @@ -112,6 +113,7 @@ PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, : ResourceHost(host->GetPpapiHost(), instance, resource), file_(base::kInvalidPlatformFileValue), file_system_type_(PP_FILESYSTEMTYPE_INVALID), + quota_policy_(quota::kQuotaLimitTypeUnknown), is_running_in_process_(host->IsRunningInProcess()), weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { // TODO(victorhsieh): eliminate plugin_delegate_ as it's no longer needed. @@ -454,13 +456,13 @@ int32_t PepperFileIOHost::OnHostMsgWillSetLength( int32_t PepperFileIOHost::OnHostMsgRequestOSFileHandle( ppapi::host::HostMessageContext* context) { if (!is_running_in_process_ && + quota_policy_ != quota::kQuotaLimitTypeUnlimited && + // TODO(hamaji): Remove the whitelist once it turned out the + // quota check is sufficient. http://crbug.com/226386 !GetContentClient()->renderer()->IsRequestOSFileHandleAllowedForURL( file_system_url_)) return PP_ERROR_FAILED; - // TODO(hamaji): Should fail if quota is not unlimited. - // http://crbug.com/224123 - RendererPpapiHost* renderer_ppapi_host = RendererPpapiHost::GetForPPInstance(pp_instance()); @@ -533,9 +535,11 @@ void PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback( ppapi::host::ReplyMessageContext reply_context, base::PlatformFileError error_code, base::PassPlatformFile file, + quota::QuotaLimitType quota_policy, const PluginDelegate::NotifyCloseFileCallback& callback) { if (error_code == base::PLATFORM_FILE_OK) notify_close_file_callback_ = callback; + quota_policy_ = quota_policy; ExecutePlatformOpenFileCallback(reply_context, error_code, file); } diff --git a/content/renderer/pepper/pepper_file_io_host.h b/content/renderer/pepper/pepper_file_io_host.h index 6f3ab97..9146fd7 100644 --- a/content/renderer/pepper/pepper_file_io_host.h +++ b/content/renderer/pepper/pepper_file_io_host.h @@ -84,6 +84,7 @@ class PepperFileIOHost : public ppapi::host::ResourceHost, ReplyMessageContext reply_context, base::PlatformFileError error_code, base::PassPlatformFile file, + quota::QuotaLimitType quota_policy, const PluginDelegate::NotifyCloseFileCallback& callback); void ExecutePlatformQueryCallback(ReplyMessageContext reply_context, base::PlatformFileError error_code, @@ -111,6 +112,9 @@ class PepperFileIOHost : public ppapi::host::ResourceHost, // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}. GURL file_system_url_; + // Used to check if we can pass file handle to plugins. + quota::QuotaLimitType quota_policy_; + // Callback function for notifying when the file handle is closed. PluginDelegate::NotifyCloseFileCallback notify_close_file_callback_; diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc index d2be7cc..335cd02 100644 --- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc @@ -295,6 +295,7 @@ class AsyncOpenFileSystemURLCallbackTranslator base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; callback_.Run(error_code, base::PassPlatformFile(&invalid_file), + quota::kQuotaLimitTypeUnknown, webkit::ppapi::PluginDelegate::NotifyCloseFileCallback()); } @@ -302,9 +303,11 @@ class AsyncOpenFileSystemURLCallbackTranslator NOTREACHED(); } - virtual void DidOpenFile(base::PlatformFile file) OVERRIDE { + virtual void DidOpenFile(base::PlatformFile file, + quota::QuotaLimitType quota_policy) OVERRIDE { callback_.Run(base::PLATFORM_FILE_OK, base::PassPlatformFile(&file), + quota_policy, close_file_callback_); // Make sure we won't leak file handle if the requester has died. if (file != base::kInvalidPlatformFileValue) { diff --git a/webkit/fileapi/file_system_callback_dispatcher.cc b/webkit/fileapi/file_system_callback_dispatcher.cc index 5317bb8..9e657f1 100644 --- a/webkit/fileapi/file_system_callback_dispatcher.cc +++ b/webkit/fileapi/file_system_callback_dispatcher.cc @@ -12,7 +12,7 @@ FileSystemCallbackDispatcher::~FileSystemCallbackDispatcher() { } void FileSystemCallbackDispatcher::DidOpenFile( - base::PlatformFile file) { + base::PlatformFile file, quota::QuotaLimitType quota_policy) { NOTREACHED(); if (file != base::kInvalidPlatformFileValue) diff --git a/webkit/fileapi/file_system_callback_dispatcher.h b/webkit/fileapi/file_system_callback_dispatcher.h index bf5e7ea..41d7327 100644 --- a/webkit/fileapi/file_system_callback_dispatcher.h +++ b/webkit/fileapi/file_system_callback_dispatcher.h @@ -11,6 +11,7 @@ #include "base/files/file_util_proxy.h" #include "base/platform_file.h" #include "base/process.h" +#include "webkit/quota/quota_types.h" #include "webkit/storage/webkit_storage_export.h" class GURL; @@ -63,8 +64,8 @@ class WEBKIT_STORAGE_EXPORT FileSystemCallbackDispatcher { // Callback for OpenFile. This isn't in WebFileSystemCallbacks, as it's just // for Pepper. // The method will be responsible for closing |file|. - virtual void DidOpenFile( - base::PlatformFile file); + virtual void DidOpenFile(base::PlatformFile file, + quota::QuotaLimitType quota_policy); }; } // namespace fileapi diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index 3a8a724..8b8a109 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -475,6 +475,7 @@ class PluginDelegate { typedef base::Callback< void (base::PlatformFileError, base::PassPlatformFile, + quota::QuotaLimitType, const NotifyCloseFileCallback&)> AsyncOpenFileSystemURLCallback; virtual bool AsyncOpenFileSystemURL( const GURL& path, diff --git a/webkit/quota/quota_types.h b/webkit/quota/quota_types.h index 8d67b76..8ba3746 100644 --- a/webkit/quota/quota_types.h +++ b/webkit/quota/quota_types.h @@ -26,6 +26,12 @@ enum StorageType { kStorageTypeUnknown, }; +enum QuotaLimitType { + kQuotaLimitTypeUnknown, + kQuotaLimitTypeLimited, + kQuotaLimitTypeUnlimited, +}; + struct UsageInfo; typedef std::vector<UsageInfo> UsageInfoEntries; |