Home
2013 年 4 月 12 日

Yesterday to help a relative, make a restaurant reservation system (fine-tuning from “口福科技”). Think this system is doing pretty good, although the code is not standardized, not enough modular, but the general framework is OK.  I recorded it in order to prepare for possible future then. (Download Address)

shudingbo - 2013 年 4 月 12 日
2013 年 3 月 7 日
, , , ,

XPCOM component develop

When translation the xpcom guide series, i found that create a running xpcom component so difficulty by this series of articles. These articles published in 2005 (then Firefox also enter the version of World War), these articles later update with the Firefox upgrade sustained, but there are still a lot of places did not change. When we read these articles, often difficult accordance with article write code that can be run (or even be able to compile through). Below some of the possible problems listed below:

[Note: I make a xpcom component wizard, used to simplify xpcom components create work. ]

1. Component registration

The component registration from the Gecko 2.0 has changes (see the official article, XPCOM changes in Gecko 2.0). Now you could not find Regxpcom program that the article mentioned, you do not need to run any special procedures to register the components, nsModuleComponentInfo structure also had been replaced by nsModuleComponentInfo. You just need to join in chrome.manifest file the components’s information (eg,interface, binary library location) or add a component manifest file. Then the Gecko loaded automatically according chrome.manifest file . chrome.manifest the contents of the file are as follows:

chrome.manifest

content    test    chrome/content/ 
locale     test    en-US    chrome/locale/en-US/ 
skin       test    classic/1.0    chrome/skin/ 
manifest   components/yuAccess.manifest

the manifest line in the chrome.manifest file, description yuAccess’s information. The yuAccess.manifest file that record YuAccess components’s information placed on the components directory.

yuAccess.manifest contents of the file are as follows:

binary-component yuAccess.dll
interfaces yuIAccess.xpt

category profile-after-change yuAccess @yutools.com/yuIAccess;1

chrome.manifest’s file format,please see:“Chrome Registration”。

2. Component as services

The steps that component as service has also undergone a change, become more simple, you just need to add the following command in the component manifest file:

category profile-after-change yuAccess @yutools.com/yuIAccess;1

3. XPIDL Code Generation

IDL generation program that generation .h and .xpt file also replaced by a python script. In the directory “$(XPCOM_SDK)\sdk\bin\” , you can find the appropriate script command execution example is as follows:

python %XPCOM_SDK%\sdk\bin\typelib.py --cachedir=./cache -I %XPCOM_SDK%\idl -o ../../bin/components/yuIAccess.xpt yuIAccess.idl
python %XPCOM_SDK%\sdk\bin\header.py --cachedir=./cache -I %XPCOM_SDK%\idl -o ../include/yuIAccess.h yuIAccess.idl
2013 年 2 月 16 日
,

回调函数与回调机制

(本文写自2007-12-19,发表于CSDN)

1.什么是回调函数

回调函数(callback Function),顾名思义,用于回调的函数。  回调函数只是一个功能片段,由用户按照回调函数调用约定来实现的一个函数。回调函数是一个工作流的一部分,由工作流来决定函数的调用(回调)时机。回调函数包含下面几个特性:

  • 属于工作流的一个部分;
  • 必须按照工作流指定的调用约定来申明(定义);
  • 他的调用时机由工作流决定,回调函数的实现者不能直接调用回调函数来实现工作流的功能;

(more…)

2013 年 2 月 13 日

XPCOM指南-9_WebLock组件打包

这是教程最后一部分, 我们将把WebLock组件的所有部分(包括库文件、类型库、头文件

和用户界面资源文件)打包成一个包,以便可以安装到其它应用里。 第一节,“Component Installation Overview”,描述了Mozilla的常规安装过程。 下一节描述WebLock组件的组织和打包步骤。

请注意: 这个教程主要是关注组件开发本身, 所以这部分描述有关打包和安装到Gecko的过程是很简单的. 如果你希望了解详细的打包和安装组件到基于Gecko应用的信息,应该参考http://www.mozilla.org/projects/xpinstall(more…)

2013 年 2 月 13 日

XPCOM指南-8_编写WebLock界面

编写组件的UI

到目前为止我们建立了一个可以安装到Gecko应用中的组件。你所使用的XPCOM接口和工具是通用的跨平台的,可以被Gecko Runtime Environment或者任何Mozilla1.2以后任何基于Gecko的应用(这时GRE已经可用)。

