Wednesday, November 3, 2010

Creating C++ Component / Interface using Mozilla Build System

This is a step-by-step guide to create C++ Component / Interface, build using Mozilla build system, and test our component using extension and web page. I tested this on Ubuntu 10.04.

1. Create a directory with the name of your extension under "/mozilla/extensions/" directory. Use only lowercase letter. Let say we created a directory "krpextension"

2. Create "Makefile.in" in krpextension directory.
#/* Makefile.in under /mozilla/extensions/krpextension directory */
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = krpextension
DIRS = public src
XPI_NAME = krpextension
INSTALL_EXTENSION_ID = krpextension@mycompany.com
XPI_PKGNAME = krpextension
USE_EXTENSION_MANIFEST = 1
DIST_FILES = install.rdf
include $(topsrcdir)/config/rules.mk
#/* End of Makefile */

3. Create two subdirectories in "krpextension" directory namely "public" and "src". Public subdirectory to hold our ".idl" file and src subdirectory to hold component header and implementation files.  Each subdirectory in-turn contains its own makefile. Step 4 contains Makefile for "public" directory and Step 5 contains Makefile for "src" directory.

4. change directory to "public" and create "Makefile.in"
#/* Makefile.in under "/mozilla/extensions/krpextension/public" directory */

DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = krpextension
XPIDL_MODULE = krpextension
XPI_NAME = krpextension
XPIDLSRCS = \
krpIComponent.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

#/* end of Makefile */

5. change directory to "src" and create "Makefile.in"
#/* Makefile.in under "/mozilla/extensions/krpextension/src" directory */
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
IS_COMPONENT = 1
MODULE = krpextension
LIBRARY_NAME =  krpExtension
USE_STATIC_LIBS = 1
XPI_NAME = krpextension
REQUIRES = xpcom \
 string \
 $(NULL)
CPPSRCS = \
 krpComponent.cpp \
 krpExtension.cpp \
 $(NULL)
include $(topsrcdir)/config/rules.mk
EXTRA_DSO_LDOPTS += \
  $(XPCOM_GLUE_LDOPTS) \
  $(NSPR_LIBS) \
  $(NULL)
#/* end of Makefile */

6. Change to "public" sub-directory under "/mozilla/extension/krpextension" and now we will create our own Interface definition file (.idl) in public directory, Let say "krpIComponent.idl", if you used other name than "krpIComponent" then replace each occurring of  krpIComponent with your custom name of Interface. 
/* krpIComponent.idl file in public subdirectory */
#include <stdio.h>
#include "nsISupports.idl"
[scriptable, uuid(1c0856f7-ed61-471e-9dac-442565a5d1d2)]
interface krpIComponent : nsISupports
{
  unsigned long long Add(in unsigned long long num1, in unsigned long long num2); 
  unsigned long long Sub(in unsigned long long num1, in unsigned long long num2);
};
/* End of krpIComponent.idl file */

7. Change to src sub-directory under /mozilla/extension/krpextension, now we will create header and implementation file for our interface.
/* krpComponent.h   header file for our component */
#ifndef __KRPCOMPONENT_H__
#define __KRPCOMPONENT_H__
#include  <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "krpIComponent.h"
#include "nsIObserverService.h"
#include "nsServiceManagerUtils.h"
#define KRPCOMPONENT_CLASSNAME "krpcomponent"
#define KRPCOMPONENT_CID                                \
{ /* 1c0856f7-ed61-471e-9dac-442565a5d1d2 */            \
  0x1C0856F7, 0xED61, 0x471E,                           \
  {0x9D, 0xAC, 0x44, 0x25, 0x65, 0xA5, 0xD1, 0xD2}      \
}
#define KRPCOMPONENT_CONTRACTID "@mycompany.com/krpcomponent;1" 
/* Header file */
class krpComponent: public krpIComponent
{
public:
  NS_DECL_ISUPPORTS
  NS_DECL_KRPICOMPONENT
  krpComponent();
private:
  ~krpComponent();
protected:
};
#endif // __KRPCOMPONENT_H__
/* End of krpComponent.h header file */


