Difference between revisions of "InternalFirefoxJSC"

From Htmlpedia
Jump to: navigation, search
Line 1: Line 1:
== Idea ==
+
== Change 2011 11 25 ==
 +
Note for me.
  
 +
The idea was to get rid of XPCOM for always.
 +
There were several ways to do it. I choosed probably the hardest way, but the more
 +
performant way, it is to replace XPCOM by JS-CTYPES.
  
One way is to get rid of XPCOM for always.
+
=== 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++.
 +
* 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.
  
So, in place of passing the HTML through memory to the nstidy.dll
+
=== 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 allow to declare functions and C types
 +
* CData is an instantiation of a CTypes
 +
* It is pure C call
  
* write a file: see here: https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO
+
=== Problems ===
* call the tidy.exe or whatever to validate
+
* I have to remove all the XPCOM code from the library, who was full of it.
* it generates an output file
+
* And replace all C++ interfaces by simple C functions exported from a dynamic library
* read it
+
* 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
* done
+
* Keep in mind to use Unicode everywhere
 +
* Keep in mind memory allocation
  
* One possible argument is to know if we need the numbers of errors or the result.
+
=== Result ===
 +
* The result is that very surprisingly it works fine.
  
=== Problem ===
+
==== Step 1 - dynamic library ====
* How to implement the filter ?
+
* removed all the Firefox header
* Perfomance issue ?
+
* removed all the Firefox memory allocation call and replaced them by the lib of Tidy
* Concurrency between windows ? How to handle several parallel call to the exe ? Should it be done ?
+
* 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 nearly from the first test.
 +
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.

Revision as of 22:56, 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. I choosed probably the hardest way, but the more performant way, it is to replace XPCOM by JS-CTYPES.

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++.
  • 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 allow to declare functions and C types
  • CData is an instantiation of a CTypes
  • It is pure C call

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 react 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 nearly from the first test. 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.