0

There are known ways of writing ActiveX plugins with Delphi, but the ActiveX itself poses a lot of limitations in browsers other than IE. So I was thinking - how to compile a plugin in NPAPI format, natively compatible with Chrome/Firefox?

Intent of the plugin is to allow to embed a VCL form into the HTML page and be able to bi-directionaly communicate with this form using JavaScript. E.g. clicking a button on a form would call JavaScript function on the page, and JavaScript functions on the page could send events to a VCL form. How this can be achieved?

Kromster
  • 7,181
  • 7
  • 63
  • 111
  • And of course it is documented: https://developer.mozilla.org/en-US/Add-ons/Plugins – David Heffernan Apr 07 '14 at 08:13
  • @DavidHeffernan: Please take a look at the answer and tell me where linked documentation has that information including working wrapper code. – Kromster Apr 07 '14 at 08:36
  • Perhaps I don't understand the question. You are asking for a library recommendation? That's off-topic as I'm sure you know. – David Heffernan Apr 07 '14 at 08:38
  • Let me try to explain: I was quested with writing a plugin for Chrome - there are two possible options, ActiveX (through 3rd party ActiveX plugin) and NPAPI plugin. ActiveX from Delphi is pretty straightforward, but NPAPI is not - I spent a good half a day Googling for solutions. Even SO had very little info on that matter. So I decided to share working solution I have found with others. Too bad it can't be expressed in simple instructions - it involves a 92kb of wrapping code. Please tell me, does that renders the question and answer off-topic? – Kromster Apr 07 '14 at 08:48
  • I think so. You are asking for a library recommendation. According to the powers that be, that is off-topic. – David Heffernan Apr 07 '14 at 08:50
  • Similar question: http://stackoverflow.com/questions/8862628/creating-npapi-plugin-in-delphi-and-accessing-exported-apis-using-javascript – Kromster Apr 07 '14 at 08:51
  • There are many question on SO approaching and crossing this blurry line. I'm asking about how to do it, with a library or without. I will gladly accept any answer that will solve the case without a "library" - e.g. Delphi > File > New > DLL Projects > "New NPAPI Project". – Kromster Apr 07 '14 at 08:57
  • You'd accept an answer that pointed you to the Add Ons SDK? – David Heffernan Apr 07 '14 at 09:11
  • 1
    Please be aware that both Firefox and Chrome will make most plugins click-to-play soon. Chrome has also already announced their intent to drop NPAPI. I can't recommend to start new projects based on NPAPI now. – Georg Fritzsche Apr 09 '14 at 13:06

1 Answers1

1

There's a list of existing NPAPI wrappers for Delphi at Mozilla bugtracker: https://www.mozdev.org/bugs/show_bug.cgi?id=8708

The latest entry (NPAPI plugin framework with scripting support + demo by Yury Sidorov) offers exactly what is needed.

With that VCL Form project can be compiled into a DLL compatible with NPAPI. Manifest.json also needs to be added. Afterwards the plugin can be installed into Chrome like usual.

Following HTML code embeds the VCL form that is stored in the plugin:

<EMBED id="embed1" TYPE="application/x-delphi-demo-plugin" ALIGN=CENTER WIDTH=400 HEIGHT=300>

<script>
var embed1 = document.getElementById('embed1');
</script>

<input type=button value="Show Value" onclick='alert("Value=" + embed1.value);'>

And that is how Form can change the HTML page around it:

with Plugin.GetBrowserWindowObject do
  GetObject('document')['bgColor'] := clRed;

P.S. The only fix that should be applied for modern Delphi versions - change string and PChar to AnsiString and PAnsiChar throughout the NPPlugin.pas. Or else communication with embedded form is broken.

Kromster
  • 7,181
  • 7
  • 63
  • 111
  • Are you sure it should be `AnsiString`? That implies a limitation to ANSI characters. I would have expected Unicode support with UTF-8 encoding. In fact looking at the library that you have linked to it seems clear that UTF-8 is the lingua franca, but that the library fails to recognise that. It would need a deal of work to fix it. – David Heffernan Apr 07 '14 at 08:27
  • Indeed UTF-8 would be a proper solution, but for now `AnsiString` does the job by making the example code working (even with ANSI limitation). The big thing here is that VCL form communicating with JS in a browser. – Kromster Apr 07 '14 at 08:39
  • @DelphiStudent: Maybe you should ask a separate question. As of now it is unclear. – Kromster Mar 15 '15 at 13:37
  • i asked question about it here is the url http://stackoverflow.com/questions/29061765/npapi-plugin-framework-error – DelphiStudent Mar 15 '15 at 14:30
  • @Krom Stren have you figure any way to read html param tag using this frame work ? – DelphiStudent Mar 18 '15 at 14:51
  • 2
    @DelphiStudent: Sure. Contact me on Skype: kromster80 – Kromster Mar 19 '15 at 05:46