/*krpComponent.cpp C++ Implementation file of our component */
#include "krpComponent.h"
/* Implementation file */
NS_IMPL_ISUPPORTS1(krpComponent, krpIComponent)
krpComponent::krpComponent()
{
  /* member initializers and constructor code */
}
krpComponent::~krpComponent()
{
  /* destructor code */
}
/* unsigned long long Add (in unsigned long long num1, in unsigned long long num2); */
NS_IMETHODIMP krpComponent::Add(PRUint64 num1, PRUint64 num2, PRUint64 *_retval NS_OUTPARAM)
{
  *_retval = num1 + num2;
    return NS_OK;
}
/* unsigned long long Sub (in unsigned long long num1, in unsigned long long num2); */
NS_IMETHODIMP krpComponent::Sub(PRUint64 num1, PRUint64 num2, PRUint64 *_retval NS_OUTPARAM)
{
  if(num1 > num2)
    *_retval = num1 - num2;
  else
    *_retval = num2 - num1;
    return NS_OK;
}
/* End of implementation class of our component. */

8. Now we will create module definition file lets say "krpExtension.cpp". If you use other name then replace all occurrences of krpExtension or krpExtension.cpp with your custom name. 
/*krpExtension.cpp Module definition file */
#include "nsXPCOM.h"
#include "nsIGenericFactory.h"
/**
 * Components to be registered
 */
#include "krpComponent.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(krpComponent)
//----------------------------------------------------------
static const nsModuleComponentInfo components[] =
{
{
KRPCOMPONENT_CLASSNAME,
KRPCOMPONENT_CID,
KRPCOMPONENT_CONTRACTID,
krpComponentConstructor
},
};
NS_IMPL_NSGETMODULE(krpExtension, components)
/* end of krpExtension.cpp File */

9. Now to integrate our component into Extension, we will create a custom extension. In "/mozilla/extensions/krpextension" create "install.rdf" file.
/*install.rdf file contents */
  <?xml version="1.0" encoding="UTF-8"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  <Description about="urn:mozilla:install-manifest">
    <em:id>krpextension@mycompany.com</em:id>
    <em:version>0.1</em:version>
    <em:targetApplication>
      <!-- Firefox -->
      <Description>
        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
        <em:minVersion>3.0</em:minVersion>
        <em:maxVersion>3.6.*</em:maxVersion>
      </Description>
    </em:targetApplication>
    <!-- front-end metadata -->
    <em:name>My First Interface Extension</em:name>
    <em:description>Just an FF Interface Example.</em:description>
    <em:creator>kailas</em:creator>
    <em:homepageURL>http://kailaspatil.blogspot.com/</em:homepageURL>
  </Description>
</RDF>
/*install.rdf file ends here */

10. Now create another file "jar.mn" in "/mozilla/extensions/krpextension" directory.
/* jar.mn file contents */
krpextension.jar:
% content krpextension %content/
% locale krpextension en-US %locale/en-US/
% skin krpextension classic/1.0 %skin/
% overlay chrome://browser/content/browser.xul  chrome://krpextension/content/ff-overlay.xul
  content/overlay.js          (chrome/content/overlay.js)
  content/ff-overlay.xul         (chrome/content/ff-overlay.xul)
  content/ff-overlay.js (chrome/content/ff-overlay.js)
  content/about.xul         (chrome/content/about.xul)
  locale/en-US/overlay.dtd         (chrome/locale/en-US/overlay.dtd)
  locale/en-US/about.dtd         (chrome/locale/en-US/overlay.dtd)
  locale/en-US/overlay.properties (chrome/locale/en-US/overlay.properties)
  skin/overlay.css         (chrome/skin/overlay.css)
/* end of jar.mn file */
The files in jar.mn reflects the XUL/JavaScript files in your custom Extension.
Use Mozilla addon to build an empty extension for Firefox, with name krpextension. Copy its "chrome" directory including subdirectories "content, locale, and skin" in chrome directory into our extension directory, i.e "/mozilla/extensions/krpextension". Note that the paths in parentheses point to actual files.

11. Now run "make" command in "mozilla/$(OBJ_DIR)$" or "make -f client.mk build" command in "/mozilla" directory. If you are using make -f client.mk build command then make sure that you setup ".mozconfig" file.  Pls read an article https://developer.mozilla.org/en/build_documentation to build firefox and prerequisites required to build Firefox. 

12. Our component should be build successfully, and in "Tools->Addons->Extension" Tab you should see our custom Extension.

