Example #1
0
static Variant to_variant(const pp::Var& p_var) {

	if (p_var.is_undefined() || p_var.is_null())
		return Variant();
	if (p_var.is_bool())
		return Variant(p_var.AsBool());
	if (p_var.is_double())
		return Variant(p_var.AsDouble());
	if (p_var.is_int())
		return Variant((int64_t)p_var.AsInt());
	if (p_var.is_string())
		return Variant(String::utf8(p_var.AsString().c_str()));

	return Variant();
};
  // Handler for messages coming in from the browser via postMessage().  The
  // @a var_message can contain be any pp:Var type; for example int, string
  // Array or Dictinary. Please see the pp:Var documentation for more details.
  // @param[in] var_message The message posted by the browser.
  virtual void HandleMessage(const pp::Var& var_message) {
    /*if (!var_message.is_string())
      return;

    std::string message = var_message.AsString();
    pp::Var var_reply;
    if (message == kHelloString) {
      var_reply = pp::Var(kReplyString);
      PostMessage(var_reply);
    }*/

    // Send integer events from JS straight to the CPU
    if (!var_message.is_int()) {
      uint32_t msgInt = var_message.AsInt();

      cpu->OnExtMessage(msgInt);
    }
  }