creating xpcom components--前言

preface 
 
  •    "Who Should Read This Book"
  •    "Organization of the Tutorial"
  •    "Following Along with the Examples"
  •    "Conventions"
  •   "Acknowledgements"
 
 

    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 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 leaned how to build a component and you will know something about the framework for these components in Gecko, which is XPCOM.

 
  •     谁应该读这本书!
  •     指南的结构
  •     跟随例子学习
  •     常规约定
  •     致谢
 
    这是一本关于Gecko以及如何为基于Gecko的程序开发xpcom组件的书。按照我们讲述的步骤,你可以将你的c++代码变成可以运行在Gecko中的组件的代码,而这本书重点就在于讲述这样一些实用的的步骤;同时,我们也希望,通过讨论这些步骤可以给我们提供一些机会,让我们讨论构建xpcom所涉及到的工具、技术、方法。相应的,这本书按照下面的方式来组织:你既可以把它当作教程来跟随学习,也可以把它当作参考手册,以单独的学习不同的xpcom的主题。举例来说,介绍部分包含了对组件、以及什么是组件的讨论;第一章(讲述编译基本的代码及在mozilla中注册的问题)提供了组件和模块关系的讨论,对xpcom接口的讨论,以及一般的注册过程的讨论。
    每一章的最开始部分都提供了本章所涉及到的主题的列表。其中包含的侧边用来高亮显示技术细节[1]。走到本书的最后,如果我们完成了我们所要说的,你应该已经学会如何去构建一个组件,而且对于Gecko里边关于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.

 

 

    谁应该读这本书!

    创建xpcom组件主要是对c++开发人员来说的。虽然你也可以用javascript和其他的语言来创建它,或者你会用c去实现,但是组件的执行代码是用c++写的,而且很多改造你的代码以便用于xpcom组件的事情也是从c++开始的。不过你也不必成为一个c++专家。基本的概念,比如继承、封装,你应该是对它们比较熟悉了,但只要可能,这本书在提到的这些的时候都会解释一下。而且由于其中的很多例子是javascript的--他们用来在mozilla中访问作为脚本对象的xpcom组件,所以熟悉javascript也是比较有用的。

    xpcom是跨平台的组建对象模型的缩写。就像他的名字所指明的一样,xpcom是跟微软的com想类似的。如果你有后者的经验,那么很多都可以直接应用到xpcom上。虽然如此,这本书没有假设你有任何的com的知识---所有的关于com的想法都会被介绍到的。

    这本书提供了关于构建xpcom组件来控制浏览器行为的指南。虽然xpcom可以用在很多的与web浏览器无关的环境下,但是他的主要客户端还是是Gecko,Gecko是一个开源的、符合标准的、嵌入式web浏览器,在这个浏览器里,可以最容易、最实际的解释xpcom的功能。你可以在"What We'll Be Working On"这一部分里边找到对组件的完整的描述。

 

    

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.
 
指南的组织方式
 
        下边的这个列表提供了一个构造步骤的概览,我们按照这些步骤来构建一个名字叫做WebLock的xpcom组件,他可以为基于Gecko的浏览器提供了屏蔽站点的功能。其中每一步都有自己的一章来介绍,同时我们将讨论与每一步相关的话题。
  •     创建组件的基本的模块代码
  •     用c++宏,特殊的字符串类还有智能指针来优化你的代码
  •     定义组件的功能;为这些功能创建XPIDL接口;为WebLock组件的接口创建执行代码
  •     完成WebLock组件:nsIContentPolicy, file I/O, locking等
  •     创建WebLock组件的用户接口
  •     打包WebLock,方便分发和安装
 
 
    

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 and 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. Releases prior to Mozilla 1.2 did not completely support XPCOM components with frozen interfaces, but changes since then have remedied this.

 

    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 Platform.

    
    
跟着例子走
    这里有几个不同的方法把xpcom组件安装到你的机器上,你可以依照其中的方法开始创建这些组件。 如果你已经有了编译好的Mozilla或者他的代码--需要版本高于1.2的,你就可以用其中的xpcom框架了。如果你没有mozilla的源代码,更简单的取得和应用xpcom的方法就是把Gecko SDK下载下来,他是一个库和工具的集合,这些库和工具组成了xpcom的框架。
    不论你采用编译Mozilla代码树的方法还是使用Gecko的SDK的方法,你可以构建你自己的组件,它可以使用其他的已经存在于Gecko中的组件。我们在找个指南中描述的WebLock组件是一个(我们希望是有用的)可实际使用的浏览器插件。为了构建他,你的Gecko SDK或者Mozilla源代码版本需要高于 1.2。Mozilla 1.2以前的release版本并不完全支持带frozen interfaces的xpcom组件,不过这种情况已经改变了。
    
   虽然用SDK和用编译的Mozilla源代码树[2]的差别很小,但是这本书假设你正在使用前者而不是后者。关于下载SDK、编译及获得Gecko组件的安全
 
 

Conventions

The formatting conventions listed in Table 1 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.

TABLE 1. Formatting Conventions Used in This Book
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. Longer code listings appear in gray boxes.

italic

variables, filenames and directory names terms 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. References to other chapters (e.g., Getting Social: Making Instances of Your Component Available) are also italicized.

"quoted"

References to other sections are double-quoted (e.g. "Organization of the Tutorial").
 

约定格式

 

    本书的表示特殊类型的信息的格式都列在了下边这个table1里边,这样可以让浏览更加的容易。我们的目标是在清晰的区分各种类型的信息的前提下,尽可能的少用特殊的格式。

 

 Table1. 这本书中用到的约定格式。  

 

 

 

 

 Table1. 这本书中用到的约定格式。  

 

 

 

 

 

 

 

 

 

 

 

 

Format Description
粗体 文本中的粗体表示组件的名字

等宽字体

代码列表、接口名字、接口中的成员(e.g., createInstance()) 用的是等宽字体。更长的代码列表放到灰色框里。  

斜体

变量的名字,文件名字还有目录的名字都用斜体表示。重要的项和概念在地一次出现在文本中的时候也是斜体。这些项要么在他们被引用以后立即被解释,要么提示读者书中有详细解释的地方。对其他的章节的引用(e.g., Getting Social: Making Instances of Your Component Available) 也是斜体化。[3]

双引号

对其他的章节的应用(例如 "Organization of the Tutorial").


 

Acknowledgements

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

 

我的注释:

[1]其中包含的侧边用来高亮显示技术细节。我没有搞清楚这句话说的是哪里。

[2]代码树的描述方式好像来自于代码的组织方式

[3]好像区别于下边的双引号

 

也许是我的理解能力有限,我总觉得原文好像表达的不是特别的好!

 

 

 

你可能感兴趣的:(creating xpcom components--前言)