mozilla

Revision 639335 of Preface

  • Revision slug: Creating_XPCOM_Components/Preface
  • Revision title: Preface
  • Revision id: 639335
  • Created:
  • Creator: teoli
  • Is current revision? Yes
  • Comment
Tags: 

Revision Content

이 문서는 Gecko 엔진과 이를 기반으로 하는 어플리케이션들을 위한 XPCOM 컴포넌트에 대한 설명을 담고 있습니다. 여기서 강조하고 있는 것은 Gecko 에서 사용 가능한 컴포넌트에 당신의 C++ 코드를 삽입하는

Though the emphasis is on the practical steps you take to make your C++ code into a component that can be used in Gecko, we hope that these steps will also give us an occasion to discuss all of the tools, techniques, and technologies that make up XPCOM. Accordingly, the book is arranged so that you can follow along and create your own components or learn about different XPCOM topics individually, as in a reference work. For example, the introduction includes a discussion of components and what they are, and the first chapter - in which you compile the basic code and register it with Mozilla - prompts a discussion of the relationship between components and modules, of XPCOM interfaces, and of the registration process in general.

The top of each chapter provides a list of the major topics covered. Sidebar sections are included to highlight technical details. By the end of the book, if we've done our job, you will have learned how to build a component and you will know something about the framework for these components in Gecko, which is XPCOM.

Who Should Read This Book

Creating XPCOM Components is meant for C++ developers. Though you can create XPCOM components in JavaScript and other languages, and though you might be able to follow along as a C programmer, the component implementation code is written in C++, and much of the discussion of how to make your code into an XPCOM component starts from C++. You don't need to be a C++ expert, however. Although basic ideas such as inheritance and encapsulation should be familar to you, wherever possible they are explained in the book as they are used. Also many of the examples are in JavaScript, which is used in Mozilla to access XPCOM components as scriptable objects, and so familiarity with that language is useful as well.

XPCOM stands for the Cross Platform Component Object Model. As this name implies, XPCOM is similar to Microsoft COM. If you have any experience with this technology, much of it can be applied to XPCOM. However, this book does not assume any prior knowledge of COM - all of the basic COM ideas will be introduced.

This book provides a tutorial about building an XPCOM component that controls browsing behavior. Although, XPCOM can be used in many environments which are unrelated to web browsing, XPCOM's main client is Gecko, an open source, standards compliant, embeddable web browser, where it's easiest and most practical to illustrate XPCOM's functionality. A full description of the component in this tutorial can be found in the What We'll Be Working On section of the tutorial.

Organization of the Tutorial

The following list provides an overview of the steps that we will take to build an XPCOM component called WebLock, which provides site blocking functionality to Gecko-based browsers. Each one of these steps has its own chapter, in which a number of topics associated with the step are discussed.

  • Create the generic module code for the component.
  • Use C++ macros, special string classes and smart pointers to optimize your code.
  • Define the functionality for the component; create an XPIDL interface for that functionality; create the implementation code specific to the custom WebLock component interface.
  • Finish implementing the WebLock component: nsIContentPolicy, file I/O, locking, etc.
  • Creating the user interface for the WebLock component.
  • Packaging WebLock for distribution and installation.

Following Along with the Examples

There are a couple of different ways to get XPCOM onto your machine so you can begin to create components. If you already have a Mozilla build or the source from Mozilla 1.2 or later, then you can use the XPCOM framework available there. If you don't already have the Mozilla source, then an even easier way to get and use XPCOM is to download the Gecko SDK, which is a collection of libraries and tools that features the XPCOM component framework.

Whether you compile your code in the Mozilla source tree or use the Gecko SDK, you can build your own components which leverage components that already exist in Gecko. The WebLock component we describe in this tutorial is a practical (and, we hope, genuinely useful) addition to the browser. In order to build it, your Gecko SDK or Mozilla source tree needs to be version 1.2 or later (XPCOM interfaces were not fully frozen in prior releases).

