0

Thanks in advance !!!!!

var pluginObject = null;
function init()
{
    var pluginObject = document.getElementById('pluginObj'); //This is  object for my Plugin.
    pluginObject.onstartevent = handleEvent(); // This is working

    //now i am calling one function in plugin that will return NPObject  using invoke default
    pluginObject.startEvent(function(e) {
        e.onstartEvent = handleEvent(); //This is not working ......how to make it work  
    });
}
function handleEvent(e)
{
    if(e)
    {
        alert(e);
    }
}
<body onload = "init()" > </body>

Here i am calling init function from body and then creating plugin object and then calling one property onstartEvent that i am taking care inside plugin. Problem is "e.onstartEvent" how to capture this object and invoke here . i am not getting it . For PluginObject i am using NPNVPlUGINOBJECT and then checking property "onstartEvent" if it is present then checking for has method and finally invoke on the PLUGIN object.

//My Plugin Code is as follows :

bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
    char *pFunc = NPN_UTF8FromIdentifier(name);
    if(!strcmp("startEvent",pFunc))
    {
        NPObject * argsVal = args[0].value.objectValue;  
        NPVariant valueToSend;
        NPVariant returnValue;
        valueToSend.type = NPVariantType_Object;
        valueToSend.value.objectValue = this; 
        NPN_InvokeDefault(mNpp,argsVal,&valueToSend,1,&returnValue); 
        return true;
    }
    return false;
}

Now in HasProperty checking in the current class property named of "onstartEvent"

bool ScriptablePluginObject::HasProperty(NPIdentifier name)
{
    char *pProp = NPN_UTF8FromIdentifier(name);
    //Check which Properties are available
    if( !strcmp( "onstartEvent", pProp ) )
    {
        return true;
    }
    return false;
}

Now in GetProperty i am finally checking and returning some integer value to the //handleEvent function

bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant *result)
{
    VOID_TO_NPVARIANT(*result);
    char *pProp = NPN_UTF8FromIdentifier(name);
    //onstartEvent

    if(!strcmp("onstartEvent", pProp))
    {
        //Calling e.onstartEvent will come here in GetProperty
        NPObject * pluginObj = NULL;   
        NPN_GetValue(mNpp,NPNVPluginElementNPObject,&pluginObj);
        NPIdentifier id = NPN_GetStringIdentifier("onstartEvent");
        bool val  = NPN_HasMethod(mNpp,pluginObj,id);
        NPVariant value;
        NPVariant retVal;
        value.type = NPVariantType_Int32; //now returning some value if val is true.
        value.value.intValue = 20;
        if(val==true)
        {
            //Finally returning value to the handle Event function in JavaScript
            NPN_Invoke(mNpp,pluginObj,id,&value,1,&retVal); 
        }
        return true;
    }
    return true;
}
r_tex
  • 77
  • 9
  • when you edit the code for a question to add something that someone requested don't take out the old information; now the question doesn't make sense. Now that I can see what you have on the C++ side I've forgotten the rest of your question, which makes it very difficult to help. Also, why did you mark it as answered if it isn't? if it is, why are you still asking more questions? – taxilian Oct 12 '12 at 16:24
  • sorry sily mistake , not aware much of stackoverflow , i had edited the answered post that was answered by you. – r_tex Oct 12 '12 at 18:09
  • i edited on answered flag post it was showing my javascript code . sorry my silly mistake i removed that code it seemed to be duplicate ..........adding again javascript code...... – r_tex Oct 12 '12 at 18:11
  • your actual question is still missing from the post' – taxilian Oct 12 '12 at 18:41
  • Uploaded initial question asked in this post !!!! uegent help required – r_tex Oct 13 '12 at 21:13

1 Answers1

1

I'm not sure I really follow what you're trying to do; from the looks of things, though, when you call the method startEvent on your plugin you pass it a function (NPObject) that will get invoked (with InvokeDefault) with a single argument "e"

You then want "e" to be the plugin? if that's the case, then all you need to do is wrap the NPObject for the plugin in a NPVariant and send it as the first parameter to the function call with InvokeDefault.


Edit:

So you have posted your NPAPI code; you have the following line executing in your callback:

e.onstartEvent = handleEvent();

Did you mean to do this? You're executing handleEvent and assigning the result to "onstartEvent" on the plugin DOM element. Did you mean to assign the function to "onstartEvent", perhaps? In that case you shouldn't have the () at the end; that causes the function to be called (and without a valid value for e).

Further, you're trying to invoke "onstartEvent" on the DOM element, but you'd be much better off using GetProperty to get the function's NPObject and then InvokeDefault on that; of course, since you're never getting the property GetProperty isn't ever called and thus your code for that isn't ever running anyway.

Oh, and since you return true from HasProperty for "onstartEvent" you can't set the function on the DOM element's property of the same name; the DOM element can claim the property or your plugin can, but you're trying to use it both ways, which won't work. Thus, since you don't have a SetProperty your assignment will fail just after your function is called with no arguments.

Hope that helps

taxilian
  • 14,229
  • 4
  • 34
  • 73
  • yes taxilian right ,pluginObject.onstartevent = handleEvent() is working fine. But e.onstartevent = handleEvent() is not working as from plugin i am using NPNInvoke first parameter is mNpp and if onstartevent is present on e i.e checking via NPNVPluginObject – r_tex Oct 10 '12 at 16:42
  • yeah, I got that part. where is e coming from? you have to pass that in as the first *NPVariant* parameter – taxilian Oct 10 '12 at 21:34
  • If you'll post your C++ code for firing onstartevent I can show you what it should be – taxilian Oct 10 '12 at 21:34
  • At Your response to my question i flagged as answered and edited for plugin source code.... – r_tex Oct 12 '12 at 18:12
  • dude; I'll look at it when I can. it will not be 'til tomorrow. you can also pop into the IRC chat tomorrow and ask for help if you want. http://npapi.com/chat – taxilian Oct 15 '12 at 01:06
  • thanx taxilian for ur support !! – r_tex Oct 15 '12 at 08:30
  • Yup I got it taxilian , i removed () in handleEvent and in hasProperty defined onstartEvent, now how to set function on the onstartEvent property i mean how to use setProperty that is my only remaining problem now.Also NPN_Invoke required after setProperty ?? – r_tex Oct 16 '12 at 17:55
  • okay, I'm now totally lost on your questions; maybe it would make sense to start a new, more specific question? I have given you all the information you need. If you still can't figure it out from what I've given you here you might want to seriously consider using http://firebreath.org – taxilian Oct 16 '12 at 18:14