summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi/cpp')
-rw-r--r--ppapi/cpp/instance.cc16
-rw-r--r--ppapi/cpp/instance.h10
-rw-r--r--ppapi/cpp/module.cc18
3 files changed, 44 insertions, 0 deletions
diff --git a/ppapi/cpp/instance.cc b/ppapi/cpp/instance.cc
index 72676d1..025741f 100644
--- a/ppapi/cpp/instance.cc
+++ b/ppapi/cpp/instance.cc
@@ -4,6 +4,7 @@
#include "ppapi/cpp/instance.h"
+#include "ppapi/c/dev/ppb_messaging_dev.h"
#include "ppapi/c/dev/ppp_printing_dev.h"
#include "ppapi/c/ppb_instance.h"
#include "ppapi/cpp/common.h"
@@ -25,6 +26,10 @@ template <> const char* interface_name<PPB_Instance>() {
return PPB_INSTANCE_INTERFACE;
}
+template <> const char* interface_name<PPB_Messaging_Dev>() {
+ return PPB_MESSAGING_DEV_INTERFACE;
+}
+
} // namespace
Instance::Instance(PP_Instance instance) : pp_instance_(instance) {
@@ -61,6 +66,10 @@ bool Instance::HandleInputEvent(const PP_InputEvent& /*event*/) {
return false;
}
+void Instance::HandleMessage(const Var& /*message_data*/) {
+ return;
+}
+
Var Instance::GetInstanceObject() {
return Var();
}
@@ -115,6 +124,13 @@ Var Instance::ExecuteScript(const Var& script, Var* exception) {
Var::OutException(exception).get()));
}
+void Instance::PostMessage(const Var& message) {
+ if (!has_interface<PPB_Messaging_Dev>())
+ return;
+ get_interface<PPB_Messaging_Dev>()->PostMessage(pp_instance(),
+ message.pp_var());
+}
+
void Instance::AddPerInstanceObject(const std::string& interface_name,
void* object) {
// Ensure we're not trying to register more than one object per interface
diff --git a/ppapi/cpp/instance.h b/ppapi/cpp/instance.h
index 497189f..69de79f 100644
--- a/ppapi/cpp/instance.h
+++ b/ppapi/cpp/instance.h
@@ -96,6 +96,16 @@ class Instance {
/** See PPB_Instance.ExecuteScript. */
Var ExecuteScript(const Var& script, Var* exception = NULL);
+
+ // These functions use the PPP_Messaging and PPB_Messaging interfaces, so that
+ // messaging can be done conveniently for a pp::Instance without using a
+ // separate C++ class.
+
+ /** See PPP_Messaging.HandleMessage. */
+ virtual void HandleMessage(const Var& message_data);
+ /** See PPB_Messaging.PostMessage. */
+ void PostMessage(const Var& message);
+
// @}
/**
diff --git a/ppapi/cpp/module.cc b/ppapi/cpp/module.cc
index 220609d..f64041d 100644
--- a/ppapi/cpp/module.cc
+++ b/ppapi/cpp/module.cc
@@ -25,6 +25,7 @@
#include <string.h>
+#include "ppapi/c/dev/ppp_messaging_dev.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/c/ppp_instance.h"
@@ -134,6 +135,20 @@ static PPP_Instance instance_interface = {
&Instance_GetInstanceObject
};
+void Messaging_HandleMessage(PP_Instance pp_instance, PP_Var var) {
+ Module* module_singleton = Module::Get();
+ if (!module_singleton)
+ return;
+ Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
+ if (!instance)
+ return;
+ instance->HandleMessage(Var(Var::PassRef(), var));
+}
+
+static PPP_Messaging_Dev instance_messaging_interface = {
+ &Messaging_HandleMessage
+};
+
// Module ----------------------------------------------------------------------
Module::Module() : pp_module_(0), get_browser_interface_(NULL), core_(NULL) {
@@ -152,6 +167,9 @@ const void* Module::GetPluginInterface(const char* interface_name) {
if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0)
return &instance_interface;
+ if (strcmp(interface_name, PPP_MESSAGING_DEV_INTERFACE) == 0)
+ return &instance_messaging_interface;
+
// Now see if anything was dynamically registered.
InterfaceMap::const_iterator found = additional_interfaces_.find(
std::string(interface_name));