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 | |
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')
-rw-r--r-- | ppapi/ppapi_proxy.gypi | 2 | ||||
-rw-r--r-- | ppapi/ppapi_tests.gypi | 2 | ||||
-rw-r--r-- | ppapi/proxy/dispatcher.cc | 2 | ||||
-rw-r--r-- | ppapi/proxy/host_dispatcher.cc | 9 | ||||
-rw-r--r-- | ppapi/proxy/host_dispatcher.h | 1 | ||||
-rw-r--r-- | ppapi/proxy/host_var_serialization_rules.cc | 6 | ||||
-rw-r--r-- | ppapi/proxy/host_var_serialization_rules.h | 8 | ||||
-rw-r--r-- | ppapi/proxy/interface_id.h | 1 | ||||
-rw-r--r-- | ppapi/proxy/plugin_var_tracker.cc | 4 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 9 | ||||
-rw-r--r-- | ppapi/proxy/ppb_testing_proxy.cc | 21 | ||||
-rw-r--r-- | ppapi/proxy/ppb_var_unittest.cc | 77 | ||||
-rw-r--r-- | ppapi/proxy/ppp_messaging_proxy.cc | 86 | ||||
-rw-r--r-- | ppapi/proxy/ppp_messaging_proxy.h | 41 | ||||
-rw-r--r-- | ppapi/proxy/ppp_messaging_proxy_test.cc | 141 | ||||
-rw-r--r-- | ppapi/proxy/serialized_var.h | 12 | ||||
-rw-r--r-- | ppapi/proxy/var_serialization_rules.h | 6 | ||||
-rw-r--r-- | ppapi/tests/test_post_message.cc | 5 |
18 files changed, 390 insertions, 43 deletions
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 550dec8..68a5364 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -136,6 +136,8 @@ 'proxy/ppp_instance_private_proxy.h', 'proxy/ppp_instance_proxy.cc', 'proxy/ppp_instance_proxy.h', + 'proxy/ppp_messaging_proxy.cc', + 'proxy/ppp_messaging_proxy.h', 'proxy/proxy_channel.cc', 'proxy/proxy_channel.h', 'proxy/proxy_module.cc', diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi index be8795c..a15748f 100644 --- a/ppapi/ppapi_tests.gypi +++ b/ppapi/ppapi_tests.gypi @@ -191,7 +191,9 @@ 'proxy/plugin_var_tracker_unittest.cc', 'proxy/ppapi_proxy_test.cc', 'proxy/ppapi_proxy_test.h', + 'proxy/ppb_var_unittest.cc', 'proxy/ppp_instance_proxy_test.cc', + 'proxy/ppp_messaging_proxy_test.cc', 'proxy/serialized_var_unittest.cc', ], }, diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc index 0edc24d..dc61c51 100644 --- a/ppapi/proxy/dispatcher.cc +++ b/ppapi/proxy/dispatcher.cc @@ -85,6 +85,7 @@ #include "ppapi/proxy/ppp_input_event_proxy.h" #include "ppapi/proxy/ppp_instance_private_proxy.h" #include "ppapi/proxy/ppp_instance_proxy.h" +#include "ppapi/proxy/ppp_messaging_proxy.h" #include "ppapi/proxy/var_serialization_rules.h" namespace pp { @@ -171,6 +172,7 @@ InterfaceList::InterfaceList() { AddPPP(PPP_InputEvent_Proxy::GetInfo()); AddPPP(PPP_Instance_Private_Proxy::GetInfo()); AddPPP(PPP_Instance_Proxy::GetInfo1_0()); + AddPPP(PPP_Messaging_Proxy::GetInfo()); } void InterfaceList::AddPPP(const InterfaceProxy::Info* info) { diff --git a/ppapi/proxy/host_dispatcher.cc b/ppapi/proxy/host_dispatcher.cc index 82b353e..40fc717 100644 --- a/ppapi/proxy/host_dispatcher.cc +++ b/ppapi/proxy/host_dispatcher.cc @@ -9,7 +9,7 @@ #include "base/debug/trace_event.h" #include "base/logging.h" #include "ppapi/c/private/ppb_proxy_private.h" -#include "ppapi/c/dev/ppb_var_deprecated.h" +#include "ppapi/c/ppb_var.h" #include "ppapi/proxy/host_var_serialization_rules.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/resource_creation_proxy.h" @@ -70,13 +70,10 @@ HostDispatcher::HostDispatcher(base::ProcessHandle remote_process_handle, g_module_to_dispatcher = new ModuleToDispatcherMap; (*g_module_to_dispatcher)[pp_module_] = this; - const PPB_Var_Deprecated* var_interface = - static_cast<const PPB_Var_Deprecated*>( - local_get_interface(PPB_VAR_DEPRECATED_INTERFACE)); + const PPB_Var* var_interface = + static_cast<const PPB_Var*>(local_get_interface(PPB_VAR_INTERFACE)); SetSerializationRules(new HostVarSerializationRules(var_interface, module)); - // TODO(brettw): It might be more testable to inject the PPB_Proxy_Private - // instead of requesting it from GetLocalInterface. ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( GetLocalInterface(PPB_PROXY_PRIVATE_INTERFACE)); DCHECK(ppb_proxy_) << "The proxy interface should always be supported."; diff --git a/ppapi/proxy/host_dispatcher.h b/ppapi/proxy/host_dispatcher.h index e3d9001..08d4dd6 100644 --- a/ppapi/proxy/host_dispatcher.h +++ b/ppapi/proxy/host_dispatcher.h @@ -13,7 +13,6 @@ #include "base/process.h" #include "ppapi/c/pp_instance.h" #include "ppapi/proxy/dispatcher.h" -#include "ppapi/proxy/plugin_var_tracker.h" #include "ppapi/shared_impl/function_group_base.h" struct PPB_Proxy_Private; diff --git a/ppapi/proxy/host_var_serialization_rules.cc b/ppapi/proxy/host_var_serialization_rules.cc index 2a1d0ee..2541f03 100644 --- a/ppapi/proxy/host_var_serialization_rules.cc +++ b/ppapi/proxy/host_var_serialization_rules.cc @@ -1,17 +1,17 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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/host_var_serialization_rules.h" #include "base/logging.h" -#include "ppapi/c/dev/ppb_var_deprecated.h" +#include "ppapi/c/ppb_var.h" namespace pp { namespace proxy { HostVarSerializationRules::HostVarSerializationRules( - const PPB_Var_Deprecated* var_interface, + const PPB_Var* var_interface, PP_Module pp_module) : var_interface_(var_interface), pp_module_(pp_module) { diff --git a/ppapi/proxy/host_var_serialization_rules.h b/ppapi/proxy/host_var_serialization_rules.h index 4fd39be..4b6f63d 100644 --- a/ppapi/proxy/host_var_serialization_rules.h +++ b/ppapi/proxy/host_var_serialization_rules.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. @@ -9,7 +9,7 @@ #include "ppapi/c/pp_module.h" #include "ppapi/proxy/var_serialization_rules.h" -struct PPB_Var_Deprecated; +struct PPB_Var; namespace pp { namespace proxy { @@ -19,7 +19,7 @@ class VarTracker; // Implementation of the VarSerializationRules interface for the host side. class HostVarSerializationRules : public VarSerializationRules { public: - HostVarSerializationRules(const PPB_Var_Deprecated* var_interface, + HostVarSerializationRules(const PPB_Var* var_interface, PP_Module pp_module); ~HostVarSerializationRules(); @@ -41,7 +41,7 @@ class HostVarSerializationRules : public VarSerializationRules { // string object. void VarToString(const PP_Var& var, std::string* str); - const PPB_Var_Deprecated* var_interface_; + const PPB_Var* var_interface_; PP_Module pp_module_; DISALLOW_COPY_AND_ASSIGN(HostVarSerializationRules); diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h index ba31aaa..23fa86d 100644 --- a/ppapi/proxy/interface_id.h +++ b/ppapi/proxy/interface_id.h @@ -58,6 +58,7 @@ enum InterfaceID { INTERFACE_ID_PPP_INPUT_EVENT, INTERFACE_ID_PPP_INSTANCE, INTERFACE_ID_PPP_INSTANCE_PRIVATE, + INTERFACE_ID_PPP_MESSAGING, INTERFACE_ID_PPP_VIDEO_DECODER_DEV, INTERFACE_ID_RESOURCE_CREATION, diff --git a/ppapi/proxy/plugin_var_tracker.cc b/ppapi/proxy/plugin_var_tracker.cc index 5734f96..16d5992 100644 --- a/ppapi/proxy/plugin_var_tracker.cc +++ b/ppapi/proxy/plugin_var_tracker.cc @@ -75,6 +75,10 @@ PluginVarTracker::VarID PluginVarTracker::MakeString(const char* str, iter_success_pair = var_id_to_string_.insert(VarIDStringMap::value_type(new_id, str_ptr)); } + // Release the local pointer. + str_ptr = NULL; + // Now the map should have the only reference. + DCHECK(iter_success_pair.first->second->HasOneRef()); iter_success_pair.first->second->AddRef(); return new_id; } diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index f4739e8..9a1e47b 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -303,6 +303,11 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PpapiMsg_PPPInstancePrivate_GetInstanceObject, PP_Instance /* instance */, pp::proxy::SerializedVar /* result */) +// PPP_Messaging. +IPC_MESSAGE_ROUTED2(PpapiMsg_PPPMessaging_HandleMessage, + PP_Instance /* instance */, + pp::proxy::SerializedVar /* message */) + // PPB_URLLoader // (Messages from browser to plugin to notify it of changes in state.) IPC_MESSAGE_ROUTED1(PpapiMsg_PPBURLLoader_UpdateProgress, @@ -744,10 +749,6 @@ IPC_SYNC_MESSAGE_ROUTED3_1( pp::proxy::HostResource /* image */, PP_Point /* top_left */, PP_Bool /* result */) -IPC_SYNC_MESSAGE_ROUTED1_0(PpapiHostMsg_PPBTesting_RunMessageLoop, - PP_Instance /* instance */) -IPC_SYNC_MESSAGE_ROUTED1_0(PpapiHostMsg_PPBTesting_QuitMessageLoop, - PP_Instance /* instance */) IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance, PP_Instance /* instance */, uint32 /* result */) diff --git a/ppapi/proxy/ppb_testing_proxy.cc b/ppapi/proxy/ppb_testing_proxy.cc index 593ed7d..ab069b1 100644 --- a/ppapi/proxy/ppb_testing_proxy.cc +++ b/ppapi/proxy/ppb_testing_proxy.cc @@ -42,21 +42,14 @@ PP_Bool ReadImageData(PP_Resource graphics_2d, } void RunMessageLoop(PP_Instance instance) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return; - IPC::SyncMessage* msg = new PpapiHostMsg_PPBTesting_RunMessageLoop( - INTERFACE_ID_PPB_TESTING, instance); - msg->EnableMessagePumping(); - dispatcher->Send(msg); + bool old_state = MessageLoop::current()->NestableTasksAllowed(); + MessageLoop::current()->SetNestableTasksAllowed(true); + MessageLoop::current()->Run(); + MessageLoop::current()->SetNestableTasksAllowed(old_state); } void QuitMessageLoop(PP_Instance instance) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return; - dispatcher->Send(new PpapiHostMsg_PPBTesting_QuitMessageLoop( - INTERFACE_ID_PPB_TESTING, instance)); + MessageLoop::current()->QuitNow(); } uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { @@ -109,10 +102,6 @@ bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, OnMsgReadImageData) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_RunMessageLoop, - OnMsgRunMessageLoop) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_QuitMessageLoop, - OnMsgQuitMessageLoop) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance, OnMsgGetLiveObjectsForInstance) IPC_MESSAGE_UNHANDLED(handled = false) diff --git a/ppapi/proxy/ppb_var_unittest.cc b/ppapi/proxy/ppb_var_unittest.cc new file mode 100644 index 0000000..a2e6794 --- /dev/null +++ b/ppapi/proxy/ppb_var_unittest.cc @@ -0,0 +1,77 @@ +// 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 <string> +#include <vector> + +#include "base/string_number_conversions.h" +#include "ppapi/c/pp_var.h" +#include "ppapi/c/ppb_var.h" +#include "ppapi/proxy/ppapi_proxy_test.h" + +// TODO(dmichael): Make PPB_Var_Proxy and PluginResourceTracker thread-safe and +// add thread-safety tests here. + +namespace { +std::string VarToString(const PP_Var& var, const PPB_Var* ppb_var) { + uint32_t len = 0; + const char* utf8 = ppb_var->VarToUtf8(var, &len); + return std::string(utf8, len); +} +} // namespace + +namespace pp { +namespace proxy { + +class PPB_VarTest : public PluginProxyTest { + public: + PPB_VarTest() {} +}; + +TEST_F(PPB_VarTest, Strings) { + const PPB_Var* ppb_var = static_cast<const PPB_Var*>( + plugin_dispatcher()->GetInterfaceFromDispatcher(PPB_VAR_INTERFACE)); + + // Make a vector of strings, where the value of test_strings[i] is "i". + const int kNumStrings = 5; + std::vector<std::string> test_strings(kNumStrings); + for (int i = 0; i < kNumStrings; ++i) + test_strings[i] = base::IntToString(i); + + std::vector<PP_Var> vars(kNumStrings); + for (int i = 0; i < kNumStrings; ++i) { + vars[i] = ppb_var->VarFromUtf8(pp_module(), + test_strings[i].c_str(), + test_strings[i].length()); + EXPECT_EQ(test_strings[i], VarToString(vars[i], ppb_var)); + } + // At this point, they should each have a ref count of 1. Add some more. + const int kRefsToAdd = 3; + for (int ref = 0; ref < kRefsToAdd; ++ref) { + for (int i = 0; i < kNumStrings; ++i) { + ppb_var->AddRef(vars[i]); + // Make sure the string is still there with the right value. + EXPECT_EQ(test_strings[i], VarToString(vars[i], ppb_var)); + } + } + for (int ref = 0; ref < kRefsToAdd; ++ref) { + for (int i = 0; i < kNumStrings; ++i) { + ppb_var->Release(vars[i]); + // Make sure the string is still there with the right value. + EXPECT_EQ(test_strings[i], VarToString(vars[i], ppb_var)); + } + } + // Now remove the ref counts for each string and make sure they are gone. + for (int i = 0; i < kNumStrings; ++i) { + ppb_var->Release(vars[i]); + uint32_t len = 10; + const char* utf8 = ppb_var->VarToUtf8(vars[i], &len); + EXPECT_EQ(NULL, utf8); + EXPECT_EQ(0u, len); + } +} + +} // namespace proxy +} // namespace pp + 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 diff --git a/ppapi/proxy/ppp_messaging_proxy.h b/ppapi/proxy/ppp_messaging_proxy.h new file mode 100644 index 0000000..a8b396a --- /dev/null +++ b/ppapi/proxy/ppp_messaging_proxy.h @@ -0,0 +1,41 @@ +// 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. + +#ifndef PPAPI_PROXY_PPP_MESSAGING_PROXY_H_ +#define PPAPI_PROXY_PPP_MESSAGING_PROXY_H_ + +#include "ppapi/c/pp_instance.h" +#include "ppapi/proxy/interface_proxy.h" + +struct PPP_Messaging; + +namespace pp { +namespace proxy { + +class SerializedVarReceiveInput; + +class PPP_Messaging_Proxy : public InterfaceProxy { + public: + PPP_Messaging_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPP_Messaging_Proxy(); + + static const Info* GetInfo(); + + const PPP_Messaging* ppp_messaging_target() const { + return static_cast<const PPP_Messaging*>(target_interface()); + } + + // InterfaceProxy implementation. + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; + + private: + // Message handlers. + void OnMsgHandleMessage(PP_Instance instance, + SerializedVarReceiveInput data); +}; + +} // namespace proxy +} // namespace pp + +#endif // PPAPI_PROXY_PPP_MESSAGING_PROXY_H_ diff --git a/ppapi/proxy/ppp_messaging_proxy_test.cc b/ppapi/proxy/ppp_messaging_proxy_test.cc new file mode 100644 index 0000000..ef4143b --- /dev/null +++ b/ppapi/proxy/ppp_messaging_proxy_test.cc @@ -0,0 +1,141 @@ +// 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 <cstring> + +#include "base/synchronization/waitable_event.h" +#include "ppapi/c/pp_var.h" +#include "ppapi/c/ppb_var.h" +#include "ppapi/c/ppp_messaging.h" +#include "ppapi/proxy/ppapi_proxy_test.h" + +namespace pp { +namespace proxy { + +namespace { + +// This is a poor man's mock of PPP_Messaging using global variables. Eventually +// we should generalize making PPAPI interface mocks by using IDL or macro/ +// template magic. +PP_Instance received_instance; +PP_Var received_var; +base::WaitableEvent handle_message_called(false, false); + +void HandleMessage(PP_Instance instance, PP_Var message_data) { + received_instance = instance; + received_var = message_data; + handle_message_called.Signal(); +} + +// Clear all the 'received' values for our mock. Call this before you expect +// one of the functions to be invoked. +void ResetReceived() { + received_instance = 0; + received_var.type = PP_VARTYPE_UNDEFINED; + received_var.value.as_id = 0; +} + +PPP_Messaging ppp_messaging_mock = { + &HandleMessage +}; + +// Define a fake PPB_Var for the host side so that we can send a string var. +void AddRef(PP_Var /*var*/) { +} +void Release(PP_Var /*var*/) { +} +PP_Var VarFromUtf8(PP_Module /*module*/, const char* /*data*/, uint32_t len) { + return PP_MakeUndefined(); +} +// No matter what id we're given, always provide kTestString and its length. +const std::string kTestString = "Hello world!"; +const char* VarToUtf8(PP_Var /*var*/, uint32_t* len) { + *len = kTestString.size(); + return kTestString.c_str(); +} + +PPB_Var ppb_var_mock = { + &AddRef, + &Release, + &VarFromUtf8, + &VarToUtf8 +}; + +} // namespace + +class PPP_Messaging_ProxyTest : public TwoWayTest { + public: + PPP_Messaging_ProxyTest() + : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { + plugin().RegisterTestInterface(PPP_MESSAGING_INTERFACE, + &ppp_messaging_mock); + host().RegisterTestInterface(PPB_VAR_INTERFACE, &ppb_var_mock); + } +}; + +TEST_F(PPP_Messaging_ProxyTest, SendMessages) { + // Grab the host-side proxy of ppp_messaging. + const PPP_Messaging* ppp_messaging = static_cast<const PPP_Messaging*>( + host().host_dispatcher()->GetProxiedInterface( + PPP_MESSAGING_INTERFACE)); + + PP_Instance expected_instance = pp_instance(); + PP_Var expected_var = PP_MakeUndefined(); + ResetReceived(); + ppp_messaging->HandleMessage(expected_instance, expected_var); + handle_message_called.Wait(); + EXPECT_EQ(expected_instance, received_instance); + EXPECT_EQ(expected_var.type, received_var.type); + + expected_var = PP_MakeNull(); + ResetReceived(); + ppp_messaging->HandleMessage(expected_instance, expected_var); + handle_message_called.Wait(); + EXPECT_EQ(expected_instance, received_instance); + EXPECT_EQ(expected_var.type, received_var.type); + + expected_var = PP_MakeBool(PP_TRUE); + ResetReceived(); + ppp_messaging->HandleMessage(expected_instance, expected_var); + handle_message_called.Wait(); + EXPECT_EQ(expected_instance, received_instance); + EXPECT_EQ(expected_var.type, received_var.type); + EXPECT_EQ(expected_var.value.as_bool, received_var.value.as_bool); + + expected_var = PP_MakeInt32(12345); + ResetReceived(); + ppp_messaging->HandleMessage(expected_instance, expected_var); + handle_message_called.Wait(); + EXPECT_EQ(expected_instance, received_instance); + EXPECT_EQ(expected_var.type, received_var.type); + EXPECT_EQ(expected_var.value.as_int, received_var.value.as_int); + + expected_var = PP_MakeDouble(3.1415); + ResetReceived(); + ppp_messaging->HandleMessage(expected_instance, expected_var); + handle_message_called.Wait(); + EXPECT_EQ(expected_instance, received_instance); + EXPECT_EQ(expected_var.type, received_var.type); + EXPECT_EQ(expected_var.value.as_double, received_var.value.as_double); + + expected_var.type = PP_VARTYPE_STRING; + expected_var.value.as_id = 1979; + ResetReceived(); + ppp_messaging->HandleMessage(expected_instance, expected_var); + handle_message_called.Wait(); + EXPECT_EQ(expected_instance, received_instance); + EXPECT_EQ(expected_var.type, received_var.type); + const std::string* received_string = + plugin().var_tracker().GetExistingString(received_var); + ASSERT_TRUE(received_string); + EXPECT_EQ(kTestString, *received_string); + // Now release the var, and the string should go away (because the ref + // count should be one). + plugin().var_tracker().Release(received_var); + EXPECT_FALSE(plugin().var_tracker().GetExistingString(received_var)); +} + +} // namespace proxy +} // namespace pp + diff --git a/ppapi/proxy/serialized_var.h b/ppapi/proxy/serialized_var.h index 84168d7..6512911 100644 --- a/ppapi/proxy/serialized_var.h +++ b/ppapi/proxy/serialized_var.h @@ -22,7 +22,7 @@ namespace proxy { class Dispatcher; class VarSerializationRules; -// This class encapsulates a var so that we can serialize and deserialize it +// This class encapsulates a var so that we can serialize and deserialize it. // The problem is that for strings, serialization and deserialization requires // knowledge from outside about how to get at or create a string. So this // object groups the var with a dispatcher so that string values can be set or @@ -40,13 +40,13 @@ class VarSerializationRules; // objects and for dealing with strings // // This makes SerializedVar complicated and easy to mess up. To make it -// reasonable to use all functions are protected and there are a use-specific -// classes that encapsulate exactly one type of use in a way that typically +// reasonable to use, all functions are protected and there are use-specific +// classes that each encapsulate exactly one type of use in a way that typically // won't compile if you do the wrong thing. // // The IPC system is designed to pass things around and will make copies in // some cases, so our system must be designed so that this stuff will work. -// This is challenging when the SerializedVar must to some cleanup after the +// This is challenging when the SerializedVar must do some cleanup after the // message is sent. To work around this, we create an inner class using a // linked_ptr so all copies of a SerializedVar can share and we can guarantee // that the actual data will get cleaned up on shutdown. @@ -145,7 +145,7 @@ class SerializedVar { // a string ID. Before this, the as_id will be 0 for VARTYPE_STRING. PP_Var var_; - // Holds the literal string value to/from IPC. This will be valid of the + // Holds the literal string value to/from IPC. This will be valid if the // var_ is VARTYPE_STRING. std::string string_value_; @@ -181,7 +181,7 @@ class SerializedVar { // IPC_MESSAGE_ROUTED1(MyFunction, SerializedVar); // Sender would be: // void MyFunctionProxy(PP_Var param) { -// Send(new MyFunctionMsg(SerializedVarSendInput(param)); +// Send(new MyFunctionMsg(SerializedVarSendInput(dispatcher, param)); // } class SerializedVarSendInput : public SerializedVar { public: diff --git a/ppapi/proxy/var_serialization_rules.h b/ppapi/proxy/var_serialization_rules.h index 38698ae..67d3db2 100644 --- a/ppapi/proxy/var_serialization_rules.h +++ b/ppapi/proxy/var_serialization_rules.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. @@ -51,10 +51,10 @@ class VarSerializationRules { Dispatcher* dispatcher) = 0; virtual void EndReceiveCallerOwned(const PP_Var& var) = 0; - // Passinag refs ------------------------------------------------------------- + // Passing refs ------------------------------------------------------------- // // A pass-ref transfer is when ownership of a reference is passed from - // onen side to the other. Normally, this happens via return values and + // one side to the other. Normally, this happens via return values and // output arguments, as for exceptions. The code generating the value // (the function returning it in the case of a return value) will AddRef // the var on behalf of the consumer of the value. Responsibility for diff --git a/ppapi/tests/test_post_message.cc b/ppapi/tests/test_post_message.cc index ea29882..02ebed6 100644 --- a/ppapi/tests/test_post_message.cc +++ b/ppapi/tests/test_post_message.cc @@ -14,6 +14,11 @@ #include "ppapi/tests/test_utils.h" #include "ppapi/tests/testing_instance.h" +// Windows defines 'PostMessage', so we have to undef it. +#ifdef PostMessage +#undef PostMessage +#endif + REGISTER_TEST_CASE(PostMessage); namespace { |