Trouble using NPN_PluginThreadAsyncCall and NPN_InvokeDefault to call back the browser from a native thread

by juliancwl » Mon, 18 Jan 2010 04:27:00 GMT


Sponsored Links
 I am developing an NPAPI plugin to process browser script.  Platform
is a build of the 1.6 Android source on Ubuntu, target is the browser
on the emulator supplied with the SDK.

Some of the JavaScript functions are asynchronous, passing in success/
failure callback functions as parameters. These are to be called back
by us when an async process has completed.

To achieve this we use the following code:

browser->invokeDefault(NP context, NPObject* onSuccessCbObject,
NPVARIANT args[] , int numargs, NPVARIANT * retVal);

This works well when called in the main plugin thread - the script
runs in the browser as expected.

However we need to implement this as an asynchronous callback. Firstly
we tried spawning a new pThread to run the above code - which
invariably crashed the browser.

So I tried using the NPN_PluginThreadAsyncCall function which seems to
allow a worker thread to run a function in the main browser UI thread.
This is called as follows:

browser->pluginthreadasynccall(  void (*func)(void *) , void *
userData)

The function we pass to this API contains the call to invokeDefault as
described above. When this is called the browser crashes immediately
(signal 11).

I am sure that all data passed to the function is valid, and the
lifetime of objects passed between threads are protected by reference
counting to ensure nothing is deleted prematurely. remove the call to
invokeDefault from the thread function, and everything completes and
cleans up as expected. But as soon as invokeDefault is called the
program crashes straight away.

Any ideas what might be going on?  Is there something else I should be
doing, or a preferred way to implement callbacks to a browser.

Many thanks - Julian.



Other Threads

1. Help regarding large Database....

HI

If i have a large Database in sqlite3 .what is the other option to
store DB other that internal memory ....
like SD card .....

Can any plz help me regarding this ...?

TIA
--~--~---------~--~----~------------~-------~--~----~

2. What's the meaning of obtainStyledAttributes() and a custom attrs.xml?

I've seen this in the Gallery API Demo shipping with the SDK.

There is an attrs.xml holding declare-stylable tags, and the gallery
adapter then does this:

in attrs.xml:

    <declare-styleable name="Gallery1">
        <attr name="android:galleryItemBackground" />
    </declare-styleable>

in Gallery1.java:

            // See res/values/attrs.xml for the <declare-styleable>
that defines
            // Gallery1.
            TypedArray a = obtainStyledAttributes
(R.styleable.Gallery1);
            mGalleryItemBackground = a.getResourceId(
 
R.styleable.Gallery1_android_galleryItemBackground, 0);
            a.recycle();

            ...

            // The preferred Gallery item background
            i.setBackgroundResource(mGalleryItemBackground);

I couldn't find any point in the code where the background resource is
set to an actual value. There is a gallery_background_1 drawable
defined, but it's nowhere used (at least Eclipse search didn't find
any references to it).
--~--~---------~--~----~------------~-------~--~----~

3. Developer review of all Android (Cupcake) devices - HTC vs. Samsung, test cases, etc.

4. Ressource Management / Priorization of applications?

5. Custom Dialog with Home Screen as background

6. Stream Audio

7. Inserting values into Database (SQL LITE)