struct PP_Var
ppb_instance_private_execute_script(PP_Instance instance, struct PP_Var script,
                                    struct PP_Var *exception)
{
    if (script.type != PP_VARTYPE_STRING) {
        trace_error("%s, 'script' is not a string\n", __func__);
        // TODO: fill exception
        return PP_MakeUndefined();
    }

    struct pp_instance_s *pp_i = tables_get_pp_instance(instance);
    if (!pp_i) {
        trace_error("%s, bad instance\n", __func__);
        return PP_MakeUndefined();
    }

    struct execute_script_param_s p;
    p.script =  script;
    p.pp_i =    pp_i;
    p.m_loop =  ppb_message_loop_get_current();
    p.depth =   ppb_message_loop_get_depth(p.m_loop) + 1;

    ppb_var_add_ref(script);
    ppb_message_loop_post_work(p.m_loop, PP_MakeCompletionCallback(_execute_script_comt, &p), 0);
    ppb_message_loop_run_int(p.m_loop, 1);
    ppb_var_release(script);

    return p.result;
}
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
struct PP_Var
n2p_call(void *object, struct PP_Var method_name, uint32_t argc, struct PP_Var *argv,
         struct PP_Var *exception)
{
    if (method_name.type != PP_VARTYPE_STRING) {
        trace_error("%s, method_name is not a string\n", __func__);
        // TODO: fill exception
        return PP_MakeUndefined();
    }

    struct call_param_s *p = g_slice_alloc(sizeof(*p));
    p->object =         object;
    p->method_name =    method_name;
    p->argc =           argc;
    p->argv =           argv;
    p->exception =      exception;
    p->m_loop =         ppb_message_loop_get_current();
    p->depth =          ppb_message_loop_get_depth(p->m_loop) + 1;

    ppb_message_loop_post_work_with_result(p->m_loop, PP_MakeCCB(n2p_call_comt, p), 0, PP_OK,
                                           p->depth, __func__);
    ppb_message_loop_run_nested(p->m_loop);

    struct PP_Var result = p->result;
    g_slice_free1(sizeof(*p), p);

    return result;
}
Exemple #4
0
/**
 * Create scriptable object for the given instance.
 * @param[in] instance The instance ID.
 * @return A scriptable object.
 */
static struct
PP_Var Instance_GetInstanceObject(PP_Instance instance)
{
  if (var_interface)
    return var_interface->CreateObject(instance, &ppp_class, NULL);
  return PP_MakeUndefined();
}
Exemple #5
0
/**
 * Creates new string PP_Var from C string. The resulting object will be a
 * refcounted string object. It will be AddRef()ed for the caller. When the
 * caller is done with it, it should be Release()d.
 * @param[in] str C string to be converted to PP_Var
 * @return PP_Var containing string.
 */
