static
void
n2p_construct_ptac(void *param)
{
    struct construct_param_s *p = param;
    NPP npp = tables_get_npobj_npp_mapping(p->object);

    NPVariant *np_args = malloc(p->argc * sizeof(NPVariant));
    for (uint32_t k = 0; k < p->argc; k ++)
        np_args[k] = pp_var_to_np_variant(p->argv[k]);

    NPVariant np_result;
    bool res = npp ? npn.construct(npp, p->object, np_args, p->argc, &np_result) : FALSE;

    for (uint32_t k = 0; k < p->argc; k ++)
        npn.releasevariantvalue(&np_args[k]);
    free(np_args);

    if (res) {
        struct PP_Var var = np_variant_to_pp_var(np_result);

        if (np_result.type == NPVariantType_Object)
            tables_add_npobj_npp_mapping(np_result.value.objectValue, npp);
        else
            npn.releasevariantvalue(&np_result);

        p->result = var;
    } else {
        p->result = PP_MakeUndefined();
    }

    ppb_message_loop_post_quit_depth(p->m_loop, PP_FALSE, p->depth);
}
Example #2
0
static
void
_execute_script_ptac(void *user_data)
{
    struct execute_script_param_s *p = user_data;
    NPString  np_script;
    NPVariant np_result;

    // no need to lock, this function is run only in browser thread
    if (!p->pp_i->npp) {
        trace_error("%s, plugin instance was destroyed\n", __func__);
        p->result = PP_MakeUndefined();
        goto quit;
    }

    np_script.UTF8Characters = ppb_var_var_to_utf8(p->script, &np_script.UTF8Length);
    if (!npn.evaluate(p->pp_i->npp, p->pp_i->np_window_obj, &np_script, &np_result)) {
        trace_error("%s, NPN_Evaluate failed\n", __func__);
        p->result = PP_MakeUndefined();
        goto quit;
    }

    // TODO: find out what exception is
    p->result = np_variant_to_pp_var(np_result);
    if (np_result.type == NPVariantType_Object)
        tables_add_npobj_npp_mapping(np_result.value.objectValue, p->pp_i->npp);
    else
        npn.releasevariantvalue(&np_result);

quit:
    ppb_message_loop_post_quit_depth(p->m_loop, PP_FALSE, p->depth);
}
static
void
p2n_invoke_comt(void *user_data, int32_t result)
{
    struct invoke_param_s *p = user_data;
    unsigned int k;

    p->result = true;
    struct np_proxy_object_s *obj = (void *)p->npobj;
    struct PP_Var exception = PP_MakeUndefined();
    struct PP_Var method_name = ppb_var_var_from_utf8_z(p->name);
    struct PP_Var res;

    struct PP_Var *pp_args = malloc(p->argCount * sizeof(*pp_args));
    for (k = 0; k < p->argCount; k ++) {
        pp_args[k] = np_variant_to_pp_var(p->args[k]);
    }

    res = ppb_var_call(obj->ppobj, method_name, p->argCount, pp_args, &exception);

    for (k = 0; k < p->argCount; k ++)
        ppb_var_release(pp_args[k]);
    free(pp_args);

    if (p->np_result) {
        *p->np_result = pp_var_to_np_variant(res);
        if (p->np_result->type == NPVariantType_Object) {
            NPP npp = tables_get_npobj_npp_mapping(p->npobj);
            tables_add_npobj_npp_mapping(p->np_result->value.objectValue, npp);
        }
    }

    ppb_var_release(res);
    ppb_var_release(method_name);
    ppb_var_release(exception);

    ppb_message_loop_post_quit_depth(p->m_loop, PP_FALSE, p->depth);
}
static
void
n2p_get_property_ptac(void *param)
{
    struct get_property_param_s *p = param;
    const char *s_name = ppb_var_var_to_utf8(p->name, NULL);
    NPIdentifier identifier = npn.getstringidentifier(s_name);
    NPVariant np_value;
    NPP npp = tables_get_npobj_npp_mapping(p->object);

    if (npp && npn.getproperty(npp, p->object, identifier, &np_value)) {
        struct PP_Var var = np_variant_to_pp_var(np_value);

        if (np_value.type == NPVariantType_Object)
            tables_add_npobj_npp_mapping(np_value.value.objectValue, npp);
        else
            npn.releasevariantvalue(&np_value);

        p->result = var;
    } else {
        p->result = PP_MakeUndefined();
    }
    ppb_message_loop_post_quit_depth(p->m_loop, PP_FALSE, p->depth);
}