本章,我们将建立WebLock组件的用户接口,这就意味着添加到 现有的 Mozilla 浏览器[other-mozlike-browsers]. 他使用 XUL, 这是一个Gecko知道如何呈现用户界面的XML语言, 同时它也跟特定的Mozilla用户界面交互, 为此它要把自己作为UI的扩展安装起来。特别是,我们在本章编写的用户界面会叠加到浏览器组件的状态栏,它提供了一个小图标,用户可以通过点击它访问weblock接口。 (more…)

2013 年 2 月 11 日

XPCOM指南-7_结束编写WebLock

注: 本文部分翻译来自官网

现在您已创建组件的大多数基础结构。 该组件可以被XPCOM和类别管理器识别,那样在 XPCOM初始化时,它就可以开启动。 组件启动时,它会读取存储在本地文件系统里Url列表,填充到相应的二进制结构。

1. Using Frozen Interfaces

然而,现在阻止站点的核心功能仍然缺失。 这个接口仍然没有冻结,组件开发人员需要讨论那些功能应该完全公开,所以API没有准备好发布。 这让你处于和大多数使用Mozilla的开发者一样的境地—你想使用一些特定的功能,但是接口似乎天天都在变。

(more…)

2013 年 2 月 10 日

XPCOM指南-6_开始编写WebLock

注: 本文部分翻译来自官网

在本章,我们开始设计和实现网络锁定功能本身。我们已经建立了实现多数的通用组件功能模块(例如注册)。这章将关注实际操作网页锁定的功能。

1. Getting Called at Startup

没有人是一个孤岛,组件也一样。你所建立的例子组件到目前为止还没有任何功能。他被注册以后,他没做任何事情。

为了当某些事件发生的时候能够触发相应动作(如,启动)或者接收到相应的事件通知,例子组件需要挂接到Mozilla,或者覆盖一个现存组件,或者在Mozilla上注册到一些事件(组件关心的)。WebLock用后面的方式,在Gecko Profile Startup事件发生的时候被触发产生调用。当Gecko应用启动的时候,会创建注册的组件,并通过通用观察者接口(nsIObserver)发出通知。

(more…)

2013 年 2 月 8 日

XPCOM指南-5_使用XPCOM实用工具简化你的生活

本章回顾你已经在教程第一部分建立的代码 (see webLock1.cpp in the previous chapter) 并且使用 XPCOM 工具类让代码更容易更有效. 同时,介绍一个在XPCOM和Gecko API中广泛使用基本的字符串类型。

作为起点,第一部分描述可以替代webLock1.cpp中的很多代码的C++ 宏. 很多用来完成软件组织和组件注册的代码都可以缩减为精简的数据结构和宏代码。

1. XPCOM 宏

为了让C++开发简单些,XPCOM框架提供了大量的宏。 尽管它们之间,有些重叠(例如,高层的宏可以用其他的宏来组织),他们通常可以组织成如下的类别。 (more…)

2013 年 1 月 10 日

XPCOM指南-4_创建组件的代码

本章会讲述一些基本代码,这些代码用于处理你的组件与XPCOM之间的关系。  如何发现和注册组件是本指南的第一节的目标。在后续的章节里,我们就可以专注WebLock本生的功能开发了。

为了创建组件库并把它加载进XPCOM,你需要编写大量的代码。 一个XPCOM组件至少需要实现XPCOM必须的3个接口,而且往往还要其它的接口。 这一章你将会看到更多的代码,然而这些并不是整个WebLock组件代码。“Using XPCOM Utilities to Make Things Easier”展示了更加简单,更加优雅的方式创建XPCOM组件(使用泛型和宏),这一章的目的是为了学习基础知识,因为这对你深入了解XPCOM是很有帮助的。 (more…)

2013 年 1 月 9 日

XPCOM指南-3_组件的内部结构

前面章节从客户使用角度描述了XPCOM组件,本章从开发者角度讨论组件。 请仔细阅读,XPCOM组件是怎么实现的,你可以略过本章到下一章节,从下一章节开始将会一步一步创建WebLock组件。

1. C++创建组件

让我们用C++开始XPCOM之旅吧。 XPCOM的大多数组件是用C++写的,然后编译为共享库(在windows下是DLLUnix下是DSO)。 (more…)