static struct
PP_Var StrToVar(const char* str)
{
  if (NULL != var_interface)
    return var_interface->VarFromUtf8(module_id, str, strlen(str));
  return PP_MakeUndefined();
}
struct PP_Var
ppb_url_util_dev_get_plugin_referrer_url(PP_Instance instance,
                                         struct PP_URLComponents_Dev *components)
{
    reset_components(components);
    return PP_MakeUndefined();
}
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);
}
Exemple #8
0
static NB_Bool nb_response_parse_values(struct NB_Response* response,
                                        struct PP_Var var) {
  NB_Bool result = NB_FALSE;
  struct PP_Var values_var = PP_MakeUndefined();
  struct PP_Var* values = NULL;
  uint32_t i, len;

  if (!nb_expect_key(var, "values", &values_var)) {
    goto cleanup;
  }

  if (!nb_var_check_type_with_error(values_var, PP_VARTYPE_ARRAY)) {
    goto cleanup;
  }

  len = nb_var_array_length(values_var);
  values = nb_calloc_list(len, sizeof(struct PP_Var));
  for (i = 0; i < len; ++i) {
    values[i] = nb_var_array_get(values_var, i);
  }

  response->values = values;
  response->values_count = len;

  result = NB_TRUE;
  values = NULL; /* Pass ownership to the response */
cleanup:
  free(values);
  nb_var_release(values_var);
  return result;
}
PP_Resource
ppb_keyboard_input_event_create_1_0(PP_Instance instance, PP_InputEvent_Type type,
                                    PP_TimeTicks time_stamp, uint32_t modifiers, uint32_t key_code,
                                    struct PP_Var character_text)
{
    return ppb_keyboard_input_event_create_1_2(instance, type, time_stamp, modifiers, key_code,
                                               character_text, PP_MakeUndefined());
}
struct PP_Var
ppb_flash_get_setting(PP_Instance instance, PP_FlashSetting setting)
{
    long cpu_count;
    struct pp_instance_s *pp_i = tables_get_pp_instance(instance);
    if (!pp_i) {
        trace_error("%s, bad instance\n", __func__);
        return PP_MakeUndefined();
    }
    struct PP_Var var = PP_MakeUndefined();

    switch (setting) {
    case PP_FLASHSETTING_3DENABLED:
        var.type = PP_VARTYPE_BOOL;
        var.value.as_bool = config.enable_3d ? PP_TRUE : PP_FALSE;
        break;
    case PP_FLASHSETTING_INCOGNITO:
        var.type = PP_VARTYPE_BOOL;
        var.value.as_bool = pp_i->incognito_mode ? PP_TRUE : PP_FALSE;
        break;
    case PP_FLASHSETTING_STAGE3DENABLED:
        var.type = PP_VARTYPE_BOOL;
        var.value.as_bool = config.enable_3d ? PP_TRUE : PP_FALSE;
        break;
    case PP_FLASHSETTING_LANGUAGE:
        var = get_flashsetting_language();
        break;
    case PP_FLASHSETTING_NUMCORES:
        cpu_count = sysconf(_SC_NPROCESSORS_ONLN);
        var.type = PP_VARTYPE_INT32;
        var.value.as_int = cpu_count > 0 ? cpu_count : 1;
        break;
    case PP_FLASHSETTING_LSORESTRICTIONS:
        var.type = PP_VARTYPE_INT32;
        var.value.as_int = PP_FLASHLSORESTRICTIONS_NONE;
        break;
    case PP_FLASHSETTING_STAGE3DBASELINEENABLED:
        // TODO: check if driver reliable enough
        var.type = PP_VARTYPE_BOOL;
        var.value.as_bool = PP_FALSE;
        break;
    }

    return var;
}
struct PP_Var
ppb_ime_input_event_get_text(PP_Resource ime_event)
{
    struct pp_input_event_s *ie = pp_resource_acquire(ime_event, PP_RESOURCE_INPUT_EVENT);
    if (!ie) {
        trace_error("%s, bad resource\n", __func__);
        return PP_MakeUndefined();
    }
    if (ie->event_class != PP_INPUTEVENT_CLASS_IME) {
        trace_error("%s, not an IME event\n", __func__);
        pp_resource_release(ime_event);
        return PP_MakeUndefined();
    }

    struct PP_Var text = ppb_var_add_ref2(ie->text);
    pp_resource_release(ime_event);
    return text;
}
struct PP_Var
ppb_keyboard_input_event_get_character_text(PP_Resource character_event)
{
    struct pp_input_event_s *ie = pp_resource_acquire(character_event, PP_RESOURCE_INPUT_EVENT);
    if (!ie) {
        trace_error("%s, bad resource\n", __func__);
        return PP_MakeUndefined();
    }
    if (ie->event_class != PP_INPUTEVENT_CLASS_KEYBOARD) {
        trace_error("%s, not a keyboard event\n", __func__);
        pp_resource_release(character_event);
        return PP_MakeUndefined();
    }

    struct PP_Var character_text = ppb_var_add_ref2(ie->text);
    pp_resource_release(character_event);
    return character_text;
}
Exemple #13
0
void PepperPluginImpl::destroy(){
  if (instance_) {
    ::ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(instance_object_);
    instance_object_ = PP_MakeUndefined();
    instance_->Delete();
    instance_ = NULL;
  }

  MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}
