Hi,
My browser plugin application needs to be able to call a javascript function asynchronously from a Juce::Thread’s run() method.
This can’t be done with a simple var::call() function because NPN_Invoke () calls are only valid on the browser thread so I have hacked the Juce wrapper code to call an asynchronous version of invokeMethod(). It seems to work OK but unfortunately it replaces the existing invokeMethod() functionality so its not by any means a patch that can be merged into the main repository yet. I’m not familiar enough with the Juce architecture to implement this properly and I also haven’t had a look at how to implement this for the ActiveX/IE case yet.
As it stands its quite useful though so I was wondering if someone could give me a hand completing this as its quite a useful functionality to have.
Thanks,
Aaron
[code]— a/plugin/wrapper/juce_NPAPI_GlueCode.cpp
+++ b/plugin/wrapper/juce_NPAPI_GlueCode.cpp
@@ -611,7 +611,45 @@ public:
return browser.hasmethod (npp, source, getIdentifierFromString (methodName));
}
- const var invokeMethod (const var::identifier& methodName,
-
struct AsyncCallbackData
-
{
-
DynamicObjectWrappingNPObject *obj;
-
var::identifier methodName;
-
var *parameters;
-
int numParameters;
-
};
-
bool asyncInvokeMethod(const var::identifier& methodName, const var* parameters, int numParameters)
-
{
-
if(browser.version < NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL)
-
return false;
-
AsyncCallbackData *data = new AsyncCallbackData;
-
data->obj = new DynamicObjectWrappingNPObject(*this);
-
data->obj->incReferenceCount();
-
data->methodName = methodName;
-
data->numParameters = numParameters;
-
data->parameters = new var[numParameters];
-
browser.pluginthreadasynccall(npp, DynamicObjectWrappingNPObject::asyncThreadCallback, data);
-
return true;
-
}
-
static void asyncThreadCallback(void *userdata)
-
{
-
AsyncCallbackData *data = (AsyncCallbackData *)userdata;
-
data->obj->invokeMethodX(data->methodName, data->parameters, data->numParameters);
-
data->obj->decReferenceCount();
-
delete [] data->parameters;
-
delete data;
-
}
-
const var invokeMethod (const var::identifier& methodName, const var* parameters, int numParameters)
-
{
-
asyncInvokeMethod(methodName, parameters, numParameters);
-
return var();
-
}
- const var invokeMethodX (const var::identifier& methodName,
const var* parameters,
int numParameters)
{
[/code]