Browser plugins


#1

I’ve just checked in the first draft of the juce wrapper for NPAPI plugins - this will run in all the usual mac/pc browsers apart from IE, which I’ll add support for later.

Architecturally the code is structured pretty similarly to the way audio plugins are done, so you include a few wrapper files and write a component that gets plonked inside the browser.

Any comments, advice, bugs, improvements, etc, would be appreciated!


#2

you’re llike a mind reader or somethin man, i was about to post an idea for a browser-embed plugin in juce, and baam here it is.

i was making a progress-bar aware FLASH uploader, but i don’t know flash and someone else had to do it for me, but now i will make it myself, test it and let you know how things work out.

thank you very much for this. oh mystical one.

–edit

got the sdk from here http://ftp.mozilla.org/pub/mozilla.org/mozilla/nightly/latest/gecko-sdk-i586-pc-msvc.zip

loaded the project, set the paths got an error

1>------ Build started: Project: JuceBrowserPluginDemo, Configuration: Debug Win32 ------
1>Compiling...
1>juce_NPAPI_GlueCode.cpp
1>c:\devel\juce\extras\browser plugins\wrapper\juce_npapi_gluecode.cpp(769) : error C2065: 'NP_CLASS_STRUCT_VERSION_ENUM' : undeclared identifier
1>c:\devel\juce\extras\browser plugins\wrapper\juce_npapi_gluecode.cpp(775) : error C2078: too many initializers
1>c:\devel\juce\extras\browser plugins\wrapper\juce_npapi_gluecode.cpp(807) : error C2440: '<function-style-cast>' : cannot convert from 'const uint32_t' to 'juce::var'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous
1>JuceBrowserPluginDemo.cpp
1>juce_LibrarySource.cpp
1>Generating Code...
1>Build log was saved at "file://c:\devel\juce\extras\browser plugins\demo\build\npapi_win\Debug\BuildLog.htm"
1>JuceBrowserPluginDemo - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

looks like some definition errors, perhaps i should use some specific SDK version ?

— edit2

also i was wondering, right now you build a component and that component is turned into a plugin, what do you thing about writing one single plugin, like Adobe Flash Player (and make that into a simple installer) that would launch binary components, just like adobe movie player laaunches SWF files, it would be a simple host/plugin situation, but the host would be the browser plugin, this would make things easier for users out there, and would make this more available:

multiple components one installer kind of situation

i was thinking about that really, but this is also amazing.


#3

Looks like you’re using an old version there - maybe try getting the npapi directly rather than using the one that’s inside the gecko project? I don’t have an easy link I can post, I’m afraid.

[quote]also i was wondering, right now you build a component and that component is turned into a plugin, what do you thing about writing one single plugin, like Adobe Flash Player (and make that into a simple installer) that would launch binary components, just like adobe movie player laaunches SWF files, it would be a simple host/plugin situation, but the host would be the browser plugin, this would make things easier for users out there, and would make this more available:
[/quote]

I don’t think you’d be able to persuade many people to install something as insecure as that![/code]


#4

well i don’t know who is maintaining the npapi right now i though that mozilla had it and i got it from:


then i checked out wikipedia links (also mozilla) here https://developer.mozilla.org/en/Plugins and this links to this http://mxr.mozilla.org/mozilla-central/source/modules/plugin/sdk/

but there are some old links to netscape site but they are down, can you tell us where did you get your copy ?

as for the other topic, i don’t think this will be an issue, it’s the same deal as with flash, it’s also “not-safe” if it can read local filesystem files and send them to remote hosts, well there goes the whole security of flash for me. Anyway i think it would be like java, if the user trusts the app the user launches it if he doesn’t he doesn’t. I guess it’s the same situatin with embedding single-component plugins, noone will trust those either, and with a wrapper component, we can make some global settings for all plugins and perhaps do some sort of binary validation check against md5 checksums (provided in html), well there is more possibilites here i guess.


#5

I can’t remember where I downloaded mine from but yours is dated 2004 so clearly not exactly cutting edge!


#6

sorry for that, i missed the date (it said latest on the mozilla webpage)

anyway i got the latest firefox sources 3.0.10 (it came out today) and built the demo (no errors no warnings), the plugin loads and works, however the scripting buttons hang firefox (i also use 3.0.10 i updated it today), sometimes the button works once but the second press, hangs the whole browser, i didn’t have time to debug this yet but i will i promise, i just wanted to say that the latest firefox sources have all the needed file to build a plugin you just need to add the below paths to the include find path

