Exemple #1
0
/**
 * Given a message from JavaScript, parse it for functions and parameters.
 *
 * The format of the message is:
 * {
 *  "cmd": <function name>,
 *  "args": [<arg0>, <arg1>, ...]
 * }
 *
 * @param[in] message The message to parse.
 * @param[out] out_function The function name.
 * @param[out] out_params A PP_Var array.
 * @return 0 if successful, otherwise 1.
 */
static int ParseMessage(struct PP_Var message,const char **out_function,struct PP_Var *out_params)
{
    if ( message.type != PP_VARTYPE_DICTIONARY )
        return(1);
    struct PP_Var cmd_value = GetDictVar(message, "cmd");
    *out_function = VarToCStr(cmd_value);
    g_ppb_var->Release(cmd_value);
    *out_params = GetDictVar(message, "args");
    PostMessage("Parse.(%s) cmd.(%s)\n",*out_function,VarToCStr(*out_params));
    if ( cmd_value.type != PP_VARTYPE_STRING )
        return(1);
    if ( out_params->type != PP_VARTYPE_ARRAY )
        return(1);
    return(0);
}
/**
 * Given a message from JavaScript, parse it for functions and parameters.
 *
 * The format of the message is:
 * {
 *  "cmd": <function name>,
 *  "args": [<arg0>, <arg1>, ...]
 * }
 *
 * @param[in] message The message to parse.
 * @param[out] out_function The function name.
 * @param[out] out_params A PP_Var array.
 * @return 0 if successful, otherwise 1.
 */
static int ParseMessage(struct PP_Var message,
                        char** out_function,
                        struct PP_Var* out_params) {
  if (message.type != PP_VARTYPE_DICTIONARY) {
    return 1;
  }

  struct PP_Var cmd_value = GetDictVar(message, "cmd");
  if (cmd_value.type != PP_VARTYPE_STRING) {
    g_ppb_var->Release(cmd_value);
    return 1;
  }
  *out_function = VarToCStr(cmd_value);
  g_ppb_var->Release(cmd_value);

  *out_params = GetDictVar(message, "args");
  if (out_params->type != PP_VARTYPE_ARRAY) {
    g_ppb_var->Release(*out_params);
    return 1;
  }

  return 0;
}
Exemple #3
0
/**
 * Append a PP_Var to the response dictionary.
 * @param[in,out] response_var The response PP_var.
 * @param[in] value The value to add to the response args.
 * @param[out] out_error An error message, if this call failed.
 */
static void AppendResponseVar(struct PP_Var* response_var,
                              struct PP_Var value,
                              const char** out_error) {
    struct PP_Var args_value = GetDictVar(*response_var, "args");
    uint32_t args_length = g_ppb_var_array->GetLength(args_value);
    PP_Bool result = g_ppb_var_array->Set(args_value, args_length, value);
    if (!result) {
        // Release the dictionary that was there before.
        g_ppb_var->Release(*response_var);

        // Return an error message instead.
        *response_var = PP_MakeUndefined();
        *out_error = PrintfToNewString("Unable to append value to result");
        return;
    }
}