14

I am starting to work on a browser extension and because of the nature of the extension I need to develop it in C++. I am currently working with Firefox but would like my code to be portable across browsers. First of all is there a library or an interface (like the NPAPI) that I can use to ensure this for extensions? What are the things I need to worry about?

I am not using XPCOM and instead writing the functionality in C++ so that I can just compile the library for each platform and can bundle it with the extension for each browser. For Firefox, I am using XUL to develop the JS wrapper for my extension and an IDL file generates the c++ interface for me. Can I do something better? I just want to make sure I am not going down the wrong path.

EDIT: Please also suggest if there is a better forum for this type of question.

Ajay
  • 18,086
  • 12
  • 59
  • 105
user220201
  • 4,514
  • 6
  • 49
  • 69

2 Answers2

4

My background: a few years back, I worked on a cross-platform, cross-browser NPAPI plugin that used OpenGL to do image rendering. I've paid some attention to the space since then, but it's not what I do nowadays. I've written non-plugin extensions for Firefox but not Safari or Chrome.


A lot depends on exactly what you want your extension to do, and what sort of user interface you want to present. Different browsers have different ideas of what extensions may and may not do.

If you just wanted to display images or video in a custom format, NPAPI is probably your best bet. NPAPI is fundamentally a thin wrapper around native platform APIs. As such, cross-platform NPAPI code has to deal with individual platform quirks, as well as different levels of support for NPAPI from browsers. Google has a project called Pepper to fix some of NPAPI's issues, but Pepper doesn't yet have support from any browser besides Chrome.

Google's Native Client project provides an alternative to NPAPI for running native code, but it imposes restrictions on native code. For example, pthreads are allowed, but network access isn't. There is a NaCL subproject called c_salt which appears to address the sort of HTML/JS UI + native code integration you seek. Unfortunately it's still in the design phase, and thus isn't terribly helpful for writing extensions today.

My understanding is that, for now, a cross-browser extension which integrates with the browser UI and also integrates with native code is not feasible. Safari and Chrome both restrict extensions much more than Firefox does, and only allow extensions written in JavaScript. I don't know if it's possible to have an extension in Safari or Chrome interact with a browser plugin written in NPAPI. I'm guessing it's either impossible or incredibly painful.

Overall, you'll find life much, much easier if you carefully restrict which browsers and platforms to target. Exactly which browsers and platforms to choose is something that only you can decide.

Ben Karel
  • 4,591
  • 2
  • 26
  • 25
  • 1
    So there isn't a FireBreath framework equivalent for writing Browser extensions? – Robert S. Barnes Feb 07 '11 at 13:18
  • 1
    Speaking of FireBreath, I just came across an excellent post on the dev's site, [Browser Plugins vs Extensions: The Difference](http://colonelpanic.net/2010/08/browser-plugins-vs-extensions-the-difference/). Admittedly, I've been confused about the difference between the two. (Which is a shame, because what I'm actually being asked to implement is an extensions!) – Courtney Christensen Apr 01 '11 at 20:38
3

Not many know about it, but yes, you can write cross browser plugins using Qt. :-)

You can use the QtBrowserPlugin just for that.

The QtBrowserPlugin solution makes it easy to write browser plugins that can be used in Mozilla FireFox, Safari, Opera, Google Chrome, QtWebKit and any other web browser that supports the "Netscape Plugin API", NPAPI.

QtBrowserPlugin is part of the Qt Solutions packages.

Shinnok
  • 6,279
  • 6
  • 31
  • 44