-1

I am working on a browser extension in Firefox to intercept HTTP requests and alter them. Due to the purpose of my project, I would need to incorporate a project that's built in C++ in order to process that information. Rewriting the C++ project would take too much work (it's a big project). I read that I could make the C++ code into a .dll file and use that, but I am unsure on how to do this (kind of new to programming extensions. Did do a lot of web dev tho).

I have been doing a lot of research, and NPAPI seems to be the way to go (I know it's being phased out, but the project is just a proof of concept that I need working). However, I'm not sure whether frameworks like FireBreath can do extensions. It also needs to be in Firefox, since my company doesn't use anything else.

Is there a good method of accessing the C++ code in an extension? I'd love some links to tutorials if there are any. I did read this previous thread, but it didn't give a solid conclusion on what to use. Also, if there's a better/easier way to do this (plugins, etc), I'd love to know!

Sorry if this is in the wrong forum. Still new here :S

Community
  • 1
  • 1
  • Did you consider [FastCGI](http://fastcgi.com/), [ICAP](http://en.wikipedia.org/wiki/Internet_Content_Adaptation_Protocol), or using an HTTP server library in C++ (like [libonion](https://www.coralbits.com/libonion/) etc...)? Why do you need to work inside the browser? Why not inside an HTTP server or proxy? – Basile Starynkevitch Oct 21 '13 at 16:08
  • I'm relatively knew to this and don't know what those are... My C++ code takes the HTTP request data, encrypts it, and then sends it back to the browser, and then users who input data (ex: random textboxes) won't know that it's being encrypted. Could these do what I'm looking for? – user2903888 Oct 21 '13 at 16:15
  • 1
    I believe you need to learn quite a lot before coding. Take time to learn more about HTTP (and follow all the links I gave you) – Basile Starynkevitch Oct 21 '13 at 16:24

2 Answers2

1

I agree with the comments that you should absolutely check all other possibilities before going with this one. I'd probably look at writing your own proxy server (similar to how Charles works) that when it's running it does whatever you want done.

FireBreath can be used to create plugins, and only to create plugins. however, you can use a plugin inside an extension, at least for now (you already know about the planned phasing out). Thus if you can capture the data using the extension (and I don't know extensions, so I'm not sure if you can or not) then you could pass it into a plugin instance using your javascript extension in order to do the processing that you want to do.

Rule of thumb, though: If it can be done in any other way than a plugin, don't use a plugin.

taxilian
  • 14,229
  • 4
  • 34
  • 73
1

@taxilian is right to say:

If it can be done in any other way than a plugin, don't use a plugin.

Writing an actual Firefox extension would be more suitable. These days you're recommended to use js-ctypes to interface with binary blobs (DLL, so, dylib). What you would do:

  • Write most of your add-on in Javascript, because that is how it is usually done and because it is the easiest way. There are ways to intercept, modify and trace http request/response e.g. the http observers are kinda an entry point to that. Have a look at MDN and other code (other add-ons) that manipulate HTTP requests to see how the different pieces (observers, nsIHttpChannel, nsITracableChannel
  • Create a C-only API for your existing library, wrapping the C++ API that you need to access for your add-on. General rule of thumb: Keep it simple.
  • Compose js-ctypes bindings to that C-only API, so that you can use it from Javascript and use those bindings in your other extension code.
nmaier
  • 32,336
  • 5
  • 63
  • 78