13. To test our component with Extension and Webpage.  First we will test it with Extension. Open overlay.js file in our extension folder "/mozilla/extensions/krpextension/chrome/content/overlay.js".  In OnLoad: function, add following lines of code to test our component. 
/*********************/
   var instance = Components.classes["@mycompany.com/krpcomponent;1"].getService();
    var obj =instance.QueryInterface(Components.interfaces.krpIComponent);
    var result = obj.Sub(10, 5);
    alert("Sub(10-5) = " + result);
/******************/
Each time firefox will start, our custom extension will start, and during initialization of our extension it will call our component method (i.e Sub(10,5) which will return result of Subtraction operation and its get displayed to user using alert box. 

Now we test our component using a Web page. Create a HTML file on local system, and use following script to test our component. It should display the correct result of Addition operation.
/************************/
<script>
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const cid = "@mydomain.com/XPCOMSample/krpComponent;1";
var obj = Components.classes[cid].createInstance();
var obj1 = obj.QueryInterface(Components.interfaces.KFFComponent);


               var res = obj1.Add(10, 5);
alert('Performing 10 + 5  =  ' +  res );

} catch (err) {
alert(err);
}
</script>
/************************************/

Tuesday, November 2, 2010

Creating C++ Component / Interface of Firefox Using Gecko-SDK

This is step-by-step guide to create, build, register and use a XPCOM component/Interface on Linux (Ubuntu)

A. Creating A Component
Step 1: Download Gecko SDK (gecko-sdk-i686-pc-linux-gnu-X.X.X.X) and Extract it to local directory  "gecko-sdk".
Step 2: Use a utility "uuidgen" to generate UUID for our main Interface.
Step 3: Create an Interface defination file "KFFComponent.idl", use following template, simply replace uuid(1c0856f7-ed61-471e-9dac-442565a5d1d2) with your unique uuid(your_UUID) field.


#include "nsISupports.idl"
[scriptable, uuid(1c0856f7-ed61-471e-9dac-442565a5d1d2)]
interface KFFComponent : nsISupports
{
  unsigned long long Add(in unsigned long long num1, in unsigned long long num2);
  unsigned long long Sub(in unsigned long long num1, in unsigned long long num2);
};

Step 4: Open command prompt and go to "gecko-sdk/bin" and run following command:
$ ./xpidl  -m  header  -I_DIR_    KFFComponent.idl

Replace "_DIR_" with the full path to the "gecko-sdk/idl". Above command will create "KFFComponent.h" header file.

Step 5: Now to create typelib file, execute following command
$ ./xpidl  -m  typelib  -I_DIR_   KFFComponent.idl
Replace "_DIR_" with the full path to the "gecko-sdk/idl". Above command will create  "KFFComponent.xpt" typelib file

Step 6: Interface header file contains the template for building our component header file as well as C++ Implementation file.

Step 7: Create our own component Header file "krpComponent.h", use following contents:

#ifndef _KRP_COMPONENT_H_
#define _KRP_COMPONENT_H_
#include "KFFComponent.h"
#define KRP_COMPONENT_CONTRACTID "@mydomain.com/XPCOMSample/krpComponent;1"
#define KRP_COMPONENT_CLASSNAME "First XPCOM Sample Interface"
#define KRP_COMPONENT_CID {0x462EF8EF, 0x9A05, 0x49DE, {0x97, 0xAC, 0x82, 0x2A, 0x6C, 0x46, 0xD2, 0xDC } }


/* KRP_COMPONENT_CID = GUID (462EF8EF-9A05-49DE-97AC-822A6C46D2DC)
    Note: Replace GUID with your own GUID field
*/
/* Header file */
class krpComponent : public KFFComponent
{
public:
  NS_DECL_ISUPPORTS
  NS_DECL_KFFCOMPONENT
  krpComponent();
private:
  ~krpComponent();
protected:
  /* additional members */
};
#endif  /* end of _KRP_COMPONENT_H_ */

Step 8: Create our won C++ Implementation file for the Componenet "krpComponent.cpp".

#include "krpComponent.h"
/* Implementation file */
NS_IMPL_ISUPPORTS1(krpComponent, KFFComponent)
krpComponent::krpComponent()
{
  /* member initializers and constructor code */
}
krpComponent::~krpComponent()
{
  /* destructor code */
}
/* unsigned long long Add (in unsigned long long num1, in unsigned long long num2); */
NS_IMETHODIMP krpComponent::Add(PRUint64 num1, PRUint64 num2, PRUint64 *_retval)
{
  *_retval = num1 + num2;
  return NS_OK;
}
/* unsigned long long Sub (in unsigned long long num1, in unsigned long long num2); */
NS_IMETHODIMP krpComponent::Sub(PRUint64 num1, PRUint64 num2, PRUint64 *_retval)
{
  *_retval = num1 - num2;
  return NS_OK;
}
/* End of implementation class template. */

