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

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: Created 7 years, 2 months 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 af3ec67b22717eaecba02235507d6a57b08a3685..f91491c06370ab90b198cb574d2fdb8e6fde2712 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,6 +8,7 @@
#include "base/callback.h"
#include "content/public/browser/browser_ppapi_host.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "ppapi/c/pp_errors.h"
@@ -96,6 +97,9 @@ int32_t PepperFileSystemBrowserHost::OnResourceMessageReceived(
PPAPI_DISPATCH_HOST_RESOURCE_CALL(
PpapiHostMsg_FileSystem_InitIsolatedFileSystem,
OnHostMsgInitIsolatedFileSystem)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
+ PpapiHostMsg_FileSystem_OpenPluginPrivateFileSystem,
+ OnHostMsgOpenPluginPrivateFileSystem)
IPC_END_MESSAGE_MAP()
return PP_ERROR_FAILED;
}
@@ -179,6 +183,29 @@ void PepperFileSystemBrowserHost::GotIsolatedFileSystemContext(
PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply());
}
+void PepperFileSystemBrowserHost::GotFileSystemContextForPluginPrivate(
+ ppapi::host::ReplyMessageContext reply_context,
+ scoped_refptr<fileapi::FileSystemContext> fs_context) {
+ if (!fs_context.get()) {
+ OpenFileSystemComplete(
+ reply_context, GURL(), std::string(), base::PLATFORM_FILE_ERROR_FAILED);
+ return;
+ }
+ fs_context_ = fs_context;
+
+ GURL origin = browser_ppapi_host_->GetDocumentURLForInstance(
+ pp_instance()).GetOrigin();
+
+ // TODO(nhiroki): Generate a real plugin_id from the plugin's MIME type.
+ std::string dummy_plugin_id = "plugin_id";
+ fs_context->OpenPluginPrivateFileSystem(
+ origin, fileapi::kFileSystemTypePluginPrivate, dummy_plugin_id,
+ fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
+ base::Bind(
+ &PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete,
+ weak_factory_.GetWeakPtr(), reply_context));
+}
+
void PepperFileSystemBrowserHost::OpenFileSystemComplete(
ppapi::host::ReplyMessageContext reply_context,
const GURL& root,
@@ -193,6 +220,47 @@ void PepperFileSystemBrowserHost::OpenFileSystemComplete(
host()->SendReply(reply_context, PpapiPluginMsg_FileSystem_OpenReply());
}
+void PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete(
+ ppapi::host::ReplyMessageContext reply_context,
+ const GURL& root,
+ const std::string& fsid,
+ base::PlatformFileError error) {
+ int32 pp_error = ppapi::PlatformFileErrorToPepperError(error);
+ if (pp_error != PP_OK) {
+ reply_context.params.set_result(pp_error);
+ host()->SendReply(
+ reply_context,
+ PpapiPluginMsg_FileSystem_OpenPluginPrivateFileSystemReply(
+ std::string()));
+ return;
+ }
+
+ int render_process_id = 0;
+ int unused;
+ if (!browser_ppapi_host_->GetRenderViewIDsForInstance(pp_instance(),
+ &render_process_id,
+ &unused)) {
+ reply_context.params.set_result(PP_ERROR_FAILED);
+ host()->SendReply(
+ reply_context,
+ PpapiPluginMsg_FileSystem_OpenPluginPrivateFileSystemReply(
+ std::string()));
+ return;
+ }
+
+ opened_ = true;
+ root_url_ = root;
+
+ content::ChildProcessSecurityPolicy* policy =
+ content::ChildProcessSecurityPolicy::GetInstance();
+ policy->GrantCreateReadWriteFileSystem(render_process_id, fsid);
+
+ reply_context.params.set_result(PP_OK);
+ host()->SendReply(
+ reply_context,
+ PpapiPluginMsg_FileSystem_OpenPluginPrivateFileSystemReply(fsid));
+}
+
int32_t PepperFileSystemBrowserHost::OnHostMsgInitIsolatedFileSystem(
ppapi::host::HostMessageContext* context,
const std::string& fsid) {
@@ -226,4 +294,29 @@ int32_t PepperFileSystemBrowserHost::OnHostMsgInitIsolatedFileSystem(
return PP_OK_COMPLETIONPENDING;
}
+int32_t PepperFileSystemBrowserHost::OnHostMsgOpenPluginPrivateFileSystem(
+ ppapi::host::HostMessageContext* context) {
+ // Do not allow multiple opens.
+ if (called_open_)
+ return PP_ERROR_INPROGRESS;
+ called_open_ = true;
+
+ int render_process_id = 0;
+ int unused;
+ if (!browser_ppapi_host_->GetRenderViewIDsForInstance(pp_instance(),
+ &render_process_id,
+ &unused)) {
+ return PP_ERROR_FAILED;
+ }
+
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&GetFileSystemContextFromRenderId, render_process_id),
+ base::Bind(
+ &PepperFileSystemBrowserHost::GotFileSystemContextForPluginPrivate,
+ weak_factory_.GetWeakPtr(), context->MakeReplyMessageContext()));
+ return PP_OK_COMPLETIONPENDING;
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698