This book assumes you are using the SDK rather than compiling in a Mozilla source tree, though the difference between these two approaches is minimal. Details about downloading the SDK, building, and getting programmatic access to Gecko components are provided in the appendix to this book, Setting up the Gecko SDK.

Conventions

The formatting conventions listed below are used to designate specific types of information in the book and make things easier to scan. The goal is to use as few formats as possible, but to distinguish the various different types of information clearly.

Format Description
bold component names appear in bold in the text
monospace code listings, interface names and members of interfaces (e.g., createInstance()) appear in monospaced font. Lines of code are placed in separate boxes. Additionally, filenames and directories appear in monospaced font.
italic variables appear in italic. Important terms and new concepts are also italicized the first time they appear in the text. Those terms are either explained immediately after they are cited, or else the reader is referred to a section in the book where they are described in detail.
link References to other sections and to figures and tables are links to those sections.

Acknowledgements

Thanks to Peter Lubczynski, John Gaunt, Ellen Evans, and Alec Flett for technical reviews. A special thanks goes to Darin Fisher for his very acute observations, close reading, and attention to detail.

{{ CXCLicenseBlock() }}

Revision Source

<p>이 문서는 Gecko 엔진과 이를 기반으로 하는 어플리케이션들을 위한 XPCOM 컴포넌트에 대한 설명을 담고 있습니다. 여기서 강조하고 있는 것은 Gecko 에서 사용 가능한 컴포넌트에 당신의 C++ 코드를 삽입하는</p>
<p>Though the emphasis is on the practical steps you take to make your C++ code into a component that can be used in Gecko, we hope that these steps will also give us an occasion to discuss all of the tools, techniques, and technologies that make up XPCOM. Accordingly, the book is arranged so that you can follow along and create your own components or learn about different XPCOM topics individually, as in a reference work. For example, the introduction includes a discussion of components and what they are, and the first chapter - in which you compile the basic code and register it with Mozilla - prompts a discussion of the relationship between components and modules, of XPCOM interfaces, and of the registration process in general.</p>
<p>The top of each chapter provides a list of the major topics covered. Sidebar sections are included to highlight technical details. By the end of the book, if we've done our job, you will have learned how to build a component and you will know something about the framework for these components in Gecko, which is XPCOM.</p>
<h3 id="Who_Should_Read_This_Book" name="Who_Should_Read_This_Book">Who Should Read This Book</h3>
<p><a href="ko/Creating_XPCOM_Components">Creating XPCOM Components</a> is meant for C++ developers. Though you can create XPCOM components in <a href="ko/JavaScript">JavaScript</a> and other languages, and though you might be able to follow along as a <a href="ko/C">C</a> programmer, the component implementation code is written in C++, and much of the discussion of how to make your code
 <i>
  into</i>
 an XPCOM component starts from C++. You don't need to be a C++ expert, however. Although basic ideas such as inheritance and encapsulation should be familar to you, wherever possible they are explained in the book as they are used. Also many of the examples are in JavaScript, which is used in Mozilla to access XPCOM components as scriptable objects, and so familiarity with that language is useful as well.</p>
