summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-21 21:46:26 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-21 21:46:26 +0000
commit077ecfd462a0dc97e2042275cf770a5b3d447ee3 (patch)
tree01395a25a92d97683b84d9048e54f6fa5c5365bc /ppapi
parentc290833eb0eb7e8d6316672d6f9ec59d22d0a5a8 (diff)
downloadchromium_src-077ecfd462a0dc97e2042275cf770a5b3d447ee3.zip
chromium_src-077ecfd462a0dc97e2042275cf770a5b3d447ee3.tar.gz
chromium_src-077ecfd462a0dc97e2042275cf770a5b3d447ee3.tar.bz2
Add resource message call and reply infrastructure.
These messages are not yet used. They will allow us to route messages directly to a resource implementation in the proxy or the host using information in a common header. The actual content of the message (as interpreted by the specifi resource in the plugin or class in the host) is a nested message. TEST=none BUT=none Review URL: https://chromiumcodereview.appspot.com/10560030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143463 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/ppapi_proxy.gypi2
-rw-r--r--ppapi/ppapi_tests.gypi2
-rw-r--r--ppapi/proxy/ppapi_messages.h38
-rw-r--r--ppapi/proxy/resource_message_params.cc91
-rw-r--r--ppapi/proxy/resource_message_params.h121
-rw-r--r--ppapi/proxy/resource_message_test_sink.cc64
-rw-r--r--ppapi/proxy/resource_message_test_sink.h41
7 files changed, 359 insertions, 0 deletions
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi
index 17a424d..09c5144 100644
--- a/ppapi/ppapi_proxy.gypi
+++ b/ppapi/ppapi_proxy.gypi
@@ -149,6 +149,8 @@
'proxy/proxy_object_var.h',
'proxy/resource_creation_proxy.cc',
'proxy/resource_creation_proxy.h',
+ 'proxy/resource_message_params.cc',
+ 'proxy/resource_message_params.h',
'proxy/serialized_flash_menu.cc',
'proxy/serialized_flash_menu.h',
'proxy/serialized_structs.cc',
diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi
index 3337ce1..3be737a 100644
--- a/ppapi/ppapi_tests.gypi
+++ b/ppapi/ppapi_tests.gypi
@@ -129,6 +129,8 @@
'sources': [
'proxy/ppapi_proxy_test.cc',
'proxy/ppapi_proxy_test.h',
+ 'proxy/resource_message_test_sink.cc',
+ 'proxy/resource_message_test_sink.h',
'shared_impl/test_globals.cc',
'shared_impl/test_globals.h',
],
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 07c939c..759459f 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -37,6 +37,7 @@
#include "ppapi/c/private/ppp_flash_browser_operations.h"
#include "ppapi/proxy/ppapi_param_traits.h"
#include "ppapi/proxy/ppapi_proxy_export.h"
+#include "ppapi/proxy/resource_message_params.h"
#include "ppapi/proxy/serialized_flash_menu.h"
#include "ppapi/proxy/serialized_structs.h"
#include "ppapi/shared_impl/ppapi_preferences.h"
@@ -1385,4 +1386,41 @@ IPC_SYNC_MESSAGE_CONTROL1_2(PpapiHostMsg_PPBX509Certificate_ParseDER,
// PPB_Font.
IPC_SYNC_MESSAGE_CONTROL0_1(PpapiHostMsg_PPBFont_GetFontFamilies,
std::string /* result */)
+
#endif // !defined(OS_NACL)
+
+//-----------------------------------------------------------------------------
+// Resource call/reply messages.
+//
+// These are the new-style resource implementations where the resource is only
+// implemented in the proxy and "resource messages" are sent between this and a
+// host object. Resource messages are a wrapper around some general routing
+// information and a separate message of a type defined by the specific resource
+// sending/receiving it. The extra paremeters allow the nested message to be
+// routed automatically to the correct resource.
+
+// Notification that a resource has been created in the plugin. The nested
+// message will be resource-type-specific.
+IPC_MESSAGE_CONTROL3(PpapiHostMsg_ResourceCreated,
+ ppapi::proxy::ResourceMessageCallParams /* call_params */,
+ PP_Instance /* instance */,
+ IPC::Message /* nested_msg */)
+
+// Notification that a resource has been destroyed in the plugin.
+IPC_MESSAGE_CONTROL1(PpapiHostMsg_ResourceDestroyed,
+ PP_Resource /* resource */)
+
+// A resource call is a request from the plugin to the host. It may or may not
+// require a reply, depending on the params. The nested message will be
+// resource-type-specific.
+IPC_MESSAGE_CONTROL2(PpapiHostMsg_ResourceCall,
+ ppapi::proxy::ResourceMessageCallParams /* call_params */,
+ IPC::Message /* nested_msg */)
+
+// A resource reply is a response to a ResourceCall from a host to the
+// plugin. The resource ID + sequence number in the params will correspond to
+// that of the previous ResourceCall.
+IPC_MESSAGE_CONTROL2(
+ PpapiPluginMsg_ResourceReply,
+ ppapi::proxy::ResourceMessageReplyParams /* reply_params */,
+ IPC::Message /* nested_msg */)
diff --git a/ppapi/proxy/resource_message_params.cc b/ppapi/proxy/resource_message_params.cc
new file mode 100644
index 0000000..5c70e49
--- /dev/null
+++ b/ppapi/proxy/resource_message_params.cc
@@ -0,0 +1,91 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/resource_message_params.h"
+
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/proxy/ppapi_messages.h"
+
+namespace ppapi {
+namespace proxy {
+
+ResourceMessageParams::ResourceMessageParams()
+ : pp_resource_(0),
+ sequence_(0) {
+}
+
+ResourceMessageParams::ResourceMessageParams(PP_Resource resource,
+ int32_t sequence)
+ : pp_resource_(resource),
+ sequence_(sequence) {
+}
+
+ResourceMessageParams::~ResourceMessageParams() {
+}
+
+void ResourceMessageParams::Serialize(IPC::Message* msg) const {
+ IPC::ParamTraits<PP_Resource>::Write(msg, pp_resource_);
+ IPC::ParamTraits<int32_t>::Write(msg, sequence_);
+}
+
+bool ResourceMessageParams::Deserialize(const IPC::Message* msg,
+ PickleIterator* iter) {
+ return IPC::ParamTraits<PP_Resource>::Read(msg, iter, &pp_resource_) &&
+ IPC::ParamTraits<int32_t>::Read(msg, iter, &sequence_);
+}
+
+ResourceMessageCallParams::ResourceMessageCallParams()
+ : ResourceMessageParams(),
+ has_callback_(0) {
+}
+
+ResourceMessageCallParams::ResourceMessageCallParams(PP_Resource resource,
+ int32_t sequence)
+ : ResourceMessageParams(resource, sequence),
+ has_callback_(0) {
+}
+
+ResourceMessageCallParams::~ResourceMessageCallParams() {
+}
+
+void ResourceMessageCallParams::Serialize(IPC::Message* msg) const {
+ ResourceMessageParams::Serialize(msg);
+ IPC::ParamTraits<bool>::Write(msg, has_callback_);
+}
+
+bool ResourceMessageCallParams::Deserialize(const IPC::Message* msg,
+ PickleIterator* iter) {
+ if (!ResourceMessageParams::Deserialize(msg, iter))
+ return false;
+ return IPC::ParamTraits<bool>::Read(msg, iter, &has_callback_);
+}
+
+ResourceMessageReplyParams::ResourceMessageReplyParams()
+ : ResourceMessageParams(),
+ result_(PP_OK) {
+}
+
+ResourceMessageReplyParams::ResourceMessageReplyParams(PP_Resource resource,
+ int32_t sequence)
+ : ResourceMessageParams(resource, sequence),
+ result_(PP_OK) {
+}
+
+ResourceMessageReplyParams::~ResourceMessageReplyParams() {
+}
+
+void ResourceMessageReplyParams::Serialize(IPC::Message* msg) const {
+ ResourceMessageParams::Serialize(msg);
+ IPC::ParamTraits<int32_t>::Write(msg, result_);
+}
+
+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_);
+}
+
+} // namespace proxy
+} // namespace ppapi
diff --git a/ppapi/proxy/resource_message_params.h b/ppapi/proxy/resource_message_params.h
new file mode 100644
index 0000000..ad1c96a
--- /dev/null
+++ b/ppapi/proxy/resource_message_params.h
@@ -0,0 +1,121 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_
+#define PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_
+
+#include "ipc/ipc_message_utils.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/proxy/ppapi_proxy_export.h"
+
+namespace ppapi {
+namespace proxy {
+
+// Common parameters for resource call and reply params structures below.
+class PPAPI_PROXY_EXPORT ResourceMessageParams {
+ public:
+ virtual ~ResourceMessageParams();
+
+ PP_Resource pp_resource() const { return pp_resource_; }
+ int32_t sequence() const { return sequence_; }
+
+ protected:
+ ResourceMessageParams();
+ ResourceMessageParams(PP_Resource resource, int32_t sequence);
+
+ virtual void Serialize(IPC::Message* msg) const;
+ virtual bool Deserialize(const IPC::Message* msg, PickleIterator* iter);
+
+ private:
+ PP_Resource pp_resource_;
+
+ // Identifier for this message. Sequence numbers are quasi-unique within a
+ // resource, but will overlap between different resource objects.
+ //
+ // If you send a lot of messages, the ID may wrap around. This is OK. All IDs
+ // are valid and 0 and -1 aren't special, so those cases won't confuse us.
+ // In practice, if you send more than 4 billion messages for a resource, the
+ // old ones will be long gone and there will be no collisions.
+ //
+ // If there is a malicious plugin (or exceptionally bad luck) that causes a
+ // wraparound and collision the worst that will happen is that we can get
+ // confused between different callbacks. But since these can only cause
+ // confusion within the plugin and within callbacks on the same resource,
+ // there shouldn't be a security problem.
+ int32_t sequence_;
+};
+
+// Parameters common to all ResourceMessage "Call" requests.
+class PPAPI_PROXY_EXPORT ResourceMessageCallParams
+ : public ResourceMessageParams {
+ public:
+ ResourceMessageCallParams();
+ ResourceMessageCallParams(PP_Resource resource, int32_t sequence);
+ virtual ~ResourceMessageCallParams();
+
+ void set_has_callback() { has_callback_ = true; }
+ bool has_callback() const { return has_callback_; }
+
+ virtual void Serialize(IPC::Message* msg) const OVERRIDE;
+ virtual bool Deserialize(const IPC::Message* msg,
+ PickleIterator* iter) OVERRIDE;
+
+ private:
+ bool has_callback_;
+};
+
+// Parameters common to all ResourceMessage "Reply" requests.
+class PPAPI_PROXY_EXPORT ResourceMessageReplyParams
+ : public ResourceMessageParams {
+ public:
+ ResourceMessageReplyParams();
+ ResourceMessageReplyParams(PP_Resource resource, int32_t sequence);
+ virtual ~ResourceMessageReplyParams();
+
+ void set_result(int32_t r) { result_ = r; }
+ int32_t result() const { return result_; }
+
+ virtual void Serialize(IPC::Message* msg) const OVERRIDE;
+ virtual bool Deserialize(const IPC::Message* msg,
+ PickleIterator* iter) OVERRIDE;
+
+ private:
+ // Pepper "result code" for the callback.
+ int32_t result_;
+};
+
+} // namespace proxy
+} // namespace ppapi
+
+namespace IPC {
+
+template <> struct PPAPI_PROXY_EXPORT
+ParamTraits<ppapi::proxy::ResourceMessageCallParams> {
+ typedef ppapi::proxy::ResourceMessageCallParams param_type;
+ static void Write(Message* m, const param_type& p) {
+ p.Serialize(m);
+ }
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
+ return r->Deserialize(m, iter);
+ }
+ static void Log(const param_type& p, std::string* l) {
+ }
+};
+
+template <> struct PPAPI_PROXY_EXPORT
+ParamTraits<ppapi::proxy::ResourceMessageReplyParams> {
+ typedef ppapi::proxy::ResourceMessageReplyParams param_type;
+ static void Write(Message* m, const param_type& p) {
+ p.Serialize(m);
+ }
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
+ return r->Deserialize(m, iter);
+ }
+ static void Log(const param_type& p, std::string* l) {
+ }
+};
+
+} // namespace IPC
+
+#endif // PPAPI_PROXY_RESOURCE_MESSAGE_PARAMS_H_
diff --git a/ppapi/proxy/resource_message_test_sink.cc b/ppapi/proxy/resource_message_test_sink.cc
new file mode 100644
index 0000000..7daf435
--- /dev/null
+++ b/ppapi/proxy/resource_message_test_sink.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/resource_message_test_sink.h"
+
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/resource_message_params.h"
+
+namespace ppapi {
+namespace proxy {
+
+namespace {
+
+// Backend for GetFirstResource[Call|Reply]Matching.
+template<class WrapperMessage, class Params>
+bool GetFirstResourceMessageMatching(const ResourceMessageTestSink& sink,
+ uint32 id,
+ Params* params,
+ IPC::Message* nested_msg) {
+ for (size_t i = 0; i < sink.message_count(); i++) {
+ const IPC::Message* msg = sink.GetMessageAt(i);
+ if (msg->type() == WrapperMessage::ID) {
+ Params cur_params;
+ IPC::Message cur_msg;
+ WrapperMessage::Read(msg, &cur_params, &cur_msg);
+ if (cur_msg.type() == id) {
+ *params = cur_params;
+ *nested_msg = cur_msg;
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+} // namespace
+
+ResourceMessageTestSink::ResourceMessageTestSink() {
+}
+
+ResourceMessageTestSink::~ResourceMessageTestSink() {
+}
+
+bool ResourceMessageTestSink::GetFirstResourceCallMatching(
+ uint32 id,
+ ResourceMessageCallParams* params,
+ IPC::Message* nested_msg) const {
+ return GetFirstResourceMessageMatching<PpapiHostMsg_ResourceCall,
+ ResourceMessageCallParams>(
+ *this, id, params, nested_msg);
+}
+
+bool ResourceMessageTestSink::GetFirstResourceReplyMatching(
+ uint32 id,
+ ResourceMessageReplyParams* params,
+ IPC::Message* nested_msg) {
+ return GetFirstResourceMessageMatching<PpapiPluginMsg_ResourceReply,
+ ResourceMessageReplyParams>(
+ *this, id, params, nested_msg);
+}
+
+} // namespace proxy
+} // namespace ppapi
diff --git a/ppapi/proxy/resource_message_test_sink.h b/ppapi/proxy/resource_message_test_sink.h
new file mode 100644
index 0000000..bf74bec
--- /dev/null
+++ b/ppapi/proxy/resource_message_test_sink.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_
+#define PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_
+
+#include "ipc/ipc_test_sink.h"
+
+namespace ppapi {
+namespace proxy {
+
+class ResourceMessageCallParams;
+class ResourceMessageReplyParams;
+
+// Extends IPC::TestSink to add extra capabilities for searching for and
+// decoding resource messages.
+class ResourceMessageTestSink : public IPC::TestSink {
+ public:
+ ResourceMessageTestSink();
+ virtual ~ResourceMessageTestSink();
+
+ // Searches the queue for the first resource call message with a nested
+ // message matching the given ID. On success, returns true and populates the
+ // givem params and nested message.
+ bool GetFirstResourceCallMatching(
+ uint32 id,
+ ResourceMessageCallParams* params,
+ IPC::Message* nested_msg) const;
+
+ // Like GetFirstResourceCallMatching except for replies.
+ bool GetFirstResourceReplyMatching(
+ uint32 id,
+ ResourceMessageReplyParams* params,
+ IPC::Message* nested_msg);
+};
+
+} // namespace proxy
+} // namespace ppapi
+
+#endif // PPAPI_PROXY_RESOURCE_MESSAGE_TEST_SINK_H_