summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy
diff options
context:
space:
mode:
authormgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-31 10:59:03 +0000
committermgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-31 10:59:03 +0000
commit17d69d8f367c5662b1c0be354d523f17d2a319b4 (patch)
tree3bd424646a210d043a01aa39f35583da3b54833b /ppapi/proxy
parent958e785645c18e72c5246684fdf344b8c1a9324a (diff)
downloadchromium_src-17d69d8f367c5662b1c0be354d523f17d2a319b4.zip
chromium_src-17d69d8f367c5662b1c0be354d523f17d2a319b4.tar.gz
chromium_src-17d69d8f367c5662b1c0be354d523f17d2a319b4.tar.bz2
[PPAPI] It is now possible to pass filesystems from JavaScript to NaCl modules.
If a DOMFileSystem is passed as a message to the NaCl module, it will be converted into a resource var which is available to the plugin via the dev interface PPB_VarResource_Dev. BUG=177017 Review URL: https://codereview.chromium.org/26564009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232080 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
-rw-r--r--ppapi/proxy/plugin_var_tracker.cc48
-rw-r--r--ppapi/proxy/plugin_var_tracker.h5
-rw-r--r--ppapi/proxy/ppapi_messages.h10
-rw-r--r--ppapi/proxy/raw_var_data.cc20
4 files changed, 75 insertions, 8 deletions
diff --git a/ppapi/proxy/plugin_var_tracker.cc b/ppapi/proxy/plugin_var_tracker.cc
index 0788b99..a9cbd9c 100644
--- a/ppapi/proxy/plugin_var_tracker.cc
+++ b/ppapi/proxy/plugin_var_tracker.cc
@@ -6,10 +6,13 @@
#include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
+#include "ipc/ipc_message.h"
#include "ppapi/c/dev/ppp_class_deprecated.h"
#include "ppapi/c/ppb_var.h"
+#include "ppapi/proxy/file_system_resource.h"
#include "ppapi/proxy/plugin_array_buffer_var.h"
#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_globals.h"
#include "ppapi/proxy/plugin_resource_var.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/proxy_object_var.h"
@@ -22,6 +25,16 @@
namespace ppapi {
namespace proxy {
+namespace {
+
+Connection GetConnectionForInstance(PP_Instance instance) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ DCHECK(dispatcher);
+ return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher);
+}
+
+} // namespace
+
PluginVarTracker::HostVar::HostVar(PluginDispatcher* d, int32 i)
: dispatcher(d),
host_object_id(i) {
@@ -154,6 +167,41 @@ void PluginVarTracker::ReleaseHostObject(PluginDispatcher* dispatcher,
ReleaseVar(found->second);
}
+PP_Var PluginVarTracker::MakeResourcePPVarFromMessage(
+ PP_Instance instance,
+ const IPC::Message& creation_message,
+ int pending_renderer_id,
+ int pending_browser_id) {
+ DCHECK(pending_renderer_id);
+ DCHECK(pending_browser_id);
+ switch (creation_message.type()) {
+ case PpapiPluginMsg_FileSystem_CreateFromPendingHost::ID: {
+ PP_FileSystemType file_system_type;
+ if (!UnpackMessage<PpapiPluginMsg_FileSystem_CreateFromPendingHost>(
+ creation_message, &file_system_type)) {
+ NOTREACHED() << "Invalid message of type "
+ "PpapiPluginMsg_FileSystem_CreateFromPendingHost";
+ return PP_MakeNull();
+ }
+ // Create a plugin-side resource and attach it to the host resource.
+ // Note: This only makes sense when the plugin is out of process (which
+ // should always be true when passing resource vars).
+ PP_Resource pp_resource =
+ (new FileSystemResource(GetConnectionForInstance(instance),
+ instance,
+ pending_renderer_id,
+ pending_browser_id,
+ file_system_type))->GetReference();
+ return MakeResourcePPVar(pp_resource);
+ }
+ default: {
+ NOTREACHED() << "Creation message has unexpected type "
+ << creation_message.type();
+ return PP_MakeNull();
+ }
+ }
+}
+
ResourceVar* PluginVarTracker::MakeResourceVar(PP_Resource pp_resource) {
// The resource 0 returns a null resource var.
if (!pp_resource)
diff --git a/ppapi/proxy/plugin_var_tracker.h b/ppapi/proxy/plugin_var_tracker.h
index 126c8fc..03a9e5e 100644
--- a/ppapi/proxy/plugin_var_tracker.h
+++ b/ppapi/proxy/plugin_var_tracker.h
@@ -59,6 +59,11 @@ class PPAPI_PROXY_EXPORT PluginVarTracker : public VarTracker {
const PP_Var& host_object);
// VarTracker public overrides.
+ virtual PP_Var MakeResourcePPVarFromMessage(
+ PP_Instance instance,
+ const IPC::Message& creation_message,
+ int pending_renderer_id,
+ int pending_browser_id) OVERRIDE;
virtual ResourceVar* MakeResourceVar(PP_Resource pp_resource) OVERRIDE;
virtual void DidDeleteInstance(PP_Instance instance) OVERRIDE;
virtual int TrackSharedMemoryHandle(PP_Instance instance,
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 02c4d84..2313cf7 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -1291,6 +1291,16 @@ IPC_MESSAGE_CONTROL0(PpapiPluginMsg_FileSystem_OpenReply)
IPC_MESSAGE_CONTROL1(PpapiHostMsg_FileSystem_InitIsolatedFileSystem,
std::string /* fsid */)
IPC_MESSAGE_CONTROL0(PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply)
+// Passed from renderer to browser. Creates an already-open file system with a
+// given |root_url| and |file_system_type|.
+IPC_MESSAGE_CONTROL2(PpapiHostMsg_FileSystem_CreateFromRenderer,
+ std::string /* root_url */,
+ PP_FileSystemType /* file_system_type */)
+// Nested within a ResourceVar for file systems being passed from the renderer
+// to the plugin. Creates an already-open file system resource on the plugin,
+// linked to the existing resource host given in the ResourceVar.
+IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FileSystem_CreateFromPendingHost,
+ PP_FileSystemType /* file_system_type */)
// Flash DRM ------------------------------------------------------------------
IPC_MESSAGE_CONTROL0(PpapiHostMsg_FlashDRM_Create)
diff --git a/ppapi/proxy/raw_var_data.cc b/ppapi/proxy/raw_var_data.cc
index 91bcfbfd..49ee8c2 100644
--- a/ppapi/proxy/raw_var_data.cc
+++ b/ppapi/proxy/raw_var_data.cc
@@ -695,14 +695,18 @@ bool ResourceRawVarData::Init(const PP_Var& var, PP_Instance /*instance*/) {
}
PP_Var ResourceRawVarData::CreatePPVar(PP_Instance instance) {
- // If pp_resource_ is NULL, it could be because we are on the plugin side and
- // there is a pending resource host on the renderer.
- // TODO(mgiuca): Create a plugin-side resource in this case.
- // Currently, this should never occur. This will be needed when passing a
- // resource from the renderer to the plugin (http://crbug.com/177017).
- DCHECK(pp_resource_);
-
- return PpapiGlobals::Get()->GetVarTracker()->MakeResourcePPVar(pp_resource_);
+ // If this is not a pending resource host, just create the var.
+ if (pp_resource_ || !creation_message_) {
+ return PpapiGlobals::Get()->GetVarTracker()->MakeResourcePPVar(
+ pp_resource_);
+ }
+
+ // This is a pending resource host, so create the resource and var.
+ return PpapiGlobals::Get()->GetVarTracker()->MakeResourcePPVarFromMessage(
+ instance,
+ *creation_message_,
+ pending_renderer_host_id_,
+ pending_browser_host_id_);
}
void ResourceRawVarData::PopulatePPVar(const PP_Var& var,