Step 9: Create our own Module definition file "krpComponentModule.cpp".
// This is necessary file to include Mozill Generic definations
#include "nsIGenericFactory.h" 
//My Component Header File 
#include "krpComponent.h" 
NS_GENERIC_FACTORY_CONSTRUCTOR(krpComponent)
static nsModuleComponentInfo components[] =
{
    {
       KRP_COMPONENT_CLASSNAME, 
       KRP_COMPONENT_CID,
       KRP_COMPONENT_CONTRACTID,
       krpComponentConstructor,
    }
};
NS_IMPL_NSGETMODULE("krpComponentsModule", components) 

B: Building our Component / Interface
Step 1: Create Makefile or use your own template
CXX   = c++
CPPFLAGS +=     -fno-rtti              \
-fno-exceptions        \
-shared  
# Change this to point at your Gecko SDK directory. 
GECKO_SDK_PATH = /home/username/cprogs/gecko-sdk
# GCC only define which allows us to not have to #include mozilla-config 
# in every .cpp file.  If your not using GCC remove this line and add 
# #include "mozilla-config.h" to each of your .cpp files. 
GECKO_CONFIG_INCLUDE = -include mozilla-config.h 
GECKO_DEFINES  = -DXPCOM_GLUE
GECKO_INCLUDES = -I $(GECKO_SDK_PATH)/include 
GECKO_LDFLAGS =  -L $(GECKO_SDK_PATH)/lib -lxpcomglue \
                 -lnspr4      \
                 -lplds4      

FILES = krpComponent.cpp krpComponentModule.cpp 
TARGET = krpComponent.so
build: 
$(CXX) -Wall -Os -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(GECKO_INCLUDES) $(GECKO_LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(FILES)
chmod +x $(TARGET)
strip $(TARGET)
clean: 
rm $(TARGET)

Step 2: Run "make" command, and it "krpComponent.so" file will be created.

C: Registering the Component
Step 1: Copy krpComponent.so and KFFComponent.xpt file to "~/.mozilla/component" directory
Step 2: use command "regxpcom" to register component
$ ./regxpcom  -x  _DIR_PATH_OF_COMPONENT_
 Replace _DIR_PATH_OF_COMPONENT with the path of component (krpComponent.so)
Step 3: Restart Mozilla.

D: Testing Component
You can either use Extension or HTML page to test our new Firefox C++ Component.
HTML Code of "TestComponent.html" page is as follows



<script>
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const cid = "@mydomain.com/XPCOMSample/krpComponent;1";
var obj = Components.classes[cid].createInstance();
var obj1 = obj.QueryInterface(Components.interfaces.KFFComponent);

               var res = obj1.Sub(10, 5);
alert('Performing 10 - 5  =  ' +  res );

} catch (err) {
alert(err);
}

</script>


Thursday, October 21, 2010

Narcissus/Zaphod JavaScript Research VM for Firefox

Narcissus is a JavaScript virtual machine written in JavaScript. Firefox extension Zaphod allows using Narcissus as the default JavaScript engine in Firefox.
Developers can write scripts specifically for the Narcissus engine (by specifying script tags with a type of "application/narcissus"), or they can replace SpiderMonkey with Narcissus as the default engine.

References:
More info about Zaphod 
Example Pages

Saturday, October 9, 2010

How to use Huawei E1550 USB Modem On Ubuntu 10.04

I am using StarHub MaxMobile SurfLite plan. A USB modem device that comes with the plan is supported on Mac and Windows OS bydefault. 
I use Ubuntu and like to work on ubuntu than windows. It was very troublesome for me to change to windows whenever I needed Internet access. I was fed up with doing back and forth in windows and ubuntu OS. And desperately wanted to use my USB stick on ubuntu. 
My previous USB stick was ZTE MF628. And I don't know how to use it on ubuntu. If anyone knows it, I will appreciate if you post how to make it work on ubuntu.
When I renewed my contract with StarHub, I got new USB stick Huawei E1550 that worked on ubuntu without any hurdles. 

