summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-11 03:13:47 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-11 03:13:47 +0000
commit20161e49ec2eb63a81d16d461605a6ce315a4d72 (patch)
treead6fd77f26f447c8bc862e5dd000f4cb4f5d3969 /ppapi
parent9aac22a97a65239b84964bc12b917403bbf39bc2 (diff)
downloadchromium_src-20161e49ec2eb63a81d16d461605a6ce315a4d72.zip
chromium_src-20161e49ec2eb63a81d16d461605a6ce315a4d72.tar.gz
chromium_src-20161e49ec2eb63a81d16d461605a6ce315a4d72.tar.bz2
PPAPI/NaCl: Make NaClIPCAdapter pass handles for Resource Messages
This fixes Gamepad for NaCl. BUG=163021,159689 TBR=brettw Review URL: https://chromiumcodereview.appspot.com/11411365 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172248 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/proxy/resource_message_params.cc51
-rw-r--r--ppapi/proxy/resource_message_params.h16
2 files changed, 58 insertions, 9 deletions
diff --git a/ppapi/proxy/resource_message_params.cc b/ppapi/proxy/resource_message_params.cc
index 49b6328..e4858da 100644
--- a/ppapi/proxy/resource_message_params.cc
+++ b/ppapi/proxy/resource_message_params.cc
@@ -41,22 +41,46 @@ ResourceMessageParams::~ResourceMessageParams() {
}
void ResourceMessageParams::Serialize(IPC::Message* msg) const {
+ WriteHeader(msg);
+ WriteHandles(msg);
+}
+
+bool ResourceMessageParams::Deserialize(const IPC::Message* msg,
+ PickleIterator* iter) {
+ return ReadHeader(msg, iter) && ReadHandles(msg, iter);
+}
+
+void ResourceMessageParams::WriteHeader(IPC::Message* msg) const {
IPC::ParamTraits<PP_Resource>::Write(msg, pp_resource_);
IPC::ParamTraits<int32_t>::Write(msg, sequence_);
+}
+
+void ResourceMessageParams::WriteHandles(IPC::Message* msg) const {
IPC::ParamTraits<std::vector<SerializedHandle> >::Write(msg,
handles_->data());
}
-bool ResourceMessageParams::Deserialize(const IPC::Message* msg,
- PickleIterator* iter) {
+bool ResourceMessageParams::ReadHeader(const IPC::Message* msg,
+ PickleIterator* iter) {
DCHECK(handles_->data().empty());
handles_->set_should_close(true);
return IPC::ParamTraits<PP_Resource>::Read(msg, iter, &pp_resource_) &&
- IPC::ParamTraits<int32_t>::Read(msg, iter, &sequence_) &&
- IPC::ParamTraits<std::vector<SerializedHandle> >::Read(
+ IPC::ParamTraits<int32_t>::Read(msg, iter, &sequence_);
+}
+
+bool ResourceMessageParams::ReadHandles(const IPC::Message* msg,
+ PickleIterator* iter) {
+ return IPC::ParamTraits<std::vector<SerializedHandle> >::Read(
msg, iter, &handles_->data());
}
+void ResourceMessageParams::ConsumeHandles() const {
+ // Note: we must not invalidate the handles. This is used for converting
+ // handles from the host OS to NaCl, and that conversion will not work if we
+ // invalidate the handles (see HandleConverter).
+ handles_->set_should_close(false);
+}
+
SerializedHandle ResourceMessageParams::TakeHandleOfTypeAtIndex(
size_t index,
SerializedHandle::Type type) const {
@@ -156,15 +180,24 @@ ResourceMessageReplyParams::~ResourceMessageReplyParams() {
}
void ResourceMessageReplyParams::Serialize(IPC::Message* msg) const {
- ResourceMessageParams::Serialize(msg);
- IPC::ParamTraits<int32_t>::Write(msg, result_);
+ // Rather than serialize all of ResourceMessageParams first, we serialize all
+ // non-handle data first, then the handles. When transferring to NaCl on
+ // Windows, we need to be able to translate Windows-style handles to POSIX-
+ // style handles, and it's easier to put all the regular stuff at the front.
+ WriteReplyHeader(msg);
+ WriteHandles(msg);
}
bool ResourceMessageReplyParams::Deserialize(const IPC::Message* msg,
PickleIterator* iter) {
- if (!ResourceMessageParams::Deserialize(msg, iter))
- return false;
- return IPC::ParamTraits<int32_t>::Read(msg, iter, &result_);
+ return (ReadHeader(msg, iter) &&
+ IPC::ParamTraits<int32_t>::Read(msg, iter, &result_) &&
+ ReadHandles(msg, iter));
+}
+
+void ResourceMessageReplyParams::WriteReplyHeader(IPC::Message* msg) const {
+ WriteHeader(msg);
+ IPC::ParamTraits<int32_t>::Write(msg, result_);
}
} // namespace proxy
diff --git a/ppapi/proxy/resource_message_params.h b/ppapi/proxy/resource_message_params.h
index 6d0abea..0e42ec9 100644
--- a/ppapi/proxy/resource_message_params.h
+++ b/ppapi/proxy/resource_message_params.h
@@ -29,6 +29,11 @@ class PPAPI_PROXY_EXPORT ResourceMessageParams {
return handles_->data();
}
+ // Makes ResourceMessageParams leave its handles open, even if they weren't
+ // taken using a Take.* function. After this call, no Take.* calls are
+ // allowed.
+ void ConsumeHandles() const;
+
// Returns the handle at the given index if it exists and is of the given
// type. The corresponding slot in the list is set to an invalid handle.
// If the index doesn't exist or the handle isn't of the given type, returns
@@ -70,6 +75,14 @@ class PPAPI_PROXY_EXPORT ResourceMessageParams {
virtual void Serialize(IPC::Message* msg) const;
virtual bool Deserialize(const IPC::Message* msg, PickleIterator* iter);
+ // Writes everything except the handles to |msg|.
+ void WriteHeader(IPC::Message* msg) const;
+ // Writes the handles to |msg|.
+ void WriteHandles(IPC::Message* msg) const;
+ // Matching deserialize helpers.
+ bool ReadHeader(const IPC::Message* msg, PickleIterator* iter);
+ bool ReadHandles(const IPC::Message* msg, PickleIterator* iter);
+
private:
class SerializedHandles
: public base::RefCountedThreadSafe<SerializedHandles> {
@@ -154,6 +167,9 @@ class PPAPI_PROXY_EXPORT ResourceMessageReplyParams
virtual bool Deserialize(const IPC::Message* msg,
PickleIterator* iter) OVERRIDE;
+ // Writes everything except the handles to |msg|.
+ void WriteReplyHeader(IPC::Message* msg) const;
+
private:
// Pepper "result code" for the callback.
int32_t result_;