Download The complete source code for this tutorial can be downloaded from here. You can choose a different Mozilla release if you like. Extract the SDK to a local directory. Create a GUID for your main interface. On Windows you can use the guidgen utility. On Linux you can use the uuidgen utility.

Author:Fenrikazahn Kigadal
Country:Republic of Macedonia
Language:English (Spanish)
Published (Last):4 January 2017
PDF File Size:12.9 Mb
ePub File Size:20.1 Mb
Price:Free* [*Free Regsitration Required]

But what about oneMorePtr? In this instance, it is never released; if you remember, an object cannot be released from memory until our refcount is at zero. The refcount is out of sync, oneMorePtr is never decremented before the return, and the object is thus left dangling in memory.

With the refcount off, the object leaks. The correct code is shown below: if! After all references are properly released, delete is called and the object is freed from memory. Example shows a typical use of nsCOMPtr.

Earlier in this chapter, the section Section 8. A few more steps are involved, but as you will see, they are generally similar to the processes described in the JavaScript component section, facilitated to some extent by the available tools and templates discussed previously.

It provides the class definition, macros for using the interface, and a template for the class implementation, which contains stubbed-out declaratory code that you can paste into your implementation file to quickly get started. For nsISimple, these members are the yourName attribute and the write and change methods.

You can use those stubs as a guide to implement the component. In a text editor, create a new file called nsSimple. Next, it defines the contract ID for this implementation class. Now the example makes the class declaration of the implementation, called nsSimpleImpl, which inherits from nsISimple, defining the class constructor and virtual destructor. It expands to the used interface method declarations. This variable is used to hold the value of the interface attribute yourName, just as it did earlier in the JavaScript class implementation.

Once you have the header file, you are ready to start the implementation source file. With a text editor, create a new file called nsSimple. Then test whether the member variable mName holds a value. If it does, allocate the necessary memory to accommodate the size of the copy.


Using XPCOM Components

In fact, virtually all of the functionality that you associate with a browser - navigation, window management, managing cookies, bookmarks, security, searching, rendering, and other features - is defined in XPCOM components and accessed by means of those component interfaces. Cookie Manager Cookie management is one of the many sets of functionality that is made available to the browser in the form of an XPCOM component and that can be reused by developers who want similar functionality in their applications. Whenever a user accesses the Cookie Manager dialog to view, organize, or remove cookies that have been stored on the system, they are using the CookieManager component behind the scenes. The Cookie Manager Dialog shows user interface [cookie-manager-ui] that is presented to the user in Mozilla for working with the CookieManager component.


Creating XPCOM components




Related Articles