Step by Step guide to use Huawei E1550 USB stick on Ubuntu:
1. Plug in Huawei E1550 USB modem to USB port. You can notice its icon is loaded on Desktop. 
2.  Type following command at command prompt:
         $ gksu gedit /etc/udev/rules.d/15-huawei-e1550.rules
3. It will open gedit. Type following lines in it and then save it and close the file.
      SUBSYSTEM=="usb",
     SYSFS{idProduct}=="1446",
     SYSFS{idVendor}=="12d1",
     RUN+="/lib/udev/modem-modeswitch --vendor 0x12d1 --product 0x1446 --type option-zerocd" 

4. Restart the computer. After restart click on "Network connection" icon in the top panel. You will see new menu item under "Mobile Broadband" category.
5. Click on that new entry. It will open a New Mobile Broadband Connections dialog. Click Forward to continue.
6.  Select you country (Singapore in my case) and click Forward. Then select service provider from the list and click forward. Then choose your Billing plan and click Forward. Then finally Click on Apply to save setting. 

It will connect you to the Internet. Enjoy, hurdle free Internet connectivity on ubuntu using USB Modem (Huawei E1550).

Wednesday, August 18, 2010

Mac OS theme on Ubuntu 10.04 (Lucid)

Installing Mac OS theme on Ubuntu 10.04 (Lucid) is easy and straightforward. 

Step 1:  Install Gstyle (Gstyle is a full Gnome Theme Manager)
             sudo add-apt-repository ppa:s-lagui/ppa
             sudo apt-get update
             sudo apt-get install gstyle
Step 2:  Once it is installed successfully. Launch Gstyle application (System -> Preferences - > Gstyle).
Step 3:  Click on Download button and then Click on Refresh button.  Select Mac4Lin theme from the list.
Step 4:  Then in each category option in the left panel of Gstyle, select Mac4Lin. I choose Mac4Lin Aqua.
Step 5A:  Now to Configure Global Menu (Top panel bar). Perform following steps:
             sudo add-apt-repository ppa:globalmenu-team
             sudo apt-get update && sudo apt-get install gnome-globalmenu
             killall gnome-panel
Step 5B:  Once done, remove all stuffs from top left panel (Right click on the panel and select “Remove from Panel”).  Right click on the top panel and select Add to Panel. Select Main Menu, follow by the Global Menu Panel Applet. Close the window. Now move the two items (right click and select Move) to the left hand corner and make sure they are side by side.

Step 6A: Now to configure Dock (Bottom panel bar). Perform following Steps:
            sudo apt-get install cairo-dock
            There are lot of dock application, but I found this one is easy to use. 
Step 6B: Before you launch the Cairo dock application, remove the bottom panel (right click at the bottom panel and select Delete This Panel).  Cairo dock needs a compositing manager to work, so make sure that your system support Compiz before launching the app. Launch Cairo dock (Menu -> Accessories -> Cairo Dock). Make sure to set it to launch everytime you startup your computer.

             Only if your system does not support Compiz: You can activate the in-built metacity compositing manager with the command:
            gconftool-2 --type boolean --set /apps/metacity/general/compositing_manager TRUE 



To change the logo in the panel bar with apple logo:
1. Download apple logo from google.
2.  Then go to /home/urprofilename/.icons/Mac4Lin_Icons_v1.0/scalable/places folder.  Check the resolution of distributor logo.png file. It may be 78 * 96. Now rescale the image you downloaded into 78 *96 or 96*96 size.
3. Then replace distributor-logo.pnggnome-main-menu.pngmain-menu.png, and start-here.png with the apple logo file.
4. Open the terminal window and type  killall gnome-panel to restart the gnome-panel. Now you should see your new icon. 

Monday, August 16, 2010

How to create Patch on Liunx?

In this post I will explain how to create a patch file and how to apply patch.
I only know the basic stuff. Therefore, if you want to know more then please use command man diff at command prompt to explore other possible options.

How to Create a Patch File?
Patch file is a readable text file which is created using diff command.
To create a patch of entire source folder including its sub directories, do as follows:

 $ diff -rauB  old_dir   new_dir   >  patchfile_name

  options -rauB mean:
  r  -> recursive (multiple levels dir)
  a ->  treat all files as text
  u -> Output NUM (default 3) lines of unified context
  B -> B is to ignore Blank Lines

