Example #1
0
native_netscape_javascript_JSObject_getWindow(
    JRIEnv* env,
    struct java_lang_Class* clazz,
    struct java_applet_Applet* hint)
{
#ifndef JAVA
    return NULL;
#else
    struct netscape_javascript_JSObject *ret = NULL;
    JSContext *cx;
    JSSavedState saved;
    JSObject *jso;

    if (!JSJ_IsEnabled()) {
        js_throwJSException(env, "Java/JavaScript communication is disabled");
        return 0;
    }

    if (!enterJS(env, NULL, &cx, NULL, &saved))
        return NULL;

    jso = JSJ_GetDefaultObject(env, (jobject) hint);
    if (exceptionOccurred((ExecEnv *)env))
        goto out;

    ret = (struct netscape_javascript_JSObject *)
        js_ReflectJSObjectToJObject(cx, jso);

  out:
    if (!exitJS(env, NULL, cx, NULL, &saved))
        return NULL;
    return ret;
#endif
}
Example #2
0
/* this calls MozillaEmbedContext to reflect the embed by
 * calling into mocha... yow! */
static JSObject *
lm_ReallyReflectEmbed(MWContext *context, LO_EmbedStruct *lo_embed,
                      int32 layer_id, uint32 index)
{
    JSObject *obj;
    MochaDecoder *decoder;
    JSContext *cx;
    jref jembed;
    NPEmbeddedApp* embed;
    lo_TopState *top_state;
    PRHashTable *map;
    PR_LOG(Moja, debug, ("really reflect embed 0x%x\n", lo_embed));

    if ((obj = lo_embed->mocha_object) != NULL)
        return obj;

    decoder = LM_GetMochaDecoder(context);
    if (!decoder)
	return NULL;
    cx = decoder->js_context;

    top_state = lo_GetMochaTopState(context);
    if (top_state->resize_reload) {
        map = lm_GetIdToObjectMap(decoder);
        
        if (map)
            obj = (JSObject *)PR_HashTableLookup(map,
                             LM_GET_MAPPING_KEY(LM_EMBEDS, layer_id, index));
        if (obj) {
            lo_embed->mocha_object = obj;
            return obj;
        }
    }

    /* set the element to something bad if we can't get the java obj */
    if (!JSJ_IsEnabled()) {
        PR_LOG(Moja, debug, ("reflected embed 0x%x as null\n",
                             lo_embed));
        return lo_embed->mocha_object = lm_DummyObject;
    }

    embed = (NPEmbeddedApp*) lo_embed->FE_Data;
    if (embed) {
        np_data *ndata = (np_data*) embed->np_data;
        np_instance *instance;

        /* XXX this comes from npglue.c, it should be put
         * in one of the plugin header files */
        extern jref npn_getJavaPeer(NPP npp);

        if (!ndata || ndata->state == NPDataSaved) {
            PR_LOG(Moja, warn, ("embed 0x%x is missing or suspended\n",
                                lo_embed));
            return NULL;
        }
        instance = ndata->instance;
	if (!instance) return NULL;
        jembed = npn_getJavaPeer(instance->npp);

        obj = js_ReflectJObjectToJSObject(decoder->js_context,
				          (HObject *)jembed);
        PR_LOG(Moja, debug, ("reflected embed 0x%x (java 0x%x) to 0x%x ok\n",
                             lo_embed, jembed, obj));

        map = lm_GetIdToObjectMap(decoder);
        if (map)
            PR_HashTableAdd(map, 
                            LM_GET_MAPPING_KEY(LM_EMBEDS, layer_id, index),
                            obj);

        return lo_embed->mocha_object = obj;
    } else {
        PR_LOG(Moja, warn, ("failed to reflect embed 0x%x\n", lo_embed));
        return NULL;
    }
}