NPObject *
p2n_allocate(NPP npp, NPClass *aClass)
{
    (void)npp;
    struct np_proxy_object_s *obj = npn.memalloc(sizeof(*obj));
    obj->npobj.referenceCount = 1;
    obj->npobj._class = aClass;
    obj->ppobj = PP_MakeUndefined();

    return (NPObject*)obj;
}
struct PP_Var
ppb_instance_private_get_window_object(PP_Instance instance)
{
    struct pp_instance_s *pp_i = tables_get_pp_instance(instance);
    if (!pp_i) {
        trace_error("%s, bad instance\n", __func__);
        return PP_MakeUndefined();
    }

    npn.retainobject(pp_i->np_window_obj); // TODO: call on browser thread?
    return ppb_var_create_object(instance, &n2p_proxy_class, pp_i->np_window_obj);
}
struct PP_Var
ppb_url_response_info_get_property(PP_Resource response, PP_URLResponseProperty property)
{
    struct pp_url_response_info_s *ri = pp_resource_acquire(response,PP_RESOURCE_URL_RESPONSE_INFO);
    if (!ri) {
        trace_error("%s, bad resource\n", __func__);
        return PP_MakeUndefined();
    }
    struct pp_url_loader_s *ul = ri->url_loader;
    struct PP_Var var = PP_MakeUndefined();

    switch (property) {
    case PP_URLRESPONSEPROPERTY_URL:
        var = ppb_var_var_from_utf8_z(ul->url);
        break;
    case PP_URLRESPONSEPROPERTY_REDIRECTURL:
        var = ppb_var_var_from_utf8_z(ul->redirect_url);
        break;
    case PP_URLRESPONSEPROPERTY_REDIRECTMETHOD:
        // redirection is believed to be always GET
        // TODO: check whenever it may be HEAD
        var = ppb_var_var_from_utf8_z("GET");
        break;
    case PP_URLRESPONSEPROPERTY_STATUSCODE:
        var.type = PP_VARTYPE_INT32;
        var.value.as_int = ul->http_code;
        break;
    case PP_URLRESPONSEPROPERTY_STATUSLINE:
        var = ppb_var_var_from_utf8_z(ul->status_line);
        break;
    case PP_URLRESPONSEPROPERTY_HEADERS:
        var = ppb_var_var_from_utf8_z(ul->headers);
        break;
    }

    pp_resource_release(response);
    return var;
}
struct PP_Var
ppb_host_resolver_get_canonical_name(PP_Resource host_resolver)
{
    // TODO: implement
    struct pp_host_resolver_s *hr = pp_resource_acquire(host_resolver, PP_RESOURCE_HOST_RESOLVER);
    if (!hr) {
        trace_error("%s, bad resource\n", __func__);
        return PP_MakeUndefined();
    }

    struct PP_Var var = ppb_var_var_from_utf8_z(hr->host);
    pp_resource_release(host_resolver);
    return var;
}
struct PP_Var
ppb_device_ref_get_name(PP_Resource device_ref)
{
    struct pp_device_ref_s *dr = pp_resource_acquire(device_ref, PP_RESOURCE_DEVICE_REF);
    if (!dr) {
        trace_error("%s, bad resource\n", __func__);
        return PP_MakeUndefined();
    }

    struct PP_Var name = ppb_var_add_ref2(dr->name);

    pp_resource_release(device_ref);
    return name;
}
Exemple #19
0
PepperPluginImpl::PepperPluginImpl(PluginModule* module, const Plugin::Parameters& params, const content::PepperPluginDelegateImpl* pluginDelegate)
    : init_data_(new InitData()),
      full_frame_(params.shouldUseManualLoader),
      instance_object_(PP_MakeUndefined()),
      container_(NULL) {
  DCHECK(module);
  init_data_->module = module;
  content::PepperPluginDelegateImpl* delegate = const_cast<content::PepperPluginDelegateImpl*>(pluginDelegate);
  init_data_->delegate = delegate;
  for (size_t i = 0; i < params.names.size(); ++i) {
      init_data_->arg_names.push_back(params.names[i].utf8().data());
      init_data_->arg_values.push_back(params.values[i].utf8().data());
  }
  init_data_->url = params.url;
}
static
void
p2n_has_method_comt(void *user_data, int32_t result)
{
    struct has_method_param_s *p = user_data;
    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);

    p->result = ppb_var_has_method(obj->ppobj, method_name, &exception);

    ppb_var_release(method_name);
    ppb_var_release(exception);

    ppb_message_loop_post_quit_depth(p->m_loop, PP_FALSE, p->depth);
}
Exemple #21
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;
    }
}
static
void
p2n_get_property_comt(void *user_data, int32_t result)
{
    struct get_property_param_s *p = user_data;
    struct np_proxy_object_s *obj = (void *)p->npobj;
    struct PP_Var exception = PP_MakeUndefined();
    struct PP_Var property_name = ppb_var_var_from_utf8_z(p->name);
    struct PP_Var res = ppb_var_get_property(obj->ppobj, property_name, &exception);

    p->result = true;
    *p->np_result = pp_var_to_np_variant(res);
    ppb_var_release(res);
    ppb_var_release(exception);

    ppb_message_loop_post_quit_depth(p->m_loop, PP_FALSE, p->depth);
}
Exemple #23
0
/**
 * Printf to a new PP_Var.
 * @param[in] format A print format string.
 * @param[in] ... The printf arguments.
 * @return A new PP_Var. */
struct PP_Var PrintfToVar(const char* format, ...) {
  if (ppb_var_interface != NULL) {
    char* string;
    va_list args;
    struct PP_Var var;

    va_start(args, format);
    string = VprintfToNewString(format, args);
    va_end(args);

    var = ppb_var_interface->VarFromUtf8(string, strlen(string));
    free(string);

    return var;
  }

