Monday, May 17, 2010

Developing Firefox Extensions

  1. Create a development profile: 


    You need to install several extensions which may slow down firefox performance. So create a separate development profile using the following steps-
    • Open command prompt
    • [Firefox Installation Directory]\firefox.exe -no-remote -P
    • Create a new profile.
    • Start firefox next time with the command: [Firefox Installation Directory]\firefox.exe -no-remote -P [new profile name]

  2. Install some useful extensions: Firebug is the most useful one.


  3. Set some developer preferences: Type about:config in the address bar. Set or add, if do not already exist, the following properties:


    • javascript.options.showInConsole = true.
    • nglayout.debug.disable_xul_cache = true.
    • browser.dom.window.dump.enabled = true.
    • javascript.options.strict = true.
    • extensions.logging.enabled = true.
    • dom.report_all_js_exceptions = true.


  4. Directory structure: Different from usual programming frameworks, Firefox extension has a predefined directory structure for files. The browser will look in specified folder when it needs a file for e.g. installation, preference or visual overlays.


    • For new extension: Use the wizard in http://ted.mielczarek.org/code/mozilla/extensionwiz/. Copy the contents of the generated zip file into [Profile]\extensions\] folder. It is a folder with the name of your desired extension name. Rename this folder name into the extension ID from install.rdf or use some unique name like an e-mail address. Restart firefox. Your add-on should appear in the browser. Check Tools->Add-ons if your extension is listed there.
    • Existing extension: Copy extension into the [Profile]\extensions\] folder. Remember the filename or sub-folder for the extension must be same as the extension ID in install.rdf or a unique name like an e-mail address.

References:
  1. Building an extension: https://developer.mozilla.org/en/Building_an_Extension
  2. Setting up development environment: https://developer.mozilla.org/en/Setting_up_extension_development_environment
  3. Creating a status bar extension: https://developer.mozilla.org/en/Creating_a_status_bar_extension
  4. http://blog.mozilla.com/addons/2009/01/28/how-to-develop-a-firefox-extension/
  5. http://www.slideshare.net/littlebtc/ext-0509
  6. http://www.slideshare.net/robnyman/how-to-write-your-first-firefox-extensio?src=related_normal&rel=530642
  7. http://www.rietta.com/firefox/Tutorial/overview.html

Tuesday, May 11, 2010

How to contribute to Salattimes firefox extension?

Analogous to my previous post this post describes how to check-in/check-out the firefox add-on project salattimes from google code server.
  1. Check-out: You need a subversion client to check-in/check-out code from the SubVersion source control server. Windows users should download TortoiseSVN from http://tortoisesvn.net/downloads. Linux and MacOS users should google to find the appropriate client.

    Windows users just right-click on explorer in your development directory and then click "SVN Checkout...". The following dialog will appear.




  2. If you click "OK", a dialog box will appear to provide username/password. You can now start programming.

    Non-windows users might need the following command on the console:
    svn co https://uvfseditor.svn.sourceforge.net/svnroot/uvfseditor uvfseditor
The rest is same as the previous post.

How to contribute to UVFSEditor?

Last few days, several programmers are accepted to join the development efforts of UVFSEditor. In this post, I will briefly write the steps necessary to involve in the development.
  1. Check-out: You need a subversion client to check-in/check-out code from the SubVersion source control server. Windows users should download TortoiseSVN from http://tortoisesvn.net/downloads. Linux and MacOS users should google to find the appropriate client.

    Windows users just right-click on explorer in your development directory and then click "SVN Checkout...". The following dialog will appear.




  2. If you click "OK", a dialog box will appear to provide username/password. You can now start programming.

    Non-windows users might need the following command on the console:












    svn co https://uvfseditor.svn.sourceforge.net/svnroot/uvfseditor uvfseditor

  3. Check-in/Commit:



  4. First of all, be careful, don't check-in until you are absolutely sure what you are checking-in does not break the existing code.

    Right click the file or folder you want to check-in. The following context menu should appear:

    First click "SVN Update", then click right mouse button again and click "SVN Commit...". The following dialog should show up:

    Write an appropriate message on the "Message:" box and click ok.



    You must write a message describing the changes you have made.

    Now you are ready for UVFSEditor development!!!
  5. Development: You need Visual Studio 2008 to develop (e.g. you can also use MonoDevelop), but the UVFSEditor will run only under Windows OS. Open the UVFSEditor.sln solution and compile. To understand the code hierarchy, first look at "UVirtualFileSystem" project. You will find there classes which resemble classes in System.IO package. The classes in "DotNetFileSystem" and "OleStructuredFileSystem" are inherited from those in "UVirtualFileSystem". The "UniversalHexEditorLib" implements a extremely flexible hex viewer as a .Net control. "UVFSEditor" is the main application project which implements a GUI and glue all libraries together.

    The "uvfsEditorSetup" projects creates an MSI installation package for the end users.
  6. Forum:There is a development forum under the following URL: https://sourceforge.net/projects/uvfseditor/forums/forum/1142984. You need to log on to access this forum. You should communicate with each other over this forum.