mozilla\modules\plugin\base\public
mozilla\nsprpub\pr\include
mozilla\nsprpub\pr\src\md\mac
mozilla\nsprpub\pr\include\obsolete
mozilla\embedding\browser\activex\src\pluginhostctrl\pluginsdk_include

and it all builds nicely.


#7

That’s strange, it doesn’t hang for me. Ah well, early days!

Maybe you’re still using a different version - I checked my code and I’m using a recent the xulrunner download, and just one search path:
xulrunner-sdk/sdk/include

There seems to be a whole range of variations on these files… I might see if I can collect the essential ones and add them to the tree somewhere…


#8

that would be a good idea cause from what i saw on the internet, almost every variation of the browser no matter if gecko or webkit based has some kind of modifications to the npapi (i saw google making a lot of modifications when using npapi with Chrome).


#9

Ok, I’ve checked some stuff in now. Would be interested to see if it fixes your crashes.


#10

After the update and rebuilding

  • the first button works OK
  • the second button hangs the browser, and i was unable to debug this behavior, i tried setting a break point inside the
const var popUpMessageBox (const var* params, int numParams)

but this code never gets executed, however

setMethod ("popUpMessageBox", (var::MethodFunction) &DemoBrowserObject::popUpMessageBox);

get’s executed on plugin load and causes no problems

  • button three was easier to debug, i set a break point inside buttonClicked, and i got to the point:
    const var invokeMethod (const var::identifier& methodName,
                            const var* parameters,
                            int numParameters)
    {
        var returnVal;
        
        NPVariant result;
        VOID_TO_NPVARIANT (result);

        if (numParameters > 0)
        {
            NPVariant* params = (NPVariant*) juce_malloc (sizeof (NPVariant*) * numParameters);

            int i;
            for (i = 0; i < numParameters; ++i)
                createNPVariantFromValue (npp, params[i], parameters[i]);

            if (browser.invoke (npp, source, getIdentifierFromString (methodName),
                                params, numParameters, &result))
            {
                returnVal = createValueFromNPVariant (npp, result);
                browser.releasevariantvalue (&result);
            }

            for (i = 0; i < numParameters; ++i)
                browser.releasevariantvalue (&params[i]);
            
            juce_free (params); <-- hangs after this
        }

after that the debugger looks like it’s running the program (no step into or anything like that is possible, i can only do STOP debuggin) but the browser hangs right after the click on the button, ofcourse the button gets activated by clicking the third JS button and this does not cause any problems.

this is what i got so far, i’m usin XP SP2 with FF 3.0.10 [Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10] VS2008


#11

Doh! I think that should probably read:

NPVariant* params = (NPVariant*) juce_malloc (sizeof (NPVariant) * numParameters);

…talk about basic c++ mistakes!


#12

well i agree that this might be a problem, but i changed that line i still no go, same results. will see at home on vista.


#13

well i built it on vista and it works like a charm, i’ll try to reinstall a clean version of Firefox at work on XP and test it again.

do you think that the whole plugin wrapper/installer thing would be possible, if not i’ll try and do that myself, but perhaps i could persuade you to perhaps implement this.


#14

Hi,guys
I build successfully the browser demo(first check in) on windows vista, using microsoft VS 2008. I think jules used the sdk from the following link:

choose the latest version: Gecko 1.9 (Firefox 3.0) in the list

hope this help.

Cheers!
Leon


#15

i’ve implemented an initial code support for linux browser plugins. i’ll clean up the code and send you the changes.

cheers


#16

[quote=“kraken”]i’ve implemented an initial code support for linux browser plugins. i’ll clean up the code and send you the changes.

cheers[/quote]

Awesome.

I’m also using vista, so I guess it could be something xp-specific. I’ll have to dust-off my xp machine and try it, I guess…

Sure, it’s possible, but not something I’d be interested in doing. I can’t really see why you think it’s a good idea…


#17

our office is movig to a new location and i didn’t have time to test it but i will asap.

as for the wrapper, i’d like to have one installer for people on my portal and show many components on the site, without the need to install multiple plugins, just one plugin, easier to distribute and easier to upgrade later. I’ll try to do something myslef i can understad it’s not something that many people will be interested in.


#18

Hi.jules
How are you?
I still got FF Browser freeze when I click the second and third buttons for your plugin demo code. I debugged it , and API in plugin for these two did not get called when I built and using demo Plugin on windows XP SP3. I use FF 3.0.

Any suggestions?
Thanks!

Leon


#19

Hi, jules
I am using windows xp SP2 not SP3 , it is typo.

i’m usin XP SP2 with FF 3.0.10 [Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10] VS2008

cheers!
Leon


#20

I’ve still not tried it in XP, I’ve just been using vista. Will hopefully try it out soon…