获取Firefox内置组件的接口实现
Getting Interface Implementation of built-in Mozilla Firefox Component
我目前正在尝试在c++中开发一个自定义密码管理器。
我已经开发了一个可部署的模块,实现了nsILoginManagerStorage接口,可以安装在firefox上,当出现密码字段时,firefox会正确调用它。
问题是,当我试图实例化要返回的nsILoginInfo对象时,do_CreateInstance函数总是返回null。我的方法实现是:
NS_IMETHODIMP FirefoxComponent::FindLogins(uint32_t *count, const nsAString & aHostname, const nsAString & aActionURL, const nsAString & aHttpRealm, nsILoginInfo * **logins)
{
nsILoginInfo ** array = static_cast<nsILoginInfo**>(nsMemory::Alloc(sizeof(nsILoginInfo*)));
nsresult result;
nsCOMPtr<nsILoginInfo> loginInfo = do_CreateInstance("@mozilla.org/login-manager/loginInfo;1" , &result);
//nsCOMPtr<nsILoginManager> loginInfo = do_CreateInstance("@mozilla.org/login-manager;1" , &result);
if (NS_FAILED(result)){
printf("shouldn't be here!!n");
return result;
}
}
我试过得到一个nsILoginManager实例(只是为了检查它是否工作),但它有相同的结果。nsILoginInfo可以通过java脚本在firefox上实例化:
Components.classes["@mozilla.org/loginmanager/loginInfo;1"].createInstance(Components.interfaces.nsILoginInfo);
我在Ubuntu x64上使用firefox 20.0和xul-runner-sdk 20.0(与20.0.1的结果相同),并使用QtCreator(用于x64)构建。
我的代码灵感来自https://github.com/infinity0/mozilla-gnome-keyring
既然我现在nsILoginInfo被正确加载到firefox中,firefox是否需要任何字段/信息来允许我访问这些接口?
感谢您的支持。
编辑:试图通过直接访问组件管理器来加载模块,但无法加载组件管理器。
nsIComponentManager * manager;
result = NS_GetComponentManager(&manager);
if (NS_FAILED(result)){
printf("failed getting component manager!!n");
return result;
}
经过多次尝试和错误后,我发现这个错误是由于库的不良链接。我丢失了一个库(libxpcom.so)。
为了正确编译和运行它,我使用libxpcom库。libxpcomglue_s。A,都在gecko sdk/xul-runner lib文件夹中找到。关于在每个平台中使用哪些库进行编译的更多信息:https://developer.mozilla.org/en-US/docs/XPCOM_Glue
相关文章:
- 如何从实现接口的模板化类实例访问结构
- 传递实现特定接口的类
- 如何在C++中实现接口
- C++ 使用接口和默认实现继承
- unique_ptr实现接口时对已删除函数的引用
- C++接口实现和子类化对象识别
- 接口实现和私有继承之间的交互
- Pimpl习惯用法、单独的接口/实现文件和多个虚拟继承.如何
- 定义大量的接口实现
- cpp文件中的纯虚拟接口实现
- 如何使用接口实现回调
- 继承接口实现
- 如何在C++中编写类java参数级接口实现
- 具有其他默认参数的接口实现
- Mixin和接口实现
- 如何在许多类中重用接口实现
- Emscripten Javascript接口实现
- 获取Firefox内置组件的接口实现
- c++中的头文件和Java中的抽象类/接口实现是相同的想法,这是正确的吗?
- C++中的接口+实现:代码不执行