Difference between revisions of "InternalFirefoxJSC"

From Htmlpedia
Jump to: navigation, search
 
 
(11 intermediate revisions by the same user not shown)
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. Replace XPCOM by JS-CTYPES is the hardest way, but the more performant way by far.
  
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++ 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.
  
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 allows to declare functions and C types
 +
* CData is an instantiation of a CTypes
 +
* It is pure C
  
* 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
+
* Remove all the XPCOM code from the library, who was full of it.
* it generates an output file
+
* Replace all C++ interfaces by simple C functions exported from a dynamic library
* read it
+
* Then on the Javascript sid, 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
* done
+
* Keep in mind to use Unicode everywhere
 +
* Keep in mind memory allocation/deallocation
  
* 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.
 +
* Check for 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 JS-CType declaration of the C function in the constructor
 +
** A wrapper that does exactly the same than the old XPCOM C++ component 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 ===
 +
# correct the stuff that mozilla add-on asked me to do
 +
# check what happens when the library is not there and take the needed action (go in online mode)
 +
# try the same on Linux 32 bits.
 +
# Publish this work.
 +
 
 +
=== Done ===
 +
# load the library from the firefox profile (done)

Latest revision as of 17:15, 27 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

  • Remove all the XPCOM code from the library, who was full of it.
  • Replace all C++ interfaces by simple C functions exported from a dynamic library
  • Then on the Javascript sid, 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/deallocation

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.
  • Check for 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 JS-CType declaration of the C function in the constructor
    • A wrapper that does exactly the same than the old XPCOM C++ component 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. try the same on Linux 32 bits.
  4. Publish this work.

Done

  1. load the library from the firefox profile (done)