# Browser plugins

**URL:** <https://forum.juce.com/t/browser-plugins/3864>\
**Category:** General JUCE discussion\
**Created:** [April 27, 2009, 3:10pm UTC](https://forum.juce.com/t/browser-plugins/3864 "2009-04-27T15:10:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 27, 2009, 3:10pm UTC](https://forum.juce.com/t/browser-plugins/3864/1 "2009-04-27T15:10:39Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [April 27, 2009, 7:16pm UTC](https://forum.juce.com/t/browser-plugins/3864/2 "2009-04-27T19:16:42Z")

</div>

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](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

```auto
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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 27, 2009, 8:05pm UTC](https://forum.juce.com/t/browser-plugins/3864/3 "2009-04-27T20:05:33Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [April 27, 2009, 8:23pm UTC](https://forum.juce.com/t/browser-plugins/3864/4 "2009-04-27T20:23:10Z")

</div>

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

> **[Plugins](https://developer.mozilla.org/en-US/docs/Archive/Plugins)**
>
> For more information about plugin roadmap, see non-archived plugin information.

  
then i checked out wikipedia links (also mozilla) here [https://developer.mozilla.org/en/Plugins](https://developer.mozilla.org/en/Plugins) and this links to this [http://mxr.mozilla.org/mozilla-central/source/modules/plugin/sdk/](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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 27, 2009, 8:42pm UTC](https://forum.juce.com/t/browser-plugins/3864/5 "2009-04-27T20:42:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [April 28, 2009, 10:15am UTC](https://forum.juce.com/t/browser-plugins/3864/6 "2009-04-28T10:15:36Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 28, 2009, 10:49am UTC](https://forum.juce.com/t/browser-plugins/3864/7 "2009-04-28T10:49:55Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [April 28, 2009, 10:55am UTC](https://forum.juce.com/t/browser-plugins/3864/8 "2009-04-28T10:55:12Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 28, 2009, 11:27am UTC](https://forum.juce.com/t/browser-plugins/3864/9 "2009-04-28T11:27:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [April 28, 2009, 12:40pm UTC](https://forum.juce.com/t/browser-plugins/3864/10 "2009-04-28T12:40:46Z")

</div>

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

```auto
const var popUpMessageBox (const var* params, int numParams)
```

but this code never gets executed, however

```auto
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:

```auto
    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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 28, 2009, 1:15pm UTC](https://forum.juce.com/t/browser-plugins/3864/11 "2009-04-28T13:15:31Z")

</div>

Doh! I think that should probably read:

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

…talk about basic c++ mistakes!

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [April 28, 2009, 1:27pm UTC](https://forum.juce.com/t/browser-plugins/3864/12 "2009-04-28T13:27:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [April 28, 2009, 9:50pm UTC](https://forum.juce.com/t/browser-plugins/3864/13 "2009-04-28T21:50:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pluginstarter](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@pluginstarter](https://forum.juce.com/u/pluginstarter)\
**Post date:** [April 28, 2009, 10:13pm UTC](https://forum.juce.com/t/browser-plugins/3864/14 "2009-04-28T22:13:45Z")

</div>

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:

> **[Gecko SDK](https://developer.mozilla.org/en-US/docs/Mozilla/Gecko/Gecko_SDK)**
>
> The Gecko SDK, also known as the XULRunner SDK, is a set of XPIDL files, headers and tools to develop XPCOM components which can then in turn e.g. be accessed from XUL using JavaScript.

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

hope this help.

Cheers!  
Leon

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [April 29, 2009, 8:33am UTC](https://forum.juce.com/t/browser-plugins/3864/15 "2009-04-29T08:33:42Z")

</div>

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

cheers

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 29, 2009, 2:30pm UTC](https://forum.juce.com/t/browser-plugins/3864/16 "2009-04-29T14:30:06Z")

</div>

[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.

> [@](#):
>
> 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.

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…

> [@](#):
>
> 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.

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…

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [April 29, 2009, 8:32pm UTC](https://forum.juce.com/t/browser-plugins/3864/17 "2009-04-29T20:32:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pluginstarter](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@pluginstarter](https://forum.juce.com/u/pluginstarter)\
**Post date:** [May 7, 2009, 5:32pm UTC](https://forum.juce.com/t/browser-plugins/3864/18 "2009-05-07T17:32:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pluginstarter](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@pluginstarter](https://forum.juce.com/u/pluginstarter)\
**Post date:** [May 7, 2009, 5:36pm UTC](https://forum.juce.com/t/browser-plugins/3864/19 "2009-05-07T17:36:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 8, 2009, 3:15pm UTC](https://forum.juce.com/t/browser-plugins/3864/20 "2009-05-08T15:15:21Z")

</div>

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

[Next page](https://forum.juce.com/t/browser-plugins/3864.md?page=2)
