Пример #1
0
static bool ewk_js_method_invoke(NPObject* npObject, NPIdentifier name, const NPVariant* npArgs, uint32_t npArgCount, NPVariant* result)
{
    Ewk_JS_Object* object = reinterpret_cast<Ewk_JS_Object*>(npObject);
    Ewk_JS_Method* method;
    Ewk_JS_Variant* args;
    Ewk_JS_Variant* ret_val;

    EINA_SAFETY_ON_NULL_RETURN_VAL(npObject, false);
    EINA_MAGIC_CHECK_OR_RETURN(object, false);

    if (!_NPN_IdentifierIsString(name)) {
        ERR("int NPIdentifier is not supported.");
        return false;
    }

    method = static_cast<Ewk_JS_Method*>(eina_hash_find(object->cls->methods, name));
    if (!method)
        return false;

    args = static_cast<Ewk_JS_Variant*>(malloc(sizeof(Ewk_JS_Variant)  *npArgCount));
    if (!args) {
        ERR("Could not allocate memory for ewk_js_variant");
        return false;
    }

    for (uint32_t i = 0; i < npArgCount; i++)
        ewk_js_npvariant_to_variant(&args[i], &npArgs[i]);
    ret_val = method->invoke(object, args, npArgCount);
    ewk_js_variant_to_npvariant(ret_val, result);

    ewk_js_variant_free(ret_val);

    return true;
}
Пример #2
0
static bool ewk_js_property_remove(NPObject* npObject, NPIdentifier name)
{
    Ewk_JS_Object* object = reinterpret_cast<Ewk_JS_Object*>(npObject);
    Ewk_JS_Property* prop;
    bool fail = false;

    EINA_SAFETY_ON_NULL_RETURN_VAL(npObject, false);
    EINA_MAGIC_CHECK_OR_RETURN(object, false);

    if (!_NPN_IdentifierIsString(name)) {
        ERR("int NPIdentifier is not supported.");
        return fail;
    }

    char* prop_name = _NPN_UTF8FromIdentifier(name);
    prop = static_cast<Ewk_JS_Property*>(eina_hash_find(object->cls->properties, prop_name));
    if (prop && prop->del)
        fail = prop->del(object, prop->name); // Class has property and property has getter.
    else if (object->cls->default_prop.del)
        fail = object->cls->default_prop.del(object, prop_name);
    else
        fail = eina_hash_del(object->properties, prop_name, 0);

    free(prop_name);
    return fail;
}
Пример #3
0
static bool ewk_js_method_has(NPObject* npObject, NPIdentifier name)
{
    Ewk_JS_Object* object = reinterpret_cast<Ewk_JS_Object*>(npObject);

    EINA_SAFETY_ON_NULL_RETURN_VAL(npObject, false);
    EINA_MAGIC_CHECK_OR_RETURN(object, false);

    if (!_NPN_IdentifierIsString(name)) {
        ERR("int NPIdentifier is not supported.");
        return false;
    }
    return eina_hash_find(object->cls->methods, name); // Returns pointer if found(true), 0(false) otherwise.
}
Пример #4
0
// These methods are used by NPAI, thats the reason to use bool instead of Eina_Bool.
static bool ewk_js_property_has(NPObject* npObject, NPIdentifier name)
{
    Ewk_JS_Object* object = reinterpret_cast<Ewk_JS_Object*>(npObject);

    EINA_SAFETY_ON_NULL_RETURN_VAL(npObject, false);
    EINA_MAGIC_CHECK_OR_RETURN(object, false);

    if (!_NPN_IdentifierIsString(name)) {
        ERR("int NPIdentifier is not supported.");
        return false;
    }

    char* prop_name = _NPN_UTF8FromIdentifier(name);
    bool fail = eina_hash_find(object->properties, prop_name); // FIXME: should search methods too?
    free(prop_name);

    return fail;
}
Пример #5
0
static bool ewk_js_property_get(NPObject* npObject, NPIdentifier name, NPVariant* result)
{
    Ewk_JS_Object* object = reinterpret_cast<Ewk_JS_Object*>(npObject);
    Ewk_JS_Variant* value;
    Ewk_JS_Property* prop;
    bool fail = false;

    EINA_SAFETY_ON_NULL_RETURN_VAL(npObject, false);
    EINA_MAGIC_CHECK_OR_RETURN(object, false);

    if (!_NPN_IdentifierIsString(name)) {
        ERR("int NPIdentifier is not supported.");
        return false;
    }

    value = static_cast<Ewk_JS_Variant*>(malloc(sizeof(Ewk_JS_Variant)));
    if (!value) {
        ERR("Could not allocate memory for ewk_js_variant");
        return false;
    }

    prop = static_cast<Ewk_JS_Property*>(eina_hash_find(object->cls->properties, name));
    if (prop && prop->get) { // Class has property and property has getter.
        fail = prop->get(object, prop->name, value);
        if (!fail)
            fail = ewk_js_variant_to_npvariant(value, result);
    } else if (object->cls->default_prop.get) { // Default getter exists.
        fail = object->cls->default_prop.get(object, prop->name, value);
        if (!fail)
            fail = ewk_js_variant_to_npvariant(value, result);
    } else { // Fallback to objects hash map.
        char* prop_name = _NPN_UTF8FromIdentifier(name);
        free(value);
        value = static_cast<Ewk_JS_Variant*>(eina_hash_find(object->properties, prop_name));
        free(prop_name);
        if (value)
            return ewk_js_variant_to_npvariant(value, result);
    }

    free(value);
    return fail;
}
Пример #6
0
bool WebBindings::identifierIsString(NPIdentifier identifier)
{
    return _NPN_IdentifierIsString(identifier);
}
Пример #7
0
bool NPN_IdentifierIsString(NPIdentifier identifier) {
  return _NPN_IdentifierIsString(identifier);
}