<p>XPCOM stands for the Cross Platform Component Object Model. As this name implies, XPCOM is similar to Microsoft COM. If you have any experience with this technology, much of it can be applied to XPCOM. However, this book does not assume any prior knowledge of COM - all of the basic COM ideas will be introduced.</p>
<p>This book provides a tutorial about building an XPCOM component that controls browsing behavior. Although, XPCOM can be used in many environments which are unrelated to web browsing, XPCOM's main client is Gecko, an open source, standards compliant, embeddable web browser, where it's easiest and most practical to illustrate XPCOM's functionality. A full description of the component in this tutorial can be found in the <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#What_We.27ll_Be_Working_On">What We'll Be Working On</a> section of the tutorial.</p>
<h3 id="Organization_of_the_Tutorial" name="Organization_of_the_Tutorial">Organization of the Tutorial</h3>
<p>The following list provides an overview of the steps that we will take to build an XPCOM component called <b>WebLock</b>, which provides site blocking functionality to Gecko-based browsers. Each one of these steps has its own chapter, in which a number of topics associated with the step are discussed.</p>
<ul>
 <li>Create the generic module code for the component.</li>
 <li>Use C++ macros, special string classes and smart pointers to optimize your code.</li>
 <li>Define the functionality for the component; create an <a href="ko/XPIDL">XPIDL</a> interface for that functionality; create the implementation code specific to the custom <b>WebLock</b> component interface.</li>
 <li>Finish implementing the <b>WebLock</b> component: <code>nsIContentPolicy</code>, file I/O, locking, etc.</li>
 <li>Creating the user interface for the WebLock component.</li>
 <li>Packaging <b>WebLock</b> for distribution and installation.</li>
</ul>
<h3 id="Following_Along_with_the_Examples" name="Following_Along_with_the_Examples">Following Along with the Examples</h3>
<p>There are a couple of different ways to get XPCOM onto your machine so you can begin to create components. If you already have a Mozilla build or the source from Mozilla 1.2 or later, then you can use the XPCOM framework available there. If you don't already have the Mozilla source, then an even easier way to get and use XPCOM is to download the Gecko SDK, which is a collection of libraries and tools that features the XPCOM component framework.</p>
<p>Whether you compile your code in the Mozilla source tree or use the Gecko SDK, you can build your own components which leverage components that already exist in Gecko. The <b>WebLock</b> component we describe in this tutorial is a practical (and, we hope, genuinely useful) addition to the browser. In order to build it, your Gecko SDK or Mozilla source tree needs to be version 1.2 or later (XPCOM interfaces were not fully frozen in prior releases).</p>
<p>This book assumes you are using the SDK rather than compiling in a Mozilla source tree, though the difference between these two approaches is minimal. Details about downloading the SDK, building, and getting programmatic access to Gecko components are provided in the appendix to this book, <a href="ko/Creating_XPCOM_Components/Setting_up_the_Gecko_SDK">Setting up the Gecko SDK</a>.</p>
<h3 id="Conventions" name="Conventions">Conventions</h3>
<p>The formatting conventions listed below are used to designate specific types of information in the book and make things easier to scan. The goal is to use as few formats as possible, but to distinguish the various different types of information clearly.</p>
<table class="standard-table">
 <tbody>
  <tr>
   <td class="header">Format</td>
   <td class="header">Description</td>
  </tr>
  <tr>
   <td><b>bold</b></td>
   <td><b>component names</b> appear in bold in the text</td>
  </tr>
  <tr>
   <td><code>monospace</code></td>
   <td><code>code listings</code>, <code>interface names</code> and <code>members</code> of interfaces (e.g., <code>createInstance()</code>) appear in monospaced font. Lines of code are placed in separate boxes. Additionally, <code>filenames</code> and <code>directories</code> appear in monospaced font.</td>
  </tr>
  <tr>
   <td>
    <i>
     italic</i>
   </td>
   <td>
    <i>
     variables</i>
    appear in italic. Important terms and new concepts are also italicized the first time they appear in the text. Those terms are either explained immediately after they are cited, or else the reader is referred to a section in the book where they are described in detail.</td>
  </tr>
  <tr>
   <td>link</td>
   <td>References to other sections and to figures and tables are links to those sections.</td>
  </tr>
 </tbody>
</table>
<h3 id="Acknowledgements" name="Acknowledgements">Acknowledgements</h3>
<p>Thanks to Peter Lubczynski, John Gaunt, Ellen Evans, and Alec Flett for technical reviews. A special thanks goes to Darin Fisher for his very acute observations, close reading, and attention to detail.</p>
<p>{{ CXCLicenseBlock() }}</p>
Revert to this revision