Chromium Code Reviews| Index: content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc |
| diff --git a/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc b/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc |
| index f8417c001a37b51632ceb2c51ce2028500511d72..67070e6020c3b047c490ce2975d74891c1060ee4 100644 |
| --- a/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc |
| +++ b/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc |
| @@ -8,8 +8,11 @@ |
| #include "base/callback.h" |
| #include "content/public/browser/browser_ppapi_host.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/plugin_service.h" |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/storage_partition.h" |
| +#include "content/public/common/pepper_plugin_info.h" |
| +#include "net/base/mime_util.h" |
| #include "ppapi/c/pp_errors.h" |
| #include "ppapi/host/dispatch_host_message.h" |
| #include "ppapi/host/ppapi_host.h" |
| @@ -18,6 +21,7 @@ |
| #include "ppapi/shared_impl/file_type_conversion.h" |
| #include "webkit/browser/fileapi/file_system_context.h" |
| #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| +#include "webkit/browser/fileapi/isolated_context.h" |
| #include "webkit/common/fileapi/file_system_util.h" |
| namespace content { |
| @@ -36,19 +40,6 @@ GetFileSystemContextFromRenderId(int render_process_id) { |
| return storage_partition->GetFileSystemContext(); |
| } |
| -// TODO(nhiroki): Move this function somewhere else to be shared. |
| -std::string IsolatedFileSystemTypeToRootName( |
| - PP_IsolatedFileSystemType_Private type) { |
| - switch (type) { |
| - case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_INVALID: |
| - break; |
| - case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_CRX: |
| - return "crxfs"; |
| - } |
| - NOTREACHED() << type; |
| - return std::string(); |
| -} |
| - |
| } // namespace |
| PepperFileSystemBrowserHost::PepperFileSystemBrowserHost(BrowserPpapiHost* host, |
| @@ -131,13 +122,14 @@ int32_t PepperFileSystemBrowserHost::OnHostMsgOpen( |
| &unused)) { |
| return PP_ERROR_FAILED; |
| } |
| + |
| + reply_context_ = context->MakeReplyMessageContext(); |
|
dmichael (off chromium)
2013/11/14 18:09:31
Did you change this for any particular reason? Pas
nhiroki
2013/11/15 12:24:01
I see. That was just clean-up purpose. Reverted th
|
| BrowserThread::PostTaskAndReplyWithResult( |
| BrowserThread::UI, |
| FROM_HERE, |
| base::Bind(&GetFileSystemContextFromRenderId, render_process_id), |
| base::Bind(&PepperFileSystemBrowserHost::GotFileSystemContext, |
| weak_factory_.GetWeakPtr(), |
| - context->MakeReplyMessageContext(), |
| file_system_type)); |
| return PP_OK_COMPLETIONPENDING; |
| } |
| @@ -158,12 +150,11 @@ void PepperFileSystemBrowserHost::OpenExistingWithContext( |
| } |
| void PepperFileSystemBrowserHost::GotFileSystemContext( |
| - ppapi::host::ReplyMessageContext reply_context, |
| fileapi::FileSystemType file_system_type, |
| scoped_refptr<fileapi::FileSystemContext> fs_context) { |
| if (!fs_context.get()) { |
| OpenFileSystemComplete( |
| - reply_context, GURL(), std::string(), base::PLATFORM_FILE_ERROR_FAILED); |
| + GURL(), std::string(), base::PLATFORM_FILE_ERROR_FAILED); |
| return; |
| } |
| GURL origin = browser_ppapi_host_->GetDocumentURLForInstance( |
| @@ -171,25 +162,11 @@ void PepperFileSystemBrowserHost::GotFileSystemContext( |
| fs_context->OpenFileSystem(origin, file_system_type, |
| fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| base::Bind(&PepperFileSystemBrowserHost::OpenFileSystemComplete, |
| - weak_factory_.GetWeakPtr(), |
| - reply_context)); |
| + weak_factory_.GetWeakPtr())); |
| fs_context_ = fs_context; |
| } |
| -void PepperFileSystemBrowserHost::GotIsolatedFileSystemContext( |
| - ppapi::host::ReplyMessageContext reply_context, |
| - scoped_refptr<fileapi::FileSystemContext> fs_context) { |
| - fs_context_ = fs_context; |
| - if (fs_context.get()) |
| - reply_context.params.set_result(PP_OK); |
| - else |
| - reply_context.params.set_result(PP_ERROR_FAILED); |
| - host()->SendReply(reply_context, |
| - PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply()); |
| -} |
| - |
| void PepperFileSystemBrowserHost::OpenFileSystemComplete( |
| - ppapi::host::ReplyMessageContext reply_context, |
| const GURL& root, |
| const std::string& /* unused */, |
| base::PlatformFileError error) { |
| @@ -198,8 +175,74 @@ void PepperFileSystemBrowserHost::OpenFileSystemComplete( |
| opened_ = true; |
| root_url_ = root; |
| } |
| - reply_context.params.set_result(pp_error); |
| - host()->SendReply(reply_context, PpapiPluginMsg_FileSystem_OpenReply()); |
| + reply_context_.params.set_result(pp_error); |
| + host()->SendReply(reply_context_, PpapiPluginMsg_FileSystem_OpenReply()); |
| +} |
| + |
| +void PepperFileSystemBrowserHost::GotIsolatedFileSystemContext( |
| + const std::string& fsid, |
| + PP_IsolatedFileSystemType_Private type, |
| + scoped_refptr<fileapi::FileSystemContext> fs_context) { |
| + fs_context_ = fs_context; |
| + if (!fs_context.get()) { |
| + SendReplyForIsolatedFileSystem(fsid, PP_ERROR_FAILED); |
| + return; |
| + } |
| + |
| + root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( |
| + browser_ppapi_host_->GetDocumentURLForInstance(pp_instance()).GetOrigin(), |
| + fsid, ppapi::IsolatedFileSystemTypeToRootName(type))); |
| + if (!root_url_.is_valid()) { |
| + SendReplyForIsolatedFileSystem(fsid, PP_ERROR_FAILED); |
| + return; |
| + } |
| + |
| + switch (type) { |
| + case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_CRX: |
| + opened_ = true; |
| + SendReplyForIsolatedFileSystem(fsid, PP_OK); |
| + return; |
| + case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_PLUGINPRIVATE: |
| + OpenPluginPrivateFileSystem(fsid, fs_context); |
| + return; |
| + default: |
| + NOTREACHED(); |
| + SendReplyForIsolatedFileSystem(fsid, PP_ERROR_BADARGUMENT); |
| + return; |
| + } |
| +} |
| + |
| +void PepperFileSystemBrowserHost::OpenPluginPrivateFileSystem( |
| + const std::string& fsid, |
| + scoped_refptr<fileapi::FileSystemContext> fs_context) { |
| + GURL origin = browser_ppapi_host_->GetDocumentURLForInstance( |
| + pp_instance()).GetOrigin(); |
| + if (!origin.is_valid()) { |
| + SendReplyForIsolatedFileSystem(fsid, PP_ERROR_FAILED); |
| + return; |
| + } |
| + |
| + const std::string plugin_id = GeneratePluginId(); |
| + if (plugin_id.empty()) { |
| + SendReplyForIsolatedFileSystem(fsid, PP_ERROR_BADARGUMENT); |
| + return; |
| + } |
| + |
| + fs_context->OpenPluginPrivateFileSystem( |
| + origin, fileapi::kFileSystemTypePluginPrivate, fsid, plugin_id, |
| + fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| + base::Bind( |
| + &PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete, |
| + weak_factory_.GetWeakPtr(), fsid)); |
| +} |
| + |
| +void PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete( |
| + const std::string& fsid, |
| + base::PlatformFileError error) { |
| + int32 pp_error = ppapi::PlatformFileErrorToPepperError(error); |
| + if (pp_error == PP_OK) |
| + opened_ = true; |
| + SendReplyForIsolatedFileSystem(fsid, pp_error); |
| } |
| int32_t PepperFileSystemBrowserHost::OnHostMsgInitIsolatedFileSystem( |
| @@ -215,31 +258,61 @@ int32_t PepperFileSystemBrowserHost::OnHostMsgInitIsolatedFileSystem( |
| if (!fileapi::ValidateIsolatedFileSystemId(fsid)) |
| return PP_ERROR_BADARGUMENT; |
| - const GURL& url = |
| - browser_ppapi_host_->GetDocumentURLForInstance(pp_instance()); |
| - const std::string root_name = IsolatedFileSystemTypeToRootName(type); |
| - if (root_name.empty()) |
| - return PP_ERROR_BADARGUMENT; |
| - |
| - root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( |
| - url.GetOrigin(), fsid, root_name)); |
| - opened_ = true; |
| - |
| int render_process_id = 0; |
| int unused; |
| if (!browser_ppapi_host_->GetRenderViewIDsForInstance(pp_instance(), |
| &render_process_id, |
| &unused)) { |
| + fileapi::IsolatedContext::GetInstance()->RevokeFileSystem(fsid); |
| return PP_ERROR_FAILED; |
| } |
| + |
| + reply_context_ = context->MakeReplyMessageContext(); |
| BrowserThread::PostTaskAndReplyWithResult( |
| BrowserThread::UI, |
| FROM_HERE, |
| base::Bind(&GetFileSystemContextFromRenderId, render_process_id), |
| base::Bind(&PepperFileSystemBrowserHost::GotIsolatedFileSystemContext, |
| - weak_factory_.GetWeakPtr(), |
| - context->MakeReplyMessageContext())); |
| + weak_factory_.GetWeakPtr(), fsid, type)); |
| return PP_OK_COMPLETIONPENDING; |
| } |
| +void PepperFileSystemBrowserHost::SendReplyForIsolatedFileSystem( |
| + const std::string& fsid, |
| + int32_t error) { |
| + if (error != PP_OK) |
| + fileapi::IsolatedContext::GetInstance()->RevokeFileSystem(fsid); |
| + reply_context_.params.set_result(error); |
| + host()->SendReply(reply_context_, |
| + PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply()); |
| +} |
| + |
| +std::string PepperFileSystemBrowserHost::GeneratePluginId() { |
| + base::FilePath plugin_path = browser_ppapi_host_->GetPluginPath(); |
| + PepperPluginInfo* info = |
| + PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(plugin_path); |
| + if (!info || info->mime_types.empty()) |
| + return std::string(); |
| + |
| + // Use the first element in |info->mime_types| even if several elements exist. |
| + std::string output = info->mime_types[0].mime_type; |
| + if (!net::IsMimeType(output)) |
| + return std::string(); |
| + |
| + // Replace a slash used for type/subtype separator with an underscore. |
| + // NOTE: This assumes there is only one slash in the MIME type. |
| + ReplaceFirstSubstringAfterOffset(&output, 0, "/", "_"); |
| + |
| + // Verify |output| contains only alphabets, digits, or "._-". |
| + for (std::string::const_iterator it = output.begin(); |
| + it != output.end(); ++it) { |
| + if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) && |
| + *it != '.' && *it != '_' && *it != '-') { |
| + LOG(WARNING) << "Failed to generate a plugin id."; |
| + return std::string(); |
| + } |
| + } |
| + return output; |
| +} |
| + |
| } // namespace content |