Skip navigation

Tag Archives: plugin

Today We’ll implement a javascript callback interface in C++.

We’re targetting a browser plugin (Which already has a “one way” js interface).
The idea : we want the plugin to trigger javascript methods, and ultimately we want to be able to link any js code to our plugin events loop.

Note:This article requires some c++/Win32 api/netscape api skills as well as a tiny clue of what is discussed here…

When coding cross platform software , you’ll often have to write some parts of your plugin twice. (sometimes more than twice)
In this case, MS activex com objects aren’t handled the way nsi controls are, so we need to split the code.

our method(s) should have an input parameter, “name” that we will use to store our javascript function name we want to trigger.

so something like : return Our_JS_CallBack(const char * name)

when called from the plugin, this method will send client’s browser a js event that will spawn our function which name is has been inputed at call.

Please be carefull here : ClientSite and ClientInstance are declared and initialised out of this 2 functions.
both of these pointers should have a correct value before using ::Our_JS_CallBack

MicroSoft CODE: m_spClientSite is a pointer to oleclientsite of your plugin ( type : ComPtr )
NetScape CODE: ClientInstance is the netscape NPP object pointer for your plugin (type : NPP);

Microsoft style:

HRESULT Plugin::Our_JS_CallBack(const char * name)
IOleClientSite *m_spClientSite = (IOleClientSite *)GetCClientSite();

IServiceProvider* isp;
IWebBrowser2* ppBrowser;

HRESULT hr = m_spClientSite->QueryInterface(IID_IServiceProvider, reinterpret_cast(&isp));
if(FAILED(hr)) return FALSE;

hr = isp->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, reinterpret_cast(&ppBrowser));
if(NULL==ppBrowser) return S_FALSE;

IDispatch *m_ppDispDoc;
hr = ppBrowser->get_Document(&m_ppDispDoc);
if(FAILED(hr)) return S_FALSE;

IHTMLDocument2 *ppDocument2;
hr = m_ppDispDoc->QueryInterface(IID_IHTMLDocument2 ,reinterpret_cast(&ppDocument2));
if(FAILED(hr)) return S_FALSE;

CComPtr scriptEngine;

DISPID callid;
OLECHAR FAR* szCallMember = T2OLE(name);
HRESULT hr3 = scriptEngine->GetIDsOfNames(IID_NULL, &szCallMember, 1, LOCALE_USER_DEFAULT, &callid);
DISPPARAMS callParameters = { 0 };
int nargs = 0;
callParameters.cArgs = nargs + 1;

CComPtr win;

VARIANT *vargs= new VARIANT[nargs + 1];
VARIANT result;

vargs[nargs] = CComVariant(win);
long index;
callParameters.rgvarg = vargs;
EXCEPINFO exception;

HRESULT hr4 = scriptEngine->Invoke(callid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &callParameters, &result, &exception, 0);

return S_OK;

NetScape Style:

NPBool NSPlugin::Our_JS_CallBack(const char *name)
NPObject *window;
NPN_GetValue(ClientInstance, NPNVWindowNPObject, &window);
NPIdentifier methodName;
methodName= NPN_GetStringIdentifier(name);
uint32_t argCount=0;
NPVariant result;
NPN_Invoke( NsInstance,
return TRUE;

You ‘ll have to declare both methods in your plugin class and be carefull not to call Our_JS_CallBack in a loop !

ie (c++ code): instance->Our_JS_CallBack(“JSEvent”);

you can then go to your HTML code after plugin’s instanciation, and write down the body of your callback

function JSEvent()
alert(“well done!”)

when the plugin executes instance->Our_JS_CallBack(“JSEvent”), a nice alert box should appear on client side, validating the javascript callback.

The hard part was understanding the concept and digging msdn 🙂


StreamPlug is an advanced media player for the web : It decodes MPEG4 video streams such as h264, and vorbis audio from a remote file using a simple http server.
This JQuery plugin will help you add a streamplug player on your website/blog, a single line is sufficient to display the player to the right size, and play the media on the fly, without any buffering time !

Streamplug installer:click here
Demo:click here
Download source: click here
Plugin Homepage:click here

Here is a demonstration on how to use it in your web contents:


– Jquery
– JStreamPlug plugin
– StreamPlug


<script type=’text/javascript’ src=’jquery.min.js’></script>
<script type=’text/javascript’ src=’jquery.JStreamPlug.js’></script>


<div class=”player”></div>



Syntax : $(element).StreamPlug(url,width,height,skin_name);

Here are described some key functionalities you can run after calling the plugin:

//Get Attributes

//Get Plugin Window Width

//Get Plugin Window Height

//Get Plugin Skin Width

//Get Plugin Skin Height

//Get Plugin Version Number

//Get current volume

//Get current play position in kb

//Get current play position in ms

//Get current received stream kb amount

//Get current file lenght in kb

//Get Current File Url

//Test if StreamPlug is Playing


//Add an url in the playlist

//Add pls to the Playlist

//Add An Url With Name

//Add Crypted Playlist

//Add Subtitle File/Url

//Add Saveable url to playlist

//Add .plc to the Playlist

//Empty the Playlist

//Load specified skin

//Move Playlist Window

//Pause Current Stream

//Play An Url

//Play Item # in Playlist

//Play Current Stream

//Play and Save Url

//Play Prev Item

//Play Next Item

//Start After n Kb

//Stop Current Stream

//Play Item From db

//Play a cgi sec file

//Play a cgi file

//Play Multiple (audio/video separated)

//Set Video Size

//Set Original Size

//Set Loop mode

//Set BackGround Color

//Set Video Ratio

//Set Volume

//Set Play-on-Start Attribute

//Set Full Screen

//Set if user Can Resize

//Set if user Can Download

//Set Border Size

//Set Border Color

//Set Active Srt (-1 none)

//Reset Srt

//Set playmode

//Set Video Url

//Set Video Url Ms

//Set Video Url Ms +ID

//Set Event Grid Pos

//Set Event Grid Size

//Set Event Js

//Set pos kb

//Set pos ms

//Set color of A/V buffers


//Show Pluggle Version

//Show the playlist window

//Show Option Window

//Show Server Version