问题
Is it possible to use a .dll made with Firebreath in a Firefox extension?
Currently, I am trying to port an extension I made for Google Chrome that uses javascript to get the HTML of the document, and then calls a function from the .dll and passes the HTML of the document as a parameter. The .dll then saves the file and launches a program.
Is there a simple way to port this functionality over to Firefox? Or will I have to rewrite the code using XPCOM?
回答1:
XPCOM is too complicated for simple things which is why Firefox 4 and above has js-ctypes (see https://developer.mozilla.org/en/js-ctypes for an overview and https://developer.mozilla.org/en/js-ctypes/Using_js-ctypes#Calling_Windows_routines for an example). This allows you to load the DLL and call an exported native function easily. If you really need to use this DLL as an NPAPI plugin things get more complicated because you need a window to load the plugin into and Firefox unlike Chrome doesn't have a dedicated background window for that. But I guess that you only turned your DLL into a plugin to be able to use it in Chrome.
On locating your DLL to use with ctypes.open() see my answer here: Reference a binary-component to js-ctypes
回答2:
For simple functionality, I also recommend js-ctypes. It is easy to use and provides good isolation (since scripts on the page cannot access the imported library).
If you really need to access an NPAPI plugin from any page, the standard approach seems to be to create an extension and modify the DOM of each page to include the plugin:
Scriptable NPAPI plugin doesn't work with Firefox
回答3:
yes you can use a firebreath dll as an firefox extension. you can use the same javascript with some modifications for Firefox and for HTML you have to use XUL. You have to load the script in a XUL that overlays default firfox's browser.xul
overlay chrome://browser/content/browser.xul chrome://Yourproject/content/Youroverlay.xul
Inside Youroverlay.xul, you can add the below line to embed Firebreath dll
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/"?>
<overlay id="myOverlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<script type="application/javascript" src="chrome://Yourproject/content/background.js"/>
<vbox style="height:0;">
<html:embed type="application/x-myproject" id="myproject1" style="height:0;"/>
</vbox>
</overlay>
来源:https://stackoverflow.com/questions/6208940/using-a-plugin-generated-with-firebreath-in-a-firefox-extension