日期:2014-05-16 浏览次数:20412 次
#include "nsISupports.idl" [scriptable, uuid(9285aaa6-19fd-4fdb-8621-916f856c024f)] interface nsIDOMHiGecko : nsISupports { attribute long myval ; /*可读可写的属性*/ boolean getIsOK(); /*一个接口*/ };
3 编译(这步可以先不做,只是可以先编译下,提前看下生成的接口是不是想要的,也可以放到 第6步 编译gecko 一起做)
编译成功后可以查看一下objdir-gecko-cosb2g/dist/include/nsIDOMHiGecko.h文件,里面定义了相应的C++类接口,在它最后的注释里还给出了如何写对应的c++实现
*********nsDOMHiGecko.h的内容************ #ifndef nsDOMHiGecko_h_ #define nsDOMHiGecko_h_ #include "nsIDOMHiGecko.h" class nsDOMHiGecko : public nsIDOMHiGecko { public: NS_DECL_ISUPPORTS //声明com引用计数接口 NS_DECL_NSIDOMHIGECKO // 声明hiGecko的接口 nsDOMHiGecko(); protected: ~nsDOMHiGecko(); private: int32_t mValue; // hiGecko的属性,用来保存idl里的myval }; #endif
#include "nsDOMHiGecko.h" #include "nsDOMClassInfoID.h" nsDOMHiGecko::nsDOMHiGecko() : mValue(0) { } nsDOMHiGecko::~nsDOMHiGecko() { } DOMCI_DATA(DOMHiGecko, nsDOMHiGecko) NS_INTERFACE_MAP_BEGIN(nsDOMHiGecko) NS_INTERFACE_MAP_ENTRY(nsISupports) // 用于com接口查询 NS_INTERFACE_MAP_ENTRY(nsIDOMHiGecko) // 用于nsIDOMHiGecko接口查询 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMHiGecko) // 用于classinfo接口查询 NS_INTERFACE_MAP_END NS_IMPL_ADDREF(nsDOMHiGecko) NS_IMPL_RELEASE(nsDOMHiGecko) NS_IMETHODIMP nsDOMHiGecko::GetIsOK(bool *_retval) { *_retval = true; return NS_OK; } NS_IMETHODIMP nsDOMHiGecko::GetMyval(int32_t *aMyval) { *aMyval = mValue; return NS_OK; } NS_IMETHODIMP nsDOMHiGecko::SetMyval(int32_t aMyval) { mValue = aMyval; return NS_OK; }
#ifndef nsDOMHiGecko_h_ #define nsDOMHiGecko_h_ #include "nsIDOMHiGecko.h" #include "nsISecurityCheckedComponent.h" class nsDOMHiGecko : public nsIDOMHiGecko ,public nsISecurityCheckedComponent { public: NS_DECL_ISUPPORTS NS_DECL_NSIDOMHIGECKO NS_DECL_NSISECURITYCHECKEDCOMPONENT nsDOMHiGecko(); protected: ~nsDOMHiGecko(); private: int32_t mValue; // hiGecko的属性,用来保存idl里的myval }; #endif
#include "nsDOMHiGecko.h" #include "nsDOMClassInfoID.h" nsDOMHiGecko::nsDOMHiGecko() { } nsDOMHiGecko::~nsDOMHiGecko() { } NS_INTERFACE_MAP_BEGIN(nsDOMHiGecko) NS_INTERFACE_MAP_ENTRY(nsIDOMHiGecko) NS_INTERFACE_MAP_ENTRY(nsISecurityCheckedComponent) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMHiGecko) NS_INTERFACE_MAP_END NS_IMPL_ADDREF(nsDOMHiGecko) NS_IMPL_RELEASE(nsDOMHiGecko) NS_IMETHODIMP nsDOMHiGecko::GetIsOK(bool *_retval) { *_retval = true; return NS_OK; } static char* cloneAllAccess() { static const char allAccess[] = "AllAccess"; return (char*)nsMemory::Clone(allAccess, sizeof(allAccess)); } static char* cloneUniversalXPConnect() { static const char universalXPConnect[] = "UniversalXPConnect"; return (char*)nsMemory::Clone(universalXPConnect, sizeof(universalXPConnect)); } NS_IMETHODIMP nsDOMHiGecko::GetMyval(int32_t *aMyval) { *aMyval = mValue; return NS_OK; } NS_IMETHODIMP nsDOMHiGecko::SetMyval(int32_t aMyval) { mValue = aMyval; return NS_OK; } NS_IMETHODIMP nsDOMHiGecko::CanCreateWrapper(const nsIID * iid, char **_retval) { *_retval = cloneAllAccess(); return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP //这个接口可以控制哪些方法可以在js里访问,这里用的是"allAccess"权限 nsDOMHiGecko::Ca