Blank lines are usually useless in the patch file.  Therefore I used B option, however you are free to tune your patch file according to your choice.
old_dir is the original source code directory,  new_dir is the new version of source code and patchfile_name is the name of the patch file.  You can give any name to your patch file.

How to Apply Patch to your Source Code?
Suppose you have got a patch file and you want to apply that patch to the version of your source code.
It is not necessary but I recommend to do a dry-run test first.

To do a dry run:
$ patch --dry-run -p1 -i patchfile_name

-i : Read the patch from patchfile.
-pnum : Strip  the  smallest prefix containing num leading slashes from each
          file name found in the patch file.  A sequence of one or more  adjacent
          slashes  is counted as a single slash.  This controls how file
          names found in the patch file are treated, in  case  you  keep  your
          files  in  a  different  directory  than the person who sent out the
          patch.

If there is no failure then you can apply patch to your source code:
patch -p1 -i patchfile_name

I hope this post will help you to generate patch from your source code and apply patch to your source code.

Saturday, August 14, 2010

How to Build Lobo browser on Ubuntu 10.04

Prerequisites:
 1. Eclipse SDK for Java.
 2. IzPack (http://izpack.org/). Download cross platform installation jar file.

Steps:
1. Create a sudirectory "XAMJ_Project" in /opt folder.  In linux, /opt belongs to root user so you may need to change the owner of /opt folder, so that write operation will be allowed.

2. Install IzPack in "/opt/IzPack". for installation of IzPack at command prompt run the command: java -jar IzPack-install-x.x.x.jar.

3. Open Eclipse and change workspace path to "/opt/XAMJ_Project".

4. Now choose the Project Explorer (Window->Show View -> Project Explorer).

5. Right click in project explorer and select New -> Project -> CVS  - > Project from CVS.
6. When prompted for server details fill out the server details as given in step 3 of Lobo Eclipse build instruction page.   
Host: xamj.cvs.sourceforge.net
Repository path: /cvsroot/xamj
User: anonymous
Password: [leave blank]
Connection type: pserver

  7.  Next, select "Use an existing module" option.

  8.  Then select 8 modules from the XAMJ_Project folder for basic web browser build.  You can choose all modules.  eight modules I choose were as follows:    

  • Common
  • cssparser
  • HTML_Renderer
  • Platform_Public_API
  • Platform_Core
  • Primary_Extension
  • XAMJ_Build
  • IzPack_RegistryPanel
 9. Next select the version of repository and check out.

 10.  Now right click on "IzPack_RegistryPanel" select "Properties" . Then select "Java Build Path".  select the "Libraries" tab. 

  11. If you see cross for some libraries then its bcoz of the wrong path. As we have already installed IzPack, search for files in /opt/Izpack/lib or /opt/IzPack/bin/Panel, and correct the paths of library files. 

  12. Now configure "Run Configuration" for your Java Application project. Please see the README.txt file in Platform_Core for instructions, and set VM Variable and Program Variable in the Arguments tab according to the README.txt file.  Also set the  Project name and Main class name in the Main tab.  The name of the main class is org.lobobrowser.main.EntryPoint .

13. Now apply your setting and run the project. It should work. If it doesn't then right click on IzPack_Registry Panel and add libraies: xpp3-1.1.3.4.M.jar, and cobra-no-commons.jar.zip. You can search and download these libraries if they are not present.

Friday, July 30, 2010

What is Really Simple Syndication( RSS)?

Really Simple Syndication (RSS) is a way to subscribe to a source of information, such as a Web site.  
RSS works by having the website author maintain a list of notifications on their website in a standard way. This list of notifications is called an "RSS Feed". Many Blog services automatically create RSS Feeds. For Websites, RSS Feeds can be created manually or with software(such as Software Garden, Inc.'s ListGarden)
The RSS Feed that is created is an XML file that lives on a Webserver. Once RSS feed is ready on web server, RSS Feeds waits for an RSS Reader to subscribe to them. The RSS Feed Reader reads the RSS Feed file and displays it. That is, the RSS Reader displays only new items from the RSS Feed. An RSS Feed Reader reads the RSS feed file, finds what is new, converts it to HTML, and displays it.

Monday, May 24, 2010

Spider-monkey Internals



SpiderMonkey Internals 
The JavaScript engine compiles and executes scripts containing JavaScript statements and functions. The engine handles memory allocation for the objects needed to execute scripts, and it cleans up—garbage collects—objects it no longer needs.

The word JavaScript may bring to mind features such as event handlers (like onclick), DOMobjects, window.open, and XMLHttpRequest. But in Mozilla, all of these features are actually provided by other components, not the SpiderMonkey engine itself. SpiderMonkey provides a few core JavaScript data types—numbers, strings, Arrays, Objects, and so on—and a few methods, such as Array.push. It also makes it easy for each application to expose some of its own objects and functions to JavaScript code. Browsers expose DOM objects. 


Spidermonkey includes/implemented JavaScript functions such as eval(), charAt(), escape(), unescape(), encodeURI(), decodeURI(), etc. 


JavaScript Event Handlers (like onClick) are implemented in  the content/event/ module in Firefox. The file use to handle events is content/event/src/nsEventStateManager.cpp.


Window.open is implemented in the dom/ module. The file  which implemented native function for window.open is  dom/src/base/nsGlobalWindow::OpenJS() in Firefox. window object is not standardized in DOM specifications, therefore, it has vendor specific implementation of it. 


XMLHttpRequest() is implemented in the content/base/ module in Firefox. The file is content/base/src/nsXMLHttpRequest.cpp implementing XHR request.  

C/C++ code accesses SpiderMonkey via the JSAPI, by including the header "jsapi.h". The JSAPI provides functions for setting up the JavaScript runtime, compiling and executing scripts, creating and examining JavaScript data structures, handling errors, enabling security checks, and debugging scripts.

In order to run any JavaScript code in SpiderMonkey, an application must have three key elements: a JSRuntime, a JSContext, and a global object.

Runtimes. A JSRuntime, or runtime, is the space in which the JavaScript variables, objects, scripts, and contexts used by your application are allocated. Every JSContext and every object in an application lives within a JSRuntime. They cannot travel to other runtimes or be shared across runtimes. Most applications only need one runtime.

A program typically has only one JSRuntime, even if it has many threads.

Contexts. A JSContext, or context, is like a little machine that can do many things involving JavaScript code and objects. It can compile and execute scripts, get and set object properties, call JavaScript functions, convert JavaScript data from one type to another, create objects, and so on. Almost all JSAPI functions require a JSContext * as the first argument.

Global objects. Lastly, the global object contains all the classes, functions, and variables that are available for JavaScript code to use. Whenever JavaScript code does something like window.open("http://www.mozilla.org/"), it is accessing a global property, in this case window. JSAPI applications have full control over what global properties scripts can see. The application starts out by creating an object and populating it with the standard JavaScript classes, like Array and Object. Then it adds whatever custom classes, functions, and variables (like window) the application wants to provide; see Custom objects below. Each time the application runs a JS script (using, for example, JS_EvaluateScript), it provides the global object for that script to use. As the script runs, it can create global functions and variables of its own. All of these functions, classes, and variables are stored as properties of the global object.

References:




Wednesday, May 5, 2010

V8 Build Error

Hi,
I downloaded v8 and followed the build instruction given at http://code.google.com/apis/v8/build.html#build .

However, When I executed the command "scons" (without quotes) it shown following errors on my machine.


cc1plus: error: dereferencing pointer 'dest' does break strict-aliasing rules
cc1plus: error: dereferencing pointer 'dest' does break strict-aliasing rules
cc1plus: error: dereferencing pointer 'dest' does break strict-aliasing rules
src/api.cc:3495: note: initialized from here
scons: *** [obj/release/api.o] Error 1
scons: building terminated because of errors.

This is bcoz warnings are considered as errors by the compiler.
To solve this problem,
open "SConstruct" file in the source directory of v8 and look for "V8_EXTRA_FLAGS"
Then comment the line (use # to comment line) '-Werror' in
gcc:{ 
    all:{ 
       WARNINGFLAGS: [
                                    
                                      ]
  },

After doing this, I was able to build it. However, I was not able to embed v8 in C++ application.
The reason was, I was running ubuntu x64 bit OS and V8 build is of 32-bit.

I ran following command to build 64-bit libaray of V8.
$ scons mode=debug arch=x64

Where mode=debug to build DEBUG version instead of by default release version. And arch=x64 to build 64-bit version instead of by-default 32-bit version.