diff options
author | dmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-03 14:38:24 +0000 |
---|---|---|
committer | dmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-03 14:38:24 +0000 |
commit | b20df1c2cf9c588dbe99b780362f63df19d80ae3 (patch) | |
tree | 16685a665167d65ab4b3a54aed443517514d8853 /ppapi/proxy/ppp_messaging_proxy.cc | |
parent | 0cd9ef3d6860ef50c46f590b0d1c990041e06da8 (diff) | |
download | chromium_src-b20df1c2cf9c588dbe99b780362f63df19d80ae3.zip chromium_src-b20df1c2cf9c588dbe99b780362f63df19d80ae3.tar.gz chromium_src-b20df1c2cf9c588dbe99b780362f63df19d80ae3.tar.bz2 |
Proxy PPP_Messaging.
I added a couple of tests while I was figuring out the ref counting problem I was having. Also lots of bonus spelling fixes.
BUG=86123
TEST=ppp_messaging_proxy_test and ppapi_tests
Review URL: http://codereview.chromium.org/7531003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95240 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/ppp_messaging_proxy.cc')
-rw-r--r-- | ppapi/proxy/ppp_messaging_proxy.cc | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/ppapi/proxy/ppp_messaging_proxy.cc b/ppapi/proxy/ppp_messaging_proxy.cc new file mode 100644 index 0000000..39ce89b --- /dev/null +++ b/ppapi/proxy/ppp_messaging_proxy.cc @@ -0,0 +1,86 @@ +// Copyright (c) 2011 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/ppp_messaging_proxy.h" + +#include <algorithm> + +#include "ppapi/c/ppp_messaging.h" +#include "ppapi/proxy/host_dispatcher.h" +#include "ppapi/proxy/plugin_var_tracker.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/serialized_var.h" + +namespace pp { +namespace proxy { + +namespace { + +void HandleMessage(PP_Instance instance, PP_Var message_data) { + HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); + if (!dispatcher || (message_data.type == PP_VARTYPE_OBJECT)) { + // The dispatcher should always be valid, and the browser should never send + // an 'object' var over PPP_Messaging. + NOTREACHED(); + return; + } + + dispatcher->Send(new PpapiMsg_PPPMessaging_HandleMessage( + INTERFACE_ID_PPP_MESSAGING, + instance, + SerializedVarSendInput(dispatcher, message_data))); +} + +static const PPP_Messaging messaging_interface = { + &HandleMessage +}; + +InterfaceProxy* CreateMessagingProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPP_Messaging_Proxy(dispatcher, target_interface); +} + +} // namespace + +PPP_Messaging_Proxy::PPP_Messaging_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPP_Messaging_Proxy::~PPP_Messaging_Proxy() { +} + +// static +const InterfaceProxy::Info* PPP_Messaging_Proxy::GetInfo() { + static const Info info = { + &messaging_interface, + PPP_MESSAGING_INTERFACE, + INTERFACE_ID_PPP_MESSAGING, + false, + &CreateMessagingProxy, + }; + return &info; +} + +bool PPP_Messaging_Proxy::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(PPP_Messaging_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, + OnMsgHandleMessage) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void PPP_Messaging_Proxy::OnMsgHandleMessage( + PP_Instance instance, SerializedVarReceiveInput message_data) { + PP_Var received_var(message_data.Get(dispatcher())); + // SerializedVarReceiveInput will decrement the reference count, but we want + // to give the recipient a reference. + PluginVarTracker::GetInstance()->AddRef(received_var); + ppp_messaging_target()->HandleMessage(instance, received_var); +} + +} // namespace proxy +} // namespace pp |