Now it’s time to look at the WebLock component as another example of XPCOM components (since you’ll be creating it shortly). This is a book about Gecko, and about creating XPCOM components for Gecko- based applications. Though the emphasis is on the practical steps you take to. About. This is a step-by-step tutorial on creating, building and registering an XPCOM component on Linux and MS Windows.
|Published (Last):||11 February 2006|
|PDF File Size:||7.25 Mb|
|ePub File Size:||16.55 Mb|
|Price:||Free* [*Free Regsitration Required]|
Creating a C++ XPCOM component
You can plug your custom functions into the framework and connect them with other components. In this article, all the instructions, environment variables, and command line will be in a Linux operating system.
XPCOM provides browser application interfaces you can use to access low-level operations, such as system hardware diagnostics, massive file operations, and system health real-time monitoring. Cerating Figure 1, sample.
First, you have to define the interfaces you want to expose to the browser or the abilities you want to provide to the Web application. Interfaces are written in an. Listing 1 shows a sample interface definition file. In Listing 1, the name is sampleand three common function prototypes are shown. On a Linux system, you can easily get this ID by using the genuuid command in the shell: You can install gecko-sdk with the default option.
The directory structure should look very similar to Listing 2.
To translate the interfaces defined in. The example uses it twice to generate an. Typically, you wouldn’t modify anything in this header file.
However, to extend and inherit from the base class, you can add more private methods and variables for extension. Listing 3 shows an example of generating the command on Linux. If you define the interface in the sample. As mentioned, you don’t modify the two generated files: You inherit the interface from them. Sometimes, you might not complete all the interface at the beginning of the development phase. You’ll want to keep the contents and structure of the base class as simple as possible.
In the extend file, you can add more complicated methods and functions.
Listing 4 shows an example of xppcom to write your extend class. For the browser to benefit from the functions provide by an XPCOM component, the component must first be registered to the browser.
There is a form you must prepare for your component. The three macros described above must be put in the form. The browser will be aware of your components upon start-up, and register them in the component list. Listing 5 shows a registration form for the sample. It is highly recommended that you put the implementation of functions and service for your XPCOM in an individual project file.
You don’t need to modify these three files unless there’s a need to modify the interfaces of your component. Listing 6 shows a sample. The sample above simply returns “hello world” to the browser application. You can add more realistic logic or functions to support the application you want to develop.
If clmponents follow the steps described above, and use make to build the sample componnents makefile, you will have a sample. The next section explores a method to test these binaries. The example uses XUL. If you try HTML, you can make various improvements.
You can use the samples provided for a quick start to developing a component for Firefox.
Sign in or register to add and subscribe to comments. Lewei Ji Published on October 27, Comments Sign in or register to add and subscribe to comments. Subscribe me to comment notifications.