Ran
Ran

Reputation:

Firefox [npapi] plugin development - firefox freeze when calling a method

I'm trying to learn how to write a Firefox plugin. I downloaded the npruntime example from Mozilla compiled it and ran it. Getting properties from the plugin worked well but when I tried to call a method, Firefox freezed. I thought maybe something is wrong with the example, so I wrote my own basic scriptable plugin that has one property and one method which returns a string. The property worked well, but calling the method caused Firefox to freeze, again.

Am I missing something? I tried debugging the plugin and everything seems fine. All the right functions are called and the value is returned properly.If I try to stop the process while Firefox hangs, I get stopped at a Windows DLL, not in my code and not in Firefox code.

If anyone can point me to the right direction...

Thanks.

Upvotes: 3

Views: 2197

Answers (2)

user2492824
user2492824

Reputation: 1

I developed npruntime for every browser. It worked well in every browser, but firefox got freezing only in Windows 7.

I solved the problem editing the firefox config "dom.ipc.plugins.enabled" to false. I don't know it will work, but it deserves to try.

Upvotes: 0

cerbert
cerbert

Reputation: 61

I hope that you've got it solved. If this is not the case, I've just discovered that the example (I assume that was the damned "npruntime sample") was flawed.

In returning a string, the example used the function strdup to allocate a string passed with a NP_something method. Fact is that NPAPI takes care of the allocated string from that point on and, when tries to destroy it, it cannot since strdup uses malloc and not NPN_MemAlloc.

The solution is to NEVER use malloc or new for objects that we pass to NPAPI functions. In the npruntime sample the error is at line 452:

STRINGZ_TO_NPVARIANT(strdup("foo return val"), *result);

and line 466:

STRINGZ_TO_NPVARIANT(strdup("default method return val"), *result);

I've corrected it with this code:

char* src = "foo return val";
char* out = (char *)NPN_MemAlloc(strlen(src) + 1);
strcpy(out, src);
STRINGZ_TO_NPVARIANT(out, *result);

and it worked. But one would think that such a flaw in a sample should be corrected by mozilla SDK maintainers.

Upvotes: 6

Related Questions