Monday, May 10, 2010

Too much to learn for Programming? - Execution environment

There are many popular languages for programming and to learn only a subset of them from scratch is a nightmare. The fact that each language needs some tuning on each platforms makes it more complex. Therefore, programming concepts should be learnt first on an abstract level and adapt those concepts to specific platform when need. A programmer should have fair level of concepts on the following areas to master any programming language as well as leverage knowledge transfer to other programming languages:
  1. Execution environment
  2. Memory Architecture and Allocation/Deallocation
  3. Object Model
  4. Algorithms, Complexity and Data Structure
  5. Language Syntax
  6. Compilation & Linking
  7. Packaging and Deployment
Next few days, I will briefly explain each of these areas and today start with the first one – execution environment.

EXECUTION ENVIRONMENT

Execution environment (EE) is a layer over the hardware on top of which your programs run. It is very often the operating system, but could also be other platforms like virtual machine (JVM or CLR) or even browser (e.g JavaScript) or other applications (e.g. VBA on office application). Your program must have one or more target platforms. Software targeting for one platform may not run on a different platform.

There are various constrains of EE e.g. OS version (32/64-bit) compatibility, requirement of certain run-time libraries etc, some supporting libraries. Some software are OS agnostic, but depends on some other execution environment layer over OS. Java and .Net programs are the best examples of such runtime environment. It is important to understand the inner workings of an execution environment if you want to be expert programmer. How EE understands your file, loads it and what information your executable file must provide so that EE is able to load it.

An example will make it clear. Windows OS considers a file executable if it has some specific extensions (e.g. .exe, .bat, .com etc.). But when the OS starts to load the file, it looks if the file has certain information at predefined location to set up the correct execution environment (DOS, Win32/64, WOW64 ). The .exe executable file is mostly of the portable file (PE) format which is derived from Common Object File Format (COFF). Let's examine the steps in brief that windows OS pass through to load an executable file:

  1. Validate parameters and flags that the shell (or programmatic CreateProcess call) specifies.
  2. Open image file (.exe).
  3. Create a process.
  4. Create initial thread.
  5. Perform other initialization.
  6. Execute initial thread.
  7. Load required DLLs and start execution of initial thread.
  8. Eventually the entry point function (main/wmain/_tmain for console and WinMain for GUI application) is executed.
So this is a fair amount of work for the OS to load and run an executable file.

The process is much different for a so called platform independent programs. During compilation a .Net compatible compiler adds reference to the MSCorEE.dll which is referred as Microsoft .NET Runtime Execution Engine to the generated PE or PE+ (for 64-bit) executable file. The steps for loading and running a .Net image are roughly described below:
  1. 1..6 of the native image load described above.
  2. Loads MSCorEE.dll in the process address space.
  3. The initial threads starts executing calling a method in MSCorEE.dll which initializes CLR, loads EXE assembly and then calls its entry point method.
The process is more straight forward for scripting code. The host application is responsible for providing memory and object model to the script code. The capability of script programs is also more restrictive than native and VM programs. For JavaScript code, the browser has a JavaScript engine which parses, loads, and executes the code.