Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2529)

Unified Diff: content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc

Issue 26803004: PPAPI: Add PluginPrivateFileSystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: overhaul Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 c304baaec296e5f99f897ae0ab6091f63bd3c9e9..6450488490b1c5949fed59cd31aa523b2134cab8 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,15 +8,20 @@
#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"
#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/file_system_util.h"
#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 {
@@ -37,19 +42,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,
@@ -187,30 +179,88 @@ void PepperFileSystemBrowserHost::GotFileSystemContext(
fs_context_ = fs_context;
}
+void PepperFileSystemBrowserHost::OpenFileSystemComplete(
+ ppapi::host::ReplyMessageContext reply_context,
+ const GURL& root,
+ const std::string& /* unused */,
+ base::PlatformFileError error) {
+ int32 pp_error = ppapi::PlatformFileErrorToPepperError(error);
+ if (pp_error == PP_OK) {
+ opened_ = true;
+ root_url_ = root;
+ }
+ reply_context.params.set_result(pp_error);
+ host()->SendReply(reply_context, PpapiPluginMsg_FileSystem_OpenReply());
+}
+
void PepperFileSystemBrowserHost::GotIsolatedFileSystemContext(
ppapi::host::ReplyMessageContext reply_context,
+ const std::string& fsid,
+ PP_IsolatedFileSystemType_Private type,
scoped_refptr<fileapi::FileSystemContext> fs_context) {
fs_context_ = fs_context;
- if (fs_context.get())
- reply_context.params.set_result(PP_OK);
- else
+ if (!fs_context.get()) {
reply_context.params.set_result(PP_ERROR_FAILED);
+ host()->SendReply(reply_context,
+ PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply());
+ return;
+ }
+
+ root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString(
teravest 2013/11/12 18:04:53 Should we do anything if root_url_.is_valid() is f
nhiroki 2013/11/14 11:34:39 Done.
+ browser_ppapi_host_->GetDocumentURLForInstance(pp_instance()),
+ fsid, ppapi::IsolatedFileSystemTypeToRootName(type)));
+
+ switch (type) {
+ case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_INVALID:
teravest 2013/11/12 18:04:53 Should this just be the default case for the switc
nhiroki 2013/11/14 11:34:39 Done.
+ NOTREACHED();
+ reply_context.params.set_result(PP_ERROR_BADARGUMENT);
+ break;
+ case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_CRX:
+ opened_ = true;
+ reply_context.params.set_result(PP_OK);
+ break;
+ case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_PLUGINPRIVATE:
+ OpenPluginPrivateFileSystem(reply_context, fsid, fs_context);
+ return;
+ }
host()->SendReply(reply_context,
PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply());
}
-void PepperFileSystemBrowserHost::OpenFileSystemComplete(
+void PepperFileSystemBrowserHost::OpenPluginPrivateFileSystem(
+ ppapi::host::ReplyMessageContext reply_context,
+ const std::string& fsid,
+ scoped_refptr<fileapi::FileSystemContext> fs_context) {
+ GURL origin = browser_ppapi_host_->GetDocumentURLForInstance(
teravest 2013/11/12 18:04:53 Should we do a validity check on origin here?
nhiroki 2013/11/14 11:34:39 Done.
+ pp_instance()).GetOrigin();
+
+ const std::string plugin_id = GeneratePluginId();
+ if (plugin_id.empty()) {
+ fileapi::IsolatedContext::GetInstance()->RevokeFileSystem(fsid);
+ reply_context.params.set_result(PP_ERROR_BADARGUMENT);
+ host()->SendReply(reply_context,
+ PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply());
+ return;
+ }
+
+ fs_context->OpenPluginPrivateFileSystem(
+ origin, fileapi::kFileSystemTypePluginPrivate, fsid, plugin_id,
+ fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
+ base::Bind(
+ &PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete,
+ weak_factory_.GetWeakPtr(), reply_context));
+}
+
+void PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete(
ppapi::host::ReplyMessageContext reply_context,
- const GURL& root,
- const std::string& /* unused */,
base::PlatformFileError error) {
int32 pp_error = ppapi::PlatformFileErrorToPepperError(error);
- if (pp_error == PP_OK) {
+ if (pp_error == PP_OK)
opened_ = true;
- root_url_ = root;
- }
reply_context.params.set_result(pp_error);
- host()->SendReply(reply_context, PpapiPluginMsg_FileSystem_OpenReply());
+ host()->SendReply(
+ reply_context,
+ PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply());
}
int32_t PepperFileSystemBrowserHost::OnHostMsgInitIsolatedFileSystem(
@@ -226,16 +276,6 @@ 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(),
@@ -249,8 +289,35 @@ int32_t PepperFileSystemBrowserHost::OnHostMsgInitIsolatedFileSystem(
base::Bind(&GetFileSystemContextFromRenderId, render_process_id),
base::Bind(&PepperFileSystemBrowserHost::GotIsolatedFileSystemContext,
weak_factory_.GetWeakPtr(),
- context->MakeReplyMessageContext()));
+ context->MakeReplyMessageContext(), fsid, type));
return PP_OK_COMPLETIONPENDING;
}
+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 "._-".
teravest 2013/11/12 18:04:53 This is stricter than what mime types require, rig
nhiroki 2013/11/14 11:34:39 That's right. MIME type requires at least one slas
+ for (std::string::const_iterator it = output.begin();
+ it != output.end(); ++it) {
+ if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) &&
+ *it != '.' && *it != '_' && *it != '-') {
+ return std::string();
+ }
+ }
+ return output;
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698