(FFOS Gecko) - several ways of using a XPCOM Service

1. Using a service in C++

nsCOMPtr<nsIServiceManager> servManager;
nsresult rv = NS_GetServiceManager(getter_AddRefs(servManager));
if (NS_FAILED(rv)) { // get ServiceManager error
  return -1;
}

// get real Service
nsCOMPtr<nsICustomService> customService;
rv = servMan->GetServiceByContractID("@mozilla.org/customservice",
                                     NS_GET_IID(nsICustomService),
                                     getter_AddRefs(customService));
if (NS_FAILED(rv)) { // get CustomService error
  return -1;
}

// call a method of CustomService
customService->callMethod(/*some parameters*/);

2. Using a service in Javascript(XPConnect)

customService = Components.classes["@mozilla.org/customservice;1"]
                 .getService();
customService = customService.QueryInterface(Components.interfaces.nsICustomService);
customService.callMethod();
时间: 2024-08-30 11:27:13

(FFOS Gecko) - several ways of using a XPCOM Service的相关文章

(FFOS Gecko) - several ways of registering a XPCOM Component

1. JavaScript Component (1) add a CustomComponent.manifest # The {classID} here must match the classID in CustomComponent.js component {e6b866e3-41b2-4f05-a4d2-3d4bde0f7ef8} components/CustomComponent.js contract @foobar/customcomponent;1 {e6b866e3-4

(FFOS Gecko) - several ways of exposing a module to navigator

当我们实现了一个module,并且通过navigator.mozCustomModule访问 根据module的实现方式的不同,有几种不同的做法. 1. XPCOM component(Javascript实现): 在chrome.manifest中配置(加粗部分): component {ComponentID} CustomModule.js contract ContractID {ComponentID} category JavaScript-navigator-property mo

(FFOS Gecko &amp; Gaia) OTA - Do real check

虽然代码分析了很多,但是还没有真正做check的工作,下面就来找到真正的checker. 代码位置:gecko/toolkit/mozapps/update/nsUpdateService.js.参考之前的(FFOS Gecko & Gaia) OTA - 代码模块总览,nsUpdateService.js中的Checker对象,实现了nsIUpdateChecker这个interface.下面就来分析Checker对象的实现. 1.  checkForUpdates函数: 实现略长,在代码中添

(FFOS Gecko &amp; Gaia) OTA - 进入Gecko层

代码位置:gecko/b2g/components/UpdatePrompt.js SystemApp发出'force-update-check'事件,也就从gaia进入到了gecko层. 1. 首先大概介绍一下UpdatePrompt.js. (a) UpdatePrompt.js里包含了2个对象,分别是UpdatePrompt和UpdateCheckListener. (b) UpdatePrompt实现了“@mozilla.org/updates/update-prompt;1”这个XPC

(FFOS Gecko &amp; Gaia) OTA - 又回到UpdatePrompt

当download完成时,又回到了UpdatePrompt,因为此时需要提示user下载完成,确认apply. 1. UpdatePrompt.showUpdateDownloaded showUpdateDownloaded: function UP_showUpdateDownloaded(aUpdate, aBackground) { if (this._systemUpdateListener) { this._systemUpdateListener.onUpdateReady();

(FFOS Gecko &amp; Gaia) OTA - 代码模块总览

OTA整体框架里会涉及以下代码,从gaia到gecko都有,而且由于历史原因,复用了desktop browser的一些模块,还有一些冗余代码,分析时走了不少弯路. 1. Gaia部分 (a) gaia/apps/settings/js/panels/about/update_check.js 这个Settings中OTA功能的入口,通过AMD(Asynchronous Module Definition)规范,定义了一个模块UpdateCheck. (b) gaia/apps/system/j

(FFOS Gecko &amp; Gaia) OTA - 重回Gaia层

SystemApp中的UpdateManager作为gaia和gecko的通信桥梁,会接收gecko中UpdatePrompt发送的'update-available'事件. 1. UpdateManager.handleEvent var detail = evt.detail; if (detail.type && detail.type === 'update-available') { // systemUpdatable是在UpdateManager初始化时new出来的,Upda

(FFOS Gecko) - useful MACRO

NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS is used for classes that have JS references or a mix of JS and C++ references to report.  This participant has Trace, Traverse, and Unlink methods.

(FFOS Gecko &amp; Gaia) OTA - 关键的apply

这篇分析已经是尾声了,在UpdatePrompt中,调用了UpdateService的applyOsUpdate函数. 1. UpdateService.applyOsUpdate 这个函数很简单,就是获取到update.zip以后,调用recovery service去完成更新. applyOsUpdate: function AUS_applyOsUpdate(aUpdate) { if (!aUpdate.isOSUpdate || aUpdate.state != STATE_APPLI