summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorvictorhsieh@chromium.org <victorhsieh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-29 00:02:16 +0000
committervictorhsieh@chromium.org <victorhsieh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-29 00:02:16 +0000
commite8bd372d58a212cbc78c0ea2db22b5bcce2c3540 (patch)
tree24c528041bbf80fd29df08bb137f414ec64556f8 /ppapi
parent5d8fd599fc96814a5fb599937bfcd1892687b8c7 (diff)
downloadchromium_src-e8bd372d58a212cbc78c0ea2db22b5bcce2c3540.zip
chromium_src-e8bd372d58a212cbc78c0ea2db22b5bcce2c3540.tar.gz
chromium_src-e8bd372d58a212cbc78c0ea2db22b5bcce2c3540.tar.bz2
Provide IPC mechanism for host-to-resource messaging
BUG= Review URL: https://chromiumcodereview.appspot.com/11267034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164577 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/host/dispatch_host_message.h1
-rw-r--r--ppapi/proxy/dispatch_reply_message.h48
-rw-r--r--ppapi/proxy/websocket_resource.cc78
3 files changed, 65 insertions, 62 deletions
diff --git a/ppapi/host/dispatch_host_message.h b/ppapi/host/dispatch_host_message.h
index f891851..b9e57dc 100644
--- a/ppapi/host/dispatch_host_message.h
+++ b/ppapi/host/dispatch_host_message.h
@@ -87,4 +87,3 @@ inline int32_t DispatchResourceCall(ObjT* obj, Method method,
} // namespace ppapi
#endif // PPAPI_HOST_DISPATCH_HOST_MESSAGE_H_
-
diff --git a/ppapi/proxy/dispatch_reply_message.h b/ppapi/proxy/dispatch_reply_message.h
index 3c12b1d..4dd5dde 100644
--- a/ppapi/proxy/dispatch_reply_message.h
+++ b/ppapi/proxy/dispatch_reply_message.h
@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// This file provides infrastructure for dispatching host resource reply
-// messages. Normal IPC Reply handlers can't take extra parameters.
-// We want to take a ResourceMessageReplyParams as a parameter.
+// This file provides infrastructure for dispatching messasges from host
+// resource, inlcuding reply messages or unsolicited replies. Normal IPC Reply
+// handlers can't take extra parameters. We want to take a
+// ResourceMessageReplyParams as a parameter.
#ifndef PPAPI_PROXY_DISPATCH_REPLY_MESSAGE_H_
#define PPAPI_PROXY_DISPATCH_REPLY_MESSAGE_H_
@@ -29,35 +30,35 @@ template <class ObjT, class Method, class A>
inline void DispatchResourceReply(ObjT* obj, Method method,
const ResourceMessageReplyParams& params,
const Tuple1<A>& arg) {
- return (obj->*method)(params, arg.a);
+ (obj->*method)(params, arg.a);
}
template<class ObjT, class Method, class A, class B>
inline void DispatchResourceReply(ObjT* obj, Method method,
const ResourceMessageReplyParams& params,
const Tuple2<A, B>& arg) {
- return (obj->*method)(params, arg.a, arg.b);
+ (obj->*method)(params, arg.a, arg.b);
}
template<class ObjT, class Method, class A, class B, class C>
inline void DispatchResourceReply(ObjT* obj, Method method,
const ResourceMessageReplyParams& params,
const Tuple3<A, B, C>& arg) {
- return (obj->*method)(params, arg.a, arg.b, arg.c);
+ (obj->*method)(params, arg.a, arg.b, arg.c);
}
template<class ObjT, class Method, class A, class B, class C, class D>
inline void DispatchResourceReply(ObjT* obj, Method method,
const ResourceMessageReplyParams& params,
const Tuple4<A, B, C, D>& arg) {
- return (obj->*method)(params, arg.a, arg.b, arg.c, arg.d);
+ (obj->*method)(params, arg.a, arg.b, arg.c, arg.d);
}
template<class ObjT, class Method, class A, class B, class C, class D, class E>
inline void DispatchResourceReply(ObjT* obj, Method method,
const ResourceMessageReplyParams& params,
const Tuple5<A, B, C, D, E>& arg) {
- return (obj->*method)(params, arg.a, arg.b, arg.c, arg.d, arg.e);
+ (obj->*method)(params, arg.a, arg.b, arg.c, arg.d, arg.e);
}
// Used to dispatch resource replies. In most cases, you should not call this
@@ -124,9 +125,38 @@ void DispatchResourceReplyOrDefaultParams(
const IPC::Message& msg) {
DCHECK(msg.type() == MsgClass::ID || msg.type() == 0)
<< "Resource reply message of unexpected type.";
- return (obj->*method)(reply_params);
+ (obj->*method)(reply_params);
}
+// Note that this only works for message with 1 or more parameters. For
+// 0-parameter messages you need to use the _0 version below (since there are
+// no params in the message).
+#define PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(msg_class, member_func) \
+ case msg_class::ID: { \
+ msg_class::Schema::Param p; \
+ if (msg_class::Read(&ipc_message__, &p)) { \
+ ppapi::proxy::DispatchResourceReply( \
+ this, \
+ &_IpcMessageHandlerClass::member_func, \
+ params, p); \
+ } else { \
+ NOTREACHED(); \
+ } \
+ break; \
+ }
+
+#define PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_0(msg_class, member_func) \
+ case msg_class::ID: { \
+ member_func(params); \
+ break; \
+ }
+
+#define PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(code) \
+ default: { \
+ code; \
+ } \
+ break;
+
} // namespace proxy
} // namespace ppapi
diff --git a/ppapi/proxy/websocket_resource.cc b/ppapi/proxy/websocket_resource.cc
index 1f93c8b..eb4176f 100644
--- a/ppapi/proxy/websocket_resource.cc
+++ b/ppapi/proxy/websocket_resource.cc
@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/proxy/dispatch_reply_message.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/ppapi_globals.h"
#include "ppapi/shared_impl/var.h"
@@ -329,59 +330,32 @@ PP_Var WebSocketResource::GetURL() {
void WebSocketResource::OnReplyReceived(
const ResourceMessageReplyParams& params,
const IPC::Message& msg) {
- if (params.sequence())
- return PluginResource::OnReplyReceived(params, msg);
-
- // TODO(toyoshim): Currently, following unsolicited reply IPCs are handled
- // manually. We should introduce more useful mechanism for that.
- switch (msg.type()) {
- case PpapiPluginMsg_WebSocket_ReceiveTextReply::ID: {
- PpapiPluginMsg_WebSocket_ReceiveTextReply::Schema::Param p;
- if (PpapiPluginMsg_WebSocket_ReceiveTextReply::Read(&msg, &p))
- OnPluginMsgReceiveTextReply(params, p.a);
- else
- NOTREACHED();
- break;
- }
- case PpapiPluginMsg_WebSocket_ReceiveBinaryReply::ID: {
- PpapiPluginMsg_WebSocket_ReceiveBinaryReply::Schema::Param p;
- if (PpapiPluginMsg_WebSocket_ReceiveBinaryReply::Read(&msg, &p))
- OnPluginMsgReceiveBinaryReply(params, p.a);
- else
- NOTREACHED();
- break;
- }
- case PpapiPluginMsg_WebSocket_ErrorReply::ID: {
- OnPluginMsgErrorReply(params);
- break;
- }
- case PpapiPluginMsg_WebSocket_BufferedAmountReply::ID: {
- PpapiPluginMsg_WebSocket_BufferedAmountReply::Schema::Param p;
- if (PpapiPluginMsg_WebSocket_BufferedAmountReply::Read(&msg, &p))
- OnPluginMsgBufferedAmountReply(params, p.a);
- else
- NOTREACHED();
- break;
- }
- case PpapiPluginMsg_WebSocket_StateReply::ID: {
- PpapiPluginMsg_WebSocket_StateReply::Schema::Param p;
- if (PpapiPluginMsg_WebSocket_StateReply::Read(&msg, &p))
- OnPluginMsgStateReply(params, p.a);
- else
- NOTREACHED();
- break;
- }
- case PpapiPluginMsg_WebSocket_ClosedReply::ID: {
- PpapiPluginMsg_WebSocket_ClosedReply::Schema::Param p;
- if (PpapiPluginMsg_WebSocket_ClosedReply::Read(&msg, &p))
- OnPluginMsgClosedReply(params, p.a, p.b, p.c, p.d);
- else
- NOTREACHED();
- break;
- }
- default:
- NOTREACHED();
+ if (params.sequence()) {
+ PluginResource::OnReplyReceived(params, msg);
+ return;
}
+
+ IPC_BEGIN_MESSAGE_MAP(WebSocketResource, msg)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
+ PpapiPluginMsg_WebSocket_ReceiveTextReply,
+ OnPluginMsgReceiveTextReply)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
+ PpapiPluginMsg_WebSocket_ReceiveBinaryReply,
+ OnPluginMsgReceiveBinaryReply)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_0(
+ PpapiPluginMsg_WebSocket_ErrorReply,
+ OnPluginMsgErrorReply)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
+ PpapiPluginMsg_WebSocket_BufferedAmountReply,
+ OnPluginMsgBufferedAmountReply)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
+ PpapiPluginMsg_WebSocket_StateReply,
+ OnPluginMsgStateReply)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
+ PpapiPluginMsg_WebSocket_ClosedReply,
+ OnPluginMsgClosedReply)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(NOTREACHED())
+ IPC_END_MESSAGE_MAP()
}
void WebSocketResource::OnPluginMsgConnectReply(