  return PP_MakeUndefined();
}
struct PP_Var
ppb_url_util_dev_get_plugin_instance_url(PP_Instance instance,
                                         struct PP_URLComponents_Dev *components)
{
    reset_components(components);
    struct pp_instance_s *pp_i = tables_get_pp_instance(instance);
    if (!pp_i) {
        trace_error("%s, bad instance\n", __func__);
        return PP_MakeUndefined();
    }

    struct PP_Var var = ppb_var_var_from_utf8_z(pp_i->instance_url);

    if (components)
        parse_url_string(ppb_var_var_to_utf8(var, NULL), components);

    return var;
}
struct PP_Var
ppb_flash_clipboard_read_data(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type,
                              uint32_t format)
{
    if (!clipboard_type_and_format_are_supported(clipboard_type, format, __func__))
        return PP_MakeUndefined();

    struct clipboard_read_data_param_s *p = g_slice_alloc(sizeof(*p));
    p->clipboard_type = clipboard_type;
    p->format =         format;
    p->m_loop =         ppb_message_loop_get_current();
    p->depth =          ppb_message_loop_get_depth(p->m_loop) + 1;

    ppb_message_loop_post_work_with_result(p->m_loop, PP_MakeCCB(clipboard_read_data_comt, p), 0,
                                           PP_OK, p->depth, __func__);
    ppb_message_loop_run_nested(p->m_loop);

    struct PP_Var result = p->result;
    g_slice_free1(sizeof(*p), p);

    return result;
}
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
clipboard_read_data_ptac(void *user_data)
{
    struct clipboard_read_data_param_s *p = user_data;

    p->result = PP_MakeUndefined();
    GtkClipboard *clipboard = get_clipboard_of_type(p->clipboard_type);
    if (!clipboard)
        goto quit;

    GdkAtom target = get_clipboard_target_atom(p->format);
    if (target == GDK_NONE)
        goto quit;

    GtkSelectionData *sd = gw_gtk_clipboard_wait_for_contents(clipboard, target);
    if (sd) {
        const guchar *sd_data = gw_gtk_selection_data_get_data(sd);
        const gint sd_length = gw_gtk_selection_data_get_length(sd);
        switch (p->format) {
        case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT:
        case PP_FLASH_CLIPBOARD_FORMAT_HTML:
            p->result = ppb_var_var_from_utf8((char *)sd_data, sd_length);
            break;
        default:
            p->result = ppb_var_array_buffer_create(sd_length);
            memcpy(ppb_var_array_buffer_map(p->result), sd_data, sd_length);
            ppb_var_array_buffer_unmap(p->result);
            break;
        }

        gw_gtk_selection_data_free(sd);
    }

quit:
    ppb_message_loop_post_quit_depth(p->m_loop, PP_FALSE, p->depth);
}
struct PP_Var
ppb_url_util_dev_get_document_url(PP_Instance instance, struct PP_URLComponents_Dev *components)
{
    reset_components(components);
    struct pp_instance_s *pp_i = tables_get_pp_instance(instance);
    if (!pp_i) {
        trace_error("%s, bad instance\n", __func__);
        return PP_MakeUndefined();
    }

    struct get_document_url_param_s p;
    p.npp = pp_i->npp;
    p.m_loop = ppb_message_loop_get_current();
    p.depth = ppb_message_loop_get_depth(p.m_loop) + 1;
    p.np_window_obj = pp_i->np_window_obj;

    ppb_message_loop_post_work(p.m_loop, PP_MakeCompletionCallback(_get_document_url_comt, &p), 0);
    ppb_message_loop_run_int(p.m_loop, 1);

    if (components)
        parse_url_string(ppb_var_var_to_utf8(p.result, NULL), components);

    return p.result;
}
Exemple #29
0
static NB_Bool nb_response_parse_cb_id(struct NB_Response* response,
                                       struct PP_Var var) {
  NB_Bool result = NB_FALSE;
  struct PP_Var cb_id = PP_MakeUndefined();

  if (!nb_optional_key(var, "cbId", &cb_id)) {
    goto cleanup;
  }

  if (!nb_var_check_type_with_error(cb_id, PP_VARTYPE_INT32)) {
    goto cleanup;
  }

  if (cb_id.value.as_int <= 0) {
    NB_VERROR("Expected response cbId to be > 0. Got %d", cb_id.value.as_int);
    goto cleanup;
  }

  response->cb_id = cb_id.value.as_int;
  result = NB_TRUE;
cleanup:
  nb_var_release(cb_id);
  return result;
}
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);
}