Difference between revisions of "InternalFirefoxJSC"

From Htmlpedia
Jump to: navigation, search
Line 13: Line 13:
 
=== What is the JS-CTYPES ===  
 
=== What is the JS-CTYPES ===  
 
* It is a way to call C dynamic libraries from Javascript. It is possible to do this from Chrome (the internal side of Firefox).
 
* It is a way to call C dynamic libraries from Javascript. It is possible to do this from Chrome (the internal side of Firefox).
* Ctypes allow to declare functions and C types
+
* Ctypes allows to declare functions and C types
 
* CData is an instantiation of a CTypes
 
* CData is an instantiation of a CTypes
* It is pure C call
+
* It is pure C  
  
 
=== Problems ===  
 
=== Problems ===  
 
* I have to remove all the XPCOM code from the library, who was full of it.
 
* I have to remove all the XPCOM code from the library, who was full of it.
 
* And replace all C++ interfaces by simple C functions exported from a dynamic library
 
* And replace all C++ interfaces by simple C functions exported from a dynamic library
* Then on the Javascript side. I create a new wrapping object type: TidyLib who react exactly like the old XPCOM C++ component but that call inside the C functions via JS-CTypes
+
* Then on the Javascript side. I create a new wrapping object type: TidyLib who reacts exactly like the old XPCOM C++ component but that call inside the C functions via JS-CTypes
 
* Keep in mind to use Unicode everywhere
 
* Keep in mind to use Unicode everywhere
 
* Keep in mind memory allocation
 
* Keep in mind memory allocation

Revision as of 23:00, 26 November 2011

Change 2011 11 25

Note for me.

The idea was to get rid of XPCOM for always. There were several ways to do it. Replace XPCOM by JS-CTYPES is the hardest way, but the more performant way by far.

What was XPCOM ?

  • XPCOM was an way to build component who exposes nice interface writen in IDL, while the code of the component could be written in C++ and called from Javacript of C++.
  • So, it was a very object relational system. Based on pure C++.
  • It is past now, since Firefox 4 has unfrozen his XPCOM glue interface, what caused binary incompatibilities of binaries between each version of Firefox.
  • This means for me, recompile each new Firefox version and then the XPCOM component of Tidy each 6/8 weeks -> a nightmare.

What is the JS-CTYPES

  • It is a way to call C dynamic libraries from Javascript. It is possible to do this from Chrome (the internal side of Firefox).
  • Ctypes allows to declare functions and C types
  • CData is an instantiation of a CTypes
  • It is pure C

Problems

  • I have to remove all the XPCOM code from the library, who was full of it.
  • And replace all C++ interfaces by simple C functions exported from a dynamic library
  • Then on the Javascript side. I create a new wrapping object type: TidyLib who reacts exactly like the old XPCOM C++ component but that call inside the C functions via JS-CTypes
  • Keep in mind to use Unicode everywhere
  • Keep in mind memory allocation

Result

  • The result is that very surprisingly it works fine.

Step 1 - dynamic library

  • removed all the Firefox header
  • removed all the Firefox memory allocation call and replaced them by the lib of Tidy
  • removed all the Firefox dependencies
  • exported a C function (with extern "C"}for each function of XPCOM interface
  • changed the build system to build a library and not a component
  • compile/compile/compile
  • got a library and checked the result with depends22_x86.
  • I see C functions like "libTidyGetErrorDescription", ...
  • Added a function to free memory

Step 2 - javascript

  • removed the creation of the XPCOM component and created a new class TidyLib
  • created 2 items for each C dynamic libray exported functions
    • a declaration of the C function in the constructor
    • a wrapper that has the same function name than the old XPCOM and that call the JS-CTypes defined functions

Step 3 - test

After some try and error due to compilation, it works fine ??? I did not expected to be so lucky.


To dos

  1. correct the stuff that mozilla add-on asked me to do
  2. check what happens when the library is not there and take the needed action (go in online mode)
  3. load the library from the firefox profile
  4. try the same on Linux 32 bits.
  5. Publish this work.