1

I have written a windowless NPAPI plugin which binds to a shared library for accessing my native resources. The plugin is loaded by a web Application running in Firefox browser. Recently, I have seen in net, that using Java Script extensions, one can also make native code function calls.But these Java Script extensions are specific to browsers.

Can some one please tell me that if I use a Java Script extension instead of NPAPI plugin for calling my native code, will there be any performance improvement in terms of latency in making native library API calls?

Kindly note: My query is generic and not specifically for Firefox browser.

abraham
  • 46,583
  • 10
  • 100
  • 152
Souvik
  • 151
  • 3
  • 14

1 Answers1

1

There is no generic answer to a question like this, the mechanisms implemented by different browsers have nothing in common.

Firefox: A native library can be called via js-ctypes. This mechanism should be more light-weight than the communication with an NPAPI plugin. Even more importantly, you don't have the overhead of inter-process communication (newer Firefox versions run plugins in separate processes).

Chrome: AFAIK the only way to access operating system functionality (such as writing files to a random location on disk) is via NPAPI, Chrome won't allow extensions to use system libraries. However, if you use a native library only to speed up execution and don't mind having this code run in a sandbox - the native client might work for you. Due to sandboxed execution it will probably be slower than an NPAPI plugin but it won't trigger huge scary warnings when your extension is installed.

Safari: From what I know, Safari doesn't let you use native libraries, not even via NPAPI plugins.

Internet Explorer: As of MSIE 9.0, Internet Explorer still doesn't have anything resembling JavaScript-based extensions.

Community
  • 1
  • 1
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • Thanks for the reply. I have never used an extension before, so I am asking this query. A NPAPI plugin is loaded in the memory of the page and therefore gets unloaded when the page is destroyed. In case of extension, does it get loaded in the memory of the extension and therefore remains alive as long as the browser instance is live ? Sorry for this novice query. – Souvik Feb 17 '12 at 01:36
  • Safari extension can use NPAPI plugins. But such plugin cannot be included in a extension. It must be installed separately. – anfilat Feb 17 '12 at 07:32
  • @anfilat: That's what I meant - basically, an extension doesn't have any way to get low-level access. If a plug-in already exists in the system then it can use it (just like a web page can do it) but that isn't really a practicable approach for most extensions due to complicated installation. – Wladimir Palant Feb 17 '12 at 12:28
  • @Souvik: This is often an oversimplified view of things. For example, Firefox will start a new process the first time an NPAPI plugin is used, AFAIK that process is never shut down. So while there might not be an active plugin instance, the plugin is still loaded. But as far as extensions go - yes, they typically remain active for the entire browser session. – Wladimir Palant Feb 17 '12 at 12:40